浏览代码

Merge branch 'cygx/mfyx_2.0' of http://8.136.199.33:3000/hongze/hz_crm_api into debug

xingzai 1 年之前
父节点
当前提交
e8444800c1
共有 5 个文件被更改,包括 217 次插入10 次删除
  1. 114 7
      controllers/cygx/order.go
  2. 3 3
      models/cygx/orde.go
  3. 90 0
      models/cygx/order_action.go
  4. 1 0
      models/db.go
  5. 9 0
      routers/commentsRouter.go

+ 114 - 7
controllers/cygx/order.go

@@ -24,6 +24,7 @@ type OrderController struct {
 // @Param   EndDate   query   string  false       "结束时间,列如2021-03-06 "
 // @Param   AdminId   query   string  false       "销售ID "
 // @Param   OrderType   query   int  false       "订单类型 1:畅读卡订单,2:单场付费订单"
+// @Param   OrderStatus   query   int  false       "订单状态,0:已取消、1:待支付、2:已支付、3:退款成功、4:退款处理中、5:退款异常、6:退款关闭"
 // @Param   PaymentProject   query   string  false       "付款项目"
 // @Param   OrderCode   query   string  false       "订单编号"
 // @Param   KeyWord   query   string  false       "搜索关键词"
@@ -46,11 +47,13 @@ func (this *OrderController) OrderList() {
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
 	orderType, _ := this.GetInt("OrderType", 1)
+	orderStatus, _ := this.GetInt("OrderStatus", -1)
 	startDate := this.GetString("StartDate")
 	endDate := this.GetString("EndDate")
 	adminId := this.GetString("AdminId")
 	orderCode := this.GetString("OrderCode")
 	keyWord := this.GetString("KeyWord")
+	paymentProject := this.GetString("PaymentProject")
 	var startSize int
 	if pageSize <= 0 {
 		pageSize = utils.PageSize20
@@ -61,7 +64,6 @@ func (this *OrderController) OrderList() {
 	startSize = utils.StartIndex(currentIndex, pageSize)
 	var condition string
 	var pars []interface{}
-
 	if orderType > 0 { //订单类型 1:畅读卡订单,2:单场付费订单
 		condition += `  AND order_type =   ? `
 		pars = append(pars, orderType)
@@ -76,12 +78,22 @@ func (this *OrderController) OrderList() {
 		condition += ` 	AND seller_id IN (` + adminId + `) `
 	}
 
+	if orderStatus > -1 { //订单状态
+		condition += ` 	AND order_status  = ?  `
+		pars = append(pars, orderStatus)
+	}
+
 	if orderCode != "" { //订单编号
 		orderCode = "%" + orderCode + "%"
 		condition += ` 	AND order_code LIKE ? `
 		pars = append(pars, orderCode)
 	}
 
+	if paymentProject != "" { //付款项目
+		condition += ` 	AND goods_name =  ? `
+		pars = append(pars, paymentProject)
+	}
+
 	if keyWord != "" { //用户姓名,手机号
 		keyWord = "%" + keyWord + "%"
 		condition += ` 	AND (mobile LIKE ?  OR  real_name LIKE ? ) `
@@ -116,12 +128,22 @@ func (this *OrderController) OrderList() {
 			item.HttpUrl = utils.CYGX_WEB_URL + "/activity/detail/" + strconv.Itoa(v.SourceId)
 		}
 		item.OrderStatus = v.OrderStatus
-		if v.OrderStatus == 0 {
+
+		switch item.OrderStatus {
+		case 0:
 			item.OrderStatusText = "已取消"
-		} else if v.OrderStatus == 1 {
+		case 1:
 			item.OrderStatusText = "待支付"
-		} else if v.OrderStatus == 2 {
+		case 2:
 			item.OrderStatusText = "已支付"
+		case 3:
+			item.OrderStatusText = "退款成功"
+		case 4:
+			item.OrderStatusText = "退款处理中"
+		case 5:
+			item.OrderStatusText = "退款异常"
+		case 6:
+			item.OrderStatusText = "退款关闭"
 		}
 		item.UserId = v.UserId
 		item.RealName = v.RealName
@@ -223,6 +245,7 @@ func (this *UserController) OrderRefund() {
 // @Param   EndDate   query   string  false       "结束时间,列如2021-03-06 "
 // @Param   AdminId   query   string  false       "销售ID "
 // @Param   OrderType   query   int  false       "订单类型 1:畅读卡订单,2:单场付费订单"
+// @Param   OrderStatus   query   int  false       "订单状态,0:已取消、1:待支付、2:已支付、3:退款成功、4:退款处理中、5:退款异常、6:退款关闭"
 // @Param   PaymentProject   query   string  false       "付款项目"
 // @Param   OrderCode   query   string  false       "订单编号"
 // @Param   KeyWord   query   string  false       "搜索关键词"
@@ -245,11 +268,13 @@ func (this *OrderController) OrderRefundList() {
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
 	orderType, _ := this.GetInt("OrderType", 1)
+	orderStatus, _ := this.GetInt("OrderStatus", -1)
 	startDate := this.GetString("StartDate")
 	endDate := this.GetString("EndDate")
 	adminId := this.GetString("AdminId")
 	orderCode := this.GetString("OrderCode")
 	keyWord := this.GetString("KeyWord")
+	paymentProject := this.GetString("PaymentProject")
 	var startSize int
 	if pageSize <= 0 {
 		pageSize = utils.PageSize20
@@ -260,7 +285,7 @@ func (this *OrderController) OrderRefundList() {
 	startSize = utils.StartIndex(currentIndex, pageSize)
 	var condition string
 	var pars []interface{}
-	condition += `  AND order_status =   3 `
+	condition += `  AND order_status  IN  (3,4,5,6) `
 	if orderType > 0 { //订单类型 1:畅读卡订单,2:单场付费订单
 		condition += `  AND order_type =   ? `
 		pars = append(pars, orderType)
@@ -275,12 +300,22 @@ func (this *OrderController) OrderRefundList() {
 		condition += ` 	AND seller_id IN (` + adminId + `) `
 	}
 
+	if orderStatus > -1 { //订单状态
+		condition += ` 	AND order_status  = ?  `
+		pars = append(pars, orderStatus)
+	}
+
 	if orderCode != "" { //订单编号
 		orderCode = "%" + orderCode + "%"
 		condition += ` 	AND order_code LIKE ? `
 		pars = append(pars, orderCode)
 	}
 
+	if paymentProject != "" { //付款项目
+		condition += ` 	AND goods_name =  ? `
+		pars = append(pars, paymentProject)
+	}
+
 	if keyWord != "" { //用户姓名,手机号
 		keyWord = "%" + keyWord + "%"
 		condition += ` 	AND (mobile LIKE ?  OR  real_name LIKE ? ) `
@@ -314,11 +349,17 @@ func (this *OrderController) OrderRefundList() {
 		case "activity": //活动详情
 			item.HttpUrl = utils.CYGX_WEB_URL + "/activity/detail/" + strconv.Itoa(v.SourceId)
 		}
+		//OrderStatus      int       `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:退款成功、4:退款处理中、5:退款异常、6:退款关闭"`
 		item.OrderStatus = v.OrderStatus
-		if v.OrderStatus == 3 {
+		switch item.OrderStatus {
+		case 3:
 			item.OrderStatusText = "退款成功"
-		} else {
+		case 4:
+			item.OrderStatusText = "退款处理中"
+		case 5:
 			item.OrderStatusText = "退款异常"
+		case 6:
+			item.OrderStatusText = "退款关闭"
 		}
 		item.UserId = v.UserId
 		item.RealName = v.RealName
@@ -350,3 +391,69 @@ func (this *OrderController) OrderRefundList() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 退款撤销
+// @Description 退款撤销接口
+// @Param	request	body cygx.UserRemarAddReq true "type json string"
+// @Success 200 操作成功
+// @router /order/refund_revoke [post]
+func (this *UserController) OrderRefundRevoke() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req cygx.CygxOrderRefundReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	orderCode := req.OrderCode
+	orderDetail, err := cygx.GetCygxOrderDetailByOrderCode(orderCode)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败, Err:" + err.Error()
+		return
+	}
+	if orderDetail.OrderStatus != 4 {
+		br.Msg = "订单状态异常!"
+		br.ErrMsg = "订单状态异常,orderCode:" + orderCode
+		return
+	}
+
+	item := new(cygx.CygxOrderAction)
+	item.Action = "关闭退款"
+	item.OrderStatus = 6
+	item.OrderStatusText = "关闭退款"
+	item.OrderCode = orderDetail.OrderCode
+	item.UserId = orderDetail.UserId
+	item.RealName = orderDetail.RealName
+	item.Mobile = orderDetail.Mobile
+	item.Email = orderDetail.Email
+	item.CompanyId = orderDetail.CompanyId
+	item.CompanyName = orderDetail.CompanyName
+	item.SellerName = orderDetail.SellerName
+	item.CreateTime = time.Now()
+	item.ModifyTime = time.Now()
+	item.AdminId = sysUser.AdminId
+	item.AdminName = sysUser.RealName
+
+	err = cygx.AddCygxOrderRefundRevoke(item)
+	if err != nil {
+		br.Msg = "新增失败."
+		br.ErrMsg = "新增失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}

+ 3 - 3
models/cygx/orde.go

@@ -53,9 +53,9 @@ type CygxOrderResp struct {
 	PointMoney       float64   `comment:"订单消耗积分抵多少钱"`
 	PayMoney         float64   `comment:"订单实付金额"`
 	RefundMoney      float64   `comment:"订单退款金额"`
-	RefundTime       time.Time `description:"退款时间"`
-	RefundRemark     string    `description:"退款原因说明"`
-	OrderStatus      int       `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
+	RefundTime       time.Time `comment:"退款时间"`
+	RefundRemark     string    `comment:"退款原因说明"`
+	OrderStatus      int       `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:退款成功、4:退款处理中、5:退款异常、6:退款关闭"`
 	PayTime          time.Time `comment:"订单付款时间"`
 	SourceId         int       `comment:"来源ID"`
 	Source           string    `comment:"来源\n报告 :article\n活动 :activity"`

+ 90 - 0
models/cygx/order_action.go

@@ -0,0 +1,90 @@
+package cygx
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// /订单操作表
+type CygxOrderAction struct {
+	ActionId         int       `orm:"column(action_id);pk";comment:"动作id"`
+	Action           string    `comment:"动作内容"`
+	OrderStatus      int       `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
+	OrderStatusText  string    `comment:"订单状态名称"`
+	OrderCode        string    `comment:"订单编号"`
+	UserId           int       `comment:"用户ID"`
+	Mobile           string    `comment:"手机号"`
+	Email            string    `comment:"邮箱"`
+	CompanyId        int       `comment:"公司ID"`
+	CompanyName      string    `comment:"公司名称"`
+	RealName         string    `comment:"用户实际名称"`
+	SellerName       string    `comment:"所属销售"`
+	CreateTime       time.Time `comment:"创建时间"`
+	ModifyTime       time.Time `comment:"修改时间"`
+	RegisterPlatform int       `comment:"来源 1小程序,2:网页"`
+	AdminId          int       `comment:"管理员ID"`
+	AdminName        string    `comment:"管理员姓名"`
+}
+
+func AddCygxOrderRefundRevoke(item *CygxOrderAction) (err error) {
+	to := orm.NewOrmUsingDB("hz_cygx")
+	o, err := to.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+		} else {
+			_ = o.Commit()
+		}
+	}()
+	updateParams := make(map[string]interface{})
+	updateParams["OrderStatus"] = 6 //退款关闭
+	ptrStructOrTableName := "cygx_order"
+	whereParam := map[string]interface{}{"order_code": item.OrderCode}
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range whereParam {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err = qs.Update(updateParams)
+	if err != nil {
+		return
+	}
+
+	_, err = o.Insert(item)
+	return
+}
+
+//// 添加CygxOrderRefund
+//func AddCygxOrderRefundRevoke(item *CygxOrderRefund) (err error) {
+//	to := orm.NewOrmUsingDB("hz_cygx")
+//	o, err := to.Begin()
+//	if err != nil {
+//		return
+//	}
+//	defer func() {
+//		if err != nil {
+//			_ = o.Rollback()
+//		} else {
+//			_ = o.Commit()
+//		}
+//	}()
+//	updateParams := make(map[string]interface{})
+//	updateParams["OrderStatus"] = 3
+//	updateParams["RefundMoney"] = item.RefundMoney
+//	updateParams["RefundRemark"] = item.Remark
+//	updateParams["RefundTime"] = time.Now()
+//	ptrStructOrTableName := "cygx_order"
+//	whereParam := map[string]interface{}{"order_code": item.OrderCode}
+//	qs := o.QueryTable(ptrStructOrTableName)
+//	for expr, exprV := range whereParam {
+//		qs = qs.Filter(expr, exprV)
+//	}
+//	_, err = qs.Update(updateParams)
+//	if err != nil {
+//		return
+//	}
+//	_, err = o.Insert(item)
+//	return
+//}

+ 1 - 0
models/db.go

@@ -474,6 +474,7 @@ func initCygx() {
 		new(cygx.CygxUserYanxuanPermissionLog),
 		new(cygx.CygxOrderRefund),
 		new(cygx.CygxOrder),
+		new(cygx.CygxOrderAction),
 	)
 }
 

+ 9 - 0
routers/commentsRouter.go

@@ -2905,6 +2905,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/cygx:UserController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/cygx:UserController"],
+        beego.ControllerComments{
+            Method: "OrderRefundRevoke",
+            Router: `/order/refund_revoke`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/cygx:UserController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/cygx:UserController"],
         beego.ControllerComments{
             Method: "Add",