|
@@ -1,6 +1,7 @@
|
|
|
package balance_controller
|
|
package balance_controller
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "fmt"
|
|
|
"github.com/astaxie/beego"
|
|
"github.com/astaxie/beego"
|
|
|
|
|
|
|
|
// "crypto/md5"
|
|
// "crypto/md5"
|
|
@@ -278,3 +279,84 @@ func (self *BalanceController) GetTakeCashOrders() {
|
|
|
self.Data["json"] = &Ret{ListCount: listCount, List: retList}
|
|
self.Data["json"] = &Ret{ListCount: listCount, List: retList}
|
|
|
self.ServeJSON()
|
|
self.ServeJSON()
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+//佣金转代金券
|
|
|
|
|
+func (self *BalanceController) TransferToBalance() {
|
|
|
|
|
+ //单位:分
|
|
|
|
|
+ amount, _ := self.GetInt64("amount")
|
|
|
|
|
+ useCache, _ := self.GetBool("cache", false)
|
|
|
|
|
+ wxUser := user_model.GetWxUserByUserId(27139, useCache)
|
|
|
|
|
+
|
|
|
|
|
+ //wxUser := self.GetCurrentWxUser(useCache)
|
|
|
|
|
+ //beego.BeeLogger.Warn("wxUser: %s", wxUser)
|
|
|
|
|
+
|
|
|
|
|
+ if wxUser == nil {
|
|
|
|
|
+ self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if amount <= 0 {
|
|
|
|
|
+ self.ReturnError(403, apps.TakeCashAmountInvalid, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ canExtract := balance_model.GetCashTotalBalance(wxUser.Id)
|
|
|
|
|
+
|
|
|
|
|
+ //余额不足
|
|
|
|
|
+ if canExtract < amount {
|
|
|
|
|
+ self.ReturnError(403, apps.BalanceNotEnough, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+ result := true
|
|
|
|
|
+ //remark:= fmt.Sprintf("%s%d", "佣金转余额", amount)
|
|
|
|
|
+ remark := "佣金转代金券"
|
|
|
|
|
+ source := balance_model.CASH_TO_BALANCE
|
|
|
|
|
+
|
|
|
|
|
+ //先扣余额
|
|
|
|
|
+ order := new(balance_model.CashBalance).Create(wxUser.Id, -amount, source,
|
|
|
|
|
+ "cash_balance", remark)
|
|
|
|
|
+
|
|
|
|
|
+ //增加代金券金额
|
|
|
|
|
+ if order != nil {
|
|
|
|
|
+ total := amount * int64(2)
|
|
|
|
|
+ oId := fmt.Sprintf("%d", order.Id)
|
|
|
|
|
+ new(balance_model.Balance).Create(wxUser.Id, wxUser.UserId, total, source, oId, remark)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ self.ReturnError(403, apps.BalanceToCashErr, "", nil)
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ type Ret struct {
|
|
|
|
|
+ State bool `json:"state"`
|
|
|
|
|
+ }
|
|
|
|
|
+ self.Data["json"] = &Ret{State: result}
|
|
|
|
|
+ self.ServeJSON()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+//现金账户变动列表
|
|
|
|
|
+func (self *BalanceController) GetCashToBalanceList() {
|
|
|
|
|
+ page, _ := self.GetInt64("page", 1)
|
|
|
|
|
+ perPage, _ := self.GetInt64("per_page", 20)
|
|
|
|
|
+ if perPage <= 0 || perPage > 100 {
|
|
|
|
|
+ perPage = 20
|
|
|
|
|
+ }
|
|
|
|
|
+ cache, _ := self.GetBool("cache", false)
|
|
|
|
|
+
|
|
|
|
|
+ //wxUser := self.GetCurrentWxUser(cache)
|
|
|
|
|
+ wxUser := user_model.GetWxUserById(27139, true)
|
|
|
|
|
+ if wxUser == nil {
|
|
|
|
|
+ self.ReturnError(403, apps.UserNeedLogin, "", nil)
|
|
|
|
|
+ }
|
|
|
|
|
+ source := balance_model.CASH_TO_BALANCE
|
|
|
|
|
+
|
|
|
|
|
+ list := balance_model.GetCasTohBalanceListByWxUId(wxUser.Id, page, perPage, source, cache)
|
|
|
|
|
+ count := balance_model.GetCashToBalanceCountByWxUId(wxUser.Id, source)
|
|
|
|
|
+ type BalanceInfo struct {
|
|
|
|
|
+ BalanceList []*balance_model.CashBalance `orm:"-" json:"balance_list"`
|
|
|
|
|
+ BalanceCount int64 `orm:"-" json:"balance_count"`
|
|
|
|
|
+ }
|
|
|
|
|
+ for _, item := range list {
|
|
|
|
|
+ // item.SourceName = item.GetSourceName()
|
|
|
|
|
+ item.CTime = item.CreatedAt.Unix()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ self.Data["json"] = &BalanceInfo{BalanceList: list, BalanceCount: count}
|
|
|
|
|
+ self.ServeJSON()
|
|
|
|
|
+}
|