belongsTo("app\\{$module}\\model\\Merchant", 'parent_merchant_id'); } /** * 商户详情 * @param $where * @param array $with * @return static|null * @throws \think\exception\DbException */ public static function detail($where, $with = []) { !is_array($where) && $where = ['merchant_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); $arr = $user['merchant_id']?json_decode($user['merchant_id'],true):[]; return $model->order(['merchant_id' => 'asc'])->where(function ($query) use($users, $arr) { $query->where('store_user_id', 'in', $users) ->whereOr('merchant_id', 'in', $arr); })->select();*/ return $model->order(['merchant_id' => 'asc'])->where(function ($query) use($user) { $query->where('merchant_id', '=', $user['merchant_id']) ->whereOr('parent_merchant_id', '=', $user['merchant_id']); })->select(); }else{ return $model->order(['merchant_id' => 'asc'])->select(); } } /** * 获取指定 * @param array $filter * @return mixed */ public static function getQuery($filter): array { $model = new static; return $model->where($filter)->order(['merchant_id' => 'asc'])->select()->toArray(); } /** * 累积商户可用余额 * @param int $merchantId * @param float $money * @return mixed */ public static function setIncBalance(int $merchantId, float $money) { return (new static)->setInc($merchantId, 'balance', $money); } /** * 消减商户可用余额 * @param int $merchantId * @param float $money * @return mixed */ public static function setDecBalance(int $merchantId, float $money) { return (new static)->setDec([['merchant_id', '=', $merchantId]], 'balance', $money); } }