@@ -0,0 +1,19 @@ | |||||
package enum | |||||
type StaffSex int32 | |||||
const ( | |||||
StaffSexForMan = 1 | |||||
StaffSexForWomen = 2 | |||||
) | |||||
func (gt StaffSex) String() string { | |||||
switch gt { | |||||
case StaffSexForMan: | |||||
return "男" | |||||
case StaffSexForWomen: | |||||
return "女" | |||||
default: | |||||
return "未知" | |||||
} | |||||
} |
@@ -0,0 +1,147 @@ | |||||
package hdl | |||||
import ( | |||||
"applet/app/admin/enum" | |||||
"applet/app/admin/lib/validate" | |||||
"applet/app/admin/md" | |||||
"applet/app/db" | |||||
"applet/app/db/model" | |||||
"applet/app/e" | |||||
"github.com/gin-gonic/gin" | |||||
"time" | |||||
) | |||||
func StaffList(c *gin.Context) { | |||||
var req md.StaffListReq | |||||
err := c.ShouldBindJSON(&req) | |||||
if err != nil { | |||||
err = validate.HandleValidateErr(err) | |||||
err1 := err.(e.E) | |||||
e.OutErr(c, err1.Code, err1.Error()) | |||||
return | |||||
} | |||||
staffDb := db.StaffDb{} | |||||
staffDb.Set() | |||||
engine := staffDb.Db.Desc("id").Limit(req.Limit, (req.Page-1)*req.Limit) | |||||
if req.Name != "" { | |||||
engine.And("name like ?", "%"+req.Name+"%") | |||||
} | |||||
if req.IdNo != "" { | |||||
engine.And("id_no like ?", "%"+req.IdNo+"%") | |||||
} | |||||
if req.Phone != "" { | |||||
engine.And("phone like ?", "%"+req.Phone+"%") | |||||
} | |||||
var list []model.Staff | |||||
count, err := engine.FindAndCount(&list) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
return | |||||
} | |||||
e.OutSuc(c, map[string]interface{}{ | |||||
"list": list, | |||||
"state": []map[string]interface{}{ | |||||
{ | |||||
"name": enum.StaffSex(enum.StaffSexForMan).String(), | |||||
"value": enum.StaffSexForMan, | |||||
}, | |||||
{ | |||||
"name": enum.StaffSex(enum.StaffSexForWomen).String(), | |||||
"value": enum.StaffSexForWomen, | |||||
}, | |||||
}, | |||||
"total": count, | |||||
}, nil) | |||||
return | |||||
} | |||||
func StaffDelete(c *gin.Context) { | |||||
var req md.StaffDeleteReq | |||||
err := c.ShouldBindJSON(&req) | |||||
if err != nil { | |||||
err = validate.HandleValidateErr(err) | |||||
err1 := err.(e.E) | |||||
e.OutErr(c, err1.Code, err1.Error()) | |||||
return | |||||
} | |||||
staffDb := db.StaffDb{} | |||||
staffDb.Set() | |||||
_, err = staffDb.StaffDelete(req.Ids) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
return | |||||
} | |||||
e.OutSuc(c, "success", nil) | |||||
return | |||||
} | |||||
func StaffAdd(c *gin.Context) { | |||||
var req md.StaffAddReq | |||||
err := c.ShouldBindJSON(&req) | |||||
if err != nil { | |||||
err = validate.HandleValidateErr(err) | |||||
err1 := err.(e.E) | |||||
e.OutErr(c, err1.Code, err1.Error()) | |||||
return | |||||
} | |||||
staffDb := db.StaffDb{} | |||||
staffDb.Set() | |||||
now := time.Now() | |||||
staff := model.Staff{ | |||||
Name: req.Name, | |||||
Sex: req.Sex, | |||||
IdNo: req.IdNo, | |||||
Phone: req.Phone, | |||||
NativePlace: req.NativePlace, | |||||
Department: req.Department, | |||||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||||
} | |||||
_, err = staffDb.StaffInsert(&staff) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
return | |||||
} | |||||
e.OutSuc(c, "success", nil) | |||||
return | |||||
} | |||||
func StaffUpdate(c *gin.Context) { | |||||
var req md.StaffUpdateReq | |||||
err := c.ShouldBindJSON(&req) | |||||
if err != nil { | |||||
err = validate.HandleValidateErr(err) | |||||
err1 := err.(e.E) | |||||
e.OutErr(c, err1.Code, err1.Error()) | |||||
return | |||||
} | |||||
staffDb := db.StaffDb{} | |||||
staffDb.Set() | |||||
staff, err := staffDb.GetStaff(req.Id) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
return | |||||
} | |||||
if staff == nil { | |||||
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") | |||||
return | |||||
} | |||||
now := time.Now() | |||||
staff.Name = req.Name | |||||
staff.Sex = req.Sex | |||||
staff.IdNo = req.IdNo | |||||
staff.Phone = req.Phone | |||||
staff.NativePlace = req.NativePlace | |||||
staff.Department = req.Department | |||||
staff.UpdateAt = now.Format("2006-01-02 15:04:05") | |||||
_, err = staffDb.StaffUpdate(staff, "name", "sex", "id_no", "phone", "native_place", "department", "update_at") | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
return | |||||
} | |||||
e.OutSuc(c, "success", nil) | |||||
return | |||||
} |
@@ -9,6 +9,10 @@ func OrderList(c *gin.Context) { | |||||
order.OrderList(c) | order.OrderList(c) | ||||
} | } | ||||
func OrderExport(c *gin.Context) { | |||||
order.OrderExport(c) | |||||
} | |||||
func OrderTotal(c *gin.Context) { | func OrderTotal(c *gin.Context) { | ||||
order.OrderTotal(c) | order.OrderTotal(c) | ||||
} | } | ||||
@@ -0,0 +1,33 @@ | |||||
package md | |||||
type StaffListReq struct { | |||||
Limit int `json:"limit"` | |||||
Page int `json:"page" ` | |||||
Name string `json:"name" label:"姓名"` | |||||
Phone string `json:"phone" label:"负责人手机号"` | |||||
IdNo string `json:"id_no" label:"身份证号码"` | |||||
} | |||||
type StaffDeleteReq struct { | |||||
Ids []int `json:"ids"` | |||||
} | |||||
type StaffAddReq struct { | |||||
Name string `json:"name"` | |||||
Sex int `json:"sex"` | |||||
IdNo string `json:"id_no"` | |||||
Phone string `json:"phone"` | |||||
NativePlace string `json:"native_place"` | |||||
Department string `json:"department"` | |||||
} | |||||
type StaffUpdateReq struct { | |||||
Id int `json:"id" binding:"required"` | |||||
Name string `json:"name"` | |||||
Sex int `json:"sex"` | |||||
IdNo string `json:"id_no"` | |||||
Phone string `json:"phone"` | |||||
NativePlace string `json:"native_place"` | |||||
Department string `json:"department"` | |||||
CreateAt string `json:"create_at"` | |||||
} |
@@ -9,8 +9,10 @@ import ( | |||||
"applet/app/utils" | "applet/app/utils" | ||||
"encoding/json" | "encoding/json" | ||||
"fmt" | "fmt" | ||||
"github.com/360EntSecGroup-Skylar/excelize" | |||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
"github.com/tidwall/gjson" | "github.com/tidwall/gjson" | ||||
"strconv" | |||||
) | ) | ||||
func OrderList(c *gin.Context) { | func OrderList(c *gin.Context) { | ||||
@@ -73,6 +75,66 @@ func OrderList(c *gin.Context) { | |||||
return | return | ||||
} | } | ||||
func OrderExport(c *gin.Context) { | |||||
var args map[string]string | |||||
if err := c.ShouldBindJSON(&args); err != nil { | |||||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||||
return | |||||
} | |||||
eg := db.Db | |||||
list, _ := db.GetOrderListExport(eg, args) | |||||
titleList := []string{"订单编号", "金额", "手机号", "企业名称", "学校名称", "状态", "送达时间", "订单时间"} | |||||
xlsx := excelize.NewFile() | |||||
xlsx.SetSheetRow("Sheet1", "A1", &titleList) | |||||
style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["FFFF00"],"pattern":1}, "alignment":{"horizontal":"center"}}`) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR, err.Error()) | |||||
return | |||||
} | |||||
xlsx.SetCellStyle("Sheet1", "A1", "M1", style) | |||||
xlsx.SetColWidth("Sheet1", "A", "A", 35) | |||||
xlsx.SetColWidth("Sheet1", "B", "B", 30) | |||||
xlsx.SetColWidth("Sheet1", "C", "E", 15) | |||||
xlsx.SetColWidth("Sheet1", "F", "I", 10) | |||||
xlsx.SetColWidth("Sheet1", "J", "J", 20) | |||||
xlsx.SetColWidth("Sheet1", "K", "K", 10) | |||||
xlsx.SetColWidth("Sheet1", "L", "L", 25) | |||||
xlsx.SetColWidth("Sheet1", "M", "M", 15) | |||||
//表头被第一行用了,只能从第二行开始 | |||||
j := 2 | |||||
if list != nil { | |||||
stateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"} | |||||
enterpriseIds := make([]int, 0) | |||||
for _, v := range *list { | |||||
enterpriseIds = append(enterpriseIds, v.EnterpriseId) | |||||
} | |||||
enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds) | |||||
for _, v := range *list { | |||||
v1 := JudgePackageOrdOrdState(&v) | |||||
enterpriseName := "" | |||||
_, ok := enterpriseMap[v.EnterpriseId] | |||||
if ok { | |||||
enterpriseName = enterpriseMap[v.EnterpriseId].Name | |||||
} | |||||
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ | |||||
utils.Int64ToStr(v1.Oid), v1.Amount, v1.BuyPhone, enterpriseName, stateArr[v1.State], | |||||
gjson.Get(v1.BuyInfo, "date").String() + " " + gjson.Get(v1.BuyInfo, "time").String(), v1.CreateAt.Format("2006-01-02 15:04:05"), | |||||
}) | |||||
j++ | |||||
} | |||||
} | |||||
c.Header("Content-Type", "application/octet-stream") | |||||
c.Header("Content-Disposition", "attachment; filename="+"订单记录"+".xlsx") | |||||
c.Header("Content-Transfer-Encoding", "binary") | |||||
//回写到web 流媒体 形成下载 | |||||
_ = xlsx.Write(c.Writer) | |||||
return | |||||
} | |||||
// JudgePackageOrdOrdState 判断订单状态 | // JudgePackageOrdOrdState 判断订单状态 | ||||
func JudgePackageOrdOrdState(ord *model.Order) *model.Order { | func JudgePackageOrdOrdState(ord *model.Order) *model.Order { | ||||
if ord.State == 5 { | if ord.State == 5 { | ||||
@@ -41,6 +41,7 @@ func GetOrderGoodsBySkuIdSess(sess *xorm.Session, oid, skuId string) *model.Orde | |||||
} | } | ||||
return &order | return &order | ||||
} | } | ||||
func GetOrderList(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) { | func GetOrderList(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) { | ||||
var order []model.Order | var order []model.Order | ||||
sess := eg.Where("1=1") | sess := eg.Where("1=1") | ||||
@@ -53,6 +54,12 @@ func GetOrderList(eg *xorm.Engine, param map[string]string) (*[]model.Order, int | |||||
if param["state"] != "" { | if param["state"] != "" { | ||||
sess.And("state =?", param["state"]) | sess.And("state =?", param["state"]) | ||||
} | } | ||||
if param["start_at"] != "" { | |||||
sess.And("create_at >= ?", param["start_at"]) | |||||
} | |||||
if param["end_at"] != "" { | |||||
sess.And("create_at <= ?", param["end_at"]) | |||||
} | |||||
if param["enterprise_name"] != "" { | if param["enterprise_name"] != "" { | ||||
var enterprise []model.Enterprise | var enterprise []model.Enterprise | ||||
eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise) | eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise) | ||||
@@ -70,6 +77,41 @@ func GetOrderList(eg *xorm.Engine, param map[string]string) (*[]model.Order, int | |||||
} | } | ||||
return &order, count | return &order, count | ||||
} | } | ||||
func GetOrderListExport(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) { | |||||
var order []model.Order | |||||
sess := eg.Where("1=1") | |||||
if param["phone"] != "" { | |||||
sess.And("buy_phone like ?", "%"+param["phone"]+"%") | |||||
} | |||||
if param["oid"] != "" { | |||||
sess.And("oid like ?", "%"+param["oid"]+"%") | |||||
} | |||||
if param["state"] != "" { | |||||
sess.And("state =?", param["state"]) | |||||
} | |||||
if param["start_at"] != "" { | |||||
sess.And("create_at >= ?", param["start_at"]) | |||||
} | |||||
if param["end_at"] != "" { | |||||
sess.And("create_at <= ?", param["end_at"]) | |||||
} | |||||
if param["enterprise_name"] != "" { | |||||
var enterprise []model.Enterprise | |||||
eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise) | |||||
oids := []int{-1} | |||||
for _, v := range enterprise { | |||||
oids = append(oids, v.Id) | |||||
} | |||||
sess.In("enterprise_id", oids) | |||||
} | |||||
count, err := sess.OrderBy("id desc").FindAndCount(&order) | |||||
if err != nil { | |||||
return nil, count | |||||
} | |||||
return &order, count | |||||
} | |||||
func GetOrderListOutput(eg *xorm.Engine, param map[string]string) *[]model.Order { | func GetOrderListOutput(eg *xorm.Engine, param map[string]string) *[]model.Order { | ||||
var order []model.Order | var order []model.Order | ||||
sess := eg.Where("1=1") | sess := eg.Where("1=1") | ||||
@@ -0,0 +1,78 @@ | |||||
package db | |||||
import ( | |||||
"applet/app/db/model" | |||||
"applet/app/utils/logx" | |||||
"reflect" | |||||
"xorm.io/xorm" | |||||
) | |||||
type StaffDb struct { | |||||
Db *xorm.Engine `json:"db"` | |||||
} | |||||
func (staffDb *StaffDb) Set() { // set方法 | |||||
staffDb.Db = Db | |||||
} | |||||
func (staffDb *StaffDb) GetStaff(id int) (m *model.Staff, err error) { | |||||
m = new(model.Staff) | |||||
has, err := staffDb.Db.Where("id =?", id).Get(m) | |||||
if err != nil { | |||||
return nil, logx.Error(err) | |||||
} | |||||
if has == false { | |||||
return nil, nil | |||||
} | |||||
return m, nil | |||||
} | |||||
func (staffDb *StaffDb) FindStaff(limit, start int) (*[]model.Staff, error) { | |||||
var m []model.Staff | |||||
if limit == 0 || start == 0 { | |||||
if err := staffDb.Db.Desc("id").Find(&m); err != nil { | |||||
return nil, logx.Error(err) | |||||
} | |||||
} else { | |||||
if err := staffDb.Db.Desc("id").Limit(limit, start).Find(m); err != nil { | |||||
return nil, logx.Error(err) | |||||
} | |||||
} | |||||
return &m, nil | |||||
} | |||||
func (staffDb *StaffDb) GetStaffByName(name string) (m *model.Staff, err error) { | |||||
m = new(model.Staff) | |||||
has, err := staffDb.Db.Where("name =?", name).Get(m) | |||||
if err != nil { | |||||
return nil, logx.Error(err) | |||||
} | |||||
if has == false { | |||||
return nil, nil | |||||
} | |||||
return m, nil | |||||
} | |||||
func (staffDb *StaffDb) StaffInsert(m *model.Staff) (int, error) { | |||||
_, err := staffDb.Db.InsertOne(m) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return m.Id, nil | |||||
} | |||||
func (staffDb *StaffDb) StaffUpdate(m *model.Staff, columns ...string) (int64, error) { | |||||
affected, err := staffDb.Db.Where("id =?", m.Id).Cols(columns...).Update(m) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
func (staffDb *StaffDb) StaffDelete(id interface{}) (int64, error) { | |||||
if reflect.TypeOf(id).Kind() == reflect.Slice { | |||||
return Db.In("id", id).Delete(model.Staff{}) | |||||
} else { | |||||
return Db.Where("id = ?", id).Delete(model.Staff{}) | |||||
} | |||||
} |
@@ -0,0 +1,13 @@ | |||||
package model | |||||
type Staff struct { | |||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
Name string `json:"name" xorm:"not null default '' comment('姓名') VARCHAR(255)"` | |||||
Sex int `json:"sex" xorm:"not null default 1 comment('性别(1:男 2:女)') TINYINT(1)"` | |||||
IdNo string `json:"id_no" xorm:"not null default '' comment('身份证号码') VARCHAR(255)"` | |||||
Phone string `json:"phone" xorm:"not null default '' comment('联系电话') CHAR(50)"` | |||||
NativePlace string `json:"native_place" xorm:"not null default '' comment('籍贯') CHAR(50)"` | |||||
Department string `json:"department" xorm:"not null default '' comment('部门') CHAR(50)"` | |||||
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||||
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||||
} |
@@ -9,7 +9,7 @@ import ( | |||||
// TokenExpireDuration is jwt 过期时间 | // TokenExpireDuration is jwt 过期时间 | ||||
const TokenExpireDuration = time.Hour * 4380 | const TokenExpireDuration = time.Hour * 4380 | ||||
var Secret = []byte("bakery_big_data") | |||||
var Secret = []byte("bakery_ipad") | |||||
// JWTUser 如果想要保存更多信息,都可以添加到这个结构体中 | // JWTUser 如果想要保存更多信息,都可以添加到这个结构体中 | ||||
type JWTUser struct { | type JWTUser struct { | ||||
@@ -78,8 +78,11 @@ func rSetCenter(r *gin.RouterGroup) { | |||||
r.POST("/set", hdl.SetCenter) // 设置中心-设置 | r.POST("/set", hdl.SetCenter) // 设置中心-设置 | ||||
} | } | ||||
func rUser(r *gin.RouterGroup) { | |||||
func rStaff(r *gin.RouterGroup) { | |||||
r.POST("/list", hdl.StaffList) | |||||
r.POST("/delete", hdl.StaffDelete) | |||||
r.POST("/add", hdl.StaffAdd) | |||||
r.POST("/update", hdl.StaffUpdate) | |||||
} | } | ||||
func rEnterprise(r *gin.RouterGroup) { | func rEnterprise(r *gin.RouterGroup) { | ||||
@@ -142,8 +145,9 @@ func rOrder(r *gin.RouterGroup) { | |||||
} | } | ||||
func rFinanceManage(r *gin.RouterGroup) { | func rFinanceManage(r *gin.RouterGroup) { | ||||
r.POST("/list", orderHdl.OrderList) //用户订单 | |||||
r.POST("/total", orderHdl.OrderTotal) //用户订单统计 | |||||
r.POST("/list", orderHdl.OrderList) //用户订单 | |||||
r.POST("/export", orderHdl.OrderExport) //用户订单导出 | |||||
r.POST("/total", orderHdl.OrderTotal) //用户订单统计 | |||||
} | } | ||||
func AdminRoute(r *gin.RouterGroup) { | func AdminRoute(r *gin.RouterGroup) { | ||||
@@ -169,7 +173,7 @@ func AdminRoute(r *gin.RouterGroup) { | |||||
rRole(r.Group("/role")) //权限管理 | rRole(r.Group("/role")) //权限管理 | ||||
rSetCenter(r.Group("/setCenter")) //设置中心 | rSetCenter(r.Group("/setCenter")) //设置中心 | ||||
rUser(r.Group("/user")) //用户管理 | |||||
rStaff(r.Group("/staff")) //员工管理 | |||||
rGoodsPay(r.Group("/goodsPay")) //商品下单 | rGoodsPay(r.Group("/goodsPay")) //商品下单 | ||||
rOrder(r.Group("/order")) //用户订单 | rOrder(r.Group("/order")) //用户订单 | ||||
rFinanceManage(r.Group("/financeManage")) //财务管理 | rFinanceManage(r.Group("/financeManage")) //财务管理 | ||||