PayOrderModel.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. use think\Model;
  5. /**
  6. * 支付订单
  7. */
  8. class PayOrderModel extends Model
  9. {
  10. // 表名
  11. protected $name = 'pay_order';
  12. // 开启自动写入时间戳字段
  13. protected $autoWriteTimestamp = false;
  14. // 定义时间戳字段名
  15. protected $createTime = false;
  16. protected $updateTime = false;
  17. protected $deleteTime = false;
  18. /**
  19. * 余额充值支付回调
  20. * @param $out_trade_no
  21. * @return array
  22. * @throws \think\Exception
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\ModelNotFoundException
  25. * @throws \think\exception\DbException
  26. * @throws \think\exception\PDOException
  27. */
  28. public static function recharge($out_trade_no)
  29. {
  30. Db::startTrans();
  31. if (!$order = self::where('out_trade_no',$out_trade_no)->lock(true)->find()) {
  32. Db::rollback();
  33. return [false,'未找到订单'];
  34. }
  35. if ($order['order_status'] != 0) {
  36. Db::rollback();
  37. return [true,'订单已支付'];
  38. }
  39. //更新订单状态
  40. if (!self::where(['out_trade_no' => $out_trade_no])->update(['order_status' => 1, 'notifytime' => time()])) {
  41. Db::rollback();
  42. return [false,'订单状态更新失败'];
  43. }
  44. //钱包更新
  45. $walletService = new Wallet();
  46. if (!$walletService->change($order['user_id'], $order['order_amount'], 'money', 10, '充值', 'pay_order', $order['table_id'])) {
  47. Db::rollback();
  48. return [false,'余额充值失败'];
  49. }
  50. Db::commit();
  51. return [true,'操作成功'];
  52. }
  53. /**
  54. * 老年大学活动支付回调
  55. * @param $out_trade_no
  56. * @return array
  57. */
  58. public static function university_event($out_trade_no)
  59. {
  60. Db::startTrans();
  61. if (!$info = self::where('out_trade_no',$out_trade_no)->lock(true)->find()){
  62. Db::rollback();
  63. return [false,'未找到订单'];
  64. }
  65. if ($info['order_status'] == 1){
  66. Db::rollback();
  67. return [true,'订单已支付'];
  68. }
  69. //更新订单状态
  70. if (!self::where(['id' => $info['id']])->update(['status' => 1])) {
  71. Db::rollback();
  72. return [false,'订单状态更新失败'];
  73. }
  74. if (!UniversityEventApplyModel::where('id',$info['table_id'])->update(['status' => 1,'pay_time' => time()])) {
  75. Db::rollback();
  76. return [false,'活动订单状态更新失败'];
  77. }
  78. Db::commit();
  79. return [true,'操作成功'];
  80. }
  81. /**
  82. * 老年大学活动支付回调
  83. * @param $out_trade_no
  84. * @return array
  85. */
  86. public static function vip($out_trade_no)
  87. {
  88. Db::startTrans();
  89. if (!$info = self::where('out_trade_no',$out_trade_no)->lock(true)->find()){
  90. Db::rollback();
  91. return [false,'未找到订单'];
  92. }
  93. if ($info['order_status'] == 1){
  94. Db::rollback();
  95. return [true,'订单已支付'];
  96. }
  97. //更新订单状态
  98. if (!self::where(['id' => $info['id']])->update(['status' => 1])) {
  99. Db::rollback();
  100. return [false,'订单状态更新失败'];
  101. }
  102. if (!VipOrderModel::where('id',$info['table_id'])->update(['status' => 1,'pay_time' => time()])) {
  103. Db::rollback();
  104. return [false,'VIP订单状态更新失败'];
  105. }
  106. if (!VipCouponUserModel::where('order_id',$info['table_id'])->update(['status' => 1,'update_time' => time()])) {
  107. Db::rollback();
  108. return [false,'VIP订单状态更新失败'];
  109. }
  110. Db::commit();
  111. return [true,'操作成功'];
  112. }
  113. }