$data['platform'], 'product_name' => $data['product_name'], 'product_specs' => $data['product_specs'], 'store_scope' => $data['store_scope'], 'insert_time' => time(), ]; $ControlGoods_id = $this->insertGetId($insert_data); return $ControlGoods_id; } /** * 写入数据 * @author 唐远望 * @version 1.0 * @date 2025-12-15 * @param $data * @return bool */ public function addControlGoods($data) { DB::beginTransaction(); try { $ControlGoodsCompanyModel = new ControlGoodsCompanyModel(); $insert_data = [ 'platform' => $data['platform'], 'product_name' => $data['product_name'], 'product_specs' => $data['product_specs'], 'store_scope' => isset($data['store_scope']) && $data['store_scope'] !='' ? 2 : 1, //店铺范围1=全部店铺 2=指定店铺 'company_scope' => isset($data['company_scope']) && $data['company_scope'] !='' ? 2 : 1, //公司范围1=全部公司 2=指定公司 'insert_time' => time(), ]; $ControlGoods_id = $this->insertGetId($insert_data); if ($insert_data['company_scope'] == 2) { $insert_company_data = []; $company_scope = explode(',', $data['company_scope']); foreach ($company_scope as $company_id) { $insert_company_data[] = [ 'control_product_logid' => $ControlGoods_id, 'company_id' => $company_id, ]; } $ControlGoodsCompanyModel->insert($insert_company_data); } DB::commit(); return true; // 成功处理... } catch (\Exception $e) { DB::rollBack(); // 错误处理... return false; } } /** * 编辑内容 * @author 唐远望 * @version 1.0 * @date 2025-12-15 * @param $data * @return bool */ public function editControlGoods_content($where, $data) { $ControlGoods = $this->where($where)->first(); if (!$ControlGoods) { return false; } DB::beginTransaction(); try { $ControlGoodsCompanyModel = new ControlGoodsCompanyModel(); $ControlGoods->platform = $data['platform']; $ControlGoods->product_name = $data['product_name']; $ControlGoods->product_specs = $data['product_specs']; $ControlGoods->store_scope = $data['store_scope']; $ControlGoods->update_time = time(); $ControlGoods->save(); $ControlGoodsCompanyModel->where('control_product_logid', $ControlGoods->id)->delete(); if ($data['company_scope'] == 2) { $insert_company_data = []; $company_scope = explode(',', $data['company_scope']); foreach ($company_scope as $company_id) { $insert_company_data[] = [ 'control_product_logid' => $ControlGoods->id, 'company_id' => $company_id, ]; } $ControlGoodsCompanyModel->insert($insert_company_data); } DB::commit(); return true; // 成功处理... } catch (\Exception $e) { DB::rollBack(); // 错误处理... return false; } } /** * 更新数据 * @author 唐远望 * @version 1.0 * @date 2025-12-15 * @param $data * @return bool */ public function updateControlGoods($where, $data) { DB::beginTransaction(); try { $this->editControlGoods_content($where, $data); DB::commit(); return true; // 成功处理... } catch (\Exception $e) { DB::rollBack(); // 错误处理... return false; } } /** * 修改状态 * @author 唐远望 * @version 1.0 * @date 2025-12-15 * @param $id * @param $status * @return bool */ public function changeStatus($where, $status) { $ControlGoods = $this->where($where)->first(); if (!$ControlGoods) { return false; } $ControlGoods->status = $status; $ControlGoods->update_time = time(); $ControlGoods->save(); return true; } /** * 删除数据 * @author 唐远望 * @version 1.0 * @date 2025-12-15 * @param $id * @return bool */ public function deleteControlGoods($where) { $ControlGoods = $this->where($where)->first(); if (!$ControlGoods) { return false; } $ControlGoods->delete(); return true; } }