NotifyService.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Laravel框架 [ Laravel ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 Laravel研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: wesmiler <12345678@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services;
  12. use App\Models\GongdengOrderModel;
  13. use App\Models\SignsModel;
  14. /**
  15. * 支付回调管理-服务类
  16. * @author wesmiler
  17. * @since 2020/11/11
  18. * Class NotifyService
  19. * @package App\Services
  20. */
  21. class NotifyService extends BaseService
  22. {
  23. protected static $instance = null;
  24. /**
  25. * 构造函数
  26. * @author wesmiler
  27. * @since 2020/11/11
  28. * NotifyService constructor.
  29. */
  30. public function __construct()
  31. {
  32. $this->model = new GongdengOrderModel();
  33. }
  34. /**
  35. * 静态入口
  36. * @return NotifyService|null
  37. */
  38. public static function make(){
  39. if(!self::$instance){
  40. self::$instance = new NotifyService();
  41. }
  42. return self::$instance;
  43. }
  44. /**
  45. * 供灯订单回调处理
  46. * @param $notifyData
  47. * @param $outTradeNo
  48. * @return false
  49. */
  50. public function notifyGongdeng($notifyData, $outTradeNo){
  51. // 验证订单是否存在
  52. $orderInfo = $this->model::where(['order_sn'=> $outTradeNo])
  53. ->select(['id','source_id','user_id','num','total','status'])
  54. ->first();
  55. // 验证参数
  56. $orderStatus = isset($orderInfo['status']) ? intval($orderInfo['status']) : 0;
  57. if (empty($orderInfo)) {
  58. NotifyService::rebackOk();
  59. return false;
  60. }
  61. // 验证订单状态是否可处理
  62. if ($orderStatus != 1) {
  63. NotifyService::rebackOk();
  64. return false;
  65. }
  66. // 验证订单金额是否正确
  67. $payDebug = config('weixin.payDebug');
  68. $payMoney = isset($postData['total_fee']) ? moneyFormat($postData['total_fee']) : 0;
  69. $orderMoney = isset($orderInfo['money']) ? moneyFormat($orderInfo['money']) : 0.00;
  70. $credit = isset($orderInfo['credit']) ? moneyFormat($orderInfo['credit']) : 0.00;
  71. $orderAmount = moneyFormat($orderMoney + $credit);
  72. if (!$payDebug && intval($orderAmount * 100) != intval($payMoney)) {
  73. return false;
  74. }
  75. // 更新订单数据
  76. // 处理支付明细
  77. // 开灯处理
  78. // 消息处理
  79. }
  80. /**
  81. * 返回成功
  82. */
  83. public static function rebackOk(){
  84. echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
  85. exit;
  86. }
  87. }