|
@@ -0,0 +1,322 @@
|
|
|
+package controllers
|
|
|
+
|
|
|
+import (
|
|
|
+ "eta/eta_mini_crm_ht/models"
|
|
|
+ "eta/eta_mini_crm_ht/models/response"
|
|
|
+ "eta/eta_mini_crm_ht/utils"
|
|
|
+ "fmt"
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+ "sync"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ ProductOrderStatus = map[models.OrderStatus]string{
|
|
|
+ "pending": "待支付",
|
|
|
+ "processing": "支付中",
|
|
|
+ "paid": "已支付",
|
|
|
+ "closed": "已关闭",
|
|
|
+ "refund": "已退款",
|
|
|
+ }
|
|
|
+
|
|
|
+ TradeOrderStatus = map[models.PaymentStatus]string{
|
|
|
+ "pending": "待支付",
|
|
|
+ "failed": "支付失败",
|
|
|
+ "done": "支付成功",
|
|
|
+ }
|
|
|
+
|
|
|
+ RefundOrderStatus = map[models.PaymentStatus]string{
|
|
|
+ "pending": "退款中",
|
|
|
+ "failed": "退款失败",
|
|
|
+ "done": "退款成功",
|
|
|
+ }
|
|
|
+ RefundStatusMap = map[models.RefundStatus]string{
|
|
|
+ "pending": "待退款",
|
|
|
+ "processing": "退款中",
|
|
|
+ "failed": "退款失败",
|
|
|
+ "success": "退款成功",
|
|
|
+ "canceled": "已取消",
|
|
|
+ }
|
|
|
+ ProductTypeMap = map[models.MerchantProductType]string{
|
|
|
+ "report": "报告",
|
|
|
+ "video": "视频",
|
|
|
+ "audio": "音频",
|
|
|
+ "package": "套餐",
|
|
|
+ }
|
|
|
+ PaymentWayMap = map[models.PaymentWay]string{
|
|
|
+ "wechat": "微信",
|
|
|
+ "alipay": "支付宝",
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
+type OrderController struct {
|
|
|
+ BaseAuthController
|
|
|
+}
|
|
|
+
|
|
|
+// ProductOrderList
|
|
|
+// @Title 商品订单列表
|
|
|
+// @Description 商品订单列表
|
|
|
+// @Param PageSize query int true "每页数据条数"
|
|
|
+// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
+// @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
|
|
|
+// @Param KeyWord query string true "报告标题/创建人"
|
|
|
+// @Param SortType query string true "排序方式"
|
|
|
+// @Success 200 {object} models.ReportAuthorResp
|
|
|
+// @router /productOrderList [get]
|
|
|
+func (this *OrderController) ProductOrderList() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ pageSize, _ := this.GetInt("PageSize")
|
|
|
+ currentIndex, _ := this.GetInt("CurrentIndex")
|
|
|
+ sortType := this.GetString("SortType")
|
|
|
+ KeyWord := this.GetString("KeyWord")
|
|
|
+
|
|
|
+ PaymentDate := this.GetString("PaymentDate")
|
|
|
+ PaymentWay := this.GetString("PaymentWay")
|
|
|
+ CreatedDate := this.GetString("CreatedDate")
|
|
|
+ ProductType := this.GetString("ProductType")
|
|
|
+ RefundStatus := this.GetString("RefundStatus")
|
|
|
+ OrderStatus := this.GetString("OrderStatus")
|
|
|
+ var condition string
|
|
|
+ if pageSize <= 0 {
|
|
|
+ pageSize = utils.PageSize20
|
|
|
+ }
|
|
|
+ if currentIndex <= 0 {
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+ if KeyWord != "" {
|
|
|
+ condition += " AND (product_name like '%" + KeyWord + "%' or real_name like '%" + KeyWord + "%' order_id like '%" + KeyWord + "%' or mobile like '%" + KeyWord + "%')"
|
|
|
+ }
|
|
|
+ sortCondition := " ORDER BY created_time "
|
|
|
+ if sortType == "" {
|
|
|
+ sortType = "DESC"
|
|
|
+ }
|
|
|
+ if CreatedDate != "" {
|
|
|
+ condition += " AND Date(created_time) = '" + CreatedDate + "'"
|
|
|
+ }
|
|
|
+ if PaymentDate != "" {
|
|
|
+ condition += " AND Date(payment_time) = '" + PaymentDate + "'"
|
|
|
+ }
|
|
|
+ if PaymentWay != "" {
|
|
|
+ condition += " AND payment_way='" + PaymentWay + "'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if OrderStatus != "" {
|
|
|
+ switch OrderStatus {
|
|
|
+ case "pending":
|
|
|
+ condition += " AND status='pending'"
|
|
|
+ case "paid":
|
|
|
+ condition += " AND status='paid'"
|
|
|
+ case "closed":
|
|
|
+ condition += " AND status='closed'"
|
|
|
+ case "refund":
|
|
|
+ condition += " AND status='refund'"
|
|
|
+ if RefundStatus != "" {
|
|
|
+ switch RefundStatus {
|
|
|
+ case "pending":
|
|
|
+ condition += " AND refund_status='pending'"
|
|
|
+ case "processing":
|
|
|
+ condition += " AND refund_status='processing'"
|
|
|
+ case "failed":
|
|
|
+ condition += " AND refund_status='failed'"
|
|
|
+ case "success":
|
|
|
+ condition += " AND refund_status='success'"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ br.Msg = "无效的订单状态"
|
|
|
+ br.ErrMsg = "无效的订单状态:" + OrderStatus
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ProductType != "" {
|
|
|
+ switch ProductType {
|
|
|
+ case "report":
|
|
|
+ condition += " AND product_type='" + string(models.ProductReport) + "'"
|
|
|
+ case "audio":
|
|
|
+ condition += " AND product_type='" + string(models.ProductAudio) + "'"
|
|
|
+ case "video":
|
|
|
+ condition += " AND product_type='" + string(models.ProductVideo) + "'"
|
|
|
+ case "package":
|
|
|
+ condition += " AND product_type='" + string(models.ProductPackage) + "'"
|
|
|
+ default:
|
|
|
+ br.Msg = "无效的产品类型"
|
|
|
+ br.ErrMsg = "无效的产品类型:" + ProductType
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sortCondition = sortCondition + sortType
|
|
|
+ total, err := models.GetProductOrderCountByCondition(condition)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取商品列表失败"
|
|
|
+ br.ErrMsg = "获取商品列表失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ startSize := utils.StartIndex(currentIndex, pageSize)
|
|
|
+ List, err := models.GetProductOrderByCondition(condition, sortCondition, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取商品列表失败"
|
|
|
+ br.ErrMsg = "获取商品列表失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var ListView []*models.ProductOrderView
|
|
|
+ for _, order := range List {
|
|
|
+ view := &models.ProductOrderView{
|
|
|
+ OrderID: order.OrderID,
|
|
|
+ RealName: order.RealName,
|
|
|
+ Mobile: fmt.Sprintf("+%s %s", order.AreaCode, order.Mobile),
|
|
|
+ ProductType: ProductTypeMap[order.ProductType],
|
|
|
+ ProductName: order.ProductName,
|
|
|
+ TotalAmount: order.TotalAmount,
|
|
|
+ TradeNO: order.TradeNO,
|
|
|
+ RefundAmount: order.RefundAmount,
|
|
|
+ PaymentWay: PaymentWayMap[order.PaymentWay],
|
|
|
+ PaymentTime: order.PaymentTime.Format(time.DateTime),
|
|
|
+ Status: ProductOrderStatus[order.Status],
|
|
|
+ RefundStatus: RefundStatusMap[order.RefundStatus],
|
|
|
+ RefundFinishTime: order.RefundFinishTime.Format(time.DateTime),
|
|
|
+ Remark: order.Remark,
|
|
|
+ CreatedTime: order.CreatedTime.Format(time.DateTime),
|
|
|
+ }
|
|
|
+ ListView = append(ListView, view)
|
|
|
+ }
|
|
|
+ page := paging.GetPaging(currentIndex, pageSize, total)
|
|
|
+ resp := new(response.ProductOrderListResp)
|
|
|
+ resp.List = ListView
|
|
|
+ resp.Paging = page
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Data = resp
|
|
|
+ br.Msg = "获取成功"
|
|
|
+}
|
|
|
+
|
|
|
+// TradeOrderList
|
|
|
+// @Title 支付订单列表
|
|
|
+// @Description 支付订单列表
|
|
|
+// @Param PageSize query int true "每页数据条数"
|
|
|
+// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
+// @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
|
|
|
+// @Param KeyWord query string true "报告标题/创建人"
|
|
|
+// @Param SortType query string true "排序方式"
|
|
|
+// @Success 200 {object} models.ReportAuthorResp
|
|
|
+// @router /tradeOrderList [get]
|
|
|
+func (this *OrderController) TradeOrderList() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ pageSize, _ := this.GetInt("PageSize")
|
|
|
+ currentIndex, _ := this.GetInt("CurrentIndex")
|
|
|
+ sortType := this.GetString("SortType")
|
|
|
+ KeyWord := this.GetString("KeyWord")
|
|
|
+ DealDate := this.GetString("DealDate")
|
|
|
+ PaymentWay := this.GetString("PaymentWay")
|
|
|
+ CreatedDate := this.GetString("CreatedDate")
|
|
|
+ OrderStatus := this.GetString("OrderStatus")
|
|
|
+ IsRefund, _ := this.GetBool("IsRefund", false)
|
|
|
+ var condition string
|
|
|
+ if pageSize <= 0 {
|
|
|
+ pageSize = utils.PageSize20
|
|
|
+ }
|
|
|
+ if currentIndex <= 0 {
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+ if IsRefund {
|
|
|
+ condition += " AND payment_type ='" + string(models.PaymentTypeRefund) + "'"
|
|
|
+ } else {
|
|
|
+ condition += " AND payment_type ='" + string(models.PaymentTypePay) + "'"
|
|
|
+ }
|
|
|
+ if KeyWord != "" {
|
|
|
+ condition += " AND (product_name like '%" + KeyWord + "%' or real_name like '%" + KeyWord + "%' order_id like '%" + KeyWord + "%' or mobile like '%" + KeyWord + "%')"
|
|
|
+ }
|
|
|
+ sortCondition := " ORDER BY created_time "
|
|
|
+ if sortType == "" {
|
|
|
+ sortType = "DESC"
|
|
|
+ }
|
|
|
+ if CreatedDate != "" {
|
|
|
+ condition += " AND Date(created_time) = '" + CreatedDate + "'"
|
|
|
+ }
|
|
|
+ if DealDate != "" {
|
|
|
+ condition += " AND Date(deal_time) = '" + DealDate + "'"
|
|
|
+ }
|
|
|
+ if PaymentWay != "" {
|
|
|
+ condition += " AND payment_way='" + PaymentWay + "'"
|
|
|
+ }
|
|
|
+
|
|
|
+ if OrderStatus != "" {
|
|
|
+ switch OrderStatus {
|
|
|
+ case "pending":
|
|
|
+ condition += " AND payment_status='pending'"
|
|
|
+ case "done":
|
|
|
+ condition += " AND payment_status='done'"
|
|
|
+ case "failed":
|
|
|
+ condition += " AND payment_status='failed'"
|
|
|
+ default:
|
|
|
+ br.Msg = "无效的支付订单状态"
|
|
|
+ br.ErrMsg = "无效的支付订单状态:" + OrderStatus
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sortCondition = sortCondition + sortType
|
|
|
+ total, err := models.GetTradeOrderCountByCondition(condition)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取支付明细列表失败"
|
|
|
+ br.ErrMsg = "获取支付明细列表失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ startSize := utils.StartIndex(currentIndex, pageSize)
|
|
|
+ List, err := models.GetTradeOrderByCondition(condition, sortCondition, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取支付明细列表失败"
|
|
|
+ br.ErrMsg = "获取支付明细列表失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var ListView []*models.TradeOrderView
|
|
|
+ var wg sync.WaitGroup
|
|
|
+ wg.Add(len(List))
|
|
|
+ for i := 0; i < len(List); i++ {
|
|
|
+ go func(order *models.TradeOrder) {
|
|
|
+ defer wg.Done()
|
|
|
+ productOrder, pdErr := models.GetProductOrderByID(order.ProductOrderId)
|
|
|
+ if pdErr != nil {
|
|
|
+ utils.FileLog.Error("获取商品订单信息失败,Err:" + pdErr.Error())
|
|
|
+ }
|
|
|
+ view := &models.TradeOrderView{
|
|
|
+ RealName: productOrder.RealName,
|
|
|
+ Mobile: fmt.Sprintf("+%s %s", productOrder.AreaCode, productOrder.Mobile),
|
|
|
+ ProductName: productOrder.ProductName,
|
|
|
+ Amount: order.Amount,
|
|
|
+ TransactionID: order.TransactionId,
|
|
|
+ ProductOrderID: order.ProductOrderId,
|
|
|
+ PaymentWay: PaymentWayMap[order.PaymentWay],
|
|
|
+ PaymentAccount: order.PaymentAccount,
|
|
|
+ MerchantID: order.MerchantId,
|
|
|
+ DealTime: order.DealTime.Format(time.DateTime),
|
|
|
+ CreatedTime: order.CreatedTime.Format(time.DateTime),
|
|
|
+ }
|
|
|
+ if IsRefund {
|
|
|
+ view.PaymentStatus = RefundOrderStatus[order.PaymentStatus]
|
|
|
+ } else {
|
|
|
+ view.PaymentStatus = TradeOrderStatus[order.PaymentStatus]
|
|
|
+ }
|
|
|
+ ListView = append(ListView, view)
|
|
|
+ }(List[i])
|
|
|
+
|
|
|
+ }
|
|
|
+ wg.Wait()
|
|
|
+ page := paging.GetPaging(currentIndex, pageSize, total)
|
|
|
+ resp := new(response.TradeOrderListResp)
|
|
|
+ resp.List = ListView
|
|
|
+ resp.Paging = page
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Data = resp
|
|
|
+ br.Msg = "获取成功"
|
|
|
+}
|