ViolationStore.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. namespace App\Models\Manager\WashConfig;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\DB;
  6. use App\Models\Manager\WashConfig\ViolationCompanyMember as ViolationCompanyMemberModel;
  7. /**
  8. * 清洗配置-违规店铺(公司)
  9. * @author: 唐远望
  10. * @version: 1.0
  11. * @date: 2025-12-03
  12. */
  13. class ViolationStore extends Model
  14. {
  15. use HasFactory;
  16. // 与模型关联的表名
  17. protected $table = 'washconfig_violation_store';
  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-03
  28. */
  29. public function addViolationStore_content($data)
  30. {
  31. $insert_data = [
  32. 'platform' => $data['platform'],
  33. 'category_id' => $data['category_id'],
  34. 'company_name' => $data['company_name'],
  35. 'social_credit_code' => $data['social_credit_code'],
  36. 'store_type' => $data['store_type'],
  37. 'employee_ids' => $data['employee_ids'],
  38. 'specify_responsible_person' => $data['specify_responsible_person'],
  39. 'province_id' => $data['province_id'],
  40. 'city_id' => $data['city_id'],
  41. 'area_info' => $data['area_info'],
  42. 'insert_time' => time(),
  43. ];
  44. $ViolationStore_id = $this->insertGetId($insert_data);
  45. return $ViolationStore_id;
  46. }
  47. /**
  48. * 写入数据
  49. * @author 唐远望
  50. * @version 1.0
  51. * @date 2025-12-03
  52. * @param $data
  53. * @return bool
  54. */
  55. public function addViolationStore($data)
  56. {
  57. DB::beginTransaction();
  58. try {
  59. $ViolationCompanyMemberModel = new ViolationCompanyMemberModel();
  60. $insert_data = [
  61. 'platform' => $data['platform'],
  62. 'category_id' => $data['category_id'],
  63. 'company_name' => $data['company_name'],
  64. 'social_credit_code' => $data['social_credit_code'],
  65. 'store_type' => $data['store_type'],
  66. 'employee_ids' => $data['employee_ids'],
  67. 'specify_responsible_person' => $data['specify_responsible_person'],
  68. 'province_id' => $data['province_id'],
  69. 'city_id' => $data['city_id'],
  70. 'area_info' => $data['area_info'],
  71. 'insert_time' => time(),
  72. ];
  73. $ViolationStore_id = $this->insertGetId($insert_data);
  74. if ($data['employee_ids'] != '') {
  75. $insert_company_data = [];
  76. $employee_ids = explode(',', $data['employee_ids']);
  77. foreach ($employee_ids as $employee_id) {
  78. $insert_company_data[] = [
  79. 'company_logid' => $ViolationStore_id,
  80. 'employee_id' => $employee_id,
  81. ];
  82. }
  83. $ViolationCompanyMemberModel->insert($insert_company_data);
  84. }
  85. DB::commit();
  86. return true;
  87. // 成功处理...
  88. } catch (\Exception $e) {
  89. DB::rollBack();
  90. // 错误处理...
  91. return false;
  92. }
  93. }
  94. /**
  95. * 编辑内容
  96. * @author 唐远望
  97. * @version 1.0
  98. * @date 2025-12-03
  99. * @param $data
  100. * @return bool
  101. */
  102. public function editViolationStore_content($where, $data)
  103. {
  104. $ViolationStore = $this->where($where)->first();
  105. if (!$ViolationStore) {
  106. return false;
  107. }
  108. $ViolationStore->platform = $data['platform'];
  109. $ViolationStore->category_id = $data['category_id'];
  110. $ViolationStore->company_name = $data['company_name'];
  111. $ViolationStore->social_credit_code = $data['social_credit_code'];
  112. $ViolationStore->store_type = $data['store_type'];
  113. $ViolationStore->employee_ids = $data['employee_ids'];
  114. $ViolationStore->specify_responsible_person = $data['specify_responsible_person'];
  115. $ViolationStore->province_id = $data['province_id'];
  116. $ViolationStore->city_id = $data['city_id'];
  117. $ViolationStore->area_info = $data['area_info'];
  118. $ViolationStore->update_time = time();
  119. $ViolationStore->save();
  120. return true;
  121. }
  122. /**
  123. * 更新数据
  124. * @author 唐远望
  125. * @version 1.0
  126. * @date 2025-12-03
  127. * @param $data
  128. * @return bool
  129. */
  130. public function updateViolationStore($ViolationStore, $data)
  131. {
  132. DB::beginTransaction();
  133. try {
  134. $ViolationStore->category_id = $data['category_id'];
  135. $ViolationStore->company_name = $data['company_name'];
  136. $ViolationStore->social_credit_code = $data['social_credit_code'];
  137. $ViolationStore->store_type = $data['store_type'];
  138. $ViolationStore->employee_ids = $data['employee_ids'];
  139. $ViolationStore->specify_responsible_person = $data['specify_responsible_person'];
  140. $ViolationStore->province_id = $data['province_id'];
  141. $ViolationStore->city_id = $data['city_id'];
  142. $ViolationStore->area_info = $data['area_info'];
  143. $ViolationStore->update_time = time();
  144. $ViolationStore->save();
  145. $ViolationCompanyMemberModel = new ViolationCompanyMemberModel();
  146. $ViolationCompanyMemberModel->where('company_logid', $ViolationStore->id)->delete();
  147. if ($data['employee_ids'] != '') {
  148. $insert_company_data = [];
  149. $employee_ids = explode(',', $data['employee_ids']);
  150. foreach ($employee_ids as $employee_id) {
  151. $insert_company_data[] = [
  152. 'company_logid' => $ViolationStore->id,
  153. 'employee_id' => $employee_id,
  154. ];
  155. }
  156. $ViolationCompanyMemberModel->insert($insert_company_data);
  157. }
  158. DB::commit();
  159. return true;
  160. // 成功处理...
  161. } catch (\Exception $e) {
  162. DB::rollBack();
  163. // 错误处理...
  164. return false;
  165. }
  166. }
  167. /**
  168. * 修改状态
  169. * @author 唐远望
  170. * @version 1.0
  171. * @date 2025-12-03
  172. * @param $id
  173. * @param $status
  174. * @return bool
  175. */
  176. public function changeStatus($ViolationStore, $status)
  177. {
  178. $ViolationStore->status = $status;
  179. $ViolationStore->update_time = time();
  180. $ViolationStore->save();
  181. return true;
  182. }
  183. /**
  184. * 删除数据
  185. * @author 唐远望
  186. * @version 1.0
  187. * @date 2025-12-03
  188. * @param $id
  189. * @return bool
  190. */
  191. public function deleteViolationStore($where)
  192. {
  193. $ViolationStore = $this->where($where)->first();
  194. if (!$ViolationStore) {
  195. return false;
  196. }
  197. $ViolationStore->delete();
  198. return true;
  199. }
  200. }