1.优化零售订单审核接口;
2.查询零售订单列表接口增加入参:商品名称;
This commit is contained in:
parent
4124d8862a
commit
ae2d54b2fa
|
@ -161,6 +161,12 @@ func ErpOrderAudit(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
// 如果订单已审核而且是已支付状态,则不能取消审核
|
||||
if erpOrder.State == model.ErpOrderStateAudited && erpOrder.PayStatus == model.HavePaid && req.State == 2 {
|
||||
app.Error(c, http.StatusInternalServerError, err, "操作失败:已支付订单不能取消审核")
|
||||
return
|
||||
}
|
||||
|
||||
orderState := model.ErpOrderStateAudited
|
||||
stockState := model.OnSale
|
||||
switch req.State {
|
||||
|
@ -176,16 +182,19 @@ func ErpOrderAudit(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
// 检查支付方式,如果没有线上支付则默认为支付已完成
|
||||
nPayStatus := model.WaitForPaying // 待支付
|
||||
var cashiers []model.ErpOrderCashier
|
||||
err = json.Unmarshal([]byte(erpOrder.CashierList), &cashiers)
|
||||
if err != nil {
|
||||
logger.Error("unmarshal CashierList err:", logger.Field("err", err))
|
||||
}
|
||||
if !model.CheckIsOnlinePay(cashiers) {
|
||||
nPayStatus = model.HavePaid // 已完成
|
||||
stockState = model.SoldOut // 库存-已售
|
||||
nPayStatus := model.NoCreatePayOrder
|
||||
if req.State == 1 { // 审核
|
||||
// 检查支付方式,如果没有线上支付则默认为支付已完成
|
||||
nPayStatus = model.WaitForPaying // 待支付
|
||||
var cashiers []model.ErpOrderCashier
|
||||
err = json.Unmarshal([]byte(erpOrder.CashierList), &cashiers)
|
||||
if err != nil {
|
||||
logger.Error("unmarshal CashierList err:", logger.Field("err", err))
|
||||
}
|
||||
if !model.CheckIsOnlinePay(cashiers) {
|
||||
nPayStatus = model.HavePaid // 已完成
|
||||
stockState = model.SoldOut // 库存-已售
|
||||
}
|
||||
}
|
||||
|
||||
begin := orm.Eloquent.Begin()
|
||||
|
|
|
@ -264,7 +264,7 @@ func AddRemark(c *gin.Context) {
|
|||
// @Accept json
|
||||
// @Param request body models.QueryCodeReq true "查询商品串码或条码模型"
|
||||
// @Success 200 {object} models.QueryCodeResp
|
||||
// @Router /api/v1/inventory/add_remark [post]
|
||||
// @Router /api/v1/inventory/query_code [post]
|
||||
func QueryCode(c *gin.Context) {
|
||||
req := &models.QueryCodeReq{}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
|
|
|
@ -179,19 +179,20 @@ type ErpOrderCreateReq struct {
|
|||
|
||||
// ErpOrderListReq 查询零售订单列表入参
|
||||
type ErpOrderListReq struct {
|
||||
ScanCode string `json:"scan_code"` // 扫码枪扫码数据:串码
|
||||
BillSn string `json:"bill_sn"` // 单据编号
|
||||
RetailType string `json:"retail_type"` // 销售类型:sale 零售销售; rejected 零售退货
|
||||
Uid int `json:"uid"` // 用户ID
|
||||
Tel string `json:"tel"` // 客户手机号
|
||||
Salesman uint32 `json:"salesman"` // 销售人员ID
|
||||
StoreId uint32 `json:"store_id"` // 门店ID
|
||||
State string `json:"state"` // 订单状态
|
||||
PayStatus uint32 `json:"pay_status"` // 支付状态 0-未创建 ;1-待支付; 2-已支付
|
||||
StartTime string `json:"start_time"` // 开始时间
|
||||
EndTime string `json:"end_time"` // 结束时间
|
||||
PageIndex int `json:"pageIndex"` // 页码
|
||||
PageSize int `json:"pageSize"` // 页面条数
|
||||
ScanCode string `json:"scan_code"` // 扫码枪扫码数据:串码
|
||||
BillSn string `json:"bill_sn"` // 单据编号
|
||||
RetailType string `json:"retail_type"` // 销售类型:sale 零售销售; rejected 零售退货
|
||||
CommodityName string `json:"commodity_name"` // 商品名称
|
||||
Uid int `json:"uid"` // 用户ID
|
||||
Tel string `json:"tel"` // 客户手机号
|
||||
Salesman uint32 `json:"salesman"` // 销售人员ID
|
||||
StoreId uint32 `json:"store_id"` // 门店ID
|
||||
State string `json:"state"` // 订单状态
|
||||
PayStatus uint32 `json:"pay_status"` // 支付状态 0-未创建 ;1-待支付; 2-已支付
|
||||
StartTime string `json:"start_time"` // 开始时间
|
||||
EndTime string `json:"end_time"` // 结束时间
|
||||
PageIndex int `json:"pageIndex"` // 页码
|
||||
PageSize int `json:"pageSize"` // 页面条数
|
||||
}
|
||||
|
||||
// ErpOrderListResp 查询零售订单列表出参
|
||||
|
@ -411,10 +412,14 @@ func (m *ErpOrderListReq) List() (*ErpOrderListResp, error) {
|
|||
if m.PageSize == 0 {
|
||||
m.PageSize = 10
|
||||
}
|
||||
if m.ScanCode != "" { // 扫码了串码,需要查询已售的商品数据
|
||||
if m.ScanCode != "" { // 扫描了串码,需要查询已售的商品数据
|
||||
return QueryListByScanCode(m.ScanCode)
|
||||
}
|
||||
|
||||
if m.CommodityName != "" { // 输入了商品名称进行查询
|
||||
return QueryListByCommodityName(m)
|
||||
}
|
||||
|
||||
qs := orm.Eloquent.Table("erp_order")
|
||||
if m.BillSn != "" {
|
||||
qs = qs.Where("bill_sn=?", m.BillSn)
|
||||
|
@ -481,6 +486,7 @@ func (m *ErpOrderListReq) List() (*ErpOrderListResp, error) {
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
// QueryListByScanCode 通过扫描串码查询列表
|
||||
func QueryListByScanCode(scanCode string) (*ErpOrderListResp, error) {
|
||||
resp := &ErpOrderListResp{}
|
||||
|
||||
|
@ -512,6 +518,66 @@ func QueryListByScanCode(scanCode string) (*ErpOrderListResp, error) {
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
// QueryListByCommodityName 通过商品名称查询列表
|
||||
func QueryListByCommodityName(req *ErpOrderListReq) (*ErpOrderListResp, error) {
|
||||
resp := &ErpOrderListResp{
|
||||
PageIndex: req.PageIndex,
|
||||
PageSize: req.PageSize,
|
||||
}
|
||||
|
||||
page := req.PageIndex - 1
|
||||
if page < 0 {
|
||||
page = 0
|
||||
}
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 10
|
||||
}
|
||||
|
||||
qs := orm.Eloquent.Debug().Table("erp_order_commodity").
|
||||
Select("erp_order_commodity.*, erp_order.*").
|
||||
Joins("JOIN erp_order ON erp_order_commodity.erp_order_id = erp_order.id")
|
||||
if req.CommodityName != "" { // 商品名称
|
||||
qs = qs.Where("erp_order_commodity.erp_commodity_name like ?", "%"+req.CommodityName+"%")
|
||||
}
|
||||
|
||||
if req.Tel != "" { // 用户手机号
|
||||
qs = qs.Where("erp_order.tel=?", req.Tel)
|
||||
}
|
||||
if req.StoreId != 0 { // 门店ID
|
||||
qs = qs.Where("erp_order.store_id=?", req.StoreId)
|
||||
}
|
||||
qs.Where("erp_order.pay_status = ?", HavePaid)
|
||||
es := qs
|
||||
|
||||
var result []RetailDetailByJoin
|
||||
|
||||
err := qs.Order("erp_order.audit_time DESC").Offset(page * req.PageSize).Limit(req.PageSize).Find(&result).Error
|
||||
if err != nil && err != RecordNotFound {
|
||||
logger.Error("erp commodity list err:", logger.Field("err", err))
|
||||
return resp, err
|
||||
}
|
||||
|
||||
var count int64
|
||||
err = es.Count(&count).Error
|
||||
if err != nil {
|
||||
logger.Errorf("QueryRetailMargin count err:", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
orders := packData(result)
|
||||
erpOrderListSetCashier(orders)
|
||||
erpOrderListSetSalesman(orders)
|
||||
|
||||
resp.List = orders
|
||||
|
||||
//跟之前保持一致
|
||||
resp.Total = int(count)
|
||||
resp.PageIndex = page + 1
|
||||
resp.PageSize = req.PageSize
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// UpdateStock 扣减or添加库存
|
||||
// 零售订单:
|
||||
// 有串码,通过串码查找库存详情表,然后更改对应库存的状态为"已售";
|
||||
|
@ -723,6 +789,7 @@ func (m *ErpOrderCreateReq) GetSalesmanList() (string, error) {
|
|||
staffProfit += item.StaffProfit * erpCommodity.Brokerage2
|
||||
}
|
||||
|
||||
var salesmanList []ErpOrderSales
|
||||
for _, item := range m.Salesman {
|
||||
item.SalesProfitPer = salesProfit / float64(len(m.Salesman))
|
||||
item.StaffProfitPer = staffProfit / float64(len(m.Salesman))
|
||||
|
@ -734,8 +801,11 @@ func (m *ErpOrderCreateReq) GetSalesmanList() (string, error) {
|
|||
}
|
||||
item.Name = userInfo.NickName
|
||||
item.SalesmanPer = staffProfit * userInfo.SalesCommRate / float64(len(m.Salesman))
|
||||
|
||||
salesmanList = append(salesmanList, item)
|
||||
}
|
||||
|
||||
m.Salesman = salesmanList
|
||||
jSalesman, err := json.Marshal(m.Salesman)
|
||||
if err != nil {
|
||||
logger.Error("salesman marshal err:", logger.Field("err", err))
|
||||
|
@ -770,13 +840,13 @@ func GetErpOrderCommodityMap(ids []uint32) (map[uint32]ErpOrderCommodity, error)
|
|||
return commodityMap, nil
|
||||
}
|
||||
var commodities []ErpOrderCommodity
|
||||
err := orm.Eloquent.Table("erp_order_commodity").Where("id IN (?)", ids).Find(&commodities).Error
|
||||
err := orm.Eloquent.Table("erp_order_commodity").Where("erp_commodity_id IN (?)", ids).Find(&commodities).Error
|
||||
if err != nil {
|
||||
logger.Error("commodities err:", logger.Field("err", err))
|
||||
return commodityMap, err
|
||||
}
|
||||
for i, _ := range commodities {
|
||||
commodityMap[commodities[i].ID] = commodities[i]
|
||||
commodityMap[commodities[i].ErpCommodityId] = commodities[i]
|
||||
}
|
||||
return commodityMap, nil
|
||||
}
|
||||
|
@ -2447,7 +2517,7 @@ func EditErpOrder(req *ErpOrderCreateReq, sysUser *SysUser) error {
|
|||
return errors.New("操作失败:" + err.Error())
|
||||
}
|
||||
|
||||
if orderInfo.State != "ErpOrderStateUnAudit" {
|
||||
if orderInfo.State != ErpOrderStateUnAudit {
|
||||
logger.Error("EditErpOrder err:", logger.Field("err", err))
|
||||
return errors.New("订单状态不是待审核,操作失败")
|
||||
}
|
||||
|
@ -2565,8 +2635,12 @@ func checkOrderData(req *ErpOrderCreateReq, sysUser *SysUser) (*ErpOrder, error)
|
|||
}
|
||||
|
||||
// 校验商品相关金额是否符合要求
|
||||
for i, _ := range req.ErpOrderCommodities {
|
||||
for i, item := range req.ErpOrderCommodities {
|
||||
if req.RetailType == RetailTypeRejected { // 零售退货订单
|
||||
if item.RejectedOrderCommodityId == 0 {
|
||||
logger.Error("rejected_order_commodity_id is null")
|
||||
return nil, errors.New("rejected_order_commodity_id is null")
|
||||
}
|
||||
v, ok := orderCommodityMap[req.ErpOrderCommodities[i].RejectedOrderCommodityId]
|
||||
if ok {
|
||||
v.RejectedPrice = req.ErpOrderCommodities[i].RejectedPrice // 退货单价
|
||||
|
|
48
docs/docs.go
48
docs/docs.go
|
@ -1869,15 +1869,15 @@ const docTemplate = `{
|
|||
"tags": [
|
||||
"库存管理"
|
||||
],
|
||||
"summary": "查询商品串码或条码",
|
||||
"summary": "添加备注",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "查询商品串码或条码模型",
|
||||
"description": "添加备注模型",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.QueryCodeReq"
|
||||
"$ref": "#/definitions/inventorymanage.AddRemarkReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -1885,7 +1885,7 @@ const docTemplate = `{
|
|||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.QueryCodeResp"
|
||||
"$ref": "#/definitions/app.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2056,6 +2056,39 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/inventory/query_code": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"库存管理"
|
||||
],
|
||||
"summary": "查询商品串码或条码",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "查询商品串码或条码模型",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.QueryCodeReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.QueryCodeResp"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/loginlog": {
|
||||
"put": {
|
||||
"security": [
|
||||
|
@ -5597,6 +5630,10 @@ const docTemplate = `{
|
|||
"description": "单据编号",
|
||||
"type": "string"
|
||||
},
|
||||
"commodity_name": {
|
||||
"description": "商品名称",
|
||||
"type": "string"
|
||||
},
|
||||
"end_time": {
|
||||
"description": "结束时间",
|
||||
"type": "string"
|
||||
|
@ -6555,6 +6592,9 @@ const docTemplate = `{
|
|||
"description": "1-管理系统 2-合作商系统",
|
||||
"type": "integer"
|
||||
},
|
||||
"uid": {
|
||||
"type": "integer"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
@ -1858,15 +1858,15 @@
|
|||
"tags": [
|
||||
"库存管理"
|
||||
],
|
||||
"summary": "查询商品串码或条码",
|
||||
"summary": "添加备注",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "查询商品串码或条码模型",
|
||||
"description": "添加备注模型",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.QueryCodeReq"
|
||||
"$ref": "#/definitions/inventorymanage.AddRemarkReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -1874,7 +1874,7 @@
|
|||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.QueryCodeResp"
|
||||
"$ref": "#/definitions/app.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2045,6 +2045,39 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/inventory/query_code": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"库存管理"
|
||||
],
|
||||
"summary": "查询商品串码或条码",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "查询商品串码或条码模型",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.QueryCodeReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.QueryCodeResp"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/loginlog": {
|
||||
"put": {
|
||||
"security": [
|
||||
|
@ -5586,6 +5619,10 @@
|
|||
"description": "单据编号",
|
||||
"type": "string"
|
||||
},
|
||||
"commodity_name": {
|
||||
"description": "商品名称",
|
||||
"type": "string"
|
||||
},
|
||||
"end_time": {
|
||||
"description": "结束时间",
|
||||
"type": "string"
|
||||
|
@ -6544,6 +6581,9 @@
|
|||
"description": "1-管理系统 2-合作商系统",
|
||||
"type": "integer"
|
||||
},
|
||||
"uid": {
|
||||
"type": "integer"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
@ -1192,6 +1192,9 @@ definitions:
|
|||
bill_sn:
|
||||
description: 单据编号
|
||||
type: string
|
||||
commodity_name:
|
||||
description: 商品名称
|
||||
type: string
|
||||
end_time:
|
||||
description: 结束时间
|
||||
type: string
|
||||
|
@ -1882,6 +1885,8 @@ definitions:
|
|||
sys_type:
|
||||
description: 1-管理系统 2-合作商系统
|
||||
type: integer
|
||||
uid:
|
||||
type: integer
|
||||
username:
|
||||
type: string
|
||||
uuid:
|
||||
|
@ -4190,20 +4195,20 @@ paths:
|
|||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: 查询商品串码或条码模型
|
||||
- description: 添加备注模型
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/models.QueryCodeReq'
|
||||
$ref: '#/definitions/inventorymanage.AddRemarkReq'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/models.QueryCodeResp'
|
||||
summary: 查询商品串码或条码
|
||||
$ref: '#/definitions/app.Response'
|
||||
summary: 添加备注
|
||||
tags:
|
||||
- 库存管理
|
||||
/api/v1/inventory/delivery:
|
||||
|
@ -4311,6 +4316,27 @@ paths:
|
|||
summary: 批量打印
|
||||
tags:
|
||||
- 库存管理
|
||||
/api/v1/inventory/query_code:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: 查询商品串码或条码模型
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/models.QueryCodeReq'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/models.QueryCodeResp'
|
||||
summary: 查询商品串码或条码
|
||||
tags:
|
||||
- 库存管理
|
||||
/api/v1/loginlog:
|
||||
post:
|
||||
consumes:
|
||||
|
|
Loading…
Reference in New Issue
Block a user