饿鲜达商品库合并修改,每日订单打款增加日志,一些bug
This commit is contained in:
@@ -1459,10 +1459,10 @@ func SumExianDaDepot(ctx *jxcontext.Context) (err error) {
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
prefix, name, _, specUnit, unit, specQuality := jxutils.SplitSkuName(v.GoodsName)
|
||||
prefix, _, _, specUnit, unit, specQuality := jxutils.SplitSkuName(v.GoodsName)
|
||||
skuName := &model.SkuName{
|
||||
Prefix: prefix,
|
||||
Name: name,
|
||||
Name: v.GoodsName,
|
||||
CategoryID: skus.CategoryIDThird,
|
||||
IsGlobal: 1,
|
||||
Unit: unit,
|
||||
@@ -1474,7 +1474,7 @@ func SumExianDaDepot(ctx *jxcontext.Context) (err error) {
|
||||
Status: model.SkuStatusNormal,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(skuName, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, &skuName)
|
||||
err = dao.CreateEntity(db, skuName)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
@@ -1486,18 +1486,15 @@ func SumExianDaDepot(ctx *jxcontext.Context) (err error) {
|
||||
Weight: int(utils.Str2Int64(skus.Weight)),
|
||||
Status: model.SkuStatusNormal,
|
||||
ExdSkuID: v.ElemeGoodsID,
|
||||
ExdSkuName: v.GoodsName,
|
||||
ExdUpc: int(utils.Str2Int64(v.UpcID)),
|
||||
ExdCategoryThirdID: skus.CategoryIDThird,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(sku, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, &sku)
|
||||
err = dao.CreateEntity(db, sku)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
dao.Commit(db)
|
||||
break
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1204,7 +1204,9 @@ func getSkuSaleStatus(inSkuBind *StoreSkuBindSkuInfo, skuNameBindInfo *StoreSkuB
|
||||
}
|
||||
|
||||
func AddEventDetail(db *dao.DaoDB, ctx *jxcontext.Context, operateType, thingID, thingType, storeID int, beforeData, afterData string) (err error) {
|
||||
if ctx.GetUserName() == "jxadmin" {
|
||||
url := ctx.GetRequest().URL.Path
|
||||
apiFunction := url[strings.LastIndex(url, "/")+1 : len(url)]
|
||||
if ctx.GetUserName() == "jxadmin" && !strings.Contains(apiFunction, "AutoPayForPopluarMan") {
|
||||
return err
|
||||
}
|
||||
operateEventDetail := &model.OperateEventDetail{
|
||||
|
||||
@@ -64,9 +64,7 @@ type StoreSkuSyncInfo struct {
|
||||
|
||||
model.Sku
|
||||
ExdSkuID string `orm:"column(exd_sku_id)"`
|
||||
ExdSkuName string
|
||||
ExdUpc int
|
||||
ExdCategoryThirdID int `orm:"column(exd_category_third_id)"`
|
||||
ExdCategoryThirdID int `orm:"column(exd_category_third_id)"`
|
||||
StoreName string
|
||||
|
||||
// sku_name
|
||||
|
||||
@@ -150,6 +150,9 @@ type SkuCategory struct {
|
||||
// WscCategoryID int64 `orm:"column(wsc_category_id)" json:"wscCategoryID"` // 这个是指对应的美团外卖商品类别
|
||||
Status int8 `orm:"default(1)" json:"status"` //分类状态,0表示禁用,1表示启用
|
||||
Img string `orm:"size(512)" json:"img"` //分类图片
|
||||
|
||||
ExdName string `json:"exdName"` //饿鲜达对应分类名
|
||||
ExdSeq int `json:"exdSeq"`
|
||||
// JdID int64 `orm:"column(jd_id);index" json:"jdID"` // 这个是指商家自己的商品类别在京东平台上的ID
|
||||
// JdSyncStatus int8 `orm:"default(2)" json:"jdSyncStatus"`
|
||||
}
|
||||
@@ -225,8 +228,6 @@ type Sku struct {
|
||||
Seq int `json:"seq"`
|
||||
|
||||
ExdSkuID string `orm:"column(exd_sku_id)" json:"exdSkuID"`
|
||||
ExdSkuName string `json:"exdSkuName"`
|
||||
ExdUpc int `json:"exdUpc"`
|
||||
ExdCategoryThirdID int `orm:"column(exd_category_third_id)" json:"exdCategoryThirdID"`
|
||||
// JdID int64 `orm:"column(jd_id);null;index" json:"jdID"`
|
||||
// JdSyncStatus int8 `orm:"default(2)" json:"jdSyncStatus"`
|
||||
|
||||
@@ -5,6 +5,7 @@ const (
|
||||
ThingTypeSkuName = 2
|
||||
ThingTypeSku = 3
|
||||
ThingTypeStore = 4
|
||||
ThingTypeUser = 5
|
||||
)
|
||||
|
||||
type ThingMap struct {
|
||||
|
||||
@@ -317,8 +317,8 @@ func genSkuParamsFromStoreSkuInfo2(storeSku *dao.StoreSkuSyncInfo, isCreate, isE
|
||||
params["name"] = utils.LimitMixedStringLen(storeSku.SkuName, ebaiapi.MaxSkuNameByteCount)
|
||||
params["cat3_id"] = getEbaiCat(storeSku.VendorVendorCatID)
|
||||
} else {
|
||||
params["upc"] = storeSku.ExdUpc
|
||||
params["name"] = storeSku.ExdSkuName
|
||||
params["upc"] = storeSku.Upc
|
||||
params["name"] = storeSku.Name
|
||||
params["cat3_id"] = storeSku.ExdCategoryThirdID
|
||||
}
|
||||
if storeSku.DescImg != "" {
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/event"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/wxpayapi"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
@@ -562,6 +564,21 @@ func CancelOrder(ctx *jxcontext.Context, order *model.GoodsOrder, reason string)
|
||||
if err2 == nil {
|
||||
dao.WrapAddIDCULDEntity(orderPayRefund, ctx.GetUserName())
|
||||
errList.AddErr(dao.CreateEntity(dao.GetDB(), orderPayRefund))
|
||||
//退款后,若此订单下单用户有推广人,则需要将分给推广人的金额记录到该推广人的欠款中
|
||||
orders, _ := dao.QueryOrders(db, order.VendorOrderID, 0, []int{model.VendorIDJX}, 0, utils.DefaultTimeValue, utils.DefaultTimeValue)
|
||||
if len(orders) > 0 {
|
||||
user, _ := dao.GetUserByID(db, "user_id", orders[0].UserID)
|
||||
if user.ParentMobile != "" {
|
||||
user2, _ := dao.GetUserByID(db, "moblie", user.ParentMobile)
|
||||
user2.Arrears = user2.Arrears + (orderPay.TotalFee * user2.DividePercentage / 100)
|
||||
dao.UpdateEntity(db, user2, "Arrears")
|
||||
if user2.ParentMobile != "" {
|
||||
user3, _ := dao.GetUserByID(db, "moblie", user2.ParentMobile)
|
||||
user3.Arrears = user3.Arrears + ((orderPay.TotalFee - user2.Arrears) * user3.DividePercentage / 100)
|
||||
dao.UpdateEntity(db, user3, "Arrears")
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errList.AddErr(err2)
|
||||
}
|
||||
@@ -656,17 +673,17 @@ func PayForPopluarMan(ctx *jxcontext.Context, vendorOrderID, userID string, pric
|
||||
//自动打款给市场推广人
|
||||
func AutoPayForPopluarMan(ctx *jxcontext.Context) (err error) {
|
||||
var (
|
||||
errMsg string
|
||||
errMsg string
|
||||
errCode string
|
||||
db = dao.GetDB()
|
||||
fromDateStr = time.Now().AddDate(0, 0, -2).Format("2006-1-2") + " 00:00:00"
|
||||
toDateStr = time.Now().AddDate(0, 0, -2).Format("2006-1-2") + " 23:59:59"
|
||||
fromDateStr = time.Now().AddDate(0, 0, -3).Format("2006-1-2") + " 00:00:00"
|
||||
toDateStr = time.Now().AddDate(0, 0, -3).Format("2006-1-2") + " 23:59:59"
|
||||
)
|
||||
result, err := dao.GetOrdersForJxPay(db, utils.Str2Time(fromDateStr), utils.Str2Time(toDateStr))
|
||||
for _, goods := range result {
|
||||
var (
|
||||
param = &wxpayapi.TransfersParam{
|
||||
param = &wxpayapi.TransfersParam{
|
||||
CheckName: wxpayapi.CheckName,
|
||||
PartnerTradeNo: goods.VendorOrderID,
|
||||
Desc: "每日推广人订单分成分到个人",
|
||||
SpbillCreateIP: ctx.GetRealRemoteIP(),
|
||||
}
|
||||
@@ -686,12 +703,18 @@ func AutoPayForPopluarMan(ctx *jxcontext.Context) (err error) {
|
||||
errMsg += fmt.Sprintf("打款失败!未找到此用户的微信验证方式!订单号:[%v],用户ID:[%v]\n", goods.VendorOrderID, user2.UserID)
|
||||
} else {
|
||||
payPrice1 = int(goods.ActualPayPrice) * user2.DividePercentage / 100
|
||||
param.OpenID = auth[0].AuthID
|
||||
param.Amount = payPrice1
|
||||
_, err := api.WxpayAPI.Transfers(param)
|
||||
if err != nil {
|
||||
return err
|
||||
//表示这个人之前有欠款,意思是取消订单退款时,这个推广人的分成收不回来,算作欠款,打钱的时候要扣除
|
||||
//表示这个人之前有小于3毛钱的款没有打(微信付款api付款最低3毛),记录下来加到以后的款项中
|
||||
rPrice := payPrice1 - user2.Arrears + user2.Profit
|
||||
err = updateUserAndTransfers(db, param, user2, auth[0].AuthID, rPrice)
|
||||
mapAfter := map[string]interface{}{
|
||||
"user_id": user2.UserID,
|
||||
"price": rPrice,
|
||||
"open_id": auth[0].AuthID,
|
||||
"name": user2.Name,
|
||||
"mobile": user2.Mobile,
|
||||
}
|
||||
err = cms.AddEventDetail(db, ctx, model.OperateAdd, user2.ID, model.ThingTypeUser, goods.StoreID, "", cms.BuildDiffData(mapAfter))
|
||||
}
|
||||
if user2.ParentMobile != "" {
|
||||
user3, err := dao.GetUserByID(db, "mobile", user2.ParentMobile)
|
||||
@@ -703,12 +726,16 @@ func AutoPayForPopluarMan(ctx *jxcontext.Context) (err error) {
|
||||
errMsg += fmt.Sprintf("打款失败!未找到此用户的微信验证方式!订单号:[%v],用户ID:[%v]\n", goods.VendorOrderID, user3.UserID)
|
||||
} else {
|
||||
payPrice2 = (int(goods.ActualPayPrice) - payPrice1) * user3.DividePercentage / 100
|
||||
param.OpenID = auth[0].AuthID
|
||||
param.Amount = payPrice2
|
||||
_, err := api.WxpayAPI.Transfers(param)
|
||||
if err != nil {
|
||||
return err
|
||||
rPrice := payPrice2 - user3.Arrears + user3.Profit
|
||||
err = updateUserAndTransfers(db, param, user3, auth[0].AuthID, rPrice)
|
||||
mapAfter := map[string]interface{}{
|
||||
"user_id": user3.UserID,
|
||||
"price": rPrice,
|
||||
"open_id": auth[0].AuthID,
|
||||
"name": user3.Name,
|
||||
"mobile": user3.Mobile,
|
||||
}
|
||||
err = cms.AddEventDetail(db, ctx, model.OperateAdd, user3.ID, model.ThingTypeUser, goods.StoreID, "", cms.BuildDiffData(mapAfter))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -716,5 +743,31 @@ func AutoPayForPopluarMan(ctx *jxcontext.Context) (err error) {
|
||||
if user != nil && errMsg != "" {
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "每日打款错误", errMsg)
|
||||
}
|
||||
if err != nil || errMsg != "" {
|
||||
errCode = model.ErrCodeGeneralFailed
|
||||
} else {
|
||||
errCode = model.ErrCodeSuccess
|
||||
}
|
||||
err = event.AddOperateEvent(ctx, ctx.GetTrackInfo(), `{"fromDateStr":`+fromDateStr+`,"toDateStr":`+toDateStr+`}`, errCode, err.Error(), 0)
|
||||
return err
|
||||
}
|
||||
|
||||
func updateUserAndTransfers(db *dao.DaoDB, param *wxpayapi.TransfersParam, user *model.User, authID string, rPrice int) (err error) {
|
||||
if rPrice >= 30 {
|
||||
param.OpenID = authID
|
||||
param.Amount = rPrice
|
||||
param.PartnerTradeNo = utils.GetUUID()
|
||||
_, err = api.WxpayAPI.Transfers(param)
|
||||
user.ProfitSum = user.ProfitSum + rPrice
|
||||
user.Profit = 0
|
||||
user.Arrears = 0
|
||||
} else if rPrice >= 0 && rPrice < 30 {
|
||||
user.Profit = rPrice
|
||||
user.Arrears = 0
|
||||
} else {
|
||||
user.Profit = 0
|
||||
user.Arrears = int(utils.Float64TwoInt64(math.Abs(utils.Int2Float64(rPrice))))
|
||||
}
|
||||
_, err = dao.UpdateEntity(db, user, "ProfitSum", "Profit", "Arrears")
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user