pc充值品牌余额

This commit is contained in:
suyl
2021-08-31 15:23:10 +08:00
parent 5a658dd646
commit 48125eeb41
9 changed files with 109 additions and 12 deletions

View File

@@ -1371,7 +1371,7 @@ func (s *DefScheduler) updateStoreAccount(order *model.GoodsOrder, bill *model.W
func (s *DefScheduler) updateBrandAccount(store *dao.StoreDetail, bill *model.Waybill) { func (s *DefScheduler) updateBrandAccount(store *dao.StoreDetail, bill *model.Waybill) {
realDesiredFee := bill.DesiredFee realDesiredFee := bill.DesiredFee
if balance, err := partner.CurStoreAcctManager.GetBrandBalance(store.BrandID); err == nil { 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)
} }
} }

View File

@@ -186,7 +186,7 @@ func (s *StoreAcctManager) GetBrandBalance(brandID int) (balance int, err error)
return dao.GetBrandBalance(dao.GetDB(), brandID) 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() { utils.CallFuncAsync(func() {
var ( var (
db = dao.GetDB() db = dao.GetDB()
@@ -197,7 +197,6 @@ func (s *StoreAcctManager) InsertBrandBill(ctx *jxcontext.Context, brandID, pric
BillType: billType, BillType: billType,
FeeType: feeType, FeeType: feeType,
VendorOrderID: vendorOrderID, VendorOrderID: vendorOrderID,
OrderID: orderID,
} }
dao.WrapAddIDCULEntity(brandBill, ctx.GetUserName()) dao.WrapAddIDCULEntity(brandBill, ctx.GetUserName())
//扣除后如果余额小于10元要发消息通知 ,每天通知一次 //扣除后如果余额小于10元要发消息通知 ,每天通知一次

View File

@@ -131,7 +131,7 @@ func NotifyPickOrder(order *model.GoodsOrder) (err error) {
order.NotifyType = int(store.SMSNotify) order.NotifyType = int(store.SMSNotify)
err = partner.CurOrderManager.UpdateOrderFields(order, []string{"NotifyType"}) err = partner.CurOrderManager.UpdateOrderFields(order, []string{"NotifyType"})
//品牌余额, 一条5分 //品牌余额, 一条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 return err
} }
balance, _ := partner.CurStoreAcctManager.GetBrandBalance(store.BrandID) 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())) 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 { 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 return err

View File

@@ -14,8 +14,9 @@ const (
PayTypeWX = 1 // 微信支付 PayTypeWX = 1 // 微信支付
PayTypeTL = 2 // 通联宝支付 PayTypeTL = 2 // 通联宝支付
PayTypeTL_DiscountCard = 3 // 通联宝支付(会员折扣卡) PayTypeTL_DiscountCard = 3 // 通联宝支付(会员折扣卡)
PayTypeTL_StoreAcctPay = 4 // 通联宝支付(门店账户充值) PayTypeTL_StoreAcctPay = 4 // 通联宝支付(门店账户充值)
PayTypeTL_BrandBillCharge = 5 //品牌账户充值pc扫码支付
PayStatusNo = 0 PayStatusNo = 0
PayStatusYes = 1 PayStatusYes = 1
@@ -41,6 +42,7 @@ const (
OrderTypeSupplyGoods = 2 //进货订单 OrderTypeSupplyGoods = 2 //进货订单
OrderTypeDefendPrice = 3 //守价订单 OrderTypeDefendPrice = 3 //守价订单
OrderTypeStoreAcct = 4 //门店账户订单 OrderTypeStoreAcct = 4 //门店账户订单
OrderTypeBrand = 5 //品牌账户订单
) )
const ( 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 { func IsWaybillPlatformOwn(bill *Waybill) bool {

View File

@@ -45,5 +45,5 @@ type IStoreAcctManager interface {
//品牌账户 //品牌账户
GetBrandBalance(brandID int) (balance int, err error) 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)
} }

View File

@@ -406,6 +406,21 @@ func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType
err = dao.CreateEntity(dao.GetDB(), orderPay) 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: default:
err = fmt.Errorf("支付方式:%d当前不支持", payType) 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) 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: default:
priceDefendOrders, _ := dao.GetPriceDefendOrder(dao.GetDB(), orderPay.VendorOrderID, nil, nil, []int{jxutils.GetDefendPriceIssue()}, 0, -1, -1, 0, "", utils.ZeroTimeValue, utils.ZeroTimeValue, false) 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 { if len(priceDefendOrders) > 0 {
@@ -2497,3 +2523,30 @@ func CreateStoreAcctOrder(ctx *jxcontext.Context, orderType, storeID, price int,
dao.Commit(db, txDB) dao.Commit(db, txDB)
return order.VendorOrderID, err 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
}

View File

@@ -44,7 +44,7 @@ func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, payType int,
param.Acct = authInfo.GetAuthID() 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 { if authInfo, err := ctx.GetV2AuthInfo(); err == nil {
param.Acct = authInfo.GetAuthID() param.Acct = authInfo.GetAuthID()
} }

View File

@@ -57,9 +57,9 @@ func (c *JxOrderController) Pay4Order() {
// @Title 请求支付京西商城相关用户支付项目 // @Title 请求支付京西商城相关用户支付项目
// @Description 请求支付京西商城相关用户支付项目 // @Description 请求支付京西商城相关用户支付项目
// @Param token header string true "认证token" // @Param token header string true "认证token"
// @Param thingID formData int fasle "项目ID" // @Param thingID formData int false "项目ID"
// @Param subAppID formData string true "appID" // @Param subAppID formData string false "appID"
// @Param vendorOrderID formData string fasle "订单ID" // @Param vendorOrderID formData string false "订单ID"
// @Param payType formData int true "支付类型" // @Param payType formData int true "支付类型"
// @Param vendorPayType formData string true "平台支付类型" // @Param vendorPayType formData string true "平台支付类型"
// @Success 200 {object} controllers.CallResult // @Success 200 {object} controllers.CallResult
@@ -387,3 +387,18 @@ func (c *JxOrderController) CreateStoreAcctOrder() {
return retVal, "", err 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
})
}

View File

@@ -763,6 +763,15 @@ func init() {
Filters: nil, Filters: nil,
Params: 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.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JxOrderController"],
web.ControllerComments{ web.ControllerComments{
Method: "GetAvailableDeliverTime", Method: "GetAvailableDeliverTime",