OnedayUserDataupdate.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\api\command;
  4. use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\AddShortUrlResponseBody\data;
  5. use app\common\model\PaymentModel;
  6. use app\common\model\ShopGoodsModel;
  7. use app\common\model\ShopOrderGoodsModel as OrderGoods;
  8. use app\common\model\ShopOrderModel;
  9. use app\common\model\UserModel;
  10. use think\console\Command;
  11. use think\console\Input;
  12. use think\console\Output;
  13. use think\facade\Db;
  14. class OnedayUserDataupdate extends Command
  15. {
  16. protected function configure()
  17. {
  18. // 每天刷新用户一些用户信息
  19. $this->setName('oneday_user_dataupdate')
  20. ->setDescription('the oneday_user_dataupdate command');
  21. }
  22. protected function execute(Input $input, Output $output)
  23. {
  24. Db::startTrans();
  25. try {
  26. $this->updateUserData();
  27. Db::commit();
  28. }catch (\Exception $e){
  29. Db::rollback();
  30. $output->writeln('error:'.$e->getMessage());
  31. }
  32. return 22;
  33. }
  34. public function updateUserData(){
  35. // 更新用户所有昨日今日数据
  36. $list = Db::name('money_log')->where('type', 6)->whereDay('create_at', 'yesterday')->field('uid')->group('uid')->select();
  37. foreach ($list as $key=>$val){
  38. $money = Db::name('money_log')->where('type', 6)->whereDay('create_at', 'yesterday')->where('uid', $val['uid'])->sum('money');
  39. Db::name('user')->where('id', $val['uid'])->save([
  40. 'yesterday_money'=>$money
  41. ]);
  42. }
  43. // $list = Db::name('user')->where('id', '>', 0)->where('today_money', '>', 0)->select();
  44. // 这是测试 上线要干掉
  45. // if (count($list) == 0){
  46. // // 如果跑了定时任务
  47. // return;
  48. // }
  49. // foreach ($list as $key=>$val){
  50. // Db::name('user')->where('id', $val['id'])->save([
  51. // 'yesterday_money'=>$val['today_money'],
  52. // 'today_money'=>0
  53. // ]);
  54. // if ($val['today_money'] > 0){
  55. // edit_user_money(4, $val['id'], $val['today_money']);
  56. // }
  57. // }
  58. Db::name('user')->where('today_box', '>', 0)->save(['today_box'=>0]);
  59. Db::name('user')->where('today_team_box', '>', 0)->save(['today_team_box'=>0]);
  60. // 开启下一期 福袋预约
  61. $max_id = Db::name('box')->where('status', 1)->max('id');
  62. $info = Db::name('box')->where('id', $max_id)->find();
  63. if ($info){
  64. Db::name('box')->where('status', 1)->save([
  65. 'status'=>2
  66. ]);
  67. $count = $info['buy_most']*(1+env('boxsetting.ONCEDAY_ADD_SCALE')/100);
  68. Db::name('box')->insert([
  69. 'buy_most'=>intval($count/10)*10,
  70. 'once_buy'=>$info['once_buy'],
  71. 'qi_count'=>$info['qi_count']+1,
  72. 'time_set'=>$info['time_set'],
  73. 'box_img'=>$info['box_img'],
  74. 'box_title'=>$info['box_title'],
  75. 'create_time'=>sr_getcurtime(time()),
  76. 'appoint_day'=>sr_getcurtime(time(), 'Y-m-d')
  77. ]);
  78. }
  79. }
  80. }