OperationData.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // $autoTask=Config::autoTask();
  22. // if ($autoTask &&!empty($autoTask['user_id'])) {
  23. // $admin_id = User::getAdminId($autoTask['user_id']);
  24. // $exists = KefuWork::where('admin_id', $admin_id)->where("created_at", '>=', date('Y-m-d'))->find();
  25. // if (!$exists) {
  26. // KefuWork::create([
  27. // 'admin_id'=>$admin_id,
  28. // ]);
  29. // }
  30. // }
  31. //统计前一天的接线总数
  32. $exists = OperationDataModel::where('type', 1)->where("date", date("Y-m-d", strtotime("-1 day")))->find();
  33. if (!$exists) {
  34. OperationDataModel::create([
  35. 'type' => 1,
  36. 'num' => $this->chatNum(),
  37. 'date' => date('Y-m-d', strtotime('-1 day')),
  38. ]);
  39. }
  40. }
  41. /**
  42. * 统计前一天的接线总数
  43. */
  44. public function chatNum()
  45. {
  46. return KefuTime::where('type', 3)
  47. ->where('created_at', '>=', date('Y-m-d 00:00:00', strtotime('-1 day')))
  48. ->where('created_at', '<=', date('Y-m-d 23:59:59', strtotime('-1 day')))
  49. ->count();
  50. }
  51. }