ViolationStore.php 5.7 KB

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