1.零售订单批量导入时去处"商品名称和商品编号不能同时为空"的限制;

2.添加租赁卡带批量出库定时任务,使用完已注释;
This commit is contained in:
chenlin 2025-04-28 18:40:24 +08:00
parent 960a45c851
commit 190379942e
6 changed files with 88 additions and 15 deletions

View File

@ -296,7 +296,7 @@ func CategoryImport(c *gin.Context) {
}
fmt.Println("header:", header.Filename)
_, colsMap, err := models.FileExcelImport([]byte(readAll), nil, 1, 0)
_, colsMap, err := models.FileExcelImport(c, []byte(readAll), nil, 1, 0)
if err != nil {
//logger.Error("file excel reader err:", err)
app.Error(c, http.StatusInternalServerError, err, err.Error())

View File

@ -465,7 +465,7 @@ func CommodityImport(c *gin.Context) {
}
fmt.Println("header:", header.Filename)
_, colsMap, err := models.FileExcelImport([]byte(readAll), nil, 2, 0)
_, colsMap, err := models.FileExcelImport(c, []byte(readAll), nil, 2, 0)
if err != nil {
//logger.Error("file excel reader err:", err)
app.Error(c, http.StatusInternalServerError, err, err.Error())

View File

@ -696,7 +696,7 @@ func ErpOrderBatchImport(c *gin.Context) {
}
fmt.Println("header:", header.Filename)
_, colsMap, err := model.FileExcelImport(readAll, nil, 4, int(req.StoreId))
_, colsMap, err := model.FileExcelImport(c, readAll, nil, 4, int(req.StoreId))
if err != nil {
logger.Errorf("file excel reader err:", err)
app.Error(c, http.StatusInternalServerError, err, err.Error())
@ -709,7 +709,7 @@ func ErpOrderBatchImport(c *gin.Context) {
}
var orderCommodities []model.ErpOrderCommodity
orderCommodities, err = model.ImportOrderData(colsMap)
orderCommodities, err = model.ImportOrderData(c, colsMap)
if err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return

View File

@ -235,7 +235,7 @@ func BatchImport(c *gin.Context) {
}
fmt.Println("header:", header.Filename)
_, colsMap, err := models.FileExcelImport(readAll, nil, 3, 0)
_, colsMap, err := models.FileExcelImport(c, readAll, nil, 3, 0)
if err != nil {
//logger.Error("file excel reader err:", err)
app.Error(c, http.StatusInternalServerError, err, err.Error())

View File

@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"github.com/xuri/excelize/v2"
"go-admin/app/admin/models/tools"
orm "go-admin/common/global"
@ -161,7 +162,7 @@ func FileExcelReader(d []byte, cols []string) ([]byte, []map[string]interface{},
}
// FileExcelImport 导入excel数据校验必填项
func FileExcelImport(d []byte, cols []string, nType, storeId int) ([]byte, []map[string]interface{}, error) {
func FileExcelImport(c *gin.Context, d []byte, cols []string, nType, storeId int) ([]byte, []map[string]interface{}, error) {
reader, err := excelize.OpenReader(bytes.NewReader(d))
if err != nil {
return nil, nil, fmt.Errorf("open reader error: %v", err)
@ -224,7 +225,7 @@ func FileExcelImport(d []byte, cols []string, nType, storeId int) ([]byte, []map
if sheetList[0] != "导零售" {
return nil, nil, errors.New("格式错误不是零售模版excel")
}
if err := checkOrderExcel(sheetCols, storeId); err != nil {
if err := checkOrderExcel(c, sheetCols, storeId); err != nil {
return nil, nil, err
}
cols = getJSONTagNames(OrderExcel{})
@ -1533,7 +1534,7 @@ func IsExistingCommodity(commodityId uint32) bool {
// return nil
//}
func checkOrderExcel(sheetCols [][]string, storeId int) error {
func checkOrderExcel(c *gin.Context, sheetCols [][]string, storeId int) error {
// 校验列数是否正确
if len(sheetCols) != 8 {
return errors.New("模版错误,请检查文件")
@ -1608,7 +1609,7 @@ func checkOrderExcel(sheetCols [][]string, storeId int) error {
return err
}
validateStock(sheetCols)
validateStock(c, sheetCols)
return nil
}
@ -1647,7 +1648,7 @@ func validateRow(sheetCols [][]string, row int, productCodeCache, productNameCac
fmt.Println("row is:", row)
// 校验商品名称和商品编号
if sheetCols[0][row] == "" && sheetCols[1][row] == "" {
return errors.New("商品名称和商品编号不能同时为空")
//return errors.New("商品名称和商品编号不能同时为空")
}
// 校验商品编号是否存在
@ -1689,7 +1690,7 @@ func validateRow(sheetCols [][]string, row int, productCodeCache, productNameCac
}
// validateStock 校验库存信息
func validateStock(sheetCols [][]string) error {
func validateStock(c *gin.Context, sheetCols [][]string) error {
// 预加载所有库存数据,按门店 store_id 过滤
var imeiStockCommodities []ErpStockCommodity
err := orm.Eloquent.Table("erp_stock_commodity").
@ -1730,7 +1731,11 @@ func validateStock(sheetCols [][]string) error {
if sheetCols[5][row] != "" {
price, err := strconv.ParseFloat(sheetCols[5][row], 64)
if err != nil || price < stock.MinRetailPrice {
return fmt.Errorf("第 %d 行: 零售价有误,不能低于最低零售价[%.2f]", row+1, stock.MinRetailPrice)
if !HasPermission(c) {
logger.Error("SalePrice less than MinRetailPrice")
return fmt.Errorf("第 %d 行: 零售价有误,不能低于最低零售价[%.2f]", row+1, stock.MinRetailPrice)
}
}
}
} else { // 非串码商品
@ -1806,7 +1811,7 @@ func transOrderData(colsMap []map[string]interface{}) ([]OrderExcel, error) {
return stockInfos, nil
}
func ImportOrderData(colsMap []map[string]interface{}) ([]ErpOrderCommodity, error) {
func ImportOrderData(c *gin.Context, colsMap []map[string]interface{}) ([]ErpOrderCommodity, error) {
list, err := transOrderData(colsMap)
if err != nil {
return nil, err
@ -1855,7 +1860,9 @@ func ImportOrderData(colsMap []map[string]interface{}) ([]ErpOrderCommodity, err
}
strMin := strconv.FormatFloat(imeiStockCommodity.MinRetailPrice, 'f', 2, 64)
if floatVal < imeiStockCommodity.MinRetailPrice {
return nil, errors.New("第" + strconv.Itoa(i+1) + "行零售价有误,不能低于最低零售价[" + strMin + "]")
if !HasPermission(c) {
return nil, errors.New("第" + strconv.Itoa(i+1) + "行零售价有误,不能低于最低零售价[" + strMin + "]")
}
}
} else {
floatVal = imeiStockCommodity.RetailPrice
@ -1933,7 +1940,9 @@ func ImportOrderData(colsMap []map[string]interface{}) ([]ErpOrderCommodity, err
}
strMin := strconv.FormatFloat(imeiStockCommodities[0].MinRetailPrice, 'f', 2, 64)
if floatVal < imeiStockCommodities[0].MinRetailPrice {
return nil, errors.New("第" + strconv.Itoa(i+1) + "行零售价有误,不能低于最低零售价[" + strMin + "]")
if !HasPermission(c) {
return nil, errors.New("第" + strconv.Itoa(i+1) + "行零售价有误,不能低于最低零售价[" + strMin + "]")
}
}
} else {
floatVal = imeiStockCommodities[0].RetailPrice

View File

@ -3714,3 +3714,67 @@ func exportStockOutDetailExcel(resp *GameCardGoodsStockOutInfoListResp) (string,
return url + fileName, nil
}
// BatchRevertCard 批量归还卡带
func BatchRevertCard() {
//type CardUserInfo struct {
// CreatedAt time.Time
// UpdatedAt time.Time
// OrderID uint64
// Uid uint64
// Tel string
// MemberLevel uint8
// Deposit uint32
// MemberExpire time.Time
// GameCardId uint64
// SerialNumber string
// StoreId uint64
//}
//
//var list []CardUserInfo
//
//// 查询符合条件的记录
//err := orm.Eloquent.Table("order_card AS oc").
// Select("oc.created_at, oc.updated_at, oc.order_id, oc.uid, u.tel, u.member_level, u.deposit, u.member_expire, oc.game_card_id, oc.serial_number, oc.store_id").
// Joins("JOIN user AS u ON oc.uid = u.uid").
// Where("oc.card_status IN (2, 3)").
// Where("u.member_level NOT IN (2, 3, 4, 5)").
// Where("u.member_expire < ?", "2024-04-01 00:00:00").
// Find(&list).Error
//if err != nil {
// fmt.Printf("BatchRevertCard query error: %v", err)
// return
//}
//
//if len(list) == 0 {
// fmt.Println("BatchRevertCard: no records to process")
// return
//}
//
//for _, info := range list {
// order := &Order{
// Model: Model{ID: uint32(info.OrderID)},
// GameCardSerialNumber: info.SerialNumber,
// RevertStoreId: 25,
// RevertShopperCode: "833998",
// PhoneExt: getPhoneExt(info.Tel),
// }
//
// err = order.Revert()
// if err != nil {
// errStr := fmt.Sprintf("BatchRevertCard revert error, orderID: %d, serialNumber: %s", info.OrderID, info.SerialNumber)
// logger.Error("*****err*****", logger.Field("err", errStr))
// // 如果需要可以继续处理其他订单,不 return
// continue
// }
// fmt.Printf("BatchRevertCard success, orderID: %d, serialNumber: %s", info.OrderID, info.SerialNumber)
//}
}
// 截取手机号后四位
func getPhoneExt(phone string) string {
if len(phone) >= 4 {
return phone[len(phone)-4:]
}
return ""
}