Agentnotify.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 支付回调通知
  7. */
  8. namespace app\allwin\controller\api\v4;
  9. use app\allwin\controller\api\Base;
  10. use app\allwin\model\AllwinUserAgent;
  11. use app\allwin\model\BankBill;
  12. use app\common\event\User;
  13. use app\common\facade\Inform;
  14. use app\common\facade\WechatPay;
  15. use app\common\model\SystemMemberSms;
  16. use filter\Filter;
  17. use Exception;
  18. class Agentnotify extends Base{
  19. /**
  20. * 开通社群主申请通知
  21. * @return void
  22. */
  23. public function agent(){
  24. try{
  25. $response = WechatPay::doPay($this->miniapp_id)->handlePaidNotify(function ($message,$fail) {
  26. $result = AllwinUserAgent::where(['pay_state'=>0,'is_type'=>1,'order_no' => Filter::filter_escape($message['out_trade_no'])])->find();
  27. if (empty($result)) {
  28. return true;
  29. }
  30. if ($message['return_code'] === 'SUCCESS') {
  31. if ($message['result_code'] === 'SUCCESS') {
  32. $sub_mchid = $message['sub_mch_id'] ?? '';
  33. $ispay = WechatPay::doPay($this->miniapp_id,false,$sub_mchid)->order->queryByOutTradeNumber($result->order_no);
  34. if ($ispay['return_code'] === 'SUCCESS') {
  35. if ($ispay['result_code'] === 'SUCCESS') {
  36. if ($ispay['trade_state'] === 'SUCCESS') {
  37. AllwinUserAgent::where(['id' => $result->id])->update(['pay_state' => 1,'paid_time' => time(),'wechat_order' =>$ispay['transaction_id']]);
  38. BankBill::add(['miniapp_id'=>$this->miniapp_id,'store_id' => 0,'money' => -$result->price,'uid'=>$result->uid,'pay_uid' => $result->uid], '微信支付[开通社群主]');
  39. //微信申请社群主审核通知
  40. SystemMemberSms::sms($this->miniapp_id,'您有一条社群主申请待审核',url('allwin/user/index'));
  41. //通知申请者到微信
  42. Inform::sms($result['uid'],$this->miniapp_id,['title' =>'业务进展通知','type' => '社群主申请','content' =>'您的社群主申请正在审核中']);
  43. //通知到后台管理的微信
  44. Inform::sms(User::isFounder($this->miniapp_id)->user_id,$this->miniapp_id,['title' =>'业务进展通知','type' => '社群主申请','content' =>'您有一条新的社群主申请待审核']);
  45. return true;
  46. }
  47. }
  48. }
  49. }
  50. }
  51. return $fail('通信失败,请稍后再通知我');
  52. });
  53. $response->send();
  54. }catch (Exception $e) {
  55. $this->error('页面不存在');
  56. }
  57. }
  58. }