826 lines
26 KiB
Go
826 lines
26 KiB
Go
package cooperativemanage
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"github.com/codinl/go-logger"
|
|
"github.com/gin-gonic/gin"
|
|
"go-admin/app/admin/models"
|
|
orm "go-admin/common/global"
|
|
"go-admin/pkg/jwtauth"
|
|
"go-admin/tools/app"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
func CooperativeBusinessList(c *gin.Context) {
|
|
req := &models.CooperativeBusinessListReq{}
|
|
if c.ShouldBindJSON(req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
list, count, err := req.List()
|
|
if err != nil {
|
|
logger.Errorf("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
|
|
ret := map[string]interface{}{
|
|
"count": count,
|
|
"list": list,
|
|
"pageIndex": req.Page,
|
|
"total_page": req.PageSize,
|
|
}
|
|
app.OK(c, ret, "")
|
|
return
|
|
}
|
|
|
|
type CooperativeMemberDeductReq struct {
|
|
CooperativeBusinessId uint32 `json:"cooperative_business_id" binding:"required"`
|
|
GoldDeduct uint32 `json:"gold_deduct" binding:"required"` // 黄金会员提成
|
|
PlatinumDeduct uint32 `json:"platinum_deduct" binding:"required"` // 白金会员提成
|
|
BlackGoldDeduct uint32 `json:"black_gold_deduct" binding:"required"` // 黑金金会员提成
|
|
// cooperative_member_deduct
|
|
}
|
|
|
|
func CooperativeAdd(c *gin.Context) {
|
|
req := &models.CooperativeBusiness{}
|
|
if err := c.ShouldBindJSON(req); err != nil {
|
|
logger.Error("para err", err)
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
req.AddTime = time.Now()
|
|
err := orm.Eloquent.Create(req).Error
|
|
if err != nil {
|
|
logger.Errorf("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "添加失败")
|
|
return
|
|
}
|
|
deduct := &models.CooperativeMemberDeduct{
|
|
CooperativeBusinessId: req.ID,
|
|
GoldDeduct: req.CooperativeMemberDeduct.GoldDeduct,
|
|
PlatinumDeduct: req.CooperativeMemberDeduct.PlatinumDeduct,
|
|
BlackGoldDeduct: req.CooperativeMemberDeduct.BlackGoldDeduct,
|
|
RenewalGoldDeduct: req.CooperativeMemberDeduct.RenewalGoldDeduct,
|
|
RenewalPlatinumDeduct: req.CooperativeMemberDeduct.RenewalPlatinumDeduct,
|
|
RenewalBlackGoldDeduct: req.CooperativeMemberDeduct.RenewalBlackGoldDeduct,
|
|
}
|
|
err = orm.Eloquent.Create(deduct).Error
|
|
if err != nil {
|
|
logger.Error("create cooperative member deduct err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "添加失败")
|
|
return
|
|
}
|
|
|
|
app.OK(c, nil, "添加成功")
|
|
return
|
|
}
|
|
|
|
func CooperativeMemberPromotionList(c *gin.Context) {
|
|
req := &models.CooperativeMemberPromotionReq{}
|
|
if c.ShouldBindJSON(req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
list, count, err := req.List()
|
|
if err != nil {
|
|
logger.Errorf("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
|
|
ret := map[string]interface{}{
|
|
"count": count,
|
|
"list": list,
|
|
"pageIndex": req.Page,
|
|
}
|
|
app.OK(c, ret, "")
|
|
return
|
|
}
|
|
|
|
func CooperativeMemberPromotionStoreList(c *gin.Context) {
|
|
req := &models.CooperativeMemberPromotionStoreReq{}
|
|
if c.ShouldBindJSON(req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
list, count, err := req.List()
|
|
if err != nil {
|
|
logger.Errorf("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
|
|
ret := map[string]interface{}{
|
|
"count": count,
|
|
"list": list,
|
|
"pageIndex": req.Page,
|
|
}
|
|
app.OK(c, ret, "")
|
|
return
|
|
}
|
|
|
|
func CooperativeMemberPromotionDayList(c *gin.Context) {
|
|
req := &models.CooperativeMemberPromotionDayReq{}
|
|
if c.ShouldBindJSON(req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
list, count, err := req.List()
|
|
if err != nil {
|
|
logger.Errorf("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
|
|
ret := map[string]interface{}{
|
|
"count": count,
|
|
"list": list,
|
|
"pageIndex": req.Page,
|
|
}
|
|
app.OK(c, ret, "")
|
|
return
|
|
}
|
|
|
|
func CooperativeMemberPromotionStoreDayList(c *gin.Context) {
|
|
req := &models.CooperativeMemberPromotionStoreDayReq{}
|
|
if c.ShouldBindJSON(req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
list, count, err := req.List()
|
|
if err != nil {
|
|
logger.Errorf("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
|
|
ret := map[string]interface{}{
|
|
"count": count,
|
|
"list": list,
|
|
"pageIndex": req.Page,
|
|
}
|
|
app.OK(c, ret, "")
|
|
return
|
|
}
|
|
|
|
func CooperativeMemberPromotionStatisticList(c *gin.Context) {
|
|
req := &models.CooperativeMemberPromotionStatisticReq{}
|
|
if c.ShouldBindJSON(req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
list, count, err := req.List()
|
|
if err != nil {
|
|
logger.Errorf("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
|
|
ret := map[string]interface{}{
|
|
"count": count,
|
|
"list": list,
|
|
"pageIndex": req.Page,
|
|
}
|
|
app.OK(c, ret, "")
|
|
return
|
|
}
|
|
|
|
func CooperativeMemberPromotionSettleInfo(c *gin.Context) {
|
|
req := &struct {
|
|
CooperativeMemberPromotionId uint32 `json:"cooperative_member_promotion_id"`
|
|
CooperativeBusinessId uint32 `json:"cooperative_business_id"`
|
|
}{}
|
|
if c.ShouldBindJSON(req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
var memberPromotion models.CooperativeMemberPromotion
|
|
err := orm.Eloquent.Table("").Where("id=?", req.CooperativeMemberPromotionId).Find(&memberPromotion).Error
|
|
if err != nil {
|
|
logger.Error("cooperative member promotion err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "结算错误")
|
|
return
|
|
}
|
|
if memberPromotion.CooperativeBusinessId != req.CooperativeBusinessId {
|
|
logger.Error("cooperative business id err:")
|
|
app.Error(c, http.StatusInternalServerError, errors.New("cooperative business id err"), "结算错误")
|
|
return
|
|
}
|
|
cooperative := new(models.CooperativeBusiness)
|
|
cooperative.ID = memberPromotion.CooperativeBusinessId
|
|
cooperative.SetMemberDeductConfig()
|
|
|
|
if memberPromotion.State != models.PromotionStateUnSettlement {
|
|
logger.Error("cooperative member promotion state err:")
|
|
app.Error(c, http.StatusInternalServerError, err, "结算错误")
|
|
return
|
|
}
|
|
|
|
if cooperative.CooperativeMemberDeduct == nil {
|
|
logger.Error("cooperative member deduct nil:")
|
|
app.Error(c, http.StatusInternalServerError, err, "结算错误")
|
|
return
|
|
}
|
|
memberPromotion.GoldDeduct = cooperative.CooperativeMemberDeduct.GoldDeduct
|
|
memberPromotion.PlatinumDeduct = cooperative.CooperativeMemberDeduct.PlatinumDeduct
|
|
memberPromotion.BlackGoldDeduct = cooperative.CooperativeMemberDeduct.BlackGoldDeduct
|
|
|
|
memberPromotion.RenewalGoldDeduct = cooperative.CooperativeMemberDeduct.RenewalGoldDeduct
|
|
memberPromotion.RenewalPlatinumDeduct = cooperative.CooperativeMemberDeduct.RenewalPlatinumDeduct
|
|
memberPromotion.RenewalBlackGoldDeduct = cooperative.CooperativeMemberDeduct.RenewalBlackGoldDeduct
|
|
|
|
memberPromotion.DeductAmount += memberPromotion.GoldCount * memberPromotion.GoldDeduct
|
|
memberPromotion.DeductAmount += memberPromotion.PlatinumCount * memberPromotion.PlatinumDeduct
|
|
memberPromotion.DeductAmount += memberPromotion.BlackGoldCount * memberPromotion.BlackGoldDeduct
|
|
|
|
memberPromotion.DeductAmount += memberPromotion.RenewalGoldCount * memberPromotion.RenewalGoldDeduct
|
|
memberPromotion.DeductAmount += memberPromotion.RenewalPlatinumCount * memberPromotion.RenewalPlatinumDeduct
|
|
memberPromotion.DeductAmount += memberPromotion.RenewalBlackGoldCount * memberPromotion.RenewalBlackGoldDeduct
|
|
|
|
app.OK(c, memberPromotion, "")
|
|
return
|
|
}
|
|
|
|
func CooperativeMemberPromotionSettleConfirm(c *gin.Context) {
|
|
req := &struct {
|
|
CooperativeMemberPromotionId uint32 `json:"cooperative_member_promotion_id"`
|
|
CooperativeBusinessId uint32 `json:"cooperative_business_id"`
|
|
}{}
|
|
if c.ShouldBindJSON(req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
var memberPromotion models.CooperativeMemberPromotion
|
|
err := orm.Eloquent.Table("").Where("id=?", req.CooperativeMemberPromotionId).Find(&memberPromotion).Error
|
|
if err != nil {
|
|
logger.Error("cooperative member promotion err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "结算错误")
|
|
return
|
|
}
|
|
if memberPromotion.CooperativeBusinessId != req.CooperativeBusinessId {
|
|
logger.Error("cooperative business id err:")
|
|
app.Error(c, http.StatusInternalServerError, errors.New("cooperative business id err"), "结算错误")
|
|
return
|
|
}
|
|
// TODO
|
|
//if memberPromotion.Date != models.MonthDateAdd(-1) {
|
|
// logger.Error("settle date err:")
|
|
// app.Error(c, http.StatusInternalServerError, errors.New("settle date err"), "结算错误")
|
|
// return
|
|
//}
|
|
|
|
cooperative := new(models.CooperativeBusiness)
|
|
cooperative.ID = memberPromotion.CooperativeBusinessId
|
|
cooperative.SetMemberDeductConfig()
|
|
|
|
if memberPromotion.State != models.PromotionStateUnSettlement {
|
|
logger.Error("cooperative member promotion state err:")
|
|
app.Error(c, http.StatusInternalServerError, err, "结算错误")
|
|
return
|
|
}
|
|
|
|
if cooperative.CooperativeMemberDeduct == nil {
|
|
logger.Error("cooperative member deduct nil:")
|
|
app.Error(c, http.StatusInternalServerError, err, "结算错误")
|
|
return
|
|
}
|
|
memberPromotion.GoldDeduct = cooperative.CooperativeMemberDeduct.GoldDeduct
|
|
memberPromotion.PlatinumDeduct = cooperative.CooperativeMemberDeduct.PlatinumDeduct
|
|
memberPromotion.BlackGoldDeduct = cooperative.CooperativeMemberDeduct.BlackGoldDeduct
|
|
|
|
memberPromotion.RenewalGoldDeduct = cooperative.CooperativeMemberDeduct.RenewalGoldDeduct
|
|
memberPromotion.RenewalPlatinumDeduct = cooperative.CooperativeMemberDeduct.RenewalPlatinumDeduct
|
|
memberPromotion.RenewalBlackGoldDeduct = cooperative.CooperativeMemberDeduct.RenewalBlackGoldDeduct
|
|
|
|
memberPromotion.DeductAmount += memberPromotion.GoldCount * memberPromotion.GoldDeduct
|
|
memberPromotion.DeductAmount += memberPromotion.PlatinumCount * memberPromotion.PlatinumDeduct
|
|
memberPromotion.DeductAmount += memberPromotion.BlackGoldCount * memberPromotion.BlackGoldDeduct
|
|
|
|
memberPromotion.DeductAmount += memberPromotion.RenewalGoldCount * memberPromotion.RenewalGoldDeduct
|
|
memberPromotion.DeductAmount += memberPromotion.RenewalPlatinumCount * memberPromotion.RenewalPlatinumDeduct
|
|
memberPromotion.DeductAmount += memberPromotion.RenewalBlackGoldCount * memberPromotion.RenewalBlackGoldDeduct
|
|
|
|
begin := orm.Eloquent.Begin()
|
|
deductSettle := &models.CooperativeDeductSettle{
|
|
CooperativeMemberPromotionId: req.CooperativeMemberPromotionId,
|
|
CooperativeBusinessId: memberPromotion.CooperativeBusinessId,
|
|
CooperativeName: memberPromotion.CooperativeName,
|
|
DeductAmount: memberPromotion.DeductAmount,
|
|
Date: memberPromotion.Date,
|
|
State: models.PromotionStateFinancePay,
|
|
GoldCount: memberPromotion.GoldCount,
|
|
PlatinumCount: memberPromotion.PlatinumCount,
|
|
BlackGoldCount: memberPromotion.BlackGoldCount,
|
|
GoldDeduct: memberPromotion.GoldDeduct,
|
|
PlatinumDeduct: memberPromotion.PlatinumDeduct,
|
|
BlackGoldDeduct: memberPromotion.BlackGoldDeduct,
|
|
|
|
RenewalGoldCount: memberPromotion.RenewalGoldCount,
|
|
RenewalPlatinumCount: memberPromotion.RenewalPlatinumCount,
|
|
RenewalBlackGoldCount: memberPromotion.RenewalBlackGoldCount,
|
|
RenewalGoldDeduct: memberPromotion.RenewalGoldDeduct,
|
|
RenewalPlatinumDeduct: memberPromotion.RenewalPlatinumDeduct,
|
|
RenewalBlackGoldDeduct: memberPromotion.RenewalBlackGoldDeduct,
|
|
}
|
|
err = begin.Create(deductSettle).Error
|
|
if err != nil {
|
|
begin.Rollback()
|
|
logger.Error("create cooperative deduct settle err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "结算错误")
|
|
return
|
|
}
|
|
err = begin.Table("cooperative_member_promotion").Where("id=?", memberPromotion.ID).
|
|
Updates(map[string]interface{}{
|
|
"state": models.PromotionStateFinancePay,
|
|
}).Error
|
|
if err != nil {
|
|
begin.Rollback()
|
|
logger.Error("update cooperative_member_promotion state err:", err)
|
|
app.Error(c, http.StatusInternalServerError,
|
|
errors.New("update cooperative_member_promotion state err"), "结算错误")
|
|
return
|
|
}
|
|
err = begin.Commit().Error
|
|
if err != nil {
|
|
begin.Rollback()
|
|
logger.Error("commit err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "结算错误")
|
|
return
|
|
}
|
|
app.OK(c, memberPromotion, "")
|
|
return
|
|
}
|
|
|
|
func CooperativeMemberPromotionSettleList(c *gin.Context) {
|
|
req := &models.CooperativeMemberPromotionSettleReq{}
|
|
if c.ShouldBindJSON(req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
list, count, err := req.List()
|
|
if err != nil {
|
|
logger.Errorf("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
|
|
ret := map[string]interface{}{
|
|
"count": count,
|
|
"list": list,
|
|
"pageIndex": req.Page,
|
|
}
|
|
app.OK(c, ret, "")
|
|
return
|
|
}
|
|
|
|
func CooperativeMemberPromotionSettleRemit(c *gin.Context) {
|
|
req := &struct {
|
|
CooperativeDeductSettleId uint32 `json:"cooperative_deduct_settle_id"`
|
|
CooperativeBusinessId uint32 `json:"cooperative_business_id"`
|
|
}{}
|
|
if c.ShouldBindJSON(req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
var deductSettle models.CooperativeDeductSettle
|
|
err := orm.Eloquent.Table("").Where("id=?", req.CooperativeDeductSettleId).Find(&deductSettle).Error
|
|
if err != nil {
|
|
logger.Error("cooperative member promotion err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "结算错误")
|
|
return
|
|
}
|
|
if deductSettle.CooperativeBusinessId != req.CooperativeBusinessId {
|
|
logger.Error("cooperative business id err:")
|
|
app.Error(c, http.StatusInternalServerError, errors.New("cooperative business id err"), "操作失败")
|
|
return
|
|
}
|
|
if deductSettle.State != models.PromotionStateFinancePay {
|
|
logger.Error("deduct settle state err:")
|
|
app.Error(c, http.StatusInternalServerError, errors.New("deduct settle state err"), "操作失败")
|
|
return
|
|
}
|
|
|
|
begin := orm.Eloquent.Begin()
|
|
err = begin.Table("cooperative_member_promotion").
|
|
Where("id=?", deductSettle.CooperativeMemberPromotionId).Updates(map[string]interface{}{
|
|
"state": models.PromotionStateSettled,
|
|
}).Error
|
|
if err != nil {
|
|
begin.Rollback()
|
|
logger.Error("update cooperative_member_promotion state err:", err)
|
|
app.Error(c, http.StatusInternalServerError, errors.New("update cooperative_member_promotion state err"), "操作失败")
|
|
return
|
|
}
|
|
err = begin.Table("cooperative_deduct_settle").Where("id=?", deductSettle.ID).Updates(map[string]interface{}{
|
|
"state": models.PromotionStateSettled,
|
|
}).Error
|
|
if err != nil {
|
|
begin.Rollback()
|
|
logger.Error("update cooperative_member_promotion state err:", err)
|
|
app.Error(c, http.StatusInternalServerError, errors.New("update cooperative_member_promotion state err"), "操作失败")
|
|
return
|
|
}
|
|
err = begin.Commit().Error
|
|
if err != nil {
|
|
begin.Rollback()
|
|
logger.Error("commit err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "结算错误")
|
|
return
|
|
}
|
|
app.OK(c, nil, "")
|
|
return
|
|
}
|
|
|
|
func CooperativePromotionMemberList(c *gin.Context) {
|
|
req := &models.CooperativePromotionMemberReq{}
|
|
if c.ShouldBindJSON(req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
list, count, err := req.List()
|
|
if err != nil {
|
|
logger.Errorf("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
|
|
ret := map[string]interface{}{
|
|
"count": count,
|
|
"list": list,
|
|
"pageIndex": req.Page,
|
|
}
|
|
app.OK(c, ret, "")
|
|
return
|
|
}
|
|
|
|
func UpdateCooperativeMemberDeduct(c *gin.Context) {
|
|
req := &models.CooperativeMemberDeduct{}
|
|
if c.ShouldBindJSON(req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
err := orm.Eloquent.Save(req).Error
|
|
if err != nil {
|
|
logger.Errorf("update cooperative member deduct err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "修改失败")
|
|
return
|
|
}
|
|
|
|
app.OK(c, nil, "修改成功")
|
|
return
|
|
}
|
|
|
|
type CooperativeAssistantMemberDeductReq struct {
|
|
CooperativeBusinessId uint32 `json:"cooperative_business_id" binding:"required"`
|
|
StoreId uint32 `json:"store_id" binding:"required"` //
|
|
GoldDeduct uint32 `json:"gold_deduct" binding:"required"` // 黄金会员提成
|
|
PlatinumDeduct uint32 `json:"platinum_deduct" binding:"required"` // 白金会员提成
|
|
BlackGoldDeduct uint32 `json:"black_gold_deduct" binding:"required"` // 黑金金会员提成
|
|
RenewalGoldDeduct uint32 `json:"renewal_gold_deduct" binding:"required"` // 续费黄金会员提成
|
|
RenewalPlatinumDeduct uint32 `json:"renewal_platinum_deduct" binding:"required"` // 续费白金会员提成
|
|
RenewalBlackGoldDeduct uint32 `json:"renewal_black_gold_deduct" binding:"required"` // 续费黑金金会员提成
|
|
// cooperative_assistant_member_deduct
|
|
}
|
|
|
|
func UpdateCooperativeMemberStoreDeduct(c *gin.Context) {
|
|
req := &CooperativeAssistantMemberDeductReq{}
|
|
if c.ShouldBindJSON(req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
memberDeduct := &models.CooperativeAssistantMemberDeduct{
|
|
CooperativeBusinessId: req.CooperativeBusinessId,
|
|
StoreId: req.StoreId,
|
|
GoldDeduct: req.GoldDeduct,
|
|
PlatinumDeduct: req.PlatinumDeduct,
|
|
BlackGoldDeduct: req.BlackGoldDeduct,
|
|
RenewalGoldDeduct: req.RenewalGoldDeduct,
|
|
RenewalPlatinumDeduct: req.RenewalPlatinumDeduct,
|
|
RenewalBlackGoldDeduct: req.RenewalBlackGoldDeduct,
|
|
}
|
|
if memberDeduct.CooperativeBusinessId == 0 {
|
|
var store models.Store
|
|
err := orm.Eloquent.Table("store").Where("id=?", memberDeduct.StoreId).Find(&store).Error
|
|
if err != nil {
|
|
logger.Error("store err:", store)
|
|
app.Error(c, http.StatusInternalServerError, err, "修改失败")
|
|
return
|
|
}
|
|
memberDeduct.CooperativeBusinessId = store.CooperativeBusinessId
|
|
}
|
|
err := orm.Eloquent.Save(memberDeduct).Error
|
|
if err != nil {
|
|
logger.Error("update cooperative member deduct err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "修改失败")
|
|
return
|
|
}
|
|
|
|
app.OK(c, nil, "修改成功")
|
|
return
|
|
}
|
|
|
|
func CooperativeOrderList(c *gin.Context) {
|
|
req := &models.CooperativeOrderReq{}
|
|
if c.ShouldBindJSON(req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
//reqJson, _ := json.Marshal(req)
|
|
//fmt.Println("reqJson:", string(reqJson))
|
|
|
|
list, count, err := req.List()
|
|
if err != nil {
|
|
logger.Errorf("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
|
|
ret := map[string]interface{}{
|
|
"count": count,
|
|
"list": list,
|
|
"pageIndex": req.Page,
|
|
}
|
|
app.OK(c, ret, "")
|
|
}
|
|
|
|
func AssistantInviteMemberReportList(c *gin.Context) {
|
|
req := models.AssistantInviteMemberReportReq{}
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
logger.Error("parameter err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
data, _ := c.Get(jwtauth.JwtPayloadKey)
|
|
sysUid, ok := data.(jwtauth.MapClaims)["identity"]
|
|
if !ok {
|
|
logger.Error("sys uid err")
|
|
app.Error(c, http.StatusInternalServerError, errors.New("sys uid err"), "查询失败")
|
|
return
|
|
}
|
|
sysUser, err := models.GetSysUser(sysUid)
|
|
if err != nil {
|
|
logger.Error("sys user err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
req.SysUser = sysUser
|
|
//req.CooperativeBusinessId = sysUser.CooperativeBusinessId
|
|
|
|
list, count, err := req.List()
|
|
if err != nil {
|
|
logger.Errorf("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
|
|
ret := map[string]interface{}{
|
|
"list": list,
|
|
"cur_page": req.Page,
|
|
"count": count,
|
|
}
|
|
app.OK(c, ret, "")
|
|
return
|
|
}
|
|
|
|
func CooperativeStoreList(c *gin.Context) {
|
|
req := &models.GetCooperativeStoreReq{}
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
data, _ := c.Get(jwtauth.JwtPayloadKey)
|
|
mapClaims := data.(jwtauth.MapClaims)
|
|
sysUid := float64(0)
|
|
if v, ok := mapClaims["identity"]; ok {
|
|
sysUid = v.(float64)
|
|
}
|
|
fmt.Println("sysUid:", sysUid)
|
|
|
|
req.SysUid = fmt.Sprintf("%.0f", sysUid)
|
|
list, count, err := req.List()
|
|
if err != nil {
|
|
logger.Errorf("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
ret := map[string]interface{}{
|
|
"count": count,
|
|
"list": list,
|
|
"pageIndex": req.Page,
|
|
"total_page": req.PageSize,
|
|
}
|
|
|
|
app.OK(c, ret, "")
|
|
}
|
|
|
|
func CooperativeGameCardStockList(c *gin.Context) {
|
|
req := models.CooperativeGameCardStockReq{}
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
logger.Error("parameter err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
//data, _ := c.Get(jwtauth.JwtPayloadKey)
|
|
//sysUid, ok := data.(jwtauth.MapClaims)["identity"]
|
|
//if !ok {
|
|
// logger.Error("sys uid err")
|
|
// app.Error(c, http.StatusInternalServerError, errors.New("sys uid err"), "查询失败")
|
|
// return
|
|
//}
|
|
//sysUser, err := models.GetSysUser(sysUid)
|
|
//if err != nil {
|
|
// logger.Error("sys user err:", err)
|
|
// app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
// return
|
|
//}
|
|
////req.CooperativeBusinessId = sysUser.CooperativeBusinessId
|
|
businessId, err := models.GetCooperativeBusinessId(c)
|
|
if err != nil {
|
|
logger.Error("get cooperative business id err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
req.CooperativeBusinessId = businessId
|
|
resp, err := req.List()
|
|
if err != nil {
|
|
logger.Errorf("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
|
|
app.OK(c, resp, "")
|
|
return
|
|
}
|
|
|
|
func CooperativeGameCardGoodsList(c *gin.Context) {
|
|
req := models.CooperativeGameCardGoodsReq{}
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
businessId, err := models.GetCooperativeBusinessId(c)
|
|
if err != nil {
|
|
logger.Error("get cooperative business id err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
req.CooperativeBusinessId = businessId
|
|
resp, err := req.List()
|
|
if err != nil {
|
|
logger.Errorf("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
|
|
app.OK(c, resp, "")
|
|
}
|
|
|
|
// 5.调拨任务列表
|
|
func CooperativeCannibalizeTaskList(c *gin.Context) {
|
|
req := models.CooperativeCannibalizeTaskReq{}
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
businessId, err := models.GetCooperativeBusinessId(c)
|
|
if err != nil {
|
|
logger.Errorf("cannibalize task get cooperative business id err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "查询失败")
|
|
return
|
|
}
|
|
req.CooperativeBusinessId = businessId
|
|
resp, err := req.List()
|
|
if err != nil {
|
|
logger.Error("err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "任务列表错误")
|
|
return
|
|
}
|
|
|
|
app.OK(c, resp, "")
|
|
}
|
|
|
|
func CooperativeStockExport(c *gin.Context) {
|
|
req := struct {
|
|
StoreId uint32 `json:"store_id"`
|
|
}{}
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
businessId, err := models.GetCooperativeBusinessId(c)
|
|
if err != nil {
|
|
logger.Errorf("cannibalize task get cooperative business id err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "导出失败")
|
|
return
|
|
}
|
|
//req.CooperativeBusinessId = businessId
|
|
var cooperativeBusiness models.CooperativeBusiness
|
|
err = orm.Eloquent.Table("cooperative_business").Where("id=?", businessId).Find(&cooperativeBusiness).Error
|
|
if err != nil {
|
|
logger.Error("cooperative business err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "导出失败")
|
|
return
|
|
}
|
|
storeIds := []uint32{req.StoreId}
|
|
if req.StoreId == 0 {
|
|
ids, err := models.GetStoreIdsByCooperativeBusinessId(businessId)
|
|
if err != nil {
|
|
logger.Error("store id cooperative business err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "导出失败")
|
|
return
|
|
}
|
|
storeIds = ids
|
|
}
|
|
|
|
goodsStock := models.CooperativeExportGoodsStock(storeIds, cooperativeBusiness)
|
|
|
|
ret := &map[string]interface{}{
|
|
"goods_stock_url": goodsStock,
|
|
}
|
|
app.OK(c, ret, "数据导出成功")
|
|
return
|
|
}
|
|
|
|
func CooperativeMemberPromotionExport(c *gin.Context) {
|
|
req := models.CooperativeExportMemberPromotionReq{}
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
logger.Errorf("para err")
|
|
app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
return
|
|
}
|
|
|
|
businessId, err := models.GetCooperativeBusinessId(c)
|
|
if err != nil {
|
|
logger.Errorf("cannibalize task get cooperative business id err:", err)
|
|
app.Error(c, http.StatusInternalServerError, err, "导出失败")
|
|
return
|
|
}
|
|
req.CooperativeBusinessId = businessId
|
|
//var cooperativeBusiness models.CooperativeBusiness
|
|
//err = orm.Eloquent.Table("cooperative_business").Where("id=?", businessId).Find(&cooperativeBusiness).Error
|
|
//if err != nil {
|
|
// logger.Error("cooperative business err:", err)
|
|
// app.Error(c, http.StatusInternalServerError, err, "导出失败")
|
|
// return
|
|
//}
|
|
//storeIds := []uint32{req.StoreId}
|
|
//if req.StoreId == 0 {
|
|
// ids, err := models.GetStoreIdsByCooperativeBusinessId(businessId)
|
|
// if err != nil {
|
|
// logger.Error("store id cooperative business err:", err)
|
|
// app.Error(c, http.StatusInternalServerError, err, "导出失败")
|
|
// return
|
|
// }
|
|
// storeIds = ids
|
|
//}
|
|
|
|
memberPromotion := req.Export()
|
|
if memberPromotion == "" {
|
|
logger.Error("member promotion url nil:")
|
|
app.Error(c, http.StatusInternalServerError, errors.New("member promotion url nil"), "导出失败")
|
|
return
|
|
}
|
|
|
|
ret := &map[string]interface{}{
|
|
"member_promotion_url": memberPromotion,
|
|
}
|
|
app.OK(c, ret, "数据导出成功")
|
|
}
|