From fb11fdd79cb93c0d02156e4b95ea049adf88dec0 Mon Sep 17 00:00:00 2001 From: chenlin Date: Thu, 20 Jun 2024 14:32:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=BA=E9=99=B7=EF=BC=9A?= =?UTF-8?q?=20=EF=BC=881=EF=BC=89=E4=BC=98=E5=8C=96=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E8=B0=83=E6=8B=A8=E6=9D=83=E9=99=90=EF=BC=8C=E6=9C=89=E8=B0=83?= =?UTF-8?q?=E5=87=BA=E8=B0=83=E5=85=A5=E9=97=A8=E5=BA=97=E4=BB=BB=E4=BD=95?= =?UTF-8?q?=E4=B8=80=E6=96=B9=E6=9D=83=E9=99=90=E5=9D=87=E5=8F=AF=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E8=AF=A6=E6=83=85=EF=BC=9B=20=EF=BC=882=EF=BC=89?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=95=86=E5=93=81=E4=B8=B2=E7=A0=81=E6=88=96?= =?UTF-8?q?=E6=9D=A1=E7=A0=81=E6=8E=A5=E5=8F=A3=E5=85=A5=E5=8F=82=E8=B0=83?= =?UTF-8?q?=E6=95=B4=EF=BC=8C=E6=96=B0=E5=A2=9E=E5=BA=93=E5=AD=98=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=92=8C=E9=97=A8=E5=BA=97id=EF=BC=9B=20=EF=BC=883?= =?UTF-8?q?=EF=BC=89=E9=9B=B6=E5=94=AE=E6=98=8E=E7=BB=86=E4=B8=AD=E9=80=80?= =?UTF-8?q?=E8=B4=A7=E8=AE=A2=E5=8D=95=E7=9B=B8=E5=85=B3=E9=87=91=E9=A2=9D?= =?UTF-8?q?=E5=92=8C=E6=95=B0=E9=87=8F=E8=B0=83=E6=95=B4=E4=B8=BA=E8=B4=9F?= =?UTF-8?q?=E6=95=B0=EF=BC=9B=20=EF=BC=884=EF=BC=89=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E5=95=86=E5=9F=8E=E9=80=80=E8=B4=A7=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8C=E7=A7=AF=E5=88=86=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=8B=E5=8A=A1=EF=BC=9B=20=EF=BC=885?= =?UTF-8?q?=EF=BC=89=E7=B3=BB=E7=BB=9F=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8D=95=E4=B8=AA=E9=97=A8=E5=BA=97=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=9F=A5=E8=AF=A2=EF=BC=8C=E8=BF=87=E6=BB=A4=E6=8E=89?= =?UTF-8?q?=E9=97=A8=E5=BA=97=E6=9D=83=E9=99=90=E8=BF=87=E6=9C=9F=E7=9A=84?= =?UTF-8?q?=E7=94=A8=E6=88=B7=EF=BC=9B=20=EF=BC=886=EF=BC=89=E6=96=B0?= =?UTF-8?q?=E5=A2=9E/=E7=BC=96=E8=BE=91=E9=87=87=E8=B4=AD=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E6=A0=A1=E9=AA=8C=E4=BF=AE=E6=94=B9=EF=BC=8C=E6=A0=B9?= =?UTF-8?q?=E6=8D=AEV1.4.1=E9=9C=80=E6=B1=82=E6=94=BE=E5=BC=80=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=BF=85=E5=A1=AB=E9=A1=B9=E6=A0=A1=E9=AA=8C=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/apis/inventorymanage/allot.go | 3 +- app/admin/apis/mallmanage/mall_goods_order.go | 16 +- app/admin/models/commodity.go | 42 +++- app/admin/models/decision.go | 60 +++-- app/admin/models/erp_order.go | 16 +- app/admin/models/game_card.go | 17 +- app/admin/models/inventory_report.go | 8 +- app/admin/models/mall.go | 5 +- app/admin/models/purchase.go | 228 ++++++++++++------ app/admin/models/sysuser.go | 18 +- app/admin/models/user_vm.go | 20 +- 11 files changed, 300 insertions(+), 133 deletions(-) diff --git a/app/admin/apis/inventorymanage/allot.go b/app/admin/apis/inventorymanage/allot.go index f49a438..af0132f 100644 --- a/app/admin/apis/inventorymanage/allot.go +++ b/app/admin/apis/inventorymanage/allot.go @@ -281,7 +281,8 @@ func InventoryAllotDetail(c *gin.Context) { // 校验入参门店是否包含在用户所有门店中,是否过期 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("操作失败:您没有该门店权限"), "操作失败:您没有该门店权限") return diff --git a/app/admin/apis/mallmanage/mall_goods_order.go b/app/admin/apis/mallmanage/mall_goods_order.go index 277ba3a..7d9b8d0 100644 --- a/app/admin/apis/mallmanage/mall_goods_order.go +++ b/app/admin/apis/mallmanage/mall_goods_order.go @@ -6,6 +6,7 @@ import ( "github.com/gin-gonic/gin" "github.com/rs/zerolog/log" "go-admin/app/admin/models" + orm "go-admin/common/global" "go-admin/tools/app" "net/http" ) @@ -89,8 +90,21 @@ func GoodsOrderDeliver(c *gin.Context) { // todo 暂时使用用户有效门店,待后续产品梳理流程后再修改 //req.DeliverStoreId = sysUser.StoreId + var storeId int 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() if err != nil { diff --git a/app/admin/models/commodity.go b/app/admin/models/commodity.go index bc37cf7..5e0fe49 100644 --- a/app/admin/models/commodity.go +++ b/app/admin/models/commodity.go @@ -214,6 +214,8 @@ type QueryCodeReq struct { ScanCode string `json:"scan_code" binding:"required"` // 扫码枪扫码数据:串码/条码 PageIndex int `json:"pageIndex"` // 页码 PageSize int `json:"pageSize"` // 页面条数 + State uint32 `json:"state"` // 库存状态:1-在库 2-已售 3-采购退货 4-调拨中 5-出库(前端只看1,4) + StoreId uint32 `json:"store_id"` // 门店id } type QueryCodeResp struct { @@ -339,7 +341,7 @@ func (m *ErpCommodityListReq) List() (*ErpCommodityListResp, error) { qs = qs.Where("erp_supplier_id=?", m.ErpSupplierId) } if m.ErpBarcode != "" { - qs = qs.Where("erp_barcode=?", m.ErpBarcode) + qs = qs.Where("erp_barcode LIKE ?", "%"+m.ErpBarcode+"%") } var count int64 @@ -520,6 +522,36 @@ func SortReportByAllotDataCommodities(commodities []ReportByAllotData) { 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 对商品数组进行排序 func SortReportByOtherDataCommodities(commodities []ReportByOtherData) { // 定义排序函数 @@ -2683,6 +2715,14 @@ func GetCodeList(req *QueryCodeReq) (*QueryCodeResp, error) { qs := orm.Eloquent.Debug().Table("erp_stock_commodity"). 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 err := qs.Order(orderStr).Offset(page * req.PageSize).Limit(req.PageSize).Find(&commodities).Error if err != nil && err != RecordNotFound { diff --git a/app/admin/models/decision.go b/app/admin/models/decision.go index 2c940e0..df10d68 100644 --- a/app/admin/models/decision.go +++ b/app/admin/models/decision.go @@ -10,7 +10,6 @@ import ( "go-admin/tools" "go-admin/tools/config" "math" - "sort" "strconv" "sync" "time" @@ -60,26 +59,27 @@ type DecisionSumData struct { // DecisionReportData 进销存报表数据 type DecisionReportData struct { - CommodityId uint32 `json:"commodity_id"` // 商品id - CommodityName string `json:"commodity_name"` // 商品名称 - CategoryID uint32 `json:"category_id"` // 商品分类id - CategoryName string `json:"category_name"` // 商品分类名称 - BeginStock uint32 `json:"begin_stock"` // 期初库存 - BeginAmount float64 `json:"begin_amount"` // 期初金额 - PurchaseStock uint32 `json:"purchase_stock"` // 采购进货 - PurchaseReturn uint32 `json:"purchase_return"` // 采购退货 - OrderSale uint32 `json:"order_sale"` // 零售销售 - OrderReject uint32 `json:"order_reject"` // 零售退货 - AllotIn uint32 `json:"allot_in"` // 调拨入库 - AllotWaitIn uint32 `json:"allot_wait_in"` // 在途库存(入库) - AllotOut uint32 `json:"allot_out"` // 调拨出库 - AllotWaitOut uint32 `json:"allot_wait_out"` // 在途库存(出库) - ProductIn uint32 `json:"product_in"` // 产品入库 - SystemOut uint32 `json:"system_out"` // 系统出库 - CheckIn uint32 `json:"check_in"` // 盘点入库 - CheckOut uint32 `json:"check_out"` // 盘点出库 - EndStock uint32 `json:"end_stock"` // 期末数量 - EndAmount float64 `json:"end_amount"` // 期末金额 + CommodityId uint32 `json:"commodity_id"` // 商品id + CommodityName string `json:"commodity_name"` // 商品名称 + CommoditySerialNumber string `json:"commodity_serial_number" gorm:"-"` // 商品编码 + CategoryID uint32 `json:"category_id"` // 商品分类id + CategoryName string `json:"category_name"` // 商品分类名称 + BeginStock uint32 `json:"begin_stock"` // 期初库存 + BeginAmount float64 `json:"begin_amount"` // 期初金额 + PurchaseStock uint32 `json:"purchase_stock"` // 采购进货 + PurchaseReturn uint32 `json:"purchase_return"` // 采购退货 + OrderSale uint32 `json:"order_sale"` // 零售销售 + OrderReject uint32 `json:"order_reject"` // 零售退货 + AllotIn uint32 `json:"allot_in"` // 调拨入库 + AllotWaitIn uint32 `json:"allot_wait_in"` // 在途库存(入库) + AllotOut uint32 `json:"allot_out"` // 调拨出库 + AllotWaitOut uint32 `json:"allot_wait_out"` // 在途库存(出库) + ProductIn uint32 `json:"product_in"` // 产品入库 + SystemOut uint32 `json:"system_out"` // 系统出库 + CheckIn uint32 `json:"check_in"` // 盘点入库 + CheckOut uint32 `json:"check_out"` // 盘点出库 + EndStock uint32 `json:"end_stock"` // 期末数量 + EndAmount float64 `json:"end_amount"` // 期末金额 } // DecisionReportList 进销存报表 @@ -172,6 +172,7 @@ func (m *ErpDecisionReportReq) DecisionReportList(c *gin.Context) (*ErpDecisionR var reportData DecisionReportData reportData.CommodityId = item.ErpCommodityId reportData.CommodityName = item.ErpCommodityName + reportData.CommoditySerialNumber = item.CommoditySerialNumber reportData.CategoryID = item.ErpCategoryId reportData.CategoryName = item.ErpCategoryName @@ -285,12 +286,7 @@ func (m *ErpDecisionReportReq) DecisionReportList(c *gin.Context) (*ErpDecisionR } // 排序规则:商品编号小 - sort.Slice(reportList, func(i, j int) bool { - if reportList[i].CommodityId != reportList[j].CommodityId { - return reportList[i].CommodityId < reportList[j].CommodityId - } - return true - }) + SortReportByDecisionCommodities(reportList) resp.SumData = sumData 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) } - 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 "+ "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 = ? "+ @@ -704,12 +700,12 @@ func getAllotWaitOutCount(req *ErpDecisionReportReq, stock ErpStock) (DecisionRe 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 "+ "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 = ?", - stock.StoreId, ErpInventoryAllotOrderUnAudit, stock.ErpCommodityId). + stock.StoreId, []uint32{ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive}, stock.ErpCommodityId). Find(&reportData).Error if err != nil { 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"). - 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 if err != nil { return DecisionReportData{}, err diff --git a/app/admin/models/erp_order.go b/app/admin/models/erp_order.go index f7f09de..dc5df7f 100644 --- a/app/admin/models/erp_order.go +++ b/app/admin/models/erp_order.go @@ -1106,7 +1106,12 @@ func ErpOrderRetailDetailSetCommodity(list []ErpOrder) { list[i].TotalStaffProfit = -list[i].TotalStaffProfit list[i].TotalDiscount = -math.Abs(list[i].TotalDiscount) 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 resp.TotalAmount += item.SaleDiscount - resp.MembersAmount += item.MemberDiscount resp.IntegrationAmount += item.VmDiscount + + if order.MemberType != ErpOrderMemberTypeGeneral { + resp.MembersAmount += item.MemberDiscount + } } resp.ChandiseObj = commodityMap @@ -3724,7 +3732,9 @@ func QueryReceiptData(req *ErpOrderDeleteReq, c *gin.Context) (*ErpOrderReceiptD resp.ModeOfPayment = cashierMap resp.ActualPayment = order.TotalAmount resp.Tel = order.Tel - resp.Uid = order.Uid + if order.MemberType != ErpOrderMemberTypeGeneral { + resp.Uid = order.Uid + } resp.StoreTel = storeInfo.Tel resp.StoreAddress = storeInfo.Address diff --git a/app/admin/models/game_card.go b/app/admin/models/game_card.go index 23d47e4..f99433b 100644 --- a/app/admin/models/game_card.go +++ b/app/admin/models/game_card.go @@ -753,17 +753,18 @@ func (*GameCardGoods) TableName() string { return "game_card_goods" } -// gen:qs +// GameCardGoodsStock +// 锁定数量 = 卡池总数 - 库存数量 - 客户持有数量 type GameCardGoodsStock struct { Model - StoreId uint64 `json:"store_id"` // 门店id - GameCardId uint64 `json:"game_card_id"` // 游戏卡id - StoreStock uint32 `json:"store_stock"` // 门店库存 - RentStock uint32 `json:"rent_stock"` // 租借库存 - UserHoldStock uint32 `json:"user_hold_stock"` - OrderCount uint32 `json:"order_count"` - TotalStock uint32 `json:"total_stock"` // 卡池-总数 + StoreId uint64 `json:"store_id"` // 门店id + GameCardId uint64 `json:"game_card_id"` // 游戏卡id + StoreStock uint32 `json:"store_stock"` // 门店库存 + RentStock uint32 `json:"rent_stock"` // 库存数量 + UserHoldStock uint32 `json:"user_hold_stock"` // 客户持有数量 + OrderCount uint32 `json:"order_count"` // 订单数量 + TotalStock uint32 `json:"total_stock"` // 卡池总数 Name string `json:"name" gorm:"-"` // 名称 CoverImg string `json:"cover_img" gorm:"-"` // 封面 } diff --git a/app/admin/models/inventory_report.go b/app/admin/models/inventory_report.go index b5740f5..ecc30ae 100644 --- a/app/admin/models/inventory_report.go +++ b/app/admin/models/inventory_report.go @@ -661,9 +661,9 @@ func (m *InventoryReportByAllotReq) ReportAllotList(c *gin.Context) (*InventoryR switch m.State { case 1: // 调拨中 qs = qs.Where("erp_inventory_allot_order.state IN (?)", - ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive) + []uint32{ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive}) countQuery = countQuery.Where("erp_inventory_allot_order.state IN (?)", - ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive) + []uint32{ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive}) case 2: // 已完成 qs = qs.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 { case 1: // 调拨中 qs = qs.Where("erp_inventory_allot_order.state IN (?)", - ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive) + []uint32{ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive}) countQuery = countQuery.Where("erp_inventory_allot_order.state IN (?)", - ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive) + []uint32{ErpInventoryAllotOrderWaitSend, ErpInventoryAllotOrderWaitReceive}) case 2: // 已完成 qs = qs.Where("erp_inventory_allot_order.state = ?", ErpInventoryAllotOrderFinished) countQuery = countQuery.Where("erp_inventory_allot_order.state = ?", ErpInventoryAllotOrderFinished) diff --git a/app/admin/models/mall.go b/app/admin/models/mall.go index e3adf5e..92ffebb 100644 --- a/app/admin/models/mall.go +++ b/app/admin/models/mall.go @@ -1160,8 +1160,9 @@ func (r *GoodsOrderRefundSendReceiveReq) Receive() error { return errors.New("state err") } + begin := orm.Eloquent.Begin() 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 { logger.Errorf("update user vm err:", err) return err @@ -1186,7 +1187,7 @@ func (r *GoodsOrderRefundSendReceiveReq) Receive() error { log.Error().Msgf("order refund err:%#v", err) return err } - begin := orm.Eloquent.Begin() + err = begin.Table("goods_order").Where("order_id=?", r.OrderId).Update("state", GoodsOrderStateRefunded).Error if err != nil { begin.Rollback() diff --git a/app/admin/models/purchase.go b/app/admin/models/purchase.go index de873f0..0d1b270 100644 --- a/app/admin/models/purchase.go +++ b/app/admin/models/purchase.go @@ -123,15 +123,15 @@ type ErpPurchaseCreateReq struct { PurchaseType string `json:"purchase_type" binding:"required"` // 采购类型:procure-采购 reject-退货 PurchaseOrderSn string `json:"purchase_order_sn"` // 采购退货订单号:出库必传 StoreId uint32 `json:"store_id"` // 门店id:入库必传 - DeliveryAddress string `json:"delivery_address"` // 交货地址:入库必传 + DeliveryAddress string `json:"delivery_address"` // 交货地址 HandlerId uint32 `json:"handler_id" binding:"required"` // 经手人id HandlerName string `json:"handler_name"` // 经手人名称 ErpSupplierId uint32 `json:"erp_supplier_id"` // 供应商id:入库必传 - ErpCashierId uint32 `json:"erp_cashier_id" binding:"required"` // 付款方式 - AccountHolder string `json:"account_holder"` // 收款人:入库必传 - OpeningBank string `json:"opening_bank"` // 开户行:入库必传 - BankAccount string `json:"bank_account" ` // 银行卡号:入库必传 - DeliveryTime string `json:"delivery_time" ` // 交货日期:入库必传 + ErpCashierId uint32 `json:"erp_cashier_id"` // 付款方式 + AccountHolder string `json:"account_holder"` // 收款人 + OpeningBank string `json:"opening_bank"` // 开户行 + BankAccount string `json:"bank_account" ` // 银行卡号 + DeliveryTime string `json:"delivery_time" ` // 交货日期 Remark string `json:"remark"` // 备注 ErpPurchaseCommodities []ErpPurchaseCommodity `json:"erp_purchase_commodity" binding:"required"` // 采购商品信息 } @@ -142,15 +142,15 @@ type ErpPurchaseEditReq struct { PurchaseType string `json:"purchase_type" binding:"required"` // 采购类型:procure-采购 reject-退货 PurchaseOrderSn string `json:"purchase_order_sn"` // 采购退货订单号:出库必传 StoreId uint32 `json:"store_id"` // 门店id:入库必传 - DeliveryAddress string `json:"delivery_address"` // 交货地址:入库必传 + DeliveryAddress string `json:"delivery_address"` // 交货地址 HandlerId uint32 `json:"handler_id" binding:"required"` // 经手人id HandlerName string `json:"handler_name"` // 经手人名称 ErpSupplierId uint32 `json:"erp_supplier_id"` // 供应商id:入库必传 - ErpCashierId uint32 `json:"erp_cashier_id" binding:"required"` // 付款方式 - AccountHolder string `json:"account_holder"` // 收款人:入库必传 - OpeningBank string `json:"opening_bank"` // 开户行:入库必传 - BankAccount string `json:"bank_account" ` // 银行卡号:入库必传 - DeliveryTime string `json:"delivery_time"` // 交货日期:入库必传 + ErpCashierId uint32 `json:"erp_cashier_id"` // 付款方式 + AccountHolder string `json:"account_holder"` // 收款人 + OpeningBank string `json:"opening_bank"` // 开户行 + BankAccount string `json:"bank_account" ` // 银行卡号 + DeliveryTime string `json:"delivery_time"` // 交货日期 Remark string `json:"remark"` // 备注 ErpPurchaseCommodities []ErpPurchaseCommodity `json:"erp_purchase_commodity" binding:"required"` // 采购商品信息 } @@ -751,13 +751,27 @@ func (m *ErpPurchaseOrder) IdInit() error { m.ErpSupplierName = supplier.Name } - if m.ErpCashierId != 0 { - cashier, err := GetAccountDetail(int(m.ErpCashierId)) - if err != nil { - logger.Error("get cashier err:", logger.Field("err", err)) - return err + //cashier, err := GetAccountDetail(int(m.ErpCashierId)) + //if err != nil { + // logger.Error("get cashier err:", logger.Field("err", 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 } @@ -793,24 +807,24 @@ func CheckCreateErpPurchaseOrderParam(req *ErpPurchaseCreateReq) error { if req.StoreId == 0 { return errors.New("操作失败:门店id为空") } - if req.DeliveryAddress == "" { - return errors.New("操作失败:交货地址为空") - } + //if req.DeliveryAddress == "" { + // return errors.New("操作失败:交货地址为空") + //} if req.ErpSupplierId == 0 { return errors.New("操作失败:供应商id为空") } - if req.AccountHolder == "" { - return errors.New("操作失败:收款人为空") - } - if req.OpeningBank == "" { - return errors.New("操作失败:开户行为空") - } - if req.BankAccount == "" { - return errors.New("操作失败:银行卡号为空") - } - if req.DeliveryTime == "" { - return errors.New("操作失败:交货日期为空") - } + //if req.AccountHolder == "" { + // return errors.New("操作失败:收款人为空") + //} + //if req.OpeningBank == "" { + // return errors.New("操作失败:开户行为空") + //} + //if req.BankAccount == "" { + // return errors.New("操作失败:银行卡号为空") + //} + //if req.DeliveryTime == "" { + // return errors.New("操作失败:交货日期为空") + //} for _, item := range req.ErpPurchaseCommodities { if item.Count <= 0 { return errors.New("操作失败:采购数量需大于0") @@ -838,24 +852,24 @@ func CheckEditErpPurchaseOrderParam(req *ErpPurchaseEditReq) error { if req.StoreId == 0 { return errors.New("操作失败:门店id为空") } - if req.DeliveryAddress == "" { - return errors.New("操作失败:交货地址为空") - } + //if req.DeliveryAddress == "" { + // return errors.New("操作失败:交货地址为空") + //} if req.ErpSupplierId == 0 { return errors.New("操作失败:供应商id为空") } - if req.AccountHolder == "" { - return errors.New("操作失败:收款人为空") - } - if req.OpeningBank == "" { - return errors.New("操作失败:开户行为空") - } - if req.BankAccount == "" { - return errors.New("操作失败:银行卡号为空") - } - if req.DeliveryTime == "" { - return errors.New("操作失败:交货日期为空") - } + //if req.AccountHolder == "" { + // return errors.New("操作失败:收款人为空") + //} + //if req.OpeningBank == "" { + // return errors.New("操作失败:开户行为空") + //} + //if req.BankAccount == "" { + // return errors.New("操作失败:银行卡号为空") + //} + //if req.DeliveryTime == "" { + // return errors.New("操作失败:交货日期为空") + //} } else if req.PurchaseType == ErpRejectOrder { // 退货单 if req.PurchaseOrderSn == "" { return errors.New("操作失败:采购退货单据编号为空") @@ -2491,7 +2505,7 @@ func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq, c *gin.Context) (*Get 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 { case "desc": SortCommoditiesDesc(commodities) @@ -2524,7 +2538,7 @@ func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq, c *gin.Context) (*Get return commodities[i].ErpSupplierId < commodities[j].ErpSupplierId }) } - } else { + } else if req.SortField == "" { // 排序规则:主供应商id小 sort.Slice(commodities, func(i, j int) bool { return commodities[i].ErpSupplierId < commodities[j].ErpSupplierId @@ -2600,8 +2614,32 @@ func getErpPurchaseDemandHide(req *GetErpPurchaseDemandReq, c *gin.Context) (*Ge // 查询采购需求单信息,筛选出有采购需求的商品id var demand []ErpPurchaseDemand - err := orm.Eloquent.Table("erp_purchase_demand"). - Where("state = 1").Find(&demand).Error + demandQs := orm.Eloquent.Table("erp_purchase_demand"). + 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 { return nil, err } @@ -4469,6 +4507,7 @@ func getReportByCommodityFromCommon(req *ErpPurchaseReportByCommodityReq, c *gin if req.ErpCategoryID != 0 && v.ErpCategoryID != req.ErpCategoryID { continue } + reportData.ErpCategoryID = v.ErpCategoryID reportData.ErpCategoryName = v.ErpCategoryName reportData.ErpCommodityId = v.ErpCommodityId @@ -4519,21 +4558,21 @@ func getReportByCommodityFromCommon(req *ErpPurchaseReportByCommodityReq, c *gin }, } - if v.PurchaseType == ErpRejectOrder { // 退货单 - reportData.PlanCount = -reportData.PlanCount - reportData.PlanAmount = -reportData.PlanAmount - reportData.Amount = -reportData.Amount - reportData.Count = -reportData.Count - reportData.NonExecutionAmount = -reportData.NonExecutionAmount - reportData.NonExecutionCount = -reportData.NonExecutionCount - - purchaseOrderData.PlanCount = -purchaseOrderData.PlanCount - purchaseOrderData.PlanAmount = -purchaseOrderData.PlanAmount - purchaseOrderData.Amount = -purchaseOrderData.Amount - purchaseOrderData.Count = -purchaseOrderData.Count - purchaseOrderData.NonExecutionAmount = -purchaseOrderData.NonExecutionAmount - purchaseOrderData.NonExecutionCount = -purchaseOrderData.NonExecutionCount - } + //if v.PurchaseType == ErpRejectOrder { // 退货单 + // reportData.PlanCount = -reportData.PlanCount + // reportData.PlanAmount = -reportData.PlanAmount + // reportData.Amount = -reportData.Amount + // reportData.Count = -reportData.Count + // reportData.NonExecutionAmount = -reportData.NonExecutionAmount + // reportData.NonExecutionCount = -reportData.NonExecutionCount + // + // purchaseOrderData.PlanCount = -purchaseOrderData.PlanCount + // purchaseOrderData.PlanAmount = -purchaseOrderData.PlanAmount + // purchaseOrderData.Amount = -purchaseOrderData.Amount + // purchaseOrderData.Count = -purchaseOrderData.Count + // purchaseOrderData.NonExecutionAmount = -purchaseOrderData.NonExecutionAmount + // purchaseOrderData.NonExecutionCount = -purchaseOrderData.NonExecutionCount + //} if v.MakerTime != nil && v.MakerTime.IsZero() { 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 { return ErpCommodityPurchaseOrderData{}, CommodityData{}, err } @@ -4673,7 +4712,7 @@ func getPurchaseOrderAndCommodityData(orderID, commodityId uint32) (ErpCommodity } // getSignalPurchaseData 根据 ErpPurchaseCommodity 表查询采购数据 -func getSignalPurchaseData(erpPurchaseOrderId, commodityId uint32) (PurchaseData, CommodityData, error) { +func getSignalPurchaseData(erpPurchaseOrderId, commodityId uint32, purchaseType string) (PurchaseData, CommodityData, error) { var purchaseData PurchaseData var commodityData CommodityData @@ -4695,7 +4734,9 @@ func getSignalPurchaseData(erpPurchaseOrderId, commodityId uint32) (PurchaseData // pc.erp_purchase_order_id //`, erpPurchaseOrderId, commodityId).Scan(&purchaseData).Error - err := orm.Eloquent.Raw(` + var err error + if purchaseType == ErpProcureOrder { + err = orm.Eloquent.Raw(` SELECT plan.plan_count AS plan_count, plan.plan_price AS plan_price, @@ -4730,6 +4771,44 @@ JOIN pi.erp_purchase_order_id ) AS inventory ON 1 = 1 `, 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 { logger.Error("getPurchaseData err:", logger.Field("err", err)) return PurchaseData{}, CommodityData{}, err @@ -4739,6 +4818,15 @@ JOIN purchaseData.NonExecutionAmount = purchaseData.PlanAmount - purchaseData.Amount 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) if err != nil { diff --git a/app/admin/models/sysuser.go b/app/admin/models/sysuser.go index 6b6c94d..368c294 100644 --- a/app/admin/models/sysuser.go +++ b/app/admin/models/sysuser.go @@ -319,15 +319,31 @@ func (e *SysUser) GetPage(pageSize int, pageIndex int) ([]SysUserPage, int, erro return nil, 0, err } + var resp []SysUserPage // 反序列化 StoreData for i, v := range doc { if doc[i].StoreData != "" { doc[i].StoreList = deserializeStoreData(v.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 diff --git a/app/admin/models/user_vm.go b/app/admin/models/user_vm.go index 17ea661..a2fc1de 100644 --- a/app/admin/models/user_vm.go +++ b/app/admin/models/user_vm.go @@ -59,10 +59,10 @@ func UserVmUpdate(gdb *gorm.DB, orderId, uid uint32, amount int, event, describe // 变动前的积分 nBeforeVm := userVm.Vm - //flag := false + flag := false begin := gdb if gdb == nil { - //flag = true + flag = true begin = orm.Eloquent.Begin() } @@ -117,14 +117,14 @@ func UserVmUpdate(gdb *gorm.DB, orderId, uid uint32, amount int, event, describe return err } - //if flag { - // err = begin.Commit().Error - // if err != nil { - // begin.Rollback() - // logger.Error("err:", logger.Field("err", err)) - // return err - // } - //} + if flag { + err = begin.Commit().Error + if err != nil { + begin.Rollback() + logger.Error("err:", logger.Field("err", err)) + return err + } + } return nil }