Unmarket.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\AllwinUnmarket;
  11. use app\allwin\model\AllwinUnmarketOrder;
  12. use app\common\facade\Inform;
  13. use app\common\facade\WechatPay;
  14. use app\allwin\model\AllwinUnmarketReward;
  15. class Unmarket extends Base{
  16. /**
  17. * 联合促销回调通知
  18. * @return void
  19. */
  20. public function Notify(){
  21. $response = WechatPay::doPay($this->miniapp_id)->handlePaidNotify(function($message, $fail) {
  22. $order = AllwinUnmarketOrder::where(['order_sn' => $message['out_trade_no'],'state' => 0])->find();
  23. if (empty($order)) {
  24. return true;
  25. }
  26. if ($message['return_code'] === 'SUCCESS') {
  27. if ($message['result_code'] === 'SUCCESS') {
  28. $sub_mchid = $message['sub_mch_id'] ?? '';
  29. $ispay = WechatPay::doPay($this->miniapp_id,true,$sub_mchid)->order->queryByOutTradeNumber($message['out_trade_no']);
  30. if ($ispay['return_code'] === 'SUCCESS' && $ispay['trade_state'] === 'SUCCESS') {
  31. $redpack_amount = AllwinUnmarketReward::redRacket($order);
  32. $order->state = 1;
  33. $order->redpack = $redpack_amount;
  34. $order->save();
  35. $unmarket = AllwinUnmarket::where(['id' => $order->share_id])->find();
  36. if($unmarket){
  37. Inform::sms($order->uid,$this->miniapp_id,['title' =>'业务进展通知','type' => '活动参与','content' =>'您已成功参与'. $unmarket->title,'state' => '成功']);
  38. }
  39. return true;
  40. } else {
  41. return $fail('通信失败,请稍后再通知我');
  42. }
  43. } else {
  44. return $fail('通信失败,请稍后再通知我');
  45. }
  46. } else {
  47. return $fail('通信失败,请稍后再通知我');
  48. }
  49. });
  50. $response->send();
  51. }
  52. }