goldzhang814 vor 1 Jahr
Ursprung
Commit
1c1d232983

+ 1 - 1
app/api/service/order/Checkout.php

@@ -713,7 +713,7 @@ class Checkout extends BaseService
     {
         if ($order['delivery'] == DeliveryTypeEnum::EXPRESS) {
             if (empty($order['address'])) {
-                $this->error = '您还没有选择配送地址';
+                $this->error = 'No shipping address';
                 return false;
             }
         }

+ 2 - 2
app/index/controller/Checkout.php

@@ -231,7 +231,7 @@ class Checkout extends Controller
             Cache::delete(PayPal::PRE_STR . $orderNo);
         }
         //todo 等会测试
-/*        $order = Order::detail(['order_no' => $orderNo]);
+        $order = Order::detail(['order_no' => $orderNo]);
         //如果有分享人,给分享人送积分
         if (isset($order['user_id'])) {
             $key = Cache::get(UserModel::SHARE_PREFIX . $order['user_id']);
@@ -242,7 +242,7 @@ class Checkout extends Controller
                 $payPoints = intval(bcmul($order['pay_price'], '100', 0));
                 UserModel::setIncPoints(intval($fromUserId), -$payPoints, $describe);
             }
-        }*/
+        }
 
         return view('paySuccessful', ['notice' => lang('login success')]);
     }

+ 6 - 0
app/index/controller/Order.php

@@ -134,6 +134,12 @@ class Order extends Controller
         }
         // 构建微信支付请求
         $payment = $model->onOrderPayment($model, $payType);
+
+        if ($payType == OrderPayTypeEnum::POINTS) {
+            if (!$payment['flag']) {
+                return $this->renderError($payment['message'] ?? '兑换失败');
+            }
+        }
         // 支付状态提醒
         return $this->renderSuccess([
             'order_id' => $model['order_id'],   // 订单id

+ 27 - 0
app/index/model/Order.php

@@ -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 [];
     }
 

+ 5 - 22
app/index/view/user/order.html

@@ -112,6 +112,11 @@
                     </div>
                     <div class="sunNavBox">
                         <a href="#">
+                            <nav class="sunNavItem orderNavItem" id="unpaid" data-type="payment">
+                                <h3 class="sunNavTitle">Unpaid</h3>
+                            </nav>
+                        </a>
+                        <a href="#">
                             <nav class="sunNavItem orderNavItem" id="treat" data-type="delivery">
                                 <h3 class="sunNavTitle">To be shipped</h3>
                             </nav>
@@ -277,28 +282,6 @@
             // 显示加载指示器
             $('#loadingIndicator').show();
             //调试后记得去除这段代码
-            /*            setTimeout(() => {
-                            // 在页面中添加数据
-                            const container = $('#orderContainer');
-                            [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16].forEach(function (item) {
-                                container.append(`
-                                        <div class="orderItem" data-id="${item}">
-                                            <h2 class="orderTitle">${item}某某电子烟</h2>
-                                            <p class="orderTime">创建时间:2019-07-03 12:00:00</p>
-                                        </div> `);
-                            });
-                            // 更新当前页数
-                            page++;
-                            // 隐藏加载指示器
-                            $('#loadingIndicator').hide();
-                            isLoading = false;
-                            //事件委托给父级
-                            container.on(tap, '.orderItem', function () {
-                                const id = $(this).attr('data-id');
-                                window.location.href = `/index/user/orderDetails.html?id=${id}&orderType=${orderType}`
-                            });
-                        }, 1000)
-                        return*/
             if (!orderType) {
                 orderType = "delivery"
             }

+ 60 - 0
app/index/view/user/orderDetails.html

@@ -490,6 +490,66 @@
             }
         }
 
+        var orderId = 99;
+        //支付方法
+        const orderPayment = (params) => {
+            return new Promise(function (resolve, reject) {
+                $.ajax({
+                    url: "/index/order/pay?payType=30&orderId=" + orderId,
+                    method: "POST",
+                    data: JSON.stringify(params),
+                    headers: {
+                        "Content-Type": "application/json",
+                        "storeId": "10001",
+                        "platform": "H5",
+                        // "Access-Token": vapesToken
+                    },
+                    dataType: "json",
+                    success: function (response) {
+                        resolve(response);
+                    },
+                    error: function (xhr, status, error) {
+                        reject(error);
+                    }
+                });
+            });
+        }
+
+
+        //支付按钮点击
+        $(".payPalButton").on(tap, async function () {
+            console.log("paypaing")
+            $("#loadingModel").show(0)
+            // 支付之前先判断是否有默认地址
+            if (!addressId) {
+                showToast('No address')
+                return
+
+                // 先添加地址
+                // const res = await addAddress()
+                // addressId = res
+            }
+
+
+            const params = {
+                //"cartIds": "10002",
+                "delivery": 10,
+                "address_id": addressId
+            }
+            const res = await orderPayment(params)
+            const {status, message, data} = res || {}
+            if (status === 200 || status === "200") {
+                window.open(data.payment.approval_link, "_blank");
+                var interId = setInterval(function () {
+                    fetchOrder(data.orderId, interId);
+                }, 2000)
+            } else if (status === 401 || status === "401") {
+                window.location.replace('../passport/logIn.html')
+            } else {
+                showToast(message)
+            }
+        });
+
         $(".orderNavItem").on(tap, function () {
             const type = $(this).attr('data-type');
             window.location.replace(`/index/user/order.html?orderType=${type}`)