V20181205Command.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace App\Console\Commands\Upgrade;
  3. use App\Models\Fpdx\ActivityModel;
  4. use App\Models\TicketModel;
  5. use Illuminate\Console\Command;
  6. class V20181205Command extends Command
  7. {
  8. protected $signature = "upgrade:v20181205";
  9. protected $description = "版本升级脚本|2018-12-05号更新版本升级\n
  10. 更新内容:\n
  11. 1. 增加活动契约系统\n
  12. 2. 72小时活动报名加入契约\n
  13. 2. 移除首页feed流解锁功能,添加邀请交换微信功能并加入契约\n
  14. 脚本任务:\n
  15. 1. 将未使用的解锁卡1:7.5转换为红花\n
  16. 2. 已报名活动未创建契约的人创建默认契约";
  17. public function handle()
  18. {
  19. $this->changeTicket2Flower();
  20. $this->addPairDeed();
  21. }
  22. public function changeTicket2Flower()
  23. {
  24. dump("「解锁卡转换成小花」开始");
  25. $datas = TicketModel::select(\DB::raw('uid, count(*) as c'))
  26. ->where([['type', 5], ['state', 0], ['validity_time', '>', time()]])
  27. ->groupBy('uid')->take(5000)->get();
  28. foreach ($datas as $data) {
  29. dump($data);
  30. \DB::beginTransaction();
  31. try {
  32. \DB::table('kdgx_partner_charge_user')->where('uid', $data->uid)
  33. ->increment('red_flower', $data->c * 7.5);
  34. \DB::table('kdgx_partner_charge_pay_logs')->insert([
  35. 'uid' => $data->uid,
  36. 'type' => 5,
  37. 'red_flower' => $data->c * 7.5,
  38. 'remark' => '更新补偿',
  39. 'create_at' => time()
  40. ]);
  41. TicketModel::where([
  42. ['type', 5],
  43. ['state', 0],
  44. ['validity_time', '>', time()],
  45. ['uid', $data->uid]
  46. ])->update(['validity_time' => mktime(12, 0, 0)]);
  47. \DB::commit();
  48. } catch (\Exception $e) {
  49. dump($e);
  50. \DB::rollBack();
  51. }
  52. }
  53. dump("「解锁卡转换成小花」结束");
  54. }
  55. /**
  56. * @deprecated
  57. */
  58. public function addPairDeed()
  59. {
  60. dump("「补全报名契约」开始");
  61. $ings = ActivityModel::getActivitys();
  62. $ings['last'] = 67;
  63. dump("当前处理的期数:「{$ings['last']}」");
  64. $activity = ActivityModel::findOrFail($ings['last']);
  65. $acks = \DB::table('kdgx_fpdx_deed')->where([
  66. ['type', 1],
  67. ['way', 0],
  68. ['publish_at', $activity->open_time]
  69. ])->pluck('way_id');
  70. $datas = \DB::table('kdgx_partner_charge_pair')->where('stage_id', $ings['last'])
  71. ->whereNotIn('id', $acks)->get();
  72. foreach ($datas as $data) {
  73. dump($data->id);
  74. \DB::beginTransaction();
  75. try {
  76. if (
  77. \DB::table('kdgx_fpdx_deed')->where([
  78. ['type', 1],
  79. ['ack', $data->id]
  80. ])->exists()
  81. ) {
  82. continue;
  83. } else {
  84. \DB::table('kdgx_fpdx_deed')->insertGetId([
  85. 'created_at' => time(),
  86. 'updated_at' => time(),
  87. 'uid' => $data->uid,
  88. 'sign' => '签名',
  89. 'type' => 1,
  90. 'ack' => $data->id,
  91. 'state' => 1,
  92. 'sign_at' => $data->create_time,
  93. 'publish_at' => $activity->open_time,
  94. 'confirm_at' => $activity->rematched_at,
  95. 'end_at' => $activity->close_time,
  96. 'way' => 0,
  97. 'way_id' => $data->id
  98. ]);
  99. }
  100. \DB::commit();
  101. } catch (\Exception $e) {
  102. dump($e);
  103. \DB::rollBack();
  104. }
  105. }
  106. dump("「补全报名契约」结束");
  107. }
  108. }