$data['enable_full_quantity'], 'platform' => $data['platform'], 'product_name' => $data['product_name'], 'product_specs' => $data['product_specs'], 'minimum_order_quantity' => $data['minimum_order_quantity'], 'sampling_cycle' => $data['sampling_cycle'], 'sampling_start_time' => $data['sampling_start_time'], 'sampling_end_time' => $data['sampling_end_time'], 'insert_time' => time(), ]; $Product_id = $this->insertGetId($insert_data); return $Product_id; } /** * 写入数据 * @author 唐远望 * @version 1.0 * @date 2025-12-30 * @param $data * @return bool */ public function addProduct($data) { DB::beginTransaction(); try { // 计算品规数量 $product_specs_data =isset($data['product_specs']) && $data['product_specs'] !='' ? explode(',', $data['product_specs']) : ''; //移除数组内空值 $product_specs_data = $product_specs_data ? array_filter($product_specs_data):''; $insert_data = [ 'enable_full_quantity' => $data['enable_full_quantity'], 'platform' => $data['platform'], 'product_name' => $data['product_name'], 'product_specs' => $data['product_specs'], 'product_specs_number' => $product_specs_data ? count($product_specs_data) : 1, 'minimum_order_quantity' => $data['minimum_order_quantity'], 'sampling_cycle' => $data['sampling_cycle'], 'sampling_start_time' => $data['sampling_start_time'], 'sampling_end_time' => $data['sampling_end_time'], 'company_id' => $data['company_id'], 'insert_time' => time(), ]; $Product_id = $this->insertGetId($insert_data); DB::commit(); return $Product_id; // 成功处理... } catch (\Exception $e) { DB::rollBack(); // 错误处理... return false; } } /** * 编辑内容 * @author 唐远望 * @version 1.0 * @date 2025-12-30 * @param $data * @return bool */ public function editProduct_content($Product, $data) { DB::beginTransaction(); try { // 计算品规数量 $product_specs_data =isset($data['product_specs']) && $data['product_specs'] !='' ? explode(',', $data['product_specs']) : ''; //移除数组内空值 $product_specs_data = $product_specs_data ? array_filter($product_specs_data):''; $Product->enable_full_quantity = $data['enable_full_quantity']; $Product->platform = $data['platform']; $Product->product_name = $data['product_name']; $Product->product_specs = $data['product_specs']; $Product->product_specs_number = $product_specs_data ? count($product_specs_data) : 1; $Product->minimum_order_quantity = $data['minimum_order_quantity']; $Product->sampling_cycle = $data['sampling_cycle']; $Product->sampling_start_time = $data['sampling_start_time']; $Product->sampling_end_time = $data['sampling_end_time']; $Product->update_time = time(); $Product->save(); DB::commit(); return true; // 成功处理... } catch (\Exception $e) { DB::rollBack(); // 错误处理... return false; } } /** * 更新数据 * @author 唐远望 * @version 1.0 * @date 2025-12-30 * @param $data * @return bool */ public function updateProduct($where, $data) { DB::beginTransaction(); try { $this->editProduct_content($where, $data); DB::commit(); return true; // 成功处理... } catch (\Exception $e) { DB::rollBack(); // 错误处理... return false; } } /** * 修改状态 * @author 唐远望 * @version 1.0 * @date 2025-12-30 * @param $id * @param $status * @return bool */ public function changeStatus($Product, $status) { $Product->status = $status; $Product->update_time = time(); $Product->save(); return true; } /** * 删除数据 * @author 唐远望 * @version 1.0 * @date 2025-12-30 * @param $id * @return bool */ public function deleteProduct($where) { $Product = $this->where($where)->first(); if (!$Product) { return false; } DB::beginTransaction(); try { $Product->delete(); DB::commit(); return true; // 成功处理... } catch (\Exception $e) { DB::rollBack(); // 错误处理... return false; } } }