订单打款修改
This commit is contained in:
@@ -8,8 +8,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/wxpayapi"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
"git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/api/apimanager"
|
"git.rosy.net.cn/jx-callback/globals/api/apimanager"
|
||||||
@@ -201,17 +199,6 @@ func RegisterUserWithMobile(ctx *jxcontext.Context, user *model.User, mobileVeri
|
|||||||
user.Avatar = inAuthInfo.GetAvatar()
|
user.Avatar = inAuthInfo.GetAvatar()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//注册时默认商城用户就加入分账接收方
|
|
||||||
if strings.Contains(ctx.GetRequest().Referer(), "wx4b5930c13f8b1170") {
|
|
||||||
param := &wxpayapi.ProfitSharingReceiverParam{
|
|
||||||
Receiver: wxpayapi.CData(`{
|
|
||||||
"type":"` + wxpayapi.AccountTypeOpen + `",
|
|
||||||
"account":"` + inAuthInfo.GetAuthID() + `",
|
|
||||||
"relation_type":" ` + wxpayapi.Relation + `"
|
|
||||||
}`),
|
|
||||||
}
|
|
||||||
_, err = api.WxpayAPI.AddProfitSharingReceiver(param)
|
|
||||||
}
|
|
||||||
if err = CreateUser(user, utils.LimitUTF8StringLen(createName, 32)); err == nil {
|
if err = CreateUser(user, utils.LimitUTF8StringLen(createName, 32)); err == nil {
|
||||||
userProvider.UpdateLastLogin(user.GetID(), authType, ctx.GetRealRemoteIP())
|
userProvider.UpdateLastLogin(user.GetID(), authType, ctx.GetRealRemoteIP())
|
||||||
TryAddStoreBossRole4User(ctx, user)
|
TryAddStoreBossRole4User(ctx, user)
|
||||||
@@ -1005,61 +992,61 @@ func UpdateUserWxNoAndPercent(user *model.User, isReceiver bool) (num int64, err
|
|||||||
dao.Rollback(db)
|
dao.Rollback(db)
|
||||||
}
|
}
|
||||||
if isReceiver {
|
if isReceiver {
|
||||||
param := &wxpayapi.ProfitSharingReceiverParam{
|
// param := &wxpayapi.ProfitSharingReceiverParam{
|
||||||
Receiver: wxpayapi.CData(`{
|
// Receiver: wxpayapi.CData(`{
|
||||||
"type":"` + wxpayapi.AccountTypeOpen + `",
|
// "type":"` + wxpayapi.AccountTypeOpen + `",
|
||||||
"account":"` + auth[0].AuthID + `",
|
// "account":"` + auth[0].AuthID + `",
|
||||||
"relation_type":" ` + wxpayapi.Relation + `"
|
// "relation_type":" ` + wxpayapi.Relation + `"
|
||||||
}`),
|
// }`),
|
||||||
}
|
// }
|
||||||
_, err := api.WxpayAPI.AddProfitSharingReceiver(param)
|
// _, err := api.WxpayAPI.AddProfitSharingReceiver(param)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return 0, err
|
// return 0, err
|
||||||
} else {
|
// } else {
|
||||||
user2.IsReceiver = 1
|
// user2.IsReceiver = 1
|
||||||
num3, err := dao.UpdateEntity(db, user2, "IsReceiver")
|
// num3, err := dao.UpdateEntity(db, user2, "IsReceiver")
|
||||||
num += num3
|
// num += num3
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
dao.Rollback(db)
|
// dao.Rollback(db)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
dao.Commit(db)
|
dao.Commit(db)
|
||||||
return num, err
|
return num, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteProfitSharingReceiver(ctx *jxcontext.Context, userID string) (err error) {
|
func DeleteProfitSharingReceiver(ctx *jxcontext.Context, userID string) (err error) {
|
||||||
db := dao.GetDB()
|
// db := dao.GetDB()
|
||||||
auth, err := dao.GetUserBindAuthInfo(db, userID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "")
|
// auth, err := dao.GetUserBindAuthInfo(db, userID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "")
|
||||||
if len(auth) == 0 {
|
// if len(auth) == 0 {
|
||||||
return fmt.Errorf("未找到此用户的微信验证方式!用户ID:[%v]\n", userID)
|
// return fmt.Errorf("未找到此用户的微信验证方式!用户ID:[%v]\n", userID)
|
||||||
}
|
// }
|
||||||
dao.Begin(db)
|
// dao.Begin(db)
|
||||||
defer func() {
|
// defer func() {
|
||||||
if r := recover(); r != nil || err != nil {
|
// if r := recover(); r != nil || err != nil {
|
||||||
dao.Rollback(db)
|
// dao.Rollback(db)
|
||||||
if r != nil {
|
// if r != nil {
|
||||||
panic(r)
|
// panic(r)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}()
|
// }()
|
||||||
param := &wxpayapi.ProfitSharingReceiverParam{
|
// param := &wxpayapi.ProfitSharingReceiverParam{
|
||||||
Receiver: wxpayapi.CData(`{
|
// Receiver: wxpayapi.CData(`{
|
||||||
"type":"` + wxpayapi.AccountTypeOpen + `",
|
// "type":"` + wxpayapi.AccountTypeOpen + `",
|
||||||
"account":"` + auth[0].AuthID + `"
|
// "account":"` + auth[0].AuthID + `"
|
||||||
}`),
|
// }`),
|
||||||
}
|
// }
|
||||||
_, err = api.WxpayAPI.DeleteProfitSharingReceiver(param)
|
// _, err = api.WxpayAPI.DeleteProfitSharingReceiver(param)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
} else {
|
// } else {
|
||||||
user2, err := dao.GetUserByID(db, "user_id", userID)
|
// user2, err := dao.GetUserByID(db, "user_id", userID)
|
||||||
user2.IsReceiver = 0
|
// user2.IsReceiver = 0
|
||||||
_, err = dao.UpdateEntity(db, user2, "IsReceiver")
|
// _, err = dao.UpdateEntity(db, user2, "IsReceiver")
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
dao.Rollback(db)
|
// dao.Rollback(db)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
dao.Commit(db)
|
// dao.Commit(db)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ type User struct {
|
|||||||
|
|
||||||
ParentMobile string `orm:"size(32)" json:"parentMobile"`
|
ParentMobile string `orm:"size(32)" json:"parentMobile"`
|
||||||
DividePercentage int `json:"dividePercentage"`
|
DividePercentage int `json:"dividePercentage"`
|
||||||
IsReceiver int `json:"isReceiver"`
|
Profit int `json:"profit"`
|
||||||
|
ProfitSum int `json:"profitSum"`
|
||||||
|
Arrears int `json:"arrears"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*User) TableUnique() [][]string {
|
func (*User) TableUnique() [][]string {
|
||||||
|
|||||||
@@ -153,7 +153,11 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, v
|
|||||||
)
|
)
|
||||||
if strings.Contains(storeSku.StoreName, model.ExdStoreName) {
|
if strings.Contains(storeSku.StoreName, model.ExdStoreName) {
|
||||||
isExd = true
|
isExd = true
|
||||||
|
if storeSku.ExdSkuID == "" {
|
||||||
|
customSkuID = 0
|
||||||
|
} else {
|
||||||
customSkuID = utils.Str2Int64(storeSku.ExdSkuID)
|
customSkuID = utils.Str2Int64(storeSku.ExdSkuID)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
isExd = false
|
isExd = false
|
||||||
customSkuID = int64(storeSku.SkuID)
|
customSkuID = int64(storeSku.SkuID)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package localjx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -13,7 +12,6 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"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/ddmsg"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
@@ -629,7 +627,7 @@ func GetOrderPay(ctx *jxcontext.Context, vendorOrderID string) (payList []*model
|
|||||||
return payList, err
|
return payList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func PayForPopluarMan(ctx *jxcontext.Context, transactionID, vendorOrderID, userID string) (err error) {
|
func PayForPopluarMan(ctx *jxcontext.Context, vendorOrderID, userID string, price int) (err error) {
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
user, err := dao.GetUserByID(db, "user_id", userID)
|
user, err := dao.GetUserByID(db, "user_id", userID)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
@@ -643,85 +641,81 @@ func PayForPopluarMan(ctx *jxcontext.Context, transactionID, vendorOrderID, user
|
|||||||
if len(goods) == 0 {
|
if len(goods) == 0 {
|
||||||
return fmt.Errorf("未找到此订单!订单ID:[%v]\n", vendorOrderID)
|
return fmt.Errorf("未找到此订单!订单ID:[%v]\n", vendorOrderID)
|
||||||
}
|
}
|
||||||
param := &wxpayapi.MultiProfitSharingParam{
|
param := &wxpayapi.TransfersParam{
|
||||||
TransactionID: transactionID,
|
CheckName: wxpayapi.CheckName,
|
||||||
OutOrderNo: vendorOrderID,
|
PartnerTradeNo: vendorOrderID,
|
||||||
|
Desc: "每日推广人订单分成分到个人",
|
||||||
|
SpbillCreateIP: ctx.GetRealRemoteIP(),
|
||||||
|
OpenID: auth[0].AuthID,
|
||||||
|
Amount: price,
|
||||||
}
|
}
|
||||||
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.Transfers(param)
|
||||||
_, err = api.WxpayAPI.MultiProfitSharing(param)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//自动打款给市场推广人
|
//自动打款给市场推广人
|
||||||
func AutoPayForPopluarMan(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) {
|
func AutoPayForPopluarMan(ctx *jxcontext.Context) (err error) {
|
||||||
var (
|
var (
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
fromDateStr = time.Now().AddDate(0, 0, -1).Format("2006-1-2") + " 00:00:00"
|
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"
|
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))
|
result, err := dao.GetOrdersForJxPay(db, utils.Str2Time(fromDateStr), utils.Str2Time(toDateStr))
|
||||||
task := tasksch.NewParallelTask("AutoPayForPopluarMan", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
for _, goods := range result {
|
||||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
|
||||||
goods := batchItemList[0].(*dao.GoodsOrderPay)
|
|
||||||
var (
|
var (
|
||||||
errMsg string
|
errMsg string
|
||||||
param = &wxpayapi.MultiProfitSharingParam{
|
param = &wxpayapi.TransfersParam{
|
||||||
TransactionID: goods.TransactionID,
|
CheckName: wxpayapi.CheckName,
|
||||||
OutOrderNo: goods.VendorOrderID,
|
PartnerTradeNo: goods.VendorOrderID,
|
||||||
|
Desc: "每日推广人订单分成分到个人",
|
||||||
|
SpbillCreateIP: ctx.GetRealRemoteIP(),
|
||||||
}
|
}
|
||||||
payPrice1 int
|
payPrice1 int
|
||||||
payPrice2 int
|
payPrice2 int
|
||||||
receivers string = "["
|
|
||||||
)
|
)
|
||||||
user, err := dao.GetUserByID(db, "user_id", goods.UserID)
|
user, err := dao.GetUserByID(db, "user_id", goods.UserID)
|
||||||
if user.ParentMobile == "" {
|
if user.ParentMobile == "" {
|
||||||
return retVal, err
|
return err
|
||||||
}
|
}
|
||||||
user2, err := dao.GetUserByID(db, "mobile", user.ParentMobile)
|
user2, err := dao.GetUserByID(db, "mobile", user.ParentMobile)
|
||||||
auth, err := dao.GetUserBindAuthInfo(db, user2.UserID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "")
|
auth, err := dao.GetUserBindAuthInfo(db, user2.UserID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return retVal, err
|
return err
|
||||||
}
|
}
|
||||||
if len(auth) == 0 {
|
if len(auth) == 0 {
|
||||||
errMsg += fmt.Sprintf("打款失败!未找到此用户的微信验证方式!订单号:[%v],用户ID:[%v]\n", goods.VendorOrderID, user2.UserID)
|
errMsg += fmt.Sprintf("打款失败!未找到此用户的微信验证方式!订单号:[%v],用户ID:[%v]\n", goods.VendorOrderID, user2.UserID)
|
||||||
} else {
|
} else {
|
||||||
payPrice1 = int(goods.ActualPayPrice) * user2.DividePercentage / 100
|
payPrice1 = int(goods.ActualPayPrice) * user2.DividePercentage / 100
|
||||||
receivers += `{"type":"` + wxpayapi.AccountTypeOpen + `","account":"` + auth[0].AuthID + `","amount":` + utils.Int2Str(payPrice1) + `,"description":"每日订单打款分到个人"}`
|
param.OpenID = auth[0].AuthID
|
||||||
// _, err := api.WxpayAPI.MultiProfitSharing(param)
|
param.Amount = payPrice1
|
||||||
|
_, err := api.WxpayAPI.Transfers(param)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if user2.ParentMobile != "" {
|
if user2.ParentMobile != "" {
|
||||||
user3, err := dao.GetUserByID(db, "mobile", user2.ParentMobile)
|
user3, err := dao.GetUserByID(db, "mobile", user2.ParentMobile)
|
||||||
auth, err := dao.GetUserBindAuthInfo(db, user3.UserID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "")
|
auth, err := dao.GetUserBindAuthInfo(db, user3.UserID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return retVal, err
|
return err
|
||||||
}
|
}
|
||||||
if len(auth) == 0 {
|
if len(auth) == 0 {
|
||||||
errMsg += fmt.Sprintf("打款失败!未找到此用户的微信验证方式!订单号:[%v],用户ID:[%v]\n", goods.VendorOrderID, user3.UserID)
|
errMsg += fmt.Sprintf("打款失败!未找到此用户的微信验证方式!订单号:[%v],用户ID:[%v]\n", goods.VendorOrderID, user3.UserID)
|
||||||
} else {
|
} else {
|
||||||
payPrice2 = (int(goods.ActualPayPrice) - payPrice1) * user3.DividePercentage / 100
|
payPrice2 = (int(goods.ActualPayPrice) - payPrice1) * user3.DividePercentage / 100
|
||||||
receivers += `,{"type":"` + wxpayapi.AccountTypeOpen + `","account":"` + auth[0].AuthID + `","amount":` + utils.Int2Str(payPrice2) + `,"description":"每日订单打款分到个人"}`
|
param.OpenID = auth[0].AuthID
|
||||||
// _, err := api.WxpayAPI.MultiProfitSharing(param)
|
param.Amount = payPrice2
|
||||||
}
|
_, err := api.WxpayAPI.Transfers(param)
|
||||||
}
|
|
||||||
receivers += "]"
|
|
||||||
param.Receivers = wxpayapi.CData(receivers)
|
|
||||||
_, err = api.WxpayAPI.MultiProfitSharing(param)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return retVal, err
|
return 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")
|
user, _ := dao.GetUserByID(dao.GetDB(), "mobile", "18160030913")
|
||||||
noticeMsg := err.Error()
|
noticeMsg := err.Error()
|
||||||
if user != nil && err != nil {
|
if user != nil && err != nil {
|
||||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "每日打款错误", noticeMsg)
|
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "每日打款错误", noticeMsg)
|
||||||
}
|
}
|
||||||
hint = "1"
|
return err
|
||||||
}
|
|
||||||
return hint, err
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,33 +131,31 @@ func (c *JxOrderController) GetMyOrderCountInfo() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Title 每日订单分账
|
// @Title 每日订单打款
|
||||||
// @Description 每日订单分账
|
// @Description 每日订单打款
|
||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
// @Param isAsync formData bool false "是否异步操作"
|
|
||||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @router /AutoPayForPopluarMan [post]
|
// @router /AutoPayForPopluarMan [post]
|
||||||
func (c *JxOrderController) AutoPayForPopluarMan() {
|
func (c *JxOrderController) AutoPayForPopluarMan() {
|
||||||
c.callAutoPayForPopluarMan(func(params *tJxorderAutoPayForPopluarManParams) (retVal interface{}, errCode string, err error) {
|
c.callAutoPayForPopluarMan(func(params *tJxorderAutoPayForPopluarManParams) (retVal interface{}, errCode string, err error) {
|
||||||
retVal, err = localjx.AutoPayForPopluarMan(params.Ctx, params.IsAsync, params.IsContinueWhenError)
|
err = localjx.AutoPayForPopluarMan(params.Ctx)
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Title 订单分账
|
// @Title 订单打款
|
||||||
// @Description 订单分账
|
// @Description 订单打款
|
||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
// @Param transactionID formData string true "微信订单ID"
|
|
||||||
// @Param vendorOrderID formData string true "订单ID"
|
// @Param vendorOrderID formData string true "订单ID"
|
||||||
// @Param userID formData string true "userID"
|
// @Param userID formData string true "userID"
|
||||||
|
// @Param price formData int true "钱"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @router /PayForPopluarMan [post]
|
// @router /PayForPopluarMan [post]
|
||||||
func (c *JxOrderController) PayForPopluarMan() {
|
func (c *JxOrderController) PayForPopluarMan() {
|
||||||
c.callPayForPopluarMan(func(params *tJxorderPayForPopluarManParams) (retVal interface{}, errCode string, err error) {
|
c.callPayForPopluarMan(func(params *tJxorderPayForPopluarManParams) (retVal interface{}, errCode string, err error) {
|
||||||
err = localjx.PayForPopluarMan(params.Ctx, params.TransactionID, params.VendorOrderID, params.UserID)
|
err = localjx.PayForPopluarMan(params.Ctx, params.VendorOrderID, params.UserID, params.Price)
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user