// +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Date: 2017-5-25 // +---------------------------------------------------------------------- namespace api\crontab\controller; use api\common\Sms; use app\talent\model\TalentAppointmentLogModel; use app\talent\model\TalentAppointmentModel; class TalentController { /** * 主方法 */ public function index() { $this->_dealRateMsg(); // $this->_test(); return 'OK'; } /** * 发送短信 */ public function _dealRateMsg() { $yesterday = date('Y-m-d', strtotime('-1 day')); $list = TalentAppointmentLogModel::with(['appointment.talent']) ->where(function($query){ $query->where('content', '通过手机号接站,接到了人才')->whereOr('content','通过扫码接站,接到了人才'); }) ->whereBetween('create_time', [$yesterday . ' 00:00:00', $yesterday . ' 23:59:59']) ->select(); if (!$list->isEmpty()) { //短信 $sms = new Sms(); foreach ($list as $v) { $sms->send($v['appointment']['talent']['mobile'],'talent_appointment_end'); } } } public function _test() { $today = date('Y-m-d'); $list = TalentAppointmentModel::where('out_time','between',[$today.' 00:00:00',$today.' 23:59:59'])->order('out_time asc')->select(); $res = []; foreach ($list as $v) { $hour = date('H:00',strtotime($v['out_time'])); if (empty($res)) { $res[$hour] = [ 'hour' => $hour, 'list' => [], ]; } $res[$hour]['list'][] = $v->toArray(); } halt(array_values($res)); } }