ViolationProduct.php 9.3 KB

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