541469799@qq.com 1 年之前
父節點
當前提交
4131f5c179
共有 3 個文件被更改,包括 148 次插入4 次删除
  1. 144 0
      app/index/controller/Order.php
  2. 2 2
      app/index/view/checkout/payError.html
  3. 2 2
      app/index/view/checkout/paySuccessful.html

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

@@ -0,0 +1,144 @@
+<?php
+// +----------------------------------------------------------------------
+// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
+// +----------------------------------------------------------------------
+// | Author: 萤火科技 <admin@yiovo.com>
+// +----------------------------------------------------------------------
+declare (strict_types=1);
+
+namespace app\index\controller;
+
+use app\index\model\Order as OrderModel;
+use app\index\model\Setting as SettingModel;
+use app\store\model\Express as ExpressModel;
+use app\common\enum\order\PayType as OrderPayTypeEnum;
+use cores\exception\BaseException;
+use think\response\Json;
+
+/**
+ * 我的订单控制器
+ * Class Order
+ * @package app\api\controller
+ */
+class Order extends Controller
+{
+    /**
+     * 获取当前用户待处理的订单数量
+     * @return Json
+     * @throws BaseException
+     */
+    public function todoCounts(): Json
+    {
+        $model = new OrderModel;
+        $counts = $model->getTodoCounts();
+        return $this->renderSuccess(compact('counts'));
+    }
+
+    /**
+     * 我的订单列表
+     * @param string $dataType 订单类型 (all全部 payment待付款 received待发货 deliver待收货 comment待评价)
+     * @return Json
+     * @throws \think\db\exception\DbException
+     * @throws BaseException
+     */
+    public function list(string $dataType): Json
+    {
+        $model = new OrderModel;
+        $list = $model->getList($dataType);
+        return $this->renderSuccess(compact('list'));
+    }
+
+    /**
+     * 订单详情信息
+     * @param int $orderId 订单ID
+     * @return Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws BaseException
+     */
+    public function detail(int $orderId): Json
+    {
+        // 订单详情
+        $model = OrderModel::getUserOrderDetail($orderId);
+        return $this->renderSuccess([
+            'order' => $model,  // 订单详情
+            'setting' => [
+                // 积分名称
+                'points_name' => SettingModel::getPointsName(),
+            ],
+        ]);
+    }
+
+    /**
+     * 获取物流信息
+     * @param int $orderId 订单ID
+     * @return Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws BaseException
+     */
+    public function express(int $orderId): Json
+    {
+        // 订单信息
+        $order = OrderModel::getDetail($orderId);
+        if (!$order['express_no']) {
+            return $this->renderError('没有物流信息');
+        }
+        // 获取物流信息
+        $model = ExpressModel::detail($order['express_id']);
+        $express = $model->dynamic($model['express_name'], $model['kuaidi100_code'], $order['express_no']);
+        if ($express === false) {
+            return $this->renderError($model->getError());
+        }
+        return $this->renderSuccess(compact('express'));
+    }
+
+    /**
+     * 确认收货
+     * @param int $orderId
+     * @return Json
+     * @throws BaseException
+     */
+    public function receipt(int $orderId): Json
+    {
+        $model = OrderModel::getDetail($orderId);
+        if ($model->receipt()) {
+            return $this->renderSuccess('确认收货成功');
+        }
+        return $this->renderError($model->getError());
+    }
+
+    /**
+     * 立即支付
+     * @param int $orderId 订单ID
+     * @param int $payType 支付方式
+     * @return Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws BaseException
+     */
+    public function pay(int $orderId, int $payType = OrderPayTypeEnum::WECHAT): Json
+    {
+        // 获取订单详情
+        $model = OrderModel::getUserOrderDetail($orderId);
+        // 订单支付事件
+        if (!$model->onPay($payType)) {
+            return $this->renderError($model->getError() ?: '订单支付失败');
+        }
+        // 构建微信支付请求
+        $payment = $model->onOrderPayment($model, $payType);
+        // 支付状态提醒
+        return $this->renderSuccess([
+            'order_id' => $model['order_id'],   // 订单id
+            'pay_type' => $payType,             // 支付方式
+            'payment' => $payment               // 微信支付参数
+        ]);
+    }
+}

+ 2 - 2
app/index/view/checkout/payError.html

@@ -4,7 +4,7 @@
 <head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
-  <title>支付成功</title>
+  <title>Checkout</title>
   <style>
     body {
       font-family: 'Arial', sans-serif;
@@ -63,7 +63,7 @@
   <i class="icon">&#10004;</i>
   <h1>{$notice}</h1>
   <p>感谢您的支付,订单已成功处理。</p>
-  <a href="#" class="btn">返回首页</a>
+  <a href="/index/index/index.htnl" class="btn">返回首页</a>
 </div>
 </body>
 

+ 2 - 2
app/index/view/checkout/paySuccessful.html

@@ -4,7 +4,7 @@
 <head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
-  <title>支付成功</title>
+  <title>Checkout</title>
   <style>
     body {
       font-family: 'Arial', sans-serif;
@@ -63,7 +63,7 @@
   <i class="icon">&#10004;</i>
   <h1>{$notice}</h1>
   <p>感谢您的支付,订单已成功处理。</p>
-  <a href="#" class="btn">返回首页</a>
+  <a href="/index/index/index.htnl" class="btn">返回首页</a>
 </div>
 </body>