OperationData.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. use app\admin\model\KefuWork;
  9. use app\admin\model\User;
  10. use app\manage\model\Config;
  11. /**
  12. * Worker 命令行类
  13. */
  14. class OperationData extends Command
  15. {
  16. public function configure()
  17. {
  18. $this->setName('operation:data')
  19. ->setDescription('每日0点统计前一天的数据');
  20. }
  21. public function execute(Input $input, Output $output)
  22. {
  23. //创建机器人客服的数据
  24. $autoTask=Config::autoTask();
  25. if ($autoTask &&!empty($autoTask['user_id'])) {
  26. $admin_id = User::getAdminId($autoTask['user_id']);
  27. $exists = KefuWork::where('admin_id', $admin_id)->where("created_at", '>=', date('Y-m-d'))->find();
  28. if (!$exists) {
  29. KefuWork::create([
  30. 'admin_id'=>$admin_id,
  31. ]);
  32. }
  33. }
  34. //统计前一天的接线总数
  35. $exists = OperationDataModel::where('type', 1)->where("date", date("Y-m-d", strtotime("-1 day")))->find();
  36. if (!$exists) {
  37. OperationDataModel::create([
  38. 'type' => 1,
  39. 'num' => $this->chatNum(),
  40. 'date' => date('Y-m-d', strtotime('-1 day')),
  41. ]);
  42. }
  43. }
  44. /**
  45. * 统计前一天的接线总数
  46. */
  47. public function chatNum()
  48. {
  49. return KefuTime::where('type', 3)
  50. ->where('created_at', '>=', date('Y-m-d 00:00:00', strtotime('-1 day')))
  51. ->where('created_at', '<=', date('Y-m-d 23:59:59', strtotime('-1 day')))
  52. ->count();
  53. }
  54. }