12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php namespace App\Models\WeiBan;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use App\Models\Traits\MultipUpdate;
- /**
- * 微伴用户模型
- *
- */
- class External extends Model
- {
- use HasFactory,MultipUpdate;
- // 与模型关联的表名
- protected $table = 'weiban_external';
- // 主键不是一个整数
- protected $keyType = 'string';
- // 主键不自增
- public $incrementing = false;
- // 是否主动维护时间戳
- public $timestamps = false;
- // 定义时间戳字段名
- // const CREATED_AT = 'insert_time';
- // const UPDATED_AT = 'update_time';
- /**
- * 添加数据
- *
- */
- public function add($data)
- {
- if( empty($data['id']) ) return '';
- // 更新时间
- $data['insert_time'] = time();
- $data['update_time'] = time();
- // 写入数据表
- $result = $this->query()->insert($data);
- // 失败返回0
- if( !$result ) return '';
- // 返回结果
- return $data['id'];
- }
- /**
- * 添加数据
- *
- */
- public function edit($id,$data)
- {
- // 更新时间
- $data['update_time'] = time();
- // 写入数据表
- $result = $this->query()->where(['id'=>$id])->update($data);
- // 失败返回0
- if( !$result ) return '';
- // 返回结果
- return $id;
- }
- /**
- * 添加数据
- *
- */
- public function getOne($id)
- {
- // 返回结果
- $custom = $this->query()->where([['id','=',$id]])->first(['id','custom_uid','avatar','name','gender','status','type','corp_name','corp_full_name']);
- // 返回结果
- if( !$custom ) return [];
- // 数据结构
- return $custom->toArray();
- }
- /**
- * 添加数据
- *
- * @param int $id 客户ID
- * @param string $field 字段
- */
- public function getValue($id,$field)
- {
- // 返回结果
- $result = $this->query()->where([['id','=',$id]])->value($field);
- // 数据结构
- return $result;
- }
-
- }
|