|
|
@@ -2,14 +2,9 @@ package railsadmin_controller
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
- "fohow.com/apps"
|
|
|
"fohow.com/apps/helpers"
|
|
|
- "fohow.com/apps/models/granary_model"
|
|
|
- "fohow.com/apps/models/product_model"
|
|
|
"fohow.com/apps/models/push_tmpl_model"
|
|
|
- "fohow.com/apps/models/subject_model"
|
|
|
"fohow.com/apps/models/user_model"
|
|
|
- "fohow.com/libs/tool"
|
|
|
"fohow.com/libs/wx_mp"
|
|
|
"github.com/astaxie/beego"
|
|
|
"strconv"
|
|
|
@@ -17,51 +12,6 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-//销售专题开奖发送消息
|
|
|
-func (self *RailsadminController) SendOpenPrizeTmpl() {
|
|
|
-
|
|
|
- id, _ := strconv.ParseInt(self.Ctx.Input.Param(":id"), 10, 64)
|
|
|
-
|
|
|
- saleSubject := subject_model.GetProductSaleSubjectById(id, false)
|
|
|
-
|
|
|
- awardedList := subject_model.GetSaleDrawCodeIsAwardedList(id, false)
|
|
|
-
|
|
|
- beego.BeeLogger.Warn("SendOpenPrizeTmpl:%d", saleSubject.Id)
|
|
|
- if saleSubject == nil || !saleSubject.IsPrizeAct || time.Now().Unix() < saleSubject.OpenPrizeTime.Unix() || saleSubject.PrizeNumber == "" || len(awardedList) == 0 {
|
|
|
- self.ReturnError(403, apps.NoExist, "", nil)
|
|
|
- }
|
|
|
-
|
|
|
- joinList := subject_model.GetSaleDrawCodeAllBySubjectId(id, false)
|
|
|
-
|
|
|
- awardedcount := subject_model.GetSaleDrawCodeIsAdwardedCount(id, false)
|
|
|
-
|
|
|
- for _, join := range joinList {
|
|
|
- wxUserGzh := user_model.GetWxUserGzhByWxUIdAndAppId(join.WxUserId, beego.AppConfig.String("WxMPAppId"), true)
|
|
|
- url := fmt.Sprintf("%s/activity/project/%d", beego.AppConfig.String("WxHost"), id)
|
|
|
- title := "开奖啦!再接再厉~ 你与大奖就差一根头发的距离!"
|
|
|
- remark := "备注:别灰心~ 敬请期待下一期。"
|
|
|
- for _, awarded := range awardedList {
|
|
|
- if awarded.WxUserId == join.WxUserId {
|
|
|
- title = fmt.Sprintf("恭喜你!你被大奖%s砸到了!", saleSubject.PrizeName)
|
|
|
- remark = "备注:奖品将在5个工作日内寄出。请登录小程序查询物流状态,谢谢!"
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- name := fmt.Sprintf("第%d期", saleSubject.Id)
|
|
|
- openTime := saleSubject.OpenPrizeTime.Format("2006-01-02 15:04:05")
|
|
|
-
|
|
|
- var codeList []string
|
|
|
- codes := subject_model.GetSaleDrawCodesBySubjectIdAndWxUid(id, join.WxUserId, true)
|
|
|
- for _, code := range codes {
|
|
|
- codeList = append(codeList, tool.GetAssignLengthStr(code.Code, 6))
|
|
|
- }
|
|
|
- wx_mp.TmplmsgOpenPrize(wxUserGzh.GzhOpenId, url, title, name, openTime, fmt.Sprintf("%d", awardedcount), strings.Join(codeList, ","), saleSubject.PrizeNumber, remark)
|
|
|
- }
|
|
|
-
|
|
|
- // self.Data["json"] = pcms
|
|
|
- self.ServeJSON()
|
|
|
-}
|
|
|
-
|
|
|
// 推送模板消息给指定的用户
|
|
|
func (self *RailsadminController) SendTemplate() {
|
|
|
id, _ := strconv.ParseInt(self.Ctx.Input.Param(":id"), 10, 64)
|
|
|
@@ -257,175 +207,3 @@ func getWxUsersBySql(key string) (list []*user_model.WxUser) {
|
|
|
}
|
|
|
return list
|
|
|
}
|
|
|
-
|
|
|
-// 粮仓单独推送自用消息,先小程序通知,失败则公众号消息
|
|
|
-func (self *RailsadminController) NonAutoNoticeSelfUseByGranaryId() {
|
|
|
-
|
|
|
- _id := self.Ctx.Input.Param(":id")
|
|
|
- id, _ := strconv.ParseInt(_id, 10, 64)
|
|
|
- useCache, _ := self.GetBool("cache")
|
|
|
- granary := granary_model.GetGranaryById(id, useCache)
|
|
|
- wxUser := user_model.GetWxUserByUserId(granary.UserId, useCache)
|
|
|
- if wxUser == nil {
|
|
|
- self.ServeJSON()
|
|
|
- self.StopRun()
|
|
|
- }
|
|
|
- var tmpl *push_tmpl_model.XcxPushTmpl
|
|
|
- if beego.BConfig.RunMode == beego.DEV {
|
|
|
- tmpl = push_tmpl_model.GetXcxPushTmplById(3)
|
|
|
- } else {
|
|
|
- tmpl = push_tmpl_model.GetXcxPushTmplById(5)
|
|
|
- }
|
|
|
- if tmpl == nil {
|
|
|
- self.ServeJSON()
|
|
|
- self.StopRun()
|
|
|
- }
|
|
|
- product := product_model.GetProductById(granary.ProductId, useCache)
|
|
|
- if product == nil {
|
|
|
- self.ServeJSON()
|
|
|
- self.StopRun()
|
|
|
- }
|
|
|
- //粮仓剩余自用份数
|
|
|
- zyCount := granary.SelfUseMin - granary.SelfUseCount
|
|
|
- if zyCount <= 0 {
|
|
|
- self.ServeJSON()
|
|
|
- self.StopRun()
|
|
|
- }
|
|
|
-
|
|
|
- var remark string
|
|
|
- kw2 := fmt.Sprintf("自用")
|
|
|
- page := fmt.Sprintf("pages/start/start?url=packageUser/pages/user/granary/granary")
|
|
|
- emphasisKw := tmpl.EmphasisKw
|
|
|
- if tmpl.EmphasisKw == "-" {
|
|
|
- emphasisKw = ""
|
|
|
- }
|
|
|
- if tmpl.PushForce == 1 {
|
|
|
- remark = tmpl.Keyword3
|
|
|
- } else {
|
|
|
- remark = fmt.Sprintf("您还有%d份商品未提货自用,请在规定时间内填写地址邮寄自用。", zyCount)
|
|
|
- }
|
|
|
- isSuccess := helpers.DeliveryNotify(*wxUser, product.Name, kw2, remark, emphasisKw, page)
|
|
|
- if !isSuccess {
|
|
|
- gzhTmpl := push_tmpl_model.GetPushTmplById(5)
|
|
|
- if gzhTmpl == nil {
|
|
|
- self.ServeJSON()
|
|
|
- self.StopRun()
|
|
|
- }
|
|
|
- if gzhTmpl.PushForce == 1 {
|
|
|
- remark = gzhTmpl.Remark
|
|
|
- } else {
|
|
|
- remark = fmt.Sprintf("请在规定时间内填写地址邮寄自用,点击前往。")
|
|
|
- }
|
|
|
- url := fmt.Sprintf("https://api.labitumall.com/v1/cfc/43")
|
|
|
- first := fmt.Sprintf("提货方式:自用")
|
|
|
- kw1 := fmt.Sprintf("FOHOW玖玖")
|
|
|
- kw2 := product.Name
|
|
|
- kw3 := fmt.Sprintf("您还有%d份未提货自用", zyCount)
|
|
|
- kw4 := fmt.Sprintf("共收成%d份", granary.TotalCount)
|
|
|
- kw5 := fmt.Sprintf("从%s开始", granary.CreatedAt.Format("2006年01月02日"))
|
|
|
- uGzh := user_model.GetWxUserGzhByWxUIdAndAppId(wxUser.Id, beego.AppConfig.String("WxMPAppId"), false)
|
|
|
- err := wx_mp.TmplmsgEventPickUpNotifyHandle(uGzh.GzhOpenId, url, first, kw1, kw2, kw3, kw4, kw5, remark)
|
|
|
- if err == nil {
|
|
|
- granary.LastZyRemindAt = time.Now().Unix()
|
|
|
- granary.Save()
|
|
|
- }
|
|
|
- } else {
|
|
|
- granary.LastZyRemindAt = time.Now().Unix()
|
|
|
- granary.Save()
|
|
|
- }
|
|
|
-
|
|
|
- self.ServeJSON()
|
|
|
-}
|
|
|
-
|
|
|
-// 粮仓单独推送挂单消息,先小程序通知,失败则公众号消息
|
|
|
-func (self *RailsadminController) NonAutoNoticeApplyForSaleByGranaryId() {
|
|
|
- _id := self.Ctx.Input.Param(":id")
|
|
|
- id, _ := strconv.ParseInt(_id, 10, 64)
|
|
|
- useCache, _ := self.GetBool("cache")
|
|
|
- granary := granary_model.GetGranaryById(id, useCache)
|
|
|
- wxUser := user_model.GetWxUserByUserId(granary.UserId, useCache)
|
|
|
- if wxUser == nil {
|
|
|
- self.ServeJSON()
|
|
|
- self.StopRun()
|
|
|
- }
|
|
|
- var tmpl *push_tmpl_model.XcxPushTmpl
|
|
|
- if beego.BConfig.RunMode == beego.DEV {
|
|
|
- tmpl = push_tmpl_model.GetXcxPushTmplById(4)
|
|
|
- } else {
|
|
|
- tmpl = push_tmpl_model.GetXcxPushTmplById(6)
|
|
|
- }
|
|
|
- if tmpl == nil {
|
|
|
- self.ServeJSON()
|
|
|
- self.StopRun()
|
|
|
- }
|
|
|
- product := product_model.GetProductById(granary.ProductId, useCache)
|
|
|
- if product == nil {
|
|
|
- self.ServeJSON()
|
|
|
- self.StopRun()
|
|
|
- }
|
|
|
- selfUse := int64(0)
|
|
|
- if granary.SelfUseCount > granary.SelfUseMin {
|
|
|
- selfUse = granary.SelfUseCount
|
|
|
- } else {
|
|
|
- selfUse = granary.SelfUseMin
|
|
|
- }
|
|
|
- //粮仓剩余可挂单份数
|
|
|
- gdCount := granary.TotalCount - selfUse - granary.BuybackCount
|
|
|
- saleOrder := granary_model.GetSaleOrderByGId(id, false)
|
|
|
- //如果有代销订单,减除代销订单的数量
|
|
|
- if saleOrder != nil {
|
|
|
- if saleOrder.State == granary_model.ORDER_STATE_ONLINE ||
|
|
|
- saleOrder.State == granary_model.ORDER_STATE_SELL_UP {
|
|
|
- gdCount = gdCount - saleOrder.TotalCount
|
|
|
- } else {
|
|
|
- gdCount = gdCount - granary.SoldCount
|
|
|
- }
|
|
|
- }
|
|
|
- if gdCount <= 0 {
|
|
|
- self.ServeJSON()
|
|
|
- self.StopRun()
|
|
|
- }
|
|
|
- var remark string
|
|
|
- kw2 := fmt.Sprintf("挂单代销")
|
|
|
- page := fmt.Sprintf("pages/start/start?url=packageUser/pages/user/granary/granary")
|
|
|
- emphasisKw := tmpl.EmphasisKw
|
|
|
- if tmpl.EmphasisKw == "-" {
|
|
|
- emphasisKw = ""
|
|
|
- }
|
|
|
- if tmpl.PushForce == 1 {
|
|
|
- remark = tmpl.Keyword3
|
|
|
- } else {
|
|
|
- remark = fmt.Sprintf("您还有%d份商品未挂单代销,请及时到会员中心-我的粮仓配置挂单数量,平台才会帮您进行代销售。", gdCount)
|
|
|
- }
|
|
|
- isSuccess := helpers.DeliveryNotify(*wxUser, product.Name, kw2, remark, emphasisKw, page)
|
|
|
- if !isSuccess {
|
|
|
- gzhTmpl := push_tmpl_model.GetPushTmplById(6)
|
|
|
- if gzhTmpl == nil {
|
|
|
- self.ServeJSON()
|
|
|
- self.StopRun()
|
|
|
- }
|
|
|
- if gzhTmpl.PushForce == 1 {
|
|
|
- remark = gzhTmpl.Remark
|
|
|
- } else {
|
|
|
- remark = fmt.Sprintf("请及时到会员中心-我的粮仓配置挂单数量,平台才会帮您进行代销售。")
|
|
|
- }
|
|
|
- url := fmt.Sprintf("https://api.labitumall.com/v1/cfc/43")
|
|
|
- first := fmt.Sprintf("提货方式:挂单代销")
|
|
|
- kw1 := fmt.Sprintf("FOHOW玖玖")
|
|
|
- kw2 := product.Name
|
|
|
- kw3 := fmt.Sprintf("您还有%d份未挂单代销", gdCount)
|
|
|
- kw4 := fmt.Sprintf("共收成%d份", granary.TotalCount)
|
|
|
- kw5 := fmt.Sprintf("从%s开始", granary.CreatedAt.Format("2006年01月02日"))
|
|
|
- uGzh := user_model.GetWxUserGzhByWxUIdAndAppId(wxUser.Id, beego.AppConfig.String("WxMPAppId"), false)
|
|
|
- err := wx_mp.TmplmsgEventPickUpNotifyHandle(uGzh.GzhOpenId, url, first, kw1, kw2, kw3, kw4, kw5, remark)
|
|
|
- if err == nil {
|
|
|
- granary.LastGdRemindAt = time.Now().Unix()
|
|
|
- granary.Save()
|
|
|
- }
|
|
|
- } else {
|
|
|
- granary.LastGdRemindAt = time.Now().Unix()
|
|
|
- granary.Save()
|
|
|
- }
|
|
|
-
|
|
|
- self.ServeJSON()
|
|
|
-}
|