You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/command/CalDealerTime.php

132 lines
4.3 KiB

<?php
declare (strict_types=1);
namespace app\command;
use app\api\model\dealer\User as DealerUserModel;
9 months ago
use app\api\model\User;
use app\common\enum\user\UserTypeEnum;
8 months ago
use app\common\model\wholesaler\Apply;
9 months ago
use think\console\Command;
use think\console\Input;
use think\console\Output;
9 months ago
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
class CalDealerTime extends Command
{
protected function configure()
{
// 指令配置
$this->setName('CalDealerTime')
9 months ago
->setDescription('会员身份以及分销身份检测');
}
9 months ago
/**
* @notes:执行
* @param Input $input
* @param Output $output
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
protected function execute(Input $input, Output $output)
{
9 months ago
$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])
6 months ago
->where('fx_effective_time', "<", $nowDay)
->field('user_id,user_type,fx_effective_time,effective_time,store_id')
->select();
6 months ago
// var_dump($dealerUser);
// exit();
9 months ago
$plusUserIds = [];
$normalUserIds = [];
if (!$dealerUser->isEmpty()) {
$dealerUser = $dealerUser->toArray();
foreach ($dealerUser as $value) {
9 months ago
//分销商到期 会员未到期
if (!empty($value['effective_time'])) {
$effective_time = strtotime($value['effective_time']);
if (strtotime($nowDay) < $effective_time) {
$plusUserIds[] = $value['user_id'];
9 months ago
} else {
9 months ago
$normalUserIds[] = $value['user_id'];//会员已到期
9 months ago
}
9 months ago
} else {
//普通会员
$normalUserIds[] = $value['user_id'];
9 months ago
}
}
9 months ago
if ($plusUserIds) {
(new User)->whereIn('user_id', $plusUserIds)->update(['user_type' => UserTypeEnum::MEMBER]);
}
9 months ago
if ($normalUserIds) {
$normalUserIds = array_unique($normalUserIds);
(new User)->whereIn('user_id', $normalUserIds)->update(['user_type' => UserTypeEnum::NORMAL]);
8 months ago
//删除采购商申请
Apply::destroy(function ($query) use ($normalUserIds) {
$query->whereIn('user_id', $normalUserIds);
});
9 months ago
}
$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]);
}
}
}
9 months ago
/**
* @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])
6 months ago
->where('fx_effective_time', "<", $nowDay)
9 months ago
->field('user_id,user_type,effective_time')
->select();
if (!$list->isEmpty()) {
$list = $list->toArray();
foreach ($list as $value) {
9 months ago
$normalUserIds[] = $value['user_id'];
9 months ago
}
if ($normalUserIds) {
(new User)->whereIn('user_id', $normalUserIds)->update(['user_type' => UserTypeEnum::NORMAL]);
8 months ago
//删除采购商申请
Apply::destroy(function ($query) use ($normalUserIds) {
$query->whereIn('user_id', $normalUserIds);
});
9 months ago
}
8 months ago
9 months ago
}
}
}