|
|
@@ -1,7 +1,9 @@
|
|
|
package railsadmin_controller
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"fohow.com/apps"
|
|
|
+ "fohow.com/apps/models/balance_model"
|
|
|
"fohow.com/apps/models/user_model"
|
|
|
"github.com/astaxie/beego"
|
|
|
"strconv"
|
|
|
@@ -34,9 +36,68 @@ func (self *RailsadminController) UpdateShopApplication() {
|
|
|
wxUser.ShowInviteMode = int64(1)
|
|
|
wxUser.Rank = int64(2)
|
|
|
wxUser.Save()
|
|
|
-
|
|
|
+ //上线分佣金
|
|
|
+ source := balance_model.SHOP_APPYCATION
|
|
|
+ go ApplySuccessInviterBenefit(wxUser, shopApplication.Id, source)
|
|
|
//更改下级会员群主ID
|
|
|
inviteList := user_model.GetWxUsersByInviteIdAll(wxUser.Id, false)
|
|
|
go user_model.UpdateClass(inviteList, wxUser.Id, wxUser.IntroUserId)
|
|
|
self.ServeJSON()
|
|
|
}
|
|
|
+
|
|
|
+func ApplySuccessInviterBenefit(wxUser *user_model.WxUser, shopId int64, source string) {
|
|
|
+
|
|
|
+ //本人充值4200代金券
|
|
|
+ rId := fmt.Sprintf("shop-apply-%d", shopId)
|
|
|
+ c := balance_model.BALANCE_UPGRADE
|
|
|
+ item := balance_model.GetBalanceBySourceAndRId(source, rId)
|
|
|
+ if item != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ b := new(balance_model.Balance).Create(wxUser.Id, wxUser.UserId, c, source, rId, fmt.Sprintf("¥%0.2f", float64(c)/100))
|
|
|
+ benefitWxUser := GetInviter(wxUser)
|
|
|
+ if b == nil || benefitWxUser == nil || benefitWxUser.Id == int64(1) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //充值成功发放佣金
|
|
|
+ beego.BeeLogger.Warn("shop-apply_benefitWxUser: %s", benefitWxUser)
|
|
|
+ beego.BeeLogger.Warn("shop-apply_newSendInviterBenefit:%v,%v,%s", wxUser, benefitWxUser, shopId)
|
|
|
+ shopApply := user_model.GetShopApplicationById(shopId)
|
|
|
+ if shopApply == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //发放佣金 13800-4500 16800-5000
|
|
|
+ count := int64(0)
|
|
|
+ if shopApply.Total == user_model.TOTAL_RANK1 {
|
|
|
+ count = user_model.PROUD_RANK1
|
|
|
+ } else {
|
|
|
+ count = user_model.PROUD_RANK2
|
|
|
+ }
|
|
|
+
|
|
|
+ remark := fmt.Sprintf("%s%s", wxUser.Nickname, "店长申请成功")
|
|
|
+
|
|
|
+ inviteOrder := new(user_model.InviteOrder).Create(benefitWxUser.Id, wxUser.Id, wxUser.Id, count, shopApply.Total, user_model.SOURCE_SHOP_BENEFIT, rId)
|
|
|
+ s := balance_model.CASH_SOURCE_PRODUCT_BENEFIT
|
|
|
+ cb := balance_model.GetCashBalanceByWxUIdAndRIdAndSource(benefitWxUser.Id, rId, s)
|
|
|
+ if cb == nil {
|
|
|
+ cb = new(balance_model.CashBalance).Create(inviteOrder.BenefitWxUId, count, s, rId, remark)
|
|
|
+ if cb != nil {
|
|
|
+ //标志进账
|
|
|
+ inviteOrder.IsEnterBalance = true
|
|
|
+ inviteOrder.EnterTime = cb.CreatedAt
|
|
|
+ inviteOrder.Save()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func GetInviter(wxUser *user_model.WxUser) *user_model.WxUser {
|
|
|
+ inviter := user_model.GetWxUserById(wxUser.InviteId, false)
|
|
|
+ if inviter == nil {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ if inviter.ShowInviteMode == int64(1) {
|
|
|
+ return inviter
|
|
|
+ } else {
|
|
|
+ return GetInviter(inviter)
|
|
|
+ }
|
|
|
+}
|