ViolationProduct.php 10.0 KB

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