ViolationProduct.php 11 KB

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