ViolationProduct.php 10 KB

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