Forráskód Böngészése

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

xingzai 1 éve
szülő
commit
7b29545ec0
4 módosított fájl, 219 hozzáadás és 0 törlés
  1. 12 0
      models/db.go
  2. 160 0
      models/order/order.go
  3. 44 0
      services/order.go
  4. 3 0
      services/task.go

+ 12 - 0
models/db.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	_ "github.com/go-sql-driver/mysql"
+	"hongze/hongze_cygx/models/order"
 	"hongze/hongze_cygx/utils"
 	"time"
 
@@ -190,8 +191,19 @@ func init() {
 		new(CygxTimelineLog),
 		new(CygxActivitySpecialPermissionPoints),
 	)
+
+	initOrder() // 订单模块
+
 	// 记录ORM查询日志
 	orm.Debug = true
 	orm.DebugLog = orm.NewLog(utils.BinLog)
 
 }
+
+// initOrder 买方研选订单模块
+func initOrder() {
+	orm.RegisterModel(
+		new(order.CygxOrder),       //订单表
+		new(order.CygxOrderAction), //订单操表
+	)
+}

+ 160 - 0
models/order/order.go

@@ -0,0 +1,160 @@
+package order
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxOrderResp struct {
+	OrderId          int       `orm:"column(order_id);pk";comment:"订单id"`
+	OrderCode        string    `comment:"订单编号"`
+	OutTradeCode     string    `comment:"外部交易号"`
+	PaymentType      int       `comment:"支付类型。取值范围:1微信支付,2支付宝支付。"`
+	GoodsName        string    `comment:"商品名称"`
+	GoodsId          int       `comment:"商品ID"`
+	BuyerInvoice     string    `comment:"买家发票信息"`
+	GoodsMoney       float64   `comment:"商品总价"`
+	OrderMoney       float64   `comment:"订单总价"`
+	Point            int       `comment:"订单消耗积分"`
+	PointMoney       float64   `comment:"订单消耗积分抵多少钱"`
+	PayMoney         float64   `comment:"订单实付金额"`
+	RefundMoney      float64   `comment:"订单退款金额"`
+	OrderStatus      int       `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
+	PayTime          time.Time `comment:"订单付款时间"`
+	SourceId         int       `comment:"来源ID"`
+	Source           string    `comment:"来源\n报告 :article\n活动 :activity"`
+	SourceTitle      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:网页"`
+	StartDate        time.Time `comment:"开始时间"`
+	EndDate          time.Time `comment:"结束时间"`
+}
+
+// 订单表
+type CygxOrder struct {
+	OrderId          int       `orm:"column(order_id);pk";comment:"订单id"`
+	OrderCode        string    `comment:"订单编号"`
+	OutTradeCode     string    `comment:"外部交易号"`
+	PaymentType      int       `comment:"支付类型。取值范围:1微信支付,2支付宝支付。"`
+	GoodsName        string    `comment:"商品名称"`
+	GoodsId          int       `comment:"商品ID"`
+	BuyerInvoice     string    `comment:"买家发票信息"`
+	GoodsMoney       float64   `comment:"商品总价"`
+	OrderMoney       float64   `comment:"订单总价"`
+	Point            int       `comment:"订单消耗积分"`
+	PointMoney       float64   `comment:"订单消耗积分抵多少钱"`
+	PayMoney         float64   `comment:"订单实付金额"`
+	RefundTime       time.Time `comment:"订单退款时间"`
+	RefundMoney      float64   `comment:"订单退款金额"`
+	OrderStatus      int       `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
+	PayTime          time.Time `comment:"订单付款时间"`
+	SourceId         int       `comment:"来源ID"`
+	Source           string    `comment:"来源\n报告 :article\n活动 :activity"`
+	SourceTitle      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:"所属销售"`
+	SellerId         int       `comment:"所属销售Id"`
+	CreateTime       time.Time `comment:"创建时间"`
+	ModifyTime       time.Time `comment:"修改时间"`
+	RegisterPlatform int       `comment:"来源 1小程序,2:网页"`
+	OrderType        int       `comment:"订单类型,1:畅读卡订单,2:单场付费订单"`
+	StartDate        time.Time `comment:"开始时间"`
+	EndDate          time.Time `comment:"结束时间"`
+}
+
+// 订单操作表
+type CygxOrderAction struct {
+	ActionId         int64     `orm:"column(action_id);pk"` // 动作id
+	Action           string    // 动作内容
+	OrderStatus      int       // 订单状态,0:已取消、1:待支付、2:已支付、3:已退款
+	OrderStatusText  string    // 订单状态名称
+	OrderCode        string    // 订单编号
+	UserId           int       // 用户ID
+	Mobile           string    // 手机号
+	Email            string    // 邮箱
+	CompanyId        int       // 公司ID
+	CompanyName      string    // 公司名称
+	RealName         string    // 用户实际名称
+	SellerName       string    // 所属销售
+	CreateTime       time.Time // 创建时间
+	ModifyTime       time.Time // 修改时间
+	RegisterPlatform int       // 来源 1小程序,2:网页
+	AdminId          int       // 管理员ID
+	AdminName        string    // 管理员姓名
+}
+
+func GetCygxOrderList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxOrder, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_order
+			WHERE 1 = 1 ` + condition
+	sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+// 自动取消订单
+func CancelCygxOrder(item *CygxOrder) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+	itemOrderAction := new(CygxOrderAction)
+	itemOrderAction.Action = "超时自动取消订单"
+	itemOrderAction.OrderStatus = 0
+	itemOrderAction.OrderStatusText = "已取消"
+	itemOrderAction.OrderCode = item.OrderCode
+	itemOrderAction.UserId = item.UserId
+	itemOrderAction.Mobile = item.Mobile
+	itemOrderAction.Email = item.Email
+	itemOrderAction.CompanyId = item.CompanyId
+	itemOrderAction.CompanyName = item.CompanyName
+	itemOrderAction.RealName = item.RealName
+	itemOrderAction.SellerName = item.SellerName
+	itemOrderAction.CreateTime = time.Now()
+	itemOrderAction.ModifyTime = time.Now()
+	itemOrderAction.RegisterPlatform = item.RegisterPlatform
+
+	_, err = o.Insert(itemOrderAction) // 写入订单操作信息
+	if err != nil {
+		return
+	}
+
+	updateParams := make(map[string]interface{})
+	updateParams["OrderStatus"] = 0
+	updateParams["ModifyTime"] = item.ModifyTime
+	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
+	}
+	return
+}

+ 44 - 0
services/order.go

@@ -0,0 +1,44 @@
+package services
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"hongze/hongze_cygx/models/order"
+	"hongze/hongze_cygx/utils"
+	"time"
+)
+
+// CancelCygxOrder 关闭到期个人用户研选权限
+func CancelCygxOrder(cont context.Context) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("自动取消十分钟之内没有付款的的订单 CancelCygxOrder ,err:", err.Error()), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	endTime := time.Now().Add(-10 * time.Minute)
+	condition = ` AND order_status = 1   AND create_time < ?   `
+	pars = append(pars, endTime)
+	orderList, e := order.GetCygxOrderList(condition, pars, 0, 999)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCygxOrderList, Err: " + e.Error())
+		return
+	}
+	fmt.Println(len(orderList))
+	if len(orderList) == 0 {
+		return
+	}
+	//订单量不大,先这么写吧
+	for _, v := range orderList {
+		fmt.Println(v.OrderCode)
+		e = order.CancelCygxOrder(v)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = errors.New("CancelCygxOrder, Err: " + e.Error())
+			return
+		}
+	}
+	return
+}

+ 3 - 0
services/task.go

@@ -132,6 +132,9 @@ func Task() {
 		updateCygxUserYanxuanPermissionToClose := task.NewTask("updateCygxUserYanxuanPermissionToClose", "0 10 1 * * *", UpdateCygxUserYanxuanPermissionToClose)
 		task.AddTask("updateCygxUserYanxuanPermissionToClose", updateCygxUserYanxuanPermissionToClose) //关闭到期个人用户研选权限
 
+		cancelCygxOrder := task.NewTask("CancelCygxOrder", "0 */1 * * * *", CancelCygxOrder)
+		task.AddTask("十分钟内未付款的订单自动取消", cancelCygxOrder) //十分钟内未付款的订单自动取消
+
 	}
 	//if utils.RunMode != "release" {
 	//	getArticleListByApi := task.NewTask("getArticleListByApi", "0 */60 * * * *", GetArticleListByApi) //通过三方接口获取策略平台上的文章