temporay up
This commit is contained in:
@@ -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{}{}
|
||||
@@ -1187,3 +1192,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
|
||||
}
|
||||
|
||||
@@ -472,6 +472,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