* 天下共赢用户和好店的关系 */ namespace app\allwin\model; use think\Model; class AllwinUser extends Model{ protected $pk = 'id'; //和主用户表绑定关系 public function user(){ return $this->hasOne('app\common\model\SystemUser','id','uid'); } //查询用户所属店铺 public function store(){ return $this->hasOne('AllwinStore','id','store_id'); } //获取用户所在店铺ID public function getUserStoreId(int $uid){ return self::where(['uid' => $uid])->field('store_id')->find(); } //添加或编辑 public static function editer(int $uid,int $store_id){ $rel = self::where(['uid' => $uid])->find(); if(empty($rel)){ self::insert(['uid' => $uid,'store_id' => $store_id]); }else{ $rel->uid = $uid; $rel->store_id = $store_id; $rel->save(); } } }