|
|
@@ -102,7 +102,7 @@ class Lists extends Backend
|
|
|
unset($params['product_area'], $params['product_area_txt']);
|
|
|
//商品
|
|
|
$add = $this->model->create($params);
|
|
|
- $result= $this->setEqualArea($add->id, $areaArr, $areaArrTxt);
|
|
|
+ $result= $this->setEqualArea($add->id, $areaArr, $areaArrTxt, 0);
|
|
|
Db::commit();
|
|
|
} catch (ValidateException|PDOException|Exception $e) {
|
|
|
Db::rollback();
|
|
|
@@ -182,8 +182,8 @@ class Lists extends Backend
|
|
|
if(empty($areaArr) || empty($areaArrTxt)) throw new ValidateException('请添加商品关联地区');
|
|
|
unset($params['product_area'], $params['product_area_txt']);
|
|
|
$row->allowField(true)->save($params);
|
|
|
- $this->productArea::where('product_id', $ids)->where('status', 1)->delete();
|
|
|
- $result= $this->setEqualArea($ids, $areaArr, $areaArrTxt);
|
|
|
+ //$this->productArea::where('product_id', $ids)->where('status', 1)->delete();
|
|
|
+ $result= $this->setEqualArea($ids, $areaArr, $areaArrTxt, 1);
|
|
|
Db::commit();
|
|
|
} catch (ValidateException|PDOException|Exception $e) {
|
|
|
Db::rollback();
|
|
|
@@ -197,7 +197,7 @@ class Lists extends Backend
|
|
|
|
|
|
|
|
|
//判断是否存在相同元素
|
|
|
- private function setEqualArea(int $product_id,array $areaArr, array $areaArrTxt): bool
|
|
|
+ private function setEqualArea(int $product_id,array $areaArr, array $areaArrTxt, int $type): bool
|
|
|
{
|
|
|
foreach ($areaArr as $key=>$row)
|
|
|
{
|
|
|
@@ -207,11 +207,13 @@ class Lists extends Backend
|
|
|
$arr['area'] = $row[2]??0;
|
|
|
$arr['county'] = $row[3]??0;
|
|
|
$arr['address'] = $areaArrTxt[$key][0];
|
|
|
- if($this->productArea::where('product_id',$arr['product_id'])
|
|
|
- ->where('province',$arr['province'])
|
|
|
- ->where('city',$arr['city'])->where('area',$arr['area'])
|
|
|
- ->where('county',$arr['county'])->where('status', 0)
|
|
|
- ->count() > 0) continue;
|
|
|
+ if(!empty($type)){
|
|
|
+ if($this->productArea::where('product_id',$arr['product_id'])
|
|
|
+ ->where('province',$arr['province'])
|
|
|
+ ->where('city',$arr['city'])->where('area',$arr['area'])
|
|
|
+ ->where('county',$arr['county'])
|
|
|
+ ->count() > 0) continue;
|
|
|
+ }
|
|
|
$this->productArea::create($arr);
|
|
|
}
|
|
|
return true;
|