| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <?php
- namespace App\Models\manager\Collect;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\DB;
- /**
- * 采集配置-商品管理
- * @author: 唐远望
- * @version: 1.0
- * @date: 2025-12-30
- */
- class Product extends Model
- {
- use HasFactory;
- // 与模型关联的表名
- protected $table = 'collect_product';
- // 是否主动维护时间戳
- public $timestamps = false;
- // 定义时间戳字段名
- // const CREATED_AT = 'insert_time';
- // const UPDATED_AT = 'update_time';
- /**
- * 添加
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-30
- */
- public function addProduct_content($data)
- {
- $insert_data = [
- 'enable_full_quantity' => $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 = !empty($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' => $data['product_specs'] ? 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 = !empty($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;
- }
- }
- }
|