作者 黄超

Merge branch 'master' of 47.108.67.251:lubenwei/wyc.tenyes.cn

@@ -12,4 +12,8 @@ public/.htaccess @@ -12,4 +12,8 @@ public/.htaccess
12 public/.user.ini 12 public/.user.ini
13 public/nginx.htaccess 13 public/nginx.htaccess
14 .htaccess 14 .htaccess
15 -public/.well-known/  
  15 +public/.well-known/
  16 +public/kevin_wx_xcx_push.log
  17 +public/pcl_pay_logs.log
  18 +public/pcl_pay_p.log
  19 +public/pcl_repay_v2.log
@@ -82,13 +82,21 @@ class Order extends Backend @@ -82,13 +82,21 @@ class Order extends Backend
82 82
83 public function refund($id) 83 public function refund($id)
84 { 84 {
85 - $res=$this->refundSendMessage($id);  
86 - print_r($res);return; 85 +
87 //查询订单 86 //查询订单
88 $order = Db::name("order")->where("id", $id)->find(); 87 $order = Db::name("order")->where("id", $id)->find();
89 if ($order['is_pay'] != 1) { 88 if ($order['is_pay'] != 1) {
90 $this->error("该订单无法退款"); 89 $this->error("该订单无法退款");
91 } 90 }
  91 + if($order['pay_type']="offlinepay"){
  92 + $relogs['update_time'] = time();
  93 + $relogs['is_pay'] = 3;
  94 + $relogs['refund_time'] = time();
  95 + $rs2 = Db::name('order')
  96 + ->where(['id' => $order['id']])
  97 + ->update($relogs);
  98 + $this->success("退款成功");
  99 + }
92 //拼接退款参数 100 //拼接退款参数
93 $pay_fee = $order['price']; 101 $pay_fee = $order['price'];
94 $refund_fee = $pay_fee; 102 $refund_fee = $pay_fee;
@@ -165,6 +165,29 @@ if (!function_exists('getOrderSn')) { @@ -165,6 +165,29 @@ if (!function_exists('getOrderSn')) {
165 } 165 }
166 } 166 }
167 } 167 }
  168 + if(!function_exists('OrderSendMessage')){
  169 + /**
  170 + * 发送模板消息
  171 + * @return void
  172 + * @throws \think\db\exception\DataNotFoundException
  173 + * @throws \think\db\exception\ModelNotFoundException
  174 + * @throws \think\exception\DbException
  175 + */
  176 + function OrderSendMessage($order_id){
  177 + $order=\think\Db::name("order")->find($order_id);
  178 + $wxxcxpush=new WxxcxPush();
  179 + $user=new User();
  180 + $user=$user->find($order['user_id']);
  181 + $driver=new \app\admin\model\Driver();
  182 + $driver=$driver->find($order['driver_id']);
  183 + $driver_user=$user->find($driver['user_id']);
  184 + $res=$wxxcxpush->Message($driver_user['wx_xcx_openid'],$order_id);
  185 + $res=$wxxcxpush->Message($user['wx_xcx_openid'],$order_id);
  186 + if ($res !== false) {
  187 + return $res;
  188 + }
  189 + }
  190 + }
168 191
169 192
170 if(!function_exists('beingPushed')){ 193 if(!function_exists('beingPushed')){
@@ -24,7 +24,9 @@ class Car extends Base @@ -24,7 +24,9 @@ class Car extends Base
24 */ 24 */
25 public function selectroute() 25 public function selectroute()
26 { 26 {
27 - $res = Db::name("route")->field("id,name,price,start_address,end_address")->limit(2)->select(); 27 + $res = Db::name("route")
  28 + ->field("id,name,price,start_address,end_address")
  29 + ->select();
28 return $this->success($res); 30 return $this->success($res);
29 } 31 }
30 32
@@ -1615,7 +1617,7 @@ class Car extends Base @@ -1615,7 +1617,7 @@ class Car extends Base
1615 $this->success("请求成功",$data); 1617 $this->success("请求成功",$data);
1616 } 1618 }
1617 public function SendMessage($id){ 1619 public function SendMessage($id){
1618 - $res=SendMessage($id); 1620 + $res=OrderSendMessage(229);
1619 $this->success("推送成功",$res); 1621 $this->success("推送成功",$res);
1620 } 1622 }
1621 1623
@@ -26,7 +26,7 @@ class WxxcxPush extends Base @@ -26,7 +26,7 @@ class WxxcxPush extends Base
26 public function sendDealApplyMessage($openid_arr, $apply_info) 26 public function sendDealApplyMessage($openid_arr, $apply_info)
27 { 27 {
28 if (empty($openid_arr)) { 28 if (empty($openid_arr)) {
29 - return array_callback(false, "未找到需要推送的人员"); 29 + return $this->array_callback(false, "未找到需要推送的人员");
30 } 30 }
31 $sum_count = 0;//总共需要推送的人 31 $sum_count = 0;//总共需要推送的人
32 $react_count = 0;//实际推送人数 32 $react_count = 0;//实际推送人数
@@ -90,15 +90,15 @@ class WxxcxPush extends Base @@ -90,15 +90,15 @@ class WxxcxPush extends Base
90 90
91 // 执行提交操作 91 // 执行提交操作
92 Db::commit(); 92 Db::commit();
93 - return array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]); 93 + return $this->array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);
94 94
95 } catch (PDOException $e) { 95 } catch (PDOException $e) {
96 Db::rollback(); 96 Db::rollback();
97 - return array_callback(false, "请求异常" . $e->getMessage()); 97 + return $this->array_callback(false, "请求异常" . $e->getMessage());
98 } 98 }
99 99
100 } else { 100 } else {
101 - return array_callback(false, "未找到可通知的社区管理员!"); 101 + return $this->array_callback(false, "未找到可通知的社区管理员!");
102 } 102 }
103 103
104 104
@@ -110,7 +110,7 @@ class WxxcxPush extends Base @@ -110,7 +110,7 @@ class WxxcxPush extends Base
110 public function sendDealSuccessMessage($openid_arr, $deal_info) 110 public function sendDealSuccessMessage($openid_arr, $deal_info)
111 { 111 {
112 if (empty($openid_arr)) { 112 if (empty($openid_arr)) {
113 - return array_callback(false, "未找到需要推送的人员"); 113 + return $this->array_callback(false, "未找到需要推送的人员");
114 } 114 }
115 $sum_count = 0;//总共需要推送的人 115 $sum_count = 0;//总共需要推送的人
116 $react_count = 0;//实际推送人数 116 $react_count = 0;//实际推送人数
@@ -168,15 +168,15 @@ class WxxcxPush extends Base @@ -168,15 +168,15 @@ class WxxcxPush extends Base
168 168
169 // 执行提交操作 169 // 执行提交操作
170 Db::commit(); 170 Db::commit();
171 - return array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]); 171 + return $this->array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);
172 172
173 } catch (PDOException $e) { 173 } catch (PDOException $e) {
174 Db::rollback(); 174 Db::rollback();
175 - return array_callback(false, "请求异常" . $e->getMessage()); 175 + return $this->array_callback(false, "请求异常" . $e->getMessage());
176 } 176 }
177 177
178 } else { 178 } else {
179 - return array_callback(false, "未找到可通知的申报用户!"); 179 + return $this->array_callback(false, "未找到可通知的申报用户!");
180 } 180 }
181 181
182 } 182 }
@@ -187,7 +187,7 @@ class WxxcxPush extends Base @@ -187,7 +187,7 @@ class WxxcxPush extends Base
187 public function sendUploadReportMessage($openid_arr, $deal_info,$report) 187 public function sendUploadReportMessage($openid_arr, $deal_info,$report)
188 { 188 {
189 if (empty($openid_arr)) { 189 if (empty($openid_arr)) {
190 - return array_callback(false, "未找到需要推送的人员"); 190 + return $this->array_callback(false, "未找到需要推送的人员");
191 } 191 }
192 $sum_count = 0;//总共需要推送的人 192 $sum_count = 0;//总共需要推送的人
193 $react_count = 0;//实际推送人数 193 $react_count = 0;//实际推送人数
@@ -244,15 +244,15 @@ class WxxcxPush extends Base @@ -244,15 +244,15 @@ class WxxcxPush extends Base
244 244
245 // 执行提交操作 245 // 执行提交操作
246 Db::commit(); 246 Db::commit();
247 - return array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]); 247 + return $this->array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);
248 248
249 } catch (PDOException $e) { 249 } catch (PDOException $e) {
250 Db::rollback(); 250 Db::rollback();
251 - return array_callback(false, "请求异常" . $e->getMessage()); 251 + return $this->array_callback(false, "请求异常" . $e->getMessage());
252 } 252 }
253 253
254 } else { 254 } else {
255 - return array_callback(false, "未找到可通知的监测人员!"); 255 + return $this->array_callback(false, "未找到可通知的监测人员!");
256 } 256 }
257 257
258 } 258 }
@@ -264,7 +264,7 @@ class WxxcxPush extends Base @@ -264,7 +264,7 @@ class WxxcxPush extends Base
264 public function sendWorkorderMessage($id,$temp) 264 public function sendWorkorderMessage($id,$temp)
265 { 265 {
266 if (empty($id)) { 266 if (empty($id)) {
267 - return array_callback(false, "id不能为空"); 267 + return $this->array_callback(false, "id不能为空");
268 } 268 }
269 $workorderInfo = Db::name("workorder_orders")->where("id", $id)->find(); 269 $workorderInfo = Db::name("workorder_orders")->where("id", $id)->find();
270 270
@@ -315,24 +315,24 @@ class WxxcxPush extends Base @@ -315,24 +315,24 @@ class WxxcxPush extends Base
315 315
316 // 执行提交操作 316 // 执行提交操作
317 Db::commit(); 317 Db::commit();
318 - return array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]); 318 + return $this->array_callback(true, "推送成功", ["sum_count" => $sum_count, "react_count" => $react_count]);
319 319
320 } catch (PDOException $e) { 320 } catch (PDOException $e) {
321 Db::rollback(); 321 Db::rollback();
322 - return array_callback(false, "请求异常" . $e->getMessage()); 322 + return $this->array_callback(false, "请求异常" . $e->getMessage());
323 } 323 }
324 324
325 } else { 325 } else {
326 - return array_callback(false, "未找到可通知的成员!"); 326 + return $this->array_callback(false, "未找到可通知的成员!");
327 } 327 }
328 328
329 } else { 329 } else {
330 - return array_callback(false, "未找到推送人员"); 330 + return $this->array_callback(false, "未找到推送人员");
331 } 331 }
332 332
333 333
334 } else { 334 } else {
335 - return array_callback(false, "未查找到有效的工单数据"); 335 + return $this->array_callback(false, "未查找到有效的工单数据");
336 } 336 }
337 337
338 338
@@ -402,16 +402,16 @@ class WxxcxPush extends Base @@ -402,16 +402,16 @@ class WxxcxPush extends Base
402 if (!empty($res_arr) && $res_arr['errcode'] == "0") { 402 if (!empty($res_arr) && $res_arr['errcode'] == "0") {
403 } else { 403 } else {
404 //推送失败,记录问题 404 //推送失败,记录问题
405 - return array_callback(true, "推1送成功".json_encode($res_arr)); 405 + return $this->array_callback(true, "推1送成功".json_encode($res_arr));
406 $insert_message_log_data['error_tips'] = json_encode($res_arr, JSON_UNESCAPED_UNICODE); 406 $insert_message_log_data['error_tips'] = json_encode($res_arr, JSON_UNESCAPED_UNICODE);
407 } 407 }
408 // 执行提交操作 408 // 执行提交操作
409 Db::commit(); 409 Db::commit();
410 - return array_callback(true, "推送成功"); 410 + return $this->array_callback(true, "推送成功");
411 411
412 } catch (PDOException $e) { 412 } catch (PDOException $e) {
413 Db::rollback(); 413 Db::rollback();
414 - return array_callback(false, "请求异常" . $e->getMessage()); 414 + return $this->array_callback(false, "请求异常" . $e->getMessage());
415 } 415 }
416 416
417 417
@@ -442,26 +442,228 @@ class WxxcxPush extends Base @@ -442,26 +442,228 @@ class WxxcxPush extends Base
442 'value5' => $reservation['remarks'], 442 'value5' => $reservation['remarks'],
443 ); 443 );
444 444
445 - $res = beingPushed(6, $openid, $page, $insert_message_log_data); 445 + $res = $this->beingPushed(6, $openid, $page, $insert_message_log_data);
446 446
447 file_put_contents("kevin_wx_xcx_push.log", date("Y-m-d H:i:s") . "《" . $reservation_id . "》" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND); 447 file_put_contents("kevin_wx_xcx_push.log", date("Y-m-d H:i:s") . "《" . $reservation_id . "》" . json_encode($res, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
448 $res_arr = !empty($res) ? json_decode($res, true) : []; 448 $res_arr = !empty($res) ? json_decode($res, true) : [];
449 if (!empty($res_arr) && $res_arr['errcode'] == "0") { 449 if (!empty($res_arr) && $res_arr['errcode'] == "0") {
450 } else { 450 } else {
451 //推送失败,记录问题 451 //推送失败,记录问题
452 - return array_callback(true, "推1送成功".json_encode($res_arr)); 452 + return $this->$this->array_callback(true, "推1送成功".json_encode($res_arr));
453 $insert_message_log_data['error_tips'] = json_encode($res_arr, JSON_UNESCAPED_UNICODE); 453 $insert_message_log_data['error_tips'] = json_encode($res_arr, JSON_UNESCAPED_UNICODE);
454 } 454 }
455 // 执行提交操作 455 // 执行提交操作
456 Db::commit(); 456 Db::commit();
457 - return array_callback(true, "推送成功"); 457 + return $this->$this->array_callback(true, "推送成功");
458 458
459 } catch (PDOException $e) { 459 } catch (PDOException $e) {
460 Db::rollback(); 460 Db::rollback();
461 - return array_callback(false, "请求异常" . $e->getMessage()); 461 + return $this->$this->array_callback(false, "请求异常" . $e->getMessage());
462 } 462 }
463 463
464 464
465 } 465 }
466 } 466 }
  467 + /**
  468 + * 小程序模板推送选择类型
  469 + * @param $type @模板类型
  470 + * @param $openid @接收人ID
  471 + * @param $page @跳转页面
  472 + * @param $temp @具体提醒参数
  473 + * @throws \think\Exception
  474 + * @throws \think\exception\PDOException
  475 + */
  476 + function beingPushed($type, $openid, $page, $temp)
  477 + {
  478 +
  479 + $data = [];
  480 + $data['touser'] = $openid;
  481 + $data['page'] = $page;
  482 + //模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
  483 + switch ($type) {
  484 + case 1:
  485 + //待审批事项提醒(新版本的长期订阅)
  486 + $data['template_id'] = "ws6bz6-WyHHA-upU2oRzc_C5toDUexe9ZicQ-ITtImA";
  487 + $data['data'] = [
  488 + "thing10" => [
  489 + 'value' =>$temp['value1'],//审核状态(待处理)
  490 + ],
  491 + "thing12" => [
  492 + 'value' => $temp['value2'],//申请人(测试黄超)
  493 + ],
  494 +
  495 + "thing8" => [
  496 + 'value' => $temp['value3'],//原因(入州报备审核)
  497 + ]
  498 + ];
  499 + break;
  500 + case 2:
  501 + //审核结果通知(新版本的长期订阅)
  502 + $data['template_id'] = "Qt2xqfH8uQyTm1A0ReNxeybtAydAhfhi4HinnyB5f0s";
  503 + $data['data'] = [
  504 + "thing1" => [
  505 + 'value' => $temp['value1'],//提醒内容(已审核)
  506 + ],
  507 +// "name1" => [
  508 +// 'value' => $temp['value2'],//审核人
  509 +// ],
  510 + "thing4" => [
  511 + 'value' => $temp['value3'],//提示说明
  512 + ]
  513 + ];
  514 + break;
  515 + case 3:
  516 + //待审批事项提醒(老版本的一次性订阅)
  517 + $data['template_id'] = "vVOonN76AFjxgz77iG-hcWrH6HJ-vPGKyIyAK0VzPIk";
  518 + $data['data'] = [
  519 + "thing1" => [
  520 + 'value' => $temp['value1'],//待办事项
  521 + ],
  522 + "thing4" => [
  523 + 'value' => $temp['value2'],//流程状态
  524 + ],
  525 + "thing2" => [
  526 + 'value' => $temp['value3'],//申请人
  527 + ],
  528 + "time3" => [
  529 + 'value' => $temp['value4'],//申请时间
  530 + ],
  531 + "thing5" => [
  532 + 'value' => $temp['value5'],//备注描述
  533 + ]
  534 + ];
  535 + break;
  536 + case 4:
  537 + //审核结果通知(老版本的一次性订阅)
  538 + $data['template_id'] = "qR9reAuv_Ulelyg1H2xbN-GoWGWFRhS0t4nhtvnFr5Q";
  539 + $data['data'] = [
  540 + "character_string1" => [
  541 + 'value' => $temp['value1'],//审核结果
  542 + ],
  543 + "date3" => [
  544 + 'value' => $temp['value2'],//审核人
  545 + ],
  546 + "thing5" => [
  547 + 'value' => $temp['value3'],//审批时间
  548 + ],
  549 + "thing6" => [
  550 + 'value' => $temp['value4'],//审批时间
  551 + ],
  552 + "thing7" => [
  553 + 'value' => $temp['value5'],//审批时间
  554 + ]
  555 + ];
  556 + break;
  557 + case 5:
  558 + //预约结果通知
  559 + $data['template_id'] = "oczyQ_SabASMQRRhDedXRGUEzCAuGh1xBw8sp2HVPvQ";
  560 + $data['data'] = [
  561 + "thing1" => [
  562 + 'value' => $temp['value1'],//备注
  563 + ],
  564 + "thing2" => [
  565 + 'value' =>$temp['value2'],//日期
  566 + ],
  567 + "number3" => [
  568 + 'value' => $temp['value3'],//就诊人
  569 + ],
  570 + "time4" => [
  571 + 'value' => $temp['value4'],//就诊人
  572 + ],
  573 + "thing6" => [
  574 + 'value' => $temp['value5'],//就诊人
  575 + ]
  576 + ];
  577 + break;
  578 + case 6:
  579 + //预约结果通知
  580 + $data['template_id'] = "Dfvkyn3So2YE5aVJtkUTFWdjgzpo6VvWkNHZBOMb_n4";
  581 + $data['data'] = [
  582 + "character_string1" => [
  583 + 'value' => $temp['value1'],//备注
  584 + ],
  585 + "number2" => [
  586 + 'value' =>$temp['value2'],//日期
  587 + ],
  588 + "name3" => [
  589 + 'value' => $temp['value3'],//就诊人
  590 + ],
  591 + "date4" => [
  592 + 'value' => $temp['value4'],//就诊人
  593 + ],
  594 + "thing9" => [
  595 + 'value' => $temp['value5'],//就诊人
  596 + ]
  597 + ];
  598 + break;
  599 + }
  600 +
  601 + return $this->sendSubscribeMessage($data);
  602 + }
  603 + /**
  604 + * 小程序订阅消息推送
  605 + * @param $data
  606 + * @throws \think\Exception
  607 + * @throws \think\exception\PDOException
  608 + */
  609 + function sendSubscribeMessage($data)
  610 + {
  611 + //access_token
  612 + $access_token =$this->getAccessToken();
  613 +
  614 + //请求url
  615 + $url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=' . $access_token;
  616 +
  617 + //file_put_contents('notify.txt',$data.PHP_EOL,FILE_APPEND);
  618 + //跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
  619 + $data['miniprogram_state'] = 'formal';
  620 +
  621 + return $this->curlPost($url, json_encode($data));
  622 + }
  623 + /**
  624 + * 获取access_token
  625 + * @return mixed
  626 + * @throws \think\Exception
  627 + * @throws \think\exception\PDOException
  628 + */
  629 + function getAccessToken()
  630 + {
  631 + $wx_xcx_token = \think\Db::name("wechat_token")->where("type", "wx_xcx")->find();
  632 + if (empty($wx_xcx_token) || empty($wx_xcx_token['access_token']) || $wx_xcx_token['over_time'] <= time()) {
  633 + //微信小程序失效
  634 + //当前时间戳
  635 + $now_time = strtotime(date('Y-m-d H:i:s', time()));
  636 +
  637 + //获取新的access_token
  638 + $appid = config("site.wxxcx_AppID");
  639 + $secret = config("site.wxxcx_AppSecret");
  640 + $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret;
  641 + $res = json_decode(file_get_contents($url), true);
  642 +
  643 + $access_token = $res['access_token'];
  644 + if (!empty($access_token)) {
  645 + $time = time();
  646 + $update_data = [
  647 + "access_token" => $access_token,
  648 + "over_time" => $time + 7200,
  649 + "type" => "wx_xcx",
  650 + "updatetime" => $time
  651 + ];
  652 + if (!empty($wx_xcx_token)) {
  653 + //更新
  654 + \think\Db::name("wechat_token")->where("id", $wx_xcx_token['id'])->update($update_data);
  655 + } else {
  656 + //新增
  657 + \think\Db::name("wechat_token")->insertGetId($update_data);
  658 + }
  659 + }
  660 + } else {
  661 + $access_token = $wx_xcx_token['access_token'];
  662 + }
  663 + return $access_token;
  664 + }
  665 + function array_callback($state = true, $msg = '', $data = array())
  666 + {
  667 + return array('state' => $state, 'msg' => $msg, 'data' => $data);
  668 + }
467 } 669 }