OperationData.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // $list = KefuTime::where('status', 0)->where("created_at", '<', date("Y-m-d"))->order('id', 'desc')->select()->toArray();
  22. // foreach($list as $item) {
  23. // KefuTime::where('id', $item['id'])->update([
  24. // 'status' => 1,
  25. // 'end_time' => time(),
  26. // ]);
  27. // KefuTime::addData($item['admin_id'], $item['type']);
  28. // }
  29. //统计前一天的接线总数
  30. $exists = OperationDataModel::where('type', 1)->where("date", date("Y-m-d", strtotime("-1 day")))->find();
  31. if (!$exists) {
  32. OperationDataModel::create([
  33. 'type' => 1,
  34. 'num' => $this->chatNum(),
  35. 'date' => date('Y-m-d', strtotime('-1 day')),
  36. ]);
  37. }
  38. }
  39. /**
  40. * 统计前一天的接线总数
  41. */
  42. public function chatNum()
  43. {
  44. return KefuTime::where('type', 3)
  45. ->where('created_at', '>=', date('Y-m-d 00:00:00', strtotime('-1 day')))
  46. ->where('created_at', '<=', date('Y-m-d 23:59:59', strtotime('-1 day')))
  47. ->count();
  48. }
  49. }