From c461e3e10eb12699237c39bea35a84479ed303e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 12 Feb 2020 17:24:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=89=93=E6=AC=BE=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/user2.go | 113 ++++++++--------- business/model/user.go | 4 +- business/partner/purchase/ebai/store_sku2.go | 6 +- business/partner/purchase/jx/localjx/order.go | 120 +++++++++--------- controllers/jx_order2.go | 16 +-- 5 files changed, 122 insertions(+), 137 deletions(-) diff --git a/business/jxstore/cms/user2.go b/business/jxstore/cms/user2.go index dd990d7e2..d71983974 100644 --- a/business/jxstore/cms/user2.go +++ b/business/jxstore/cms/user2.go @@ -8,8 +8,6 @@ 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" @@ -201,17 +199,6 @@ func RegisterUserWithMobile(ctx *jxcontext.Context, user *model.User, mobileVeri 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 { userProvider.UpdateLastLogin(user.GetID(), authType, ctx.GetRealRemoteIP()) TryAddStoreBossRole4User(ctx, user) @@ -1005,61 +992,61 @@ func UpdateUserWxNoAndPercent(user *model.User, isReceiver bool) (num int64, err 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) - } - } + // 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) + // 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 } diff --git a/business/model/user.go b/business/model/user.go index 275d11713..f1ad3627b 100644 --- a/business/model/user.go +++ b/business/model/user.go @@ -52,7 +52,9 @@ type User struct { ParentMobile string `orm:"size(32)" json:"parentMobile"` DividePercentage int `json:"dividePercentage"` - IsReceiver int `json:"isReceiver"` + Profit int `json:"profit"` + ProfitSum int `json:"profitSum"` + Arrears int `json:"arrears"` } func (*User) TableUnique() [][]string { diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index 84d93c9d6..db58c90a2 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -153,7 +153,11 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, v ) if strings.Contains(storeSku.StoreName, model.ExdStoreName) { isExd = true - customSkuID = utils.Str2Int64(storeSku.ExdSkuID) + if storeSku.ExdSkuID == "" { + customSkuID = 0 + } else { + customSkuID = utils.Str2Int64(storeSku.ExdSkuID) + } } else { isExd = false customSkuID = int64(storeSku.SkuID) diff --git a/business/partner/purchase/jx/localjx/order.go b/business/partner/purchase/jx/localjx/order.go index a64c1b27c..53dbc2894 100644 --- a/business/partner/purchase/jx/localjx/order.go +++ b/business/partner/purchase/jx/localjx/order.go @@ -2,7 +2,6 @@ package localjx import ( "crypto/md5" - "errors" "fmt" "math" "sort" @@ -13,7 +12,6 @@ import ( "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" @@ -629,7 +627,7 @@ func GetOrderPay(ctx *jxcontext.Context, vendorOrderID string) (payList []*model 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() user, err := dao.GetUserByID(db, "user_id", userID) if user == nil { @@ -643,85 +641,81 @@ func PayForPopluarMan(ctx *jxcontext.Context, transactionID, vendorOrderID, user if len(goods) == 0 { return fmt.Errorf("未找到此订单!订单ID:[%v]\n", vendorOrderID) } - param := &wxpayapi.MultiProfitSharingParam{ - TransactionID: transactionID, - OutOrderNo: vendorOrderID, + param := &wxpayapi.TransfersParam{ + CheckName: wxpayapi.CheckName, + 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.MultiProfitSharing(param) + _, err = api.WxpayAPI.Transfers(param) return err } //自动打款给市场推广人 -func AutoPayForPopluarMan(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) { +func AutoPayForPopluarMan(ctx *jxcontext.Context) (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)) - 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, - } - payPrice1 int - payPrice2 int - receivers string = "[" - ) - user, err := dao.GetUserByID(db, "user_id", goods.UserID) - if user.ParentMobile == "" { - return retVal, err + for _, goods := range result { + var ( + errMsg string + param = &wxpayapi.TransfersParam{ + CheckName: wxpayapi.CheckName, + PartnerTradeNo: goods.VendorOrderID, + Desc: "每日推广人订单分成分到个人", + SpbillCreateIP: ctx.GetRealRemoteIP(), } - user2, err := dao.GetUserByID(db, "mobile", user.ParentMobile) - auth, err := dao.GetUserBindAuthInfo(db, user2.UserID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "") + payPrice1 int + payPrice2 int + ) + user, err := dao.GetUserByID(db, "user_id", goods.UserID) + if user.ParentMobile == "" { + return err + } + user2, err := dao.GetUserByID(db, "mobile", user.ParentMobile) + auth, err := dao.GetUserBindAuthInfo(db, user2.UserID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "") + if err != nil { + return err + } + if len(auth) == 0 { + 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 retVal, err + return 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 err } if len(auth) == 0 { - errMsg += fmt.Sprintf("打款失败!未找到此用户的微信验证方式!订单号:[%v],用户ID:[%v]\n", goods.VendorOrderID, user2.UserID) + errMsg += fmt.Sprintf("打款失败!未找到此用户的微信验证方式!订单号:[%v],用户ID:[%v]\n", goods.VendorOrderID, user3.UserID) } else { - payPrice1 = int(goods.ActualPayPrice) * user2.DividePercentage / 100 - receivers += `{"type":"` + wxpayapi.AccountTypeOpen + `","account":"` + auth[0].AuthID + `","amount":` + utils.Int2Str(payPrice1) + `,"description":"每日订单打款分到个人"}` - // _, err := api.WxpayAPI.MultiProfitSharing(param) - } - if user2.ParentMobile != "" { - user3, err := dao.GetUserByID(db, "mobile", user2.ParentMobile) - auth, err := dao.GetUserBindAuthInfo(db, user3.UserID, model.AuthBindTypeAuth, []string{"weixinmini"}, "", "") + 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 retVal, err - } - if len(auth) == 0 { - errMsg += fmt.Sprintf("打款失败!未找到此用户的微信验证方式!订单号:[%v],用户ID:[%v]\n", goods.VendorOrderID, user3.UserID) - } else { - payPrice2 = (int(goods.ActualPayPrice) - payPrice1) * user3.DividePercentage / 100 - receivers += `,{"type":"` + wxpayapi.AccountTypeOpen + `","account":"` + auth[0].AuthID + `","amount":` + utils.Int2Str(payPrice2) + `,"description":"每日订单打款分到个人"}` - // _, err := api.WxpayAPI.MultiProfitSharing(param) + return err } } - receivers += "]" - param.Receivers = wxpayapi.CData(receivers) - _, 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 + user, _ := dao.GetUserByID(dao.GetDB(), "mobile", "18160030913") + noticeMsg := err.Error() + if user != nil && err != nil { + ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "每日打款错误", noticeMsg) + } + return err } diff --git a/controllers/jx_order2.go b/controllers/jx_order2.go index 730a00514..6eab161ca 100644 --- a/controllers/jx_order2.go +++ b/controllers/jx_order2.go @@ -131,33 +131,31 @@ func (c *JxOrderController) GetMyOrderCountInfo() { }) } -// @Title 每日订单分账 -// @Description 每日订单分账 +// @Title 每日订单打款 +// @Description 每日订单打款 // @Param token header string true "认证token" -// @Param isAsync formData bool false "是否异步操作" -// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /AutoPayForPopluarMan [post] func (c *JxOrderController) AutoPayForPopluarMan() { 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 }) } -// @Title 订单分账 -// @Description 订单分账 +// @Title 订单打款 +// @Description 订单打款 // @Param token header string true "认证token" -// @Param transactionID formData string true "微信订单ID" // @Param vendorOrderID formData string true "订单ID" // @Param userID formData string true "userID" +// @Param price formData int true "钱" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /PayForPopluarMan [post] func (c *JxOrderController) PayForPopluarMan() { 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 }) }