32], [['logo', 'province', 'city', 'district', 'town', 'operation_address'], 'string', 'max' => 255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'user_id' => 'User ID', 'level' => 'Level', 'settlement_amount' => 'Settlement Amount', 'settlement_amount_total' => 'Settlement Amount Total', 'discard_amount' => 'Discard Amount', 'center_name' => 'Center Name', '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', 'lon' => 'Lon', 'lat' => 'Lat', '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 getLevel() { return $this->hasOne(Level::class, ['level' => 'level', 'mall_id' => 'mall_id']); } /** * @return ActiveQueryInterface the relational query object. */ public function getLevelInfo() { return $this->hasOne(Level::class, ['level' => 'level', 'mall_id' => 'mall_id']); } /** * @return ActiveQueryInterface the relational query object. */ public function getApply() { return $this->hasOne(ApplyList::class, ['user_id' => 'user_id'])->orderBy('id desc'); } /** * @return ActiveQueryInterface the relational query object. */ public function getApplyInfo() { return $this->hasOne(ApplyList::class, ['user_id' => 'user_id']) ->andWhere(['status' => 2]) ->orderBy('id desc'); } /** * 获取推广中心 * * @param integer $user_id * @return static|null */ public static function getCenterByUserId(int $user_id) { return static::find() ->andWhere(['user_id' => $user_id]) ->one(); } /** * 获取推广中心 * * @param integer $mall_id * @param integer $id * @return static|null */ public static function getCenterById(int $mall_id, int $id) { return static::find() ->andWhere(['mall_id' => $mall_id]) ->andWhere(['id' => $id]) ->one(); } /** * 查询距离 * * @param float $lon * @param float $lat * @return Expression */ public static function getDistanceSql(float $lon, float $lat) { $sql = <<province . $this->city . $this->district . $this->town . $this->operation_address; } /** * 添加运营中心 * * @param ApplyList $apply * @param Level $level * @return boolean */ public static function addUserByApply( ApplyList $apply, Level $level, float $lon, float $lat ) { $data['mall_id'] = $apply->mall_id; $data['user_id'] = $apply->user_id; $data['level'] = $level->level; $data['center_name'] = $apply->center_name; $data['logo'] = $apply->logo; $data['province_id'] = $apply->province_id; $data['province'] = $apply->province; $data['city_id'] = $apply->city_id; $data['city'] = $apply->city; $data['district_id'] = $apply->district_id; $data['district'] = $apply->district; $data['town_id'] = $apply->town_id; $data['town'] = $apply->town; $data['operation_address'] = $apply->operation_address; $data['status'] = $apply->status; $data['lon'] = $lon; $data['lat'] = $lat; $model = new static; $model->load($data, ''); return $model->save(); } /** * 添加总佣金 * * @param integer $user_id * @param float $amount * @return float */ public static function addSettlementAmountTotal(int $user_id, float $amount) { return static::updateAllCounters( ['settlement_amount_total' => $amount], ['user_id' => $user_id] ); } /** * 添加总佣金 * * @param integer $user_id * @param float $amount * @return float */ public static function addSettlementAmount(int $user_id, float $amount) { return static::updateAllCounters( ['settlement_amount' => $amount], ['user_id' => $user_id] ); } /** * 添加失效佣金 * * @param integer $user_id * @param float $amount * @return float */ public static function addDiscardAmount(int $user_id, float $amount) { return static::updateAllCounters( ['discard_amount' => $amount], ['user_id' => $user_id] ); } /** * 设置等级 * * @param Level $level * @return true|static */ public function setLevel(Level $level) { $this->level = $level->level; // $this->upgrade_level_at = time(); return $this->save(); } /** * 当前是否有会员使用此等级 * * @param Level $level * @return boolean */ public static function hasLevel(Level $level) { return !empty( static::find() ->andWhere(['level' => $level->level]) ->limit(1) ->select(['id']) ->one() ); } /** * 推广中心数据显示 * @param array $params * @return array */ public static function getIncomeInfo(array $params) { $is_install = MallAddons::isInstall($params['mall_id'], $params['addons_name']); $data['total_commission'] = 0; $data['is_install'] = 0; $basic = \Yii::$app->services->setting->addons->get($params['mall_id'], $params['addons_name'], 'basic'); $data['is_show_at_center'] = 1; if(isset($basic['show_center'])) $data['is_show_at_center'] = $basic['show_center']; if ($is_install) { $model = self::findOne([ 'user_id' => $params['user_id'], 'status' => StatusEnum::ENABLED, ]); $data['total_commission'] = $model->settlement_amount_total ?? 0.00;// 累计总佣金 $data['is_install'] = $is_install; } return $data; } }