Vip.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\CorpVip;
  5. use App\Models\AdminVip;
  6. use App\Models\Admin;
  7. class Vip extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'command:vip';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '会员信息处理';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. //获取当前可用会员信息
  37. $vipInfo = AdminVip::where('vip_end_time', '>', time())->get()->toArray();
  38. if(empty($vipInfo)){
  39. echo '无当前可用会员数据'.PHP_EOL;
  40. die;
  41. }
  42. $i = 0;
  43. foreach($vipInfo as $k=>$v){
  44. //判断管理员是否存在
  45. $adminInfo = Admin::where('id', $v['admin_id'])->first();
  46. if(!$adminInfo){
  47. echo $v['admin_id'].'管理员不存在'.PHP_EOL;
  48. continue;
  49. } else {
  50. $adminInfo = collect($adminInfo)->toArray();
  51. }
  52. //判断是否已经有企业会员记录
  53. $corpVipInfo = CorpVip::where('corp_id', $adminInfo['corp_id'])->first();
  54. if($corpVipInfo){
  55. //已存在则按照规则整合会员
  56. if($corpVipInfo['vip_level'] == $v['vip_level']){
  57. $query = [];
  58. $query['vip_start_time'] = time();
  59. $query['vip_end_time'] = time()+3600*24*7;
  60. CorpVip::where('corp_id', $adminInfo['corp_id'])->update($query);
  61. echo $v['admin_id'].'管理员时间叠加'.PHP_EOL;
  62. } elseif($corpVipInfo['vip_level'] > $v['vip_level']){
  63. echo $v['admin_id'].'管理员低级会员无需合并'.PHP_EOL;
  64. } else {
  65. $query = [];
  66. $query['vip_level'] = $v['vip_level'];
  67. $query['vip_start_time'] = $v['vip_start_time'];
  68. $query['vip_end_time'] = $v['vip_end_time'];
  69. CorpVip::where('corp_id', $adminInfo['corp_id'])->update($query);
  70. echo $v['admin_id'].'管理员高级会员直接替换'.PHP_EOL;
  71. }
  72. } else {
  73. //不存在则直接插入
  74. $query = [];
  75. $query['corp_id'] = $adminInfo['corp_id'];
  76. $query['app_id'] = 1;
  77. $query['vip_level'] = $v['vip_level'];
  78. $query['vip_start_time']= time();
  79. $query['vip_end_time'] = time()+3600*24*7;
  80. $query['create_time'] = time();
  81. $query['update_time'] = time();
  82. $res = CorpVip::insert($query);
  83. if($res){
  84. echo $v['admin_id'].'管理员合并成功'.PHP_EOL;
  85. } else {
  86. echo $v['admin_id'].'管理员合并失败'.PHP_EOL;
  87. }
  88. }
  89. $i++;
  90. }
  91. echo '整合管理员'.$i.'个';
  92. }
  93. }