2.从系统导出的excel数据,在外部对excel某一列进行更改时,新增的要回传到原来的地方;并对改动的地方进行覆盖。
3.销售单管理、出库管理、发货单三个接口里面展示第三方订单编号和快递单号
4.选择多个仓库时,只要选择发货单子就会报错
5.在这个/api/split-account-deduction-log/create接口里,当传参时,如果参数 total_amount 是0,则会报错 {"code":204,"data":{},"msg":"TotalAmount不能为空"} 0是金额数字,不能当空值进行判断(T)
传递参数created_by,没有往数据表里写入
6.商品销毁的同时写入日志,也能通过读取这个日志,还原销毁的商品。传出这个新增的接口
7.新增一个不需要签名认证的分帐扣钱日志列表接口,新增一个返回字段buniness_no,并对这个字段进行模糊查询。
测试接口:/open/split-account-deduction-log/list
8.增加个新接口:首先 调用 /api/sales-order/create 创建销售订单的时候会锁定库存,
现在我需要一个解锁库存的接口,传递参数是订单编号
POST /api/sales-order/unlock-inventory // 解锁销售订单库存
/api/split-account-deduction-log/update /api/sales-order/unlock-inventory 在这两个接口里不需要签名认证
/api/sales-order/unlock-inventory 在这个接口里面返回解锁的所有商品信息
/api/split-account-deduction-log/update 在这个接口里面的status也需要更改,status没有变化
182 lines
5.5 KiB
Go
182 lines
5.5 KiB
Go
package service
|
||
|
||
import (
|
||
"encoding/json"
|
||
"psi/database"
|
||
"psi/models"
|
||
systemReq "psi/models/request"
|
||
systemRes "psi/models/response"
|
||
"psi/utils"
|
||
"time"
|
||
|
||
"gorm.io/datatypes"
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
type SplitAccountDeductionLogService struct{}
|
||
|
||
// GetSplitAccountDeductionLogList 获取分账扣钱日志列表
|
||
func (s *SplitAccountDeductionLogService) GetSplitAccountDeductionLogList(req systemReq.GetSplitAccountDeductionLogListRequest, db ...*gorm.DB) (*systemRes.SplitAccountDeductionLogListResponse, error) {
|
||
databaseConn := database.OptionalDB(db...)
|
||
|
||
if req.Page < 1 {
|
||
req.Page = 1
|
||
}
|
||
if req.PageSize < 1 || req.PageSize > 100 {
|
||
req.PageSize = 20
|
||
}
|
||
|
||
query := databaseConn.Model(&models.SplitAccountDeductionLog{})
|
||
|
||
if req.BusinessNo != "" {
|
||
query = query.Where("business_no like ?", "%"+req.BusinessNo+"%")
|
||
}
|
||
if req.ConfigID != "" {
|
||
query = query.Where("config_id = ?", req.ConfigID)
|
||
}
|
||
if req.StartCreatedAt != "" {
|
||
query = query.Where("created_at >= ?", req.StartCreatedAt)
|
||
}
|
||
if req.EndCreatedAt != "" {
|
||
query = query.Where("created_at <= ?", req.EndCreatedAt)
|
||
}
|
||
|
||
var total int64
|
||
if err := query.Count(&total).Error; err != nil {
|
||
return nil, utils.NewError("查询总数失败")
|
||
}
|
||
|
||
var logs []models.SplitAccountDeductionLog
|
||
offset := (req.Page - 1) * req.PageSize
|
||
if err := query.Order("created_at DESC").Offset(offset).Limit(req.PageSize).Find(&logs).Error; err != nil {
|
||
return nil, utils.NewError("查询分账扣钱日志列表失败")
|
||
}
|
||
|
||
var logItems []systemRes.SplitAccountDeductionLogItem
|
||
for _, log := range logs {
|
||
logItems = append(logItems, systemRes.ConvertSplitAccountDeductionLogToItem(log))
|
||
}
|
||
|
||
return &systemRes.SplitAccountDeductionLogListResponse{
|
||
List: logItems,
|
||
Total: total,
|
||
Page: req.Page,
|
||
PageSize: req.PageSize,
|
||
}, nil
|
||
}
|
||
|
||
// GetSplitAccountDeductionLogDetail 获取分账扣钱日志详情
|
||
func (s *SplitAccountDeductionLogService) GetSplitAccountDeductionLogDetail(id int64, db ...*gorm.DB) (*models.SplitAccountDeductionLog, error) {
|
||
databaseConn := database.OptionalDB(db...)
|
||
|
||
var log models.SplitAccountDeductionLog
|
||
|
||
result := databaseConn.Where("id = ?", id).First(&log)
|
||
if result.Error != nil {
|
||
return nil, utils.NewError("分账扣钱日志不存在")
|
||
}
|
||
|
||
return &log, nil
|
||
}
|
||
|
||
// CreateSplitAccountDeductionLog 创建分账扣钱日志
|
||
func (s *SplitAccountDeductionLogService) CreateSplitAccountDeductionLog(req systemReq.AddSplitAccountDeductionLogRequest, username string, db ...*gorm.DB) (int64, error) {
|
||
databaseConn := database.OptionalDB(db...)
|
||
|
||
var deductionDetails datatypes.JSON
|
||
if req.DeductionDetails != "" {
|
||
var temp interface{}
|
||
if err := json.Unmarshal([]byte(req.DeductionDetails), &temp); err != nil {
|
||
return 0, utils.NewError("扣款规则格式错误,不是合法的JSON")
|
||
}
|
||
deductionDetails, _ = json.Marshal(temp)
|
||
}
|
||
|
||
now := time.Now().Unix()
|
||
log := models.SplitAccountDeductionLog{
|
||
BusinessNo: req.BusinessNo,
|
||
ConfigID: req.ConfigID,
|
||
ConfigName: req.ConfigName,
|
||
DeductionDetails: deductionDetails,
|
||
TotalAmount: *req.TotalAmount,
|
||
DeductionAmount: *req.DeductionAmount,
|
||
RemainingAmount: *req.RemainingAmount,
|
||
CreatedBy: username,
|
||
CreatedAt: now,
|
||
UpdatedAt: now,
|
||
}
|
||
|
||
if err := databaseConn.Create(&log).Error; err != nil {
|
||
return 0, utils.NewError("创建分账扣钱日志失败: " + err.Error())
|
||
}
|
||
|
||
return log.ID, nil
|
||
}
|
||
|
||
// UpdateSplitAccountDeductionLog 更新分账扣钱日志
|
||
func (s *SplitAccountDeductionLogService) UpdateSplitAccountDeductionLog(req systemReq.UpdateSplitAccountDeductionLogRequest, username string, db ...*gorm.DB) error {
|
||
databaseConn := database.OptionalDB(db...)
|
||
|
||
var log models.SplitAccountDeductionLog
|
||
result := databaseConn.Where("id = ?", req.ID).First(&log)
|
||
if result.Error != nil {
|
||
return utils.NewError("分账扣钱日志不存在")
|
||
}
|
||
|
||
updateData := make(map[string]interface{})
|
||
updateData["updated_at"] = time.Now().Unix()
|
||
updateData["updated_by"] = username
|
||
|
||
if req.BusinessNo != "" {
|
||
updateData["business_no"] = req.BusinessNo
|
||
}
|
||
if req.ConfigID > 0 {
|
||
updateData["config_id"] = req.ConfigID
|
||
}
|
||
if req.ConfigName != "" {
|
||
updateData["config_name"] = req.ConfigName
|
||
}
|
||
if req.DeductionDetails != "" {
|
||
var temp interface{}
|
||
if err := json.Unmarshal([]byte(req.DeductionDetails), &temp); err != nil {
|
||
return utils.NewError("扣款规则格式错误,不是合法的JSON")
|
||
}
|
||
deductionDetails, _ := json.Marshal(temp)
|
||
updateData["deduction_details"] = datatypes.JSON(deductionDetails)
|
||
}
|
||
if req.TotalAmount > 0 {
|
||
updateData["total_amount"] = req.TotalAmount
|
||
}
|
||
if req.DeductionAmount > 0 {
|
||
updateData["deduction_amount"] = req.DeductionAmount
|
||
}
|
||
if req.RemainingAmount > 0 {
|
||
updateData["remaining_amount"] = req.RemainingAmount
|
||
}
|
||
|
||
updateData["status"] = req.Status
|
||
|
||
if err := databaseConn.Model(&log).Updates(updateData).Error; err != nil {
|
||
return utils.NewError("更新分账扣钱日志失败: " + err.Error())
|
||
}
|
||
|
||
return nil
|
||
}
|
||
|
||
// DeleteSplitAccountDeductionLog 删除分账扣钱日志
|
||
func (s *SplitAccountDeductionLogService) DeleteSplitAccountDeductionLog(req systemReq.DeleteSplitAccountDeductionLogRequest, username string, db ...*gorm.DB) error {
|
||
databaseConn := database.OptionalDB(db...)
|
||
|
||
var log models.SplitAccountDeductionLog
|
||
result := databaseConn.Where("id = ?", req.ID).First(&log)
|
||
if result.Error != nil {
|
||
return utils.NewError("分账扣钱日志不存在")
|
||
}
|
||
|
||
if err := databaseConn.Delete(&log).Error; err != nil {
|
||
return utils.NewError("删除分账扣钱日志失败: " + err.Error())
|
||
}
|
||
|
||
return nil
|
||
}
|