Browse Source

order

master
黄梓健 5 years ago
parent
commit
96fed7fdf9
  1. 15
      controllers/base.go
  2. 178
      controllers/client/good.go
  3. 22
      controllers/client/invite_envelope.go
  4. 14
      controllers/client/live.go
  5. 10
      controllers/client/wx.go
  6. 7
      log/hdzj.log
  7. 6
      models/customer_goods.go
  8. 28
      models/customer_order.go
  9. 36
      models/customer_order_sub.go
  10. 1
      models/init_models.go
  11. 3
      models/live_config.go
  12. 8
      models/test/config.json
  13. 11
      models/test/private.json
  14. 32
      models/test/sensitive_test.go
  15. BIN
      models/test/敏感词汇.xlsx
  16. 2
      models/user_order.go
  17. 18
      services/pay/order.go
  18. 5
      utils/code/code.go

15
controllers/base.go

@ -6,6 +6,7 @@ import (
"hudongzhuanjia/logger"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"net/http"
"strconv"
"github.com/ouxuanserver/osmanthuswine/src/core"
@ -20,7 +21,17 @@ type BaseCtl struct {
}
func (t *BaseCtl) Prepare() {
//t.OriginResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
t.OriginResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
t.OriginResponseWriter.Header().Set("Access-Control-Allow-Credentials", "true")
t.OriginResponseWriter.Header().Set("Access-Control-Allow-Methods", "*")
t.OriginResponseWriter.Header().Set("Access-Control-Allow-Headers", "Content-Type,Access-Token")
t.OriginResponseWriter.Header().Set("Access-Control-Expose-Headers", "*")
if t.Request.OriginRequest.Method == "OPTIONS" {
t.OriginResponseWriter.WriteHeader(http.StatusOK)
t.OriginResponseWriter.Write(nil)
return
}
t.Page, _ = t.GetInt("page")
t.PageSize, _ = t.GetInt("page_size")
t.Limit = t.Page * t.PageSize
@ -28,6 +39,10 @@ func (t *BaseCtl) Prepare() {
type M map[string]interface{}
func (t *BaseCtl) Bind(obj interface{}) error {
return t.RequestToStruct(obj)
}
func (t *BaseCtl) Get(key string) (value string, exist bool) {
value, exist = t.Request.REQUEST[key]
return

178
controllers/client/good.go

@ -1,6 +1,7 @@
package client
import (
"encoding/json"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
@ -20,7 +21,11 @@ func (t *GoodCtl) GoodOption() {
option := new(models.CustomerOrderOption)
exist, err := option.GetByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "订单活动不存在")
if !exist {
t.JSON([]interface{}{})
return
}
//t.Assert(exist, code.MSG_ORDER_NOT_EXIST, "订单活动不存在")
t.JSON(option)
}
@ -33,11 +38,19 @@ func (t *GoodCtl) ListGood() {
option := new(models.CustomerOrderOption)
exist, err := option.GetByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "订单活动不存在")
if !exist {
t.JSON([]interface{}{})
return
}
//t.Assert(exist, code.MSG_ORDER_NOT_EXIST, "订单活动不存在")
goods, err := models.GetGoodsByActivityId(activityId, areaId)
t.CheckErr(err)
//
//for index := range goods {
// goods[index].GoodType = option.PostFeeType
// goods[index].Postage = option.PostFee
//}
t.JSON(goods)
return
}
@ -46,36 +59,64 @@ func (t *GoodCtl) ListOrder() {
activityId := t.MustGetInt64("activity_id")
status := t.MustGetInt("status")
areaId := t.MustGetInt64("area_id")
uid := t.MustGetUID()
activity := new(models.Activity)
exist, err := models.GetById(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
orders, err := models.GetCustomerOrdersByActivityId(activity.Id, activity.RehearsalId, areaId, status)
orders, err := models.GetCustomerOrdersByActivityId(uid, activity.Id, activity.RehearsalId, areaId, status)
t.CheckErr(err)
outTradeNos := make([]string, 0)
for _, order := range orders {
outTradeNos = append(outTradeNos, order.OutTradeNo)
}
subs, err := models.GetCustomerOrderSubByOutTradeNos(outTradeNos)
t.CheckErr(err)
for index, order := range orders {
for _, sub := range subs {
if order.OutTradeNo == sub.OutTradeNo {
orders[index].SubOrders = append(orders[index].SubOrders, sub)
}
}
}
t.JSON(orders)
}
type OrderParam struct {
ActivityId int64 `json:"activity_id"`
AreaId int64 `json:"area_id"`
Name string `json:"name"`
Phone string `json:"phone"`
Address string `json:"address"`
Goods interface{} `json:"goods"`
}
// 下订单
func (t *GoodCtl) Order() {
userId := t.MustGetUID() //
activityId := t.MustGetInt64("activity_id")
areaId := t.MustGetInt64("area_id") // 地区id
name := t.MustGet("name") // 收货人名字
phone := t.MustGet("phone") // 收货电话
address := t.MustGet("address") // 收货地址
goodId := t.MustGetInt64("good_id") // 商品id
num := t.MustGetInt("num") // 商品数量
param := OrderParam{}
if t.Request.OriginRequest.Method == "POST" {
t.CheckErr(t.Bind(&param))
} else if t.Request.OriginRequest.Method == "GET" {
param.ActivityId = t.MustGetInt64("activity_id")
param.AreaId = t.MustGetInt64("area_id")
param.Name = t.MustGet("name")
param.Phone = t.MustGet("phone")
param.Address = t.MustGet("address")
goods := t.MustGet("goods")
err := json.Unmarshal([]byte(goods), &param.Goods)
t.CheckErr(err)
}
activity := new(models.Activity)
exist, err := models.GetById(activity, activityId)
exist, err := models.GetById(activity, param.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
area := new(models.AreaStore)
exist, err = models.GetById(area, areaId)
exist, err = models.GetById(area, param.AreaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
@ -85,7 +126,7 @@ func (t *GoodCtl) Order() {
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
option := new(models.CustomerOrderOption)
exist, err = option.GetByActivityId(activityId)
exist, err = option.GetByActivityId(param.ActivityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "订单活动不存在")
//if option.Status == 0 {
@ -98,48 +139,60 @@ func (t *GoodCtl) Order() {
defer session.Close()
session.Begin()
good := new(models.CustomerGoods)
exist, err = session.Where("is_delete=0 and id=?", goodId).Get(good)
if err != nil || !exist {
session.Rollback()
t.ERROR("商品信息异常", code.MSG_DATA_NOT_EXIST)
}
subOrders := make([]*models.CustomerOrderSub, 0)
var price = 0
for _, g := range goods {
good := new(models.CustomerGoods)
exist, err = session.Where("is_delete=0 and id=?", g["id"]).Get(good)
if err != nil || !exist {
session.Rollback()
t.ERROR("商品信息异常", code.MSG_DATA_NOT_EXIST)
}
if good.Stock == 0 {
session.Rollback()
t.ERROR("商品库存不足", code.MSG_DATA_NOT_EXIST)
}
if good.Stock > 0 {
good.Stock--
_, err = session.ID(good.Id).Cols("stock").Update(good)
if err != nil {
if good.Stock-g["num"] < 0 {
session.Rollback()
t.CheckErr(err)
t.ERROR("商品库存不足", code.MSG_DATA_NOT_EXIST)
}
if good.Stock > 0 {
_, err = session.ID(good.Id).Decr("stock", g["num"]).Cols("stock").Update(good)
if err != nil {
session.Rollback()
t.CheckErr(err)
}
}
price += int(good.Price*100) * g["num"]
subOrders = append(subOrders, &models.CustomerOrderSub{
IsDelete: false,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
OutTradeNo: "",
GoodsId: good.Id,
GoodsNum: g["num"],
GoodName: good.Name,
GoodPrice: good.Price,
})
}
res, err := pay_service.UnifiedOrder("欧轩互动-直播商品", user.Openid,
int64(int(good.Price*100)*num+int(option.PostFee*100)), 4, userId, activity.Id)
int64(price+int(option.PostFee*100)), 4, userId, activity.Id)
if err != nil {
session.Rollback()
t.CheckErr(err)
}
order := new(models.CustomerOrder)
order.AreaId = areaId
order.AreaId = param.AreaId
order.AreaName = area.Name
order.RehearsalId = activity.RehearsalId
order.BuyerId = userId
order.GoodsId = goodId
order.GoodsName = good.Name
order.ActivityId = activity.Id
order.TotalAmount = float64(num)*good.Price + option.PostFee
order.TotalAmount = float64(price)/100 + option.PostFee
order.PayAmount = order.TotalAmount
order.OutTradeNo = res["out_trade_no"].(string)
order.GoodsNum = num
order.Address = address
order.Receiver = name
order.Phone = phone
order.Address = param.Address
order.Receiver = param.Name
order.Phone = param.Phone
order.Postage = option.PostFee
order.Status = 0
order.IsDelete = false
@ -150,9 +203,18 @@ func (t *GoodCtl) Order() {
session.Rollback()
t.CheckErr(err)
}
session.Commit()
for _, subOrder := range subOrders {
subOrder.OutTradeNo = order.OutTradeNo
_, err = session.InsertOne(subOrder)
if err != nil {
session.Rollback()
t.CheckErr(err)
}
}
session.Commit()
res["order_id"] = order.Id
t.JSON(res)
}
@ -164,3 +226,39 @@ func (t *GoodCtl) Reorder() {
t.CheckErr(err)
t.JSON(res)
}
// 订单状态[0未支付1已支付即待发货3已发货4确认收货5申请退款6已退款7申请退货8已退货9已取消]
// 申请退款
func (t *GoodCtl) RefundOrder() {
outTradeNo := t.MustGet("out_trade_no")
order := new(models.CustomerOrder)
exist, err := order.GetByOutTradeNO(outTradeNo)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_ORDER_NOT_EXIST, "用户订单不存在")
if order.Status == 1 { // 退款
_, err = order.UpdateStatusBy(outTradeNo, 1, 5)
} else if order.Status == 3 {
_, err = order.UpdateStatusBy(outTradeNo, 3, 7)
} else {
t.ERROR("订单完成状态不能申请退款", code.MSG_CUSTOMER_ORDER_ERROR)
return
}
t.CheckErr(err)
t.SUCCESS("成功申请退款")
}
func (t *GoodCtl) CancelOrder() {
outTradeNo := t.MustGet("out_trade_no")
order := new(models.CustomerOrder)
exist, err := order.GetByOutTradeNO(outTradeNo)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_ORDER_NOT_EXIST, "用户订单不存在")
if order.Status != 0 {
t.ERROR("非待支付状态不能取消", code.MSG_CUSTOMER_ORDER_ERROR)
}
_, err = order.UpdateStatusBy(outTradeNo, 0, 9)
t.CheckErr(err)
t.SUCCESS("成功取消订单")
}

22
controllers/client/invite_envelope.go

@ -12,17 +12,6 @@ type InvitationLetterCtl struct {
controllers.AuthorCtl
}
// InviteEnvelope doc
// @Summary InviteEnvelope
// @Description 填写要求信息
// @Tags invite envelope
// @Accept json
// @Produce json
// @Param activity_id query int true "邀请函内容"
// @Success 0 {string} string "success"
// @Failure 404 {string} string "参数不存在"
// @Failure 405 {string} string "用户不存在"
// @Router /Client/InviteEnvelopeCtl/invite [post]
func (t *InvitationLetterCtl) Invite() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
@ -53,17 +42,6 @@ func (t *InvitationLetterCtl) Invite() {
t.STRING("success")
}
// InviteEnvelope doc
// @Summary InviteEnvelope
// @Description get invite envelope setting
// @Tags invite envelope
// @Accept json
// @Produce json
// @Param activity_id query int true "Activity ID"
// @Success 0 {object} models.Invitation
// @Failure 404 {string} string "参数不存在"
// @Failure 405 {string} string "用户不存在"
// @Router /Client/InviteEnvelopeCtl/setting [get]
func (t *InvitationLetterCtl) Setting() {
activityId := t.MustGetInt64("activity_id")
uid := t.MustGetUID()

14
controllers/client/live.go

@ -26,14 +26,23 @@ type LiveCtl struct {
// 详情
func (t *LiveCtl) Detail() {
activityId := t.MustGetInt64("activity_id")
areaId := t.MustGetInt64("area_id")
areaId, exist := t.GetInt64("area_id")
if !exist { // 假设不存地区,那就设置为主地区
area := new(models.AreaStore)
exist, err := area.GetMainAreaById(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
areaId = area.Id
}
userId := t.MustGetUID()
err := new(models.LiveViewer).Record(userId, activityId)
t.CheckErr(err)
live := new(models.LiveConfig)
exist, err := live.GetByActivityId(activityId)
exist, err = live.GetByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "直播活动不存在")
@ -45,6 +54,7 @@ func (t *LiveCtl) Detail() {
}
live.AdminLiveUrl = ""
live.AreaId = areaId
t.JSON(live)
}

10
controllers/client/wx.go

@ -16,11 +16,11 @@ type WxCtl struct {
const SignUrl = "jsapi_ticket=%s&noncestr=%s&timestamp=%d&url=%s"
type TicketCache struct {
Url string `json:"url" xorm:"not null comment('路径')"`
Token string `json:"-" xorm:"not null comment('token')"`
TokenExpired int64 `json:"ticket_expired" xorm:"not null default(0) comment('token过期时间')"`
Ticket string `json:"ticket" xorm:"not null comment('ticket')"`
TicketExpired int64 `json:"ticket_expired" xorm:"not null default(0) comment('ticket 过期时间')"`
Url string `json:"url"`
Token string `json:"token"`
TokenExpired int64 `json:"ticket_expired"`
Ticket string `json:"ticket"`
TicketExpired int64 `json:"ticket_expired"`
}
var cache TicketCache

7
log/hdzj.log

@ -17,3 +17,10 @@
2020-04-07 14:33:46.303 ERROR logger/logger.go:92 check err {"error": "Error 1292: Incorrect datetime value: '' for column 'created_at' at row 1"}
2020-04-16 14:25:59.479 INFO common/wechat_oauth.go:68 127.0.0.1:5000
2020-04-16 14:25:59.490 ERROR logger/logger.go:92 check err {"error": "xml.NewDecoder.Decode:EOF"}
2020-04-23 16:29:03.000 ERROR logger/logger.go:92 check err {"error": "<xml><return_code>FAIL</return_code><return_msg>invalid total_fee</return_msg></xml>"}
2020-04-23 16:31:14.337 ERROR logger/logger.go:92 check err {"error": "<xml><return_code>FAIL</return_code><return_msg>invalid total_fee</return_msg></xml>"}
2020-04-23 16:31:55.746 ERROR logger/logger.go:92 check err {"error": "<xml><return_code>FAIL</return_code><return_msg>invalid total_fee</return_msg></xml>"}
2020-04-23 16:33:32.268 ERROR logger/logger.go:92 check err {"error": "<xml><return_code>FAIL</return_code><return_msg>invalid total_fee</return_msg></xml>"}
2020-04-23 16:34:10.928 ERROR logger/logger.go:92 check err {"error": "<xml><return_code>FAIL</return_code><return_msg>invalid total_fee</return_msg></xml>"}
2020-04-23 16:37:49.184 ERROR logger/logger.go:92 check err {"error": "<xml><return_code>FAIL</return_code><return_msg>invalid total_fee</return_msg></xml>"}
2020-04-23 19:00:16.688 ERROR logger/logger.go:92 check err {"error": "json: cannot unmarshal string into Go struct field OrderParam.activity_id of type int64"}

6
models/customer_goods.go

@ -24,9 +24,9 @@ type CustomerGoods struct {
Desc string `json:"desc" xorm:"not null default '' comment('商品介绍') VARCHAR(255)"`
//// 无关变量
//GoodType int `json:"good_type" xorm:"-"`
//Postage float64 `json:"postage" xorm:"-"`
Qrcode string `json:"qrcode,omitempty" xorm:"-"`
GoodType int `json:"good_type" xorm:"-"`
Postage float64 `json:"postage" xorm:"-"`
Qrcode string `json:"qrcode,omitempty" xorm:"-"`
}
func (t *CustomerGoods) TableName() string {

28
models/customer_order.go

@ -22,9 +22,9 @@ type CustomerOrder struct {
OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('订单流水号') VARCHAR(255)"`
OrderEntryPersonId int64 `json:"order_enter_person_id" xorm:"not null default 0 comment('订单录入人员id') BIGINT(20)"`
BuyerId int64 `json:"buyer_id" xorm:"not null default 0 comment('user表id') BIGINT(20)"`
GoodsId int64 `json:"goods_id" xorm:"not null default 0 comment('customer_goods表id') BIGINT(20)"`
GoodsName string `json:"goods_name" xorm:"not null default '' comment('商品名字') VARCHAR(255)"`
GoodsNum int `json:"goods_num" xorm:"not null default 0 comment('商品数量') INT(11)"`
GoodsId int64 `json:"goods_id,omitempty" xorm:"not null default 0 comment('customer_goods表id') BIGINT(20)"`
GoodsName string `json:"goods_name,omitempty" xorm:"not null default '' comment('商品名字') VARCHAR(255)"`
GoodsNum int `json:"goods_num,omitempty" xorm:"not null default 0 comment('商品数量') INT(11)"`
TotalAmount float64 `json:"total_amount" xorm:"not null default 0.00 comment('订单总额') DECIMAL(18)"`
PayAmount float64 `json:"pay_amount" xorm:"not null default 0.00 comment('支付金额') DECIMAL(18)"`
Postage float64 `json:"postage" xorm:"not null default 0.00 comment('邮费[0免邮]') DECIMAL(18)"`
@ -35,10 +35,11 @@ type CustomerOrder struct {
Phone string `json:"phone" xorm:"not null default '' comment('收件人电话') VARCHAR(128)"`
// 无关变量
OrderTime string `json:"order_time" xorm:"-"`
Good *CustomerGoods `json:"good" xorm:"-"`
User *User `json:"user" xorm:"-"`
OrderEntryPersonName string `json:"order_entry_person_name" xorm:"-"`
OrderTime string `json:"order_time,omitempty" xorm:"-"`
Good *CustomerGoods `json:"good,omitempty" xorm:"-"`
User *User `json:"user,omitempty" xorm:"-"`
OrderEntryPersonName string `json:"order_entry_person_name,omitempty" xorm:"-"`
SubOrders []*CustomerOrderSub `json:"sub_orders,omitempty" xorm:"-"`
}
func (t *CustomerOrder) TableName() string {
@ -63,9 +64,16 @@ func (t *CustomerOrder) Count(activityId, rehearsalId int64, limitTime time.Time
limitTime, activityId, rehearsalId).Count(t)
}
func GetCustomerOrdersByActivityId(activityId, rehearsalId, areaId int64, status int) ([]*CustomerOrder, error) {
func GetCustomerOrdersByActivityId(userId, activityId, rehearsalId, areaId int64, status int) ([]*CustomerOrder, error) {
orders := make([]*CustomerOrder, 0)
err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=? and status=? and area_id=?",
status, activityId, rehearsalId, areaId).Asc("created_at").Find(&orders)
err := core.GetXormAuto().Where("is_delete=0 and buyer_id=? and activity_id=? and "+
"rehearsal_id=? and area_id=? and status=?", userId, activityId, rehearsalId, areaId, status).
Asc("created_at").Find(&orders)
return orders, err
}
func (t *CustomerOrder) UpdateStatusBy(outTradeNo string, originStatus, status int) (int64, error) {
t.Status = status
return core.GetXormAuto().Where("is_delete=0 and status=? and out_trade_no=?",
originStatus, outTradeNo).Cols("status").Update(t)
}

36
models/customer_order_sub.go

@ -0,0 +1,36 @@
package models
import (
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"time"
)
const CustomerOrderSubTN = TableNamePrefix + "customer_order_sub"
type CustomerOrderSub struct {
Id int64 `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
IsDelete bool `json:"is_delete" xorm:"not null default 0 comment('软删除') TINYINT(1)"`
CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
OutTradeNo string `json:"out_trade_no" xorm:"not null default 0 comment('订单号') VARCHAR(128)"`
GoodsId int64 `json:"goods_id" xorm:"not null default 0 comment('商品id') INT(11)"`
GoodsNum int `json:"goods_num" xorm:"not null default 0 comment('商品数量') INT(11)"`
GoodName string `json:"good_name" xorm:"not null default '' comment('商品名字') VARCHAR(128)"`
GoodPrice float64 `json:"good_price" xorm:"not null default 0.00 comment('商品价格') DECIMAL(18)"`
}
func (t *CustomerOrderSub) TableName() string {
return CustomerOrderSubTN
}
func (t *CustomerOrderSub) Alias(n string) string {
return fmt.Sprintf("%s as %s", t.TableName(), n)
}
func GetCustomerOrderSubByOutTradeNos(outTradeNos []string) (subs []*CustomerOrderSub, err error) {
err = core.GetXormAuto().Where("is_delete=0").In("out_trade_no", outTradeNos).
Asc("created_at").Find(&subs)
return
}

1
models/init_models.go

@ -79,6 +79,7 @@ func init() {
new(LiveConfig),
new(LiveRedEnvelopeRule),
new(UserTransfer),
new(CustomerOrderSub),
)
fmt.Printf("error=======>%v\n\n", err)
}

3
models/live_config.go

@ -39,6 +39,9 @@ type LiveConfig struct {
LikeNum int `json:"like_num" xorm:"not null default 0 comment('点赞数') INT(11)"`
ImGroupId string `json:"im_group_id" xorm:"not null default '' comment('腾讯im聊天群id') VARCHAR(255)"`
ImGroupName string `json:"im_group_name" xorm:"not null default '' comment('聊天群名称') VARCHAR(255)"`
// 无关数据
AreaId int64 `json:"area_id" xorm:"-"`
}
func (t *LiveConfig) TableName() string {

8
models/test/config.json

@ -1,8 +0,0 @@
{
"port": "20181",
"host": "0.0.0.0",
"cross_domain": "*",
"post_max_memory": 1024000,
"api_router": "/PcClient/*",
"update_path": "example_update"
}

11
models/test/private.json

@ -1,11 +0,0 @@
{
"db": {
"host": "gz-cdb-onvbcfqn.sql.tencentcdb.com",
"port": "61232",
"user": "root",
"password": "Pox2210XXa@",
"name": "hudongzhuanjia",
"prefix": "ox_",
"max_open_conn": 500
}
}

32
models/test/sensitive_test.go

@ -1,32 +0,0 @@
package test
import (
"github.com/360EntSecGroup-Skylar/excelize/v2"
"hudongzhuanjia/models"
"testing"
"time"
)
func TestAddSensitive(t *testing.T) {
f, err := excelize.OpenFile("敏感词汇.xlsx")
if err != nil {
t.Fatal(err)
}
rows, err := f.GetRows("big_audit_keyword")
for i, row := range rows {
if i == 0 {
continue
}
if err := models.Save(nil, &models.Sensitive{
Keyword: row[1],
Category: row[2],
Host: row[3],
CreateAt: time.Now(),
UpdateAt: time.Now(),
}, nil); err != nil {
t.Fatal(err)
}
}
}

BIN
models/test/敏感词汇.xlsx

2
models/user_order.go

@ -29,7 +29,7 @@ type UserOrder struct {
TimeExpire string `json:"time_expire" xorm:"not null default('') comment('交易结束时间') VARCHAR(14)"`
TimeEnd string `json:"time_end" xorm:"not null default('') comment('交易结算时间') VARCHAR(14)"`
PrepayId string `json:"prepay_id" xorm:"not null default('') comment('预支付交易会话标识') VARCHAR(64)"`
Status int `json:"status" xorm:"not null default(0) comment('0尚未支付/支付中1支付成功2已撤销3转入退款4退款成功5支付失败6订单关闭') TINYINT(1)"`
Status int `json:"status" xorm:"not null default(0) comment('0尚未支付/支付中1支付成功2已撤销3转入退款4退款成功5支付失败6订单关闭7订单超时') TINYINT(1)"`
ErrMsg string `json:"err_msg" xorm:"not null default '' comment('出现错误') VARCHAR(255)"`
// 退款

18
services/pay/order.go

@ -17,7 +17,7 @@ import (
)
func init() {
//go loopUnifiedOrder()
go loopUnifiedOrder()
}
var orderDelayQueue = make(chan *orderDelayQueueParam, math.MaxInt8)
@ -61,7 +61,11 @@ func loopUnifiedOrder() {
}
for _, order := range orders {
PutOrderDelayQueue(order.Body, order.OutTradeNo, order.OpenId, int(order.TotalFee), order.Status, 0, 0)
expire, err := core2.ParseTime(order.TimeExpire)
if err != nil {
expire = time.Now().Add(12 * time.Hour)
}
PutOrderDelayQueue(order.Body, order.OutTradeNo, order.OpenId, int(order.TotalFee), order.Status, expire.Unix(), 0)
}
defer func() {
@ -79,9 +83,11 @@ func loopUnifiedOrder() {
panic("通道异常关闭")
}
if param.Expires <= time.Now().Unix() {
//if param.Status == 0 {
// Close(param.OutTradeNo) // 超时关闭订单
//}
if param.Status == 0 {
order := new(models.UserOrder)
_, err = order.UpdateStatusByOutTradeNo(param.OutTradeNo, 7)
//Close(param.OutTradeNo) // 超时关闭订单
}
continue // 超时
}
@ -136,7 +142,7 @@ func UnifiedOrder(body, openid string, fee, goodType, userId, activityId int64)
now := time.Now()
timeStart := core2.FormatTime(now)
timeExpire := core2.FormatTime(now.Add(2 * time.Hour))
timeExpire := core2.FormatTime(now.Add(12 * time.Hour))
outTradeNo := utils.RandomStr(32)
nonceStr := utils.RandomStr(32)
resp, err := pay.UnifiedOrder2(client, &pay.UnifiedOrderRequest{

5
utils/code/code.go

@ -32,6 +32,11 @@ const (
MSG_LOTTERY_RULE_NOT_EXIST = 4003 // 抽奖规则不存在
MSG_ORDER_RULE_NOT_EXIST = 4005 // 订单抽奖规则不存在
MSG_ORDER_LADDER_NOT_EXIST = 4006 // 订单抽奖阶梯不存在
MSG_CUSTOMER_ORDER_NOT_EXIST = 4007 // 客户订单不存在
MSG_CUSTOMER_ORDER_NO_PAY = 4008 // 订单未支付
MSG_CUSTOMER_ORDER_SEND = 4009 // 订单已发货
MSG_ORDER_NOT_EXIST = 5000 // 订单活动不存在
MSG_CUSTOMER_ORDER_ERROR = 5001 // 订单已完成
MSG_SIGN_UP_NOT_EXIST = 5000 // 签到规则不存在
MSG_SIGN_HISTORY_EXIST = 5001 // 签到存在
MSG_SIGN_UP_REHEARSAL_LIMIT = 5002 // 签到彩排人数限制

Loading…
Cancel
Save