ViolationProduct.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. /**
  8. * 违规处理-违规商品模型
  9. * @author: 唐远望
  10. * @version: 1.0
  11. * @date: 2025-12-08
  12. */
  13. class ViolationProduct extends Model
  14. {
  15. use HasFactory;
  16. // 与模型关联的表名
  17. protected $table = 'process_violation_product';
  18. // 是否主动维护时间戳
  19. public $timestamps = false;
  20. // 定义时间戳字段名
  21. // const CREATED_AT = 'insert_time';
  22. // const UPDATED_AT = 'update_time';
  23. /**
  24. * 添加
  25. * @author 唐远望
  26. * @version 1.0
  27. * @date 2025-12-08
  28. */
  29. public function addViolationProduct_content($data)
  30. {
  31. $insert_data = [
  32. 'first_responsible_person' => $data['first_responsible_person'],
  33. 'responsible_person' => $data['responsible_person'],
  34. 'platform' => $data['platform'],
  35. 'company_name' => $data['company_name'],
  36. 'product_name' => $data['product_name'],
  37. 'product_specs' => $data['product_specs'],
  38. 'online_posting_cunt' => $data['online_posting_cunt'],
  39. 'link_url' => $data['link_url'],
  40. 'store_name' => $data['store_name'],
  41. 'source_responsible_person' => $data['source_responsible_person'],
  42. 'processing_status' => '1',
  43. 'insert_time' => time(),
  44. ];
  45. $ViolationProduct_id = $this->insertGetId($insert_data);
  46. return $ViolationProduct_id;
  47. }
  48. /**
  49. * 写入数据
  50. * @author 唐远望
  51. * @version 1.0
  52. * @date 2025-12-08
  53. * @param $data
  54. * @return bool
  55. */
  56. public function addViolationProduct($data)
  57. {
  58. DB::beginTransaction();
  59. try {
  60. $ViolationProductMemberModel = new ViolationProductMemberModel();
  61. $insert_data = [
  62. 'first_responsible_person' => $data['first_responsible_person'],
  63. 'responsible_person' => $data['responsible_person'],
  64. 'platform' => $data['platform'],
  65. 'company_name' => $data['company_name'],
  66. 'product_name' => $data['product_name'],
  67. 'product_specs' => $data['product_specs'],
  68. 'online_posting_cunt' => $data['online_posting_cunt'],
  69. 'link_url' => $data['link_url'],
  70. 'store_name' => $data['store_name'],
  71. 'source_responsible_person' => $data['source_responsible_person'],
  72. 'processing_status' => '1',
  73. 'insert_time' => time(),
  74. ];
  75. $ViolationProduct_id = $this->insertGetId($insert_data);
  76. $first_responsible_persons = explode(',', $data['first_responsible_person']);
  77. $first_responsible_person_data = [];
  78. if (count($first_responsible_persons) > 0) {
  79. foreach ($first_responsible_persons as $key => $employee_id) {
  80. $first_responsible_person_data[] = [
  81. 'violation_product_logid' => $ViolationProduct_id,
  82. 'employee_id' => $employee_id,
  83. 'duty_type' => 1, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  84. ];
  85. }
  86. }
  87. $ViolationProductMemberModel->inser($first_responsible_person_data);
  88. $responsible_persons = explode(',', $data['responsible_person']);
  89. $responsible_person_data = [];
  90. if (count($responsible_persons) > 0) {
  91. foreach ($responsible_persons as $key => $employee_id) {
  92. $responsible_person_data[] = [
  93. 'violation_product_logid' => $ViolationProduct_id,
  94. 'employee_id' => $employee_id,
  95. 'duty_type' => 2, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  96. ];
  97. }
  98. }
  99. $ViolationProductMemberModel->inser($responsible_person_data);
  100. $source_responsible_persons = explode(',', $data['source_responsible_person']);
  101. $source_responsible_person_data = [];
  102. if (count($source_responsible_persons) > 0) {
  103. foreach ($source_responsible_persons as $key => $employee_id) {
  104. $source_responsible_person_data[] = [
  105. 'violation_product_logid' => $ViolationProduct_id,
  106. 'employee_id' => $employee_id,
  107. 'duty_type' => 3, //责任类型1=第一责任人,2=责任人,3=溯源责任人
  108. ];
  109. }
  110. }
  111. $ViolationProductMemberModel->inser($source_responsible_person_data);
  112. DB::commit();
  113. return true;
  114. // 成功处理...
  115. } catch (\Exception $e) {
  116. DB::rollBack();
  117. // 错误处理...
  118. return false;
  119. }
  120. }
  121. /**
  122. * 编辑内容
  123. * @author 唐远望
  124. * @version 1.0
  125. * @date 2025-12-08
  126. * @param $data
  127. * @return bool
  128. */
  129. public function editViolationProduct_content($where, $data)
  130. {
  131. $ViolationProduct = $this->where($where)->first();
  132. if (!$ViolationProduct) {
  133. return false;
  134. }
  135. $ViolationProduct->first_responsible_person = $data['first_responsible_person'];
  136. $ViolationProduct->responsible_person = $data['responsible_person'];
  137. $ViolationProduct->platform = $data['platform'];
  138. $ViolationProduct->company_name = $data['company_name'];
  139. $ViolationProduct->product_name = $data['product_name'];
  140. $ViolationProduct->product_specs = $data['product_specs'];
  141. $ViolationProduct->online_posting_cunt = $data['online_posting_cunt'];
  142. $ViolationProduct->link_url = $data['link_url'];
  143. $ViolationProduct->store_name = $data['store_name'];
  144. $ViolationProduct->source_responsible_person = $data['source_responsible_person'];
  145. $ViolationProduct->update_time = time();
  146. $ViolationProduct->save();
  147. return true;
  148. }
  149. /**
  150. * 更新数据
  151. * @author 唐远望
  152. * @version 1.0
  153. * @date 2025-12-08
  154. * @param $data
  155. * @return bool
  156. */
  157. public function updateViolationProduct($where, $data)
  158. {
  159. DB::beginTransaction();
  160. try {
  161. $this->editViolationProduct_content($where, $data);
  162. DB::commit();
  163. return true;
  164. // 成功处理...
  165. } catch (\Exception $e) {
  166. DB::rollBack();
  167. // 错误处理...
  168. return false;
  169. }
  170. }
  171. /**
  172. * 修改状态
  173. * @author 唐远望
  174. * @version 1.0
  175. * @date 2025-12-08
  176. * @param $id
  177. * @param $status
  178. * @return bool
  179. */
  180. public function changeStatus($where, $status)
  181. {
  182. $ViolationProduct = $this->where($where)->first();
  183. if (!$ViolationProduct) {
  184. return false;
  185. }
  186. $ViolationProduct->status = $status;
  187. $ViolationProduct->update_time = time();
  188. $ViolationProduct->save();
  189. return true;
  190. }
  191. /**
  192. * 修改处理状态
  193. * @author 唐远望
  194. * @version 1.0
  195. * @date 2025-12-08
  196. * @param $id
  197. * @param $processing_status
  198. * @return bool
  199. */
  200. public function changeProcessingStatus($where, $processing_status)
  201. {
  202. $ViolationProduct = $this->where($where)->first();
  203. if (!$ViolationProduct) {
  204. return false;
  205. }
  206. $ViolationProduct->processing_status = $processing_status;
  207. $ViolationProduct->update_time = time();
  208. $ViolationProduct->save();
  209. return true;
  210. }
  211. /**
  212. * 删除数据
  213. * @author 唐远望
  214. * @version 1.0
  215. * @date 2025-12-08
  216. * @param $id
  217. * @return bool
  218. */
  219. public function deleteViolationProduct($where)
  220. {
  221. $ViolationProduct = $this->where($where)->first();
  222. if (!$ViolationProduct) {
  223. return false;
  224. }
  225. $ViolationProduct->delete();
  226. return true;
  227. }
  228. }