* Add duplicate name judgment.
This commit is contained in:
+17
-11
@@ -150,21 +150,16 @@ class branchModel extends model
|
||||
->add('status', 'active')
|
||||
->get();
|
||||
|
||||
$existBranchName = $this->dao->select('name')->from(TABLE_BRANCH)->where('name')->eq($branch->name)->fetch('name');
|
||||
if(!empty($existBranchName))
|
||||
{
|
||||
$this->app->loadLang('product');
|
||||
$productType = $this->dao->select('`type`')->from(TABLE_PRODUCT)->where('id')->eq($productID)->fetch('type');
|
||||
|
||||
dao::$errors['name'] = str_replace('@branch@', $this->lang->product->branchName[$productType], $this->lang->branch->existName);
|
||||
return false;
|
||||
}
|
||||
|
||||
$lastOrder = (int)$this->dao->select('`order`')->from(TABLE_BRANCH)->where('product')->eq($productID)->orderBy('order_desc')->limit(1)->fetch('order');
|
||||
$branch->order = empty($lastOrder) ? 1 : $lastOrder + 1;
|
||||
|
||||
$this->app->loadLang('product');
|
||||
$productType = $this->dao->select('`type`')->from(TABLE_PRODUCT)->where('id')->eq($productID)->fetch('type');
|
||||
$this->lang->error->unique = str_replace('@branch@', $this->lang->product->branchName[$productType], $this->lang->branch->existName);
|
||||
|
||||
$this->dao->insert(TABLE_BRANCH)->data($branch)
|
||||
->batchCheck($this->config->branch->create->requiredFields, 'notempty')
|
||||
->checkIF(!empty($branch->name), 'name', 'unique', "product = $productID")
|
||||
->exec();
|
||||
|
||||
if(!dao::isError()) return $this->dao->lastInsertID();
|
||||
@@ -185,9 +180,14 @@ class branchModel extends model
|
||||
$newBranch = fixer::input('post')->get();
|
||||
$newBranch->closedDate = $newBranch->status == 'closed' ? helper::today() : '';
|
||||
|
||||
$this->app->loadLang('product');
|
||||
$productType = $this->getProductType($branchID);
|
||||
$this->lang->error->unique = str_replace('@branch@', $this->lang->product->branchName[$productType], $this->lang->branch->existName);
|
||||
|
||||
$this->dao->update(TABLE_BRANCH)->data($newBranch)
|
||||
->where('id')->eq($branchID)
|
||||
->batchCheck($this->config->branch->edit->requiredFields, 'notempty')
|
||||
->checkIF(!empty($newBranch->name) and $newBranch->name != $oldBranch->name, 'name', 'unique', "product = $oldBranch->product")
|
||||
->exec();
|
||||
|
||||
if(!dao::isError()) return common::createChanges($oldBranch, $newBranch);
|
||||
@@ -206,6 +206,10 @@ class branchModel extends model
|
||||
$oldBranchList = $this->getList($productID, 'all');
|
||||
$branchIDList = array_keys($this->post->IDList);
|
||||
|
||||
$this->app->loadLang('product');
|
||||
$productType = $this->dao->select('`type`')->from(TABLE_PRODUCT)->where('id')->eq($productID)->fetch('type');
|
||||
$this->lang->error->unique = str_replace('@branch@', $this->lang->product->branchName[$productType], $this->lang->branch->existName);
|
||||
|
||||
foreach($branchIDList as $branchID)
|
||||
{
|
||||
if($branchID == BRANCH_MAIN)
|
||||
@@ -221,11 +225,13 @@ class branchModel extends model
|
||||
$branch->name = $data->name[$branchID];
|
||||
$branch->desc = $data->desc[$branchID];
|
||||
$branch->status = $data->status[$branchID];
|
||||
$branch->default = (isset($data->default) and $branchID == $data->default and $branch->status != 'active') ? 1 : 0;
|
||||
$branch->default = (isset($data->default) and $branchID == $data->default) ? 1 : 0;
|
||||
$branch->closedDate = $branch->status == 'closed' ? helper::today() : '';
|
||||
|
||||
|
||||
$this->dao->update(TABLE_BRANCH)->data($branch)
|
||||
->batchCheck($this->config->branch->create->requiredFields, 'notempty')
|
||||
->checkIF(!empty($branch->name) and $branch->name != $oldBranchList[$branchID]->name, 'name', 'unique', "product = $productID")
|
||||
->where('id')->eq($branchID)
|
||||
->exec();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user