|
@@ -13,9 +13,11 @@ declare (strict_types=1);
|
|
|
namespace app\index\model;
|
|
|
|
|
|
use app\common\library\paypal\PayPal;
|
|
|
+use app\index\service\order\PaySuccess;
|
|
|
use app\index\model\{Goods as GoodsModel, OrderRefund as OrderRefundModel, Setting as SettingModel};
|
|
|
use app\index\service\{User as UserService, Payment as PaymentService};
|
|
|
use app\index\service\order\{PaySuccess as OrderPaySuccesService, source\Factory as OrderSourceFactory};
|
|
|
+use app\index\model\User as UserModel;
|
|
|
use app\common\model\Order as OrderModel;
|
|
|
use app\common\service\{Order as OrderService, order\Complete as OrderCompleteService};
|
|
|
use app\common\enum\{
|
|
@@ -30,6 +32,7 @@ use app\common\enum\{
|
|
|
};
|
|
|
use app\common\library\helper;
|
|
|
use cores\exception\BaseException;
|
|
|
+use think\facade\Log;
|
|
|
|
|
|
/**
|
|
|
* 订单模型
|
|
@@ -98,6 +101,30 @@ class Order extends OrderModel
|
|
|
if ($payType == OrderPayTypeEnum::PAYPAL) {
|
|
|
return $this->onPaymentByPaypal($order);
|
|
|
}
|
|
|
+
|
|
|
+ //积分兑换
|
|
|
+ if ($payType == OrderPayTypeEnum::POINTS) {
|
|
|
+ $userInfo = UserService::getCurrentLoginUser();
|
|
|
+ $points = $userInfo['points'];
|
|
|
+
|
|
|
+ $payPoints = intval(bcmul(strval($order['pay_price']), '100', 0));//订单所需积分
|
|
|
+ if (intval($points) < $payPoints) {
|
|
|
+ return ['flag' => false, 'message' => '积分不够'];
|
|
|
+ } else {
|
|
|
+ $orderModel = new PaySuccess($order['order_no']);
|
|
|
+ $transId = 'VP' . date('YmdHis') . $userInfo['user_id'];
|
|
|
+
|
|
|
+ $describe = "用户消费:{$order['order_no']}";
|
|
|
+ UserModel::setIncPoints($userInfo['user_id'], -$payPoints, $describe);
|
|
|
+ $status = $orderModel->onPaySuccess(OrderPayTypeEnum::POINTS, ['transaction_id' => $transId]);
|
|
|
+ if ($status) {
|
|
|
+ return ['flag' => true, 'message' => 'success'];
|
|
|
+ } else {
|
|
|
+ Log::error('orderPayment:积分兑换error,userId:' . $userInfo['user_id'] . ',orderNo:' . $order['order_no']);
|
|
|
+ return ['flag' => false, 'message' => 'error'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return [];
|
|
|
}
|
|
|
|