fix:
This commit is contained in:
parent
34f7ee039d
commit
6d93a6e65d
326
controller/erp_retail.go
Normal file
326
controller/erp_retail.go
Normal file
|
@ -0,0 +1,326 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/codinl/go-logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"mh-server/lib/auth"
|
||||
"mh-server/lib/status"
|
||||
"time"
|
||||
|
||||
"mh-server/model"
|
||||
)
|
||||
|
||||
func ErpOrderList(c *gin.Context) {
|
||||
req := &model.ErpOrderListReq{}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
logger.Error(err)
|
||||
RespJson(c, status.BadRequest, nil)
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := req.List()
|
||||
if err != nil {
|
||||
logger.Error("erp commodity list err:", err)
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, resp)
|
||||
return
|
||||
}
|
||||
|
||||
func ErpOrderCreate(c *gin.Context) {
|
||||
req := struct {
|
||||
//StoreId uint32 `json:"store_id"`
|
||||
Cashiers []model.ErpCashier `json:"cashiers" binding:"required"`
|
||||
Salesman1 uint32 `json:"salesman_1" binding:"required"`
|
||||
Salesman2 uint32 `json:"salesman_2"`
|
||||
RetailType string `json:"retail_type" binding:"required"`
|
||||
Tel string `json:"tel" binding:"required"`
|
||||
MemberType string `json:"member_type"` // 会员类型:
|
||||
ErpOrderCommodities []model.ErpOrderCommodity `json:"erp_order_commodities"`
|
||||
}{}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
logger.Error(err)
|
||||
RespJson(c, status.BadRequest, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.Cashiers) == 0 {
|
||||
logger.Error("cashiers is nil")
|
||||
RespJson(c, status.BadRequest, nil)
|
||||
return
|
||||
}
|
||||
if len(req.ErpOrderCommodities) == 0 {
|
||||
logger.Error("commodities is nil")
|
||||
RespJson(c, status.BadRequest, nil)
|
||||
return
|
||||
}
|
||||
jCashier, err := json.Marshal(req.Cashiers)
|
||||
if err != nil {
|
||||
logger.Error("cashiers marshal err:", err)
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
|
||||
uc := auth.GetCurrentUser(c)
|
||||
if uc == nil {
|
||||
logger.Error("uc is nil")
|
||||
RespJson(c, status.Unauthorized, nil)
|
||||
return
|
||||
}
|
||||
|
||||
//uc = &auth.UserClaims{Uid: 8588420}
|
||||
assistant := model.GetUserByUid(uc.Uid)
|
||||
if assistant.UserType != 2 {
|
||||
logger.Error("not assistant")
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
store, err := model.GetStore(uint32(assistant.StoreId))
|
||||
if err != nil {
|
||||
logger.Error("assistant store err:", err)
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
erpOrder := &model.ErpOrder{
|
||||
BillSn: model.NewErpBillSn(),
|
||||
RetailType: req.RetailType,
|
||||
Tel: req.Tel,
|
||||
StoreId: uint32(assistant.StoreId),
|
||||
StoreName: store.Name,
|
||||
MakerId: uint32(assistant.Uid),
|
||||
MakerName: assistant.ShopAssistantName,
|
||||
AuditTime: time.Now(),
|
||||
AuditorId: assistant.Uid,
|
||||
AuditorName: assistant.ShopAssistantName,
|
||||
CashierList: string(jCashier),
|
||||
Salesman1: req.Salesman1,
|
||||
Salesman2: req.Salesman2,
|
||||
MemberType: req.MemberType,
|
||||
State: model.ErpOrderStateUnAudit,
|
||||
}
|
||||
|
||||
commodityMap := make(map[uint32]model.ErpCommodity)
|
||||
if req.RetailType == model.RetailTypeSale {
|
||||
commodityIds := make([]uint32, 0, len(req.ErpOrderCommodities))
|
||||
for i, _ := range req.ErpOrderCommodities {
|
||||
commodityIds = append(commodityIds, req.ErpOrderCommodities[i].ErpCommodityId)
|
||||
}
|
||||
var commodities []model.ErpCommodity
|
||||
err = model.DB.Table("erp_commodity").Where("id IN (?)", commodityIds).Find(&commodities).Error
|
||||
if err != nil {
|
||||
logger.Error("commodities err:", err)
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
|
||||
for i, _ := range commodities {
|
||||
commodityMap[commodities[i].ID] = commodities[i]
|
||||
}
|
||||
|
||||
model.SetUserInfo(req.Tel)
|
||||
}
|
||||
|
||||
var orderCommodityMap map[uint32]model.ErpOrderCommodity
|
||||
if req.RetailType == model.RetailTypeRejected {
|
||||
ids := make([]uint32, 0, len(req.ErpOrderCommodities))
|
||||
for i, _ := range req.ErpOrderCommodities {
|
||||
ids = append(ids, req.ErpOrderCommodities[i].RejectedOrderCommodityId)
|
||||
}
|
||||
orderCommodityMap, err = model.GetErpOrderCommodityMap(ids)
|
||||
if err != nil {
|
||||
logger.Error("order commodity map err:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
begin := model.DB.Begin()
|
||||
err = begin.Create(erpOrder).Error
|
||||
if err != nil {
|
||||
begin.Rollback()
|
||||
logger.Error("create erp order err:", err)
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
|
||||
for i, _ := range req.ErpOrderCommodities {
|
||||
req.ErpOrderCommodities[i].ErpOrderId = erpOrder.ID
|
||||
|
||||
if req.RetailType == model.RetailTypeRejected {
|
||||
v, ok := orderCommodityMap[req.ErpOrderCommodities[i].RejectedOrderCommodityId]
|
||||
if ok {
|
||||
v.RejectedPrice = req.ErpOrderCommodities[i].RejectedPrice
|
||||
v.RejectedCount = req.ErpOrderCommodities[i].RejectedCount
|
||||
v.RejectedAmount = v.RejectedCount * v.RejectedPrice
|
||||
} else {
|
||||
logger.Error("rejected order commodity id is null")
|
||||
return
|
||||
}
|
||||
v.ID = 0
|
||||
req.ErpOrderCommodities[i] = v
|
||||
// 添加库存 TODO
|
||||
if req.ErpOrderCommodities[i].RejectedPrice > req.ErpOrderCommodities[i].RetailPrice {
|
||||
logger.Error("rejected price gt retail price ")
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
if req.ErpOrderCommodities[i].RejectedCount > req.ErpOrderCommodities[i].Count {
|
||||
logger.Error("rejected count gt retail count ")
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
|
||||
} else if req.RetailType == model.RetailTypeSale {
|
||||
|
||||
v, ok := commodityMap[req.ErpOrderCommodities[i].ErpCommodityId]
|
||||
if ok {
|
||||
req.ErpOrderCommodities[i].ErpCommodityName = v.Name
|
||||
req.ErpOrderCommodities[i].ErpCategoryId = v.ErpCategoryId
|
||||
req.ErpOrderCommodities[i].ErpCategoryName = v.ErpCategoryName
|
||||
req.ErpOrderCommodities[i].RetailPrice = v.RetailPrice
|
||||
//req.ErpOrderCommodities[i].MemberPrice = v.MemberPrice
|
||||
}
|
||||
if req.ErpOrderCommodities[i].PresentType == 2 {
|
||||
req.ErpOrderCommodities[i].RetailPrice = 0
|
||||
}
|
||||
|
||||
// 减库存 TODO
|
||||
if erpOrder.MemberType == model.ErpOrderMemberTypeMember {
|
||||
req.ErpOrderCommodities[i].Amount = req.ErpOrderCommodities[i].Count * req.ErpOrderCommodities[i].MemberPrice
|
||||
} else {
|
||||
req.ErpOrderCommodities[i].Amount = req.ErpOrderCommodities[i].Count * req.ErpOrderCommodities[i].RetailPrice
|
||||
}
|
||||
}
|
||||
|
||||
erpOrder.TotalAmount += req.ErpOrderCommodities[i].Amount
|
||||
erpOrder.TotalCount += req.ErpOrderCommodities[i].Count
|
||||
}
|
||||
|
||||
err = begin.Create(&req.ErpOrderCommodities).Error
|
||||
if err != nil {
|
||||
begin.Rollback()
|
||||
logger.Error("Create")
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
err = begin.Commit().Error
|
||||
if err != nil {
|
||||
begin.Rollback()
|
||||
logger.Error("commit err:", err)
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
erpOrder.Commodities = req.ErpOrderCommodities
|
||||
erpOrder.Cashiers = req.Cashiers
|
||||
|
||||
RespOK(c, erpOrder)
|
||||
return
|
||||
}
|
||||
|
||||
func ErpOrderDetail(c *gin.Context) {
|
||||
req := &struct {
|
||||
ErpOrderId uint32 `json:"erp_order_id"`
|
||||
}{}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
logger.Error(err)
|
||||
RespJson(c, status.BadRequest, nil)
|
||||
return
|
||||
}
|
||||
var order model.ErpOrder
|
||||
err := model.DB.Table("erp_order").Where("id = ?", req.ErpOrderId).Find(&order).Error
|
||||
if err != nil {
|
||||
logger.Error("order err:", err)
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
var orderCommodities []model.ErpOrderCommodity
|
||||
err = model.DB.Table("erp_order_commodity").Where("erp_order_id=?", req.ErpOrderId).Find(&orderCommodities).Error
|
||||
if err != nil {
|
||||
logger.Error("order commodities err:", err)
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
order.Commodities = orderCommodities
|
||||
order.SetErpCashier()
|
||||
|
||||
RespOK(c, order)
|
||||
return
|
||||
}
|
||||
|
||||
func ErpOrderCommodityList(c *gin.Context) {
|
||||
req := &struct {
|
||||
Tel string `json:"tel"`
|
||||
IMEI string `json:"imei"`
|
||||
ErpCommodityName string `json:"erp_commodity_name"`
|
||||
}{}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
logger.Error(err)
|
||||
RespJson(c, status.BadRequest, nil)
|
||||
return
|
||||
}
|
||||
|
||||
var commodities []model.ErpOrderCommodity
|
||||
qs := model.DB.Table("erp_order_commodity")
|
||||
if req.Tel != "" {
|
||||
qs = qs.Where("tel=?", req.Tel)
|
||||
}
|
||||
if req.IMEI != "" {
|
||||
qs = qs.Where("imei=?", req.IMEI)
|
||||
}
|
||||
if req.ErpCommodityName != "" {
|
||||
qs = qs.Where("erp_commodity_name=?", req.ErpCommodityName)
|
||||
}
|
||||
err := qs.Order("id DESC").Find(&commodities).Error
|
||||
if err != nil {
|
||||
logger.Error("erp commodity list err:", err)
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, commodities)
|
||||
return
|
||||
}
|
||||
|
||||
func ShopAssistantList(c *gin.Context) {
|
||||
req := &struct {
|
||||
StoreId uint32 `json:"store_id"`
|
||||
}{}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
logger.Error(err)
|
||||
RespJson(c, status.BadRequest, nil)
|
||||
return
|
||||
}
|
||||
|
||||
uc := auth.GetCurrentUser(c)
|
||||
if uc == nil {
|
||||
logger.Error("uc is nil")
|
||||
RespJson(c, status.Unauthorized, nil)
|
||||
return
|
||||
}
|
||||
|
||||
//uc = &auth.UserClaims{Uid: 8588420}
|
||||
assistant := model.GetUserByUid(uc.Uid)
|
||||
if assistant.UserType != 2 {
|
||||
logger.Error("not assistant")
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
req.StoreId = uint32(assistant.StoreId)
|
||||
var users []model.User
|
||||
qs := model.DB.Table("user").Where("user_type=2")
|
||||
if req.StoreId != 0 {
|
||||
qs = qs.Where("store_id=?", req.StoreId)
|
||||
}
|
||||
|
||||
err := qs.Order("id DESC").Find(&users).Error
|
||||
if err != nil {
|
||||
logger.Error("erp commodity list err:", err)
|
||||
RespJson(c, status.InternalServerError, nil)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, users)
|
||||
return
|
||||
}
|
2
go.mod
2
go.mod
|
@ -16,11 +16,11 @@ require (
|
|||
github.com/qiniu/x v7.0.8+incompatible // indirect
|
||||
github.com/rs/zerolog v1.23.0
|
||||
github.com/satori/go.uuid v1.2.0 // indirect
|
||||
github.com/shopspring/decimal v1.3.1
|
||||
github.com/spf13/cobra v1.1.3
|
||||
github.com/spf13/viper v1.7.1
|
||||
github.com/wechatpay-apiv3/wechatpay-go v0.2.6
|
||||
github.com/xuri/excelize/v2 v2.6.0
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
|
||||
gorm.io/gorm v1.24.3
|
||||
qiniupkg.com/x v7.0.8+incompatible // indirect
|
||||
)
|
||||
|
|
7
go.sum
7
go.sum
|
@ -136,8 +136,9 @@ github.com/jinzhu/gorm v1.9.16 h1:+IyIjPEABKRpsu/F8OvDPy9fyQlgsg2luMV2ZIH5i5o=
|
|||
github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.0.1 h1:HjfetcXq097iXP0uoPCdnM4Efp5/9MsM0/M+XOTeR3M=
|
||||
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas=
|
||||
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
|
||||
|
@ -227,8 +228,6 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb
|
|||
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
|
||||
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
|
@ -438,6 +437,8 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
|||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/gorm v1.24.3 h1:WL2ifUmzR/SLp85CSURAfybcHnGZ+yLSGSxgYXlFBHg=
|
||||
gorm.io/gorm v1.24.3/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
|
52
model/cashier.go
Normal file
52
model/cashier.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package model
|
||||
|
||||
//go:generate goqueryset -in cashier.go
|
||||
// gen:qs
|
||||
type ErpCashier struct {
|
||||
Model
|
||||
|
||||
Name string `json:"name" gorm:"type:varchar(512)"`
|
||||
BankName string `json:"bank_name" gorm:"type:varchar(512)"`
|
||||
BankAccount string `json:"bank_account" gorm:"type:varchar(512)"`
|
||||
State uint32 `json:"state"` // 状态:1-使用 2-未用
|
||||
Remark string `json:"remark" gorm:"type:varchar(512)"`
|
||||
Type uint32 `json:"type"` //
|
||||
//Description string `json:"description"`
|
||||
// erp_cashier
|
||||
}
|
||||
|
||||
// gen:qs
|
||||
type ErpStoreCashier struct {
|
||||
Model
|
||||
|
||||
ErpCashierId uint32 `json:"erp_cashier_id" gorm:"index"`
|
||||
Name string `json:"name" gorm:"type:varchar(512)"`
|
||||
BankName string `json:"bank_name" gorm:"type:varchar(512)"`
|
||||
BankAccount string `json:"bank_account" gorm:"type:varchar(512)"`
|
||||
StoreId uint32 `json:"store_id" gorm:"index"`
|
||||
StoreName string `json:"store_name"`
|
||||
State uint32 `json:"state"` // 状态:1-使用 2-未用
|
||||
Remark string `json:"remark" gorm:"type:varchar(512)"`
|
||||
// erp_store_cashier
|
||||
}
|
||||
|
||||
type PayModeInfo struct {
|
||||
StoreCashierId uint32 `json:"store_cashier_id"`
|
||||
Amount uint32 `json:"amount"`
|
||||
StoreCashier ErpStoreCashier `json:"store_cashier" gorm:"-"`
|
||||
}
|
||||
|
||||
type ErpCashierStoreListResp struct {
|
||||
Total int `json:"total"`
|
||||
PageNum int `json:"page_num"`
|
||||
PageSize int `json:"page_size"`
|
||||
List []ErpStoreCashier `json:"list"`
|
||||
ExportUrl string `json:"export_url"`
|
||||
}
|
||||
|
||||
type ErpCashierListResp struct {
|
||||
Total int `json:"total"`
|
||||
PageNum int `json:"page_num"`
|
||||
PageSize int `json:"page_size"`
|
||||
List []ErpCashier `json:"list"`
|
||||
}
|
1467
model/commodity.go
Normal file
1467
model/commodity.go
Normal file
File diff suppressed because it is too large
Load Diff
276
model/erp_retail_order.go
Normal file
276
model/erp_retail_order.go
Normal file
|
@ -0,0 +1,276 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/codinl/go-logger"
|
||||
"math/rand"
|
||||
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
ErpOrderStateUnAudit = "un_audit"
|
||||
ErpOrderStateAudited = "audited"
|
||||
)
|
||||
const (
|
||||
ErpOrderMemberTypeGeneral = "general"
|
||||
ErpOrderMemberTypeMember = "member"
|
||||
)
|
||||
|
||||
const (
|
||||
RetailTypeSale = "sale"
|
||||
RetailTypeRejected = "rejected"
|
||||
)
|
||||
|
||||
type ErpOrder struct {
|
||||
Model
|
||||
|
||||
BillSn string `json:"bill_sn" gorm:"index"`
|
||||
RetailType string `json:"retail_type"` // 销售类型:
|
||||
Tel string `json:"tel" gorm:"index"`
|
||||
StoreId uint32 `json:"store_id" gorm:"index"`
|
||||
StoreName string `json:"store_name"`
|
||||
MakerId uint32 `json:"maker_id" gorm:"index"`
|
||||
MakerName string `json:"maker_name"`
|
||||
AuditTime time.Time `json:"audit_time"`
|
||||
AuditorId uint32 `json:"auditor_id" gorm:"index"`
|
||||
AuditorName string `json:"auditor_name"`
|
||||
//ErpCashierId uint32 `json:"erp_cashier_id" gorm:"index"`
|
||||
//ErpCashierName string `json:"erp_cashier_name"`
|
||||
CashierList string `json:"cashier_list" gorm:"type:text"` // 付款方式
|
||||
Salesman1 uint32 `json:"salesman_1"`
|
||||
Salesman2 uint32 `json:"salesman_2"`
|
||||
MemberType string `json:"member_type"` // 会员类型:
|
||||
State string `json:"state" gorm:"index"`
|
||||
TotalAmount uint32 `json:"total_amount"` // 包含退货
|
||||
TotalCount uint32 `json:"total_count"` // 包含退货
|
||||
SaleOrderId uint32 `json:"sale_order_id"` // 销售订单id
|
||||
|
||||
//RejectedTotalAmount uint32 `json:"rejected_total_amount"`
|
||||
//RejectedTotalCount uint32 `json:"rejected_total_count"`
|
||||
|
||||
Commodities []ErpOrderCommodity `json:"commodities" gorm:"-"`
|
||||
Cashiers []ErpCashier `json:"cashiers" gorm:"-"`
|
||||
// erp_order
|
||||
}
|
||||
|
||||
type ErpOrderCommodity struct {
|
||||
Model
|
||||
|
||||
ErpOrderId uint32 `json:"erp_order_id"`
|
||||
ErpCategoryId uint32 `json:"erp_category_id"`
|
||||
ErpCategoryName string `json:"erp_category_name"`
|
||||
ErpCommodityId uint32 `json:"erp_commodity_id"`
|
||||
ErpCommodityName string `json:"erp_commodity_name"`
|
||||
IMEIType uint32 `json:"imei_type"` // 1-无串码 2-串码
|
||||
IMEI string `json:"imei"`
|
||||
PresentType uint32 `json:"present_type"` // 赠送类型:1-非赠送 2-赠送
|
||||
RetailPrice uint32 `json:"retail_price"`
|
||||
MemberPrice uint32 `json:"member_price"`
|
||||
Count uint32 `json:"count"`
|
||||
Amount uint32 `json:"amount"`
|
||||
Remark string `json:"remark"`
|
||||
Tel string `json:"tel" gorm:"index"`
|
||||
RejectedPrice uint32 `json:"rejected_price"`
|
||||
RejectedCount uint32 `json:"rejected_count"`
|
||||
RejectedAmount uint32 `json:"rejected_amount"`
|
||||
RejectedOrderCommodityId uint32 `json:"rejected_order_commodity_id"`
|
||||
|
||||
// erp_order_commodity
|
||||
}
|
||||
|
||||
type ErpOrderListReq struct {
|
||||
BillSn string `json:"bill_sn"`
|
||||
//Type string `json:"type"`
|
||||
RetailType string `json:"retail_type"`
|
||||
Tel string `json:"tel"`
|
||||
StoreId uint32 `json:"store_id"`
|
||||
State string `json:"state"`
|
||||
StartTime string `json:"start_time"`
|
||||
EndTime string `json:"end_time"`
|
||||
PageNum int `json:"page_num"`
|
||||
PageSize int `json:"page_size"`
|
||||
IsExport uint32 `json:"is_export"` // 1-导出
|
||||
//StartTime time.Time `json:"start_time"`
|
||||
//EndTime time.Time `json:"end_time"`
|
||||
}
|
||||
type ErpOrderListResp struct {
|
||||
List []ErpOrder `json:"list"`
|
||||
Total int `json:"total"`
|
||||
PageNum int `json:"page_num"`
|
||||
PageSize int `json:"page_size"`
|
||||
}
|
||||
|
||||
func (m *ErpOrderListReq) List() (*ErpOrderListResp, error) {
|
||||
resp := &ErpOrderListResp{
|
||||
PageNum: m.PageNum,
|
||||
PageSize: m.PageSize,
|
||||
}
|
||||
page := m.PageNum - 1
|
||||
if page < 0 {
|
||||
page = 0
|
||||
}
|
||||
if m.PageSize == 0 {
|
||||
m.PageSize = 10
|
||||
}
|
||||
qs := DB.Table("erp_order")
|
||||
if m.BillSn != "" {
|
||||
qs = qs.Where("bill_sn=?", m.BillSn)
|
||||
}
|
||||
//if m.Type != "" {
|
||||
// qs = qs.Where("type=?", m.Type)
|
||||
//}
|
||||
if m.RetailType != "" {
|
||||
qs = qs.Where("retail_type=?", m.RetailType)
|
||||
}
|
||||
if m.Tel != "" {
|
||||
qs = qs.Where("tel=?", m.Tel)
|
||||
}
|
||||
if m.StoreId != 0 {
|
||||
qs = qs.Where("store_id=?", m.StoreId)
|
||||
}
|
||||
if m.State != "" {
|
||||
qs = qs.Where("state=?", m.State)
|
||||
}
|
||||
if m.StartTime != "" {
|
||||
parse, err := time.Parse(DateTimeFormat, m.StartTime)
|
||||
if err != nil {
|
||||
logger.Errorf("err:", err)
|
||||
//return users, 0, err
|
||||
}
|
||||
qs = qs.Where("created_at > ?", parse)
|
||||
}
|
||||
if m.EndTime != "" {
|
||||
parse, err := time.Parse(DateTimeFormat, m.EndTime)
|
||||
if err != nil {
|
||||
logger.Errorf("err:", err)
|
||||
//return users, 0, err
|
||||
}
|
||||
parse = parse.AddDate(0, 0, 1)
|
||||
qs = qs.Where("created_at < ?", parse)
|
||||
}
|
||||
|
||||
var count int64
|
||||
err := qs.Count(&count).Error
|
||||
if err != nil {
|
||||
logger.Error("count err:", err)
|
||||
return resp, err
|
||||
}
|
||||
resp.Total = int(count)/m.PageSize + 1
|
||||
var orders []ErpOrder
|
||||
err = qs.Order("id DESC").Offset(page * m.PageSize).Limit(m.PageSize).Find(&orders).Error
|
||||
if err != nil && err != RecordNotFound {
|
||||
logger.Error("erp commodity list err:", err)
|
||||
return resp, err
|
||||
}
|
||||
ErpOrderListSetCashier(orders)
|
||||
|
||||
resp.List = orders
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func NewErpBillSn() string {
|
||||
nowTime := time.Now()
|
||||
rand.Seed(nowTime.UnixNano())
|
||||
max := 1
|
||||
for {
|
||||
if max > 5 {
|
||||
logger.Error("create sn err")
|
||||
return ""
|
||||
}
|
||||
random := rand.Int31n(9999) + 1000
|
||||
sn := fmt.Sprintf("%s%d", nowTime.Format("060102"), random)
|
||||
exist, err := QueryRecordExist(fmt.Sprintf("SELECT * FROM erp_order WHERE bill_sn='%s'", sn))
|
||||
if err != nil {
|
||||
logger.Error("exist sn err")
|
||||
}
|
||||
if !exist {
|
||||
return sn
|
||||
}
|
||||
|
||||
max++
|
||||
}
|
||||
}
|
||||
|
||||
//func NewErpPurchaseSn() string {
|
||||
// nowTime := time.Now()
|
||||
// rand.Seed(nowTime.UnixNano())
|
||||
// max := 1
|
||||
// for {
|
||||
// if max > 5 {
|
||||
// logger.Error("create sn err")
|
||||
// return ""
|
||||
// }
|
||||
// random := rand.Int31n(9999) + 1000
|
||||
// sn := fmt.Sprintf("%s%d", nowTime.Format("060102"), random)
|
||||
// exist, err := QueryRecordExist(fmt.Sprintf("SELECT * FROM erp_purchase_order WHERE serial_number='%s'", sn))
|
||||
// if err != nil {
|
||||
// logger.Error("exist sn err")
|
||||
// }
|
||||
// if !exist {
|
||||
// return sn
|
||||
// }
|
||||
//
|
||||
// max++
|
||||
// }
|
||||
//}
|
||||
|
||||
func ErpOrderListSetCashier(list []ErpOrder) {
|
||||
for i, _ := range list {
|
||||
//if list[i].CashierList != "" {
|
||||
// var cashiers []ErpCashier
|
||||
// err := json.Unmarshal([]byte(list[i].CashierList), &cashiers)
|
||||
// if err != nil {
|
||||
// logger.Error("unmarshal err:", err)
|
||||
// }
|
||||
// list[i].Cashiers = cashiers
|
||||
// list[i].CashierList = ""
|
||||
//}
|
||||
list[i].SetErpCashier()
|
||||
}
|
||||
}
|
||||
|
||||
func (m *ErpOrder) SetErpCashier() {
|
||||
if m.CashierList != "" {
|
||||
var cashiers []ErpCashier
|
||||
err := json.Unmarshal([]byte(m.CashierList), &cashiers)
|
||||
if err != nil {
|
||||
logger.Error("unmarshal err:", err)
|
||||
}
|
||||
m.Cashiers = cashiers
|
||||
m.CashierList = ""
|
||||
}
|
||||
}
|
||||
|
||||
func GetErpOrderCommodityMap(ids []uint32) (map[uint32]ErpOrderCommodity, error) {
|
||||
commodityMap := make(map[uint32]ErpOrderCommodity, 0)
|
||||
if len(ids) == 0 {
|
||||
return commodityMap, nil
|
||||
}
|
||||
var commodities []ErpOrderCommodity
|
||||
err := DB.Table("erp_order_commodity").Where("id IN (?)", ids).Find(&commodities).Error
|
||||
if err != nil {
|
||||
logger.Error("commodities err:", err)
|
||||
return commodityMap, err
|
||||
}
|
||||
for i, _ := range commodities {
|
||||
commodityMap[commodities[i].ID] = commodities[i]
|
||||
}
|
||||
return commodityMap, nil
|
||||
}
|
||||
|
||||
func SetUserInfo(tel string) {
|
||||
var user User
|
||||
err := DB.Table("user").Where("tel=?", tel).Find(&user).Error
|
||||
if err != nil {
|
||||
logger.Error("user err:", err)
|
||||
return
|
||||
}
|
||||
if user.FirstRetailOrder.IsZero() {
|
||||
err := DB.Table("user").Where("uid=?", user.Uid).Update("first_retail_order", time.Now()).Error
|
||||
if err != nil {
|
||||
logger.Error("update user err:", err)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,7 +47,9 @@ type User struct {
|
|||
ShopAssistantName string `json:"shop_assistant_name"` // 店员名称
|
||||
//RenewalTime time.Time `json:"renewal_time"`
|
||||
//RenewalMemberLevel uint32 `json:"renewal_member_level"`
|
||||
OpenMemberLevel uint32 `json:"open_member_level"`
|
||||
OpenMemberLevel uint32 `json:"open_member_level"`
|
||||
FirstRetailOrder time.Time `json:"first_retail_order"`
|
||||
//MemberLevelString string `json:"member_level_string" gorm:"-"` // 会员类型
|
||||
|
||||
Version uint32 `json:"-"` //
|
||||
UserVm *UserVm `json:"user_vm" gorm:"-"` //
|
||||
|
|
|
@ -281,4 +281,15 @@ func ConfigAppRouter(r gin.IRouter) {
|
|||
recycleConsole.POST("order/check", controller.RecycleCardOrderCheck) // 管理端
|
||||
recycleConsole.POST("order/list", controller.ConsoleRecycleCardOrderList)
|
||||
}
|
||||
retail := console.Group("retail")
|
||||
{
|
||||
retail.POST("order_commodity_list", controller.ErpOrderCommodityList)
|
||||
|
||||
recycleConsole.Use(auth.UserAccessAuth)
|
||||
retail.POST("order/list", controller.ErpOrderList)
|
||||
retail.POST("order/create", controller.ErpOrderCreate)
|
||||
retail.POST("order_detail", controller.ErpOrderDetail)
|
||||
retail.POST("shop_assistant_list", controller.ShopAssistantList)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user