Task.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\api\command;
  3. use app\common\logic\ScanLogic;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\Output;
  7. use app\common\model\ProductOrder;
  8. use app\common\model\UserModel;
  9. use think\Model;
  10. class Task extends Command
  11. {
  12. protected function configure()
  13. {
  14. $this->setName('task')->setDescription('Here is the remark ');
  15. }
  16. protected function execute(Input $input, Output $output)
  17. {
  18. /* 永不超时 */
  19. // ini_set('max_execution_time', 0);
  20. // 记录开始运行的时间
  21. $GLOBALS['_beginTime'] = microtime(TRUE);
  22. $output->writeln('定时任务开始执行:' . date('Y-m-d H:i:s', time()));
  23. /*** 发放分红收益 ***/
  24. $output->writeln("开始发放加权分红:");
  25. $i = 0;
  26. $count = $this->reset_user_pledge($i);
  27. $output->writeln('定时任务执行结束,总执行:' . $count . '个');
  28. }
  29. public function reset_user_pledge(&$i){
  30. $productOrder = new ProductOrder(); //Loader::model('ProductOrder');
  31. $num = 6; //空投数量
  32. $ids = 14; //空投产品
  33. UserModel::chunk(500, function($items) use (&$i,$num , $ids, $productOrder) {
  34. foreach ($items as $item) {
  35. // 判断空投是否只够6个
  36. $res = $productOrder::where('user_id', $item->id)->where('product_id', $ids)->where('type_id', 5)->count();
  37. if($res < 6){
  38. $num = $num - $res;
  39. $productOrder::setPopularNoAreaOrder($num, 0, 0, $ids, $item->id, 5);
  40. $i ++;
  41. }
  42. }
  43. });
  44. return $i;
  45. }
  46. }