ViolationStore.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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($where, $data)
  128. {
  129. DB::beginTransaction();
  130. try {
  131. $ViolationCompanyMemberModel = new ViolationCompanyMemberModel();
  132. $ViolationStore = $this->where($where)->first();
  133. if (!$ViolationStore) {
  134. return false;
  135. }
  136. $ViolationStore->category_id = $data['category_id'];
  137. $ViolationStore->company_name = $data['company_name'];
  138. $ViolationStore->social_credit_code = $data['social_credit_code'];
  139. $ViolationStore->store_type = $data['store_type'];
  140. $ViolationStore->employee_ids = $data['employee_ids'];
  141. $ViolationStore->specify_responsible_person = $data['specify_responsible_person'];
  142. $ViolationStore->province_id = $data['province_id'];
  143. $ViolationStore->city_id = $data['city_id'];
  144. $ViolationStore->area_info = $data['area_info'];
  145. $ViolationStore->update_time = time();
  146. $ViolationStore->save();
  147. $ViolationCompanyMemberModel->where('company_logid', $ViolationStore->id)->delete();
  148. if ($data['employee_ids'] != '') {
  149. $insert_company_data = [];
  150. $employee_ids = explode(',', $data['employee_ids']);
  151. foreach ($employee_ids as $employee_id) {
  152. $insert_company_data[] = [
  153. 'company_logid' => $ViolationStore->id,
  154. 'employee_id' => $employee_id,
  155. ];
  156. }
  157. $ViolationCompanyMemberModel->insert($insert_company_data);
  158. }
  159. DB::commit();
  160. return true;
  161. // 成功处理...
  162. } catch (\Exception $e) {
  163. DB::rollBack();
  164. // 错误处理...
  165. return false;
  166. }
  167. }
  168. /**
  169. * 修改状态
  170. * @author 唐远望
  171. * @version 1.0
  172. * @date 2025-12-03
  173. * @param $id
  174. * @param $status
  175. * @return bool
  176. */
  177. public function changeStatus($where, $status)
  178. {
  179. $ViolationStore = $this->where($where)->first();
  180. if (!$ViolationStore) {
  181. return false;
  182. }
  183. $ViolationStore->status = $status;
  184. $ViolationStore->update_time = time();
  185. $ViolationStore->save();
  186. return true;
  187. }
  188. /**
  189. * 删除数据
  190. * @author 唐远望
  191. * @version 1.0
  192. * @date 2025-12-03
  193. * @param $id
  194. * @return bool
  195. */
  196. public function deleteViolationStore($where)
  197. {
  198. $ViolationStore = $this->where($where)->first();
  199. if (!$ViolationStore) {
  200. return false;
  201. }
  202. $ViolationStore->delete();
  203. return true;
  204. }
  205. }