ViolationStore.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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->platform = $data['platform'];
  124. $ViolationStore->store_name = $data['store_name'];
  125. $ViolationStore->store_type = $data['store_type'];
  126. $ViolationStore->employee_ids = $data['employee_ids'];
  127. $ViolationStore->specify_responsible_person = $data['specify_responsible_person'];
  128. $ViolationStore->update_time = time();
  129. $ViolationStore->save();
  130. $ViolationStoreMemberModel = new ViolationStoreMemberModel();
  131. $ViolationStoreMemberModel->where('store_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. 'store_logid' => $ViolationStore->id,
  138. 'employee_id' => $employee_id,
  139. ];
  140. }
  141. $ViolationStoreMemberModel->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($ViolationStore, $status)
  162. {
  163. $ViolationStore->status = $status;
  164. $ViolationStore->update_time = time();
  165. $ViolationStore->save();
  166. return true;
  167. }
  168. /**
  169. * 删除数据
  170. * @author 唐远望
  171. * @version 1.0
  172. * @date 2025-12-03
  173. * @param $id
  174. * @return bool
  175. */
  176. public function deleteViolationStore($where)
  177. {
  178. $ViolationStore = $this->where($where)->first();
  179. if (!$ViolationStore) {
  180. return false;
  181. }
  182. $ViolationStore->delete();
  183. return true;
  184. }
  185. }