修复缺陷:

(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 !models.CheckUserStore(allotOrder.DeliverStoreId, sysUser) {
if !models.CheckUserStore(allotOrder.DeliverStoreId, sysUser) &&
!models.CheckUserStore(allotOrder.ReceiveStoreId, sysUser) {
app.Error(c, http.StatusInternalServerError, errors.New("操作失败:您没有该门店权限"),
"操作失败:您没有该门店权限")
return

View File

@ -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 {

View File

@ -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-出库前端只看14
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 {

View File

@ -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

View File

@ -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

View File

@ -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:"-"` // 封面
}

View File

@ -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)

View File

@ -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()

View File

@ -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 {

View File

@ -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

View File

@ -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
}