You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
592 lines
20 KiB
592 lines
20 KiB
package order
|
|
|
|
import (
|
|
"fmt"
|
|
"recook/internal/back"
|
|
"recook/internal/dbc"
|
|
"recook/internal/model/aftersales"
|
|
"recook/internal/model/goods"
|
|
"recook/internal/model/manage"
|
|
"recook/internal/model/order"
|
|
"recook/internal/model/user"
|
|
"recook/tools"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/golangkit/formatime"
|
|
"github.com/jinzhu/gorm"
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
func QueryOrderCateCount(c *gin.Context) {
|
|
var p queryOrderListParam
|
|
if err := tools.Params(&p, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
where := ""
|
|
if p.ShippingMethod == 1 {
|
|
where = "shipping_method = 1"
|
|
} else {
|
|
where = "shipping_method = 0"
|
|
}
|
|
|
|
//获取供应商
|
|
gys_token := c.Request.Header.Get("X-Recook-GYSToken")
|
|
gysId, _ := dbc.Rds.Get(gys_token).Result()
|
|
myGysId, _ := strconv.Atoi(gysId)
|
|
|
|
if myGysId > 0 {
|
|
p.VendorID = uint(myGysId)
|
|
where += " and vendor_id = " + gysId
|
|
}
|
|
|
|
var totalCount uint
|
|
// AND store_id = 0
|
|
dbc.DB.Table((&order.GoodsDetail{}).TableName()).Where(where).Where("pay_status = 1 AND (ass_type = 0 or (recook_order_goods_detail.ass_type != 0 and recook_order_goods_detail.is_closed=1))").Count(&totalCount)
|
|
|
|
var noShipCount uint
|
|
dbc.DB.Table((&order.GoodsDetail{}).TableName()).Where(where).Where("pay_status = 1 AND (ass_type = 0 or (recook_order_goods_detail.ass_type != 0 and recook_order_goods_detail.is_closed=1)) AND express_status = 0 AND date_add( recook_order_goods_detail.order_time, INTERVAL 2 DAY )> now()").Count(&noShipCount)
|
|
|
|
var shipCount uint
|
|
dbc.DB.Table((&order.GoodsDetail{}).TableName()).Where(where).Where("pay_status = 1 AND (ass_type = 0 or (recook_order_goods_detail.ass_type != 0 and recook_order_goods_detail.is_closed=1)) AND express_status = 1 ").Count(&shipCount)
|
|
|
|
var finishCount uint
|
|
dbc.DB.Table((&order.GoodsDetail{}).TableName()).Where(where).Where("pay_status = 1 AND (ass_type = 0 or (recook_order_goods_detail.ass_type != 0 and recook_order_goods_detail.is_closed=1)) AND status = 1").Count(&finishCount)
|
|
|
|
var outSendCount uint
|
|
dbc.DB.Table((&order.GoodsDetail{}).TableName()).Where(where).Where("pay_status = 1 AND (ass_type = 0 or (recook_order_goods_detail.ass_type != 0 and recook_order_goods_detail.is_closed=1)) AND express_status = 0 AND date_add( recook_order_goods_detail.order_time, INTERVAL 2 DAY )< now() ").Count(&outSendCount)
|
|
|
|
back.Suc(c, "操作成功", gin.H{
|
|
"totalCount": totalCount,
|
|
"noShipCount": noShipCount,
|
|
"shipCount": shipCount,
|
|
"finishCount": finishCount,
|
|
"outSendCount": outSendCount,
|
|
})
|
|
}
|
|
|
|
type queryOrderListParam struct {
|
|
Page uint `json:"page"`
|
|
Limit uint `json:"limit"`
|
|
Status uint `json:"status"`
|
|
OrderID uint `json:"orderId"`
|
|
VendorID uint `json:"vendorId"`
|
|
UserName string `json:"userName"`
|
|
UserPhone string `json:"userPhone"`
|
|
StartDate string `json:"startDate"`
|
|
EndDate string `json:"endDate"`
|
|
ShippingMethod int `json:"shipping_method"`
|
|
SkuCode string `json:"skuCode"`
|
|
SendStartDate string `json:"sendStartDate"`
|
|
SendEndDate string `json:"sendEndDate"`
|
|
ExpressNo string `json:"expressNo"`
|
|
}
|
|
|
|
type orderListResp struct {
|
|
ID uint `gorm:"column:id;primary_key" json:"goodsDetailId"`
|
|
OrderID uint `gorm:"column:order_id" json:"orderId"`
|
|
VendorID uint `gorm:"column:vendor_id" json:"vendorId"` // 供应商ID: 0表示自营
|
|
VendorName string `gorm:"column:vendorName" json:"vendorName"`
|
|
GoodsID uint `gorm:"column:goods_id" json:"goodsId"` // 商品ID
|
|
GoodsName string `gorm:"column:goods_name" json:"goodsName"` // 商品名快照
|
|
SkuName string `gorm:"column:sku_name" json:"skuName"` // SKU名字组合起来
|
|
SkuCode string `gorm:"column:sku_code" json:"skuCode"` // 条形码或者编码
|
|
CateName string `gorm:"column:category_name" json:"cateName"`
|
|
MainPhotoURL string `gorm:"column:main_photo_url" json:"mainPhotoUrl"` // 主图快照 先读sku 没有则读取主图
|
|
UnitPrice decimal.Decimal `gorm:"column:unit_price" json:"unitPrice"` // 单价
|
|
Attribute string `json:"attribute"`
|
|
Quantity uint `gorm:"column:quantity" json:"quantity"` // 商品数量
|
|
ExpressStatus uint `gorm:"column:express_status" json:"expressStatus"`
|
|
ExpressCompName string `gorm:"column:express_comp_name" json:"expressCompName"`
|
|
ExpressCompCode string `gorm:"column:express_comp_code" json:"expressCompCode"`
|
|
ExpressNo string `gorm:"column:express_no" json:"expressNo"`
|
|
ShippingMethod uint `gorm:"column:shipping_method" json:"shippingMethod"` // 0快递 1自提
|
|
StoreID uint `gorm:"column:store_id" json:"-"`
|
|
CreatedAt formatime.Second `gorm:"column:created_at" json:"createdAt"` // 创建时间
|
|
CompletedAt formatime.Second `gorm:"column:completed_at" json:"completedAt"` // 完成时间
|
|
BuyerMessage string `gorm:"column:buyer_message" json:"buyerMessage"` // 买家留言
|
|
Address order.Addr `json:"address"`
|
|
Status uint `json:"status" gorm:"-"`
|
|
PurchasePrice decimal.Decimal `json:"purchasePrice" gorm:"-"` //采购价
|
|
BrandName string `json:"brandName" gorm:"-"` //品牌
|
|
PayMethod uint `json:"payMethod" gorm:"-"` //支付方式
|
|
NeedSend formatime.Second `json:"needSend" gorm:"-"` //应发货时间
|
|
ReportMsg string `gorm:"report_msg" json:"reportMsg"` // 报备说明
|
|
Report int `gorm:"report" json:"report"` // 是否报备 1=报备
|
|
}
|
|
|
|
// 拒绝售后理由
|
|
type afterReject struct {
|
|
OrderId uint `json:"orderID" validate:"numeric,required"`
|
|
OrderGoodsID uint `json:"orderGoodsID" validate:"numeric,required"`
|
|
ReasonID uint `json:"reasonId" validate:"numeric"`
|
|
Detail string `json:"detail" validate:"max=255"` // 存在详情理由, reasonid不传或者传0
|
|
}
|
|
|
|
func QueryOrderList(c *gin.Context) {
|
|
var p queryOrderListParam
|
|
if err := tools.Params(&p, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
//获取供应商
|
|
gys_token := c.Request.Header.Get("X-Recook-GYSToken")
|
|
gysId, _ := dbc.Rds.Get(gys_token).Result()
|
|
myGysId, _ := strconv.Atoi(gysId)
|
|
|
|
if myGysId > 0 {
|
|
p.VendorID = uint(myGysId)
|
|
}
|
|
|
|
var limit uint = 10
|
|
if p.Limit > 0 {
|
|
limit = p.Limit
|
|
}
|
|
//订单状态
|
|
where := ""
|
|
if p.Status == 1 {
|
|
where = "(recook_order_goods_detail.ass_type = 0 or (recook_order_goods_detail.ass_type != 0 and recook_order_goods_detail.is_closed=1))AND recook_order_goods_detail.express_status = 0 AND date_add( recook_order_goods_detail.order_time, INTERVAL 2 DAY )>now()"
|
|
} else if p.Status == 2 || p.Status == 3 {
|
|
where = "(recook_order_goods_detail.ass_type = 0 or (recook_order_goods_detail.ass_type != 0 and recook_order_goods_detail.is_closed=1)) AND recook_order_goods_detail.express_status = 1"
|
|
} else if p.Status == 4 {
|
|
where = "(recook_order_goods_detail.ass_type = 0 or (recook_order_goods_detail.ass_type != 0 and recook_order_goods_detail.is_closed=1)) AND recook_order_goods_detail.status = 1"
|
|
} else if p.Status == 5 {
|
|
where = "(recook_order_goods_detail.ass_type = 0 or (recook_order_goods_detail.ass_type != 0 and recook_order_goods_detail.is_closed=1))AND recook_order_goods_detail.express_status = 0 AND date_add( recook_order_goods_detail.order_time, INTERVAL 2 DAY )< now()"
|
|
} else {
|
|
where = "(recook_order_goods_detail.ass_type = 0 or (recook_order_goods_detail.ass_type != 0 and recook_order_goods_detail.is_closed=1))"
|
|
}
|
|
if p.StartDate != "" && p.EndDate != "" {
|
|
where += " and recook_order_goods_detail.order_time > '" + p.StartDate + "' and order_time < '" + p.EndDate + "'"
|
|
}
|
|
//去除未支付状况
|
|
// where += " and recook_order_goods_detail.status != 0 "
|
|
|
|
//sku编码
|
|
whereSku := "1=1"
|
|
if p.SkuCode != "" {
|
|
whereSku += " and recook_order_goods_detail.sku_code = " + p.SkuCode
|
|
}
|
|
|
|
//发货时间
|
|
whereExp := "1=1"
|
|
if p.SendStartDate != "" && p.SendEndDate != "" {
|
|
whereExp += " and recook_order_goods_express.express_time > '" + p.SendStartDate + "' and recook_order_goods_express.express_time < '" + p.SendEndDate + "'"
|
|
}
|
|
|
|
//快递单号
|
|
whereExpNo := "1=1"
|
|
if p.ExpressNo != "" {
|
|
whereExpNo += " and recook_order_goods_express.express_no = '" + p.ExpressNo + "'"
|
|
}
|
|
|
|
//收货地址
|
|
whereAddr := "1=1"
|
|
if p.UserName != "" {
|
|
whereAddr += " and recook_order_addr.receiver_name = '" + p.UserName + "'"
|
|
}
|
|
if p.UserPhone != "" {
|
|
whereAddr += " and recook_order_addr.mobile = '" + p.UserPhone + "'"
|
|
}
|
|
if p.ShippingMethod == 1 {
|
|
where += " and recook_order_goods_detail.shipping_method = 1"
|
|
} else {
|
|
where += " and recook_order_goods_detail.shipping_method = 0"
|
|
}
|
|
total := 0
|
|
dbc.DB.Order("recook_order_goods_detail.id desc").
|
|
Table("recook_order_goods_detail").Select("recook_order_goods_detail.*").
|
|
Joins("INNER JOIN recook_order_addr on recook_order_goods_detail.order_id = recook_order_addr.order_id").
|
|
Joins("LEfT JOIN recook_order_goods_express on recook_order_goods_express.order_goods_id = recook_order_goods_detail.id and recook_order_goods_express.order_id = recook_order_goods_detail.order_id ").
|
|
Where(where).Where(whereAddr).Where(whereExp).Where(whereExpNo).Where(whereSku).Where(order.GoodsDetail{
|
|
OrderID: p.OrderID,
|
|
VendorID: p.VendorID,
|
|
PayStatus: 1,
|
|
}).
|
|
Group("recook_order_goods_detail.id").
|
|
Count(&total)
|
|
|
|
var goodsList []order.GoodsDetail
|
|
dbc.DB.Limit(limit).Offset(p.Page*limit).Order("recook_order_goods_detail.id desc").
|
|
Table("recook_order_goods_detail").Select("recook_order_goods_detail.*").
|
|
Joins("INNER JOIN recook_order_addr on recook_order_goods_detail.order_id = recook_order_addr.order_id").
|
|
Joins("LEfT JOIN recook_order_goods_express on recook_order_goods_express.order_goods_id = recook_order_goods_detail.id and recook_order_goods_express.order_id = recook_order_goods_detail.order_id ").
|
|
Where(where).Where(whereAddr).Preload("Addr", whereAddr).Where(whereExpNo).Where(whereExp).Where(whereSku).
|
|
Group("recook_order_goods_detail.id").
|
|
Find(&goodsList, order.GoodsDetail{
|
|
OrderID: p.OrderID,
|
|
VendorID: p.VendorID,
|
|
PayStatus: 1,
|
|
})
|
|
|
|
//var goodsList []order.GoodsDetail
|
|
//dbc.DB.Limit(limit).Offset(p.Page*limit).Order("id desc").Preload("Addr", whereAddr).Where(where).Find(&goodsList, order.GoodsDetail{
|
|
// OrderID: p.OrderID,
|
|
// VendorID: p.VendorID,
|
|
// PayStatus: 1,
|
|
//})
|
|
var attribute goods.Attribute
|
|
var info order.Information
|
|
var sku goods.Sku
|
|
list := make([]orderListResp, 0, 0)
|
|
for _, v := range goodsList {
|
|
dbc.DB.Select("name").First(&attribute, "goods_id = ?", v.GoodsID)
|
|
dbc.DB.Select("completed_at,pay_method").First(&info, "id = ?", v.OrderID)
|
|
dbc.DB.Select("purchase_price").First(&sku, "id = ?", v.SkuID)
|
|
needSendInt := v.CreatedAt.Time.AddDate(0, 0, 2).Unix()
|
|
needSend := formatime.NewSecond(needSendInt)
|
|
list = append(list, orderListResp{
|
|
ID: v.ID,
|
|
OrderID: v.OrderID,
|
|
VendorID: v.VendorID,
|
|
VendorName: v.VendorName,
|
|
GoodsID: v.GoodsID,
|
|
GoodsName: v.GoodsName,
|
|
CateName: v.CategoryName,
|
|
SkuName: v.SkuName,
|
|
SkuCode: v.SkuCode,
|
|
MainPhotoURL: v.MainPhotoURL,
|
|
UnitPrice: v.UnitPrice,
|
|
Quantity: v.Quantity,
|
|
Attribute: attribute.Name,
|
|
CompletedAt: info.CompletedAt,
|
|
ExpressStatus: v.ExpressStatus,
|
|
ExpressCompName: v.ExpressCompName,
|
|
ExpressCompCode: v.ExpressCompCode,
|
|
ExpressNo: v.ExpressNo,
|
|
CreatedAt: v.OrderTime,
|
|
BuyerMessage: v.BuyerMessage,
|
|
Address: v.Addr,
|
|
Status: v.Status,
|
|
PurchasePrice: sku.PurchasePrice,
|
|
BrandName: v.BrandName,
|
|
PayMethod: info.PayMethod,
|
|
NeedSend: needSend,
|
|
ReportMsg: v.ReportMsg,
|
|
Report: v.Report,
|
|
})
|
|
}
|
|
|
|
back.Suc(c, "", gin.H{
|
|
"total": total,
|
|
"list": list,
|
|
})
|
|
}
|
|
|
|
type detailParam struct {
|
|
OrderID uint `json:"orderId" validate:"required"`
|
|
}
|
|
|
|
type orderDetailResp struct {
|
|
order.Information
|
|
Nickname string `gorm:"column:nickname" json:"nickname"`
|
|
Mobile string `gorm:"column:mobile" json:"mobile"`
|
|
Address order.Addr `json:"address"`
|
|
Coupons []order.CouponDetail `json:"coupons"`
|
|
GoodsList []order.GoodsDetail `json:"goodsList"`
|
|
AfterSalesGoodsList []aftersales.Goods `json:"afterSalesGoodsList"`
|
|
Invoice interface{} `json:"invoice"`
|
|
}
|
|
|
|
func QueryOrderDetail(c *gin.Context) {
|
|
var p detailParam
|
|
if err := tools.Params(&p, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
var info order.Information
|
|
dbc.DB.First(&info, p.OrderID)
|
|
var addr order.Addr
|
|
dbc.DB.First(&addr, "order_id = ?", p.OrderID)
|
|
var invoice order.Invoice
|
|
dbc.DB.First(&invoice, "order_id = ?", p.OrderID)
|
|
var userInfo user.Information
|
|
dbc.DB.Select("nickname, mobile").First(&userInfo, info.UserID)
|
|
|
|
one := &invoice
|
|
if one.ID == 0 {
|
|
one = nil
|
|
}
|
|
|
|
coupons := make([]order.CouponDetail, 0, 0)
|
|
dbc.DB.Find(&coupons, "order_id = ?", p.OrderID)
|
|
|
|
goodsList := make([]order.GoodsDetail, 0, 0)
|
|
dbc.DB.Find(&goodsList, "order_id = ?", p.OrderID)
|
|
|
|
afterSalesGoodsList := make([]aftersales.Goods, 0, 0)
|
|
dbc.DB.Order("id desc").Find(&afterSalesGoodsList, "order_id = ?", info.ID)
|
|
orderGoodsIds := []uint{}
|
|
for _, orderGoodsInfo := range goodsList {
|
|
orderGoodsIds = append(orderGoodsIds, orderGoodsInfo.ID)
|
|
}
|
|
|
|
goodsExpress := []order.GoodsExpress{}
|
|
dbc.DB.Model(&aftersales.Goods{}).Find(&goodsExpress, "order_goods_id in (?)", orderGoodsIds)
|
|
expressMap := map[uint]order.GoodsExpress{}
|
|
for _, express := range goodsExpress {
|
|
expressMap[express.OrderGoodsID] = express
|
|
}
|
|
for index, orderGoodsInfo := range goodsList {
|
|
goodsList[index].ExpressCompName = expressMap[orderGoodsInfo.ID].ExpressCompName
|
|
goodsList[index].ExpressNo = expressMap[orderGoodsInfo.ID].ExpressNo
|
|
}
|
|
|
|
back.Suc(c, "", orderDetailResp{
|
|
Information: info,
|
|
Nickname: userInfo.Nickname,
|
|
Mobile: userInfo.Mobile,
|
|
Address: addr,
|
|
Coupons: coupons,
|
|
GoodsList: goodsList,
|
|
AfterSalesGoodsList: afterSalesGoodsList,
|
|
Invoice: one,
|
|
})
|
|
}
|
|
|
|
type queryOrderReasonParam struct {
|
|
Page uint `json:"page"`
|
|
Limit uint `json:"limit"`
|
|
}
|
|
|
|
func QueryOrdeReason(c *gin.Context) {
|
|
var p queryOrderReasonParam
|
|
if err := tools.Params(&p, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
var limit uint = 10
|
|
if p.Limit > 0 {
|
|
limit = p.Limit
|
|
}
|
|
var list []order.Reason
|
|
dbc.DB.Limit(limit).Offset((p.Page - 1) * limit).Where("is_delete = 0").Order("id desc").Find(&list)
|
|
|
|
total := 0
|
|
dbc.DB.Table("recook_order_reason").Where("is_delete = 0").Count(&total)
|
|
|
|
back.Suc(c, "", gin.H{
|
|
"total": total,
|
|
"list": list,
|
|
})
|
|
}
|
|
|
|
type reasonAddRequestParm struct {
|
|
Detail string `json:"detail" validate:"max=255"`
|
|
Type uint `json:"type"`
|
|
}
|
|
|
|
// 添加
|
|
func AddReasons(c *gin.Context) {
|
|
var p reasonAddRequestParm
|
|
err := tools.Params(&p, c)
|
|
if err != nil {
|
|
back.Fail(c, "参数错误:"+err.Error())
|
|
return
|
|
}
|
|
|
|
var reason order.Reason
|
|
reason.Content = p.Detail
|
|
reason.Type = p.Type
|
|
|
|
fmt.Println(reason)
|
|
|
|
if err = dbc.DB.Create(&reason).Error; err != nil {
|
|
back.Fail(c, "创建错误:"+err.Error())
|
|
return
|
|
}
|
|
|
|
back.Suc(c, "操作成功", nil)
|
|
return
|
|
}
|
|
|
|
type reasonUpdateRequestParm struct {
|
|
Detail string `json:"detail" validate:"max=255"`
|
|
ID int `json:"id"`
|
|
Type uint `json:"type"`
|
|
}
|
|
|
|
// 修改
|
|
func UpdateReasons(c *gin.Context) {
|
|
var p reasonUpdateRequestParm
|
|
err := tools.Params(&p, c)
|
|
if err != nil {
|
|
back.Fail(c, "参数错误:"+err.Error())
|
|
return
|
|
}
|
|
var userId = c.MustGet("Manager_ID").(uint)
|
|
|
|
var user manage.UserInfo
|
|
user.ID = userId
|
|
// 理论上这里需要鉴权
|
|
if err := dbc.DB.Find(&user).Error; err == gorm.ErrRecordNotFound {
|
|
back.Fail(c, "不存在此用户"+err.Error())
|
|
return
|
|
}
|
|
|
|
if err = dbc.DB.Model(&order.Reason{}).Where("id=?", p.ID).Updates(order.Reason{Content: p.Detail, Type: p.Type}).Error; err != nil {
|
|
back.Fail(c, "数据异常:"+err.Error())
|
|
return
|
|
}
|
|
|
|
back.Suc(c, "操作成功", nil)
|
|
return
|
|
}
|
|
|
|
type reasonDelRequestParm struct {
|
|
ReasonID int `json:"reasonId" validate:"numeric"`
|
|
}
|
|
|
|
func DeleteReasons(c *gin.Context) {
|
|
var p reasonDelRequestParm
|
|
err := tools.Params(&p, c)
|
|
if err != nil {
|
|
back.Fail(c, "参数错误:"+err.Error())
|
|
return
|
|
}
|
|
|
|
var userId = c.MustGet("Manager_ID").(uint)
|
|
|
|
var user manage.UserInfo
|
|
user.ID = userId
|
|
// 理论上这里需要鉴权
|
|
if err := dbc.DB.Find(&user).Error; err == gorm.ErrRecordNotFound {
|
|
back.Fail(c, "不存在此用户"+err.Error())
|
|
return
|
|
}
|
|
|
|
var reason order.Reason
|
|
reason.ID = uint(p.ReasonID)
|
|
|
|
if err = dbc.DB.Model(&reason).Update("is_delete", 1).Error; err != nil {
|
|
back.Fail(c, "删除错误:"+err.Error())
|
|
return
|
|
}
|
|
|
|
back.Suc(c, "操作成功", nil)
|
|
return
|
|
}
|
|
|
|
// 售后驳回理由
|
|
func QueryOrdeAfterReason(c *gin.Context) {
|
|
var p queryOrderReasonParam
|
|
if err := tools.Params(&p, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
var limit uint = 10
|
|
if p.Limit > 0 {
|
|
limit = p.Limit
|
|
}
|
|
var list []order.AfterReason
|
|
dbc.DB.Limit(limit).Offset((p.Page - 1) * limit).Where("is_delete = 0").Order("id desc").Find(&list)
|
|
|
|
total := 0
|
|
dbc.DB.Table("recook_order_after_reason").Where("is_delete = 0").Count(&total)
|
|
|
|
back.Suc(c, "", gin.H{
|
|
"total": total,
|
|
"list": list,
|
|
})
|
|
}
|
|
|
|
// 售后驳回列表
|
|
func QueryOrdeAfterReasonShow(c *gin.Context) {
|
|
|
|
var list []order.AfterReason
|
|
if dbc.DB.Where("is_delete = 0").Order("id desc").Find(&list).RecordNotFound() {
|
|
back.Fail(c, "未找到售后驳回信息")
|
|
return
|
|
}
|
|
total := 0
|
|
dbc.DB.Table("recook_order_after_reason").Where("is_delete = 0").Count(&total)
|
|
|
|
back.Suc(c, "", gin.H{
|
|
"total": total,
|
|
"list": list,
|
|
})
|
|
}
|
|
|
|
// 添加售后驳回理由
|
|
func AddAfterReasons(c *gin.Context) {
|
|
var p reasonAddRequestParm
|
|
err := tools.Params(&p, c)
|
|
if err != nil {
|
|
back.Fail(c, "参数错误:"+err.Error())
|
|
return
|
|
}
|
|
|
|
var reason order.AfterReason
|
|
reason.Content = p.Detail
|
|
reason.Type = 1
|
|
|
|
if err = dbc.DB.Create(&reason).Error; err != nil {
|
|
back.Fail(c, "创建错误:"+err.Error())
|
|
return
|
|
}
|
|
|
|
back.Suc(c, "操作成功", nil)
|
|
return
|
|
}
|
|
|
|
// 修改售后驳回理由
|
|
func UpdateAfterReasons(c *gin.Context) {
|
|
var p reasonUpdateRequestParm
|
|
err := tools.Params(&p, c)
|
|
if err != nil {
|
|
back.Fail(c, "参数错误:"+err.Error())
|
|
return
|
|
}
|
|
var userId = c.MustGet("Manager_ID").(uint)
|
|
|
|
var user manage.UserInfo
|
|
user.ID = userId
|
|
// 理论上这里需要鉴权
|
|
if err := dbc.DB.Find(&user).Error; err == gorm.ErrRecordNotFound {
|
|
back.Fail(c, "不存在此用户"+err.Error())
|
|
return
|
|
}
|
|
|
|
if err = dbc.DB.Model(&order.AfterReason{}).Where("id=?", p.ID).Update("content", p.Detail).Error; err != nil {
|
|
back.Fail(c, "数据异常:"+err.Error())
|
|
return
|
|
}
|
|
|
|
back.Suc(c, "操作成功", nil)
|
|
return
|
|
}
|
|
|
|
//删除售后驳回理由
|
|
func DeleteAfterReasons(c *gin.Context) {
|
|
var p reasonDelRequestParm
|
|
err := tools.Params(&p, c)
|
|
if err != nil {
|
|
back.Fail(c, "参数错误:"+err.Error())
|
|
return
|
|
}
|
|
|
|
var userId = c.MustGet("Manager_ID").(uint)
|
|
|
|
var user manage.UserInfo
|
|
user.ID = userId
|
|
// 理论上这里需要鉴权
|
|
if err := dbc.DB.Find(&user).Error; err == gorm.ErrRecordNotFound {
|
|
back.Fail(c, "不存在此用户"+err.Error())
|
|
return
|
|
}
|
|
|
|
var reason order.AfterReason
|
|
reason.ID = uint(p.ReasonID)
|
|
|
|
if err = dbc.DB.Model(&reason).Update("is_delete", 1).Error; err != nil {
|
|
back.Fail(c, "删除错误:"+err.Error())
|
|
return
|
|
}
|
|
|
|
back.Suc(c, "操作成功", nil)
|
|
return
|
|
}
|