setName('operation:data') ->setDescription('每日0点统计前一天的数据'); } public function execute(Input $input, Output $output) { // //创建机器人客服的数据 // $autoTask=Config::autoTask(); // if ($autoTask &&!empty($autoTask['user_id'])) { // $admin_id = User::getAdminId($autoTask['user_id']); // $exists = KefuWork::where('admin_id', $admin_id)->where("created_at", '>=', date('Y-m-d'))->find(); // if (!$exists) { // KefuWork::create([ // 'admin_id'=>$admin_id, // ]); // } // } //统计前一天的接线总数 $exists = OperationDataModel::where('type', 1)->where("date", date("Y-m-d", strtotime("-1 day")))->find(); if (!$exists) { OperationDataModel::create([ 'type' => 1, 'num' => $this->chatNum(), 'date' => date('Y-m-d', strtotime('-1 day')), ]); } } /** * 统计前一天的接线总数 */ public function chatNum() { return KefuTime::where('type', 3) ->where('created_at', '>=', date('Y-m-d 00:00:00', strtotime('-1 day'))) ->where('created_at', '<=', date('Y-m-d 23:59:59', strtotime('-1 day'))) ->count(); } }