| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- namespace App\Models\Manager\Personnel;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\DB;
- /**
- * 员工openid模型
- * @author 唐远望
- * @version 1.0
- * @date 2026-01-19
- */
- class EmployeeOpenid extends Model
- {
- use HasFactory;
- // 与模型关联的表名
- protected $table = 'personnel_employee_openid';
- // 是否主动维护时间戳
- public $timestamps = false;
- // 定义时间戳字段名
- // const CREATED_AT = 'insert_time';
- // const UPDATED_AT = 'update_time';
- /**
- * 添加
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-04
- */
- public function addEmployeeOpenid_content($data)
- {
- $insert_data = [
- 'employee_id' => $data['employee_id'],
- 'unionid' => $data['unionid'],
- 'openid' => $data['openid'],
- 'type' => isset($data['type']) ? $data['type'] : '3',
- 'insert_time' => time(),
- ];
- $EmployeeOpenid_id = $this->insertGetId($insert_data);
- return $EmployeeOpenid_id;
- }
- /**
- * 写入数据
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-04
- * @param $data
- * @return bool
- */
- public function addEmployeeOpenid($data)
- {
- DB::beginTransaction();
- try {
- $insert_data = [
- 'employee_id' => $data['employee_id'],
- 'unionid' => $data['unionid'],
- 'openid' => $data['openid'],
- 'type' => isset($data['type']) ? $data['type'] : '3',
- 'insert_time' => time(),
- ];
- $EmployeeOpenid_id = $this->insertGetId($insert_data);
- DB::commit();
- return $EmployeeOpenid_id;
- // 成功处理...
- } catch (\Exception $e) {
- DB::rollBack();
- // 错误处理...
- return false;
- }
- }
- /**
- * 编辑内容
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-04
- * @param $data
- * @return bool
- */
- public function editEmployeeOpenid_content($where, $data)
- {
- $EmployeeOpenid = $this->where($where)->first();
- if (!$EmployeeOpenid) {
- return false;
- }
- $EmployeeOpenid->employee_id = $data['employee_id'];
- $EmployeeOpenid->unionid = $data['unionid'];
- $EmployeeOpenid->openid = $data['openid'];
- $EmployeeOpenid->type = isset($data['type']) ? $data['type'] : '3';
- $EmployeeOpenid->update_time = time();
- $EmployeeOpenid->save();
- return true;
- }
- /**
- * 更新数据
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-04
- * @param $data
- * @return bool
- */
- public function updateEmployeeOpenid($EmployeeOpenid, $data)
- {
- DB::beginTransaction();
- try {
- $EmployeeOpenid->employee_id = $data['employee_id'];
- $EmployeeOpenid->unionid = $data['unionid'];
- $EmployeeOpenid->openid = $data['openid'];
- $EmployeeOpenid->type = isset($data['type']) ? $data['type'] : '3';
- $EmployeeOpenid->update_time = time();
- $EmployeeOpenid->save();
- DB::commit();
- return true;
- // 成功处理...
- } catch (\Exception $e) {
- DB::rollBack();
- print_r($e->getMessage());
- exit;
- // 错误处理...
- return false;
- }
- }
- /**
- * 删除数据
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-04
- * @param $id
- * @return bool
- */
- public function deleteEmployeeOpenid($where)
- {
- $EmployeeOpenid = $this->where($where)->first();
- if (!$EmployeeOpenid) {
- return false;
- }
- $EmployeeOpenid->delete();
- return true;
- }
- }
|