BalancePayServices.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * 余额支付
  4. */
  5. namespace app\api\services;
  6. use app\common\service\ShopOrderService;
  7. use think\facade\Db;
  8. class BalancePayServices extends BasePayServices
  9. {
  10. /**
  11. * 余额支付订单处理
  12. * @param $uid
  13. * @param $order_id
  14. * @throws \think\Exception
  15. * @throws \think\db\exception\DataNotFoundException
  16. * @throws \think\db\exception\DbException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. */
  19. public function balanceToOrder($uid, $order_id){
  20. $order_info = ShopOrderService::make()->getInfoBySn($order_id, $uid);
  21. if ($order_info['status'] != 0){
  22. sr_throw('订单已支付,不能再次支付');
  23. }
  24. $user = Db::name('user')->where('id', $uid)->find();
  25. if (!$order_info){
  26. sr_throw('订单号错误');
  27. }
  28. if ($user['money']<$order_info['payment']){
  29. sr_throw('当前用户余额不足');
  30. }
  31. // 扣除余额
  32. edit_user_money(11, $uid, $order_info['payment']);
  33. // 发送购买通知信息
  34. addUserMessage($uid, 3, '余额购买商品成功', '恭喜你已经兑换到心仪的商品,请等待发货,如有疑问请联系客服');
  35. $out_trade_no = 'BA'.$order_id.mt_rand(1, 10000);
  36. // 支付信息处理
  37. $insert = [
  38. 'total_fee' => $order_info['payment'],
  39. 'trade_type' => 'app',
  40. 'body' => '购买商品',
  41. 'state' => 6,
  42. 'out_trade_no' => $out_trade_no,
  43. 'pay_way' => 3,
  44. 'remarks' => $order_id,
  45. 'order_type' => 4,
  46. 'pay_at'=>sr_getcurtime(time()),
  47. 'uid' => $uid,
  48. 'voucher_img' => '',
  49. 'out_trade_no1'=>''
  50. ];
  51. // 添加支付订单表
  52. Db::name('payment')->insert($insert);
  53. $ser = new ThirdPayServices();
  54. $ser->payBalanceDown($order_id, 3, '');
  55. }
  56. }