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.
78 lines
2.3 KiB
78 lines
2.3 KiB
package couponusers
|
|
|
|
import (
|
|
"CouponBackendGo/api/v1/couponusers"
|
|
"CouponBackendGo/internal/model/dto"
|
|
"CouponBackendGo/internal/service"
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
"mime/multipart"
|
|
)
|
|
|
|
type CouponUsers struct{}
|
|
|
|
func NewCouponUsers() *CouponUsers {
|
|
return &CouponUsers{}
|
|
}
|
|
|
|
func (c *CouponUsers) GetCouponUsers(r *ghttp.Request) {
|
|
var req *couponusers.GetCouponUsersReq
|
|
if err := r.Parse(&req); err != nil {
|
|
r.Response.WriteJsonExit(dto.Error(err.Error()))
|
|
}
|
|
result, err := service.CouponUsers().GetCouponUsersByCondition(r.Context(), req.CouponId, req.Jwcode, req.Name)
|
|
if err != nil {
|
|
r.Response.WriteJsonExit(dto.Error(err.Error()))
|
|
}
|
|
if result == nil {
|
|
r.Response.WriteJsonExit(dto.Error("没有符合条件的用户"))
|
|
}
|
|
r.Response.WriteJsonExit(dto.SuccessWithData(result))
|
|
|
|
}
|
|
|
|
func (c *CouponUsers) DeleteCouponUserByJwcode(r *ghttp.Request) {
|
|
var req *couponusers.DelCouponUserByJwcodeReq
|
|
if err := r.Parse(&req); err != nil {
|
|
r.Response.WriteJsonExit(dto.Error(err.Error()))
|
|
}
|
|
result, err := service.CouponUsers().DeleteCouponUserByJwcode(r.Context(), req.CouponId, req.Jwcode)
|
|
if err != nil {
|
|
r.Response.WriteJsonExit(dto.Error(err.Error()))
|
|
}
|
|
affected, err := result.RowsAffected()
|
|
if affected == 0 {
|
|
r.Response.WriteJsonExit(dto.Error("删除失败,删除了0条"))
|
|
}
|
|
r.Response.WriteJsonExit(dto.SuccessWithMsg("删除成功"))
|
|
//r.Response.WriteJsonExit(dto.SuccessWithData(result))
|
|
}
|
|
|
|
// 待测试
|
|
// 接受前端传来的excel表格,并解析,返回jwcode切片,可以有重复的,在插入时进行验证,如果有重复的,只插入一次
|
|
func (c *CouponUsers) InsertJwcodeByExcel(r *ghttp.Request) {
|
|
|
|
// 从请求中获取文件
|
|
file, _, err := r.FormFile("excelFile")
|
|
if err != nil {
|
|
r.Response.WriteJsonExit(dto.Error(err.Error()))
|
|
}
|
|
// 关闭文件
|
|
defer func(file multipart.File) {
|
|
err := file.Close()
|
|
if err != nil {
|
|
// 处理关闭文件时的错误
|
|
r.Response.WriteJsonExit(dto.Error("关闭文件失败"))
|
|
}
|
|
}(file)
|
|
|
|
//参数校验,检查文件是否为空
|
|
if file == nil {
|
|
r.Response.WriteJsonExit(dto.Error("文件为空"))
|
|
}
|
|
|
|
jwcodes, err := service.CouponUsers().InsertJwcodeByExcel(file)
|
|
if err != nil {
|
|
r.Response.WriteJsonExit(dto.Error(err.Error()))
|
|
}
|
|
r.Response.WriteJsonExit(dto.SuccessWithData(jwcodes))
|
|
}
|