BalancePayServices.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * 支付宝支付
  4. */
  5. namespace app\api\services;
  6. use AlibabaCloud\SDK\OSS\OSS\GetObjectRequest\header;
  7. use app\common\model\ShopOrderModel as Order;
  8. use Rsa\RsaClient;
  9. use Symfony\Component\Translation\Dumper\IniFileDumper;
  10. use think\facade\Db;
  11. class BalancePayServices extends BasePayServices
  12. {
  13. public function balanceToOrder($uid, $order_id){
  14. $order_info = Db::name('shop_order')->where('order_sn', $order_id)->where('user_id', $uid)->find();
  15. if ($order_info['status'] != 0){
  16. sr_throw('订单已支付,不能再次支付');
  17. }
  18. $user = Db::name('user')->where('id', $uid)->find();
  19. if (!$order_info){
  20. sr_throw('订单号错误');
  21. }
  22. if ($user['money']<$order_info['payment']){
  23. sr_throw('当前用户余额不足');
  24. }
  25. // Db::name('shop_order')->where('order_sn', $order_id)->save([
  26. // 'status'=>1,
  27. // 'updated_time'=>sr_getcurtime(time()),
  28. // 'pay_type'=>3
  29. // ]);
  30. edit_user_money(11, $uid, $order_info['payment']);
  31. addUserMessage($uid, 3, '余额购买商品成功', '恭喜你已经兑换到心仪的商品,请等待发货,如有疑问请联系客服');
  32. $out_trade_no = 'BA'.$order_id.mt_rand(1, 10000);
  33. $insert = [
  34. 'total_fee' => $order_info['payment'],
  35. 'trade_type' => 'app',
  36. 'body' => '购买商品',
  37. 'state' => 6,
  38. 'out_trade_no' => $out_trade_no,
  39. 'pay_way' => 3,
  40. 'remarks' => $order_id,
  41. 'order_type' => 4,
  42. 'pay_at'=>sr_getcurtime(time()),
  43. 'uid' => $uid,
  44. 'voucher_img' => '',
  45. 'out_trade_no1'=>''
  46. ];
  47. // 添加支付订单表
  48. Db::name('payment')->insert($insert);
  49. $ser = new ThirdPayServices();
  50. $ser->payBalanceDown($order_id, 3, '');
  51. }
  52. }