setName('CalDealerTime') ->setDescription('会员身份以及分销身份检测'); } /** * @notes:执行 * @param Input $input * @param Output $output * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author: wanghousheng */ protected function execute(Input $input, Output $output) { $nowDay = date('Y-m-d'); $this->dealerUser($nowDay); $this->plusUser($nowDay); } /** * @notes:分销商用户 * @param $nowDay * @return void * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author: wanghousheng */ private function dealerUser($nowDay) { $dealerUser = (new User)->where(['user_type' => UserTypeEnum::DEALER]) ->whereDay('fx_effective_time', $nowDay) ->field('user_id,user_type,fx_effective_time,effective_time') ->select(); $plusUserIds = []; $normalUserIds = []; if (!$dealerUser->isEmpty()) { $dealerUser = $dealerUser->toArray(); foreach ($dealerUser as $value) { //分销商到期 会员未到期 if (!empty($value['effective_time'])) { $effective_time = strtotime($value['effective_time']); if (strtotime($nowDay) < $effective_time) { $plusUserIds[] = $value['user_id']; } else { $normalUserIds[] = $value['user_id'];//会员已到期 } } else { //普通会员 $normalUserIds[] = $value['user_id']; } } if ($plusUserIds) { (new User)->whereIn('user_id', $plusUserIds)->update(['user_type' => UserTypeEnum::MEMBER]); } if ($normalUserIds) { $normalUserIds = array_unique($normalUserIds); (new User)->whereIn('user_id', $normalUserIds)->update(['user_type' => UserTypeEnum::NORMAL]); } $dealerUserIds = array_unique(array_merge($normalUserIds, $plusUserIds)); //删除分销商(软) if ($dealerUserIds) { // foreach ($dealerUserIds as $value) { // UserModel::detail($value)->delete(); // } (new DealerUserModel())->whereIn('user_id', $dealerUserIds)->update(['is_delete' => 1]); } } } /** * @notes:plus会员 * @param $nowDay * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author: wanghousheng */ private function plusUser($nowDay) { $normalUserIds = []; $list = (new User)->where(['user_type' => UserTypeEnum::MEMBER]) ->whereDay('effective_time', $nowDay) ->field('user_id,user_type,effective_time') ->select(); if (!$list->isEmpty()) { $list = $list->toArray(); foreach ($list as $value) { $normalUserIds[] = $value['user_id']; } if ($normalUserIds) { (new User)->whereIn('user_id', $normalUserIds)->update(['user_type' => UserTypeEnum::NORMAL]); } } } }