ViolationStore.php 6.0 KB

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