diff --git a/admin/controllers/biz/store/Store.php b/admin/controllers/biz/store/Store.php index 2c8968cd..f135b12c 100644 --- a/admin/controllers/biz/store/Store.php +++ b/admin/controllers/biz/store/Store.php @@ -22,6 +22,7 @@ class Store extends HD_Controller $this->load->library('bizAccount'); $this->load->helper('db'); $this->load->model('auto/auto_brand_model'); + $this->load->model('biz/biz_car_brand_model'); } public function index() @@ -73,10 +74,10 @@ class Store extends HD_Controller $count = $this->biz_model->count($where); $bizlists = []; $account = new BizAccount(); - $brandAry = $this->auto_brand_model->select(['status>'=>0], 'initial asc', 0, 0, 'id,name'); - if($biz_lists){ + $brandAry = $this->auto_brand_model->select(['status>' => 0], 'initial asc', 0, 0, 'id,name'); + if ($biz_lists) { $map = []; - foreach($brandAry as $item) { + foreach ($brandAry as $item) { $map[$item['id']] = null !== $item['name'] ? $item['name'] : ''; } foreach ($biz_lists as $v) { @@ -118,6 +119,14 @@ class Store extends HD_Controller $biz['avatar'] = build_qiniu_image_url($biz['headimg'], 200, 200); $biz['car_brand_id'] = $biz['car_brand_id'] ? intval($biz['car_brand_id']) : ''; + $carBrands = $this->biz_car_brand_model->select(['biz_id' => $id], '', '', 'brand_id'); + $carBrandsIds = []; + if ($carBrands) { + foreach ($carBrands as $item) { + $carBrandsIds[] = intval($item['brand_id']); + } + } + $biz['car_brand_ids'] = $carBrandsIds; $this->data['biz'] = $biz; } else { $map_city = $this->city_ary(); @@ -145,7 +154,7 @@ class Store extends HD_Controller public function add() { - + $car_brand_ids = $this->input->post('car_brand_ids'); $biz['status'] = 1; $biz['biz_name'] = $this->input->post('biz_name', true); if (!$biz['biz_name']) { @@ -176,7 +185,17 @@ class Store extends HD_Controller if (!$id) { return $this->show_json(SYS_CODE_FAIL, '添加失败'); } - + if (is_array($car_brand_ids)) { + $carBrandData = []; + foreach ($car_brand_ids as $item) { + $carBrandData[] = [ + 'biz_id' => $id, + 'brand_id' => $item, + 'c_time' => time() + ]; + } + $carBrandData && $this->biz_car_brand_model->replace_batch($carBrandData); + } return $this->show_json(SYS_CODE_SUCCESS, '操作成功'); } @@ -188,7 +207,7 @@ class Store extends HD_Controller $id = intval($this->input->post('id')); $company_id = intval($this->input->post('company_id', true)); $srv_company_id = intval($this->input->post('srv_company_id', true)); - + $car_brand_ids = $this->input->post('car_brand_ids'); $biz['biz_name'] = $this->input->post('biz_name', true); if (!$biz['biz_name']) { return $this->show_json(SYS_CODE_FAIL, '门店不能为空'); @@ -215,7 +234,19 @@ class Store extends HD_Controller if (!$res) { return $this->show_json(SYS_CODE_FAIL, '添加失败'); } - + if (is_array($car_brand_ids)) { + $carBrandData = []; + foreach ($car_brand_ids as $item) { + $carBrandData[] = [ + 'biz_id' => $id, + 'brand_id' => $item, + 'c_time' => time() + ]; + } + $carBrandData && $this->biz_car_brand_model->replace_batch($carBrandData); + } else { + $this->biz_car_brand_model->delete(['biz_id' => $id]); + } return $this->show_json(SYS_CODE_SUCCESS, '操作成功'); } diff --git a/admin/views/biz/store/edit.php b/admin/views/biz/store/edit.php index a69dd215..d500138a 100644 --- a/admin/views/biz/store/edit.php +++ b/admin/views/biz/store/edit.php @@ -135,14 +135,15 @@