ViolationProduct.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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\ViolationProductMember as ViolationProductMemberModel;
  7. use App\Facades\Servers\Logs\Log;
  8. /**
  9. * 违规处理-违规商品模型
  10. * @author: 唐远望
  11. * @version: 1.0
  12. * @date: 2025-12-08
  13. */
  14. class ViolationProduct extends Model
  15. {
  16. use HasFactory;
  17. // 与模型关联的表名
  18. protected $table = 'process_violation_product';
  19. // 是否主动维护时间戳
  20. public $timestamps = false;
  21. // 定义时间戳字段名
  22. // const CREATED_AT = 'insert_time';
  23. // const UPDATED_AT = 'update_time';
  24. /**
  25. * 平台定义
  26. * @author 唐远望
  27. * @version 1.0
  28. * @date 2025-12-31
  29. */
  30. public function platform_data()
  31. {
  32. $platform_data = [
  33. '全部' => '0',
  34. '淘宝' => '1',
  35. '京东' => '2',
  36. '拼多多' => '3',
  37. '美团' => '4',
  38. '药师帮' => '5',
  39. '1药城' => '6',
  40. '药久久' => '7',
  41. ];
  42. return $platform_data;
  43. }
  44. /**
  45. * 添加
  46. * @author 唐远望
  47. * @version 1.0
  48. * @date 2025-12-08
  49. */
  50. public function addViolationProduct_content($data)
  51. {
  52. $insert_data = [
  53. 'company_id' => $data['company_id'],
  54. 'source_id' => $data['source_id'],
  55. 'first_responsible_person' => $data['first_responsible_person'],
  56. 'responsible_person' => $data['responsible_person'],
  57. 'platform' => $data['platform'],
  58. 'company_name' => $data['company_name'],
  59. 'product_name' => $data['product_name'],
  60. 'product_specs' => $data['product_specs'],
  61. 'online_posting_price' => isset($data['online_posting_price']) ? $data['online_posting_price'] : 1,
  62. 'online_posting_count' => isset($data['online_posting_count']) ? $data['online_posting_count'] : 1,
  63. 'link_url' => $data['link_url'],
  64. 'store_name' => $data['store_name'],
  65. 'source_responsible_person' => $data['source_responsible_person'],
  66. 'processing_status' => '1',
  67. 'insert_time' => time(),
  68. ];
  69. $ViolationProduct_id = $this->insertGetId($insert_data);
  70. return $ViolationProduct_id;
  71. }
  72. /**
  73. * 写入数据
  74. * @author 唐远望
  75. * @version 1.0
  76. * @date 2025-12-08
  77. * @param $data
  78. * @return bool
  79. */
  80. public function addViolationProduct($data, $is_import = false)
  81. {
  82. if ($is_import == false) {
  83. $source_where[] = ['company_id', '=', $data['company_id']];
  84. $source_where[] = ['source_id', '=', $data['source_id']];
  85. $source_where[] = ['product_name', '=', $data['product_name']];
  86. $source_where[] = ['product_specs', '=', $data['product_specs']];
  87. $source_id_log = $this->where($source_where)->count();
  88. if ($source_id_log > 0) {
  89. return true;
  90. }
  91. }
  92. DB::beginTransaction();
  93. try {
  94. $ViolationProductMemberModel = new ViolationProductMemberModel();
  95. $insert_data = [
  96. 'company_id' => $data['company_id'],
  97. 'source_id' => $data['source_id'],
  98. 'first_responsible_person' => $data['first_responsible_person'] ? ',' . $data['first_responsible_person'] . ',' : '',
  99. 'responsible_person' => $data['responsible_person'] ? ',' . $data['responsible_person'] . ',' : '',
  100. 'platform' => $data['platform'],
  101. 'company_name' => $data['company_name'],
  102. 'product_name' => $data['product_name'],
  103. 'product_specs' => $data['product_specs'],
  104. 'online_posting_price' => isset($data['online_posting_price']) ? $data['online_posting_price'] : 1,
  105. 'online_posting_count' => isset($data['online_posting_count']) ? $data['online_posting_count'] : 1,
  106. 'social_credit_code' => $data['social_credit_code'],
  107. 'province_id' => $data['province_id'],
  108. 'province_name' => $data['province_name'],
  109. 'city_id' => $data['city_id'],
  110. 'city_name' => $data['city_name'],
  111. 'area_info' => $data['area_info'],
  112. 'link_url' => $data['link_url'],
  113. 'store_name' => $data['store_name'],
  114. 'source_responsible_person' => $data['source_responsible_person'] ? ',' . $data['source_responsible_person'] . ',' : '',
  115. 'category_name' => $data['category_name'],
  116. 'company_category_name' => $data['company_category_name'],
  117. 'processing_status' => '1',
  118. 'insert_time' => time(),
  119. ];
  120. $ViolationProduct_id = $this->insertGetId($insert_data);
  121. $first_responsible_persons = $data['first_responsible_person'] != '' ? explode(',', $data['first_responsible_person']) : [];
  122. $first_responsible_person_data = [];
  123. if (count($first_responsible_persons) > 0) {
  124. foreach ($first_responsible_persons as $key => $employee_id) {
  125. $first_responsible_person_data[] = [
  126. 'violation_product_logid' => $ViolationProduct_id,
  127. 'employee_id' => $employee_id,
  128. 'duty_type' => 1, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  129. ];
  130. }
  131. }
  132. $ViolationProductMemberModel->insert($first_responsible_person_data);
  133. $responsible_persons = $data['responsible_person'] != '' ? explode(',', $data['responsible_person']) : [];
  134. $responsible_person_data = [];
  135. if (count($responsible_persons) > 0) {
  136. foreach ($responsible_persons as $key => $employee_id) {
  137. $responsible_person_data[] = [
  138. 'violation_product_logid' => $ViolationProduct_id,
  139. 'employee_id' => $employee_id,
  140. 'duty_type' => 2, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  141. ];
  142. }
  143. }
  144. $ViolationProductMemberModel->insert($responsible_person_data);
  145. $source_responsible_persons = $data['source_responsible_person'] != '' ? explode(',', $data['source_responsible_person']) : [];
  146. $source_responsible_person_data = [];
  147. if (count($source_responsible_persons) > 0) {
  148. foreach ($source_responsible_persons as $key => $employee_id) {
  149. $source_responsible_person_data[] = [
  150. 'violation_product_logid' => $ViolationProduct_id,
  151. 'employee_id' => $employee_id,
  152. 'duty_type' => 3, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  153. ];
  154. }
  155. }
  156. $ViolationProductMemberModel->insert($source_responsible_person_data);
  157. DB::commit();
  158. return true;
  159. // 成功处理...
  160. } catch (\Exception $e) {
  161. DB::rollBack();
  162. // 错误处理...
  163. Log::info('job_error', '数据清洗-新增违规商品处理记录失败', ['data' => $data, 'error' => $e->getMessage()]);
  164. return false;
  165. }
  166. }
  167. /**
  168. * 编辑内容
  169. * @author 唐远望
  170. * @version 1.0
  171. * @date 2025-12-08
  172. * @param $data
  173. * @return bool
  174. */
  175. public function editViolationProduct_content($where, $data)
  176. {
  177. $ViolationProduct = $this->where($where)->first();
  178. if (!$ViolationProduct) {
  179. return false;
  180. }
  181. $ViolationProduct->company_id = $data['company_id'];
  182. $ViolationProduct->first_responsible_person = $data['first_responsible_person'];
  183. $ViolationProduct->responsible_person = $data['responsible_person'];
  184. $ViolationProduct->platform = $data['platform'];
  185. $ViolationProduct->company_name = $data['company_name'];
  186. $ViolationProduct->product_name = $data['product_name'];
  187. $ViolationProduct->product_specs = $data['product_specs'];
  188. $ViolationProduct->online_posting_count = $data['online_posting_count'];
  189. $ViolationProduct->link_url = $data['link_url'];
  190. $ViolationProduct->store_name = $data['store_name'];
  191. $ViolationProduct->source_responsible_person = $data['source_responsible_person'];
  192. $ViolationProduct->update_time = time();
  193. $ViolationProduct->save();
  194. return true;
  195. }
  196. /**
  197. * 更新数据
  198. * @author 唐远望
  199. * @version 1.0
  200. * @date 2025-12-08
  201. * @param $data
  202. * @return bool
  203. */
  204. public function updateViolationProduct($where, $data)
  205. {
  206. DB::beginTransaction();
  207. try {
  208. $this->editViolationProduct_content($where, $data);
  209. DB::commit();
  210. return true;
  211. // 成功处理...
  212. } catch (\Exception $e) {
  213. DB::rollBack();
  214. // 错误处理...
  215. return false;
  216. }
  217. }
  218. /**
  219. * 修改状态
  220. * @author 唐远望
  221. * @version 1.0
  222. * @date 2025-12-08
  223. * @param $id
  224. * @param $status
  225. * @return bool
  226. */
  227. public function changeStatus($where, $status)
  228. {
  229. $ViolationProduct = $this->where($where)->first();
  230. if (!$ViolationProduct) {
  231. return false;
  232. }
  233. $ViolationProduct->status = $status;
  234. $ViolationProduct->update_time = time();
  235. $ViolationProduct->save();
  236. return true;
  237. }
  238. /**
  239. * 修改处理状态
  240. * @author 唐远望
  241. * @version 1.0
  242. * @date 2025-12-08
  243. * @param $id
  244. * @param $processing_status
  245. * @return bool
  246. */
  247. public function changeProcessingStatus($where, $processing_status)
  248. {
  249. $ViolationProduct = $this->where($where)->first();
  250. if (!$ViolationProduct) {
  251. return false;
  252. }
  253. $ViolationProduct->processing_status = $processing_status;
  254. $ViolationProduct->update_time = time();
  255. $ViolationProduct->save();
  256. return true;
  257. }
  258. /**
  259. * 删除数据
  260. * @author 唐远望
  261. * @version 1.0
  262. * @date 2025-12-08
  263. * @param $id
  264. * @return bool
  265. */
  266. public function deleteViolationProduct($where)
  267. {
  268. $ViolationProduct = $this->where($where)->first();
  269. if (!$ViolationProduct) {
  270. return false;
  271. }
  272. $ViolationProduct->delete();
  273. return true;
  274. }
  275. }