'ID', 'mall_id' => 'Mall ID', 'user_id' => 'User ID', 'center_id' => 'Center ID', 'deleted_at' => 'Deleted At', 'updated_at' => 'Updated At', 'created_at' => 'Created At', ]; } /** * @return ActiveQueryInterface the relational query object. */ public function getCenter() { return $this->hasOne(UserCenter::class, ['id' => 'center_id']); } /** * 获取用户所属 * * @param integer $user_id * @return static|null */ public static function getUserAffiliationByUserId(int $user_id) { return static::find() ->andWhere(['user_id' => $user_id]) ->one(); } /** * 获取当前选择的运营中心 * * @param integer $user_id * @param float $lon * @param float $lat * @return array */ public static function getUserAffiliationCenterByUserId(int $user_id, float $lon, float $lat) { $center_id = static::find() ->andWhere(['user_id' => $user_id]) ->select('center_id') ->scalar(); if (empty($center_id)) { return []; } return UserCenter::find() ->andWhere(['id' => $center_id]) ->select([ 'id', 'center_name', 'province', 'city', 'district', 'town', 'operation_address', 'logo', UserCenter::getDistanceSql($lon, $lat) ]) ->asArray() ->all(); } /** * 删除所属 * * @return boolean */ public function delSelect() { return $this->delete(); } /** * 添加选择 * * @param integer $mall_id * @param integer $user_id * @param integer $center_id * @return true|static */ public static function addSelect( int $mall_id, int $user_id, int $center_id ) { $model = new static; $model->load(compact('mall_id', 'user_id', 'center_id'), ''); return $model->save(); } }