123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- namespace app\services\pay;
- use app\services\BaseServices;
- use app\services\order\OtherOrderServices;
- use app\services\order\StoreOrderServices;
- use app\services\order\StoreOrderSuccessServices;
- use app\services\activity\integral\StoreIntegralOrderServices;
- use app\services\user\UserMoneyServices;
- use app\services\user\UserServices;
- use think\exception\ValidateException;
- class YuePayServices extends BaseServices
- {
-
- public function yueOrderPay(array $orderInfo, $uid)
- {
- if (!$orderInfo) {
- throw new ValidateException('订单不存在');
- }
- if ($orderInfo['paid']) {
- throw new ValidateException('该订单已支付!');
- }
- $type = 'pay_product';
- if (isset($orderInfo['member_type'])) {
- $type = 'pay_member';
- }
-
- $services = app()->make(UserServices::class);
- $userInfo = $services->getUserInfo($uid);
- if ($userInfo['now_money'] < $orderInfo['pay_price']) {
- return ['status' => 'pay_deficiency', 'msg' => '余额不足' . floatval($orderInfo['pay_price'])];
- }
- $this->transaction(function () use ($services, $orderInfo, $userInfo, $type) {
- $res = false !== $services->bcDec($userInfo['uid'], 'now_money', $orderInfo['pay_price'], 'uid');
- switch ($type) {
- case 'pay_product':
- $id = $orderInfo['id'] ?? 0;
-
- $orderSerives = app()->make(StoreOrderServices::class);
- $orderInfo = $orderSerives->get($id);
- if (!$orderInfo) {
- throw new ValidateException('订单不存在');
- }
- $orderInfo = $orderInfo->toArray();
-
- $now_money = bcsub((string)$userInfo['now_money'], (string)$orderInfo['pay_price'], 2);
- $number = $orderInfo['pay_price'];
-
- $userMoneyServices = app()->make(UserMoneyServices::class);
- $res = $res && $userMoneyServices->income('pay_product', $userInfo['uid'], $number, $now_money, $orderInfo['id']);
-
- $orderServices = app()->make(StoreOrderSuccessServices::class);
- $res = $res && $orderServices->paySuccess($orderInfo, PayServices::YUE_PAY, ['userInfo' => $userInfo]);
- break;
- case 'pay_member':
-
- $OtherOrderServices = app()->make(OtherOrderServices::class);
- $res = $res && $OtherOrderServices->paySuccess($orderInfo, PayServices::YUE_PAY, ['userInfo' => $userInfo]);
- break;
- }
- if (!$res) {
- throw new ValidateException('余额支付失败!');
- }
- });
- return ['status' => true];
- }
-
- public function yueIntegralOrderPay(array $orderInfo, $uid)
- {
- if (!$orderInfo) {
- throw new ValidateException('订单不存在');
- }
- if ($orderInfo['paid']) {
- throw new ValidateException('该订单已支付!');
- }
- $type = 'pay_integral_product';
-
- $services = app()->make(UserServices::class);
- $userInfo = $services->getUserInfo($uid);
- if($userInfo) {
- $userInfo = $userInfo->toArray();
- } else {
- throw new ValidateException('用户信息不存在!');
- }
- if ($userInfo['now_money'] < $orderInfo['total_price']) {
- return ['status' => 'pay_deficiency', 'msg' => '余额不足' . floatval($orderInfo['total_price'])];
- }
- $this->transaction(function () use ($services, $orderInfo, $userInfo, $type) {
- $res = false !== $services->bcDec($userInfo['uid'], 'now_money', $orderInfo['total_price'], 'uid');
- switch ($type) {
- case 'pay_integral_product':
- $id = $orderInfo['id'] ?? 0;
-
- $orderSerives = app()->make(StoreIntegralOrderServices::class);
- $orderInfo = $orderSerives->get($id);
- if (!$orderInfo) {
- throw new ValidateException('订单不存在');
- }
- $orderInfo = $orderInfo->toArray();
-
- $now_money = bcsub((string)$userInfo['now_money'], (string)$orderInfo['total_price'], 2);
- $number = $orderInfo['total_price'];
-
- $userMoneyServices = app()->make(UserMoneyServices::class);
- $res = $res && $userMoneyServices->income('pay_integral_product', $userInfo['uid'], $number, $now_money, $orderInfo['id']);
-
- $orderServices = app()->make(StoreIntegralOrderServices::class);
- $res = $res && $orderServices->paySuccess($orderInfo, PayServices::YUE_PAY, ['userInfo' => $userInfo]);
- break;
- }
- if (!$res) {
- throw new ValidateException('余额支付失败!');
- }
- });
- return ['status' => true];
- }
- }
|