<?php /** * Created by PhpStorm. * User: Administrator * Date: 2019/6/7 * Time: 16:48 */ namespace app\portal\controller; use app\portal\model\IndentModel; use app\portal\model\LogisticsModel; use cmf\controller\HomeBaseController; use think\Db; class LoadController extends HomeBaseController { public function index(){ $indentModel = new IndentModel(); $where['state'] = ['eq',2]; $data = $indentModel->selectData($where); if(!empty($data)){ foreach($data as $key => $vo){ $birdController = new BirdController(); $result = $birdController->getOrder($vo['id']); } } } public function test(){ dump(cache('a1')); dump(cache('yuyue1')); dump(cache('dingyue1')); dump(cache('b')); dump(cache('result')); dump(cache('result_data')); } public function notify(){ $RequestType = empty($_POST['RequestType']) ? 0: $_POST['RequestType']; $RequestData = empty($_POST['RequestData']) ? 0: $_POST['RequestData']; if(empty($RequestType)){ $this->error('error'); } if($RequestType != 101){ $this->error('error'); } $result = json_decode($RequestData,true); cache('result',$result); cache('result_data',$result['Data']); $indentModel = new IndentModel(); foreach($result['Data'] as $key => $vo){ $indent = $indentModel->findData(['logistic_code'=>$vo['LogisticCode']]); if(!empty($indent)){ if($vo['State'] ==1 || $vo['State'] == 2){ if($indent['state'] == 2){ $indentModel->updateData(['id'=>$indent['id']],['state'=>5]); } } if($vo['State'] == 3){ $indentModel->updateData(['id'=>$indent['id']],['state'=>3]); } } } $bird = config('bird'); $date = date("Y-m-d H:i:s",time()); $data = '{ "EBusinessID": "'.$bird['EBusinessID'].'", "UpdateTime": "'.$date.'", "Success": true, "Reason": ""}'; cache('data',$data); return $data; } /** *服务器定时任务 删除超过24小时的订单 */ public function indent_overtime(){ //查询所有订单 $indent = Db::name('indent') -> where("state",4) -> select(); foreach ($indent as $key => $val){ $now_time = time(); $time = $now_time-$val['create_time']; if($time>86400){ Db::name('indent') -> delete($val['id']); } } } /** * 服务器定时任务 三个月未交易改变老师状态 */ public function binding(){ //查询所有业务员 $salesman = Db::name('my_user') -> where('status',2) -> select() -> toArray(); //查询这个业务员下的所有老师 foreach ($salesman as $key => $val){ $teacher = Db::name('my_user') -> where('pid',$val['id']) -> select() -> toArray(); //查询老师下的学生 foreach ($teacher as $key2 => $val2){ $student = Db::name('my_user') -> where('pid',$val2['id']) -> select() -> toArray(); //查询学生下的订单 foreach ($student as $key3 => $val3){ $student_indent[] = Db::name('indent') -> where('uid='.$val3['uid']) -> where("state = 2 or state = 3 or state = 5") -> select() -> toArray(); } //查询老师的订单 $teacher_indent = Db::name('indent') -> where("uid=".$val2['uid']) -> where("state = 2 or state = 3 or state = 5 ") -> select() -> toArray(); //判断订单状态 if(empty($teacher_indent) && empty($student_indent)){ $time = time()-$val2['bind_time']; //超过三个月修改订单状态 if($time >= 7776000){ Db::name('my_user') -> where('id',$val2['id']) -> update(['bind_status'=>2]); } } $student_indent = []; } } } }