123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2020-09-27
- * Time: 15:38
- */
-
- namespace api\js\controller;
-
-
- use api\js\model\JsModel;
- use api\js\model\JsOrderModel;
- use api\js\model\JsProjectModel;
- use api\js\model\UserModel;
- use cmf\controller\RestBaseController;
- use JPush\Client;
- use JPush\Exceptions\APIConnectionException;
- use think\Db;
- use think\Exception;
- class SystemController extends RestBaseController
- {
- /**
- * 服务自动结束
- */
- public function automatic()
- {
- $JsOrderModel = new JsOrderModel();
- $list = $JsOrderModel::where('status',6)->field('id,jiedan_js_id,user_id,start_time,minute,jgpus,order_price,order_sn')->select();
-
-
-
-
-
- $info = cmf_get_option('jspus');
- // $js_client = new Client($info['js_app_key'],$info['js_master_secret']);
- // $client = new Client($info['app_key'],$info['master_secret']);
- foreach ($list as $vo){
-
-
- $url = '/pages/ddxq/ddxq?id='.$vo['id'];
- $jsuserid = $js_user_id = Db::name('js')->where('id',$vo['jiedan_js_id'])->value('user_id');
- $js_user_id.='js';
- if(($vo['start_time'] +$vo['minute'] * 60 - time()) <= 10*60 && $vo['jgpus'] == 0){
- //推送
- Db::name('js_order')->where('id',$vo['id'])->update(['jgpus'=>1]);
-
-
- $js_client = new Client($info['js_app_key'],$info['js_master_secret']);
- $client = new Client($info['app_key'],$info['master_secret']);
-
- $extras = [
- 'id' => $vo['id'],
- 'flag' => '用户',
- 'url' =>$url
- ];
- $array = [
- 'extras'=> $extras,
- ];
- $text= '服务还有10分钟结束';
- $platform = array('ios', 'android');
- $user_id = $vo['user_id'].'js';
-
- try{
- $client->push()
- ->setPlatform($platform)
- ->setNotificationAlert($text)
- ->iosNotification($text, $array)
- ->androidNotification($text, $array)
- ->addAlias("{$user_id}")
- ->send();
-
- }catch (APIConnectionException $e){
- // dump($e);
- $this->error('推送失败:'. $e);
- }catch (APIConnectionException $e){
- // print $e;
- $this->error('推送失败:'.$e);
- }
-
- $extras = [
- 'id' => $vo['id'],
- 'flag' => '技师端',
- 'url' =>$url
- ];
- $array = [
- 'extras'=> $extras,
- ];
- $text= '服务还有10分钟结束';
- try{
- $js_client->push()
- ->setPlatform($platform)
- ->setNotificationAlert($text)
- ->iosNotification($text, $array)
- ->androidNotification($text, $array)
- ->addAlias("{$js_user_id}")
- ->send();
- }catch (\JPush\Exceptions\APIConnectionException $e){
- // dump($e);
- // $this->error('推送失败:'. $e);
- }catch (\JPush\Exceptions\APIRequestException $e){
- // print $e;
- // $this->error('推送失败:'.$e);
- }
- }
- if(($vo['start_time'] + $vo['minute'] * 60) <= time() && $vo['jgpus'] == 1){
- Db::name('js_order')->where('id',$vo['id'])->update(['jgpus'=>2]);
- $JsOrderModel::where('id',$vo['id'])->update(['status'=>3,'finish_time'=>time()]);
- JsModel::where('id',$vo['jiedan_js_id'])->setInc('jiedan_num',1);
- $userDalance = UserModel::get($jsuserid)['balance'];
- if($vo['order_price'] > 0){
- UserModel::where('id',$jsuserid)->setInc('balance',$vo['order_price']);
- $log['user_id'] = $jsuserid;
- $log['money'] = $vo['order_price'];
- $log['order_sn'] = $vo['order_sn'];
- $log['yue'] = $userDalance + $vo['order_price'];
- $log['type'] = 8;
- $log['remark'] = '完成服务获得金额.';
- $log['add_time'] = time();
- $log['obj_id'] = $vo['id'];
- if($log['money'] != 0){
- Db::name('user_money_log')->insert($log);
- }
- }
- fenxiao($vo['id'],1);
- fenxiao($vo['id'],2);
- $js_user_id = Db::name('js')->where('id',$vo['jiedan_js_id'])->value('user_id');
- $js_user_id.='js';
- $js_client = new Client($info['js_app_key'],$info['js_master_secret']);
- $client = new Client($info['app_key'],$info['master_secret']);
- $platform = array('ios', 'android');
- $user_id = $vo['user_id'].'js';
- $extras = [
- 'id' => $vo['id'],
- 'flag' => '用户',
- 'url' => $url
- ];
- $array = [
- 'extras'=> $extras,
- ];
- $text= '服务已结束';
- try{
- $client->push()
- ->setPlatform($platform)
- ->setNotificationAlert($text)
- ->iosNotification($text, $array)
- ->androidNotification($text, $array)
- ->addAlias("{$user_id}")
- ->send();
-
- }catch (\JPush\Exceptions\APIConnectionException $e){
- // dump($e);
-
- }catch (\JPush\Exceptions\APIRequestException $e){
- // print $e;
- }
-
-
- $extras = [
- 'id' => $vo['id'],
- 'flag' => '技师端',
- 'url' => $url
- ];
- $array = [
- 'extras'=> $extras,
- ];
- $text= '服务已结束';
- try{
- $js_client->push()
- ->setPlatform($platform)
- ->setNotificationAlert($text)
- ->iosNotification($text, $array)
- ->androidNotification($text, $array)
- ->addAlias("{$js_user_id}")
- ->send();
-
- }catch (\JPush\Exceptions\APIConnectionException $e){
- // dump($e);
-
- // $this->error('推送失败:'. $e);
- }catch (\JPush\Exceptions\APIRequestException $e){
- // print $e;
-
- }
-
- }
- }
-
- }
-
-
- /**
- * 下单后无接单自动取消订单
- */
-
- public function cancelOrder()
- {
- $info = cmf_get_option('duration');
- $JsOrderModel = new JsOrderModel();
- $list = $JsOrderModel::where('status',1)->field('id,user_id,price,pay_price,create_time,type,appoint_time')->select();
- foreach ($list as $value){
- if($value['type'] == 1){
- if(time() > ($value['create_time']+$info['real_time']*3600)){
- if(Db::name('js_order')->where('id',$value['id'])->update(['status'=>5])){
- $outMoney = $value['pay_price'];
- if($outMoney > 0){
- $userDalance = UserModel::get($value['user_id'])['balance'];
- UserModel::where('id',$value['user_id'])->setInc('balance',$outMoney);
- $log['user_id'] = $value['user_id'];
- $log['money'] = $outMoney;
- $log['yue'] = $userDalance + $outMoney;
- $log['type'] = 2;
- $log['remark'] = '无技师接单,自动取消订单退款';
- $log['add_time'] = time();
- $log['obj_id'] = $value['id'];
- Db::name('user_money_log')->insert($log);
- }
- }
- }
- }
- if($value['type'] == 2){
- if(time() > (($value['create_time']+$value['appoint_time'])+$info['make_time']*3600)){
- if(Db::name('js_order')->where('id',$value['id'])->update(['status'=>5])){
- $outMoney = $value['pay_price'];
- if($outMoney > 0){
- UserModel::where('id',$value['user_id'])->setInc('balance',$outMoney);
- $userDalance = UserModel::get($value['user_id'])['balance'];
- $log['user_id'] = $value['user_id'];
- $log['money'] = $outMoney;
- $log['yue'] = $userDalance + $outMoney;
- $log['type'] = 2;
- $log['remark'] = '无技师接单,自动取消订单退款';
- $log['add_time'] = time();
- $log['obj_id'] = $value['id'];
- Db::name('user_money_log')->insert($log);
- }
- }
-
- }
- }
- }
- }
- public function getautomatic(){
- $str = cmf_curl_get('http://dd.yunjuhui.net/api/js/system/automatic');
- if(strlen($str)>0){
- file_put_contents('./autolog/autolog_'.date("YmdHis").'.txt',$str);
- }
-
- }
- public function tongji(){
- $sql = "SELECT count(id) as order_num,user_id FROM `xh_js_order` WHERE `status`=3 or `status`=4 group by user_id order by order_num desc";
- $list = Db::query($sql);
- foreach($list as $user){
- UserModel::where('id',$user['user_id'])->setField('order_num',$user['order_num']);
- }
- }
- }
|