123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- /**
- * 客户资质模型
- *
- */
- class CustomCompany extends Model
- {
- use HasFactory;
- // 与模型关联的表名
- protected $table = 'custom_company';
- // 是否主动维护时间戳
- public $timestamps = false;
- // 定义时间戳字段名
- // const CREATED_AT = 'insert_time';
- // const UPDATED_AT = 'update_time';
- /**
- * 编码转id
- *
- * @param string $code 编码
- *
- */
- public function codeToId($code){
- return intval(str_ireplace('klzz','',$code));
- }
-
- /**
- * id转编码
- *
- * @param int $id 编码
- *
- */
- public function idToCode($id){
- return 'klzz'. str_pad($id, 9, '0', STR_PAD_LEFT);;
- }
- /**
- * 添加数据
- *
- */
- public function add($data)
- {
- // 时间
- $data['insert_time'] = time();
- $data['update_time'] = time();
- // 写入数据表
- $id = $this->query()->insertGetId($data);
- // 返回结果
- return $id;
- }
- /**
- * 添加数据
- *
- */
- public function edit($id,$data)
- {
- // 更新时间
- $data['update_time'] = time();
- // 写入数据表
- $result = $this->query()->where(['id'=>$id])->update($data);
- // 返回结果
- return $result;
- }
- /**
- * 添加数据
- *
- */
- public function upsertOne($data)
- {
- // // 数据
- // $data['uid'] = $uid;
- $data['insert_time'] = time();
- $data['update_time'] = time();
- // 获取结果
- $uid = $this->query()->upsert($data,'custom_uid',['remark','remark_company','license_name','license_code','license_area','license_addr','legal_name','status','update_time']);
- // 如果存在的话,更新
- if( $uid ) return $uid;
- // 如果不存在的话,新增
- // return $this->add($data);
- }
- /**
- * 查询某条数据
- *
- */
- public function getOne($uid){
- // 返回结果
- $result = $this->query()->where([['custom_uid','=',$uid]])->first(['id','custom_uid','remark','remark_company','license_name','license_code','license_area','license_addr','legal_name','status','update_time']);
- // 返回结果
- return $result;
- }
- /**
- * 添加数据
- *
- * @param int $uid 客户ID
- * @param string $field 字段
- */
- public function getValue($uid,$field)
- {
- // 返回结果
- $result = $this->query()->where([['custom_uid','=',$uid]])->value($field);
- // 数据结构
- return $result;
- }
- }
|