123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
-
- namespace App\Console\Commands;
-
- use Illuminate\Console\Command;
- use App\Models\CorpVip;
- use App\Models\AdminVip;
- use App\Models\Admin;
-
- class Vip extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'command:vip';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '会员信息处理';
-
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
- * Execute the console command.
- * @return mixed
- */
- public function handle()
- {
- //获取当前可用会员信息
- $vipInfo = AdminVip::where('vip_end_time', '>', time())->get()->toArray();
- if(empty($vipInfo)){
- echo '无当前可用会员数据'.PHP_EOL;
- die;
- }
- $i = 0;
- foreach($vipInfo as $k=>$v){
- //判断管理员是否存在
- $adminInfo = Admin::where('id', $v['admin_id'])->first();
- if(!$adminInfo){
- echo $v['admin_id'].'管理员不存在'.PHP_EOL;
- continue;
- } else {
- $adminInfo = collect($adminInfo)->toArray();
- }
-
- //判断是否已经有企业会员记录
- $corpVipInfo = CorpVip::where('corp_id', $adminInfo['corp_id'])->first();
- if($corpVipInfo){
- //已存在则按照规则整合会员
- if($corpVipInfo['vip_level'] == $v['vip_level']){
- $query = [];
- $query['vip_start_time'] = time();
- $query['vip_end_time'] = time()+3600*24*7;
- CorpVip::where('corp_id', $adminInfo['corp_id'])->update($query);
- echo $v['admin_id'].'管理员时间叠加'.PHP_EOL;
- } elseif($corpVipInfo['vip_level'] > $v['vip_level']){
- echo $v['admin_id'].'管理员低级会员无需合并'.PHP_EOL;
- } else {
- $query = [];
- $query['vip_level'] = $v['vip_level'];
- $query['vip_start_time'] = $v['vip_start_time'];
- $query['vip_end_time'] = $v['vip_end_time'];
- CorpVip::where('corp_id', $adminInfo['corp_id'])->update($query);
- echo $v['admin_id'].'管理员高级会员直接替换'.PHP_EOL;
- }
- } else {
- //不存在则直接插入
- $query = [];
- $query['corp_id'] = $adminInfo['corp_id'];
- $query['app_id'] = 1;
- $query['vip_level'] = $v['vip_level'];
- $query['vip_start_time']= time();
- $query['vip_end_time'] = time()+3600*24*7;
- $query['create_time'] = time();
- $query['update_time'] = time();
- $res = CorpVip::insert($query);
- if($res){
- echo $v['admin_id'].'管理员合并成功'.PHP_EOL;
- } else {
- echo $v['admin_id'].'管理员合并失败'.PHP_EOL;
- }
- }
- $i++;
- }
- echo '整合管理员'.$i.'个';
- }
- }
|