123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php namespace App\Models\Work;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- /**
- * 企业自定义的state参数记录表
- *
- */
- class State extends Model
- {
- use HasFactory;
- // 与模型关联的表名
- protected $table = 'work_state';
- // 是否主动维护时间戳
- public $timestamps = false;
- // 定义时间戳字段名
- // const CREATED_AT = 'insert_time';
- // const UPDATED_AT = 'update_time';
- /**
- * 添加数据
- *
- */
- public function add($data)
- {
- // 时间
- $data['insert_time'] = time();
- $data['update_time'] = time();
- // 写入数据表
- $id = $this->query()->insertGetId($data);
- // 如果操作失败
- if( !$id ) return $id;
- // 返回结果
- return $id;
- }
- /**
- * 添加数据
- *
- */
- public function edit($id,$data)
- {
- // 更新时间
- $data['update_time'] = time();
- // 写入数据表
- $result = $this->query()->where(['id'=>$id])->update($data);
- // 如果操作失败
- if( !$result ) return $result;
- // 返回结果
- return $result;
- }
- /**
- * 获取列表
- * @param Bool $force 是否强制更新
- *
- */
- public function getList()
- {
- // 结果数据
- $list = $this->query()->get(['id','remark','config_id','is_follow','qr_code','tags','user','user_type','custom_uid']);
- // 返回结果
- return $list;
- }
- /**
- * 单个
- *
- * @param int ID
- * @param string 指定字段
- *
- */
- public function getOne($id,$field='')
- {
- // 获取列表数据
- $one = $this->query()->where([['id','=',$id]])->first(['id','remark','config_id','is_follow','qr_code','tags','user','user_type','custom_uid']);
- // 获取数据
- $one = $one ? $one->toArray() : [];
- // 返回值
- return empty($field) ? $one : ( isset($one[$field]) ? $one[$field] : null);
- }
- /**
- * 推送客服专用
- *
- */
- public function getFollowQrcode($force = false){
- // 获取结果
- $qrcode = $force ? null : cache('admin:work:state:follow:qrcode');
- // 判断结果
- if( is_null($qrcode) ){
- // 获取列表数据
- $qrcode = $this->query()->where([['is_follow','=',1]])->value('qr_code');
- // 存起来
- cache(['admin:work:state:follow:qrcode'=>$qrcode],now()->addHours(2));
- }
- // 返回值
- return $qrcode;
- }
- }
|