ViolationStore.php 6.8 KB

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