|
|
@@ -0,0 +1,201 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Models\Api\WashConfig;
|
|
|
+
|
|
|
+use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
+use Illuminate\Database\Eloquent\Model;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+use App\Models\Api\WashConfig\ViolationCompanyMember as ViolationCompanyMemberModel;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 清洗配置-违规店铺
|
|
|
+ * @author: 唐远望
|
|
|
+ * @version: 1.0
|
|
|
+ * @date: 2025-12-15
|
|
|
+ */
|
|
|
+class ViolationStore extends Model
|
|
|
+{
|
|
|
+ use HasFactory;
|
|
|
+ // 与模型关联的表名
|
|
|
+ protected $table = 'washconfig_violation_store';
|
|
|
+ // 是否主动维护时间戳
|
|
|
+ public $timestamps = false;
|
|
|
+ // 定义时间戳字段名
|
|
|
+ // const CREATED_AT = 'insert_time';
|
|
|
+ // const UPDATED_AT = 'update_time';
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2025-12-15
|
|
|
+ */
|
|
|
+ public function addViolationStore_content($data)
|
|
|
+ {
|
|
|
+ $insert_data = [
|
|
|
+ 'company_name' => $data['company_name'],
|
|
|
+ 'social_credit_code' => $data['social_credit_code'],
|
|
|
+ 'store_type' => $data['store_type'],
|
|
|
+ 'insert_time' => time(),
|
|
|
+ ];
|
|
|
+ $ViolationStore_id = $this->insertGetId($insert_data);
|
|
|
+ return $ViolationStore_id;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 写入数据
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2025-12-15
|
|
|
+ * @param $data
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function addViolationStore($data)
|
|
|
+ {
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $ViolationCompanyMemberModel = new ViolationCompanyMemberModel();
|
|
|
+ $insert_data = [
|
|
|
+ 'company_name' => $data['company_name'],
|
|
|
+ 'social_credit_code' => $data['social_credit_code'],
|
|
|
+ 'store_type' => $data['store_type'],
|
|
|
+ 'employee_ids' => $data['employee_ids'],
|
|
|
+ 'insert_time' => time(),
|
|
|
+ ];
|
|
|
+ $ViolationStore_id = $this->insertGetId($insert_data);
|
|
|
+
|
|
|
+ if ($data['employee_ids'] != '') {
|
|
|
+ $insert_company_data = [];
|
|
|
+ $employee_ids = explode(',', $data['employee_ids']);
|
|
|
+ foreach ($employee_ids as $employee_id) {
|
|
|
+ $insert_company_data[] = [
|
|
|
+ 'company_logid' => $ViolationStore_id,
|
|
|
+ 'company_id' => $employee_id,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $ViolationCompanyMemberModel->insert($insert_company_data);
|
|
|
+ }
|
|
|
+ DB::commit();
|
|
|
+ return true;
|
|
|
+ // 成功处理...
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+ // 错误处理...
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑内容
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2025-12-15
|
|
|
+ * @param $data
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function editViolationStore_content($where, $data)
|
|
|
+ {
|
|
|
+ $ViolationStore = $this->where($where)->first();
|
|
|
+ if (!$ViolationStore) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $ViolationStore->company_name = $data['company_name'];
|
|
|
+ $ViolationStore->social_credit_code = $data['social_credit_code'];
|
|
|
+ $ViolationStore->store_type = $data['store_type'];
|
|
|
+ $ViolationStore->update_time = time();
|
|
|
+ $ViolationStore->save();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新数据
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2025-12-15
|
|
|
+ * @param $data
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function updateViolationStore($where, $data)
|
|
|
+ {
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $ViolationCompanyMemberModel = new ViolationCompanyMemberModel();
|
|
|
+ $ViolationStore = $this->where($where)->first();
|
|
|
+ if (!$ViolationStore) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $ViolationStore->company_name = $data['company_name'];
|
|
|
+ $ViolationStore->social_credit_code = $data['social_credit_code'];
|
|
|
+ $ViolationStore->store_type = $data['store_type'];
|
|
|
+ $ViolationStore->employee_ids = $data['employee_ids'];
|
|
|
+ $ViolationStore->update_time = time();
|
|
|
+ $ViolationStore->save();
|
|
|
+
|
|
|
+ $ViolationCompanyMemberModel->where('company_logid', $ViolationStore->id)->delete();
|
|
|
+ if ($data['employee_ids'] != '') {
|
|
|
+ $insert_company_data = [];
|
|
|
+ $employee_ids = explode(',', $data['employee_ids']);
|
|
|
+ foreach ($employee_ids as $employee_id) {
|
|
|
+ $insert_company_data[] = [
|
|
|
+ 'company_logid' => $ViolationStore->id,
|
|
|
+ 'company_id' => $employee_id,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $ViolationCompanyMemberModel->insert($insert_company_data);
|
|
|
+ }
|
|
|
+ DB::commit();
|
|
|
+ return true;
|
|
|
+ // 成功处理...
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+ // 错误处理...
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改状态
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2025-12-15
|
|
|
+ * @param $id
|
|
|
+ * @param $status
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function changeStatus($where, $status)
|
|
|
+ {
|
|
|
+ $ViolationStore = $this->where($where)->first();
|
|
|
+ if (!$ViolationStore) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $ViolationStore->status = $status;
|
|
|
+ $ViolationStore->update_time = time();
|
|
|
+ $ViolationStore->save();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除数据
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2025-12-15
|
|
|
+ * @param $id
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function deleteViolationStore($where)
|
|
|
+ {
|
|
|
+ $ViolationStore = $this->where($where)->first();
|
|
|
+ if (!$ViolationStore) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $ViolationStore->delete();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|