饿鲜达商品库合并修改,每日订单打款增加日志,一些bug

This commit is contained in:
苏尹岚
2020-02-13 16:25:54 +08:00
parent e46e86396c
commit e46245f7e2
7 changed files with 82 additions and 30 deletions

View File

@@ -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 != "" {

View File

@@ -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
}