LowPriceGoods.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <?php
  2. namespace App\Models\Manager\Process;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\DB;
  6. use App\Models\Manager\Process\LowPriceGoodsMember as LowPriceGoodsMemberModel;
  7. use App\Facades\Servers\Logs\Log;
  8. use App\Models\Manager\Process\Notices as NoticesModel;
  9. use App\Models\Manager\Personnel\Employee as EmployeeModel;
  10. /**
  11. * 违规处理-低价商品模型
  12. * @author: 唐远望
  13. * @version: 1.0
  14. * @date: 2025-12-08
  15. */
  16. class LowPriceGoods extends Model
  17. {
  18. use HasFactory;
  19. // 与模型关联的表名
  20. protected $table = 'process_lowprice_product';
  21. // 是否主动维护时间戳
  22. public $timestamps = false;
  23. // 定义时间戳字段名
  24. // const CREATED_AT = 'insert_time';
  25. // const UPDATED_AT = 'update_time';
  26. /**
  27. * 平台定义
  28. * @author 唐远望
  29. * @version 1.0
  30. * @date 2025-12-31
  31. */
  32. public function platform_data()
  33. {
  34. //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药九九,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  35. $platform_data = [
  36. '全部' => '0',
  37. '淘宝' => '1',
  38. '京东' => '2',
  39. '拼多多' => '3',
  40. '美团' => '4',
  41. '药师帮' => '5',
  42. '1药城' => '6',
  43. '药九九' => '7',
  44. '药易购' => '8',
  45. '药帮忙' => '9',
  46. '熊猫药药' => '10',
  47. '药房网' => '11',
  48. ];
  49. return $platform_data;
  50. }
  51. /**
  52. * 添加
  53. * @author 唐远望
  54. * @version 1.0
  55. * @date 2025-12-08
  56. */
  57. public function addLowPriceGoods_content($data)
  58. {
  59. $insert_data = [
  60. 'company_id' => $data['company_id'],
  61. 'source_id' => $data['source_id'],
  62. 'first_responsible_person' => $data['first_responsible_person'] ? ',' . $data['first_responsible_person'] . ',' : '',
  63. 'responsible_person' => $data['responsible_person'] ? ',' . $data['responsible_person'] . ',' : '',
  64. 'platform' => $data['platform'],
  65. 'company_name' => $data['company_name'],
  66. 'product_brand' => isset($data['product_brand']) ? $data['product_brand'] : '',
  67. 'product_name' => $data['product_name'],
  68. 'product_specs' => $data['product_specs'],
  69. 'suggested_price' => $data['suggested_price'],
  70. 'ultra_low_price' => $data['ultra_low_price'],
  71. 'is_ultra_low_price' => $data['is_ultra_low_price'],
  72. 'online_posting_price' => $data['online_posting_price'],
  73. 'online_posting_count' => isset($data['online_posting_count']) && is_numeric($data['online_posting_count']) ? $data['online_posting_count'] : 1,
  74. 'continuous_listing_count' => isset($data['continuous_listing_count']) && is_numeric($data['continuous_listing_count']) ? $data['continuous_listing_count'] : 1,
  75. 'social_credit_code' => $data['social_credit_code'],
  76. 'province_id' => $data['province_id'],
  77. 'province_name' => $data['province_name'],
  78. 'city_id' => $data['city_id'],
  79. 'city_name' => $data['city_name'],
  80. 'area_info' => $data['area_info'],
  81. 'link_url' => $data['link_url'],
  82. 'store_name' => $data['store_name'],
  83. 'anonymous_store_name' => isset($data['anonymous_store_name']) ? $data['anonymous_store_name'] : '',
  84. 'source_responsible_person' => $data['source_responsible_person'] ? ',' . $data['source_responsible_person'] . ',' : '',
  85. 'category_name' => $data['category_name'],
  86. 'company_category_name' => $data['company_category_name'],
  87. 'processing_status' => '1',
  88. 'insert_time' => time(),
  89. 'scrape_date' => isset($data['scrape_date']) ? $data['scrape_date'] : '',
  90. 'collection_time' => isset($data['collection_time']) ? $data['collection_time'] : '',
  91. 'shipment_province_id' => isset($data['shipment_province_id']) ? $data['shipment_province_id'] : '0', // 发货省份id
  92. 'shipment_province_name' => isset($data['shipment_province_name']) ? $data['shipment_province_name'] : '', // 发货省份
  93. 'shipment_city_id' => isset($data['shipment_city_id']) ? $data['shipment_city_id'] : '0', // 发货城市id
  94. 'shipment_city_name' => isset($data['shipment_city_name']) ? $data['shipment_city_name'] : '', // 发货城市
  95. 'merge_city_id' => $data['merge_city_id'],
  96. 'merge_province_id' => $data['merge_province_id'],
  97. 'merge_city_name' => $data['merge_city_name'],
  98. 'merge_province_name' => $data['merge_province_name'],
  99. 'snapshot_url' => isset($data['snapshot_url']) ? $data['snapshot_url'] : '', // 商品快照地址
  100. 'specify_responsible_person' => isset($data['specify_responsible_person']) ? $data['specify_responsible_person'] : '1', // 指派责任人 0=开启 1=关闭
  101. ];
  102. $LowPriceGoods_id = $this->insertGetId($insert_data);
  103. return $LowPriceGoods_id;
  104. }
  105. /**
  106. * 写入数据
  107. * @author 唐远望
  108. * @version 1.0
  109. * @date 2025-12-08
  110. * @param $data
  111. * @return bool
  112. */
  113. public function addLowPriceGoods($data, $is_import = false)
  114. {
  115. if ($is_import == false) {
  116. //去重规则:品牌方公司ID+店铺公司名称+店铺名称+品牌名称+商品名称+规格+盒数(针对采集)
  117. $source_where[] = ['company_id', '=', $data['company_id']]; //品牌方公司ID
  118. $source_where[] = ['company_name', '=', $data['company_name']]; //店铺公司名称
  119. $source_where[] = ['store_name', '=', $data['store_name']]; //店铺名称
  120. $source_where[] = ['product_brand', '=', $data['product_brand']]; //品牌名称
  121. $source_where[] = ['product_name', '=', $data['product_name']]; //商品名称
  122. $source_where[] = ['product_specs', '=', $data['product_specs']]; //规格
  123. $source_where[] = ['scrape_date', '=', $data['scrape_date']]; //采集日期
  124. $source_id_log = $this->where($source_where)->select(['id', 'online_posting_price'])->first();
  125. if (!empty($source_id_log)) {
  126. if ($source_id_log->online_posting_price > $data['online_posting_price']) {
  127. $snapshot_url= isset($data['snapshot_url']) ? $data['snapshot_url'] : ''; // 商品快照地址
  128. $this->where('id', $source_id_log->id)->update(['online_posting_price' => $data['online_posting_price'], 'source_id' => $data['source_id'],'snapshot_url' => $snapshot_url,'update_time'=>time()]);
  129. }
  130. return true;
  131. }
  132. }
  133. DB::beginTransaction();
  134. try {
  135. //执行挂网数据统计
  136. $data = $this->handleCountData($data);
  137. $LowPriceGoodsMemberModel = new LowPriceGoodsMemberModel();
  138. $insert_data = [
  139. 'company_id' => $data['company_id'],
  140. 'source_id' => $data['source_id'],
  141. 'first_responsible_person' => $data['first_responsible_person'] ? ',' . $data['first_responsible_person'] . ',' : '',
  142. 'responsible_person' => $data['responsible_person'] ? ',' . $data['responsible_person'] . ',' : '',
  143. 'platform' => $data['platform'],
  144. 'company_name' => $data['company_name'],
  145. 'product_brand' => isset($data['product_brand']) ? $data['product_brand'] : '',
  146. 'product_name' => $data['product_name'],
  147. 'product_specs' => $data['product_specs'],
  148. 'suggested_price' => $data['suggested_price'],
  149. 'ultra_low_price' => $data['ultra_low_price'],
  150. 'is_ultra_low_price' => $data['is_ultra_low_price'],
  151. 'online_posting_price' => $data['online_posting_price'],
  152. 'online_posting_count' => isset($data['online_posting_count']) && is_numeric($data['online_posting_count']) ? $data['online_posting_count'] : 1,
  153. 'continuous_listing_count' => isset($data['continuous_listing_count']) && is_numeric($data['continuous_listing_count']) ? $data['continuous_listing_count'] : 1,
  154. 'social_credit_code' => $data['social_credit_code'],
  155. 'province_id' => $data['province_id'],
  156. 'province_name' => $data['province_name'],
  157. 'city_id' => $data['city_id'],
  158. 'city_name' => $data['city_name'],
  159. 'area_info' => $data['area_info'],
  160. 'link_url' => $data['link_url'],
  161. 'store_name' => $data['store_name'],
  162. 'anonymous_store_name' => isset($data['anonymous_store_name']) ? $data['anonymous_store_name'] : '',
  163. 'source_responsible_person' => $data['source_responsible_person'] ? ',' . $data['source_responsible_person'] . ',' : '',
  164. 'category_name' => $data['category_name'],
  165. 'company_category_name' => $data['company_category_name'],
  166. 'processing_status' => '1',
  167. 'insert_time' => time(),
  168. 'scrape_date' => isset($data['scrape_date']) ? $data['scrape_date'] : '',
  169. 'collection_time' => isset($data['collection_time']) ? $data['collection_time'] : '',
  170. 'shipment_province_id' => isset($data['shipment_province_id']) ? $data['shipment_province_id'] : '0', // 发货省份id
  171. 'shipment_province_name' => isset($data['shipment_province_name']) ? $data['shipment_province_name'] : '', // 发货省份
  172. 'shipment_city_id' => isset($data['shipment_city_id']) ? $data['shipment_city_id'] : '0', // 发货城市id
  173. 'shipment_city_name' => isset($data['shipment_city_name']) ? $data['shipment_city_name'] : '', // 发货城市
  174. 'merge_city_id' => $data['merge_city_id'],
  175. 'merge_province_id' => $data['merge_province_id'],
  176. 'merge_city_name' => $data['merge_city_name'],
  177. 'merge_province_name' => $data['merge_province_name'],
  178. 'snapshot_url' => isset($data['snapshot_url']) ? $data['snapshot_url'] : '', // 商品快照地址
  179. 'specify_responsible_person' => isset($data['specify_responsible_person']) ? $data['specify_responsible_person'] : '1', // 指派责任人 0=开启 1=关闭
  180. ];
  181. $LowPriceGoods_id = $this->insertGetId($insert_data);
  182. $first_responsible_persons = $data['first_responsible_person'] != '' ? explode(',', $data['first_responsible_person']) : [];
  183. $first_responsible_person_data = [];
  184. if (count($first_responsible_persons) > 0) {
  185. foreach ($first_responsible_persons as $key => $employee_id) {
  186. //如果不是数字或者为空,则跳过
  187. if ($employee_id == '' || is_null($employee_id) || !is_numeric($employee_id)) continue;
  188. $first_responsible_person_data[] = [
  189. 'lowprice_product_logid' => $LowPriceGoods_id,
  190. 'employee_id' => $employee_id,
  191. 'duty_type' => 1, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  192. ];
  193. }
  194. }
  195. $LowPriceGoodsMemberModel->insert($first_responsible_person_data);
  196. $responsible_persons = $data['responsible_person'] != '' ? explode(',', $data['responsible_person']) : [];
  197. $responsible_person_data = [];
  198. if (count($responsible_persons) > 0) {
  199. foreach ($responsible_persons as $key => $employee_id) {
  200. //如果不是数字或者为空,则跳过
  201. if ($employee_id == '' || is_null($employee_id) || !is_numeric($employee_id)) continue;
  202. $responsible_person_data[] = [
  203. 'lowprice_product_logid' => $LowPriceGoods_id,
  204. 'employee_id' => $employee_id,
  205. 'duty_type' => 2, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  206. ];
  207. }
  208. }
  209. $LowPriceGoodsMemberModel->insert($responsible_person_data);
  210. $source_responsible_persons = $data['source_responsible_person'] != '' ? explode(',', $data['source_responsible_person']) : [];
  211. $source_responsible_person_data = [];
  212. if (count($source_responsible_persons) > 0) {
  213. foreach ($source_responsible_persons as $key => $employee_id) {
  214. //如果不是数字或者为空,则跳过
  215. if ($employee_id == '' || is_null($employee_id) || !is_numeric($employee_id)) continue;
  216. $source_responsible_person_data[] = [
  217. 'lowprice_product_logid' => $LowPriceGoods_id,
  218. 'employee_id' => $employee_id,
  219. 'duty_type' => 3, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  220. ];
  221. }
  222. }
  223. $LowPriceGoodsMemberModel->insert($source_responsible_person_data);
  224. //添加通知
  225. // $this->addNotices($insert_data, $LowPriceGoods_id);
  226. DB::commit();
  227. return true;
  228. // 成功处理...
  229. } catch (\Exception $e) {
  230. DB::rollBack();
  231. Log::info('job_error', '数据清洗-新增低价商品处理记录失败', ['data' => $data, 'error' => $e->getMessage()]);
  232. // 错误处理...
  233. return false;
  234. }
  235. }
  236. function getLastSamplingInfo($currentWeek, $samplingCycle)
  237. {
  238. // 获取所有小于当前星期的配置
  239. $previousWeeks = array_filter($samplingCycle, function ($week) use ($currentWeek) {
  240. return $week < $currentWeek;
  241. });
  242. if (!empty($previousWeeks)) {
  243. // 存在小于当前星期的配置,取最大值
  244. $lastWeek = max($previousWeeks);
  245. $daysToSubtract = $currentWeek - $lastWeek;
  246. } else {
  247. // 不存在(当前是最小的),取最大的配置星期(跨周)
  248. $lastWeek = max($samplingCycle);
  249. $daysToSubtract = $currentWeek + (7 - $lastWeek);
  250. }
  251. return [
  252. 'last_week' => $lastWeek,
  253. 'days_to_subtract' => $daysToSubtract
  254. ];
  255. }
  256. /**
  257. * 处理连续挂网&累计挂网数据统计
  258. * @author 唐远望
  259. * @version 1.0
  260. * @date 2026-05-07
  261. *
  262. */
  263. public function handleCountData($product_data_info)
  264. {
  265. $collect_config_info = isset($product_data_info['collect_config_info']) ? $product_data_info['collect_config_info'] : ''; //采集配置信息
  266. if (trim($collect_config_info) == '') return $product_data_info;
  267. $collect_config_info = json_decode($collect_config_info, true); //{"sampling_cycle": "", "sampling_start_time": "", "sampling_end_time": ""}
  268. //采集周期
  269. $sampling_cycle = isset($collect_config_info['sampling_cycle']) ? explode(',', $collect_config_info['sampling_cycle']) : '';
  270. //采集开始时间
  271. $sampling_start_time = isset($collect_config_info['sampling_start_time']) ? $collect_config_info['sampling_start_time'] : '';
  272. //采集结束时间
  273. $sampling_end_time = isset($collect_config_info['sampling_end_time']) ? $collect_config_info['sampling_end_time'] : '';
  274. if (!is_array($sampling_cycle)) return $product_data_info;
  275. $current_time = $product_data_info['collection_time'];
  276. //如果当前时间在采集开始时间结束时间范围内,则进行连续挂网和累计挂网统计
  277. if ($sampling_start_time != '' && $sampling_end_time != '' && $current_time >= $sampling_start_time && $current_time <= $sampling_end_time) {
  278. // 获取采集时间是星期几
  279. $now_week = date('w', $current_time);
  280. if ($now_week == 0) {
  281. $now_week = 7;
  282. }
  283. if (!in_array($now_week, $sampling_cycle)) {
  284. return $product_data_info;
  285. }
  286. //排序$sampling_cycle从小到大
  287. sort($sampling_cycle);
  288. // 使用
  289. $result = $this->getLastSamplingInfo($now_week, $sampling_cycle);
  290. $days_to_subtract = isset($result['days_to_subtract']) ? $result['days_to_subtract'] : 0;
  291. // echo "往前推 {$result['days_to_subtract']} 天";
  292. //查询当前商品是否在上一个周期采集中过
  293. $up_scrape_date_time = $current_time - $days_to_subtract * 24 * 3600; //查询上周这个时间点
  294. $up_scrape_date = date('Y-m-d', $up_scrape_date_time);
  295. $source_last_week_where[] = ['company_id', '=', $product_data_info['company_id']]; //品牌方公司ID
  296. $source_last_week_where[] = ['platform', '=', $product_data_info['platform']]; //挂网平台ID
  297. $source_last_week_where[] = ['company_name', '=', $product_data_info['company_name']]; //店铺公司名称
  298. $source_last_week_where[] = ['store_name', '=', $product_data_info['store_name']]; //店铺名称
  299. $source_last_week_where[] = ['product_brand', '=', $product_data_info['product_brand']]; //品牌名称
  300. $source_last_week_where[] = ['product_name', '=', $product_data_info['product_name']]; //商品名称
  301. $source_last_week_where[] = ['product_specs', '=', $product_data_info['product_specs']]; //规格
  302. $source_last_week_where[] = ['scrape_date', '=', $up_scrape_date]; //上个周期采集日期
  303. $source_last_week_log = $this->where($source_last_week_where)->count();
  304. if ($source_last_week_log > 0) {
  305. $product_data_info['continuous_listing_count'] = $product_data_info['continuous_listing_count'] + 1; //连续挂网次数+1
  306. }
  307. //查询当前商品上次连续挂网次数
  308. $source_last_time_where[] = ['company_id', '=', $product_data_info['company_id']]; //品牌方公司ID
  309. $source_last_time_where[] = ['platform', '=', $product_data_info['platform']]; //挂网平台ID
  310. $source_last_time_where[] = ['company_name', '=', $product_data_info['company_name']]; //店铺公司名称
  311. $source_last_time_where[] = ['store_name', '=', $product_data_info['store_name']]; //店铺名称
  312. $source_last_time_where[] = ['product_brand', '=', $product_data_info['product_brand']]; //品牌名称
  313. $source_last_time_where[] = ['product_name', '=', $product_data_info['product_name']]; //商品名称
  314. $source_last_time_where[] = ['product_specs', '=', $product_data_info['product_specs']]; //规格
  315. $source_last_time_log = $this->where($source_last_time_where)->orderbyDesc('scrape_date')->first();
  316. if (!empty($source_last_time_log)) {
  317. $product_data_info['online_posting_count'] = $source_last_time_log->online_posting_count + 1; //累计挂网次数+1
  318. }
  319. } else if ($sampling_start_time != '' && $sampling_end_time == '0' && $current_time >= $sampling_start_time) {
  320. //如果当前时间在采集开始时间结束时间未设置,则进行连续挂网和累计挂网统计
  321. // 获取采集时间是星期几
  322. $collection_time = strtotime($product_data_info['collection_time']);
  323. $now_week = date('w', $collection_time);
  324. if ($now_week == 0) {
  325. $now_week = 7;
  326. }
  327. if (!in_array($now_week, $sampling_cycle)) {
  328. return $product_data_info;
  329. }
  330. //排序$sampling_cycle从小到大
  331. sort($sampling_cycle);
  332. // 使用
  333. $result = $this->getLastSamplingInfo($now_week, $sampling_cycle);
  334. $days_to_subtract = isset($result['days_to_subtract']) ? $result['days_to_subtract'] : 0;
  335. $up_scrape_date_time = $collection_time - $days_to_subtract * 24 * 3600; //查询上周这个时间点
  336. //查询当前商品上次采集记录
  337. $up_scrape_date = date('Y-m-d', $up_scrape_date_time);
  338. $source_last_week_where[] = ['company_id', '=', $product_data_info['company_id']]; //品牌方公司ID
  339. $source_last_week_where[] = ['platform', '=', $product_data_info['platform']]; //挂网平台ID
  340. $source_last_week_where[] = ['company_name', '=', $product_data_info['company_name']]; //店铺公司名称
  341. $source_last_week_where[] = ['store_name', '=', $product_data_info['store_name']]; //店铺名称
  342. $source_last_week_where[] = ['product_brand', '=', $product_data_info['product_brand']]; //品牌名称
  343. $source_last_week_where[] = ['product_name', '=', $product_data_info['product_name']]; //商品名称
  344. $source_last_week_where[] = ['product_specs', '=', $product_data_info['product_specs']]; //规格
  345. $source_last_week_where[] = ['scrape_date', '=', $up_scrape_date]; //上个周期采集日期
  346. $source_last_week_log = $this->where($source_last_week_where)->count();
  347. if ($source_last_week_log > 0) {
  348. $product_data_info['continuous_listing_count'] = $product_data_info['continuous_listing_count'] + 1; //连续挂网次数+1
  349. }
  350. //查询当前商品上次连续挂网次数
  351. $source_last_time_where[] = ['company_id', '=', $product_data_info['company_id']]; //品牌方公司ID
  352. $source_last_time_where[] = ['platform', '=', $product_data_info['platform']]; //挂网平台ID
  353. $source_last_time_where[] = ['company_name', '=', $product_data_info['company_name']]; //店铺公司名称
  354. $source_last_time_where[] = ['store_name', '=', $product_data_info['store_name']]; //店铺名称
  355. $source_last_time_where[] = ['product_brand', '=', $product_data_info['product_brand']]; //品牌名称
  356. $source_last_time_where[] = ['product_name', '=', $product_data_info['product_name']]; //商品名称
  357. $source_last_time_where[] = ['product_specs', '=', $product_data_info['product_specs']]; //规格
  358. $source_last_time_log = $this->where($source_last_time_where)->orderbyDesc('scrape_date')->first();
  359. if (!empty($source_last_time_log)) {
  360. $product_data_info['online_posting_count'] = $source_last_time_log->online_posting_count + 1; //累计挂网次数+1
  361. }
  362. }
  363. return $product_data_info;
  364. }
  365. /**
  366. * 处理通知消息
  367. * @author 唐远望
  368. * @version 1.0
  369. * @date 2026-03-21
  370. * @param $data
  371. * @return bool
  372. */
  373. public function addNotices($low_price_data, $data_logid)
  374. {
  375. //添加通知
  376. $NoticesModel = new NoticesModel();
  377. $EmployeeModel = new EmployeeModel();
  378. $notices_data = [];
  379. if ($low_price_data['first_responsible_person'] != '' && $low_price_data['responsible_person'] != '') {
  380. //合并数据并去重
  381. $first_responsible_persons = array_unique(explode(',', $low_price_data['first_responsible_person']));
  382. $responsible_persons = array_unique(explode(',', $low_price_data['responsible_person']));
  383. $all_persons = array_merge($first_responsible_persons, $responsible_persons);
  384. //查询已已经开启通知设置的用户
  385. $employee_ids = $EmployeeModel->whereIn('id', $all_persons)->where('open_notice', 0)->pluck('id')->toArray();
  386. if (count($employee_ids) == 0) return true;
  387. foreach ($employee_ids as $key => $employee_id) {
  388. if ($employee_id == '' || is_null($employee_id)) continue;
  389. $notices_data[] = [
  390. 'company_id' => $low_price_data['company_id'],
  391. 'custom_uid' => $employee_id,
  392. 'title' => '您有一条新的低价商品待处理,请及时查看。',
  393. 'content_type' => '1', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  394. 'data_logid' => $data_logid,
  395. 'insert_time' => time()
  396. ];
  397. }
  398. $NoticesModel->insert($notices_data);
  399. } else if ($low_price_data['first_responsible_person'] != '') {
  400. $first_responsible_persons = array_unique(explode(',', $low_price_data['first_responsible_person']));
  401. //查询已已经开启通知设置的用户
  402. $employee_ids = $EmployeeModel->whereIn('id', $first_responsible_persons)->where('open_notice', 0)->pluck('id')->toArray();
  403. if (count($employee_ids) == 0) return true;
  404. foreach ($employee_ids as $key => $employee_id) {
  405. if ($employee_id == '' || is_null($employee_id)) continue;
  406. $notices_data[] = [
  407. 'company_id' => $low_price_data['company_id'],
  408. 'custom_uid' => $employee_id,
  409. 'title' => '您有一条新的低价商品待处理,请及时查看。',
  410. 'content_type' => '1', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  411. 'data_logid' => $data_logid,
  412. 'insert_time' => time()
  413. ];
  414. }
  415. $NoticesModel->insert($notices_data);
  416. } else if ($low_price_data['responsible_person'] != '') {
  417. $responsible_persons = array_unique(explode(',', $low_price_data['responsible_person']));
  418. //查询已已经开启通知设置的用户
  419. $employee_ids = $EmployeeModel->whereIn('id', $responsible_persons)->where('open_notice', 0)->pluck('id')->toArray();
  420. if (count($employee_ids) == 0) return true;
  421. foreach ($employee_ids as $key => $employee_id) {
  422. if ($employee_id == '' || is_null($employee_id)) continue;
  423. $notices_data[] = [
  424. 'company_id' => $low_price_data['company_id'],
  425. 'custom_uid' => $employee_id,
  426. 'title' => '您有一条新的低价商品待处理,请及时查看。',
  427. 'content_type' => '1', //内容类型1=低价挂网2=禁止挂网3=违规店铺
  428. 'data_logid' => $data_logid,
  429. 'insert_time' => time()
  430. ];
  431. }
  432. $NoticesModel->insert($notices_data);
  433. }
  434. return true;
  435. }
  436. /**
  437. * 编辑内容
  438. * @author 唐远望
  439. * @version 1.0
  440. * @date 2025-12-08
  441. * @param $data
  442. * @return bool
  443. */
  444. public function editLowPriceGoods_content($where, $data)
  445. {
  446. $LowPriceGoods = $this->where($where)->first();
  447. if (!$LowPriceGoods) {
  448. return false;
  449. }
  450. $LowPriceGoods->company_id = $data['company_id'];
  451. $LowPriceGoods->first_responsible_person = $data['first_responsible_person'];
  452. $LowPriceGoods->responsible_person = $data['responsible_person'];
  453. $LowPriceGoods->platform = $data['platform'];
  454. $LowPriceGoods->company_name = $data['company_name'];
  455. $LowPriceGoods->product_name = $data['product_name'];
  456. $LowPriceGoods->product_specs = $data['product_specs'];
  457. $LowPriceGoods->suggested_price = $data['suggested_price'];
  458. $LowPriceGoods->online_posting_price = $data['online_posting_price'];
  459. $LowPriceGoods->online_posting_count = $data['online_posting_count'];
  460. $LowPriceGoods->link_url = $data['link_url'];
  461. $LowPriceGoods->store_name = $data['store_name'];
  462. $LowPriceGoods->source_responsible_person = $data['source_responsible_person'];
  463. $LowPriceGoods->update_time = time();
  464. $LowPriceGoods->save();
  465. return true;
  466. }
  467. /**
  468. * 更新数据
  469. * @author 唐远望
  470. * @version 1.0
  471. * @date 2025-12-08
  472. * @param $data
  473. * @return bool
  474. */
  475. public function updateLowPriceGoods($where, $data)
  476. {
  477. DB::beginTransaction();
  478. try {
  479. $this->editLowPriceGoods_content($where, $data);
  480. DB::commit();
  481. return true;
  482. // 成功处理...
  483. } catch (\Exception $e) {
  484. DB::rollBack();
  485. // 错误处理...
  486. return false;
  487. }
  488. }
  489. /**
  490. * 修改状态
  491. * @author 唐远望
  492. * @version 1.0
  493. * @date 2025-12-08
  494. * @param $id
  495. * @param $status
  496. * @return bool
  497. */
  498. public function changeStatus($where, $status)
  499. {
  500. $LowPriceGoods = $this->where($where)->first();
  501. if (!$LowPriceGoods) {
  502. return false;
  503. }
  504. $LowPriceGoods->status = $status;
  505. $LowPriceGoods->update_time = time();
  506. $LowPriceGoods->save();
  507. return true;
  508. }
  509. /**
  510. * 修改处理状态
  511. * @author 唐远望
  512. * @version 1.0
  513. * @date 2025-12-08
  514. * @param $id
  515. * @param $processing_status
  516. * @return bool
  517. */
  518. public function changeProcessingStatus($where, $processing_status)
  519. {
  520. $LowPriceGoods = $this->where($where)->first();
  521. if (!$LowPriceGoods) {
  522. return false;
  523. }
  524. $LowPriceGoods->processing_status = $processing_status;
  525. $LowPriceGoods->update_time = time();
  526. $LowPriceGoods->save();
  527. return true;
  528. }
  529. /**
  530. * 删除数据
  531. * @author 唐远望
  532. * @version 1.0
  533. * @date 2025-12-08
  534. * @param $id
  535. * @return bool
  536. */
  537. public function deleteLowPriceGoods($where)
  538. {
  539. $LowPriceGoods = $this->where($where)->first();
  540. if (!$LowPriceGoods) {
  541. return false;
  542. }
  543. $LowPriceGoods->delete();
  544. return true;
  545. }
  546. }