Browse Source

fix: order cancel but stock not incr

master
黄梓健 5 years ago
parent
commit
bad8b47bbf
  1. 37
      controllers/client/good.go
  2. 6
      log/hdzj.log
  3. 4
      models/customer_order.go
  4. 2
      models/customer_order_sub.go
  5. 4
      utils/define/define.go

37
controllers/client/good.go

@ -7,6 +7,7 @@ import (
"hudongzhuanjia/models"
pay_service "hudongzhuanjia/services/pay"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"strings"
"time"
)
@ -84,7 +85,7 @@ func (t *GoodCtl) ListOrder() {
for _, order := range orders {
outTradeNos = append(outTradeNos, order.OutTradeNo)
}
subs, err := models.GetCustomerOrderSubByOutTradeNos(outTradeNos)
subs, err := models.GetCustomerOrderSubByOutTradeNos(outTradeNos...)
t.CheckErr(err)
for index, order := range orders {
order.ServicePhone = option.MainServicePhone
@ -220,9 +221,9 @@ func (t *GoodCtl) Order() {
//ExpressId: 0,
//ExpressName: "",
//ExpressNo: "",
//CancelTime: time.Time{},
//AutoReceiveTime: time.Now().AddDate(0, 0, 15),
//OrderTime: time.Now(),
CancelTime: define.DefaultTime,
AutoReceiveTime: define.DefaultTime,
//OrderTime: ,
//Good: nil,
//User: nil,
//OrderEntryPersonName: "",
@ -289,8 +290,34 @@ func (t *GoodCtl) CancelOrder() {
if order.Status != 0 {
t.ERROR("非待支付状态不能取消", code.MSG_CUSTOMER_ORDER_ERROR)
}
_, err = order.UpdateStatusBy(outTradeNo, 0, 9)
session := core.GetXormAuto().NewSession()
defer session.Close()
err = session.Begin()
t.CheckErr(err)
order.Status = 9
_, err = session.Where("is_delete=0 and status=? and out_trade_no=?",
0, outTradeNo).Cols("status, cancel_time").Update(order)
if err != nil {
session.Rollback()
t.CheckErr(err)
}
subs := make([]*models.CustomerOrderSub, 0)
err = session.Where("is_delete=0 and out_trade_no=?", outTradeNo).Find(&subs)
if err != nil {
session.Rollback()
t.CheckErr(err)
}
for _, sub := range subs {
_, err = session.Where("id=?", sub.GoodsId).
Incr("stock", sub.GoodsNum).Update(&models.CustomerGoods{})
if err != nil {
session.Rollback()
t.CheckErr(err)
}
}
err = session.Commit()
t.CheckErr(err)
pay_service.Close(outTradeNo)
t.SUCCESS("成功取消订单")
}

6
log/hdzj.log

@ -25,3 +25,9 @@
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"}
2020-04-23 19:33:15.206 ERROR logger/logger.go:92 check err {"error": "Error 1052: Column 'is_delete' in where clause is ambiguous"}
2020-04-24 16:15:19.869 ERROR logger/logger.go:92 check err {"error": "Error 1292: Incorrect datetime value: '' for column 'cancel_time' at row 1"}
2020-04-24 16:15:39.242 ERROR logger/logger.go:92 check err {"error": "Error 1292: Incorrect datetime value: '' for column 'cancel_time' at row 1"}
2020-04-24 16:17:25.348 ERROR logger/logger.go:92 check err {"error": "Error 1292: Incorrect datetime value: '' for column 'cancel_time' at row 1"}
2020-04-24 16:18:18.277 ERROR logger/logger.go:92 check err {"error": "Error 1048: Column 'cancel_time' cannot be null"}
2020-04-24 16:51:38.582 ERROR logger/logger.go:92 查询订单出现错误 {"错误原因": "<xml><return_code>FAIL</return_code><return_msg>当前使用此业务的用户过多,请稍后再试</return_msg></xml>", "交易订单号": "6VxH4qIla22QsgBQDZRuOHZVTbBVtGhx"}
2020-04-24 17:15:07.448 ERROR logger/logger.go:92 check err {"error": "No content found to be updated"}

4
models/customer_order.go

@ -37,8 +37,8 @@ type CustomerOrder struct {
ExpressId int `json:"express_id" xorm:"not null default '0' comment('快递公司名字') INT(11)"`
ExpressName string `json:"express_name" xorm:"not null default '' comment('快递名字') VARCHAR(128)"`
ExpressNo string `json:"express_no" xorm:"not null default '' comment('快递单号') VARCHAR(128)"`
CancelTime time.Time `json:"cancel_time" xorm:"not null default '1970-01-01 08:00:00' comment('取消时间') TIMESTAMP"`
AutoReceiveTime time.Time `json:"auto_receive_time" xorm:"not null default '1970-01-01 08:00:00' comment('自动收货时间') TIMESTAMP"`
CancelTime time.Time `json:"cancel_time" xorm:"comment('取消时间') DATETIME"`
AutoReceiveTime time.Time `json:"auto_receive_time" xorm:"comment('自动收货时间') DATETIME"`
// 无关变量
OrderTime string `json:"order_time,omitempty" xorm:"-"`

2
models/customer_order_sub.go

@ -32,7 +32,7 @@ func (t *CustomerOrderSub) Alias(n string) string {
return fmt.Sprintf("%s as %s", t.TableName(), n)
}
func GetCustomerOrderSubByOutTradeNos(outTradeNos []string) (subs []map[string]string, err error) {
func GetCustomerOrderSubByOutTradeNos(outTradeNos ...string) (subs []map[string]string, err error) {
err = core.GetXormAuto().Table(new(CustomerOrderSub)).Alias("s").
Select("s.out_trade_no, s.goods_id, s.goods_num, s.good_name, s.good_price, g.goods_pic_url").Join("left",
new(CustomerGoods).Alias("g"), "g.id=s.goods_id").

4
utils/define/define.go

@ -1,5 +1,7 @@
package define
import "time"
const TimeFormat = "2006-01-01 15:04:05"
const (
@ -83,3 +85,5 @@ const (
TYPE_CUSTOMER = "customer"
TYPE_ENTRYPEOPLE = "entry_people"
)
var DefaultTime = time.Date(1970, 1, 1, 8, 0, 0, 0, time.UTC)
Loading…
Cancel
Save