OnedayUserDataupdate.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. // 更新用户所有昨日今日数据
  37. $list = Db::name('money_log')->where('type', 6)->whereDay('create_at', 'yesterday')->field('uid')->group('uid')->select();
  38. foreach ($list as $key => $val) {
  39. $money = Db::name('money_log')->where('type', 6)->whereDay('create_at', 'yesterday')->where('uid', $val['uid'])->sum('money');
  40. Db::name('user')->where('id', $val['uid'])->save([
  41. 'yesterday_money' => $money
  42. ]);
  43. }
  44. Db::name('user')->where('today_box', '>', 0)->save(['today_box' => 0]);
  45. Db::name('user')->where('today_team_box', '>', 0)->save(['today_team_box' => 0]);
  46. // 开启下一期 福袋预约
  47. $max_id = Db::name('box')->where('status', 1)->max('id');
  48. $info = Db::name('box')->where('id', $max_id)->find();
  49. if ($info) {
  50. Db::name('box')->where('status', 1)->save([
  51. 'status' => 2
  52. ]);
  53. $count = $info['buy_most'] * (1 + env('boxsetting.ONCEDAY_ADD_SCALE') / 100);
  54. Db::name('box')->insert([
  55. 'buy_most' => intval($count / 10) * 10,
  56. 'once_buy' => $info['once_buy'],
  57. 'qi_count' => $info['qi_count'] + 1,
  58. 'time_set' => $info['time_set'],
  59. 'box_img' => $info['box_img'],
  60. 'box_title' => $info['box_title'],
  61. 'create_time' => sr_getcurtime(time()),
  62. 'appoint_day' => sr_getcurtime(time(), 'Y-m-d')
  63. ]);
  64. }
  65. }
  66. }