32], [['idcard_front', 'idcard_reverse', 'operation_license', 'logo', 'province', 'city', 'district', 'town', 'operation_address', 'reject_content'], 'string', 'max' => 255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'user_id' => 'User ID', 'level' => 'Level', 'name' => 'Name', 'mobile' => 'Mobile', 'center_name' => 'Center Name', 'idcard_front' => 'Idcard Front', 'idcard_reverse' => 'Idcard Reverse', 'operation_license' => 'Operation License', 'logo' => 'Logo', 'province_id' => 'Province ID', 'province' => 'Province', 'city_id' => 'City ID', 'city' => 'City', 'district_id' => 'District ID', 'district' => 'District', 'town_id' => 'Town ID', 'town' => 'Town', 'operation_address' => 'Operation Address', 'status' => 'Status', 'reject_content' => 'Reject Content', 'apply_at' => 'Apply At', 'deleted_at' => 'Deleted At', 'updated_at' => 'Updated At', 'created_at' => 'Created At', ]; } /** * @return ActiveQueryInterface the relational query object. */ public function getUser() { return $this->hasOne(MallUser::class, ['id' => 'user_id']); } /** * @return ActiveQueryInterface the relational query object. */ public function getCenter() { return $this->hasOne(UserCenter::class, ['user_id' => 'user_id']); } /** * 添加申请记录 * * @param integer $user_id * @param integer $mall_id * @param array $array * @return true|static */ public static function addApplyList( int $user_id, int $mall_id, array $data ) { $model = new static; $data = array_merge($data, compact('user_id', 'mall_id'), [ 'status' => static::APPLYING, 'level' => 0 ]); $model->load($data, ''); return $model->save(); } /** * 是否已经申请或者已经通过 * * @param integer $user_id * @return boolean|static */ public static function hasApplyOrPassByUserId(int $user_id) { $one = static::find() ->andWhere( [ 'user_id' => $user_id, 'status' => [ static::APPLYING, static::PASSED ] ] ) ->select(['id', 'status', 'user_id']) ->orderBy('id desc') ->one(); return empty($one) ? false : $one; } /** * 获取申请状态 * * @param integer $user_id * @return static|int */ public static function getApplyStatus(int $user_id) { return static::find() ->select(['id', 'user_id', 'status', 'reject_content']) ->andWhere(['user_id' => $user_id]) ->orderBy('id desc') ->one() ?? 0; } /** * 通过名称搜索ID * * @param integer $mall_id * @param string $name * @return array */ public static function getUserIdByName(int $mall_id, string $name) { return static::find() ->andWhere(['mall_id' => $mall_id]) ->andWhere(['like', 'name', $name]) ->select(['user_id']) ->column(); } /** * 通过名称搜索ID * * @param integer $mall_id * @param string $mobile * @return array */ public static function getUserIdByMobile(int $mall_id, string $mobile) { return static::find() ->andWhere(['mall_id' => $mall_id]) ->andWhere(['like', 'mobile', $mobile]) ->select(['user_id']) ->column(); } /** * 通过申请中详情 * * @param integer $mall_id * @param integer $id * @return static|null */ public static function getApplyingById(int $mall_id, int $id) { return static::find() ->andWhere(['mall_id' => $mall_id, 'id' => $id, 'status' => static::APPLYING]) ->one(); } /** * 通过 * * @param Level $level * @return boolean */ public function pass(Level $level) { $this->level = $level->id; $this->apply_at = time(); $this->status = static::PASSED; return $this->save(); } /** * 驳回 * * @param string $content * @return boolean */ public function reject(string $content = '') { $this->status = static::REJECTED; $this->reject_content = $content; return $this->save(); } /** * 获取地址 * * @return string */ public function getOperationAddress() { return $this->province . $this->city . $this->district . $this->town . $this->operation_address; } /** * 是否通过后被删除运营中心 * * @return boolean */ public function isPassedButDelete() { return ($this->status == static::PASSED && empty($this->center)); } }