ViolationStore.php 6.1 KB

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