OperationData.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace app\admin\command;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\Output;
  6. use app\admin\model\OperationData as OperationDataModel;
  7. use app\admin\model\KefuTime;
  8. /**
  9. * Worker 命令行类
  10. */
  11. class OperationData extends Command
  12. {
  13. public function configure()
  14. {
  15. $this->setName('operation:data')
  16. ->setDescription('每日0点统计前一天的数据');
  17. }
  18. public function execute(Input $input, Output $output)
  19. {
  20. //统计前一天的接线总数
  21. OperationDataModel::create([
  22. 'type' => 1,
  23. 'num' => $this->chatNum(),
  24. 'date' => date('Y-m-d', strtotime('-1 day')),
  25. ]);
  26. }
  27. /**
  28. * 统计前一天的接线总数
  29. */
  30. public function chatNum()
  31. {
  32. return KefuTime::where('type', 3)
  33. ->where('created_at', '>=', date('Y-m-d 00:00:00', strtotime('-1 day')))
  34. ->where('created_at', '<=', date('Y-m-d 23:59:59', strtotime('-1 day')))
  35. ->count();
  36. }
  37. }