diff --git a/business/jxcallback/scheduler/defsch/defsch.go b/business/jxcallback/scheduler/defsch/defsch.go index b71817a79..0ffee88da 100644 --- a/business/jxcallback/scheduler/defsch/defsch.go +++ b/business/jxcallback/scheduler/defsch/defsch.go @@ -1371,7 +1371,7 @@ func (s *DefScheduler) updateStoreAccount(order *model.GoodsOrder, bill *model.W func (s *DefScheduler) updateBrandAccount(store *dao.StoreDetail, bill *model.Waybill) { realDesiredFee := bill.DesiredFee if balance, err := partner.CurStoreAcctManager.GetBrandBalance(store.BrandID); err == nil { - partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, balance-int(realDesiredFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, bill.VendorOrderID, "") + partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, balance-int(realDesiredFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, bill.VendorOrderID) } } diff --git a/business/jxstore/cms/store_acct.go b/business/jxstore/cms/store_acct.go index ce4ed3ef1..82a023766 100644 --- a/business/jxstore/cms/store_acct.go +++ b/business/jxstore/cms/store_acct.go @@ -186,7 +186,7 @@ func (s *StoreAcctManager) GetBrandBalance(brandID int) (balance int, err error) return dao.GetBrandBalance(dao.GetDB(), brandID) } -func (s *StoreAcctManager) InsertBrandBill(ctx *jxcontext.Context, brandID, price, billType, feeType int, vendorOrderID string, orderID string) (err error) { +func (s *StoreAcctManager) InsertBrandBill(ctx *jxcontext.Context, brandID, price, billType, feeType int, vendorOrderID string) (err error) { utils.CallFuncAsync(func() { var ( db = dao.GetDB() @@ -197,7 +197,6 @@ func (s *StoreAcctManager) InsertBrandBill(ctx *jxcontext.Context, brandID, pric BillType: billType, FeeType: feeType, VendorOrderID: vendorOrderID, - OrderID: orderID, } dao.WrapAddIDCULEntity(brandBill, ctx.GetUserName()) //扣除后,如果余额小于10元要发消息通知 ,每天通知一次 diff --git a/business/jxutils/smsmsg/smsmsg.go b/business/jxutils/smsmsg/smsmsg.go index a1800a9a8..d6417ec1a 100644 --- a/business/jxutils/smsmsg/smsmsg.go +++ b/business/jxutils/smsmsg/smsmsg.go @@ -131,7 +131,7 @@ func NotifyPickOrder(order *model.GoodsOrder) (err error) { order.NotifyType = int(store.SMSNotify) err = partner.CurOrderManager.UpdateOrderFields(order, []string{"NotifyType"}) //品牌余额, 一条5分 - err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, 5, model.BrandBillTypeExpend, feeType, order.VendorOrderID, "") + err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, 5, model.BrandBillTypeExpend, feeType, order.VendorOrderID) return err } balance, _ := partner.CurStoreAcctManager.GetBrandBalance(store.BrandID) @@ -338,7 +338,7 @@ func NotifyBrandBalance(brandID int) (err error) { err = api.Cacher.Set("brandID"+utils.Int2Str(brandID), 1, utils.Str2Time(time.Now().AddDate(0, 0, 1).Format("2006-01-02")+"00:00:00").Sub(time.Now())) } if count > 0 { - partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, brandID, 5*count, model.BrandBillTypeExpend, model.BrandBillFeeTypeSys, "", "") + partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, brandID, 5*count, model.BrandBillTypeExpend, model.BrandBillFeeTypeSys, "") } } return err diff --git a/business/model/order.go b/business/model/order.go index 3816f561c..77b737b9c 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -14,8 +14,9 @@ const ( PayTypeWX = 1 // 微信支付 PayTypeTL = 2 // 通联宝支付 - PayTypeTL_DiscountCard = 3 // 通联宝支付(会员折扣卡) - PayTypeTL_StoreAcctPay = 4 // 通联宝支付(门店账户充值) + PayTypeTL_DiscountCard = 3 // 通联宝支付(会员折扣卡) + PayTypeTL_StoreAcctPay = 4 // 通联宝支付(门店账户充值) + PayTypeTL_BrandBillCharge = 5 //品牌账户充值(pc扫码支付) PayStatusNo = 0 PayStatusYes = 1 @@ -41,6 +42,7 @@ const ( OrderTypeSupplyGoods = 2 //进货订单 OrderTypeDefendPrice = 3 //守价订单 OrderTypeStoreAcct = 4 //门店账户订单 + OrderTypeBrand = 5 //品牌账户订单 ) const ( @@ -513,6 +515,25 @@ func (v *StoreAcctOrder) TableUnique() [][]string { } } +type BrandOrder struct { + ModelIDCUL + + VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` + BrandID int `orm:"column(vendor_id)" json:"vendorID"` + ActualPayPrice int `json:"actualPayPrice"` // 单位为分 顾客实际支付 + UserID string `orm:"column(user_id);size(48);index" json:"userID"` + OrderType int `json:"orderType"` + Status int `json:"status"` // 参见OrderStatus*相关的常量定义 + OrderFinishedAt time.Time `orm:"type(datetime)" json:"orderFinishedAt"` +} + +func (v *BrandOrder) TableIndex() [][]string { + return [][]string{ + []string{"VendorOrderID", "BrandID"}, + []string{"CreatedAt"}, + } +} + // 判断是否是购买平台自有物流 // 对于京东,饿百来说,就是其自有的物流,对于微商城来说,是达达 func IsWaybillPlatformOwn(bill *Waybill) bool { diff --git a/business/partner/partner_store_acct.go b/business/partner/partner_store_acct.go index 081d7494c..addb90171 100644 --- a/business/partner/partner_store_acct.go +++ b/business/partner/partner_store_acct.go @@ -45,5 +45,5 @@ type IStoreAcctManager interface { //品牌账户 GetBrandBalance(brandID int) (balance int, err error) - InsertBrandBill(ctx *jxcontext.Context, brandID, price, billType, feeType int, vendorOrderID string, orderID string) (err error) + InsertBrandBill(ctx *jxcontext.Context, brandID, price, billType, feeType int, vendorOrderID string) (err error) } diff --git a/business/partner/purchase/jx/localjx/order.go b/business/partner/purchase/jx/localjx/order.go index 704caf858..625e188ca 100644 --- a/business/partner/purchase/jx/localjx/order.go +++ b/business/partner/purchase/jx/localjx/order.go @@ -406,6 +406,21 @@ func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType err = dao.CreateEntity(dao.GetDB(), orderPay) } } + case model.PayTypeTL_BrandBillCharge: + brandOrder := &model.BrandOrder{ + VendorOrderID: vendorOrderID, + } + if err = dao.GetEntity(db, brandOrder, "VendorOrderID"); err == nil && brandOrder.ID != 0 { + order = &model.GoodsOrder{ + VendorOrderID: vendorOrderID, + ActualPayPrice: int64(brandOrder.ActualPayPrice), + VendorID: model.VendorIDJX, + } + if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID); err == nil && orderPay != nil { + dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName()) + err = dao.CreateEntity(dao.GetDB(), orderPay) + } + } default: err = fmt.Errorf("支付方式:%d当前不支持", payType) } @@ -572,6 +587,17 @@ func OnPayFinished(orderPay *model.OrderPay) (err error) { partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(nil, storeOrder.StoreID, storeOrder.ActualPayPrice, partner.StoreAcctTypeIncomePay, orderPay.VendorOrderID, 0) } } + case model.PayTypeTL_BrandBillCharge: + brandOrder := &model.BrandOrder{ + VendorOrderID: orderPay.VendorOrderID, + } + if err = dao.GetEntity(dao.GetDB(), brandOrder, "VendorOrderID"); err == nil && brandOrder.ID != 0 { + brandOrder.OrderFinishedAt = time.Now() + brandOrder.Status = model.OrderStatusFinished + if _, err = dao.UpdateEntity(dao.GetDB(), brandOrder, "OrderFinishedAt", "Status"); err == nil { + partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, brandOrder.BrandID, brandOrder.ActualPayPrice, model.BrandBillTypeIncome, model.BrandBillFeeTypeCharge, orderPay.VendorOrderID) + } + } default: priceDefendOrders, _ := dao.GetPriceDefendOrder(dao.GetDB(), orderPay.VendorOrderID, nil, nil, []int{jxutils.GetDefendPriceIssue()}, 0, -1, -1, 0, "", utils.ZeroTimeValue, utils.ZeroTimeValue, false) if len(priceDefendOrders) > 0 { @@ -2497,3 +2523,30 @@ func CreateStoreAcctOrder(ctx *jxcontext.Context, orderType, storeID, price int, dao.Commit(db, txDB) return order.VendorOrderID, err } + +func CreateBrandOrder(ctx *jxcontext.Context, brandID, price int) (vendorOrderID string, err error) { + var ( + db = dao.GetDB() + ) + brandOrder := &model.BrandOrder{ + VendorOrderID: utils.Int64ToStr(jxutils.GenOrderNo()), + UserID: ctx.GetUserID(), + BrandID: brandID, + OrderType: model.OrderTypeBrand, + Status: model.OrderStatusWait4Pay, + ActualPayPrice: price, + } + dao.WrapAddIDCULEntity(brandOrder, ctx.GetUserName()) + txDB, _ := dao.Begin(db) + defer func() { + if r := recover(); r != nil { + dao.Rollback(db, txDB) + panic(r) + } + }() + if err = dao.CreateEntity(db, brandOrder); err != nil { + dao.Rollback(db, txDB) + } + dao.Commit(db, txDB) + return brandOrder.VendorOrderID, err +} diff --git a/business/partner/purchase/jx/localjx/tonglianpay.go b/business/partner/purchase/jx/localjx/tonglianpay.go index 806170af0..a14e8fcb6 100644 --- a/business/partner/purchase/jx/localjx/tonglianpay.go +++ b/business/partner/purchase/jx/localjx/tonglianpay.go @@ -44,7 +44,7 @@ func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, payType int, param.Acct = authInfo.GetAuthID() } } - if vendorPayType == tonglianpayapi.PayTypeZfbJS || vendorPayType == tonglianpayapi.PayTypeZfbApp || vendorPayType == tonglianpayapi.PayTypeZfbQrcode { + if vendorPayType == tonglianpayapi.PayTypeZfbJS || vendorPayType == tonglianpayapi.PayTypeZfbApp { if authInfo, err := ctx.GetV2AuthInfo(); err == nil { param.Acct = authInfo.GetAuthID() } diff --git a/controllers/jx_order2.go b/controllers/jx_order2.go index 4c776d59c..f1c27be8b 100644 --- a/controllers/jx_order2.go +++ b/controllers/jx_order2.go @@ -57,9 +57,9 @@ func (c *JxOrderController) Pay4Order() { // @Title 请求支付京西商城相关用户支付项目 // @Description 请求支付京西商城相关用户支付项目 // @Param token header string true "认证token" -// @Param thingID formData int fasle "项目ID" -// @Param subAppID formData string true "appID" -// @Param vendorOrderID formData string fasle "订单ID" +// @Param thingID formData int false "项目ID" +// @Param subAppID formData string false "appID" +// @Param vendorOrderID formData string false "订单ID" // @Param payType formData int true "支付类型" // @Param vendorPayType formData string true "平台支付类型" // @Success 200 {object} controllers.CallResult @@ -387,3 +387,18 @@ func (c *JxOrderController) CreateStoreAcctOrder() { return retVal, "", err }) } + +// @Title 创建品牌账户订单 +// @Description 创建品牌账户订单 +// @Param token header string true "认证token" +// @Param brandID formData int false "品牌ID" +// @Param price formData int true "支付金额" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /CreateBrandOrder [post] +func (c *JxOrderController) CreateBrandOrder() { + c.callCreateBrandOrder(func(params *tJxorderCreateBrandOrderParams) (retVal interface{}, errCode string, err error) { + retVal, err = localjx.CreateBrandOrder(params.Ctx, params.BrandID, params.Price) + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 0b79a179f..08daaed2b 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -763,6 +763,15 @@ func init() { Filters: nil, Params: nil}) + web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"], + web.ControllerComments{ + Method: "CreateBrandOrder", + Router: `/CreateBrandOrder`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"], web.ControllerComments{ Method: "GetAvailableDeliverTime",