|
@@ -8,15 +8,31 @@ import (
|
|
|
"eta/eta_mini_crm_ht/models/response"
|
|
|
"eta/eta_mini_crm_ht/services"
|
|
|
"eta/eta_mini_crm_ht/utils"
|
|
|
+ "fmt"
|
|
|
"github.com/go-sql-driver/mysql"
|
|
|
"github.com/rdlucklib/rdluck_tools/paging"
|
|
|
"github.com/shopspring/decimal"
|
|
|
+ "math/rand"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
+var (
|
|
|
+ CNProductMap = map[models.MerchantProductType]string{
|
|
|
+ models.ProductPackage: "套餐",
|
|
|
+ models.ProductVideo: "视频",
|
|
|
+ models.ProductAudio: "音频",
|
|
|
+ models.ProductReport: "报告",
|
|
|
+ }
|
|
|
+
|
|
|
+ CNSaleStatusMap = map[models.SaleStatus]string{
|
|
|
+ models.OnSale: "已上架",
|
|
|
+ models.OffSale: "未上架",
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
type ProductController struct {
|
|
|
BaseAuthController
|
|
|
}
|
|
@@ -135,6 +151,7 @@ func (this *ProductController) AddProduct() {
|
|
|
this.ServeJSON()
|
|
|
}()
|
|
|
var req request.ProductReq
|
|
|
+ var permissionName string
|
|
|
err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
if err != nil {
|
|
|
br.Msg = "参数解析异常!"
|
|
@@ -157,7 +174,23 @@ func (this *ProductController) AddProduct() {
|
|
|
product.Title = req.ProductName
|
|
|
product.ValidDays = req.ValidDays
|
|
|
product.Description = req.Description
|
|
|
- product.CoverSrc = req.CoverSrc
|
|
|
+ if req.CoverSrc == "" {
|
|
|
+ var imageList []models.ImageSource
|
|
|
+ imageList, err = models.GetImageByPermissionId(req.SourceId)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Error("套餐封面获取失败", err.Error())
|
|
|
+ //br.Msg = "默认套餐封面获取失败,请上传封面"
|
|
|
+ //br.ErrMsg = "默认套餐封面获取失败,请上传封面,Err:" + err.Error()
|
|
|
+ //return
|
|
|
+ } else {
|
|
|
+ var rnd = rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
+ index := rnd.Intn(len(imageList))
|
|
|
+ product.CoverSrc = imageList[index].SrcUrl
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ product.CoverSrc = req.CoverSrc
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
switch req.Type {
|
|
|
case "report":
|
|
@@ -167,7 +200,7 @@ func (this *ProductController) AddProduct() {
|
|
|
case "video":
|
|
|
product.RiskLevel, product.Title, err = services.GetRiskLevel("video", req.SourceId)
|
|
|
case "package":
|
|
|
- product.RiskLevel, _, err = services.GetRiskLevel("package", req.SourceId)
|
|
|
+ product.RiskLevel, permissionName, err = services.GetRiskLevel("package", req.SourceId)
|
|
|
default:
|
|
|
br.Msg = "产品类型错误"
|
|
|
br.ErrMsg = "获取产品列表失败,Err:产品类型错误"
|
|
@@ -216,6 +249,7 @@ func (this *ProductController) AddProduct() {
|
|
|
product.Price = req.Price
|
|
|
product.SourceId = req.SourceId
|
|
|
product.Type = models.MerchantProductType(req.Type)
|
|
|
+ product.Creator = this.SysUser.SysRealName
|
|
|
if product.Type == "" {
|
|
|
br.Msg = "新增产品错误"
|
|
|
br.ErrMsg = "产品类型为空"
|
|
@@ -227,8 +261,21 @@ func (this *ProductController) AddProduct() {
|
|
|
var mysqlErr *mysql.MySQLError
|
|
|
if errors.As(err, &mysqlErr) {
|
|
|
if mysqlErr.Number == 1062 {
|
|
|
- br.Msg = "该产品已设置付费,请刷新后重试"
|
|
|
- br.ErrMsg = "该产品已设置付费,请刷新后重试"
|
|
|
+ if product.Type == models.ProductPackage {
|
|
|
+ var dbProduct models.MerchantProduct
|
|
|
+ dbProduct, err = models.GetProductByProductType(product.SourceId, models.ProductPackage)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Error("获取套餐产品信息失败,err:" + err.Error())
|
|
|
+ br.Msg = "[" + permissionName + "]已设置付费套餐,请重新选择"
|
|
|
+ br.ErrMsg = "[" + permissionName + "]已设置付费套餐,请重新选择"
|
|
|
+ } else {
|
|
|
+ br.Msg = "[" + permissionName + "]已设置付费套餐[" + dbProduct.Title + "],请重新选择"
|
|
|
+ br.ErrMsg = "[" + permissionName + "]已设置付费套餐[" + dbProduct.Title + "],请重新选择"
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ br.Msg = "该产品已设置付费,请刷新后重试"
|
|
|
+ br.ErrMsg = "该产品已设置付费,请刷新后重试"
|
|
|
+ }
|
|
|
} else {
|
|
|
utils.FileLog.Error("新增产品失败,err:" + err.Error())
|
|
|
br.Msg = "新增产品失败"
|
|
@@ -350,6 +397,123 @@ func (this *ProductController) DeleteProduct() {
|
|
|
br.Success = true
|
|
|
}
|
|
|
|
|
|
+// ProductList
|
|
|
+// @Title 产品列表
|
|
|
+// @Description pdf研报列表
|
|
|
+// @Param PageSize query int true "每页数据条数"
|
|
|
+// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
+// @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
|
|
|
+// @Param KeyWord query string true "报告标题/创建人"
|
|
|
+// @Param SortType query string true "排序方式"
|
|
|
+// @Success 200 {object} models.ReportAuthorResp
|
|
|
+// @router /productList [get]
|
|
|
+func (this *ProductController) ProductList() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ pageSize, _ := this.GetInt("PageSize")
|
|
|
+ currentIndex, _ := this.GetInt("CurrentIndex")
|
|
|
+ sortType := this.GetString("SortType")
|
|
|
+ KeyWord := this.GetString("KeyWord")
|
|
|
+ CreatedTime := this.GetString("CreatedTime")
|
|
|
+ UpdatedTime := this.GetString("UpdatedTime")
|
|
|
+ IsSingle, _ := this.GetBool("IsSingle", true)
|
|
|
+ ProductType := this.GetString("ProductType")
|
|
|
+ SaleStatus := this.GetString("SaleStatus")
|
|
|
+ var condition string
|
|
|
+ if pageSize <= 0 {
|
|
|
+ pageSize = utils.PageSize20
|
|
|
+ }
|
|
|
+ if currentIndex <= 0 {
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+ if KeyWord != "" {
|
|
|
+ condition += " AND title like '%" + KeyWord + "%'"
|
|
|
+ }
|
|
|
+ sortCondition := " ORDER BY created_time "
|
|
|
+ if sortType == "" {
|
|
|
+ sortType = "DESC"
|
|
|
+ }
|
|
|
+ if CreatedTime != "" {
|
|
|
+ condition += " AND Date(created_time) = '" + CreatedTime + "'"
|
|
|
+ }
|
|
|
+ if UpdatedTime != "" {
|
|
|
+ condition += " AND Date(updated_time) = '" + UpdatedTime + "'"
|
|
|
+ }
|
|
|
+ if SaleStatus != "" {
|
|
|
+ switch SaleStatus {
|
|
|
+ case "onSale":
|
|
|
+ condition += " AND sale_status='on_sale'"
|
|
|
+ case "offSale":
|
|
|
+ condition += " AND sale_status='off_sale'"
|
|
|
+ default:
|
|
|
+ br.Msg = "无效的销售状态"
|
|
|
+ br.ErrMsg = "无效的销售状态:" + SaleStatus
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if IsSingle {
|
|
|
+ if ProductType != "" {
|
|
|
+ switch ProductType {
|
|
|
+ case "report":
|
|
|
+ condition += " AND type='" + string(models.ProductReport) + "'"
|
|
|
+ case "audio":
|
|
|
+ condition += " AND type='" + string(models.ProductAudio) + "'"
|
|
|
+ case "video":
|
|
|
+ condition += " AND type='" + string(models.ProductVideo) + "'"
|
|
|
+ default:
|
|
|
+ br.Msg = "无效的产品类型"
|
|
|
+ br.ErrMsg = "无效的产品类型:" + ProductType
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ condition += " AND type = '" + string(models.ProductPackage) + "'"
|
|
|
+ }
|
|
|
+ sortCondition = sortCondition + sortType
|
|
|
+ total, err := models.GetProductCountByCondition(condition)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取产品列表失败"
|
|
|
+ br.ErrMsg = "获取产品列表失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ startSize := utils.StartIndex(currentIndex, pageSize)
|
|
|
+ List, err := models.GetProductByCondition(condition, sortCondition, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取产品列表失败"
|
|
|
+ br.ErrMsg = "获取产品列表失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var ListView []*services.ProductView
|
|
|
+ for _, product := range List {
|
|
|
+ view := &services.ProductView{
|
|
|
+ ProductName: product.Title,
|
|
|
+ ProductType: CNProductMap[product.Type],
|
|
|
+ PublishedTime: product.CreatedTime.Format(time.DateTime),
|
|
|
+ RiskLevel: product.RiskLevel,
|
|
|
+ Price: fmt.Sprintf("¥%s", product.Price),
|
|
|
+ SaleStatus: CNSaleStatusMap[product.SaleStatus],
|
|
|
+ }
|
|
|
+ if !product.UpdatedTime.IsZero() {
|
|
|
+ view.UpdatedTime = product.UpdatedTime.Format(time.DateTime)
|
|
|
+ }
|
|
|
+ ListView = append(ListView, view)
|
|
|
+ }
|
|
|
+ page := paging.GetPaging(currentIndex, pageSize, total)
|
|
|
+ resp := new(response.ProductListResp)
|
|
|
+ resp.List = ListView
|
|
|
+ resp.Paging = page
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Data = resp
|
|
|
+ br.Msg = "获取成功"
|
|
|
+}
|
|
|
+
|
|
|
//
|
|
|
//// OnSale @Title 上架产品
|
|
|
//// @Description 上架产品
|