Commit 63a13041 by 孙龙

up

parent 38c53a01
...@@ -42,6 +42,7 @@ type OrderTrack struct { ...@@ -42,6 +42,7 @@ type OrderTrack struct {
ERPORDERID string `json:"ERPORDERID"`//订单关联的erpid ERPORDERID string `json:"ERPORDERID"`//订单关联的erpid
ORDERID int64 `json:"ORDERID"`//订单id ORDERID int64 `json:"ORDERID"`//订单id
STATUS int64 `json:"STATUS"`//状态 STATUS int64 `json:"STATUS"`//状态
FQTY int64 `json:"FQTY"`//出库数量
} }
...@@ -50,6 +51,8 @@ type OrderTrackList []*OrderTrack ...@@ -50,6 +51,8 @@ type OrderTrackList []*OrderTrack
type OrderItems struct { type OrderItems struct {
OrderId int64 `json:"order_id" db:"order_id"` OrderId int64 `json:"order_id" db:"order_id"`
RecId int64 `json:"rec_id" db:"rec_id"` RecId int64 `json:"rec_id" db:"rec_id"`
GoodsNumber int64 `json:"goods_number" db:"goods_number"`
FQTY int64 `json:"fqty" db:"fqty"`
} }
func InsertData(trackList OrderTrackList) error{ func InsertData(trackList OrderTrackList) error{
...@@ -59,9 +62,12 @@ func InsertData(trackList OrderTrackList) error{ ...@@ -59,9 +62,12 @@ func InsertData(trackList OrderTrackList) error{
status_cn string status_cn string
ok bool ok bool
) )
//开启事务
tx, _ := db.DB.Beginx()
for _,data := range trackList{ for _,data := range trackList{
orderItems := &OrderItems{} orderItems := &OrderItems{}
err = db.DB.Get(orderItems,"SELECT order_id,rec_id FROM lie_order_items WHERE erp_rec_id = ?",data.ORDERENTRYID) err = db.DB.Get(orderItems,"SELECT order_id,rec_id,goods_number,fqty FROM lie_order_items WHERE erp_rec_id = ?",data.ORDERENTRYID)
if err != nil{ if err != nil{
logger.Error("%s",fmt.Sprintf("没有找到该明细的信息 %d",data.ORDERENTRYID)) logger.Error("%s",fmt.Sprintf("没有找到该明细的信息 %d",data.ORDERENTRYID))
return errors.New(fmt.Sprintf("没有找到该明细的信息 %d",data.ORDERENTRYID)) return errors.New(fmt.Sprintf("没有找到该明细的信息 %d",data.ORDERENTRYID))
...@@ -70,12 +76,33 @@ func InsertData(trackList OrderTrackList) error{ ...@@ -70,12 +76,33 @@ func InsertData(trackList OrderTrackList) error{
if status_cn,ok = ORDER_TRACK_STATUS_CN[data.STATUS];!ok { if status_cn,ok = ORDER_TRACK_STATUS_CN[data.STATUS];!ok {
status_cn = "" status_cn = ""
} }
sql := " INSERT INTO lie_order_items_tracking (rec_id,order_id,status,msg,status_cn,create_name,create_time) VALUES(?,?,?,?,?,?,?)"
_,err :=db.DB.Exec(sql, orderItems.RecId,orderItems.OrderId,data.STATUS,data.MSG,status_cn,data.CREATOR,create_time) sql := " INSERT INTO lie_order_items_tracking (rec_id,order_id,status,fqty,msg,status_cn,create_name,create_time) VALUES(?,?,?,?,?,?,?,?)"
_,err :=tx.Exec(sql, orderItems.RecId,orderItems.OrderId,data.STATUS,data.FQTY,data.MSG,status_cn,data.CREATOR,create_time)
if err != nil{ if err != nil{
logger.Error("%s",err) logger.Error(" 新增lie_order_items_tracking表失败 :%s, %s",sql,err)
tx.Rollback()
return err
}
if data.FQTY > 0 && data.STATUS == 110{
sql1 := " UPDATE lie_order_items set fqty = ? where rec_id = ? "
newFqty := int64(data.FQTY)+int64(orderItems.FQTY)
if newFqty > orderItems.GoodsNumber{
newFqty = orderItems.GoodsNumber
}
_,err :=tx.Exec(sql1,newFqty,orderItems.RecId)
if err != nil{
logger.Error("修改lie_order_items表失败 %s, %s",sql1,err)
tx.Rollback()
return err return err
} }
} }
}
err = tx.Commit()
if err != nil{
logger.Error("%s",err)
return err
}
return nil return nil
} }
\ No newline at end of file
...@@ -20,5 +20,6 @@ require ( ...@@ -20,5 +20,6 @@ require (
github.com/stretchr/testify v1.4.0 // indirect github.com/stretchr/testify v1.4.0 // indirect
github.com/syyongx/php2go v0.9.4 github.com/syyongx/php2go v0.9.4
github.com/tidwall/gjson v1.6.0 github.com/tidwall/gjson v1.6.0
golang.org/x/text v0.3.2 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
) )
...@@ -33,6 +33,7 @@ func InsertOrderItemsTracking(msg string) (err error){ ...@@ -33,6 +33,7 @@ func InsertOrderItemsTracking(msg string) (err error){
orderTrackHandle.ERPORDERID = msgList[i].Get("ERPORDERID").String() orderTrackHandle.ERPORDERID = msgList[i].Get("ERPORDERID").String()
orderTrackHandle.ORDERID = msgList[i].Get("ORDERID").Int() orderTrackHandle.ORDERID = msgList[i].Get("ORDERID").Int()
orderTrackHandle.STATUS = msgList[i].Get("STATUS").Int() orderTrackHandle.STATUS = msgList[i].Get("STATUS").Int()
orderTrackHandle.FQTY = msgList[i].Get("FQTY").Int()
orderTrackList = append(orderTrackList,orderTrackHandle) orderTrackList = append(orderTrackList,orderTrackHandle)
} }
err = orderTrack.InsertData(orderTrackList) err = orderTrack.InsertData(orderTrackList)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment