Ver código fonte

订单表新增订单优惠金额discount_amount和实付总金额paid_amount字段

skyline 1 mês atrás
pai
commit
3836af88c3

+ 36 - 17
haha-admin-web/src/views/order/utils/hook.tsx

@@ -80,23 +80,38 @@ export function useOrder(tableRef: Ref) {
     {
       label: "订单金额",
       prop: "totalAmount",
-      minWidth: 90,
-      formatter: ({ totalAmount }) => totalAmount ? `¥${(totalAmount / 100).toFixed(2)}` : "¥0.00"
+      minWidth: 100,
+      formatter: ({ totalAmount }) => totalAmount ? `¥${totalAmount}` : "¥0.00"
     },
     {
-      label: "实付金额",
-      prop: "totalAmount",
-      minWidth: 90,
-      formatter: ({ totalAmount, discountAmount }) => {
-        const payAmount = (totalAmount || 0) - (discountAmount || 0);
-        return `¥${(payAmount / 100).toFixed(2)}`;
+      label: "优惠金额",
+      prop: "discountAmount",
+      minWidth: 100,
+      formatter: ({ discountAmount }) => {
+        const amount = discountAmount || 0;
+        return amount > 0 ? `¥${amount}` : "¥0.00";
+      },
+      cellRenderer: ({ row }) => {
+        const amount = row.discountAmount || 0;
+        if (amount > 0) {
+          return <el-tag type="success" size="small">-¥{amount}</el-tag>;
+        }
+        return <span class="text-gray-400">¥0.00</span>;
       }
     },
     {
-      label: "优惠金额",
-      prop: "discountAmount",
-      minWidth: 90,
-      formatter: ({ discountAmount }) => discountAmount ? `¥${(discountAmount / 100).toFixed(2)}` : "¥0.00"
+      label: "实付金额",
+      prop: "paidAmount",
+      minWidth: 100,
+      formatter: ({ paidAmount, totalAmount, discountAmount }) => {
+        // 优先使用paidAmount,如果没有则计算
+        const amount = paidAmount || (totalAmount || 0) - (discountAmount || 0);
+        return `¥${amount}`;
+      },
+      cellRenderer: ({ row }) => {
+        const amount = row.paidAmount || (row.totalAmount || 0) - (row.discountAmount || 0);
+        return <span class="text-red-600 font-bold">¥{amount}</span>;
+      }
     },
     {
       label: "支付方式",
@@ -246,13 +261,17 @@ export function useOrder(tableRef: Ref) {
               <ElDescriptionsItem label="门店名称">{order.shopName || "-"}</ElDescriptionsItem>
               <ElDescriptionsItem label="活动 ID">{order.activityId || "-"}</ElDescriptionsItem>
               <ElDescriptionsItem label="订单金额">
-                ¥{((order.totalAmount || 0) / 100).toFixed(2)}
-              </ElDescriptionsItem>
-              <ElDescriptionsItem label="实付金额">
-                ¥{(((order.totalAmount || 0) - (order.discountAmount || 0)) / 100).toFixed(2)}
+                ¥{order.totalAmount || '0.00'}
               </ElDescriptionsItem>
               <ElDescriptionsItem label="优惠金额">
-                ¥{((order.discountAmount || 0) / 100).toFixed(2)}
+                {order.discountAmount > 0 ? (
+                  <el-tag type="success" size="small">-¥{order.discountAmount}</el-tag>
+                ) : (
+                  <span class="text-gray-400">¥0.00</span>
+                )}
+              </ElDescriptionsItem>
+              <ElDescriptionsItem label="实付金额">
+                <span class="text-red-600 font-bold text-lg">¥{order.paidAmount || (order.totalAmount || 0) - (order.discountAmount || 0)}</span>
               </ElDescriptionsItem>
               <ElDescriptionsItem label="支付方式">
                 <el-tag type={order.payType === "wechat" ? "success" : order.payType === "alipay" ? "primary" : "info"} size="small">

+ 4 - 0
haha-miniapp/src/main/java/com/haha/miniapp/controller/OrderController.java

@@ -68,6 +68,8 @@ public class OrderController {
                 orderMap.put("outTradeNo", order.getOutTradeNo());
                 orderMap.put("deviceId", order.getDeviceId());
                 orderMap.put("totalAmount", order.getTotalAmount());
+                orderMap.put("discountAmount", order.getDiscountAmount() != null ? order.getDiscountAmount() : 0);
+                orderMap.put("paidAmount", order.getPaidAmount() != null ? order.getPaidAmount() : order.getTotalAmount());
                 orderMap.put("payStatus", order.getPayStatus());
                 orderMap.put("status", order.getStatus());
                 orderMap.put("createTime", order.getCreateTime());
@@ -145,6 +147,8 @@ public class OrderController {
             orderDetail.put("outTradeNo", order.getOutTradeNo());
             orderDetail.put("deviceId", order.getDeviceId());
             orderDetail.put("totalAmount", order.getTotalAmount());
+            orderDetail.put("discountAmount", order.getDiscountAmount() != null ? order.getDiscountAmount() : 0);
+            orderDetail.put("paidAmount", order.getPaidAmount() != null ? order.getPaidAmount() : order.getTotalAmount());
             orderDetail.put("payStatus", order.getPayStatus());
             orderDetail.put("status", order.getStatus());
             orderDetail.put("createTime", order.getCreateTime());

+ 9 - 0
haha-mp/src/api/order.ts

@@ -27,7 +27,16 @@ export interface OrderInfo {
   outTradeNo: string;
   hahaOrderNo: string;
   deviceId: string;
+  
+  /** 订单总金额(原价) */
   totalAmount: number;
+  
+  /** 订单优惠金额(营销活动优惠 + 优惠券优惠) */
+  discountAmount?: number;
+  
+  /** 实付总金额 = totalAmount - discountAmount */
+  paidAmount?: number;
+  
   payStatus: string;
   status: number;
   statusText?: string;

+ 1 - 1
haha-mp/src/pages/orderDetail/orderDetail.vue

@@ -43,7 +43,7 @@
           <view class="amount-value-wrapper">
             <text class="amount-prefix">合计</text>
             <text class="amount-symbol">¥</text>
-            <text class="amount-integer">{{ order.totalAmount.toFixed(2) }}</text>
+            <text class="amount-integer">{{ (order.paidAmount || order.totalAmount || 0).toFixed(2) }}</text>
           </view>
         </view>
 

+ 1 - 1
haha-mp/src/pages/orders/orders.vue

@@ -41,7 +41,7 @@
             </view>
             <view class="price-info">
               <text class="price-label">实付:</text>
-              <text class="price-value">¥{{ order.totalAmount.toFixed(2) }}</text>
+              <text class="price-value">¥{{ (order.paidAmount || order.totalAmount || 0).toFixed(2) }}</text>
             </view>
             <view class="quantity-info">共{{ getQuantity(order) }}件</view>
           </view>