feat: upgrade

master
howell 4 years ago
parent a723581442
commit e46b3d0d38

@ -1,211 +0,0 @@
package jst
import (
"bytes"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"log"
"recook/internal/dbc"
order2 "recook/internal/v2/logic/manage/order"
"recook/internal/v2/model/gys/goods"
jst2 "recook/internal/v2/model/jst"
manage "recook/internal/v2/model/recook/order"
"recook/tools"
"strconv"
)
type jst struct {
Code int `json:"code"`
Msg string `json:"msg"`
}
var ok = jst{
0,
"执行成功",
}
var fail = jst{
-1,
"执行失败",
}
type query struct {
TS string `form:"ts"`
PartnerID string `form:"partnerid"`
Method string `form:"method"`
Sign string `form:"sign"`
}
type InventorySync struct {
Modified string `json:"modified" binding:"required"`
Qty uint `json:"qty" binding:"required"`
SkuID string `json:"sku_id" binding:"required"`
}
type logisticsSync struct {
Items []struct {
OuterOiID string `json:"outer_oi_id"`
Qty int64 `json:"qty"`
SkuID string `json:"sku_id"`
SoID string `json:"so_id"`
} `json:"items"`
LID string `json:"l_id"`
LcID string `json:"lc_id"`
LogisticsCompany string `json:"logistics_company"`
OID uint `json:"o_id"`
SendDate string `json:"send_date"`
SoID string `json:"so_id"`
}
func (l *logisticsSync) String() string {
b, err := json.Marshal(*l)
if err != nil {
return fmt.Sprintf("%+v", *l)
}
var out bytes.Buffer
err = json.Indent(&out, b, "", " ")
if err != nil {
return fmt.Sprintf("%+v", *l)
}
return out.String()
}
func validate(q *query, js *jst2.ShopModel) bool {
r := tools.MD5(q.Method+js.PartnerID+"ts"+q.TS+js.PartnerKey) == q.Sign
if !r {
log.Printf("参数校验失败: %+v, %+v\n", q, js)
}
return r
}
//CallBack 聚水潭消息推送callback.
func CallBack(c *gin.Context) {
fmt.Printf("接受的URL:%v\n", c.Request.URL.String())
var q = c.DefaultQuery("method", "null")
//if e := c.ShouldBindQuery(&q); e != nil {
// log.Println(e.Error())
// c.JSON(400, fail)
// return
//}
log.Printf("方法是%+v", q)
switch q {
case "logistics.upload":
var o logisticsSync
if e := c.ShouldBindJSON(&o); e != nil {
log.Println("bind logistics data error")
c.JSON(400, fail)
return
}
log.Printf("logistics jst_back: %+v\n", o.String())
handleLogisticsSyncCallback(&o)
case "inventory.upload":
var o []InventorySync
if e := c.ShouldBindJSON(&o); e != nil {
log.Println("bind inventory data error")
c.JSON(400, fail)
return
}
log.Printf("inventory jst_back: %+v\n", o)
handleInventorySyncCallback(o)
default:
}
c.JSON(200, ok)
}
//物流同步,消息回传
func handleLogisticsSyncCallback(o *logisticsSync) {
ogi, err := strconv.ParseInt(o.SoID, 10, 64)
if err != nil {
return
}
//构建聚水潭,数据库查询店铺资料
j := &jst2.OrderModel{}
jo := j.FindByOrderID(uint(ogi))
jsm := &jst2.ShopModel{}
js := jsm.FindByID(jo.JSTShopID)
if js.ID == 0 {
return
}
og := &manage.RecookOrderGoodsDetailModel{}
data := og.FindByOrderId(jo.OrderID)
if len(data) == 0 {
return
}
//遍历聚水潭订单数据data
for _, v := range data {
for _, k := range o.Items {
if v.SkuCode == k.SkuID { //比较sku_code,相同则进行发货
je := jst2.ExpressModel{}
je = je.FindByLcID(o.LcID)
e := []order2.ExpressInfo{
{
o.LogisticsCompany,
o.LID,
},
}
if je.Id > 0 {
e = []order2.ExpressInfo{
{
je.Name,
o.LID,
},
}
}
//查询该子订单是否有过发货记录,有记录则把快递数据叠加
var ex []manage.RecookOrderGoodsExpressModel
dbc.DB.Table((&manage.RecookOrderGoodsExpressModel{}).TableName()).Find(&ex, "order_goods_id=?", v.Id)
if len(ex) > 0 {
for _, model := range ex {
e = append(e, order2.ExpressInfo{
ExpressCompName: model.ExpressCompName,
ExpressNo: model.ExpressNo,
})
}
}
fmt.Println(e)
_ = order2.Expresslogic.Express(v.VendorId, "jst", v, e)
}
}
}
//原代码
//je := jst2.ExpressModel{}
//je = je.FindByLcID(o.LcID)
//e := []order2.ExpressInfo{
// {
// o.LogisticsCompany,
// o.LID,
// },
//}
//if je.Id > 0 {
// e = []order2.ExpressInfo{
// {
// je.Name,
// o.LID,
// },
// }
//}
//for _, v := range data {
// _ = order2.Expresslogic.Express(v.VendorId, "jst", v, e)
//}
}
func handleInventorySyncCallback(o []InventorySync) {
for _, v := range o {
gg := &goods.GysGoodsSkuModel{}
gg.SetInventoryByCode(v.SkuID, v.Qty)
}
}

@ -56,7 +56,7 @@ func (o logic) Create(args ApplyCreate) error {
return errors.New("无法发起云体店申请")
}
if args.Kind == 2 && u1.Level < 3 {
if args.Kind == 2 && (u1.Level != 10 || u1.IsOffline) {
return errors.New("无法发起实体店申请")
}
@ -65,8 +65,8 @@ func (o logic) Create(args ApplyCreate) error {
}
parentID := u1.Id
if u1.Level == 1 {
parentID = u1.ParentID
if u1.Level != 10 {
parentID = u1.RootID
}
if err := mysql.Db.Create(&upgrade.ApplyEntry{

@ -57,10 +57,8 @@ func (o logic) Sure(args ApplySure) error {
if len(mobile) != 11 || !strings.HasPrefix(mobile, "1") {
return fmt.Errorf("手机格式不正确")
}
if mu.Id == 0 {
// 没有就创建
if err := mysql.Db.Transaction(func(tx *gorm.DB) error {
sql := `select max(id)+floor(1+rand()*5) from recook_user_info`
@ -76,8 +74,9 @@ func (o logic) Sure(args ApplySure) error {
HeadImgUrl: "",
Phone: mobile,
Identifier: time.Now().Format("060102") + baseCode.Encode(uint64(lastId)),
Level: 1,
ParentID: ae.ParentID,
Level: 2,
ParentID: 0,
RootID: ae.ParentID,
}
if err := tx.Create(&info).Error; err != nil {
@ -124,8 +123,9 @@ func (o logic) Sure(args ApplySure) error {
return err
}
if err := tx.Model(&mu).Updates(user.RecookUserInfoModel{
Level: 1,
ParentID: ae.ParentID,
Level: 2,
ParentID: 0,
RootID: ae.ParentID,
UpgradeTime1: formatime.NewSecondNow()}).Error; err != nil {
return err
}

@ -38,6 +38,7 @@ type RecookUserInfoModel struct {
InvitationNo string
Identifier string
RootID uint
IsOffline bool `json:"is_offline"`
}
// TableName sets the insert table name for this struct type

Loading…
Cancel
Save