| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <?php
- namespace App\Models\Manager\WashConfig;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\DB;
- use App\Models\Manager\WashConfig\ViolationCompanyMember as ViolationCompanyMemberModel;
- /**
- * 清洗配置-违规店铺(公司)
- * @author: 唐远望
- * @version: 1.0
- * @date: 2025-12-03
- */
- 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-03
- */
- 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-03
- * @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-03
- * @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-03
- * @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-03
- * @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-03
- * @param $id
- * @return bool
- */
- public function deleteViolationStore($where)
- {
- $ViolationStore = $this->where($where)->first();
- if (!$ViolationStore) {
- return false;
- }
- $ViolationStore->delete();
- return true;
- }
- }
|