2022-05-10 07:17:34 +00:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/codinl/go-logger"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"mh-server/lib/auth"
|
|
|
|
"mh-server/lib/status"
|
|
|
|
"mh-server/model"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func CooperativeGameCardGoodsStockAdds(c *gin.Context) {
|
|
|
|
req := struct {
|
|
|
|
Cards []model.GameCardGoods `json:"cards"`
|
|
|
|
}{}
|
|
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
|
|
logger.Error("ShouldBindJSON err")
|
|
|
|
RespJson(c, status.BadRequest, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
uc := auth.GetCurrentUser(c)
|
|
|
|
if uc == nil {
|
|
|
|
logger.Error("uc is nil")
|
|
|
|
RespJson(c, status.Unauthorized, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-12 05:42:45 +00:00
|
|
|
assistant := model.GetUserByUid(uc.Uid)
|
|
|
|
if assistant.UserType != 2 {
|
|
|
|
logger.Error("not assistant")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if assistant.XcxRoleId != 2 {
|
|
|
|
logger.Error("not shop manager")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
serialNumbers := ""
|
2022-05-10 07:17:34 +00:00
|
|
|
cardGoods := &model.GameCardGoods{}
|
|
|
|
for i, _ := range req.Cards {
|
|
|
|
req.Cards[i].CardType = model.GameCardGoodsTypeCommon
|
|
|
|
req.Cards[i].ShareProfitType = 1
|
2022-05-12 05:42:45 +00:00
|
|
|
req.Cards[i].Status = model.GameCardGoodsStatusStock
|
|
|
|
req.Cards[i].StoreId = assistant.StoreId
|
|
|
|
serialNumbers += req.Cards[i].SerialNumber + ","
|
2022-05-10 07:17:34 +00:00
|
|
|
}
|
|
|
|
err := cardGoods.Adds(req.Cards)
|
|
|
|
if err != nil {
|
2022-05-28 07:24:17 +00:00
|
|
|
logger.Errorf("err:%#v", err)
|
2022-05-10 07:17:34 +00:00
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-12 05:42:45 +00:00
|
|
|
operationLog := &model.OperationLog{
|
|
|
|
Uid: assistant.Uid,
|
|
|
|
Description: "游戏卡入库",
|
|
|
|
OperationType: model.OperationTypeGameCardGoodsInStock,
|
|
|
|
CorrelationName: model.LogCorrelationOrderId,
|
|
|
|
StoreId: uint32(assistant.StoreId),
|
|
|
|
StoreName: "",
|
|
|
|
CooperativeName: assistant.CooperativeName,
|
|
|
|
CooperativeBusinessId: assistant.CooperativeBusinessId,
|
|
|
|
Detail: serialNumbers[:len(serialNumbers)-1],
|
|
|
|
}
|
|
|
|
operationLog.AddLog()
|
|
|
|
|
2022-05-10 07:17:34 +00:00
|
|
|
RespOK(c, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func GameCardGoodsStockAnalysis(c *gin.Context) {
|
|
|
|
req := model.GameCardGoodsStockAnalysisReq{}
|
|
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
|
|
logger.Error("ShouldBindJSON err")
|
|
|
|
RespJson(c, status.BadRequest, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-12 05:42:45 +00:00
|
|
|
uc := auth.GetCurrentUser(c)
|
|
|
|
if uc == nil {
|
|
|
|
logger.Error("uc is nil")
|
|
|
|
RespJson(c, status.Unauthorized, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assistant := model.GetUserByUid(uc.Uid)
|
|
|
|
if assistant.UserType != 2 {
|
|
|
|
logger.Error("not assistant")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.StoreId = uint32(assistant.StoreId)
|
2022-05-10 07:17:34 +00:00
|
|
|
resp, err := req.GameCardStockListAnalysis()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("err:", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
//ret := make(map[string]interface{}, 0)
|
|
|
|
//ret["list"] = stockList
|
|
|
|
//ret["count"] = total
|
|
|
|
//ret["page_index"] = req.PageNum
|
|
|
|
|
|
|
|
RespOK(c, resp)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func CooperativeExportDataGameCardGoodsStock(c *gin.Context) {
|
|
|
|
uc := auth.GetCurrentUser(c)
|
|
|
|
if uc == nil {
|
|
|
|
logger.Error("uc is nil")
|
|
|
|
RespJson(c, status.Unauthorized, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assistant := model.GetUserByUid(uc.Uid)
|
|
|
|
if assistant.XcxRoleId != 2 {
|
|
|
|
logger.Error("xcx role err:")
|
|
|
|
RespJson(c, status.NoAuth, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-12 05:42:45 +00:00
|
|
|
if assistant.UserType != 2 {
|
|
|
|
logger.Error("not assistant")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-10 07:17:34 +00:00
|
|
|
goodsStock := model.ExportGoodsStock(uint32(assistant.StoreId))
|
|
|
|
|
|
|
|
ret := &map[string]interface{}{
|
|
|
|
"goods_stock_url": goodsStock,
|
|
|
|
}
|
|
|
|
RespOK(c, ret)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1.创建调拨
|
|
|
|
func CooperativeCannibalizeTaskCreate(c *gin.Context) {
|
|
|
|
req := struct {
|
|
|
|
FromStoreId uint32 `json:"from_store_id"`
|
|
|
|
ToStoreId uint32 `json:"to_store_id"`
|
|
|
|
}{}
|
|
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
|
|
logger.Errorf("para err")
|
|
|
|
RespJson(c, status.BadRequest, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
uc := auth.GetCurrentUser(c)
|
|
|
|
if uc == nil {
|
|
|
|
logger.Error("uc is nil")
|
|
|
|
RespJson(c, status.Unauthorized, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assistant := model.GetUserByUid(uc.Uid)
|
2022-05-12 05:42:45 +00:00
|
|
|
if assistant.UserType != 2 {
|
|
|
|
logger.Error("not assistant")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-10 07:17:34 +00:00
|
|
|
req.FromStoreId = uint32(assistant.StoreId)
|
|
|
|
if req.FromStoreId == 0 || req.ToStoreId == 0 {
|
|
|
|
RespJson(c, status.BadRequest, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
task := &model.CannibalizeStockTask{
|
|
|
|
FromStoreId: req.FromStoreId,
|
|
|
|
ToStoreId: req.ToStoreId,
|
|
|
|
TaskId: uint32(time.Now().Unix()),
|
|
|
|
Count: 0,
|
|
|
|
Status: model.CannibalizeTaskStatusNotImportGoods,
|
|
|
|
}
|
|
|
|
err := model.DB.Create(task).Error
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("err:", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
RespOK(c, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2.导入调拨卡
|
|
|
|
func CooperativeCannibalizeTaskImportGoods(c *gin.Context) {
|
|
|
|
req := struct {
|
|
|
|
CannibalizeStockTaskId uint32 `json:"cannibalize_stock_task_id"`
|
|
|
|
SerialNumberList []string `json:"serial_number_list"` // 编号
|
|
|
|
}{}
|
|
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
|
|
logger.Errorf("para err")
|
|
|
|
RespJson(c, status.BadRequest, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-12 05:42:45 +00:00
|
|
|
|
|
|
|
uc := auth.GetCurrentUser(c)
|
|
|
|
if uc == nil {
|
|
|
|
logger.Error("uc is nil")
|
|
|
|
RespJson(c, status.Unauthorized, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assistant := model.GetUserByUid(uc.Uid)
|
|
|
|
if assistant.UserType != 2 {
|
|
|
|
logger.Error("not assistant")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-10 07:17:34 +00:00
|
|
|
unImportGoods, err := model.CannibalizeTaskImportGoods(req.CannibalizeStockTaskId, req.SerialNumberList)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("err:", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if unImportGoods > 0 {
|
|
|
|
//app.OK(c, nil, fmt.Sprintf("有 %d 个卡未导入", unImportGoods))
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//app.OK(c, nil, "导入调拨卡成功")
|
|
|
|
RespOK(c, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3.确认发货
|
|
|
|
func CooperativeCannibalizeTaskDeliverGoods(c *gin.Context) {
|
|
|
|
req := struct {
|
|
|
|
CannibalizeStockTaskId uint32 `json:"cannibalize_stock_task_id"`
|
|
|
|
}{}
|
|
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
|
|
logger.Errorf("para err")
|
|
|
|
RespJson(c, status.BadRequest, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-12 05:42:45 +00:00
|
|
|
uc := auth.GetCurrentUser(c)
|
|
|
|
if uc == nil {
|
|
|
|
logger.Error("uc is nil")
|
|
|
|
RespJson(c, status.Unauthorized, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assistant := model.GetUserByUid(uc.Uid)
|
|
|
|
if assistant.UserType != 2 {
|
|
|
|
logger.Error("not assistant")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-10 07:17:34 +00:00
|
|
|
err := model.CannibalizeDeliverGoods(req.CannibalizeStockTaskId)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("err:", err)
|
|
|
|
//app.Error(c, http.StatusInternalServerError, err, "发货错误")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//app.OK(c, nil, "发货成功")
|
|
|
|
RespOK(c, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// 4.确认入库
|
|
|
|
func CooperativeCannibalizeTaskPutInStorage(c *gin.Context) {
|
|
|
|
req := struct {
|
|
|
|
CannibalizeStockTaskId uint32 `json:"cannibalize_stock_task_id"`
|
|
|
|
}{}
|
|
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
|
|
logger.Errorf("para err")
|
|
|
|
//app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
|
|
RespJson(c, status.BadRequest, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-12 05:42:45 +00:00
|
|
|
uc := auth.GetCurrentUser(c)
|
|
|
|
if uc == nil {
|
|
|
|
logger.Error("uc is nil")
|
|
|
|
RespJson(c, status.Unauthorized, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assistant := model.GetUserByUid(uc.Uid)
|
|
|
|
if assistant.UserType != 2 {
|
|
|
|
logger.Error("not assistant")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-13 09:35:10 +00:00
|
|
|
if assistant.XcxRoleId != 2 {
|
|
|
|
logger.Error("xcx role err:")
|
|
|
|
RespJson(c, status.NoAuth, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-10 07:17:34 +00:00
|
|
|
err := model.CannibalizePutInStorage(req.CannibalizeStockTaskId)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("err:", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
RespOK(c, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// 5.调拨任务列表
|
|
|
|
func CooperativeCannibalizeTaskList(c *gin.Context) {
|
|
|
|
req := model.CannibalizeTaskListReq{}
|
|
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
|
|
logger.Errorf("para err")
|
|
|
|
//app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
|
|
RespJson(c, status.BadRequest, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
uc := auth.GetCurrentUser(c)
|
|
|
|
if uc == nil {
|
|
|
|
logger.Error("uc is nil")
|
|
|
|
RespJson(c, status.Unauthorized, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assistant := model.GetUserByUid(uc.Uid)
|
2022-05-12 05:42:45 +00:00
|
|
|
if assistant.UserType != 2 {
|
|
|
|
logger.Error("not assistant")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-10 07:17:34 +00:00
|
|
|
req.StoreId = uint32(assistant.StoreId)
|
|
|
|
if req.StoreId == 0 {
|
|
|
|
RespJson(c, status.BadRequest, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := req.GetCannibalizeTaskList()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("err:", err)
|
|
|
|
//app.Error(c, http.StatusInternalServerError, err, "任务列表错误")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//app.OK(c, resp, "")
|
|
|
|
RespOK(c, resp)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// 6.调拨任务卡列表
|
|
|
|
func CooperativeCannibalizeTaskGameCardGoodsList(c *gin.Context) {
|
|
|
|
req := model.CannibalizeTaskGameCardGoodsListReq{}
|
|
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
|
|
logger.Errorf("para err")
|
|
|
|
//app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
|
|
RespJson(c, status.BadRequest, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-12 05:42:45 +00:00
|
|
|
uc := auth.GetCurrentUser(c)
|
|
|
|
if uc == nil {
|
|
|
|
logger.Error("uc is nil")
|
|
|
|
RespJson(c, status.Unauthorized, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assistant := model.GetUserByUid(uc.Uid)
|
|
|
|
if assistant.UserType != 2 {
|
|
|
|
logger.Error("not assistant")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-10 07:17:34 +00:00
|
|
|
resp, err := req.GetCannibalizeTaskGameCardGoodsList()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("err:", err)
|
|
|
|
//app.Error(c, http.StatusInternalServerError, err, "任务列表错误")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//app.OK(c, resp, "")
|
|
|
|
RespOK(c, resp)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func CooperativeCannibalizeTaskDel(c *gin.Context) {
|
|
|
|
req := struct {
|
|
|
|
CannibalizeStockTaskId uint32 `json:"cannibalize_stock_task_id"`
|
|
|
|
}{}
|
|
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
|
|
logger.Errorf("para err")
|
|
|
|
//app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
|
|
RespJson(c, status.BadRequest, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-12 05:42:45 +00:00
|
|
|
uc := auth.GetCurrentUser(c)
|
|
|
|
if uc == nil {
|
|
|
|
logger.Error("uc is nil")
|
|
|
|
RespJson(c, status.Unauthorized, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assistant := model.GetUserByUid(uc.Uid)
|
|
|
|
if assistant.UserType != 2 {
|
|
|
|
logger.Error("not assistant")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-10 07:17:34 +00:00
|
|
|
err := model.CannibalizeTaskDel(req.CannibalizeStockTaskId)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("err:", err)
|
|
|
|
//app.Error(c, http.StatusInternalServerError, err, "改任务状态不能删除")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//app.OK(c, nil, "发货成功")
|
|
|
|
RespOK(c, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func CooperativeGameCardGoodsList(c *gin.Context) {
|
|
|
|
req := model.CooperativeGameCardGoodsListReq{}
|
|
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
|
|
logger.Errorf("para err")
|
|
|
|
//app.Error(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
//goodsStock := model.ExportGoodsStock(req.StoreId)
|
|
|
|
uc := auth.GetCurrentUser(c)
|
|
|
|
if uc == nil {
|
|
|
|
logger.Error("uc is nil")
|
|
|
|
RespJson(c, status.Unauthorized, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.AssistantUid = uc.Uid
|
2022-05-12 05:42:45 +00:00
|
|
|
assistant := model.GetUserByUid(uc.Uid)
|
|
|
|
if assistant.UserType != 2 {
|
|
|
|
logger.Error("not assistant")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-10 07:17:34 +00:00
|
|
|
resp, err := req.List()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("list err:", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//ret := &map[string]interface{}{
|
|
|
|
// "goods_stock_url": goodsStock,
|
|
|
|
//}
|
|
|
|
//app.OK(c, ret, "数据导出成功")
|
|
|
|
RespOK(c, resp)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func AssistantMemberPromotionList(c *gin.Context) {
|
|
|
|
req := model.AssistantMemberPromotionReq{}
|
|
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
|
|
logger.Errorf("para err")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
uc := auth.GetCurrentUser(c)
|
|
|
|
if uc == nil {
|
|
|
|
logger.Error("uc is nil")
|
|
|
|
RespJson(c, status.Unauthorized, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.AssistantUid = uc.Uid
|
|
|
|
|
|
|
|
req.Assistant = model.GetUserByUid(uc.Uid)
|
|
|
|
if req.Assistant.XcxRoleId != 2 {
|
|
|
|
logger.Error("xcx role err:")
|
|
|
|
RespJson(c, status.NoAuth, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-12 05:42:45 +00:00
|
|
|
if req.Assistant.UserType != 2 {
|
|
|
|
logger.Error("not assistant")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-10 07:17:34 +00:00
|
|
|
list, totalPage, err := req.List()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("list err:", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := &map[string]interface{}{
|
|
|
|
"list": list,
|
|
|
|
"total_page": totalPage,
|
|
|
|
"page_num": req.PageNum,
|
|
|
|
}
|
|
|
|
RespOK(c, ret)
|
|
|
|
return
|
|
|
|
}
|
2022-06-03 03:30:03 +00:00
|
|
|
|
|
|
|
func AssistantMemberPromotionDetail(c *gin.Context) {
|
|
|
|
req := struct {
|
|
|
|
AssistantUid uint32 `json:"assistant_uid" binding:"required"`
|
|
|
|
Date string `json:"date" binding:"required"`
|
|
|
|
PageNum int `json:"page_num" binding:"required"`
|
|
|
|
PageSize int `json:"page_size"`
|
|
|
|
}{}
|
|
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
|
|
logger.Errorf("para err")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
uc := auth.GetCurrentUser(c)
|
|
|
|
if uc == nil {
|
|
|
|
logger.Error("uc is nil")
|
|
|
|
RespJson(c, status.Unauthorized, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
//req.AssistantUid = uc.Uid
|
|
|
|
dateTime, err := time.Parse("2006-01", req.Date)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("parse err:", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.PageNum -= 1
|
|
|
|
if req.PageNum < 0 {
|
|
|
|
req.PageNum = 0
|
|
|
|
}
|
|
|
|
if req.PageSize == 0 {
|
|
|
|
req.PageSize = 10
|
|
|
|
}
|
|
|
|
var list []model.UserInvite
|
|
|
|
qs := model.NewUserInviteQuerySet(model.DB).FromUidEq(req.AssistantUid).
|
|
|
|
MemberOpenTimeGte(dateTime).MemberOpenTimeLte(dateTime.AddDate(0, 1, 0))
|
|
|
|
|
|
|
|
count, err := qs.Count()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("err:", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
totalPage := int(count)/req.PageSize + 1
|
|
|
|
|
|
|
|
err = qs.OrderDescByMemberOpenTime().Offset(req.PageNum * req.PageSize).Limit(req.PageSize).All(&list)
|
|
|
|
if err != nil && err != model.RecordNotFound {
|
|
|
|
logger.Error("err:", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
//req.Assistant = model.GetUserByUid(uc.Uid)
|
|
|
|
//if req.Assistant.XcxRoleId != 2 {
|
|
|
|
// logger.Error("xcx role err:")
|
|
|
|
// RespJson(c, status.NoAuth, nil)
|
|
|
|
// return
|
|
|
|
//}
|
|
|
|
//if req.Assistant.UserType != 2 {
|
|
|
|
// logger.Error("not assistant")
|
|
|
|
// RespJson(c, status.InternalServerError, nil)
|
|
|
|
// return
|
|
|
|
//}
|
|
|
|
//list, totalPage, err := req.List()
|
|
|
|
//if err != nil {
|
|
|
|
// logger.Error("list err:", err)
|
|
|
|
// RespJson(c, status.InternalServerError, nil)
|
|
|
|
// return
|
|
|
|
//}
|
|
|
|
//model.UserInviteListSetToUser(list)
|
|
|
|
|
|
|
|
ret := &map[string]interface{}{
|
|
|
|
"list": list,
|
|
|
|
"total_page": totalPage,
|
|
|
|
"page_num": req.PageNum,
|
|
|
|
}
|
|
|
|
RespOK(c, ret)
|
|
|
|
return
|
|
|
|
}
|