Explorar o código

充值免收手续费

abiao %!s(int64=2) %!d(string=hai) anos
pai
achega
a6c3376947

+ 28 - 13
go/gopath/src/fohow.com/apps/controllers/balance_controller/balance_controller.go

@@ -32,7 +32,7 @@ const (
 	WX_TAKE_CASH_AMOUNT_LIMIT_MAX = 20000   //5000元
 )
 
-//提货券和提货券余额
+// 提货券和提货券余额
 func (self *BalanceController) GetBalanceInfo() {
 	type BalanceInfo struct {
 		Total          int64 `orm:"-" json:"total"`            //余额,单位分
@@ -56,7 +56,7 @@ func (self *BalanceController) GetBalanceInfo() {
 	self.ServeJSON()
 }
 
-//提货券变动列表
+// 提货券变动列表
 func (self *BalanceController) GetBalanceList() {
 	page, _ := self.GetInt64("page", 1)
 	perPage, _ := self.GetInt64("per_page", 20)
@@ -83,7 +83,7 @@ func (self *BalanceController) GetBalanceList() {
 	self.ServeJSON()
 }
 
-//资金详情
+// 资金详情
 func (self *BalanceController) GetBalanceDetail() {
 	_id := self.Ctx.Input.Param(":id")
 	id, _ := strconv.ParseInt(_id, 10, 64)
@@ -102,7 +102,7 @@ func (self *BalanceController) GetBalanceDetail() {
 	self.ServeJSON()
 }
 
-//佣金详情
+// 佣金详情
 func (self *BalanceController) GetCashBalanceDetail() {
 	_id := self.Ctx.Input.Param(":id")
 	id, _ := strconv.ParseInt(_id, 10, 64)
@@ -121,7 +121,7 @@ func (self *BalanceController) GetCashBalanceDetail() {
 	self.ServeJSON()
 }
 
-//现金账户变动列表
+// 现金账户变动列表
 func (self *BalanceController) GetCashBalanceList() {
 	page, _ := self.GetInt64("page", 1)
 	perPage, _ := self.GetInt64("per_page", 20)
@@ -150,7 +150,7 @@ func (self *BalanceController) GetCashBalanceList() {
 	self.ServeJSON()
 }
 
-//现金账户信息
+// 现金账户信息
 func (self *BalanceController) GetCashBalanceInfo() {
 	type BalanceInfo struct {
 		Available   int64 `orm:"-" json:"available"`    //对应页面上可提现余额,单位分,进账+出账
@@ -213,24 +213,39 @@ func (self *BalanceController) TakeCash() {
 	}
 
 	canExtract := balance_model.GetCashTotalBalance(wxUser.Id)
-
+	freeFeiCashLimit := balance_model.GetRechargeBalance(wxUser.Id)
+	usedLimit := balance_model.GetTakeFeeBalance(wxUser.Id)
+	freeFeiCash := freeFeiCashLimit - usedLimit
 	//余额不足
+
 	if canExtract < amount {
 		self.ReturnError(403, apps.BalanceNotEnough, "", nil)
 	}
+
 	//超过微信余额限制5K,按5K计算
 	if amount > WX_TAKE_CASH_AMOUNT_LIMIT_MAX {
 		amount = WX_TAKE_CASH_AMOUNT_LIMIT_MAX
 	}
 
+	freeAmount := int64(0)
+	feeAmount := int64(0) //假如提现 100,免额 50
+	if freeFeiCash > 0 {
+		if freeFeiCash < amount {
+			freeAmount = freeFeiCash         // 用掉的额度
+			feeAmount = amount - freeFeiCash // 收费的部份
+		} else {
+			freeAmount = amount //用掉的额度
+		}
+	}
+
 	takeCashLock.Lock()
 	defer takeCashLock.Unlock()
 
 	//处理提现手续费
-	feeTotal := float64(amount) * (float64(sys_config.GetTakeCashTax())) / float64(100)
+	feeTotal := float64(feeAmount) * (float64(sys_config.GetTakeCashTax())) / float64(100)
 	fee := int64(math.Floor(feeTotal + 0.5))
 
-	o := new(balance_model.TakeCashOrder).Create(wxUser.Id, amount)
+	o := new(balance_model.TakeCashOrder).Create(wxUser.Id, amount, feeAmount, freeAmount)
 	if o != nil {
 		new(balance_model.CashBalance).Create(wxUser.Id, -amount, balance_model.CASH_SOURCE_TAKE_CASH,
 			o.OrderId, balance_model.CASH_SOURCE_TAKE_CASH_NAME)
@@ -252,7 +267,7 @@ func (self *BalanceController) TakeCash() {
 	self.ServeJSON()
 }
 
-//获取提现限额
+// 获取提现限额
 func (self *BalanceController) GetTakeCashLimit() {
 	type LimitInfo struct {
 		MinLimitCash int64 `json:"min_limit_cash"` //提现限额
@@ -272,7 +287,7 @@ func (self *BalanceController) GetTakeCashLimit() {
 	self.ServeJSON()
 }
 
-//提现流列表
+// 提现流列表
 func (self *BalanceController) GetTakeCashOrders() {
 
 	page, _ := self.GetInt64("page", 1)
@@ -329,7 +344,7 @@ func (self *BalanceController) GetTakeCashOrders() {
 	self.ServeJSON()
 }
 
-//佣金转提货券
+// 佣金转提货券
 func (self *BalanceController) TransferToBalance() {
 	//单位:分
 	amount, _ := self.GetInt64("amount")
@@ -389,7 +404,7 @@ func (self *BalanceController) TransferToBalance() {
 	self.ServeJSON()
 }
 
-//现金账户变动列表
+// 现金账户变动列表
 func (self *BalanceController) GetCashToBalanceList() {
 	page, _ := self.GetInt64("page", 1)
 	perPage, _ := self.GetInt64("per_page", 20)

+ 20 - 0
go/gopath/src/fohow.com/apps/models/balance_model/cash_balance.go

@@ -303,6 +303,26 @@ func GetCashTotalBalance(wxUId int64) int64 {
 	return ret.Count
 }
 
+// 充值账户余额
+func GetRechargeBalance(wxUId int64) int64 {
+	type Ret struct {
+		Count int64
+	}
+	ret := &Ret{}
+	o := orm.NewOrm()
+	tbn := new(CashBalance).TableName()
+	sql := fmt.Sprintf("SELECT sum(`count`) as count FROM `%s` WHERE wx_uid=? and created_at >='2023-10-01 00:00:00' and source in('?','?','?');", tbn)
+	err := o.Raw(sql, wxUId, CASH_SOURCE_RECHARGE_CASH, ORDER_FOOD, CANCEL_FOOD).QueryRow(ret)
+	if err != nil {
+		beego.BeeLogger.Error("GetRechargeBalance, wxUser:%d err=[%s]", wxUId, err)
+		return 0
+	}
+	if ret.Count < 0 {
+		return 0
+	}
+	return ret.Count
+}
+
 func GetCashBalanceByWxUIdAndRIdAndSource(wxUId int64, rId, source string) *CashBalance {
 	item := &CashBalance{}
 	if err := orm.NewOrm().QueryTable(item).

+ 29 - 5
go/gopath/src/fohow.com/apps/models/balance_model/takecash.go

@@ -32,6 +32,8 @@ type TakeCashOrder struct {
 	OrderId    string    `orm:"column(order_id)"                                    json:"order_id"`     // varchar(64)
 	TradeNo    string    `orm:"column(trade_no);null"                               json:"trade_no"`     // varchar(64)
 	Count      int64     `orm:"column(count);null"                                  json:"count"`        // bigint(20)
+	FeiCount   int64     `orm:"column(fei_count)"                                   json:"fei_count"`    // int(11)
+	FreeCount  int64     `orm:"column(free_count)"                                  json:"free_count"`   // int(11)
 	Fee        int64     `orm:"column(fee);null"                                    json:"fee"`          // bigint(20)
 	State      int64     `orm:"column(pay_state);null"                              json:"pay_state"`    // tinyint(1)
 	RealState  int64     `orm:"column(real_state);null"                              json:"-"`           // tinyint(1)
@@ -51,10 +53,12 @@ func (self *TakeCashOrder) TableName() string {
 	return take_cash_orders_tablename
 }
 
-func (self *TakeCashOrder) Create(wxUId, count int64) (item *TakeCashOrder) {
+func (self *TakeCashOrder) Create(wxUId, count, feiCount, freeCount int64) (item *TakeCashOrder) {
 	oId := createOrderId(ORDER_ID_PREFIX_TX)
 	item = &TakeCashOrder{
 		Count:     count,
+		FeiCount:  feiCount,
+		FreeCount: freeCount,
 		WxUId:     wxUId,
 		OrderId:   oId,
 		RealState: REAL_STATE,
@@ -77,7 +81,7 @@ func (self *TakeCashOrder) Save() error {
 	return nil
 }
 
-//状态值中文
+// 状态值中文
 func (self *TakeCashOrder) GetStateCn() string {
 	stateCn := ""
 	switch self.State {
@@ -142,7 +146,7 @@ func GetTakeCashOrderById(id int64, useCache bool) *TakeCashOrder {
 	}
 }
 
-//获取某人的提现流列表
+// 获取某人的提现流列表
 func GetTakeCashOrderListByWxUId(wxUId, page, perPage int64, useCache bool) (list []*TakeCashOrder) {
 	k := fmt.Sprintf("balance_model.GetTakeCashOrderListByWxUId.wxUId(%d).page(%d).perPage(%d)", wxUId, page, perPage)
 	if useCache {
@@ -165,7 +169,7 @@ func GetTakeCashOrderListByWxUId(wxUId, page, perPage int64, useCache bool) (lis
 	return list
 }
 
-//获取某人的提现流列表总条数
+// 获取某人的提现流列表总条数
 func GetTakeCashOrderCountByWxUId(wxUId int64, useCache bool) int64 {
 
 	k := fmt.Sprintf("balance_model.GetTakeCashOrderCountByWxUId.wxUId(%d)", wxUId)
@@ -224,7 +228,7 @@ func GetTakeCashOrderListByWxUIdAndTime(wxUId int64, now time.Time, useCache boo
 
 }
 
-//取正在提现的订单列表
+// 取正在提现的订单列表
 func GetAllTakingCashOrders() (list []*TakeCashOrder) {
 	sql := fmt.Sprintf("select * from %s where pay_state=? and audit_state=? and expc_pay_at < ?", take_cash_orders_tablename)
 	if _, err := orm.NewOrm().Raw(sql, 0, 1, time.Now().Add(-8*time.Hour)).QueryRows(&list); err != nil {
@@ -232,3 +236,23 @@ func GetAllTakingCashOrders() (list []*TakeCashOrder) {
 	}
 	return list
 }
+
+// 充值账户余额
+func GetTakeFeeBalance(wxUId int64) int64 {
+	type Ret struct {
+		Count int64
+	}
+	ret := &Ret{}
+	o := orm.NewOrm()
+	tbn := new(TakeCashOrder).TableName()
+	sql := fmt.Sprintf("SELECT sum(`free_count`) as count FROM `%s` WHERE wx_uid=?;", tbn)
+	err := o.Raw(sql, wxUId).QueryRow(ret)
+	if err != nil {
+		beego.BeeLogger.Error("GetTakeFeeBalance, wxUser:%d err=[%s]", wxUId, err)
+		return 0
+	}
+	if ret.Count < 0 {
+		return 0
+	}
+	return ret.Count
+}