Partnershipnotify.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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\AllwinStore;
  11. use app\allwin\model\Worker;
  12. use app\allwin\model\WorkerStoreOrder;
  13. use app\allwin\model\BankBill;
  14. use app\common\event\User as CommonUser;
  15. use app\common\facade\Inform;
  16. use app\common\facade\WechatPay;
  17. use app\common\model\SystemMemberSms;
  18. use Exception;
  19. class Partnershipnotify extends Base{
  20. /**
  21. * 支付回调
  22. */
  23. public function workerNotify(){
  24. $response = WechatPay::doPay($this->miniapp_id)->handlePaidNotify(function($message, $fail) {
  25. $order = Worker::where(['order_no' => $message['out_trade_no'],'pay_state' => 0])->find();
  26. if (empty($order)) {
  27. return true;
  28. }
  29. if ($message['return_code'] === 'SUCCESS') {
  30. if ($message['result_code'] === 'SUCCESS') {
  31. $sub_mchid = $message['sub_mch_id'] ?? '';
  32. $ispay = WechatPay::doPay($this->miniapp_id,true,$sub_mchid)->order->queryByOutTradeNumber($message['out_trade_no']);
  33. if ($ispay['return_code'] === 'SUCCESS' && $ispay['trade_state'] === 'SUCCESS') {
  34. $data = [
  35. 'member_miniapp_id' => $this->miniapp_id,
  36. 'city_id' => 0,
  37. 'store_id' => 0,
  38. 'user_id' => $order->uid,
  39. 'pay_uid' => $order->uid,
  40. 'message' => '开通合伙人费用',
  41. 'update_time' => time()
  42. ];
  43. if($ispay['total_fee'] == $order->price * 100){
  44. Worker::where(['id' => $order->id])->update(['pay_state' => 1,'paid_time' => time(),'wechat_order' =>$ispay['transaction_id']]);
  45. $data['money'] = $order->price;
  46. }else{
  47. $data['money'] = $ispay['total_fee'] / 100;
  48. }
  49. BankBill::create($data);
  50. //微信申请合伙人审核通知
  51. SystemMemberSms::sms($this->miniapp_id,'您有一条合伙人待审核',url('allwin/user/worker'));
  52. //通知申请者到微信
  53. Inform::sms($order['uid'],$this->miniapp_id,['title' =>'业务进展通知','type' => '合伙人申请','content' =>'您的合伙人申请正在审核中']);
  54. //通知到后台管理的微信
  55. Inform::sms(CommonUser::isFounder($this->miniapp_id)->user_id,$this->miniapp_id,['title' =>'业务进展通知','type' => '合伙人申请','content' =>'您有一条新的合伙人申请待审核']);
  56. return true;
  57. } else {
  58. return $fail('通信失败,请稍后再通知我');
  59. }
  60. } else {
  61. return $fail('通信失败,请稍后再通知我');
  62. }
  63. } else {
  64. return $fail('通信失败,请稍后再通知我');
  65. }
  66. });
  67. $response->send();
  68. }
  69. public function onStoreNotify(){
  70. $response = WechatPay::doPay($this->miniapp_id)->handlePaidNotify(function($message, $fail) {
  71. $order = WorkerStoreOrder::where(['order_no' => $message['out_trade_no'], 'pay_state' => 0])->find();
  72. if (empty($order)) {
  73. return true;
  74. }
  75. if ($message['return_code'] === 'SUCCESS') {
  76. if ($message['result_code'] === 'SUCCESS') {
  77. $sub_mchid = $message['sub_mch_id'] ?? '';
  78. $ispay = WechatPay::doPay($this->miniapp_id,true,$sub_mchid)->order->queryByOutTradeNumber($message['out_trade_no']);
  79. if ($ispay['return_code'] === 'SUCCESS' && $ispay['trade_state'] === 'SUCCESS') {
  80. $store = AllwinStore::where(['id' => $order->store_id])->find();
  81. $data = [
  82. 'member_miniapp_id' => $this->miniapp_id,
  83. 'city_id' => 0,
  84. 'store_id' => 0,
  85. 'user_id' => $order->uid,
  86. 'pay_uid' => $order->uid,
  87. 'message' => '开通好店费用',
  88. 'update_time' => time()
  89. ];
  90. if($ispay['total_fee'] == $order->price * 100){
  91. WorkerStoreOrder::where(['id' => $order->id])->update(['pay_state' => 1, 'paid_time' => time(), 'wechat_order' =>$ispay['transaction_id']]);
  92. $data['money'] = $order->price;
  93. }else{
  94. $data['money'] = $ispay['total_fee'] / 100;
  95. }
  96. BankBill::create($data);
  97. //好店审核通知
  98. SystemMemberSms::sms($this->miniapp_id,'您有一条好店信息待审核',url('allwin/store/index'));
  99. //通知申请者到微信
  100. Inform::sms($order['uid'],$this->miniapp_id,['title' =>'业务进展通知','type' => '好店申请','content' =>'您提交的好店申请正在审核中']);
  101. //通知到后台管理的微信
  102. Inform::sms(CommonUser::isFounder($this->miniapp_id)->user_id,$this->miniapp_id,['title' =>'业务进展通知','type' => '好店申请','content' =>'您有一条新的好店申请待审核']);
  103. return true;
  104. } else {
  105. return $fail('通信失败,请稍后再通知我');
  106. }
  107. } else {
  108. return $fail('通信失败,请稍后再通知我');
  109. }
  110. } else {
  111. return $fail('通信失败,请稍后再通知我');
  112. }
  113. });
  114. $response->send();
  115. }
  116. }