ViolationStore.php 7.2 KB

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