From e14c8d984c8860bc5c621231c25fb62ba95d9aaa Mon Sep 17 00:00:00 2001 From: qianhy Date: Fri, 10 Mar 2023 10:35:40 +0800 Subject: [PATCH] store add fixbug auo_brands to table --- admin/controllers/biz/store/Store.php | 75 ++++++++++++++------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/admin/controllers/biz/store/Store.php b/admin/controllers/biz/store/Store.php index d286a7d5..6c00c993 100755 --- a/admin/controllers/biz/store/Store.php +++ b/admin/controllers/biz/store/Store.php @@ -285,10 +285,10 @@ class Store extends HD_Controller } $auto_brands = $this->input->post('auto_brands'); - if ($auto_brands) { + /*if ($auto_brands) { $jsondata = array('auto_brands' => $auto_brands); $biz['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE); - } + }*/ //上传头像 $biz['headimg'] = $this->input->post('headimg'); @@ -303,6 +303,7 @@ class Store extends HD_Controller if (!$id) { return $this->show_json(SYS_CODE_FAIL, '添加失败'); } + $this->grant_auto_brands($auto_brands, $id, $biz['type']); foreach ($tag_more as $key => $value) { if ($value) { @@ -319,6 +320,42 @@ class Store extends HD_Controller return $this->show_json(SYS_CODE_SUCCESS, '操作成功'); } + private function grant_auto_brands($auto_brands, $id, $biz_type){ + if($auto_brands){ + $brand_ids = implode(',',$auto_brands); + $where = [ + 'biz_id' => $id, + "brand_id not in ({$brand_ids})" => null, + ]; + if($this->auto_brand_biz_model->count($where)){ + $this->auto_brand_biz_model->delete($where); + } + $add_datas = []; + foreach ($auto_brands as $key => $val) { + $where = [ + 'biz_id' => $id, + 'brand_id' => $val + ]; + if(!$this->auto_brand_biz_model->count($where)){ + $add_datas[] = [ + 'biz_id' => $id, + 'type' => $biz_type, + 'brand_id' => $val, + 'c_time' => time() + ]; + } + } + $add_datas && $this->auto_brand_biz_model->add_batch($add_datas); + }else{ + $where = [ + 'biz_id' => $id, + ]; + if($this->auto_brand_biz_model->count($where)){ + $this->auto_brand_biz_model->delete($where); + } + } + } + public function edit() { if (!$this->if_ajax) { @@ -371,39 +408,7 @@ class Store extends HD_Controller // unset($jsondata['auto_brands']); // } // $biz['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE); - if($auto_brands){ - $brand_ids = implode(',',$auto_brands); - $where = [ - 'biz_id' => $id, - "brand_id not in ({$brand_ids})" => null, - ]; - if($this->auto_brand_biz_model->count($where)){ - $this->auto_brand_biz_model->delete($where); - } - $add_datas = []; - foreach ($auto_brands as $key => $val) { - $where = [ - 'biz_id' => $id, - 'brand_id' => $val - ]; - if(!$this->auto_brand_biz_model->count($where)){ - $add_datas[] = [ - 'biz_id' => $id, - 'type' => $biz['type'], - 'brand_id' => $val, - 'c_time' => time() - ]; - } - } - $add_datas && $this->auto_brand_biz_model->add_batch($add_datas); - }else{ - $where = [ - 'biz_id' => $id, - ]; - if($this->auto_brand_biz_model->count($where)){ - $this->auto_brand_biz_model->delete($where); - } - } + $this->grant_auto_brands($auto_brands, $id, $biz['type']); //门店标签 $tag_more = $this->input->post('tag_more');