Browse Source

no message

panghu 6 months ago
parent
commit
c13de1f39a
8 changed files with 729 additions and 41 deletions
  1. 2 0
      .gitignore
  2. 92 4
      api/shop_order.go
  3. 455 0
      doc/shopOrder.md
  4. 13 13
      model/x_members.gen.go
  5. 81 22
      model/x_shop_orders.gen.go
  6. 77 0
      model/x_shops.gen.go
  7. 5 1
      request/api/shop_order.go
  8. 4 1
      router/api_shop_order.go

+ 2 - 0
.gitignore

@@ -1,3 +1,5 @@
+.idea
+.lingma
 .env
 config.json
 server/weixin/cert/

+ 92 - 4
api/shop_order.go

@@ -3,13 +3,14 @@ package api
 import (
 	"encoding/json"
 	"fmt"
-	"github.com/gin-gonic/gin"
-	"github.com/shopspring/decimal"
 	"go_zh/model"
 	"go_zh/pkg/validator"
 	"go_zh/request/api"
 	"go_zh/server"
 	"go_zh/server/chinaums"
+
+	"github.com/gin-gonic/gin"
+	"github.com/shopspring/decimal"
 )
 
 type ShopOrderController struct {
@@ -42,7 +43,7 @@ func (shopOrder ShopOrderController) GetOrderSn(c *gin.Context) {
 	}
 	//对最小金额做判断
 	minMoney, _ := decimal.NewFromString("0.01")
-	if money.LessThan(minMoney) { //当 money小于minMoney时
+	if money.LessThan(minMoney) { //当 money 小于 minMoney 时
 		shopOrder.responseError(c, 400, "金额不合法")
 		return
 	}
@@ -128,7 +129,7 @@ func (shopOrder ShopOrderController) GetOrderSn(c *gin.Context) {
 	var wxData interface{}
 	var notifyUrl string
 	if data.PayType == 1 { //微信支付
-		//查询当前用户openid
+		//查询当前用户 openid
 		memberOpenIdModel := model.XMemberOpenID{}
 		var memberOpenIdInfo = model.XMemberOpenID{}
 		memberOpenIdInfo, err = memberOpenIdModel.GetMemberOpenInfo(mId, 1)
@@ -165,3 +166,90 @@ func (shopOrder ShopOrderController) GetOrderSn(c *gin.Context) {
 	result["pay_url"] = payUrl
 	shopOrder.responseSuccess(c, result)
 }
+
+// GetOrderInfo 获取订单详情
+func (shopOrder ShopOrderController) GetOrderInfo(c *gin.Context) {
+
+	//数据验证
+	var data api.GetOrderInfoRequest
+	msg, ok := validator.ValidatorData(c, &data)
+	if !ok {
+		shopOrder.responseError(c, 400, msg)
+		return
+	}
+
+	shopOrderModel := model.XShopOrder{}
+	info, err := shopOrderModel.GetOrderInfo(data.OrderSn)
+	if err != nil {
+		shopOrder.responseError(c, 400, "订单查询失败")
+		return
+	}
+
+	if info.RsSn == "" {
+		shopOrder.responseError(c, 400, "订单不存在")
+		return
+	}
+
+	shopOrder.responseSuccess(c, info)
+}
+
+// GetShopBankOrder 获取商户银联待入账金额列表(最新 10 条)
+func (shopOrder ShopOrderController) GetShopBankOrder(c *gin.Context) {
+	// 获取当前登录会员 ID
+	mId := c.GetInt("mId")
+	if mId == 0 {
+		shopOrder.responseError(c, 401, "缺少登陆信息")
+		return
+	}
+
+	// 根据会员 ID 获取店铺信息
+	shopModel := model.XShop{}
+	shop, err := shopModel.GetShopByMemberId(mId)
+	if err != nil || shop.ID == 0 {
+		shopOrder.responseError(c, 400, "未找到店铺信息")
+		return
+	}
+
+	// 查询订单列表(最新 10 条)
+	shopOrderModel := model.XShopOrder{}
+	items, err := shopOrderModel.GetBankOrderList(shop.ID)
+	if err != nil {
+		shopOrder.responseError(c, 400, "订单列表查询失败")
+		return
+	}
+
+	// 获取银联待入账总金额
+	totalBankMoney, err := shopOrderModel.GetTotalBankMoney(shop.ID)
+	if err != nil {
+		shopOrder.responseError(c, 400, "总金额查询失败")
+		return
+	}
+
+	// 获取商户配置(折扣比例)
+	shopSetModel := model.XShopSet{}
+	shopSetInfo, err := shopSetModel.GetShopSetInfo(shop.ID)
+	if err != nil {
+		// 如果没有配置,使用默认值 0
+		shopSetInfo.Discount, _ = decimal.NewFromString("0")
+	}
+
+	// 计算清分金额和待入账金额
+	discountPercent := shopSetInfo.Discount
+	clearingMoney := discountPercent.Div(decimal.NewFromInt(100)).Mul(totalBankMoney)
+	bankWaitMoney := totalBankMoney.Sub(clearingMoney)
+
+	// 处理每个订单项,计算实际收益金额
+	for i := range items {
+		itemClearingMoney := discountPercent.Div(decimal.NewFromInt(100)).Mul(items[i].PayMoney)
+		items[i].PayMoney = items[i].PayMoney.Sub(itemClearingMoney)
+		items[i].IsClearing = 0 // 设置为待清分状态
+	}
+
+	// 构建响应数据
+	result := map[string]interface{}{
+		"total_money": bankWaitMoney.String(),
+		"list":        items,
+	}
+
+	shopOrder.responseSuccess(c, result)
+}

+ 455 - 0
doc/shopOrder.md

@@ -0,0 +1,455 @@
+# ShopOrder API 文档
+
+## 概述
+
+商家订单系统 API,提供订单创建、订单查询等功能。支持微信支付、支付宝支付和银联支付三种支付方式。
+
+**基础路径**: `/api/shopOrder`  
+**认证方式**: Bearer Token  
+**数据格式**: JSON
+
+---
+
+## 目录
+
+- [获取订单详情](#获取订单详情)
+- [创建订单支付](#创建订单支付)
+- [获取商户银联待入账金额列表](#获取商户银联待入账金额列表)
+
+---
+
+## 接口列表
+
+### 认证方式
+
+所有接口都需要通过 `ApiMiddleware` 中间件进行认证。
+
+**支持的认证方式:**
+
+1. **Header 方式**(推荐):
+   ```
+   Authorization: Bearer <your-token>
+   ```
+
+2. **Query 参数方式**:
+   ```
+   GET /api/shopOrder/info?order_sn=xxx&token=your-token
+   ```
+
+---
+
+### 1. 获取订单详情
+
+#### 基本信息
+- **接口路径**: `/api/shopOrder/info`
+- **请求方式**: GET
+- **接口描述**: 根据订单编号查询订单详细信息(包含店铺名称)
+- **认证要求**: 需要 Token 认证
+- **请求头要求**:
+  - `Content-Type`: application/json
+  - `Authorization`: Bearer {token}
+
+#### 请求参数
+
+| 参数名 | 类型 | 位置 | 必填 | 说明 | 验证规则 |
+|--------|------|------|------|------|----------|
+| order_sn | string | query | 是 | 订单编号 | required, min=1, max=64 |
+
+#### 请求示例
+
+```http
+GET /api/shopOrder/info?order_sn=382FS1234567890 HTTP/1.1
+Host: localhost:8080
+Content-Type: application/json
+Authorization: Bearer your-token-here
+```
+
+#### 响应格式
+
+**成功响应 (200)**
+```json
+{
+    "code": 200,
+    "message": "success",
+    "data": {
+        "rs_sn": "382FS1234567890",
+        "pay_sn": "PAY20260312001",
+        "status": 2,
+        "pay_money": "100.00",
+        "shop_name": "某某店铺"
+    }
+}
+```
+
+**失败响应 - 参数错误 (400)**
+```json
+{
+    "code": 400,
+    "message": "订单编号不能为空",
+    "data": []
+}
+```
+
+**失败响应 - 订单不存在 (400)**
+```json
+{
+    "code": 400,
+    "message": "订单不存在",
+    "data": []
+}
+```
+
+**失败响应 - 认证失败 (401)**
+```json
+{
+    "code": 401,
+    "message": "token 失效",
+    "data": null
+}
+```
+
+#### 返回字段说明
+
+| 字段名 | 类型 | 说明 |
+|--------|------|------|
+| rs_sn | string | 店铺订单支付编号 |
+| pay_sn | string | 支付编号 |
+| status | int | 订单状态(1:待支付,2:已支付,3:已退款/已完成) |
+| pay_money | decimal | 支付金额 |
+| shop_name | string | 店铺名称 |
+
+#### cURL 测试示例
+
+```bash
+# 正常查询
+curl -X GET "http://localhost:8080/api/shopOrder/info?order_sn=382FS1234567890" \
+  -H "Authorization: Bearer your-token"
+
+# 缺少参数测试
+curl -X GET "http://localhost:8080/api/shopOrder/info"
+
+# 订单不存在测试
+curl -X GET "http://localhost:8080/api/shopOrder/info?order_sn=INVALID_SN"
+```
+
+#### 注意事项
+
+1. 该接口需要登录认证(通过 `ApiMiddleware`)
+2. 订单编号必须是有效的字符串,长度不超过 64 个字符
+3. 如果订单不存在,会返回"订单不存在"的错误提示
+4. 接口会自动关联店铺表,返回店铺名称信息
+
+---
+
+### 2. 创建订单支付
+
+#### 基本信息
+- **接口路径**: `/api/shopOrder/create`
+- **请求方式**: GET/POST
+- **接口描述**: 创建订单并获取支付信息(支持微信、支付宝、银联)
+- **认证要求**: ⚠️ 必须登录(微信支付时需要验证用户身份)
+- **请求头要求**:
+  - `Content-Type`: application/json
+  - `Authorization`: Bearer {token}(微信支付时必须)
+
+#### 请求参数
+
+| 参数名 | 类型 | 位置 | 必填 | 说明 | 验证规则 |
+|--------|------|------|------|------|----------|
+| shop_id | int | body/query | 是 | 商家 ID | required, gt=0 |
+| pay_type | int | body/query | 是 | 支付方式(1:微信,2:支付宝) | required, gt=0, lt=3 |
+| pay_money | string | body/query | 是 | 支付金额 | required, gt=0, lte=1000000 |
+| pay_code_source | int | body/query | 否 | 收款码来源(1:普通,2:烟草) | omitempty |
+
+**参数说明:**
+- `shop_id`: 商家店铺 ID,必须大于 0
+- `pay_type`: 支付方式,1=微信支付,2=支付宝支付
+- `pay_money`: 支付金额,支持小数,最大 1000000
+- `pay_code_source`: 可选参数,默认为 1
+
+#### 请求示例
+
+```http
+POST /api/shopOrder/create HTTP/1.1
+Host: localhost:8080
+Content-Type: application/json
+Authorization: Bearer your-token-here
+
+{
+    "shop_id": 1,
+    "pay_type": 1,
+    "pay_money": "100.00",
+    "pay_code_source": 1
+}
+```
+
+#### 响应格式
+
+**成功响应 (200)**
+```json
+{
+    "code": 200,
+    "message": "success",
+    "data": {
+        "is_bank": 0,
+        "wx_pay": {
+            "appId": "wx1234567890",
+            "timeStamp": "1234567890",
+            "nonceStr": "random_string",
+            "package": "prepay_id=xxx",
+            "signType": "RSA",
+            "paySign": "signature"
+        },
+        "zfb_pay": "",
+        "pay_url": ""
+    }
+}
+```
+
+**失败响应 - 参数错误 (400)**
+```json
+{
+    "code": 400,
+    "message": "商家 id 不能为空",
+    "data": []
+}
+```
+
+**失败响应 - 金额错误 (400)**
+```json
+{
+    "code": 400,
+    "message": "金额不合法",
+    "data": []
+}
+```
+
+**失败响应 - 会员信息错误 (409)**
+```json
+{
+    "code": 409,
+    "message": "会员信息错误",
+    "data": []
+}
+```
+
+**失败响应 - 商户号信息错误 (400)**
+```json
+{
+    "code": 400,
+    "message": "商户号信息错误 xxx",
+    "data": []
+}
+```
+
+**失败响应 - 订单创建失败 (400)**
+```json
+{
+    "code": 400,
+    "message": "订单创建失败",
+    "data": []
+}
+```
+
+#### 返回字段说明
+
+| 字段名 | 类型 | 说明 |
+|--------|------|------|
+| is_bank | int | 是否银联支付(0:否,1:是) |
+| wx_pay | object | 微信支付参数(仅微信支付时返回) |
+| zfb_pay | string | 支付宝支付 URL(仅支付宝支付时返回) |
+| pay_url | string | H5 支付跳转 URL(仅银联支付时返回) |
+
+**wx_pay 对象结构(微信支付时返回):**
+```json
+{
+    "appId": "wx1234567890",
+    "timeStamp": "1234567890",
+    "nonceStr": "random_string",
+    "package": "prepay_id=xxx",
+    "signType": "RSA",
+    "paySign": "signature"
+}
+```
+
+#### cURL 测试示例
+
+```bash
+# 创建微信订单
+curl -X POST "http://localhost:8080/api/shopOrder/create" \
+  -H "Content-Type: application/json" \
+  -H "Authorization: Bearer your-token" \
+  -d '{
+    "shop_id": 1,
+    "pay_type": 1,
+    "pay_money": "100.00"
+  }'
+
+# 创建支付宝订单
+curl -X POST "http://localhost:8080/api/shopOrder/create" \
+  -H "Content-Type: application/json" \
+  -H "Authorization: Bearer your-token" \
+  -d '{
+    "shop_id": 1,
+    "pay_type": 2,
+    "pay_money": "50.00"
+  }'
+```
+
+#### 注意事项
+
+1. 当 `pay_type=1`(微信支付)时,必须携带有效的 token 以获取用户 openid
+2. 支付金额最小为 0.01 元,最大为 1000000 元
+3. 如果商户配置了银联信息,会走银联支付通道(`is_bank=1`)
+4. 微信支付返回前端 SDK 需要的支付参数,支付宝返回支付 URL,银联支付返回 H5 跳转链接
+5. 订单编号由系统自动生成,格式如:382FS + 时间戳
+
+---
+
+### 3. 获取商户银联待入账金额列表
+
+#### 基本信息
+- **接口路径**: `/api/shopOrder/shopBankOrder`
+- **请求方式**: GET
+- **接口描述**: 获取商户银联待入账订单列表(最新 10 条)及待入账总金额(已扣除清分金额)
+- **认证要求**: 需要 Token 认证
+- **请求头要求**:
+  - `Content-Type`: application/json
+  - `Authorization`: Bearer {token}
+
+#### 请求参数
+
+无需参数,自动从 token 中获取会员信息并查询关联店铺。
+
+#### 请求示例
+
+```http
+GET /api/shopOrder/shopBankOrder HTTP/1.1
+Host: localhost:8080
+Content-Type: application/json
+Authorization: Bearer your-token-here
+```
+
+#### 响应格式
+
+**成功响应 (200)**
+```json
+{
+    "code": 200,
+    "message": "success",
+    "data": {
+        "total_money": "19600.00",
+        "list": [
+            {
+                "rs_sn": "382FS1234567890",
+                "pay_money": "98.00",
+                "is_clearing": 0,
+                "status": 6,
+                "created_at": "2026-03-14T10:00:00Z"
+            },
+            {
+                "rs_sn": "382FS1234567891",
+                "pay_money": "196.00",
+                "is_clearing": 0,
+                "status": 6,
+                "created_at": "2026-03-14T09:00:00Z"
+            }
+        ]
+    }
+}
+```
+
+**失败响应 - 未授权 (401)**
+```json
+{
+    "code": 401,
+    "message": "缺少登陆信息",
+    "data": []
+}
+```
+
+**失败响应 - 未找到店铺 (400)**
+```json
+{
+    "code": 400,
+    "message": "未找到店铺信息",
+    "data": []
+}
+```
+
+#### 返回字段说明
+
+| 字段名 | 类型 | 说明 |
+|--------|------|------|
+| total_money | string | 银联待入账总金额(已扣除清分金额) |
+| list | array | 订单列表(最新 10 条) |
+
+**list 数组元素结构:**
+
+| 字段名 | 类型 | 说明 |
+|--------|------|------|
+| rs_sn | string | 订单编号 |
+| pay_money | string | 支付金额(已扣除清分金额) |
+| is_clearing | int | 是否清分(0:待清分,1:已清分) |
+| status | int | 订单状态(6:待入账) |
+| created_at | string | 创建时间(RFC3339 格式) |
+
+#### cURL 测试示例
+
+```bash
+# 查询最新 10 条银联待入账订单
+curl -X GET "http://localhost:8080/api/shopOrder/shopBankOrder" \
+  -H "Authorization: Bearer your-token"
+```
+
+#### 注意事项
+
+1. 该接口需要登录认证,自动从 token 中获取会员 ID
+2. 根据会员 ID 自动查询其关联的店铺(未删除且状态为 1)
+3. 仅查询 status=6(待入账)且 is_bank=1(银联支付)的订单
+4. 固定返回最新的 10 条记录,按 ID 降序排序
+5. 返回的金额为扣除清分金额后的实际收益金额
+6. 清分比例由商户配置的 discount 字段决定(折扣百分比)
+7. 计算公式:`待入账金额 = 总金额 - (总金额 × discount / 100)`
+
+---
+
+### 通用说明
+
+### 错误码说明
+
+| 错误码 | HTTP 状态码 | 说明 | 常见场景 |
+|--------|-----------|------|----------|
+| 200 | 200 OK | 成功 | 请求成功处理 |
+| 400 | Bad Request | 请求参数错误 | 参数缺失、格式错误、验证失败 |
+| 401 | Unauthorized | 未授权/认证失败 | token 无效、过期或缺失 |
+| 409 | Conflict | 资源冲突 | 会员信息错误、数据不存在 |
+
+**业务错误信息详见各接口的响应格式说明。**
+
+### 数据格式
+
+**请求/响应格式:** JSON (`application/json`)
+
+**金额精度:**
+- 使用 `decimal.Decimal` 类型,保留两位小数
+- 支持字符串或数字传递
+
+**时间格式:** RFC3339 格式(`created_at`、`updated_at`)
+
+### 版本信息
+
+- **API 版本**: v1
+- **最后更新**: 2026-03-14
+- **维护者**: 开发团队
+- **文档路径**: `/doc/shopOrder.md`
+
+### 更新日志
+
+#### v1.0.0 (2026-03-13)
+- ✨ 新增:获取订单详情接口 `/info`
+- 🐛 修复:优化订单查询接口的参数验证
+- 📝 改进:完善 API 文档说明
+
+#### v1.0.0 (2026-03-12)
+- ✨ 初始版本:创建订单支付接口 `/create`

+ 13 - 13
model/x_members.gen.go

@@ -13,31 +13,31 @@ const TableNameXMember = "x_members"
 
 // XMember mapped from table <x_members>
 type XMember struct {
-	ID           int     `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
+	ID           int       `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
 	Phone        string    `gorm:"column:phone;not null;comment:手机号码" json:"phone"`                 // 手机号码
 	Nickname     string    `gorm:"column:nickname;not null;default:振合网;comment:昵称" json:"nickname"` // 昵称
 	Password     string    `gorm:"column:password;not null;comment:登录密码" json:"password"`           // 登录密码
 	PayPass      string    `gorm:"column:pay_pass;not null;comment:支付密码" json:"pay_pass"`           // 支付密码
 	Encrypt      string    `gorm:"column:encrypt;not null;comment:加密字符串" json:"encrypt"`            // 加密字符串
-	Status       int     `gorm:"column:status;not null;comment:状态,0:关闭,1:开启" json:"status"`       // 状态,0:关闭,1:开启
+	Status       int       `gorm:"column:status;not null;comment:状态,0:关闭,1:开启" json:"status"`       // 状态,0:关闭,1:开启
 	CreatedAt    time.Time `gorm:"column:created_at" json:"created_at"`
 	UpdatedAt    time.Time `gorm:"column:updated_at" json:"updated_at"`
-	RecomID      int     `gorm:"column:recom_id;not null;comment:推荐人ID" json:"recom_id"`         // 推荐人ID
+	RecomID      int       `gorm:"column:recom_id;not null;comment:推荐人ID" json:"recom_id"`         // 推荐人ID
 	HeadImg      string    `gorm:"column:head_img;comment:头像" json:"head_img"`                     // 头像
 	InviteCode   string    `gorm:"column:invite_code;not null;comment:推荐码" json:"invite_code"`     // 推荐码
-	LevelID      int     `gorm:"column:level_id;not null;comment:等级ID" json:"level_id"`          // 等级ID
+	LevelID      int       `gorm:"column:level_id;not null;comment:等级ID" json:"level_id"`          // 等级ID
 	TokenStr     string    `gorm:"column:token_str;comment:token" json:"token_str"`                // token
 	ConsumeMoney float64   `gorm:"column:consume_money;comment:消费金" json:"consume_money"`          // 消费金
 	Money        float64   `gorm:"column:money;comment:余额" json:"money"`                           // 余额
 	BenefitMoney float64   `gorm:"column:benefit_money;comment:公益豆" json:"benefit_money"`          // 公益豆
 	ShareImg     string    `gorm:"column:share_img;comment:分享海报图片" json:"share_img"`               // 分享海报图片
-	Sex          int      `gorm:"column:sex;comment:性别" json:"sex"`                               // 性别
+	Sex          int       `gorm:"column:sex;comment:性别" json:"sex"`                               // 性别
 	CodeImg      string    `gorm:"column:code_img;comment:推荐码" json:"code_img"`                    // 推荐码
 	Describe     string    `gorm:"column:describe;comment:描述" json:"describe"`                     // 描述
 	Sid          string    `gorm:"column:sid;comment:长链接登陆编号" json:"sid"`                          // 长链接登陆编号
-	OnLine       int      `gorm:"column:on_line;comment:长链接在线" json:"on_line"`                    // 长链接在线
-	Source       int      `gorm:"column:source;default:1;comment:来源 1微信 2支付宝 3浏览器" json:"source"` // 来源 1微信 2支付宝 3浏览器
-	IsDel        int      `gorm:"column:is_del;comment:是否删除 0否 1是" json:"is_del"`                 // 是否删除 0否 1是
+	OnLine       int       `gorm:"column:on_line;comment:长链接在线" json:"on_line"`                    // 长链接在线
+	Source       int       `gorm:"column:source;default:1;comment:来源 1微信 2支付宝 3浏览器" json:"source"` // 来源 1微信 2支付宝 3浏览器
+	IsDel        int       `gorm:"column:is_del;comment:是否删除 0否 1是" json:"is_del"`                 // 是否删除 0否 1是
 	MergeSource  string    `gorm:"column:merge_source;comment:账户合并了那些来源账户" json:"merge_source"`    // 账户合并了那些来源账户
 	BeanMoney    float64   `gorm:"column:bean_money;comment:振合豆" json:"bean_money"`                // 振合豆
 }
@@ -47,12 +47,12 @@ func (*XMember) TableName() string {
 	return TableNameXMember
 }
 
-//根据token获取用户信息
-func (m *XMember) GetMemberByToken(token string) (*XMember, error)  {
+// 根据 token 获取用户信息
+func (m *XMember) GetMemberByToken(token string) (*XMember, error) {
 	member := &XMember{}
-	model := config.Mdb.Model(member).Where("token_str = ?",token)
+	model := config.Mdb.Model(member).Where("token_str = ?", token)
 	if err := model.First(member).Error; err != nil {
-		return member,err
+		return member, err
 	}
 	return member, nil
-}
+}

+ 81 - 22
model/x_shop_orders.gen.go

@@ -5,34 +5,35 @@
 package model
 
 import (
-	"github.com/shopspring/decimal"
 	"go_zh/config"
 	"time"
+
+	"github.com/shopspring/decimal"
 )
 
 const TableNameXShopOrder = "x_shop_orders"
 
 // XShopOrder mapped from table <x_shop_orders>
 type XShopOrder struct {
-	ID            int     `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
-	ShopID        int     `gorm:"column:shop_id;not null;comment:店铺ID" json:"shop_id"`                // 店铺ID
-	MID           int     `gorm:"column:m_id;not null;comment:会员ID" json:"m_id"`                      // 会员ID
-	RsSn          string    `gorm:"column:rs_sn;not null;comment:店铺订单支付编号" json:"rs_sn"`                // 店铺订单支付编号
-	PaySn         string    `gorm:"column:pay_sn;not null;comment:支付编号" json:"pay_sn"`                  // 支付编号
-	PayType       int     `gorm:"column:pay_type;not null;comment:支付类型,1:微信,2:支付宝" json:"pay_type"`   // 支付类型,1:微信,2:支付宝
-	PayMoney      decimal.Decimal   `gorm:"column:pay_money;not null;comment:支付金额" json:"pay_money"`            // 支付金额
-	Status        int     `gorm:"column:status;not null;comment:1:待支付,2:已支付,3:已退款,已完成" json:"status"` // 1:待支付,2:已支付,3:已退款,已完成
-	CreatedAt     time.Time `gorm:"column:created_at" json:"created_at"`
-	UpdatedAt     time.Time `gorm:"column:updated_at" json:"updated_at"`
-	Discount      decimal.Decimal   `gorm:"column:discount;default:0.00;comment:折扣金额" json:"discount"`                             // 折扣金额
-	IsClearing    int      `gorm:"column:is_clearing;comment:是否清分 0:待清分,1:已清分" json:"is_clearing"`                        // 是否清分 0:待清分,1:已清分
-	ServiceMoney  decimal.Decimal   `gorm:"column:service_money;not null;default:0.00;comment:平台手续费" json:"service_money"`         // 平台手续费
-	DiscountMoney decimal.Decimal   `gorm:"column:discount_money;not null;default:0.00;comment:让利金额" json:"discount_money"`        // 让利金额
-	EarningsMoney decimal.Decimal   `gorm:"column:earnings_money;not null;default:0.00;comment:收益金额" json:"earnings_money"`        // 收益金额
-	ReturnSn      string    `gorm:"column:return_sn;comment:退款订单编号" json:"return_sn"`                                      // 退款订单编号
-	IsReport      int      `gorm:"column:is_report;comment:是否播报" json:"is_report"`                                        // 是否播报
-	PayCodeSource int     `gorm:"column:pay_code_source;default:1;comment:支付收款码来源 1普通收款码 2烟草收款码" json:"pay_code_source"` // 支付收款码来源 1普通收款码 2烟草收款码
-	IsBank        int     `gorm:"column:is_bank;comment:是否银联支付 0否1是" json:"is_bank"`                                     // 是否银联支付 0否1是
+	ID            int             `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
+	ShopID        int             `gorm:"column:shop_id;not null;comment:店铺ID" json:"shop_id"`                // 店铺ID
+	MID           int             `gorm:"column:m_id;not null;comment:会员ID" json:"m_id"`                      // 会员ID
+	RsSn          string          `gorm:"column:rs_sn;not null;comment:店铺订单支付编号" json:"rs_sn"`                // 店铺订单支付编号
+	PaySn         string          `gorm:"column:pay_sn;not null;comment:支付编号" json:"pay_sn"`                  // 支付编号
+	PayType       int             `gorm:"column:pay_type;not null;comment:支付类型,1:微信,2:支付宝" json:"pay_type"`   // 支付类型,1:微信,2:支付宝
+	PayMoney      decimal.Decimal `gorm:"column:pay_money;not null;comment:支付金额" json:"pay_money"`            // 支付金额
+	Status        int             `gorm:"column:status;not null;comment:1:待支付,2:已支付,3:已退款,已完成" json:"status"` // 1:待支付,2:已支付,3:已退款,已完成
+	CreatedAt     time.Time       `gorm:"column:created_at" json:"created_at"`
+	UpdatedAt     time.Time       `gorm:"column:updated_at" json:"updated_at"`
+	Discount      decimal.Decimal `gorm:"column:discount;default:0.00;comment:折扣金额" json:"discount"`                             // 折扣金额
+	IsClearing    int             `gorm:"column:is_clearing;comment:是否清分 0:待清分,1:已清分" json:"is_clearing"`                        // 是否清分 0:待清分,1:已清分
+	ServiceMoney  decimal.Decimal `gorm:"column:service_money;not null;default:0.00;comment:平台手续费" json:"service_money"`         // 平台手续费
+	DiscountMoney decimal.Decimal `gorm:"column:discount_money;not null;default:0.00;comment:让利金额" json:"discount_money"`        // 让利金额
+	EarningsMoney decimal.Decimal `gorm:"column:earnings_money;not null;default:0.00;comment:收益金额" json:"earnings_money"`        // 收益金额
+	ReturnSn      string          `gorm:"column:return_sn;comment:退款订单编号" json:"return_sn"`                                      // 退款订单编号
+	IsReport      int             `gorm:"column:is_report;comment:是否播报" json:"is_report"`                                        // 是否播报
+	PayCodeSource int             `gorm:"column:pay_code_source;default:1;comment:支付收款码来源 1普通收款码 2烟草收款码" json:"pay_code_source"` // 支付收款码来源 1普通收款码 2烟草收款码
+	IsBank        int             `gorm:"column:is_bank;comment:是否银联支付 0否1是" json:"is_bank"`                                     // 是否银联支付 0否1是
 }
 
 // TableName XShopOrder's table name
@@ -40,9 +41,67 @@ func (*XShopOrder) TableName() string {
 	return TableNameXShopOrder
 }
 
-//新增订单
+// 新增订单
 func (so *XShopOrder) CreateShopOrder() error {
 
 	err := config.Mdb.Model(&so).Create(&so).Error
 	return err
-}
+}
+
+// OrderInfo 订单详情(包含店铺名称)
+type OrderInfo struct {
+	RsSn     string          `json:"rs_sn"`     // 店铺订单支付编号
+	PaySn    string          `json:"pay_sn"`    // 支付编号
+	Status   int             `json:"status"`    // 订单状态
+	PayMoney decimal.Decimal `json:"pay_money"` // 支付金额
+	ShopName string          `json:"shop_name"` // 店铺名称
+}
+
+// GetOrderInfo 获取订单详情(关联店铺表)
+func (so *XShopOrder) GetOrderInfo(orderSn string) (OrderInfo, error) {
+	var info OrderInfo
+
+	err := config.Mdb.Table("x_shop_orders as o").
+		Joins("JOIN x_shops as s ON s.id = o.shop_id").
+		Where("o.rs_sn = ?", orderSn).
+		Select("o.rs_sn, o.pay_sn, o.status, o.pay_money, s.shop_name").
+		Find(&info).Error
+
+	return info, err
+}
+
+// BankOrderItem 银联待入账订单项
+type BankOrderItem struct {
+	RsSn       string          `json:"rs_sn"`       // 订单编号
+	PayMoney   decimal.Decimal `json:"pay_money"`   // 支付金额
+	IsClearing int             `json:"is_clearing"` // 是否清分
+	Status     int             `json:"status"`      // 订单状态
+	CreatedAt  time.Time       `json:"created_at"`  // 创建时间
+}
+
+// GetBankOrderList 获取银联待入账订单列表(最新 10 条)
+func (so *XShopOrder) GetBankOrderList(shopId int) ([]BankOrderItem, error) {
+	var items []BankOrderItem
+
+	// 查询最新 10 条记录
+	err := config.Mdb.Model(&XShopOrder{}).
+		Where("shop_id = ? AND status = ? AND is_bank = ?", shopId, 6, 1).
+		Select("rs_sn, pay_money, is_clearing, status, created_at").
+		Order("id desc").
+		Limit(10).
+		Find(&items).Error
+
+	return items, err
+}
+
+// GetTotalBankMoney 获取银联待入账总金额
+func (so *XShopOrder) GetTotalBankMoney(shopId int) (decimal.Decimal, error) {
+	var total decimal.Decimal
+
+	err := config.Mdb.Model(&XShopOrder{}).
+		Where("shop_id = ? AND status = ? AND is_bank = ?", shopId, 6, 1).
+		Select("COALESCE(SUM(pay_money), 0)").
+		Scan(&total).Error
+
+	return total, err
+}

+ 77 - 0
model/x_shops.gen.go

@@ -0,0 +1,77 @@
+// Code generated by gorm.io/gen. DO NOT EDIT.
+// Code generated by gorm.io/gen. DO NOT EDIT.
+// Code generated by gorm.io/gen. DO NOT EDIT.
+
+package model
+
+import (
+	"time"
+
+	"go_zh/config"
+
+	"github.com/shopspring/decimal"
+)
+
+const TableNameXShop = "x_shops"
+
+// XShop mapped from table <x_shops>
+type XShop struct {
+	ID            int             `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
+	ShopName      string          `gorm:"column:shop_name;not null;comment:店铺名称" json:"shop_name"`                           // 店铺名称
+	ShopSn        string          `gorm:"column:shop_sn;not null;comment:店铺编号" json:"shop_sn"`                               // 店铺编号
+	ShopPhone     string          `gorm:"column:shop_phone;not null;comment:店铺电话" json:"shop_phone"`                         // 店铺电话
+	Shopkeeper    string          `gorm:"column:shopkeeper;not null;comment:店主姓名" json:"shopkeeper"`                         // 店主姓名
+	ShopLogo      string          `gorm:"column:shop_logo;not null;comment:店铺logo" json:"shop_logo"`                         // 店铺logo
+	ClassID       int             `gorm:"column:class_id;not null;comment:一级分类ID" json:"class_id"`                           // 一级分类ID
+	ClassTwoID    int             `gorm:"column:class_two_id;not null;comment:二级分类ID" json:"class_two_id"`                   // 二级分类ID
+	ProvinceID    int             `gorm:"column:province_id;not null;comment:省份ID" json:"province_id"`                       // 省份ID
+	CityID        int             `gorm:"column:city_id;not null;comment:市ID" json:"city_id"`                                // 市ID
+	AreaID        int             `gorm:"column:area_id;not null;comment:区ID" json:"area_id"`                                // 区ID
+	StreetID      int             `gorm:"column:street_id;not null;comment:街道ID" json:"street_id"`                           // 街道ID
+	CityName      string          `gorm:"column:city_name;not null;comment:城市名称" json:"city_name"`                           // 城市名称
+	Address       string          `gorm:"column:address;not null;comment:详细地址" json:"address"`                               // 详细地址
+	Status        int             `gorm:"column:status;not null;comment:状态,0:待审核,1:已通过,2:已关闭" json:"status"`                 // 状态,0:待审核,1:已通过,2:已关闭
+	Type          int             `gorm:"column:type;not null;comment:类型:1:省代,2:市代,3:区代,4:分销商,5:店铺,6:自营店铺,7:厂家" json:"type"` // 类型:1:省代,2:市代,3:区代,4:分销商,5:店铺,6:自营店铺,7:厂家
+	IsDel         int             `gorm:"column:is_del;not null;comment:是否删除" json:"is_del"`                                 // 是否删除
+	Lon           float64         `gorm:"column:lon;not null;comment:经度" json:"lon"`                                         // 经度
+	Lat           float64         `gorm:"column:lat;not null;comment:纬度" json:"lat"`                                         // 纬度
+	CreatedAt     time.Time       `gorm:"column:created_at" json:"created_at"`
+	UpdatedAt     time.Time       `gorm:"column:updated_at" json:"updated_at"`
+	Sort          int             `gorm:"column:sort;not null;comment:排序" json:"sort"`                               // 排序
+	ClassName     string          `gorm:"column:class_name;not null;comment:分类名称" json:"class_name"`                 // 分类名称
+	ShopScore     float64         `gorm:"column:shop_score;default:0.00;comment:评分" json:"shop_score"`               // 评分
+	CollectNum    int             `gorm:"column:collect_num;comment:收藏人数" json:"collect_num"`                        // 收藏人数
+	ShopCode      string          `gorm:"column:shop_code;comment:推荐码" json:"shop_code"`                             // 推荐码
+	ShopShareImg  string          `gorm:"column:shop_share_img;comment:店铺推荐图" json:"shop_share_img"`                 // 店铺推荐图
+	MID           int             `gorm:"column:m_id;comment:绑定账户ID" json:"m_id"`                                    // 绑定账户ID
+	Sex           bool            `gorm:"column:sex;default:1;comment:性别" json:"sex"`                                // 性别
+	RecomShopID   int             `gorm:"column:recom_shop_id;comment:推广店铺ID" json:"recom_shop_id"`                  // 推广店铺ID
+	ShopMoney     decimal.Decimal `gorm:"column:shop_money;default:0.0000;comment:店铺余额" json:"shop_money"`           // 店铺余额
+	PurchaseMoney decimal.Decimal `gorm:"column:purchase_money;default:0.00;comment:店铺进货金" json:"purchase_money"`    // 店铺进货金
+	LicenseSn     string          `gorm:"column:license_sn;not null;comment:营业执照编号" json:"license_sn"`               // 营业执照编号
+	PayImg        string          `gorm:"column:pay_img;comment:收款码" json:"pay_img"`                                 // 收款码
+	GoodsAudit    bool            `gorm:"column:goods_audit;comment:商品是否审核1需要审核 0不用审核" json:"goods_audit"`           // 商品是否审核1需要审核 0不用审核
+	Discount      int             `gorm:"column:discount;comment:店铺折扣" json:"discount"`                              // 店铺折扣
+	AccreditIds   string          `gorm:"column:accredit_ids;comment:授权地址ids" json:"accredit_ids"`                   // 授权地址ids
+	CodeImg       string          `gorm:"column:code_img;comment:店铺code图片地址" json:"code_img"`                        // 店铺code图片地址
+	PayVoice      bool            `gorm:"column:pay_voice;default:1;comment:是否开启线下支付语音提醒 0否 1是" json:"pay_voice"`    // 是否开启线下支付语音提醒 0否 1是
+	OrderNotice   bool            `gorm:"column:order_notice;default:1;comment:是否开启新订单通知 0否 1是" json:"order_notice"` // 是否开启新订单通知 0否 1是
+	BankMoney     decimal.Decimal `gorm:"column:bank_money;default:0.00;comment:银联到账金额" json:"bank_money"`           // 银联到账金额
+	Openid        string          `gorm:"column:openid;comment:公众号id" json:"openid"`                                 // 公众号id
+	IsEquipment   int             `gorm:"column:is_equipment;comment:是否绑定设备" json:"is_equipment"`                    // 是否绑定设备
+	IsMove        int             `gorm:"column:is_move;default:1;comment:实体门店还是移动商贩 1是实体门店 2是移动商贩" json:"is_move"`  // 实体门店还是移动商贩 1是实体门店 2是移动商贩
+}
+
+// TableName XShop's table name
+func (*XShop) TableName() string {
+	return TableNameXShop
+}
+
+// GetShopByMemberId 根据会员 ID 获取店铺信息
+func (s *XShop) GetShopByMemberId(memberId int) (*XShop, error) {
+	shop := &XShop{}
+	err := config.Mdb.Model(s).
+		Where("m_id = ? AND is_del = ? AND status = ?", memberId, 0, 1).
+		First(shop).Error
+	return shop, err
+}

+ 5 - 1
request/api/shop_order.go

@@ -1,8 +1,12 @@
 package api
 
 type CreateOrderRequest struct {
-	ShopId        int    `binding:"required,gt=0" form:"shop_id" json:"shop_id" label:"商家id"`
+	ShopId        int    `binding:"required,gt=0" form:"shop_id" json:"shop_id" label:"商家 id"`
 	PayType       int    `binding:"required,gt=0,lt=3" form:"pay_type" json:"pay_type" label:"支付方式"`
 	PayMoney      string `binding:"required,gt=0,lte=1000000" form:"pay_money" json:"pay_money" label:"支付金额"`
 	PayCodeSource int    `binding:"omitempty" form:"pay_code_source" json:"pay_code_source" label:"收款码来源"`
 }
+
+type GetOrderInfoRequest struct {
+	OrderSn string `binding:"required,min=1,max=64" form:"order_sn" query:"order_sn" json:"order_sn" label:"订单编号"`
+}

+ 4 - 1
router/api_shop_order.go

@@ -1,9 +1,10 @@
 package router
 
 import (
-	"github.com/gin-gonic/gin"
 	"go_zh/api"
 	"go_zh/middleware"
+
+	"github.com/gin-gonic/gin"
 )
 
 func init() {
@@ -14,6 +15,8 @@ func init() {
 		shopOrderGroup := v1.Group("/shopOrder")
 		{
 			shopOrderGroup.GET("/create", api.ShopOrderController{}.GetOrderSn)
+			shopOrderGroup.GET("/info", api.ShopOrderController{}.GetOrderInfo)
+			shopOrderGroup.GET("/shopBankOrder", api.ShopOrderController{}.GetShopBankOrder)
 		}
 	})
 }