wanghousheng 8 months ago
parent b432fa2691
commit 1de56bc79f
  1. 156
      app/command/CalDealerTime.php

@ -4,17 +4,15 @@ declare (strict_types=1);
namespace app\command; namespace app\command;
use think\facade\Db;
use app\api\model\User;
use app\api\model\dealer\User as DealerUserModel; use app\api\model\dealer\User as DealerUserModel;
use app\api\model\User;
use app\common\enum\user\UserTypeEnum;
use think\console\Command;
use think\console\Input; use think\console\Input;
use think\console\Output; use think\console\Output;
use app\api\model\PreSale; use think\db\exception\DataNotFoundException;
use think\console\Command; use think\db\exception\DbException;
use app\api\model\PreSaleLog; use think\db\exception\ModelNotFoundException;
use app\api\model\PreSaleMessage;
use app\api\model\{Goods as GoodsModel};
use app\common\enum\user\UserTypeEnum;
// /www/server/php/74/bin/php /server/wwwroot/yanzong/think CalDealerTime // /www/server/php/74/bin/php /server/wwwroot/yanzong/think CalDealerTime
@ -24,67 +22,105 @@ class CalDealerTime extends Command
{ {
// 指令配置 // 指令配置
$this->setName('CalDealerTime') $this->setName('CalDealerTime')
->setDescription('自动计算分销时间'); ->setDescription('会员身份以及分销身份检测');
} }
/**
* @notes:执行
* @param Input $input
* @param Output $output
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
protected function execute(Input $input, Output $output) protected function execute(Input $input, Output $output)
{ {
//todo wmc这边代码需要优化 $nowDay = date('Y-m-d');
//$list = User::where('status', 1) $this->dealerUser($nowDay);
$list = User::where('user_type', 'in', [UserTypeEnum::MEMBER,UserTypeEnum::DEALER]) $this->plusUser($nowDay);
->where('is_delete', '=', 0) }
//->where('store_id',10001)
/**
* @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(); ->select();
// print '<pre>'; $plusUserIds = [];
// print_r($list->toArray()); $normalUserIds = [];
// print '</pre>'; if (!$dealerUser->isEmpty()) {
// die; $dealerUser = $dealerUser->toArray();
$del_fx_user_ids = []; foreach ($dealerUser as $value) {
$del_hy_user_ids = []; $fx_effective_time = strtotime($value['fx_effective_time'] . ' 23:59:59');
foreach ($list as $item) { if (time() > $fx_effective_time) {
//如果分销商到期,改成会员;并且删除分销商 //分销商到期 会员未到期
if(isset($item['fx_effective_time']) && strtotime($item['fx_effective_time']) <= strtotime(date('Y-m-d'))){ if (!empty($value['effective_time'])) {
$del_fx_user_ids[] = $item['user_id']; $effective_time = strtotime($value['effective_time'] . ' 23:59:59');
// User::where('user_id',$item['user_id'])->update([ if (time() < $effective_time) {
// 'user_type'=>UserTypeEnum::MEMBER $plusUserIds[] = $value['user_id'];
// ]); } else {
// //分销商表软删除 $normalUserIds[] = $value['user_id'];//会员已到期
// DealerUserModel::where('user_id',$item['user_id'])->update(['is_delete'=>1]); }
} else {
//普通会员
$normalUserIds[] = $value['user_id'];
}
}
} }
//如果会员到期,分销商到期了,改成普通用户 if ($plusUserIds) {
if((strtotime($item['effective_time']) <= strtotime(date('Y-m-d'))) && (isset($item['fx_effective_time']) && strtotime($item['fx_effective_time']) <= strtotime(date('Y-m-d')))){ (new User)->whereIn('user_id', $plusUserIds)->update(['user_type' => UserTypeEnum::MEMBER]);
$del_hy_user_ids[] = $item['user_id'];
// User::where('user_id',$item['user_id'])->update([
// 'user_type'=>UserTypeEnum::NORMAL
// ]);
} }
//如果会员到期,分销商根本没有,改成普通用户 if ($normalUserIds) {
if((strtotime($item['effective_time']) <= strtotime(date('Y-m-d'))) && !isset($item['fx_effective_time'])){ $normalUserIds = array_unique($normalUserIds);
$del_hy_user_ids[] = $item['user_id']; (new User)->whereIn('user_id', $normalUserIds)->update(['user_type' => UserTypeEnum::NORMAL]);
// User::where('user_id',$item['user_id'])->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]);
} }
} }
//var_dump([$del_fx_user_ids, $del_hy_user_ids]);die;
Db::transaction(function () use ($del_fx_user_ids, $del_hy_user_ids) {
//如果分销商到期,改成会员;并且删除分销商
User::whereIn('user_id',$del_fx_user_ids)->update([
'user_type'=>UserTypeEnum::MEMBER
]);
//分销商表软删除
DealerUserModel::whereIn('user_id',$del_fx_user_ids)->update(['is_delete'=>1]);
//如果会员到期,分销商到期了/根本没有,改成普通用户
User::whereIn('user_id',$del_hy_user_ids)->update([
'user_type'=>UserTypeEnum::NORMAL
]);
});
} }
/**
* @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) {
$effective_time = strtotime($value['effective_time'] . ' 23:59:59');
if (time() > $effective_time) {
$normalUserIds[] = $value['user_id'];
}
}
if ($normalUserIds) {
(new User)->whereIn('user_id', $normalUserIds)->update(['user_type' => UserTypeEnum::NORMAL]);
}
}
}
} }

Loading…
Cancel
Save