GetUserTeamMoney.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\api\command;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\Output;
  7. use think\facade\Db;
  8. /**
  9. * 结算今日奖金 by wes
  10. * Class GetUserTeamMoney
  11. * @package app\api\command
  12. */
  13. class GetUserTeamMoney extends Command
  14. {
  15. protected function configure()
  16. {
  17. // 获取用户今日奖金
  18. $this->setName('get_user_team_money')
  19. ->setDescription('the get_user_team_money command');
  20. }
  21. protected function execute(Input $input, Output $output)
  22. {
  23. Db::startTrans();
  24. try {
  25. $list = Db::name('user')->where('today_money', '>', 0)->select();
  26. foreach ($list as $key=>$val){
  27. edit_user_money(6, $val['id'], $val['today_money']);
  28. // 累计奖金
  29. Db::name('user')->where('id', $val['id'])->inc('todayaward_money', floatval($val['today_money']))->update();
  30. }
  31. Db::name('user')->where('today_money', '>', 0)->save(['today_money'=>0]);
  32. Db::commit();
  33. }catch (\Exception $e){
  34. Db::rollback();
  35. $output->writeln('key'.$e->getMessage());
  36. return 22;
  37. }
  38. return 22;
  39. }
  40. }