Bläddra i källkod

Merge branch 'master' of http://git.hiwavo.com/Fohow/fohow_api

abiao 3 år sedan
förälder
incheckning
0ae1e7a61e

+ 27 - 1
go/gopath/src/fohow.com/apps/controllers/balance_controller/balance_controller.go

@@ -6,6 +6,7 @@ import (
 	"fohow.com/libs/lib_redis"
 	"fohow.com/libs/tool"
 	"github.com/astaxie/beego"
+	"math"
 	"strings"
 
 	// "crypto/md5"
@@ -101,6 +102,25 @@ func (self *BalanceController) GetBalanceDetail() {
 	self.ServeJSON()
 }
 
+//佣金详情
+func (self *BalanceController) GetCashBalanceDetail() {
+	_id := self.Ctx.Input.Param(":id")
+	id, _ := strconv.ParseInt(_id, 10, 64)
+	//uId := self.GetCurrentUserId()
+	wxUId := self.GetCurrentWxUserIdByToken()
+	item := balance_model.GetCashBalanceById(id)
+	if item == nil {
+		self.ReturnError(403, apps.NoExist, "", nil)
+	}
+	if item.WxUId != wxUId {
+		self.ReturnError(403, apps.BalanceNotExist, "", nil)
+	}
+	item.CTime = item.CreatedAt.Unix()
+	item.SourceName = item.GetSourceName()
+	self.Data["json"] = item
+	self.ServeJSON()
+}
+
 //现金账户变动列表
 func (self *BalanceController) GetCashBalanceList() {
 	page, _ := self.GetInt64("page", 1)
@@ -204,6 +224,10 @@ func (self *BalanceController) TakeCash() {
 	takeCashLock.Lock()
 	defer takeCashLock.Unlock()
 
+	//处理提现手续费
+	feeTotal := float64(amount) * (float64(sys_config.GetTakeCashTax())) / float64(100)
+	fee := int64(math.Floor(feeTotal + 0.5))
+
 	o := new(balance_model.TakeCashOrder).Create(wxUser.Id, amount)
 	if o != nil {
 		new(balance_model.CashBalance).Create(wxUser.Id, -amount, balance_model.CASH_SOURCE_TAKE_CASH,
@@ -213,6 +237,8 @@ func (self *BalanceController) TakeCash() {
 		o.AccountName = user.AccountName
 		o.BankAccount = user.BankAccount
 		o.BankName = user.BankName
+		o.Fee = fee
+		o.Count = amount - fee //实际提现金额扣取手续费
 		o.Save()
 	}
 	//提现成功加入提现处理队列
@@ -234,7 +260,7 @@ func (self *BalanceController) GetTakeCashLimit() {
 	limitInfo := new(LimitInfo)
 	limitInfo.MaxLimitCash = TAKE_CASH_AMOUNT_LIMIT_MAX
 	limitInfo.MinLimitCash = TAKE_CASH_AMOUNT_LIMIT_MIN
-	limitInfo.FeeBl = int64(0)
+	limitInfo.FeeBl = sys_config.GetTakeCashTax()
 
 	if beego.AppConfig.String("RunMode") == "dev" {
 		limitInfo.MinLimitCash = 1

+ 13 - 1
go/gopath/src/fohow.com/apps/models/balance_model/cash_balance.go

@@ -95,7 +95,7 @@ type CashBalance struct {
 	SourceName string    `orm:"-"                                 json:"source_name"`                 // varchar(64)
 	RelateId   string    `orm:"column(relate_id);null"                              json:"relate_id"` // varchar(255)
 	Remark     string    `orm:"column(remark);null"                                 json:"remark"`    // varchar(255)
-	CTime      int64     `orm:"-"                                       json:"c_time"`                // int(11)
+	CTime      int64     `orm:"-"                                       json:"ctime"`                 // int(11)
 	CreatedAt  time.Time `orm:"column(created_at);null;auto_now_add;type(datetime)" json:"-"`         // datetime
 	UpdatedAt  time.Time `orm:"column(updated_at);null;auto_now;type(datetime)"     json:"-"`         // datetime
 }
@@ -400,3 +400,15 @@ func GetCashToBalanceCountByWxUId(wxUId int64, s string) int64 {
 	count, _ := o.QueryTable(item).Filter("wx_uid", wxUId).Filter("source", s).Count()
 	return count
 }
+
+func GetCashBalanceById(id int64) *CashBalance {
+	item := &CashBalance{}
+	if err := orm.NewOrm().QueryTable(item).
+		Filter("id", id).Limit(1).
+		One(item); err != nil {
+		beego.BeeLogger.Debug("GetCashBalanceById(%s), err=%s",
+			id, err)
+		return nil
+	}
+	return item
+}

+ 1 - 0
go/gopath/src/fohow.com/apps/models/balance_model/takecash.go

@@ -32,6 +32,7 @@ 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)
+	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)
 	AuditState int64     `orm:"column(audit_state);null"                            json:"audit_state"`  // tinyint(1)

+ 16 - 0
go/gopath/src/fohow.com/apps/models/sys_config/sys_config.go

@@ -26,6 +26,7 @@ const (
 	SHUT_WECHAT           = "SHUT_WECHAT"
 	CODE_FOHOW_OUBIAO     = "oubiao"
 	CODE_FOHOW            = "fohow"
+	TAKECASH_TAX          = "TAKECASH_TAX"
 	sys_configs_tablename = "sys_configs"
 	pay_configs_tablename = "pay_configs"
 )
@@ -284,3 +285,18 @@ func GetShutWechatPromotion() bool {
 	}
 	return false
 }
+
+//获取提现手续费
+func GetTakeCashTax() int64 {
+	SysConfig := &SysConfig{}
+	if err := orm.NewOrm().QueryTable(SysConfig).Filter("code", TAKECASH_TAX).Limit(1).One(SysConfig); err != nil {
+		beego.BeeLogger.Error("get SysConfig by  err=%s", err)
+		SysConfig = nil
+		return int64(0)
+	}
+	value, err := strconv.ParseInt(SysConfig.CodeValue, 10, 64)
+	if err != nil {
+		return int64(0)
+	}
+	return value
+}

+ 6 - 2
go/gopath/src/fohow.com/routers/routes.go

@@ -201,10 +201,14 @@ func init() {
 	beego.Router("/v1/user/balance/:id([0-9]+)", &balance_controller.BalanceController{}, "get:GetBalanceDetail")
 	//提货券账户余额
 	beego.Router("/v1/user/balance/info", &balance_controller.BalanceController{}, "get:GetBalanceInfo")
-	//现金账户变动列表
+
+	//佣金账户变动列表
 	beego.Router("/v1/user/cash/balances", &balance_controller.BalanceController{}, "get:GetCashBalanceList")
-	//金账户余额
+	//金账户余额
 	beego.Router("/v1/user/cash/balance/info", &balance_controller.BalanceController{}, "get:GetCashBalanceInfo")
+	//佣金账户变更详情
+	beego.Router("/v1/user/cash/balance/:id([0-9]+)", &balance_controller.BalanceController{}, "get:GetCashBalanceDetail")
+
 	//提现
 	beego.Router("/v1/user/takecash", &balance_controller.BalanceController{}, "post:TakeCash")
 	//提现流