PayNotifyLogic.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\common\logic;
  15. use app\common\enum\PayEnum;
  16. use app\common\enum\user\AccountLogEnum;
  17. use app\common\model\recharge\RechargeOrder;
  18. use app\common\model\agricultural_machinery\UserService;
  19. use app\common\model\user\User;
  20. use think\facade\Db;
  21. use think\facade\Log;
  22. /**
  23. * 支付成功后处理订单状态
  24. * Class PayNotifyLogic
  25. * @package app\api\logic
  26. */
  27. class PayNotifyLogic extends BaseLogic
  28. {
  29. public static function handle($action, $orderSn, $extra = [])
  30. {
  31. Db::startTrans();
  32. try {
  33. self::$action($orderSn, $extra);
  34. Db::commit();
  35. return true;
  36. } catch (\Exception $e) {
  37. Db::rollback();
  38. Log::write(implode('-', [
  39. __CLASS__,
  40. __FUNCTION__,
  41. $e->getFile(),
  42. $e->getLine(),
  43. $e->getMessage()
  44. ]));
  45. self::setError($e->getMessage());
  46. return $e->getMessage();
  47. }
  48. }
  49. /**
  50. * @notes 充值回调
  51. * @param $orderSn
  52. * @param array $extra
  53. * @author 段誉
  54. * @date 2023/2/27 15:28
  55. */
  56. public static function recharge($orderSn, array $extra = [])
  57. {
  58. $order = RechargeOrder::where('sn', $orderSn)->findOrEmpty();
  59. // 增加用户累计充值金额及用户余额
  60. $user = User::findOrEmpty($order->user_id);
  61. $user->total_recharge_amount += $order->order_amount;
  62. $user->user_money += $order->order_amount;
  63. $user->save();
  64. // 记录账户流水
  65. AccountLogLogic::add(
  66. $order->user_id,
  67. AccountLogEnum::UM_INC_RECHARGE,
  68. AccountLogEnum::INC,
  69. $order->order_amount,
  70. $order->sn,
  71. '用户充值'
  72. );
  73. // 更新充值订单状态
  74. $order->transaction_id = $extra['transaction_id'] ?? '';
  75. $order->pay_status = PayEnum::ISPAID;
  76. $order->pay_time = time();
  77. $order->save();
  78. }
  79. /**
  80. * @notes 充值回调
  81. * @param $orderSn
  82. * @param array $extra
  83. * @author 段誉
  84. * @date 2023/2/27 15:28
  85. */
  86. public static function service($orderSn, array $extra = [])
  87. {
  88. $order = RechargeOrder::where('sn', $orderSn)->findOrEmpty();
  89. // 更新充值订单状态
  90. $order->transaction_id = $extra['transaction_id'] ?? '';
  91. $order->pay_status = PayEnum::ISPAID;
  92. $order->pay_time = time();
  93. $order->save();
  94. //更新服务数据
  95. $s_where['order_id'] = $order['id'];
  96. $user_service_info = UserService::where($s_where)->findOrEmpty();
  97. if(!$user_service_info->isEmpty()){
  98. $user_service_info->status = 1;
  99. $user_service_info->expiration_time = time() + 365*24*60*60;
  100. $user_service_info->save();
  101. $type = $user_service_info['type'];
  102. switch ($type){
  103. case 1:
  104. $updateData['agricultural_status']=2;
  105. break;
  106. case 2:
  107. $updateData['bake_status']=2;
  108. break;
  109. case 3:
  110. $updateData['air_status']=2;
  111. break;
  112. }
  113. $updateWhere['id'] = $user_service_info['user_id'];
  114. $ret = User::where($updateWhere)->update($updateData);
  115. }
  116. }
  117. }