SystemController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020-09-27
  6. * Time: 15:38
  7. */
  8. namespace api\js\controller;
  9. use api\js\model\JsModel;
  10. use api\js\model\JsOrderModel;
  11. use api\js\model\JsProjectModel;
  12. use api\js\model\UserModel;
  13. use cmf\controller\RestBaseController;
  14. use JPush\Client;
  15. use JPush\Exceptions\APIConnectionException;
  16. use think\Db;
  17. use think\Exception;
  18. class SystemController extends RestBaseController
  19. {
  20. /**
  21. * 服务自动结束
  22. */
  23. public function automatic()
  24. {
  25. $JsOrderModel = new JsOrderModel();
  26. $list = $JsOrderModel::where('status',6)->field('id,jiedan_js_id,user_id,start_time,minute,jgpus,order_price,order_sn')->select();
  27. $info = cmf_get_option('jspus');
  28. // $js_client = new Client($info['js_app_key'],$info['js_master_secret']);
  29. // $client = new Client($info['app_key'],$info['master_secret']);
  30. foreach ($list as $vo){
  31. $url = '/pages/ddxq/ddxq?id='.$vo['id'];
  32. $jsuserid = $js_user_id = Db::name('js')->where('id',$vo['jiedan_js_id'])->value('user_id');
  33. $js_user_id.='js';
  34. if(($vo['start_time'] +$vo['minute'] * 60 - time()) <= 10*60 && $vo['jgpus'] == 0){
  35. //推送
  36. Db::name('js_order')->where('id',$vo['id'])->update(['jgpus'=>1]);
  37. $js_client = new Client($info['js_app_key'],$info['js_master_secret']);
  38. $client = new Client($info['app_key'],$info['master_secret']);
  39. $extras = [
  40. 'id' => $vo['id'],
  41. 'flag' => '用户',
  42. 'url' =>$url
  43. ];
  44. $array = [
  45. 'extras'=> $extras,
  46. ];
  47. $text= '服务还有10分钟结束';
  48. $platform = array('ios', 'android');
  49. $user_id = $vo['user_id'].'js';
  50. try{
  51. $client->push()
  52. ->setPlatform($platform)
  53. ->setNotificationAlert($text)
  54. ->iosNotification($text, $array)
  55. ->androidNotification($text, $array)
  56. ->addAlias("{$user_id}")
  57. ->send();
  58. }catch (APIConnectionException $e){
  59. // dump($e);
  60. $this->error('推送失败:'. $e);
  61. }catch (APIConnectionException $e){
  62. // print $e;
  63. $this->error('推送失败:'.$e);
  64. }
  65. $extras = [
  66. 'id' => $vo['id'],
  67. 'flag' => '技师端',
  68. 'url' =>$url
  69. ];
  70. $array = [
  71. 'extras'=> $extras,
  72. ];
  73. $text= '服务还有10分钟结束';
  74. try{
  75. $js_client->push()
  76. ->setPlatform($platform)
  77. ->setNotificationAlert($text)
  78. ->iosNotification($text, $array)
  79. ->androidNotification($text, $array)
  80. ->addAlias("{$js_user_id}")
  81. ->send();
  82. }catch (\JPush\Exceptions\APIConnectionException $e){
  83. // dump($e);
  84. // $this->error('推送失败:'. $e);
  85. }catch (\JPush\Exceptions\APIRequestException $e){
  86. // print $e;
  87. // $this->error('推送失败:'.$e);
  88. }
  89. }
  90. if(($vo['start_time'] + $vo['minute'] * 60) <= time() && $vo['jgpus'] == 1){
  91. Db::name('js_order')->where('id',$vo['id'])->update(['jgpus'=>2]);
  92. $JsOrderModel::where('id',$vo['id'])->update(['status'=>3,'finish_time'=>time()]);
  93. JsModel::where('id',$vo['jiedan_js_id'])->setInc('jiedan_num',1);
  94. $userDalance = UserModel::get($jsuserid)['balance'];
  95. if($vo['order_price'] > 0){
  96. UserModel::where('id',$jsuserid)->setInc('balance',$vo['order_price']);
  97. $log['user_id'] = $jsuserid;
  98. $log['money'] = $vo['order_price'];
  99. $log['order_sn'] = $vo['order_sn'];
  100. $log['yue'] = $userDalance + $vo['order_price'];
  101. $log['type'] = 8;
  102. $log['remark'] = '完成服务获得金额.';
  103. $log['add_time'] = time();
  104. $log['obj_id'] = $vo['id'];
  105. if($log['money'] != 0){
  106. Db::name('user_money_log')->insert($log);
  107. }
  108. }
  109. fenxiao($vo['id'],1);
  110. fenxiao($vo['id'],2);
  111. $js_user_id = Db::name('js')->where('id',$vo['jiedan_js_id'])->value('user_id');
  112. $js_user_id.='js';
  113. $js_client = new Client($info['js_app_key'],$info['js_master_secret']);
  114. $client = new Client($info['app_key'],$info['master_secret']);
  115. $platform = array('ios', 'android');
  116. $user_id = $vo['user_id'].'js';
  117. $extras = [
  118. 'id' => $vo['id'],
  119. 'flag' => '用户',
  120. 'url' => $url
  121. ];
  122. $array = [
  123. 'extras'=> $extras,
  124. ];
  125. $text= '服务已结束';
  126. try{
  127. $client->push()
  128. ->setPlatform($platform)
  129. ->setNotificationAlert($text)
  130. ->iosNotification($text, $array)
  131. ->androidNotification($text, $array)
  132. ->addAlias("{$user_id}")
  133. ->send();
  134. }catch (\JPush\Exceptions\APIConnectionException $e){
  135. // dump($e);
  136. }catch (\JPush\Exceptions\APIRequestException $e){
  137. // print $e;
  138. }
  139. $extras = [
  140. 'id' => $vo['id'],
  141. 'flag' => '技师端',
  142. 'url' => $url
  143. ];
  144. $array = [
  145. 'extras'=> $extras,
  146. ];
  147. $text= '服务已结束';
  148. try{
  149. $js_client->push()
  150. ->setPlatform($platform)
  151. ->setNotificationAlert($text)
  152. ->iosNotification($text, $array)
  153. ->androidNotification($text, $array)
  154. ->addAlias("{$js_user_id}")
  155. ->send();
  156. }catch (\JPush\Exceptions\APIConnectionException $e){
  157. // dump($e);
  158. // $this->error('推送失败:'. $e);
  159. }catch (\JPush\Exceptions\APIRequestException $e){
  160. // print $e;
  161. }
  162. }
  163. }
  164. }
  165. /**
  166. * 下单后无接单自动取消订单
  167. */
  168. public function cancelOrder()
  169. {
  170. $info = cmf_get_option('duration');
  171. $JsOrderModel = new JsOrderModel();
  172. $list = $JsOrderModel::where('status',1)->field('id,user_id,price,pay_price,create_time,type,appoint_time')->select();
  173. foreach ($list as $value){
  174. if($value['type'] == 1){
  175. if(time() > ($value['create_time']+$info['real_time']*3600)){
  176. if(Db::name('js_order')->where('id',$value['id'])->update(['status'=>5])){
  177. $outMoney = $value['pay_price'];
  178. if($outMoney > 0){
  179. $userDalance = UserModel::get($value['user_id'])['balance'];
  180. UserModel::where('id',$value['user_id'])->setInc('balance',$outMoney);
  181. $log['user_id'] = $value['user_id'];
  182. $log['money'] = $outMoney;
  183. $log['yue'] = $userDalance + $outMoney;
  184. $log['type'] = 2;
  185. $log['remark'] = '无技师接单,自动取消订单退款';
  186. $log['add_time'] = time();
  187. $log['obj_id'] = $value['id'];
  188. Db::name('user_money_log')->insert($log);
  189. }
  190. }
  191. }
  192. }
  193. if($value['type'] == 2){
  194. if(time() > (($value['create_time']+$value['appoint_time'])+$info['make_time']*3600)){
  195. if(Db::name('js_order')->where('id',$value['id'])->update(['status'=>5])){
  196. $outMoney = $value['pay_price'];
  197. if($outMoney > 0){
  198. UserModel::where('id',$value['user_id'])->setInc('balance',$outMoney);
  199. $userDalance = UserModel::get($value['user_id'])['balance'];
  200. $log['user_id'] = $value['user_id'];
  201. $log['money'] = $outMoney;
  202. $log['yue'] = $userDalance + $outMoney;
  203. $log['type'] = 2;
  204. $log['remark'] = '无技师接单,自动取消订单退款';
  205. $log['add_time'] = time();
  206. $log['obj_id'] = $value['id'];
  207. Db::name('user_money_log')->insert($log);
  208. }
  209. }
  210. }
  211. }
  212. }
  213. }
  214. public function getautomatic(){
  215. $str = cmf_curl_get('http://dd.yunjuhui.net/api/js/system/automatic');
  216. if(strlen($str)>0){
  217. file_put_contents('./autolog/autolog_'.date("YmdHis").'.txt',$str);
  218. }
  219. }
  220. public function tongji(){
  221. $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";
  222. $list = Db::query($sql);
  223. foreach($list as $user){
  224. UserModel::where('id',$user['user_id'])->setField('order_num',$user['order_num']);
  225. }
  226. }
  227. }