Accept Merge Request #183: (su -> mark)
Merge Request: 根据京东建议售价修改京西价 Created By: @苏尹岚 Accepted By: @苏尹岚 URL: https://rosydev.coding.net/p/jx-callback/d/jx-callback/git/merge/183
This commit is contained in:
@@ -178,6 +178,12 @@ type tStoreSkusSecKill struct {
|
||||
NoticeMsg string
|
||||
}
|
||||
|
||||
type JdStoreSkus struct {
|
||||
JdStoreID int `json:"jdStoreID"`
|
||||
JdSkuID int `json:"jdSkuID"`
|
||||
Price int `json:"price"`
|
||||
}
|
||||
|
||||
const (
|
||||
maxStoreNameBind = 10000 // 最大门店SkuName bind个数
|
||||
maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数
|
||||
@@ -3536,3 +3542,94 @@ func SendSeckillSkusCountMsg(ctx *jxcontext.Context, vendorIDs []int, isAsync, i
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func RefreshJxPriceByVendor(ctx *jxcontext.Context, jdStoreSkus []*JdStoreSkus, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
jdMap = make(map[int][]*JdStoreSkus)
|
||||
jxMap = make(map[int]map[int]int)
|
||||
param []*StoreSkuBindInfo
|
||||
)
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
for _, v := range jdStoreSkus {
|
||||
var (
|
||||
pricePercentagePack []*model.PricePercentageItem
|
||||
cats []*model.ThingMap
|
||||
skus []*model.SkuAndName
|
||||
)
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM thing_map t1
|
||||
WHERE t1.deleted_at = ? AND t1.thing_type = ?
|
||||
AND t1.vendor_thing_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
model.ThingTypeSku,
|
||||
v.JdSkuID,
|
||||
}
|
||||
err = dao.GetRows(db, &cats, sql, sqlParams...)
|
||||
if len(cats) > 0 {
|
||||
skus, err = dao.GetSkus(db, []int{int(cats[0].ThingID)}, nil, nil, nil)
|
||||
if err != nil || len(skus) == 0 {
|
||||
return result, fmt.Errorf("没有找到该京西skuID!,京西skuID :[%v]", cats[0].ThingID)
|
||||
}
|
||||
} else {
|
||||
return result, fmt.Errorf("没有找到该京东skuID对应的京西skuID!,京东skuID :[%v]", v.JdSkuID)
|
||||
}
|
||||
store, err := dao.GetStoreDetailByVendorStoreID(db, utils.Int2Str(v.JdStoreID), model.VendorIDJD)
|
||||
if err != nil || store == nil {
|
||||
return result, fmt.Errorf("没有找到该京东门店对应的京西门店!,京东门店ID :[%v]", v.JdStoreID)
|
||||
}
|
||||
err = jxutils.Strings2Objs(store.PricePercentagePackStr, &pricePercentagePack)
|
||||
jxPrice := jxutils.CaculateJxPriceByPricePack(pricePercentagePack, 0, v.Price)
|
||||
jdMap[store.ID] = append(jdMap[store.ID], &JdStoreSkus{
|
||||
JdSkuID: skus[0].NameID,
|
||||
Price: jxPrice,
|
||||
})
|
||||
}
|
||||
for k, v := range jdMap {
|
||||
var skuNameMap = make(map[int]int)
|
||||
for _, vv := range v {
|
||||
if skuNameMap[vv.JdSkuID] != 0 {
|
||||
if skuNameMap[vv.JdSkuID] > vv.Price {
|
||||
skuNameMap[vv.JdSkuID] = vv.Price
|
||||
}
|
||||
} else {
|
||||
skuNameMap[vv.JdSkuID] = vv.Price
|
||||
}
|
||||
}
|
||||
jxMap[k] = skuNameMap
|
||||
}
|
||||
for k, v := range jxMap {
|
||||
for kk, vv := range v {
|
||||
result, err := dao.GetStoreSkuBindByNameID(db, k, kk, model.SkuStatusNormal)
|
||||
if len(result) > 0 && err == nil {
|
||||
if result[0].UnitPrice > vv {
|
||||
storeSkuBindInfo := &StoreSkuBindInfo{
|
||||
StoreID: k,
|
||||
NameID: kk,
|
||||
UnitPrice: vv,
|
||||
}
|
||||
param = append(param, storeSkuBindInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
_, err = UpdateStoresSkusByBind(ctx, nil, param, isAsync, isContinueWhenError)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
taskSeq := tasksch.NewSeqTask2("根据京东平台价刷新京西平台价", ctx, isContinueWhenError, taskSeqFunc, 2)
|
||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = taskSeq.GetResult(0)
|
||||
hint = "1"
|
||||
} else {
|
||||
hint = taskSeq.GetID()
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/wxpayapi"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals/api/apimanager"
|
||||
@@ -967,3 +969,85 @@ func WriteToExcelJd(task *tasksch.SeqTask, jd []JdUserStruct) (err error) {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateUserWxNoAndPercent(user *model.User, isReceiver bool) (num int64, err error) {
|
||||
db := dao.GetDB()
|
||||
user2, err := dao.GetUserByID(db, "user_id", user.UserID)
|
||||
auth, err := dao.GetUserBindAuthInfo(db, user.UserID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "")
|
||||
if len(auth) == 0 {
|
||||
return 0, fmt.Errorf("未找到此用户的微信验证方式!用户ID:[%v]\n", user.UserID)
|
||||
}
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
user2.DividePercentage = user.DividePercentage
|
||||
num2, err := dao.UpdateEntity(db, user2, "DividePercentage")
|
||||
num += num2
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
if isReceiver {
|
||||
param := &wxpayapi.ProfitSharingReceiverParam{
|
||||
Receiver: wxpayapi.CData(`{
|
||||
"type":"` + wxpayapi.AccountTypeOpen + `",
|
||||
"account":"` + auth[0].AuthID + `",
|
||||
"relation_type":" ` + wxpayapi.Relation + `"
|
||||
}`),
|
||||
}
|
||||
_, err := api.WxpayAPI.AddProfitSharingReceiver(param)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
user2.IsReceiver = 1
|
||||
num3, err := dao.UpdateEntity(db, user2, "IsReceiver")
|
||||
num += num3
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
return num, err
|
||||
}
|
||||
|
||||
func DeleteProfitSharingReceiver(ctx *jxcontext.Context, userID string) (err error) {
|
||||
db := dao.GetDB()
|
||||
auth, err := dao.GetUserBindAuthInfo(db, userID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "")
|
||||
if len(auth) == 0 {
|
||||
return fmt.Errorf("未找到此用户的微信验证方式!用户ID:[%v]\n", userID)
|
||||
}
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
param := &wxpayapi.ProfitSharingReceiverParam{
|
||||
Receiver: wxpayapi.CData(`{
|
||||
"type":"` + wxpayapi.AccountTypeOpen + `",
|
||||
"account":"` + auth[0].AuthID + `"
|
||||
}`),
|
||||
}
|
||||
_, err = api.WxpayAPI.DeleteProfitSharingReceiver(param)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
user2, err := dao.GetUserByID(db, "user_id", userID)
|
||||
user2.IsReceiver = 0
|
||||
_, err = dao.UpdateEntity(db, user2, "IsReceiver")
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -82,6 +82,8 @@ func AddOperateEventDetail(db *dao.DaoDB, operateEventDetail *model.OperateEvent
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
operateEventDetail.BeforeData = utils.LimitUTF8StringLen(operateEventDetail.BeforeData, 3200)
|
||||
operateEventDetail.AfterData = utils.LimitUTF8StringLen(operateEventDetail.AfterData, 3200)
|
||||
err = dao.CreateEntity(db, operateEventDetail)
|
||||
dao.Commit(db)
|
||||
return err
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||
"git.rosy.net.cn/jx-callback/globals/api/apimanager"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
@@ -260,10 +262,33 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
case 3:
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
priceReferSnapshotList, err = dao.GetPriceReferSnapshotNoPage(db, []int{0}, nil, nil, snapshotAt)
|
||||
for _, v := range priceReferSnapshotList {
|
||||
for _, appOrg := range apimanager.CurAPIManager.GetAppOrgCodeList(model.VendorIDJD) {
|
||||
directPrice, err := jd.GetAPI(appOrg).GetJdSkuDirectPrice(v.SkuID)
|
||||
if err != nil || directPrice == 0 {
|
||||
continue
|
||||
} else {
|
||||
v.JdDirectPrice = int(directPrice)
|
||||
dao.UpdateEntity(db, v, "JdDirectPrice")
|
||||
}
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
taskSeq := tasksch.NewSeqTask2("生成每日价格统计", ctx, isContinueWhenError, taskSeqFunc, 3)
|
||||
taskSeq := tasksch.NewSeqTask2("生成每日价格统计", ctx, isContinueWhenError, taskSeqFunc, 4)
|
||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = taskSeq.GetResult(0)
|
||||
|
||||
@@ -63,6 +63,11 @@ type tGoodsAndOrder struct {
|
||||
PromotionType int `json:"promotionType"` // todo 当前是用于记录京东的PromotionType(生成jxorder用),没有做转换
|
||||
}
|
||||
|
||||
type GoodsOrderPay struct {
|
||||
model.GoodsOrder
|
||||
TransactionID string `orm:"column(transaction_id)" json:"transactionID"`
|
||||
}
|
||||
|
||||
//actID指结算活动的id
|
||||
func QueryOrders(db *DaoDB, vendorOrderID string, actID int, vendorIDs []int, storeID int, fromDate, toDate time.Time) (orderList []*model.GoodsOrder, err error) {
|
||||
sqlParams := []interface{}{}
|
||||
@@ -1188,3 +1193,25 @@ func GetJxOrderCount(db *DaoDB, storeID int, orderID string, date time.Time) (co
|
||||
err = GetRow(db, &count, sql, sqlParams...)
|
||||
return count, err
|
||||
}
|
||||
|
||||
func GetOrdersForJxPay(db *DaoDB, finishTimeBegin, finishTimeEnd time.Time) (goods []*GoodsOrderPay, err error) {
|
||||
sql := `
|
||||
SELECT a.*,b.transaction_id
|
||||
FROM goods_order a
|
||||
JOIN order_pay b ON a.vendor_order_id = b.vendor_order_id AND a.vendor_id = b.vendor_id
|
||||
JOIN user c ON c.user_id = a.user_id
|
||||
WHERE a.vendor_id = ?
|
||||
AND a.order_finished_at >= ?
|
||||
AND a.order_finished_at <= ?
|
||||
AND a.status = ?
|
||||
AND c.parent_mobile <> ''
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
model.VendorIDJX,
|
||||
finishTimeBegin,
|
||||
finishTimeEnd,
|
||||
model.OrderStatusFinished,
|
||||
}
|
||||
err = GetRows(db, &goods, sql, sqlParams...)
|
||||
return goods, err
|
||||
}
|
||||
|
||||
@@ -477,6 +477,7 @@ type PriceReferSnapshot struct {
|
||||
MaxVendorPrice int `json:"maxVendorPrice"`
|
||||
MinVendorPrice int `json:"minVendorPrice"`
|
||||
AvgVendorPrice int `json:"avgVendorPrice"`
|
||||
JdDirectPrice int `json:"jdDirectPrice"`
|
||||
}
|
||||
|
||||
func (*PriceReferSnapshot) TableUnique() [][]string {
|
||||
|
||||
@@ -49,6 +49,10 @@ type User struct {
|
||||
LastLoginAt *time.Time `orm:"null" json:"lastLoginAt"`
|
||||
LastLoginIP string `orm:"size(64);column(last_login_ip)" json:"lastLoginIP"`
|
||||
LastLoginType string `orm:"size(16)" json:"lastLoginType"`
|
||||
|
||||
ParentMobile string `orm:"size(32)" json:"parentMobile"`
|
||||
DividePercentage int `json:"dividePercentage"`
|
||||
IsReceiver int `json:"isReceiver"`
|
||||
}
|
||||
|
||||
func (*User) TableUnique() [][]string {
|
||||
|
||||
@@ -2,11 +2,20 @@ package localjx
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/wxpayapi"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/ddmsg"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
@@ -615,3 +624,96 @@ func GetOrderPay(ctx *jxcontext.Context, vendorOrderID string) (payList []*model
|
||||
payList, err = dao.GetOrderPayList(db, vendorOrderID, jxutils.GetPossibleVendorIDFromVendorOrderID(vendorOrderID))
|
||||
return payList, err
|
||||
}
|
||||
|
||||
func PayForPopluarMan(ctx *jxcontext.Context, transactionID, vendorOrderID, userID string) (err error) {
|
||||
db := dao.GetDB()
|
||||
user, err := dao.GetUserByID(db, "user_id", userID)
|
||||
if user == nil {
|
||||
return fmt.Errorf("未找到此用户!用户ID:[%v]\n", userID)
|
||||
}
|
||||
auth, err := dao.GetUserBindAuthInfo(db, userID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "")
|
||||
if len(auth) == 0 {
|
||||
return fmt.Errorf("未找到此用户的微信验证方式!用户ID:[%v]\n", userID)
|
||||
}
|
||||
goods, err := dao.QueryOrders(db, vendorOrderID, 0, []int{model.VendorIDJX}, 0, utils.ZeroTimeValue, utils.ZeroTimeValue)
|
||||
if len(goods) == 0 {
|
||||
return fmt.Errorf("未找到此订单!订单ID:[%v]\n", vendorOrderID)
|
||||
}
|
||||
param := &wxpayapi.MultiProfitSharingParam{
|
||||
TransactionID: transactionID,
|
||||
OutOrderNo: vendorOrderID,
|
||||
}
|
||||
param.Receivers = wxpayapi.CData(`[{"type":"` + wxpayapi.AccountTypeOpen + `","account":"` + auth[0].AuthID + `","amount":` + utils.Int2Str(int(goods[0].ActualPayPrice)*user.DividePercentage/100) + `,"description":"每日订单打款分到个人"}]`)
|
||||
_, err = api.WxpayAPI.MultiProfitSharing(param)
|
||||
return err
|
||||
}
|
||||
|
||||
//自动打款给市场推广人
|
||||
func AutoPayForPopluarMan(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
fromDateStr = time.Now().AddDate(0, 0, -1).Format("2006-1-2") + " 00:00:00"
|
||||
toDateStr = time.Now().AddDate(0, 0, -1).Format("2006-1-2") + " 23:59:59"
|
||||
)
|
||||
result, err := dao.GetOrdersForJxPay(db, utils.Str2Time(fromDateStr), utils.Str2Time(toDateStr))
|
||||
fmt.Println(result)
|
||||
task := tasksch.NewParallelTask("AutoPayForPopluarMan", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
goods := batchItemList[0].(*dao.GoodsOrderPay)
|
||||
var (
|
||||
errMsg string
|
||||
param = &wxpayapi.MultiProfitSharingParam{
|
||||
TransactionID: goods.TransactionID,
|
||||
OutOrderNo: goods.VendorOrderID,
|
||||
}
|
||||
)
|
||||
user, err := dao.GetUserByID(db, "user_id", goods.UserID)
|
||||
if user.ParentMobile == "" {
|
||||
return retVal, err
|
||||
}
|
||||
user2, err := dao.GetUserByID(db, "mobile", user.ParentMobile)
|
||||
auth, err := dao.GetUserBindAuthInfo(db, user2.UserID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "")
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
if len(auth) == 0 {
|
||||
errMsg += fmt.Sprintf("打款失败!未找到此用户的微信验证方式!订单号:[%v],用户ID:[%v]\n", goods.VendorOrderID, user2.UserID)
|
||||
} else {
|
||||
param.Receivers = wxpayapi.CData(`[{"type":"` + wxpayapi.AccountTypeOpen + `","account":"` + auth[0].AuthID + `","amount":` + utils.Int2Str(int(goods.ActualPayPrice)*user2.DividePercentage/100) + `,"description":"每日订单打款分到个人"}]`)
|
||||
_, err := api.WxpayAPI.MultiProfitSharing(param)
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
}
|
||||
if user2.ParentMobile != "" {
|
||||
user3, err := dao.GetUserByID(db, "mobile", user2.ParentMobile)
|
||||
auth, err := dao.GetUserBindAuthInfo(db, user3.UserID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "")
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
if len(auth) == 0 {
|
||||
errMsg += fmt.Sprintf("打款失败!未找到此用户的微信验证方式!订单号:[%v],用户ID:[%v]\n", goods.VendorOrderID, user3.UserID)
|
||||
} else {
|
||||
param.Receivers = wxpayapi.CData(`[{"type":"` + wxpayapi.AccountTypeOpen + `","account":"` + auth[0].AuthID + `","amount":` + utils.Int2Str(int(goods.ActualPayPrice)*user3.DividePercentage/100) + `,"description":"每日订单打款分到个人"}]`)
|
||||
_, err := api.WxpayAPI.MultiProfitSharing(param)
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return retVal, errors.New(errMsg)
|
||||
}, result)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
if isAsync {
|
||||
hint = task.GetID()
|
||||
} else {
|
||||
_, err = task.GetResult(0)
|
||||
user, _ := dao.GetUserByID(dao.GetDB(), "mobile", "18160030913")
|
||||
noticeMsg := err.Error()
|
||||
if user != nil && err != nil {
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "每日打款错误", noticeMsg)
|
||||
}
|
||||
hint = "1"
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user