belongsTo('app\common\model\User','user_id','user_id'); } /** * 获取器:图片地址 * @param $value * @return string */ public function getFilePathAttr($value): string { return $value; // $value ? request()->domain().'/'.$value : '' } /** * 充值卡详情 * @param $where * @param array $with * @return static|null * @throws \think\exception\DbException */ public static function detail($where, $with = []) { !is_array($where) && $where = ['card_id' => (int)$where]; return static::get($where, $with); } /** * 获取全部 * @param array $user * @return mixed */ public static function getAll($user = []) { $model = new static; if(isset($user['is_super']) && $user['is_super'] == 0) { $users = User::getScope($user); $model->where(function ($query) use($users) { $query->where('store_user_id', 'in', $users); }); return $model->order(['card_id' => 'asc'])->where(function ($query) use($users) { $query->where('store_user_id', 'in', $users); })->select(); }else{ return $model->order(['card_id' => 'asc'])->select(); } } /** * 获取指定 * @param array $filter * @return mixed */ public static function getQuery($filter): array { $model = new static; return $model->where($filter)->order(['card_id' => 'asc'])->select()->toArray(); } /** * 切换使用状态 * @param $is_used * @return false|int */ public function changeStatus($is_used) { return $this->save(['is_used' => $is_used]); } }