exa_customer.go 5.2 KB
Newer Older
Mr.奇淼('s avatar
Mr.奇淼( 已提交
1
package v1
Mr.奇淼('s avatar
Mr.奇淼( 已提交
2 3 4

import (
	"fmt"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
5 6
	"gin-vue-admin/global/response"
	"gin-vue-admin/model"
7
	"gin-vue-admin/model/request"
8
	resp "gin-vue-admin/model/response"
9
	"gin-vue-admin/service"
10
	"gin-vue-admin/utils"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
11 12 13 14 15 16 17 18
	"github.com/gin-gonic/gin"
)

// @Tags SysApi
// @Summary 创建客户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
19
// @Param data body model.ExaCustomer true "创建客户"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
20
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
21
// @Router /customer/customer [post]
Mr.奇淼('s avatar
Mr.奇淼( 已提交
22
func CreateExaCustomer(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
23
	var cu model.ExaCustomer
24
	_ = c.ShouldBindJSON(&cu)
25 26 27 28 29 30 31 32 33 34 35
	CustomerVerify := utils.Rules{
		"CustomerName":      {utils.NotEmpty()},
		"CustomerPhoneData":      {utils.NotEmpty()},
		"SysUserID":      {utils.NotEmpty()},
		"SysUserAuthorityID":      {utils.NotEmpty()},
	}
	CustomerVerifyErr := utils.Verify(cu, CustomerVerify)
	if CustomerVerifyErr!=nil {
		response.FailWithMessage(CustomerVerifyErr.Error(), c)
		return
	}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
36
	claims, _ := c.Get("claims")
37
	waitUse := claims.(*request.CustomClaims)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
38 39
	cu.SysUserID = waitUse.ID
	cu.SysUserAuthorityID = waitUse.AuthorityId
40
	err := service.CreateExaCustomer(cu)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
41
	if err != nil {
42
		response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
43
	} else {
44
		response.OkWithMessage("创建成功", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
45 46 47 48 49 50 51 52
	}
}

// @Tags SysApi
// @Summary 删除客户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
53
// @Param data body model.ExaCustomer true "删除客户"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
54
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
55
// @Router /customer/customer [delete]
Mr.奇淼('s avatar
Mr.奇淼( 已提交
56
func DeleteExaCustomer(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
57
	var cu model.ExaCustomer
58
	_ = c.ShouldBindJSON(&cu)
59 60 61 62 63 64 65 66
	CustomerVerify := utils.Rules{
		"ID":      {utils.NotEmpty()},
	}
	CustomerVerifyErr := utils.Verify(cu.Model, CustomerVerify)
	if CustomerVerifyErr!=nil {
		response.FailWithMessage(CustomerVerifyErr.Error(), c)
		return
	}
67
	err := service.DeleteExaCustomer(cu)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
68
	if err != nil {
69
		response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
70
	} else {
71
		response.OkWithMessage("删除成功", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
72 73 74 75 76 77 78 79
	}
}

// @Tags SysApi
// @Summary 更新客户信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
80
// @Param data body model.ExaCustomer true "创建客户"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
81
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
82
// @Router /customer/customer [put]
R
rainyan 已提交
83
func UpdateExaCustomer(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
84
	var cu model.ExaCustomer
85
	_ = c.ShouldBindJSON(&cu)
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
	IdCustomerVerify := utils.Rules{
		"ID":      {utils.NotEmpty()},
	}
	IdCustomerVerifyErr := utils.Verify(cu.Model, IdCustomerVerify)
	if IdCustomerVerifyErr!=nil {
		response.FailWithMessage(IdCustomerVerifyErr.Error(), c)
		return
	}
	CustomerVerify := utils.Rules{
		"CustomerName":      {utils.NotEmpty()},
		"CustomerPhoneData":      {utils.NotEmpty()},
		"SysUserID":      {utils.NotEmpty()},
		"SysUserAuthorityID":      {utils.NotEmpty()},
	}
	CustomerVerifyErr := utils.Verify(cu, CustomerVerify)
	if CustomerVerifyErr!=nil {
		response.FailWithMessage(CustomerVerifyErr.Error(), c)
		return
	}
105
	err := service.UpdateExaCustomer(&cu)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
106
	if err != nil {
107
		response.FailWithMessage(fmt.Sprintf("更新失败:%v", err), c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
108
	} else {
109
		response.OkWithMessage("更新成功", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
110 111 112 113 114 115 116 117
	}
}

// @Tags SysApi
// @Summary 获取单一客户信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
118
// @Param data body model.ExaCustomer true "获取单一客户信息"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
119
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
120
// @Router /customer/customer [get]
Mr.奇淼('s avatar
Mr.奇淼( 已提交
121
func GetExaCustomer(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
122
	var cu model.ExaCustomer
123
	_ = c.ShouldBindQuery(&cu)
124 125 126 127 128 129 130 131
	IdCustomerVerify := utils.Rules{
		"ID":      {utils.NotEmpty()},
	}
	IdCustomerVerifyErr := utils.Verify(cu.Model, IdCustomerVerify)
	if IdCustomerVerifyErr!=nil {
		response.FailWithMessage(IdCustomerVerifyErr.Error(), c)
		return
	}
132
	err, customer := service.GetExaCustomer(cu.ID)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
133
	if err != nil {
134
		response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
135
	} else {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
136
		response.OkWithData(resp.ExaCustomerResponse{Customer: customer}, c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
137 138 139 140 141 142 143 144
	}
}

// @Tags SysApi
// @Summary 获取权限客户列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
Mr.奇淼('s avatar
Mr.奇淼( 已提交
145
// @Param data body request.PageInfo true "获取权限客户列表"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
146
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
147
// @Router /customer/customerList [get]
Mr.奇淼('s avatar
Mr.奇淼( 已提交
148 149
func GetExaCustomerList(c *gin.Context) {
	claims, _ := c.Get("claims")
150 151
	waitUse := claims.(*request.CustomClaims)
	var pageInfo request.PageInfo
152
	_ = c.ShouldBindQuery(&pageInfo)
153 154 155 156 157 158 159 160 161
	CustomerVerify := utils.Rules{
		"Page": {utils.NotEmpty()},
		"PageSize": {utils.NotEmpty()},
	}
	CustomerVerifyErr := utils.Verify(pageInfo, CustomerVerify)
	if CustomerVerifyErr!=nil {
		response.FailWithMessage(CustomerVerifyErr.Error(), c)
		return
	}
162
	err, customerList, total := service.GetCustomerInfoList(waitUse.AuthorityId, pageInfo)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
163
	if err != nil {
164
		response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
165
	} else {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
166 167 168 169 170 171
		response.OkWithData(resp.PageResult{
			List:     customerList,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
172
	}
173
}