1、串码追踪接口优化,增加"采购换机"类型;

2、零售明细/销售明细中非串码商品按新增时添加数据进行展示,不单独拆分为每件商品一条数据;
3、零售明细中"采购单价"改成"采购价";
4、出库明细接口优化,返回门店名称和游戏名称;
5、采购换机列表接口返回数据添加采购换机商品信息。
This commit is contained in:
chenlin 2025-02-27 10:41:44 +08:00
parent 4a7b9a74a8
commit 2dbf95e50e
5 changed files with 174 additions and 19 deletions

View File

@ -3813,6 +3813,28 @@ func QueryImeiTraceData(req *ImeiTraceReq) (*ImeiTraceResp, error) {
}
results = append(results, retailRecords...)
// 6.查询采购换机订单
var purchaseChangeRecords []ImeiTraceData
err = orm.Eloquent.Table("erp_purchase_change_commodity").
Select(`erp_purchase_change_order.store_id AS store_id,
erp_purchase_change_order.store_name AS store_name,
'采购换机' AS serial_type,
erp_purchase_change_order.maker_time AS maker_time,
erp_purchase_change_order.serial_number AS serial_number,
erp_purchase_change_commodity.erp_commodity_id AS erp_commodity_id,
erp_purchase_change_commodity.erp_commodity_name AS erp_commodity_name,
erp_purchase_change_commodity.count AS count,
erp_purchase_change_commodity.remark AS remarks`).
Joins("LEFT JOIN erp_purchase_change_order ON erp_purchase_change_order.id = "+
"erp_purchase_change_commodity.change_order_id").
Where("erp_purchase_change_commodity.origin_imei = ? or erp_purchase_change_commodity.new_imei = ?",
req.IMEI, req.IMEI).
Find(&purchaseChangeRecords).Error
if err != nil {
return nil, err
}
results = append(results, purchaseChangeRecords...)
for i, _ := range results {
if results[i].CommoditySerialNumber == "" {
commodityInfo, _ := GetCommodity(results[i].ErpCommodityId)

View File

@ -1474,6 +1474,8 @@ func (m *ErpOrder) SetRetailDetailCommodity() {
}
var respOrderCommodities []ErpOrderCommodity
nonSerialMap := make(map[string]ErpOrderCommodity)
for _, item := range orderCommodities {
if m.RetailType == RetailTypeRejected { // 退货订单,金额需要转换为负值
item.Count = -item.Count
@ -1503,12 +1505,10 @@ func (m *ErpOrder) SetRetailDetailCommodity() {
}
for _, stockCommodityId := range idList {
var orderCommodity ErpOrderCommodity
orderCommodity = item
orderCommodity := item
orderCommodity.Count = 1
if m.RetailType == RetailTypeRejected { // 退货订单,数量需要转换为负值
orderCommodity.Count = -1
} else {
orderCommodity.Count = 1
}
nCount := math.Abs(float64(item.Count))
@ -1530,18 +1530,49 @@ func (m *ErpOrder) SetRetailDetailCommodity() {
orderCommodity.ErpSupplierId = stockCommodity.ErpSupplierId
orderCommodity.ErpSupplierName = stockCommodity.ErpSupplierName
orderCommodity.WholesalePrice = stockCommodity.WholesalePrice
orderCommodity.StaffCostPrice = stockCommodity.StaffCostPrice
orderCommodity.StaffPrice = orderCommodity.WholesalePrice + orderCommodity.StaffCostPrice
//orderCommodity.WholesalePrice = stockCommodity.WholesalePrice
//orderCommodity.StaffCostPrice = stockCommodity.StaffCostPrice
//orderCommodity.StaffPrice = orderCommodity.WholesalePrice + orderCommodity.StaffCostPrice
if m.RetailType == RetailTypeRejected { // 退货订单,数量需要转换为负值
orderCommodity.WholesalePrice = -orderCommodity.WholesalePrice
orderCommodity.StaffCostPrice = -orderCommodity.StaffCostPrice
orderCommodity.StaffPrice = -orderCommodity.StaffPrice
}
respOrderCommodities = append(respOrderCommodities, orderCommodity)
// 用商品ID和库存商品ID组合作为合并key
key := fmt.Sprintf("%d_%.2f", orderCommodity.ErpCommodityId, orderCommodity.SalePrice)
if existing, ok := nonSerialMap[key]; ok {
// 合并相同商品:累加数量、各金额/折扣
existing.Count += orderCommodity.Count
existing.SaleDiscount += orderCommodity.SaleDiscount
existing.MemberDiscount += orderCommodity.MemberDiscount
existing.VmDiscount += orderCommodity.VmDiscount
existing.Amount += orderCommodity.Amount
existing.ReceivedAmount += orderCommodity.ReceivedAmount
existing.RejectedCount += orderCommodity.RejectedCount
existing.RejectedAmount += orderCommodity.RejectedAmount
existing.SalesProfit += orderCommodity.SalesProfit
existing.StaffProfit += orderCommodity.StaffProfit
existing.StaffCostPrice += orderCommodity.StaffCostPrice
existing.WholesalePrice += orderCommodity.WholesalePrice
//existing.RetailPrice += orderCommodity.RetailPrice
//existing.SalePrice += orderCommodity.SalePrice
existing.StaffPrice = existing.WholesalePrice + existing.StaffCostPrice
nonSerialMap[key] = existing
} else {
nonSerialMap[key] = orderCommodity
}
}
}
}
// 将合并后的非串码商品追加到返回结果中
for _, commodity := range nonSerialMap {
commodity.WholesalePrice = tools.RoundToTwoDecimalPlaces(commodity.WholesalePrice)
commodity.StaffPrice = tools.RoundToTwoDecimalPlaces(commodity.WholesalePrice + commodity.StaffCostPrice)
respOrderCommodities = append(respOrderCommodities, commodity)
}
m.Commodities = respOrderCommodities
}
@ -1639,6 +1670,10 @@ func ErpOrderRetailDetailSetCommodityAI(list []ErpOrder) {
func (m *ErpOrder) SetRetailDetailCommodityAI(orderCommodities []ErpOrderCommodity, stockMap map[uint32]ErpStockCommodity) {
var respOrderCommodities []ErpOrderCommodity
// 对非串码商品做合并处理key格式为 "ErpCommodityId_stockCommodityId"
nonSerialMap := make(map[string]ErpOrderCommodity)
for _, item := range orderCommodities {
fmt.Println("orderId is:", item.ErpOrderId)
if m.RetailType == RetailTypeRejected { // 退货订单,金额需要转换为负值
@ -1695,18 +1730,50 @@ func (m *ErpOrder) SetRetailDetailCommodityAI(orderCommodities []ErpOrderCommodi
orderCommodity.ErpSupplierId = stockCommodity.ErpSupplierId
orderCommodity.ErpSupplierName = stockCommodity.ErpSupplierName
orderCommodity.WholesalePrice = stockCommodity.WholesalePrice
orderCommodity.StaffCostPrice = stockCommodity.StaffCostPrice
orderCommodity.StaffPrice = orderCommodity.WholesalePrice + orderCommodity.StaffCostPrice
// 备注:创建零售订单时的采购价应该已经计算,以那边为准
//orderCommodity.WholesalePrice = stockCommodity.WholesalePrice
//orderCommodity.StaffCostPrice = stockCommodity.StaffCostPrice
//orderCommodity.StaffPrice = orderCommodity.WholesalePrice + orderCommodity.StaffCostPrice
if m.RetailType == RetailTypeRejected { // 退货订单,数量需要转换为负值
orderCommodity.WholesalePrice = -orderCommodity.WholesalePrice
orderCommodity.StaffCostPrice = -orderCommodity.StaffCostPrice
orderCommodity.StaffPrice = -orderCommodity.StaffPrice
}
respOrderCommodities = append(respOrderCommodities, orderCommodity)
// 用商品ID和库存商品ID组合作为合并key
key := fmt.Sprintf("%d_%.2f", orderCommodity.ErpCommodityId, orderCommodity.SalePrice)
if existing, ok := nonSerialMap[key]; ok {
// 合并相同商品:累加数量、各金额/折扣
existing.Count += orderCommodity.Count
existing.SaleDiscount += orderCommodity.SaleDiscount
existing.MemberDiscount += orderCommodity.MemberDiscount
existing.VmDiscount += orderCommodity.VmDiscount
existing.Amount += orderCommodity.Amount
existing.ReceivedAmount += orderCommodity.ReceivedAmount
existing.RejectedCount += orderCommodity.RejectedCount
existing.RejectedAmount += orderCommodity.RejectedAmount
existing.SalesProfit += orderCommodity.SalesProfit
existing.StaffProfit += orderCommodity.StaffProfit
existing.StaffCostPrice += orderCommodity.StaffCostPrice
existing.WholesalePrice += orderCommodity.WholesalePrice
//existing.RetailPrice += orderCommodity.RetailPrice
//existing.SalePrice += orderCommodity.SalePrice
existing.StaffPrice = existing.WholesalePrice + existing.StaffCostPrice
nonSerialMap[key] = existing
} else {
nonSerialMap[key] = orderCommodity
}
}
}
}
// 将合并后的非串码商品追加到返回结果中
for _, commodity := range nonSerialMap {
commodity.WholesalePrice = tools.RoundToTwoDecimalPlaces(commodity.WholesalePrice)
commodity.StaffPrice = tools.RoundToTwoDecimalPlaces(commodity.WholesalePrice + commodity.StaffCostPrice)
respOrderCommodities = append(respOrderCommodities, commodity)
}
m.Commodities = respOrderCommodities
}
@ -3844,7 +3911,7 @@ func retailDetailExport(list []ErpOrder, sumData RetailDetailTotalData, c *gin.C
"供应商", "是否串码", "商品串码", "是否赠送", "销售数量", "指导零售价", "零售价", "零售优惠", "会员优惠", "实际零售价/退货价"}
if flag1 { // 采购单价
title = append(title, "采购价")
title = append(title, "采购价")
nEndCount += 1
}
if flag2 { // 员工成本价
@ -5054,16 +5121,62 @@ func packData(result []RetailDetailByJoin) []ErpOrder {
commodity.StaffProfit = item.StaffProfit
commodity.StaffPrice = item.WholesalePrice + item.StaffCostPrice
// 若商品为非串码IMEIType==1则尝试合并同一订单中相同 ErpCommodityId 的记录
if commodity.IMEIType == 1 {
merged := false
for idx, exist := range order.Commodities {
// 合并条件:同为非串码且 ErpCommodityId 相同
if exist.IMEIType == 1 && exist.ErpCommodityId == commodity.ErpCommodityId &&
exist.SalePrice == commodity.SalePrice {
order.Commodities[idx].Count += commodity.Count
order.Commodities[idx].SaleDiscount += commodity.SaleDiscount
order.Commodities[idx].MemberDiscount += commodity.MemberDiscount
order.Commodities[idx].VmDiscount += commodity.VmDiscount
order.Commodities[idx].Amount += commodity.Amount
order.Commodities[idx].ReceivedAmount += commodity.ReceivedAmount
order.Commodities[idx].RejectedCount += commodity.RejectedCount
order.Commodities[idx].RejectedAmount += commodity.RejectedAmount
order.Commodities[idx].SalesProfit += commodity.SalesProfit
order.Commodities[idx].StaffProfit += commodity.StaffProfit
order.Commodities[idx].StaffCostPrice += commodity.StaffCostPrice
order.Commodities[idx].WholesalePrice += commodity.WholesalePrice
//order.Commodities[idx].RetailPrice += commodity.RetailPrice
//order.Commodities[idx].SalePrice += commodity.SalePrice
// 重新计算员工价格
order.Commodities[idx].StaffPrice = order.Commodities[idx].WholesalePrice + order.Commodities[idx].StaffCostPrice
merged = true
break
}
}
if !merged {
order.Commodities = append(order.Commodities, commodity)
}
} else {
// 串码商品不合并,直接追加
order.Commodities = append(order.Commodities, commodity)
}
orderIdMap[item.ErpOrderId] = order
}
for _, item := range orderIdMap {
orders = append(orders, item)
for _, order := range orderIdMap {
for i := range order.Commodities {
if order.Commodities[i].IMEIType == 1 {
order.Commodities[i].WholesalePrice = tools.RoundToTwoDecimalPlaces(order.Commodities[i].WholesalePrice)
order.Commodities[i].StaffPrice = tools.RoundToTwoDecimalPlaces(order.Commodities[i].WholesalePrice + order.Commodities[i].StaffCostPrice)
}
}
orders = append(orders, order)
}
// 根据AuditTime进行降序排序
sort.SliceStable(orders, func(i, j int) bool {
// 若其中一个 AuditTime 为空,则按其他字段排序或认为空时间最小
if orders[i].AuditTime == nil {
return false
}
if orders[j].AuditTime == nil {
return true
}
return orders[i].AuditTime.After(*orders[j].AuditTime)
})

View File

@ -3481,9 +3481,9 @@ type GameCardOutRecord struct {
Model
SerialNumber string `json:"serial_number" gorm:"index"` // 游戏卡串码
StoreId uint64 `json:"store_id"` // 门店id
StoreName string `json:"store_name" gorm:"-"` // 门店名称
StoreName string `json:"store_name"` // 门店名称
GameCardId uint64 `json:"game_card_id"` // 游戏卡id
GameCardName string `json:"game_card_name" gorm:"-"` // 游戏名称
GameCardName string `json:"game_card_name"` // 游戏名称
FirstStockTime *time.Time `json:"first_stock_time"` // 首次入库时间
StockTime *time.Time `json:"stock_time"` // 入库时间
OutStockTime *time.Time `json:"out_stock_time"` // 出库时间

View File

@ -504,7 +504,10 @@ func (m *ErpPurchaseChangeOrderListReq) List(c *gin.Context) (*ErpPurchaseChange
}
}
changeOrderListSetCommodity(orders)
resp.List = orders
return resp, nil
}
@ -602,3 +605,20 @@ func AuditChangeOrder(begin *gorm.DB, req ErpPurchaseChangeOrder, state int) err
return nil
}
// 添加采购换机订单的商品信息
func changeOrderListSetCommodity(list []ErpPurchaseChangeOrder) {
for i, _ := range list {
list[i].SetCommodity()
}
}
func (m *ErpPurchaseChangeOrder) SetCommodity() {
var orderCommodities []ErpPurchaseChangeCommodity
err := orm.Eloquent.Table("erp_purchase_change_commodity").Where("change_order_id = ?", m.ID).Find(&orderCommodities).Error
if err != nil {
logger.Error("SetCommodity query erp_purchase_change_commodity err:", logger.Field("err", err))
}
m.Commodities = orderCommodities
}

View File

@ -31,7 +31,7 @@ func registerErpPurchaseManageRouter(v1 *gin.RouterGroup, authMiddleware *jwt.Gi
r.POST("change/create", purchasemanage.ErpPurchaseChangeCreate) // 采购换机-新增
r.POST("change/edit", purchasemanage.ErpPurchaseChangeEdit) // 采购换机-编辑
r.POST("change/list", purchasemanage.ErpPurchaseChangeList) // 采购换机列表
r.POST("change/list", purchasemanage.ErpPurchaseChangeList) // 采购换机-列表
r.POST("change/delete", purchasemanage.ErpPurchaseChangeDelete) // 采购换机-删除
r.POST("change/audit", purchasemanage.ErpPurchaseChangeAudit) // 采购换机-审核
}