修复缺陷:

(1)优化库存调拨权限,有调出调入门店任何一方权限均可查看详情;
(2)查询商品串码或条码接口入参调整,新增库存状态和门店id;
(3)零售明细中退货订单相关金额和数量调整为负数;
(4)小程序商城退货流程优化,积分更新添加事务;
(5)系统用户列表支持单个门店用户查询,过滤掉门店权限过期的用户;
(6)新增/编辑采购订单校验修改,根据V1.4.1需求放开部分必填项校验;
This commit is contained in:
chenlin 2024-06-20 14:32:03 +08:00
parent f754f9ccd2
commit fb11fdd79c
11 changed files with 300 additions and 133 deletions

View File

@ -281,7 +281,8 @@ func InventoryAllotDetail(c *gin.Context) {
// 校验入参门店是否包含在用户所有门店中,是否过期 // 校验入参门店是否包含在用户所有门店中,是否过期
if !(tools.GetRoleName(c) == "admin" || tools.GetRoleName(c) == "系统管理员") { if !(tools.GetRoleName(c) == "admin" || tools.GetRoleName(c) == "系统管理员") {
if !models.CheckUserStore(allotOrder.DeliverStoreId, sysUser) { if !models.CheckUserStore(allotOrder.DeliverStoreId, sysUser) &&
!models.CheckUserStore(allotOrder.ReceiveStoreId, sysUser) {
app.Error(c, http.StatusInternalServerError, errors.New("操作失败:您没有该门店权限"), app.Error(c, http.StatusInternalServerError, errors.New("操作失败:您没有该门店权限"),
"操作失败:您没有该门店权限") "操作失败:您没有该门店权限")
return return

View File

@ -6,6 +6,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"go-admin/app/admin/models" "go-admin/app/admin/models"
orm "go-admin/common/global"
"go-admin/tools/app" "go-admin/tools/app"
"net/http" "net/http"
) )
@ -89,8 +90,21 @@ func GoodsOrderDeliver(c *gin.Context) {
// todo 暂时使用用户有效门店,待后续产品梳理流程后再修改 // todo 暂时使用用户有效门店,待后续产品梳理流程后再修改
//req.DeliverStoreId = sysUser.StoreId //req.DeliverStoreId = sysUser.StoreId
var storeId int
storeInfo, _ := models.GetUserEffectiveStore(uint32(sysUser.UserId)) storeInfo, _ := models.GetUserEffectiveStore(uint32(sysUser.UserId))
req.DeliverStoreId = uint32(storeInfo[0].StoreID) if storeInfo == nil {
var stores []models.Store
err = orm.Eloquent.Table("store").Find(&stores).Error
if err != nil {
app.Error(c, http.StatusInternalServerError, errors.New("store is null"), "门店id为空")
return
}
storeId = int(stores[0].ID)
} else {
storeId = storeInfo[0].StoreID
}
req.DeliverStoreId = uint32(storeId)
orderDetail, err := req.OrderDeliver() orderDetail, err := req.OrderDeliver()
if err != nil { if err != nil {

View File

@ -214,6 +214,8 @@ type QueryCodeReq struct {
ScanCode string `json:"scan_code" binding:"required"` // 扫码枪扫码数据:串码/条码 ScanCode string `json:"scan_code" binding:"required"` // 扫码枪扫码数据:串码/条码
PageIndex int `json:"pageIndex"` // 页码 PageIndex int `json:"pageIndex"` // 页码
PageSize int `json:"pageSize"` // 页面条数 PageSize int `json:"pageSize"` // 页面条数
State uint32 `json:"state"` // 库存状态:1-在库 2-已售 3-采购退货 4-调拨中 5-出库前端只看14
StoreId uint32 `json:"store_id"` // 门店id
} }
type QueryCodeResp struct { type QueryCodeResp struct {
@ -339,7 +341,7 @@ func (m *ErpCommodityListReq) List() (*ErpCommodityListResp, error) {
qs = qs.Where("erp_supplier_id=?", m.ErpSupplierId) qs = qs.Where("erp_supplier_id=?", m.ErpSupplierId)
} }
if m.ErpBarcode != "" { if m.ErpBarcode != "" {
qs = qs.Where("erp_barcode=?", m.ErpBarcode) qs = qs.Where("erp_barcode LIKE ?", "%"+m.ErpBarcode+"%")
} }
var count int64 var count int64
@ -520,6 +522,36 @@ func SortReportByAllotDataCommodities(commodities []ReportByAllotData) {
sort.SliceStable(commodities, less) sort.SliceStable(commodities, less)
} }
// SortReportByDecisionCommodities 对商品数组进行排序
func SortReportByDecisionCommodities(commodities []DecisionReportData) {
// 定义排序函数
less := func(i, j int) bool {
// 解析商品编号,提取分类编号和商品编号的数字部分
catNumI, subCatNumI, threeSubCatNumI, itemNumI := parseSerialNumber(commodities[i].CommoditySerialNumber)
catNumJ, subCatNumJ, threeSubCatNumJ, itemNumJ := parseSerialNumber(commodities[j].CommoditySerialNumber)
// 按照分类编号从小到大排序
if catNumI != catNumJ {
return catNumI < catNumJ
}
// 如果分类编号相同,按照具体分类下的商品编号递增排序
if subCatNumI != subCatNumJ {
return subCatNumI < subCatNumJ
}
if threeSubCatNumI != threeSubCatNumJ {
return threeSubCatNumI < threeSubCatNumJ
}
// 如果具体分类编号也相同,按照商品编号递增排序
return itemNumI < itemNumJ
}
// 调用排序函数进行排序
sort.SliceStable(commodities, less)
}
// SortReportByOtherDataCommodities 对商品数组进行排序 // SortReportByOtherDataCommodities 对商品数组进行排序
func SortReportByOtherDataCommodities(commodities []ReportByOtherData) { func SortReportByOtherDataCommodities(commodities []ReportByOtherData) {
// 定义排序函数 // 定义排序函数
@ -2683,6 +2715,14 @@ func GetCodeList(req *QueryCodeReq) (*QueryCodeResp, error) {
qs := orm.Eloquent.Debug().Table("erp_stock_commodity"). qs := orm.Eloquent.Debug().Table("erp_stock_commodity").
Where("imei LIKE ? OR erp_barcode LIKE ?", "%"+req.ScanCode+"%", "%"+req.ScanCode+"%") Where("imei LIKE ? OR erp_barcode LIKE ?", "%"+req.ScanCode+"%", "%"+req.ScanCode+"%")
if req.State != 0 {
qs = qs.Where("state = ?", req.State)
}
if req.StoreId != 0 {
qs = qs.Where("store_id = ?", req.StoreId)
}
es := qs es := qs
err := qs.Order(orderStr).Offset(page * req.PageSize).Limit(req.PageSize).Find(&commodities).Error err := qs.Order(orderStr).Offset(page * req.PageSize).Limit(req.PageSize).Find(&commodities).Error
if err != nil && err != RecordNotFound { if err != nil && err != RecordNotFound {

View File

@ -10,7 +10,6 @@ import (
"go-admin/tools" "go-admin/tools"
"go-admin/tools/config" "go-admin/tools/config"
"math" "math"
"sort"
"strconv" "strconv"
"sync" "sync"
"time" "time"
@ -60,26 +59,27 @@ type DecisionSumData struct {
// DecisionReportData 进销存报表数据 // DecisionReportData 进销存报表数据
type DecisionReportData struct { type DecisionReportData struct {
CommodityId uint32 `json:"commodity_id"` // 商品id CommodityId uint32 `json:"commodity_id"` // 商品id
CommodityName string `json:"commodity_name"` // 商品名称 CommodityName string `json:"commodity_name"` // 商品名称
CategoryID uint32 `json:"category_id"` // 商品分类id CommoditySerialNumber string `json:"commodity_serial_number" gorm:"-"` // 商品编码
CategoryName string `json:"category_name"` // 商品分类名称 CategoryID uint32 `json:"category_id"` // 商品分类id
BeginStock uint32 `json:"begin_stock"` // 期初库存 CategoryName string `json:"category_name"` // 商品分类名称
BeginAmount float64 `json:"begin_amount"` // 期初金额 BeginStock uint32 `json:"begin_stock"` // 期初库存
PurchaseStock uint32 `json:"purchase_stock"` // 采购进货 BeginAmount float64 `json:"begin_amount"` // 期初金额
PurchaseReturn uint32 `json:"purchase_return"` // 采购退货 PurchaseStock uint32 `json:"purchase_stock"` // 采购进货
OrderSale uint32 `json:"order_sale"` // 零售销售 PurchaseReturn uint32 `json:"purchase_return"` // 采购退货
OrderReject uint32 `json:"order_reject"` // 零售退货 OrderSale uint32 `json:"order_sale"` // 零售销售
AllotIn uint32 `json:"allot_in"` // 调拨入库 OrderReject uint32 `json:"order_reject"` // 零售退货
AllotWaitIn uint32 `json:"allot_wait_in"` // 在途库存(入库) AllotIn uint32 `json:"allot_in"` // 调拨入库
AllotOut uint32 `json:"allot_out"` // 调拨出库 AllotWaitIn uint32 `json:"allot_wait_in"` // 在途库存(入库)
AllotWaitOut uint32 `json:"allot_wait_out"` // 在途库存(出库) AllotOut uint32 `json:"allot_out"` // 调拨出库
ProductIn uint32 `json:"product_in"` // 产品入库 AllotWaitOut uint32 `json:"allot_wait_out"` // 在途库存(出库)
SystemOut uint32 `json:"system_out"` // 系统出库 ProductIn uint32 `json:"product_in"` // 产品入库
CheckIn uint32 `json:"check_in"` // 盘点入库 SystemOut uint32 `json:"system_out"` // 系统出库
CheckOut uint32 `json:"check_out"` // 盘点出库 CheckIn uint32 `json:"check_in"` // 盘点入库
EndStock uint32 `json:"end_stock"` // 期末数量 CheckOut uint32 `json:"check_out"` // 盘点出库
EndAmount float64 `json:"end_amount"` // 期末金额 EndStock uint32 `json:"end_stock"` // 期末数量
EndAmount float64 `json:"end_amount"` // 期末金额
} }
// DecisionReportList 进销存报表 // DecisionReportList 进销存报表
@ -172,6 +172,7 @@ func (m *ErpDecisionReportReq) DecisionReportList(c *gin.Context) (*ErpDecisionR
var reportData DecisionReportData var reportData DecisionReportData
reportData.CommodityId = item.ErpCommodityId reportData.CommodityId = item.ErpCommodityId
reportData.CommodityName = item.ErpCommodityName reportData.CommodityName = item.ErpCommodityName
reportData.CommoditySerialNumber = item.CommoditySerialNumber
reportData.CategoryID = item.ErpCategoryId reportData.CategoryID = item.ErpCategoryId
reportData.CategoryName = item.ErpCategoryName reportData.CategoryName = item.ErpCategoryName
@ -285,12 +286,7 @@ func (m *ErpDecisionReportReq) DecisionReportList(c *gin.Context) (*ErpDecisionR
} }
// 排序规则:商品编号小 // 排序规则:商品编号小
sort.Slice(reportList, func(i, j int) bool { SortReportByDecisionCommodities(reportList)
if reportList[i].CommodityId != reportList[j].CommodityId {
return reportList[i].CommodityId < reportList[j].CommodityId
}
return true
})
resp.SumData = sumData resp.SumData = sumData
resp.Total = len(reportList) resp.Total = len(reportList)
@ -597,7 +593,7 @@ func getChangeReduceCount(req *ErpDecisionReportReq, stock ErpStock) (DecisionRe
qs = qs.Where("erp_inventory_change_order.audit_time > ?", parse) qs = qs.Where("erp_inventory_change_order.audit_time > ?", parse)
} }
err := qs.Select("SUM(erp_inventory_change_commodity.count) AS check_in"). err := qs.Select("SUM(erp_inventory_change_commodity.count) AS check_out").
Joins("JOIN erp_inventory_change_order "+ Joins("JOIN erp_inventory_change_order "+
"ON erp_inventory_change_order.id = erp_inventory_change_commodity.change_order_id"). "ON erp_inventory_change_order.id = erp_inventory_change_commodity.change_order_id").
Where("erp_inventory_change_order.change_type = ? and erp_inventory_change_order.store_id = ? "+ Where("erp_inventory_change_order.change_type = ? and erp_inventory_change_order.store_id = ? "+
@ -704,12 +700,12 @@ func getAllotWaitOutCount(req *ErpDecisionReportReq, stock ErpStock) (DecisionRe
qs = qs.Where("erp_inventory_allot_commodity.audit_time > ?", parse) qs = qs.Where("erp_inventory_allot_commodity.audit_time > ?", parse)
} }
err := qs.Select("SUM(erp_inventory_allot_commodity.count) AS allot_out"). err := qs.Select("SUM(erp_inventory_allot_commodity.count) AS allot_wait_out").
Joins("JOIN erp_inventory_allot_order "+ Joins("JOIN erp_inventory_allot_order "+
"ON erp_inventory_allot_order.id = erp_inventory_allot_commodity.allot_order_id"). "ON erp_inventory_allot_order.id = erp_inventory_allot_commodity.allot_order_id").
Where("erp_inventory_allot_order.deliver_store_id = ? and erp_inventory_allot_order.state != ? "+ Where("erp_inventory_allot_order.deliver_store_id = ? and erp_inventory_allot_order.state in (?) "+
"and erp_inventory_allot_commodity.commodity_id = ?", "and erp_inventory_allot_commodity.commodity_id = ?",
stock.StoreId, ErpInventoryAllotOrderUnAudit, stock.ErpCommodityId). stock.StoreId, []uint32{ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive}, stock.ErpCommodityId).
Find(&reportData).Error Find(&reportData).Error
if err != nil { if err != nil {
return DecisionReportData{}, err return DecisionReportData{}, err
@ -822,7 +818,7 @@ func getSystemEndCount(req *ErpDecisionReportReq, stock ErpStock) (DecisionRepor
} }
err := qs.Select("SUM(count) as end_stock, SUM(wholesale_price) as end_amount"). err := qs.Select("SUM(count) as end_stock, SUM(wholesale_price) as end_amount").
Where("state = ? and store_id = ? and erp_commodity_id = ?", InStock, stock.StoreId, Where("state in (?) and store_id = ? and erp_commodity_id = ?", []uint32{InStock, InAllot}, stock.StoreId,
stock.ErpCommodityId).Find(&reportData).Error stock.ErpCommodityId).Find(&reportData).Error
if err != nil { if err != nil {
return DecisionReportData{}, err return DecisionReportData{}, err

View File

@ -1106,7 +1106,12 @@ func ErpOrderRetailDetailSetCommodity(list []ErpOrder) {
list[i].TotalStaffProfit = -list[i].TotalStaffProfit list[i].TotalStaffProfit = -list[i].TotalStaffProfit
list[i].TotalDiscount = -math.Abs(list[i].TotalDiscount) list[i].TotalDiscount = -math.Abs(list[i].TotalDiscount)
list[i].VmCount = -uint32(math.Abs(float64(list[i].VmCount))) list[i].VmCount = -uint32(math.Abs(float64(list[i].VmCount)))
list[i].StorePer = -math.Abs(list[i].StorePer) if list[i].TotalStaffProfit > 0 {
list[i].StorePer = math.Abs(list[i].StorePer)
} else {
list[i].StorePer = -math.Abs(list[i].StorePer)
}
} }
} }
} }
@ -3706,8 +3711,11 @@ func QueryReceiptData(req *ErpOrderDeleteReq, c *gin.Context) (*ErpOrderReceiptD
commodityMap[key] = tableData commodityMap[key] = tableData
resp.TotalAmount += item.SaleDiscount resp.TotalAmount += item.SaleDiscount
resp.MembersAmount += item.MemberDiscount
resp.IntegrationAmount += item.VmDiscount resp.IntegrationAmount += item.VmDiscount
if order.MemberType != ErpOrderMemberTypeGeneral {
resp.MembersAmount += item.MemberDiscount
}
} }
resp.ChandiseObj = commodityMap resp.ChandiseObj = commodityMap
@ -3724,7 +3732,9 @@ func QueryReceiptData(req *ErpOrderDeleteReq, c *gin.Context) (*ErpOrderReceiptD
resp.ModeOfPayment = cashierMap resp.ModeOfPayment = cashierMap
resp.ActualPayment = order.TotalAmount resp.ActualPayment = order.TotalAmount
resp.Tel = order.Tel resp.Tel = order.Tel
resp.Uid = order.Uid if order.MemberType != ErpOrderMemberTypeGeneral {
resp.Uid = order.Uid
}
resp.StoreTel = storeInfo.Tel resp.StoreTel = storeInfo.Tel
resp.StoreAddress = storeInfo.Address resp.StoreAddress = storeInfo.Address

View File

@ -753,17 +753,18 @@ func (*GameCardGoods) TableName() string {
return "game_card_goods" return "game_card_goods"
} }
// gen:qs // GameCardGoodsStock
// 锁定数量 = 卡池总数 - 库存数量 - 客户持有数量
type GameCardGoodsStock struct { type GameCardGoodsStock struct {
Model Model
StoreId uint64 `json:"store_id"` // 门店id StoreId uint64 `json:"store_id"` // 门店id
GameCardId uint64 `json:"game_card_id"` // 游戏卡id GameCardId uint64 `json:"game_card_id"` // 游戏卡id
StoreStock uint32 `json:"store_stock"` // 门店库存 StoreStock uint32 `json:"store_stock"` // 门店库存
RentStock uint32 `json:"rent_stock"` // 租借库存 RentStock uint32 `json:"rent_stock"` // 库存数量
UserHoldStock uint32 `json:"user_hold_stock"` UserHoldStock uint32 `json:"user_hold_stock"` // 客户持有数量
OrderCount uint32 `json:"order_count"` OrderCount uint32 `json:"order_count"` // 订单数量
TotalStock uint32 `json:"total_stock"` // 卡池-总数 TotalStock uint32 `json:"total_stock"` // 卡池总数
Name string `json:"name" gorm:"-"` // 名称 Name string `json:"name" gorm:"-"` // 名称
CoverImg string `json:"cover_img" gorm:"-"` // 封面 CoverImg string `json:"cover_img" gorm:"-"` // 封面
} }

View File

@ -661,9 +661,9 @@ func (m *InventoryReportByAllotReq) ReportAllotList(c *gin.Context) (*InventoryR
switch m.State { switch m.State {
case 1: // 调拨中 case 1: // 调拨中
qs = qs.Where("erp_inventory_allot_order.state IN (?)", qs = qs.Where("erp_inventory_allot_order.state IN (?)",
ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive) []uint32{ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive})
countQuery = countQuery.Where("erp_inventory_allot_order.state IN (?)", countQuery = countQuery.Where("erp_inventory_allot_order.state IN (?)",
ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive) []uint32{ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive})
case 2: // 已完成 case 2: // 已完成
qs = qs.Where("erp_inventory_allot_order.state = ?", ErpInventoryAllotOrderFinished) qs = qs.Where("erp_inventory_allot_order.state = ?", ErpInventoryAllotOrderFinished)
countQuery = countQuery.Where("erp_inventory_allot_order.state = ?", ErpInventoryAllotOrderFinished) countQuery = countQuery.Where("erp_inventory_allot_order.state = ?", ErpInventoryAllotOrderFinished)
@ -1022,9 +1022,9 @@ func (m *InventoryReportAllotDetailReq) ReportAllotDetailList(c *gin.Context) (*
switch m.State { switch m.State {
case 1: // 调拨中 case 1: // 调拨中
qs = qs.Where("erp_inventory_allot_order.state IN (?)", qs = qs.Where("erp_inventory_allot_order.state IN (?)",
ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive) []uint32{ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive})
countQuery = countQuery.Where("erp_inventory_allot_order.state IN (?)", countQuery = countQuery.Where("erp_inventory_allot_order.state IN (?)",
ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive) []uint32{ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive})
case 2: // 已完成 case 2: // 已完成
qs = qs.Where("erp_inventory_allot_order.state = ?", ErpInventoryAllotOrderFinished) qs = qs.Where("erp_inventory_allot_order.state = ?", ErpInventoryAllotOrderFinished)
countQuery = countQuery.Where("erp_inventory_allot_order.state = ?", ErpInventoryAllotOrderFinished) countQuery = countQuery.Where("erp_inventory_allot_order.state = ?", ErpInventoryAllotOrderFinished)

View File

@ -1160,8 +1160,9 @@ func (r *GoodsOrderRefundSendReceiveReq) Receive() error {
return errors.New("state err") return errors.New("state err")
} }
begin := orm.Eloquent.Begin()
if goodsOrder.Vm != 0 { if goodsOrder.Vm != 0 {
err = UserVmUpdate(nil, 0, goodsOrder.Uid, int(goodsOrder.Vm), VmEventBuyGoods, "购买商品积分抵扣取消") err = UserVmUpdate(begin, 0, goodsOrder.Uid, int(goodsOrder.Vm), VmEventBuyGoods, "购买商品积分抵扣取消")
if err != nil { if err != nil {
logger.Errorf("update user vm err:", err) logger.Errorf("update user vm err:", err)
return err return err
@ -1186,7 +1187,7 @@ func (r *GoodsOrderRefundSendReceiveReq) Receive() error {
log.Error().Msgf("order refund err:%#v", err) log.Error().Msgf("order refund err:%#v", err)
return err return err
} }
begin := orm.Eloquent.Begin()
err = begin.Table("goods_order").Where("order_id=?", r.OrderId).Update("state", GoodsOrderStateRefunded).Error err = begin.Table("goods_order").Where("order_id=?", r.OrderId).Update("state", GoodsOrderStateRefunded).Error
if err != nil { if err != nil {
begin.Rollback() begin.Rollback()

View File

@ -123,15 +123,15 @@ type ErpPurchaseCreateReq struct {
PurchaseType string `json:"purchase_type" binding:"required"` // 采购类型procure-采购 reject-退货 PurchaseType string `json:"purchase_type" binding:"required"` // 采购类型procure-采购 reject-退货
PurchaseOrderSn string `json:"purchase_order_sn"` // 采购退货订单号:出库必传 PurchaseOrderSn string `json:"purchase_order_sn"` // 采购退货订单号:出库必传
StoreId uint32 `json:"store_id"` // 门店id:入库必传 StoreId uint32 `json:"store_id"` // 门店id:入库必传
DeliveryAddress string `json:"delivery_address"` // 交货地址:入库必传 DeliveryAddress string `json:"delivery_address"` // 交货地址
HandlerId uint32 `json:"handler_id" binding:"required"` // 经手人id HandlerId uint32 `json:"handler_id" binding:"required"` // 经手人id
HandlerName string `json:"handler_name"` // 经手人名称 HandlerName string `json:"handler_name"` // 经手人名称
ErpSupplierId uint32 `json:"erp_supplier_id"` // 供应商id:入库必传 ErpSupplierId uint32 `json:"erp_supplier_id"` // 供应商id:入库必传
ErpCashierId uint32 `json:"erp_cashier_id" binding:"required"` // 付款方式 ErpCashierId uint32 `json:"erp_cashier_id"` // 付款方式
AccountHolder string `json:"account_holder"` // 收款人:入库必传 AccountHolder string `json:"account_holder"` // 收款人
OpeningBank string `json:"opening_bank"` // 开户行:入库必传 OpeningBank string `json:"opening_bank"` // 开户行
BankAccount string `json:"bank_account" ` // 银行卡号:入库必传 BankAccount string `json:"bank_account" ` // 银行卡号
DeliveryTime string `json:"delivery_time" ` // 交货日期:入库必传 DeliveryTime string `json:"delivery_time" ` // 交货日期
Remark string `json:"remark"` // 备注 Remark string `json:"remark"` // 备注
ErpPurchaseCommodities []ErpPurchaseCommodity `json:"erp_purchase_commodity" binding:"required"` // 采购商品信息 ErpPurchaseCommodities []ErpPurchaseCommodity `json:"erp_purchase_commodity" binding:"required"` // 采购商品信息
} }
@ -142,15 +142,15 @@ type ErpPurchaseEditReq struct {
PurchaseType string `json:"purchase_type" binding:"required"` // 采购类型procure-采购 reject-退货 PurchaseType string `json:"purchase_type" binding:"required"` // 采购类型procure-采购 reject-退货
PurchaseOrderSn string `json:"purchase_order_sn"` // 采购退货订单号:出库必传 PurchaseOrderSn string `json:"purchase_order_sn"` // 采购退货订单号:出库必传
StoreId uint32 `json:"store_id"` // 门店id:入库必传 StoreId uint32 `json:"store_id"` // 门店id:入库必传
DeliveryAddress string `json:"delivery_address"` // 交货地址:入库必传 DeliveryAddress string `json:"delivery_address"` // 交货地址
HandlerId uint32 `json:"handler_id" binding:"required"` // 经手人id HandlerId uint32 `json:"handler_id" binding:"required"` // 经手人id
HandlerName string `json:"handler_name"` // 经手人名称 HandlerName string `json:"handler_name"` // 经手人名称
ErpSupplierId uint32 `json:"erp_supplier_id"` // 供应商id:入库必传 ErpSupplierId uint32 `json:"erp_supplier_id"` // 供应商id:入库必传
ErpCashierId uint32 `json:"erp_cashier_id" binding:"required"` // 付款方式 ErpCashierId uint32 `json:"erp_cashier_id"` // 付款方式
AccountHolder string `json:"account_holder"` // 收款人:入库必传 AccountHolder string `json:"account_holder"` // 收款人
OpeningBank string `json:"opening_bank"` // 开户行:入库必传 OpeningBank string `json:"opening_bank"` // 开户行
BankAccount string `json:"bank_account" ` // 银行卡号:入库必传 BankAccount string `json:"bank_account" ` // 银行卡号
DeliveryTime string `json:"delivery_time"` // 交货日期:入库必传 DeliveryTime string `json:"delivery_time"` // 交货日期
Remark string `json:"remark"` // 备注 Remark string `json:"remark"` // 备注
ErpPurchaseCommodities []ErpPurchaseCommodity `json:"erp_purchase_commodity" binding:"required"` // 采购商品信息 ErpPurchaseCommodities []ErpPurchaseCommodity `json:"erp_purchase_commodity" binding:"required"` // 采购商品信息
} }
@ -751,13 +751,27 @@ func (m *ErpPurchaseOrder) IdInit() error {
m.ErpSupplierName = supplier.Name m.ErpSupplierName = supplier.Name
} }
if m.ErpCashierId != 0 { //cashier, err := GetAccountDetail(int(m.ErpCashierId))
cashier, err := GetAccountDetail(int(m.ErpCashierId)) //if err != nil {
if err != nil { // logger.Error("get cashier err:", logger.Field("err", err))
logger.Error("get cashier err:", logger.Field("err", err)) // return err
return err //}
//m.ErpCashierName = cashier.Name
// 根据字典填充付款方式
var DictData DictData
DictData.DictType = "purchase_pay_type"
result, err := DictData.Get()
if err != nil {
return err
}
for _, item := range result {
dictValue, _ := tools.StringToInt(item.DictValue)
if int(m.ErpCashierId) == dictValue {
m.ErpCashierName = item.DictLabel
break
} }
m.ErpCashierName = cashier.Name
} }
return nil return nil
} }
@ -793,24 +807,24 @@ func CheckCreateErpPurchaseOrderParam(req *ErpPurchaseCreateReq) error {
if req.StoreId == 0 { if req.StoreId == 0 {
return errors.New("操作失败:门店id为空") return errors.New("操作失败:门店id为空")
} }
if req.DeliveryAddress == "" { //if req.DeliveryAddress == "" {
return errors.New("操作失败:交货地址为空") // return errors.New("操作失败:交货地址为空")
} //}
if req.ErpSupplierId == 0 { if req.ErpSupplierId == 0 {
return errors.New("操作失败:供应商id为空") return errors.New("操作失败:供应商id为空")
} }
if req.AccountHolder == "" { //if req.AccountHolder == "" {
return errors.New("操作失败:收款人为空") // return errors.New("操作失败:收款人为空")
} //}
if req.OpeningBank == "" { //if req.OpeningBank == "" {
return errors.New("操作失败:开户行为空") // return errors.New("操作失败:开户行为空")
} //}
if req.BankAccount == "" { //if req.BankAccount == "" {
return errors.New("操作失败:银行卡号为空") // return errors.New("操作失败:银行卡号为空")
} //}
if req.DeliveryTime == "" { //if req.DeliveryTime == "" {
return errors.New("操作失败:交货日期为空") // return errors.New("操作失败:交货日期为空")
} //}
for _, item := range req.ErpPurchaseCommodities { for _, item := range req.ErpPurchaseCommodities {
if item.Count <= 0 { if item.Count <= 0 {
return errors.New("操作失败:采购数量需大于0") return errors.New("操作失败:采购数量需大于0")
@ -838,24 +852,24 @@ func CheckEditErpPurchaseOrderParam(req *ErpPurchaseEditReq) error {
if req.StoreId == 0 { if req.StoreId == 0 {
return errors.New("操作失败:门店id为空") return errors.New("操作失败:门店id为空")
} }
if req.DeliveryAddress == "" { //if req.DeliveryAddress == "" {
return errors.New("操作失败:交货地址为空") // return errors.New("操作失败:交货地址为空")
} //}
if req.ErpSupplierId == 0 { if req.ErpSupplierId == 0 {
return errors.New("操作失败:供应商id为空") return errors.New("操作失败:供应商id为空")
} }
if req.AccountHolder == "" { //if req.AccountHolder == "" {
return errors.New("操作失败:收款人为空") // return errors.New("操作失败:收款人为空")
} //}
if req.OpeningBank == "" { //if req.OpeningBank == "" {
return errors.New("操作失败:开户行为空") // return errors.New("操作失败:开户行为空")
} //}
if req.BankAccount == "" { //if req.BankAccount == "" {
return errors.New("操作失败:银行卡号为空") // return errors.New("操作失败:银行卡号为空")
} //}
if req.DeliveryTime == "" { //if req.DeliveryTime == "" {
return errors.New("操作失败:交货日期为空") // return errors.New("操作失败:交货日期为空")
} //}
} else if req.PurchaseType == ErpRejectOrder { // 退货单 } else if req.PurchaseType == ErpRejectOrder { // 退货单
if req.PurchaseOrderSn == "" { if req.PurchaseOrderSn == "" {
return errors.New("操作失败:采购退货单据编号为空") return errors.New("操作失败:采购退货单据编号为空")
@ -2491,7 +2505,7 @@ func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq, c *gin.Context) (*Get
return resp, err return resp, err
} }
if req.SortField == "erp_commodity_serial_number" { if req.SortField == "erp_commodity_serial_number" || req.SortField == "erp_commodity_name" {
switch req.SortType { switch req.SortType {
case "desc": case "desc":
SortCommoditiesDesc(commodities) SortCommoditiesDesc(commodities)
@ -2524,7 +2538,7 @@ func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq, c *gin.Context) (*Get
return commodities[i].ErpSupplierId < commodities[j].ErpSupplierId return commodities[i].ErpSupplierId < commodities[j].ErpSupplierId
}) })
} }
} else { } else if req.SortField == "" {
// 排序规则主供应商id小 // 排序规则主供应商id小
sort.Slice(commodities, func(i, j int) bool { sort.Slice(commodities, func(i, j int) bool {
return commodities[i].ErpSupplierId < commodities[j].ErpSupplierId return commodities[i].ErpSupplierId < commodities[j].ErpSupplierId
@ -2600,8 +2614,32 @@ func getErpPurchaseDemandHide(req *GetErpPurchaseDemandReq, c *gin.Context) (*Ge
// 查询采购需求单信息筛选出有采购需求的商品id // 查询采购需求单信息筛选出有采购需求的商品id
var demand []ErpPurchaseDemand var demand []ErpPurchaseDemand
err := orm.Eloquent.Table("erp_purchase_demand"). demandQs := orm.Eloquent.Table("erp_purchase_demand").
Where("state = 1").Find(&demand).Error Where("state = 1")
// 非管理员才判断所属门店
if !(tools.GetRoleName(c) == "admin" || tools.GetRoleName(c) == "系统管理员") {
sysUser, err := GetSysUserByCtx(c)
if err != nil {
return nil, errors.New("操作失败:" + err.Error())
}
// 返回sysUser未过期的门店id列表
storeList := GetValidStoreIDs(sysUser.StoreData)
if len(storeList) > 0 {
if len(storeList) > 0 {
if len(storeList) == 1 {
demandQs = demandQs.Where("store_id = ?", storeList[0])
} else {
demandQs = demandQs.Where("store_id IN (?)", storeList)
}
}
} else {
return nil, errors.New("用户未绑定门店")
}
}
err := demandQs.Find(&demand).Error
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -4469,6 +4507,7 @@ func getReportByCommodityFromCommon(req *ErpPurchaseReportByCommodityReq, c *gin
if req.ErpCategoryID != 0 && v.ErpCategoryID != req.ErpCategoryID { if req.ErpCategoryID != 0 && v.ErpCategoryID != req.ErpCategoryID {
continue continue
} }
reportData.ErpCategoryID = v.ErpCategoryID reportData.ErpCategoryID = v.ErpCategoryID
reportData.ErpCategoryName = v.ErpCategoryName reportData.ErpCategoryName = v.ErpCategoryName
reportData.ErpCommodityId = v.ErpCommodityId reportData.ErpCommodityId = v.ErpCommodityId
@ -4519,21 +4558,21 @@ func getReportByCommodityFromCommon(req *ErpPurchaseReportByCommodityReq, c *gin
}, },
} }
if v.PurchaseType == ErpRejectOrder { // 退货单 //if v.PurchaseType == ErpRejectOrder { // 退货单
reportData.PlanCount = -reportData.PlanCount // reportData.PlanCount = -reportData.PlanCount
reportData.PlanAmount = -reportData.PlanAmount // reportData.PlanAmount = -reportData.PlanAmount
reportData.Amount = -reportData.Amount // reportData.Amount = -reportData.Amount
reportData.Count = -reportData.Count // reportData.Count = -reportData.Count
reportData.NonExecutionAmount = -reportData.NonExecutionAmount // reportData.NonExecutionAmount = -reportData.NonExecutionAmount
reportData.NonExecutionCount = -reportData.NonExecutionCount // reportData.NonExecutionCount = -reportData.NonExecutionCount
//
purchaseOrderData.PlanCount = -purchaseOrderData.PlanCount // purchaseOrderData.PlanCount = -purchaseOrderData.PlanCount
purchaseOrderData.PlanAmount = -purchaseOrderData.PlanAmount // purchaseOrderData.PlanAmount = -purchaseOrderData.PlanAmount
purchaseOrderData.Amount = -purchaseOrderData.Amount // purchaseOrderData.Amount = -purchaseOrderData.Amount
purchaseOrderData.Count = -purchaseOrderData.Count // purchaseOrderData.Count = -purchaseOrderData.Count
purchaseOrderData.NonExecutionAmount = -purchaseOrderData.NonExecutionAmount // purchaseOrderData.NonExecutionAmount = -purchaseOrderData.NonExecutionAmount
purchaseOrderData.NonExecutionCount = -purchaseOrderData.NonExecutionCount // purchaseOrderData.NonExecutionCount = -purchaseOrderData.NonExecutionCount
} //}
if v.MakerTime != nil && v.MakerTime.IsZero() { if v.MakerTime != nil && v.MakerTime.IsZero() {
purchaseOrderData.MakerTime = nil purchaseOrderData.MakerTime = nil
@ -4627,7 +4666,7 @@ func getPurchaseOrderAndCommodityData(orderID, commodityId uint32) (ErpCommodity
} }
// 查询采购订单的计划和执行信息 // 查询采购订单的计划和执行信息
purchaseData, commodityData, err := getSignalPurchaseData(purchaseOrder.ID, commodityId) purchaseData, commodityData, err := getSignalPurchaseData(purchaseOrder.ID, commodityId, purchaseOrder.PurchaseType)
if err != nil { if err != nil {
return ErpCommodityPurchaseOrderData{}, CommodityData{}, err return ErpCommodityPurchaseOrderData{}, CommodityData{}, err
} }
@ -4673,7 +4712,7 @@ func getPurchaseOrderAndCommodityData(orderID, commodityId uint32) (ErpCommodity
} }
// getSignalPurchaseData 根据 ErpPurchaseCommodity 表查询采购数据 // getSignalPurchaseData 根据 ErpPurchaseCommodity 表查询采购数据
func getSignalPurchaseData(erpPurchaseOrderId, commodityId uint32) (PurchaseData, CommodityData, error) { func getSignalPurchaseData(erpPurchaseOrderId, commodityId uint32, purchaseType string) (PurchaseData, CommodityData, error) {
var purchaseData PurchaseData var purchaseData PurchaseData
var commodityData CommodityData var commodityData CommodityData
@ -4695,7 +4734,9 @@ func getSignalPurchaseData(erpPurchaseOrderId, commodityId uint32) (PurchaseData
// pc.erp_purchase_order_id // pc.erp_purchase_order_id
//`, erpPurchaseOrderId, commodityId).Scan(&purchaseData).Error //`, erpPurchaseOrderId, commodityId).Scan(&purchaseData).Error
err := orm.Eloquent.Raw(` var err error
if purchaseType == ErpProcureOrder {
err = orm.Eloquent.Raw(`
SELECT SELECT
plan.plan_count AS plan_count, plan.plan_count AS plan_count,
plan.plan_price AS plan_price, plan.plan_price AS plan_price,
@ -4730,6 +4771,44 @@ JOIN
pi.erp_purchase_order_id pi.erp_purchase_order_id
) AS inventory ON 1 = 1 ) AS inventory ON 1 = 1
`, erpPurchaseOrderId, commodityId, erpPurchaseOrderId, commodityId).Scan(&purchaseData).Error `, erpPurchaseOrderId, commodityId, erpPurchaseOrderId, commodityId).Scan(&purchaseData).Error
} else {
err = orm.Eloquent.Raw(`
SELECT
plan.plan_count AS plan_count,
plan.plan_price AS plan_price,
plan.plan_amount AS plan_amount,
inventory.count AS count,
inventory.price AS price,
inventory.amount AS amount
FROM
(
SELECT
SUM(pc.rejected_count) AS plan_count,
AVG(pc.rejected_price) AS plan_price,
SUM(pc.rejected_amount) AS plan_amount
FROM
erp_purchase_commodity pc
WHERE
pc.erp_purchase_order_id = ? AND pc.erp_commodity_id = ?
GROUP BY
pc.erp_purchase_order_id
) AS plan
JOIN
(
SELECT
SUM(pi.count) AS count,
AVG(pi.implementation_price) AS price,
SUM(pi.amount) AS amount
FROM
erp_purchase_inventory pi
WHERE
pi.erp_purchase_order_id = ? AND pi.erp_commodity_id = ?
GROUP BY
pi.erp_purchase_order_id
) AS inventory ON 1 = 1
`, erpPurchaseOrderId, commodityId, erpPurchaseOrderId, commodityId).Scan(&purchaseData).Error
}
if err != nil { if err != nil {
logger.Error("getPurchaseData err:", logger.Field("err", err)) logger.Error("getPurchaseData err:", logger.Field("err", err))
return PurchaseData{}, CommodityData{}, err return PurchaseData{}, CommodityData{}, err
@ -4739,6 +4818,15 @@ JOIN
purchaseData.NonExecutionAmount = purchaseData.PlanAmount - purchaseData.Amount purchaseData.NonExecutionAmount = purchaseData.PlanAmount - purchaseData.Amount
purchaseData.NonExecutionCount = purchaseData.PlanCount - purchaseData.Count purchaseData.NonExecutionCount = purchaseData.PlanCount - purchaseData.Count
if purchaseType == ErpRejectOrder {
purchaseData.PlanCount = -purchaseData.PlanCount
purchaseData.PlanAmount = -purchaseData.PlanAmount
purchaseData.Amount = -purchaseData.Amount
purchaseData.Count = -purchaseData.Count
purchaseData.NonExecutionAmount = -purchaseData.NonExecutionAmount
purchaseData.NonExecutionCount = -purchaseData.NonExecutionCount
}
// 查询订单对应的商品信息 // 查询订单对应的商品信息
commodityInfo, err := GetCommodity(commodityId) commodityInfo, err := GetCommodity(commodityId)
if err != nil { if err != nil {

View File

@ -319,15 +319,31 @@ func (e *SysUser) GetPage(pageSize int, pageIndex int) ([]SysUserPage, int, erro
return nil, 0, err return nil, 0, err
} }
var resp []SysUserPage
// 反序列化 StoreData // 反序列化 StoreData
for i, v := range doc { for i, v := range doc {
if doc[i].StoreData != "" { if doc[i].StoreData != "" {
doc[i].StoreList = deserializeStoreData(v.StoreData) doc[i].StoreList = deserializeStoreData(v.StoreData)
doc[i].StoreData = "" doc[i].StoreData = ""
} }
if e.StoreId != 0 { // 查询某个门店的销售员时,判断用户门店有效期
// 返回sysUser未过期的门店id列表
storeList := GetValidStoreIDs(v.StoreData)
if len(storeList) > 0 {
tempList := CompareLists(storeList, []uint32{e.StoreId})
if len(tempList) == 0 { // 没有匹配的数据
continue
}
} else {
continue
}
}
resp = append(resp, doc[i])
} }
return doc, int(count), nil return resp, int(count), nil
} }
// 反序列化 StoreData // 反序列化 StoreData

View File

@ -59,10 +59,10 @@ func UserVmUpdate(gdb *gorm.DB, orderId, uid uint32, amount int, event, describe
// 变动前的积分 // 变动前的积分
nBeforeVm := userVm.Vm nBeforeVm := userVm.Vm
//flag := false flag := false
begin := gdb begin := gdb
if gdb == nil { if gdb == nil {
//flag = true flag = true
begin = orm.Eloquent.Begin() begin = orm.Eloquent.Begin()
} }
@ -117,14 +117,14 @@ func UserVmUpdate(gdb *gorm.DB, orderId, uid uint32, amount int, event, describe
return err return err
} }
//if flag { if flag {
// err = begin.Commit().Error err = begin.Commit().Error
// if err != nil { if err != nil {
// begin.Rollback() begin.Rollback()
// logger.Error("err:", logger.Field("err", err)) logger.Error("err:", logger.Field("err", err))
// return err return err
// } }
//} }
return nil return nil
} }