|
|
package evaluation
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
mysql2 "git.oa00.com/go/mysql"
|
|
|
"github.com/golangkit/formatime"
|
|
|
"gorm.io/gorm"
|
|
|
"log"
|
|
|
"recook/internal/dbc"
|
|
|
"recook/internal/libs/bean"
|
|
|
"recook/internal/model/goods"
|
|
|
"recook/internal/v2/model/gys/enterprise"
|
|
|
"recook/internal/v2/model/live"
|
|
|
goods2 "recook/internal/v2/model/recook/goods"
|
|
|
manage "recook/internal/v2/model/recook/order"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
type logic struct {
|
|
|
}
|
|
|
|
|
|
var EvaLogic = &logic{}
|
|
|
|
|
|
/*评价审核逻辑层*/
|
|
|
type momentsCopy struct {
|
|
|
ID uint `gorm:"column:id;primary_key" json:"id"`
|
|
|
GoodsID uint `gorm:"column:goods_id" json:"goodsId"`
|
|
|
Text string `gorm:"column:text" json:"text"`
|
|
|
UserID uint `gorm:"column:user_id" json:"userId"`
|
|
|
HeadImgURL string `gorm:"column:head_img_url" json:"headImgUrl"`
|
|
|
Nickname string `gorm:"column:nickname" json:"nickname"`
|
|
|
Reviewing uint `gorm:"column:reviewing" json:"reviewing"` // 1 审核中, 0 审核通过, 2 拒绝
|
|
|
CreatedAt formatime.Second `gorm:"column:created_at" json:"createdAt"`
|
|
|
ReasonID uint `gorm:"column:reason_id" json:"reasonId"`
|
|
|
ReasonNote string `gorm:"column:reason_note" json:"reasonNote"`
|
|
|
ManagerID int `gorm:"column:manager_id" json:"managerId"` // 审核人id(系统操作员)
|
|
|
Compliance int `gorm:"column:compliance" json:"compliance"` //合规
|
|
|
GoosName string `json:"goos_name"`
|
|
|
Emg string `json:"emg"`
|
|
|
}
|
|
|
type ImageAll struct {
|
|
|
Base momentsCopy `json:"base"`
|
|
|
Images []goods.MomentsCopyPhoto `json:"images"`
|
|
|
//Compliance goods.IsCompliance `json:"compliance"` //风险系数
|
|
|
}
|
|
|
|
|
|
func (l logic) SearchAll(title string, start string, end string, status int, security int, page bean.Page) (rest []ImageAll, total int64, err error) {
|
|
|
if security == 0 && status == 0 {
|
|
|
return nil, 0, errors.New("安全或审核状态必填其一")
|
|
|
}
|
|
|
|
|
|
where := mysql2.Db
|
|
|
|
|
|
if title != "" { //商品标题不为空,则查询该商品相关的产品id
|
|
|
var gg goods2.RecookGoodsInfoModel
|
|
|
var glist []uint //模糊查询关键字相关的商品list
|
|
|
dbc.DB.Table(gg.TableName()).Where("goods_name like ?", fmt.Sprintf("%%%s%%", title)).Pluck("id", &glist)
|
|
|
where = where.Where("goods_id in (?)", glist)
|
|
|
}
|
|
|
if start != "" && end != "" { //开始和结束时间不为空
|
|
|
ts, _ := time.ParseInLocation("2006-01-02 15:04:05", start, time.Local)
|
|
|
te, _ := time.ParseInLocation("2006-01-02 15:04:05", end, time.Local)
|
|
|
where = where.Where("created_at between ? and ?", ts, te)
|
|
|
}
|
|
|
//判断审核状态
|
|
|
if status != 0 {
|
|
|
if status == 1 { //待审核 ,区别安全和风险
|
|
|
//查出所以风险的idlist
|
|
|
if security == 1 { //1=安全 2=风险
|
|
|
//全部安全的,待审核的
|
|
|
where = where.Where("compliance=? and reviewing=? ", 0, 1)
|
|
|
} else if security == 2 {
|
|
|
//全部风险的,待审核的
|
|
|
where = where.Where("compliance=? and reviewing=?", 1, 1)
|
|
|
}
|
|
|
}
|
|
|
//判断驳回的内容
|
|
|
if status == 2 {
|
|
|
//查询审核为驳回的
|
|
|
where = where.Where("reviewing=?", 2)
|
|
|
|
|
|
}
|
|
|
if status == 3 {
|
|
|
//查询审核为通过的
|
|
|
where = where.Where("reviewing=?", 0)
|
|
|
}
|
|
|
}
|
|
|
var base []goods.MomentsCopy
|
|
|
//Reviewing uint `gorm:"column:reviewing" json:"reviewing"` // 1 审核中, 0 审核通过, 2 拒绝
|
|
|
var name goods.MomentsCopy
|
|
|
mysql2.Db.Table(name.TableName()).Where(where).Limit(page.GetLimit()).Offset(page.GetStart()).Order("id desc").Find(&base)
|
|
|
mysql2.Db.Table(name.TableName()).Where(where).Count(&total)
|
|
|
//获取需要展示的base部分,并且遍历,放入图片
|
|
|
var imagname goods.MomentsCopyPhoto
|
|
|
for _, v := range base {
|
|
|
var ims []goods.MomentsCopyPhoto
|
|
|
mysql2.Db.Table(imagname.TableName()).Where("moments_copy_id=?", v.ID).Find(&ims)
|
|
|
var goodsNa goods2.RecookGoodsInfoModel
|
|
|
mysql2.Db.Table(goodsNa.TableName()).Where("id=?", v.GoodsID).First(&goodsNa)
|
|
|
rest = append(rest, ImageAll{
|
|
|
Base: momentsCopy{
|
|
|
ID: v.ID,
|
|
|
GoodsID: v.GoodsID,
|
|
|
Text: v.Text,
|
|
|
UserID: v.UserID,
|
|
|
HeadImgURL: v.HeadImgURL,
|
|
|
Nickname: v.Nickname,
|
|
|
Reviewing: v.Reviewing,
|
|
|
CreatedAt: v.CreatedAt,
|
|
|
ReasonID: v.ReasonID,
|
|
|
ReasonNote: v.ReasonNote,
|
|
|
ManagerID: v.ManagerID,
|
|
|
Compliance: v.Compliance,
|
|
|
GoosName: goodsNa.GoodsName,
|
|
|
Emg: v.Emg,
|
|
|
},
|
|
|
Images: ims,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//审核通过和驳回
|
|
|
func (l logic) Pass(id uint, status uint) error {
|
|
|
if id == 0 {
|
|
|
return errors.New("id必传")
|
|
|
}
|
|
|
if status == 0 {
|
|
|
return errors.New("审核状态必传")
|
|
|
}
|
|
|
//开启事务
|
|
|
err := mysql2.Db.Transaction(func(tx *gorm.DB) error {
|
|
|
//更新主表的状态
|
|
|
if status == 1 { //驳回
|
|
|
a := goods.MomentsCopy{}
|
|
|
err := tx.Table(a.TableName()).Where("id=?", id).Update("reviewing", 2).Error
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
err = tx.Table("recook_user_trend").Where("trend_type=? and origin_id=?", 1, id).Update("is_show", 1).Error
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if status == 2 { //通过
|
|
|
a := goods.MomentsCopy{}
|
|
|
err := tx.Table(a.TableName()).Where("id=?", id).Update("reviewing", 0).Error
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
err = tx.Table("recook_user_trend").Where("trend_type=? and origin_id=?", 1, id).Update("is_show", 1).Error
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
})
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
type orderEvaRep struct {
|
|
|
Id uint `json:"id"`
|
|
|
GoodsId uint `json:"goods_id"`
|
|
|
OrderDetailId uint `json:"order_detail_id"`
|
|
|
EvaTime formatime.Second `json:"eva_time"`
|
|
|
NiceName string `json:"nice_name"`
|
|
|
GoodsName string `json:"goods_name"`
|
|
|
GysName string `json:"gys_name"`
|
|
|
Context string `json:"context"`
|
|
|
Status int `json:"status"`
|
|
|
Images []goods.EvaluationPhoto `json:"images"`
|
|
|
Emg string `json:"emg"`
|
|
|
}
|
|
|
|
|
|
//展示全部的评价搜索list
|
|
|
func (l logic) OrderEvaluation(goodsId uint, goodsName string, startTime string, endTime string, gysId uint, security int, status int, page bean.Page) (rest []orderEvaRep, total int64, e error) {
|
|
|
if status == 0 {
|
|
|
return nil, 0, errors.New("状态为必传项")
|
|
|
}
|
|
|
if status == 1 {
|
|
|
if security == 0 {
|
|
|
return nil, 0, errors.New("待审核必须穿安全或风险的类别")
|
|
|
}
|
|
|
}
|
|
|
where := mysql2.Db
|
|
|
if goodsId != 0 { //判断商品id是否为空
|
|
|
where = where.Where("goods_id=?", goodsId)
|
|
|
}
|
|
|
if goodsName != "" { //判断商品名称是否为空
|
|
|
var gl []uint
|
|
|
gif := goods2.RecookGoodsInfoModel{}
|
|
|
mysql2.Db.Table(gif.TableName()).Where("goods_name like ?", fmt.Sprintf("%%%s%%", goodsName)).Pluck("id", &gl)
|
|
|
where = where.Where("goods_id in(?)", gl)
|
|
|
}
|
|
|
if startTime != "" && endTime != "" { //判断居间时间
|
|
|
st, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime, time.Local)
|
|
|
et, _ := time.ParseInLocation("2006-01-02 15:04:05", endTime, time.Local)
|
|
|
where = where.Where("created_at between ? and ? ", st, et)
|
|
|
}
|
|
|
if gysId != 0 { //判断供应商id是否为空
|
|
|
var gl []uint
|
|
|
gif := goods2.RecookGoodsInfoModel{}
|
|
|
mysql2.Db.Table(gif.TableName()).Where("vendor_id=?", gysId).Pluck("id", &gl)
|
|
|
where = where.Where("goods_id in(?)", gl)
|
|
|
}
|
|
|
if status == 1 { //待审核
|
|
|
if security == 1 { //安全的 ,
|
|
|
where = where.Where("compliance=? and pass=?", 0, 0)
|
|
|
|
|
|
}
|
|
|
if security == 2 {
|
|
|
where = where.Where("compliance=? and pass=?", 1, 0)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if status == 2 { //驳回
|
|
|
where = where.Where("pass=?", 2)
|
|
|
}
|
|
|
if status == 3 { //通过
|
|
|
where = where.Where("pass=?", 1)
|
|
|
}
|
|
|
var eva goods.Evaluation
|
|
|
mysql2.Db.Table(eva.TableName()).Where(where).Count(&total)
|
|
|
var rgl []goods.Evaluation
|
|
|
mysql2.Db.Table(eva.TableName()).Where(where).Limit(page.GetLimit()).Offset(page.GetStart()).Find(&rgl)
|
|
|
for _, v := range rgl {
|
|
|
|
|
|
var oid manage.RecookOrderGoodsDetailModel
|
|
|
mysql2.Db.Table(oid.TableName()).Where("order_id=? and goods_id=?", v.OrderID, v.GoodsID).First(&oid)
|
|
|
var gys enterprise.GysEnterpriseStateModel
|
|
|
mysql2.Db.Table(gys.TableName()).Where("user_id=?", oid.VendorId).First(&gys)
|
|
|
var images []goods.EvaluationPhoto
|
|
|
var im goods.EvaluationPhoto
|
|
|
mysql2.Db.Table(im.TableName()).Where("evaluation_id=?", v.ID).Find(&images)
|
|
|
rest = append(rest, orderEvaRep{
|
|
|
Id: v.ID,
|
|
|
GoodsId: v.GoodsID,
|
|
|
OrderDetailId: oid.Id,
|
|
|
EvaTime: v.CreatedAt,
|
|
|
NiceName: v.Nickname,
|
|
|
GoodsName: oid.GoodsName,
|
|
|
Context: v.Content,
|
|
|
Status: v.Compliance,
|
|
|
Images: images,
|
|
|
Emg: v.Emg,
|
|
|
})
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//传入id 和 状态 审批
|
|
|
func (l logic) OrderEvaPass(id uint, status uint) error {
|
|
|
var oev goods.Evaluation
|
|
|
if id == 0 {
|
|
|
return errors.New("必须传入id")
|
|
|
}
|
|
|
if status == 0 {
|
|
|
return errors.New("必须传入审批结果")
|
|
|
}
|
|
|
|
|
|
if status == 2 { //通过
|
|
|
mysql2.Db.Table(oev.TableName()).Where("id=?", id).Update("pass", 1)
|
|
|
}
|
|
|
if status == 1 { //驳回
|
|
|
mysql2.Db.Table(oev.TableName()).Where("id=?", id).Update("pass", 2)
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//回显list
|
|
|
type shortList struct {
|
|
|
Id uint `json:"id"`
|
|
|
GoodsId uint `json:"goods_id"` //商品id
|
|
|
RelatedGoods string `json:"related_goods"` //关联商品
|
|
|
TopicId uint `json:"topic_id"` //话题id
|
|
|
CreatedAt formatime.Second `json:"created_at"` //创建时间
|
|
|
MediaUrl string `json:"media_url"` //视频地址
|
|
|
CoverUrl string `json:"cover_url"` //封面地址
|
|
|
Content string `json:"content"` //评价内容
|
|
|
TopicOfConversation string `json:"topic_of_conversation"` //话题
|
|
|
Emg string `json:"emg"`
|
|
|
}
|
|
|
|
|
|
//按条件展示短视频
|
|
|
func (l logic) ShortList(name string, conversation string, start string, end string, security int, status int, page bean.Page) (list []shortList, total int64, e error) {
|
|
|
|
|
|
where := mysql2.Db.Where("is_del=?", 0)
|
|
|
//商品名称条件不为空
|
|
|
if name != "" {
|
|
|
var gl []uint
|
|
|
mysql2.Db.Table((&goods2.RecookGoodsInfoModel{}).TableName()).Where("goods_name like ? ", fmt.Sprintf("%%%s%%", name)).Pluck("id", &gl)
|
|
|
where = where.Where("goods_id in (?)", gl)
|
|
|
}
|
|
|
//话题不为空
|
|
|
if conversation != "" {
|
|
|
var cl []uint
|
|
|
mysql2.Db.Table("recook_live_topic").Where("title like ?", fmt.Sprintf("%%%s%%", conversation)).Pluck("id", &cl)
|
|
|
where = where.Where("topic_id in (?)", cl)
|
|
|
}
|
|
|
//开始和结束时间不为空
|
|
|
if start != "" && end != "" {
|
|
|
log.Println(start, end)
|
|
|
t1, _ := time.ParseInLocation("2006-01-02 15:04:05", start, time.Local)
|
|
|
t2, _ := time.ParseInLocation("2006-01-02 15:04:05", end, time.Local)
|
|
|
log.Println(t1, t2)
|
|
|
where = where.Where("created_at between ? and ?", t1, t2)
|
|
|
}
|
|
|
//安全或风险 必须在状态为1时
|
|
|
|
|
|
if status == 0 {
|
|
|
return nil, 0, errors.New("必须传入审核状态!")
|
|
|
}
|
|
|
if status == 1 { //待审核
|
|
|
//pass 0=待审核,1=驳回,2=通过
|
|
|
where = where.Where("pass=0")
|
|
|
if security == 0 {
|
|
|
return nil, 0, errors.New("待审核时,必须安全或风险状态")
|
|
|
}
|
|
|
if security == 1 { //安全
|
|
|
where = where.Where("compliance=?", 0)
|
|
|
}
|
|
|
if security == 2 { //风险
|
|
|
where = where.Where("compliance=?", 1)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if status == 2 { //驳回
|
|
|
where = where.Where("pass=?", 1)
|
|
|
}
|
|
|
if status == 3 { //通过
|
|
|
where = where.Where("pass=?", 2)
|
|
|
}
|
|
|
var short live.Short
|
|
|
mysql2.Db.Table(short.TableName()).Where(where).Where("deleted is null").Count(&total)
|
|
|
mysql2.Db.Table(short.TableName()).Where(where).Where("deleted is null").Limit(page.GetLimit()).Offset(page.GetStart()).Find(&list)
|
|
|
for i, v := range list {
|
|
|
var g goods2.RecookGoodsInfoModel
|
|
|
mysql2.Db.Table(g.TableName()).Where("id=?", v.GoodsId).First(&g)
|
|
|
list[i].RelatedGoods = g.GoodsName
|
|
|
var title string
|
|
|
mysql2.Db.Table("recook_live_topic").Where("id=?", list[i].TopicId).Pluck("title", &title)
|
|
|
list[i].TopicOfConversation = title
|
|
|
}
|
|
|
|
|
|
return
|
|
|
}
|