新增操作记录日志
This commit is contained in:
parent
16615530de
commit
e1887b52e7
@ -24,9 +24,11 @@ func (r *Order) ReportPreOrder(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
adminUserId := c.GetInt64("UserId")
|
||||
|
||||
// 业务处理
|
||||
orderService := service.OrderService{}
|
||||
_, err = orderService.ReportPreProduct(orderProductId)
|
||||
_, err = orderService.ReportPreProduct(orderProductId, adminUserId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
|
||||
@ -111,9 +111,12 @@ func (r *OrderInquiry) CancelOrderInquiry(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 后台用户id
|
||||
adminUserId := c.GetInt64("UserId")
|
||||
|
||||
// 业务处理
|
||||
orderInquiryService := service.OrderInquiryService{}
|
||||
_, err = orderInquiryService.CancelOrderInquiry(req.CancelOrderInquiry, orderInquiryId)
|
||||
_, err = orderInquiryService.CancelOrderInquiry(req.CancelOrderInquiry, orderInquiryId, adminUserId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
|
||||
@ -112,9 +112,12 @@ func (r *OrderProduct) CancelOrderProduct(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 后台用户id
|
||||
adminUserId := c.GetInt64("UserId")
|
||||
|
||||
// 业务处理
|
||||
orderProductService := service.OrderProductService{}
|
||||
_, err = orderProductService.CancelOrderProduct(req.CancelOrderProduct, orderProductId)
|
||||
_, err = orderProductService.CancelOrderProduct(req.CancelOrderProduct, orderProductId, adminUserId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
|
||||
91
api/dao/orderOperationLog.go
Normal file
91
api/dao/orderOperationLog.go
Normal file
@ -0,0 +1,91 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
type OrderOperationLogDao struct {
|
||||
}
|
||||
|
||||
// GetOrderOperationLogById 获取订单操作日志数据-订单操作日志id
|
||||
func (r *OrderOperationLogDao) GetOrderOperationLogById(operationLogId int64) (m *model.OrderOperationLog, err error) {
|
||||
err = global.Db.First(&m, operationLogId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetOrderOperationLogPreloadById 获取订单操作日志数据-加载全部关联-订单操作日志id
|
||||
func (r *OrderOperationLogDao) GetOrderOperationLogPreloadById(operationLogId int64) (m *model.OrderOperationLog, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, operationLogId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetOrderOperationLogByOrderId 获取订单操作日志数据-药品订单id
|
||||
func (r *OrderOperationLogDao) GetOrderOperationLogByOrderId(orderId int64) (m []*model.OrderOperationLog, err error) {
|
||||
err = global.Db.Where("order_id = ?", orderId).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetOrderOperationLogByOrderNo 获取订单操作日志数据-药品订单编号
|
||||
func (r *OrderOperationLogDao) GetOrderOperationLogByOrderNo(orderNo int64) (m []*model.OrderOperationLog, err error) {
|
||||
err = global.Db.Where("order_no = ?", orderNo).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteOrderOperationLog 删除订单操作日志
|
||||
func (r *OrderOperationLogDao) DeleteOrderOperationLog(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.OrderOperationLog{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditOrderOperationLog 修改订单操作日志
|
||||
func (r *OrderOperationLogDao) EditOrderOperationLog(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.OrderOperationLog{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditOrderOperationLogById 修改订单操作日志-订单操作日志id
|
||||
func (r *OrderOperationLogDao) EditOrderOperationLogById(tx *gorm.DB, productRefundId int64, data interface{}) error {
|
||||
err := tx.Model(&model.OrderOperationLog{}).Where("order_product_id = ?", productRefundId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOrderOperationLogList 获取订单操作日志列表
|
||||
func (r *OrderOperationLogDao) GetOrderOperationLogList(maps interface{}) (m []*model.OrderOperationLog, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddOrderOperationLog 新增订单操作日志
|
||||
func (r *OrderOperationLogDao) AddOrderOperationLog(tx *gorm.DB, model *model.OrderOperationLog) (*model.OrderOperationLog, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
36
api/model/orderOperationLog.go
Normal file
36
api/model/orderOperationLog.go
Normal file
@ -0,0 +1,36 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// OrderOperationLog 订单操作日志表
|
||||
type OrderOperationLog struct {
|
||||
OperationLogId int64 `gorm:"column:operation_log_id;type:bigint(19);primary_key;comment:主键id" json:"operation_log_id"`
|
||||
OrderId int64 `gorm:"column:order_id;type:bigint(19);comment:订单id" json:"order_id"`
|
||||
OrderNo string `gorm:"column:order_no;type:varchar(255);comment:系统订单编号" json:"order_no"`
|
||||
OrderType int `gorm:"column:order_type;type:tinyint(1);comment:订单类型(1:问诊 2:药品 3:检测)" json:"order_type"`
|
||||
OperatorId int64 `gorm:"column:operator_id;type:bigint(19);comment:操作人id(后台用户)" json:"operator_id"`
|
||||
OperationContent string `gorm:"column:operation_content;type:varchar(255);comment:操作内容" json:"operation_content"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *OrderOperationLog) TableName() string {
|
||||
return "gdxz_order_operation_log"
|
||||
}
|
||||
|
||||
func (m *OrderOperationLog) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.OperationLogId == 0 {
|
||||
m.OperationLogId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -22,7 +22,7 @@ type OrderInquiryService struct {
|
||||
}
|
||||
|
||||
// CancelOrderInquiry 取消问诊订单
|
||||
func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry, orderInquiryId int64) (bool, error) {
|
||||
func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry, orderInquiryId, adminUserId int64) (bool, error) {
|
||||
// 获取订单数据
|
||||
orderInquiryDao := dao.OrderInquiryDao{}
|
||||
orderInquiry, err := orderInquiryDao.GetOrderInquiryById(orderInquiryId)
|
||||
@ -212,6 +212,22 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
orderOperationLog := &model.OrderOperationLog{
|
||||
OrderId: orderInquiry.OrderInquiryId,
|
||||
OrderNo: orderInquiry.InquiryNo,
|
||||
OrderType: 1,
|
||||
OperatorId: adminUserId,
|
||||
OperationContent: "取消订单并退款",
|
||||
}
|
||||
|
||||
orderOperationLogDao := dao.OrderOperationLogDao{}
|
||||
orderOperationLog, err = orderOperationLogDao.AddOrderOperationLog(tx, orderOperationLog)
|
||||
if err != nil || orderOperationLog == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
|
||||
return true, nil
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/extend/prescription"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
@ -15,7 +16,7 @@ type OrderService struct {
|
||||
}
|
||||
|
||||
// ReportPreProduct 商品订单上报处方平台
|
||||
func (r *OrderService) ReportPreProduct(orderProductId int64) (bool, error) {
|
||||
func (r *OrderService) ReportPreProduct(orderProductId, adminUserId int64) (bool, error) {
|
||||
// 获取药品订单详情
|
||||
orderProductDao := dao.OrderProductDao{}
|
||||
orderProduct, err := orderProductDao.GetOrderProductPreloadById(orderProductId)
|
||||
@ -278,6 +279,7 @@ func (r *OrderService) ReportPreProduct(orderProductId int64) (bool, error) {
|
||||
return false, errors.New("上报处方失败1")
|
||||
}
|
||||
|
||||
// 修改商品表
|
||||
orderProductData := make(map[string]interface{})
|
||||
orderProductData["report_pre_status"] = 1
|
||||
orderProductData["report_pre_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||||
@ -285,7 +287,23 @@ func (r *OrderService) ReportPreProduct(orderProductId int64) (bool, error) {
|
||||
err = orderProductDao.EditOrderProductById(tx, orderProductId, orderProductData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("上报处方失败2")
|
||||
return false, errors.New("上报处方失败")
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
orderOperationLog := &model.OrderOperationLog{
|
||||
OrderId: orderProduct.OrderProductId,
|
||||
OrderNo: orderProduct.OrderProductNo,
|
||||
OrderType: 2,
|
||||
OperatorId: adminUserId,
|
||||
OperationContent: "上报处方平台",
|
||||
}
|
||||
|
||||
orderOperationLogDao := dao.OrderOperationLogDao{}
|
||||
orderOperationLog, err = orderOperationLogDao.AddOrderOperationLog(tx, orderOperationLog)
|
||||
if err != nil || orderOperationLog == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
|
||||
@ -119,7 +119,7 @@ func (r *OrderProductService) GetOrderProduct(orderProductId int64) (getOrderPro
|
||||
}
|
||||
|
||||
// CancelOrderProduct 取消药品订单
|
||||
func (r *OrderProductService) CancelOrderProduct(req requests.CancelOrderProduct, orderProductId int64) (bool, error) {
|
||||
func (r *OrderProductService) CancelOrderProduct(req requests.CancelOrderProduct, orderProductId, adminUserId int64) (bool, error) {
|
||||
// 获取药品订单详情
|
||||
orderProductDao := dao.OrderProductDao{}
|
||||
orderProduct, err := orderProductDao.GetOrderProductPreloadById(orderProductId)
|
||||
@ -283,6 +283,22 @@ func (r *OrderProductService) CancelOrderProduct(req requests.CancelOrderProduct
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
orderOperationLog := &model.OrderOperationLog{
|
||||
OrderId: orderProduct.OrderProductId,
|
||||
OrderNo: orderProduct.OrderProductNo,
|
||||
OrderType: 2,
|
||||
OperatorId: adminUserId,
|
||||
OperationContent: "取消订单并退款",
|
||||
}
|
||||
|
||||
orderOperationLogDao := dao.OrderOperationLogDao{}
|
||||
orderOperationLog, err = orderOperationLogDao.AddOrderOperationLog(tx, orderOperationLog)
|
||||
if err != nil || orderOperationLog == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
|
||||
return true, nil
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user