Browse Source

冰排添加备注,订单流程改动

huangyan 1 month ago
parent
commit
df18ec1249

+ 56 - 8
app/admin/controller/waybill.go

@@ -73,7 +73,6 @@ func (e WaybillController) GetPage(c *gin.Context) {
 
 	//数据权限检查
 	p := actions.GetPermissionFromContext(c)
-
 	var userObj model.SysUser
 	err = userSvc.Get(&dto.SysUserGetReq{Id: p.UserId}, nil, &userObj)
 	if err != nil {
@@ -92,6 +91,17 @@ func (e WaybillController) GetPage(c *gin.Context) {
 		e.Error(500, err, err.Error())
 		return
 	}
+	for i, _ := range list {
+		var ReCheckuser model.SysUser
+		err = userSvc.GetUser(list[i].ReCheckId, &ReCheckuser)
+		if err != nil {
+			e.Error(500, err, err.Error())
+			return
+		}
+		list[i].ReCheck.Id = list[i].ReCheckId
+		list[i].ReCheck.NickName = ReCheckuser.Username
+		list[i].ReCheck.Phone = ReCheckuser.Phone
+	}
 	e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
 }
 
@@ -603,6 +613,41 @@ func (e WaybillController) Audit(c *gin.Context) {
 	e.OK(req.GetId(), "修改成功")
 }
 
+// AdminAudit 管理员审核订单
+// @Summary 管理员审核订单
+// @Description 审核订单
+// @Tags 运单
+// @Accept  application/json
+// @Product application/json
+// @Param data body dto.WaybillAdmin true "body"
+// @Success 200 {string} string	"{"code": 200, "message": "添加成功"}"
+// @Success 200 {string} string	"{"code": -1, "message": "添加失败"}"
+// @Router /api/waybill/audit [put]
+// @Security Bearer
+func (e WaybillController) AdminAudit(c *gin.Context) {
+	s := service.Waybill{}
+	req := dto.WaybillAdmin{}
+	err := e.MakeContext(c).
+		MakeOrm().
+		Bind(&req).
+		MakeService(&s.Service).
+		Errors
+	if err != nil {
+		e.Logger.Error(err)
+		e.Error(500, err, err.Error())
+		return
+	}
+	p := actions.GetPermissionFromContext(c)
+
+	req.SetUpdateBy(user.GetUserId(c))
+	err = s.AdminAudit(&req, p)
+	if err != nil {
+		e.Error(500, err, err.Error())
+		return
+	}
+	e.OK(req.GetId(), "修改成功")
+}
+
 // Delivery 派单
 // @Summary 派单
 // @Description 派单
@@ -630,16 +675,19 @@ func (e WaybillController) Delivery(c *gin.Context) {
 		return
 	}
 	p := actions.GetPermissionFromContext(c)
-
+	if len(req.WaybillIds) == 0 {
+		e.Error(500, err, "配送员不能为空")
+		return
+	}
 	oldIceRaftCode := make([]string, 0)
 	missingIceRaftCode := make([]string, 0)
-
-	err = IceRaftSvc.GetPageByCoolerBoxId(req.CoolerBoxId, &oldIceRaftCode, p)
-	if err != nil {
-		e.Error(500, err, err.Error())
-		return
+	if req.CoolerBoxId != 0 {
+		err = IceRaftSvc.GetPageByCoolerBoxId(req.CoolerBoxId, &oldIceRaftCode, p)
+		if err != nil {
+			e.Error(500, err, err.Error())
+			return
+		}
 	}
-
 	req.SetUpdateBy(user.GetUserId(c))
 	req.OldIceRaftCode = oldIceRaftCode
 	err = s.Delivery(&req, p)

+ 1 - 0
app/admin/model/ice_raft.go

@@ -15,6 +15,7 @@ type IceRaft struct {
 	IceRaftRecordId int               `json:"iceRaftRecordId" gorm:"size:128"`                      // 最新入库记录
 	FreezeClaim     float32           `json:"freezeClaim" gorm:"type:decimal(10,2);comment:冷冻要求"`   // 冷冻要求 单位小时
 	IceRaftRecord   IceRaftRecordOmit `json:"iceRaftRecord" gorm:"->;foreignkey:IceRaftRecordId;references:Id"`
+	Label           string            `json:"label" gorm:"size:128;comment:标签"` // 标签
 	model2.ControlBy
 	model2.ModelTime
 	model2.DeptBy

+ 3 - 2
app/admin/model/waybill.go

@@ -110,9 +110,10 @@ type Waybill struct {
 	IsCold                     int            `json:"isCold"   gorm:"size:128;default:1"`                   // 是否冷链 1 否 2 是
 	PaymentStatus              int            `json:"paymentStatus"  gorm:"size:128;default:1"`             //支付状态 1 结清 2 未结清  3 支付完成
 	PaymentType                int            `json:"paymentType"  gorm:"size:128;default:0"`               //支付方式  1现金 2线上支付 3银行卡 4医保 5其他
-	PaymentRemark              int            `json:"paymentremark"  gorm:"size:128;"`                      //支付备注
+	PaymentRemark              string         `json:"paymentremark"  gorm:"size:128;"`                      //支付备注
 	AssignmentStatus           int            `json:"assignmentStatus"  gorm:"size:128;default:1"`          //分配状态  1 未分配  2已分配
-	AuditRemark                string         `json:"audit_remark"  gorm:"size:255;"`                       //审核备注
+	AuditRemark                string         `json:"audit_remark"  gorm:"size:255;"`                       //驳回原因
+	AdminAuditRemark           string         `json:"admin_audit_remark"  gorm:"size:255;"`                 //管理员审核备注
 	model2.ControlBy
 	model2.ModelTime
 	model2.DeptBy

+ 2 - 0
app/admin/service/dto/ice_raft.go

@@ -42,6 +42,7 @@ type IceRaftInsertReq struct {
 	CodeList         []string `json:"codeList" vd:"len($)>0;msg:'冰排编号不能为空'"` // 冰排名称
 	Status           string   `json:"status"`                                // 1-停用 2-正常
 	FreezeClaim      float32  `json:"freezeClaim"`                           // 冷冻要求 单位小时
+	Label            string   `json:"label"`                                 // 标签
 	common.ControlBy `swaggerignore:"true"`
 	common.DeptBy    `swaggerignore:"true"`
 }
@@ -53,6 +54,7 @@ func (s *IceRaftInsertReq) Generate(model *model.IceRaft, code string) {
 	model.Code = code
 	model.Status = s.Status
 	model.FreezeClaim = s.FreezeClaim
+	model.Label = s.Label
 	if s.ControlBy.UpdateBy != 0 {
 		model.UpdateBy = s.UpdateBy
 	}

+ 25 - 3
app/admin/service/dto/waybill.go

@@ -128,10 +128,16 @@ type WaybillUpdateReqaudit struct {
 	InspectionReportIsAudit    int    `json:"inspectionReportIssue"  gorm:"size:128;default:1"`    // 检验报告是否审核 1 未审核 2已审核
 	DispensingMedicinesIsAudit int    `json:"dispensingMedicinesIssue"  gorm:"size:128;default:1"` //  调配药品信息是否审核  1 未审核 2已审核
 	IsCold                     int    `json:"isCold"  gorm:"size:128;default:1"`                   // 是否冷链 1 否 2 是
-	AuditRemark                string `json:"audit_remark"  gorm:"size:255;default:''"`            //审核备注
+	AuditRemark                string `json:"audit_remark"  gorm:"size:255;default:''"`            //驳回原因
 	model2.ControlBy           `swaggerignore:"true"`
 	model2.DeptBy              `swaggerignore:"true"`
 }
+type WaybillAdmin struct {
+	Id               int    `json:"id" comment:"编码" swaggerignore:"true"` // 编码
+	AdminAuditRemark string `json:"admin_audit_remark"`                   //管理员审核备注
+	model2.ControlBy `swaggerignore:"true"`
+	model2.DeptBy    `swaggerignore:"true"`
+}
 
 func (s *WaybillUpdateReq) Generate(m *model.Waybill) {
 	if s.Id != 0 {
@@ -159,12 +165,23 @@ func (s *WaybillUpdateReq) Generate(m *model.Waybill) {
 		m.CreateBy = s.CreateBy
 	}
 }
+func (s *WaybillAdmin) Generate(m *model.Waybill) {
+	if s.Id != 0 {
+		m.Id = s.Id
+	}
+	m.AdminAuditRemark = s.AdminAuditRemark
+	if s.ControlBy.UpdateBy != 0 {
+		m.UpdateBy = s.UpdateBy
+	}
+	if s.ControlBy.CreateBy != 0 {
+		m.CreateBy = s.CreateBy
+	}
+}
 func (s *WaybillUpdateReqaudit) Generate(m *model.Waybill) {
 	if s.Id != 0 {
 		m.Id = s.Id
 	}
 	m.OrderNo = s.OrderNo
-
 	m.PrescriptionIsAudit = s.PrescriptionIsAudit
 	m.InvoiceIsAudit = s.InvoiceIsAudit
 	m.InspectionReportIsAudit = s.InspectionReportIsAudit
@@ -179,6 +196,9 @@ func (s *WaybillUpdateReq) GetId() interface{} {
 func (s *WaybillUpdateReqaudit) GetId() interface{} {
 	return s.Id
 }
+func (s *WaybillAdmin) GetId() interface{} {
+	return s.Id
+}
 
 type WaybillUpdateStatusReq struct {
 	Id               int `json:"id" comment:"编码" swaggerignore:"true"` // 编码
@@ -222,8 +242,10 @@ func (s *UpdateStatusReq) GetId() interface{} {
 
 type WaybillDeliveryReq struct {
 	WaybillIds          []int    `json:"waybillIds"`                            // 运单id
+	DeliveryId          int      `json:"deliveryId"`                            // 配送人id
 	CoolerBoxId         int      `json:"coolerBoxId"`                           // 保温箱id
 	IceRaftCode         []string `json:"iceRaftCode"`                           // 冰排code
+	Status              int      `json:"status"`                                // 配送状态
 	OldIceRaftCode      []string `json:"oldIceRaftCode" swaggerignore:"true"`   // 旧的冰排code
 	TamperProofLabel    string   `json:"tamperProofLabel"  gorm:"size:128"`     // 防拆标签
 	TamperProofLabelImg string   `json:"tamperProofLabelImg"  gorm:"size:text"` // 防拆标签图片
@@ -267,7 +289,7 @@ type WaybillReceiptReq struct {
 	Receiptsign     string `json:"receiptsign"`     // 签收图片签字
 	PaymentStatus   int    `json:"paymentStatus"`   //支付状态 1 结清 2 未结清  3 支付完成
 	PaymentType     int    `json:"paymentType"`     //支付方式  1现金 2线上支付 3银行卡 4医保 5其他
-	PaymentRemark   int    `json:"paymentremark"`   //支付备注
+	PaymentRemark   string `json:"paymentremark"`   //支付备注
 	AssessStar      int    `json:"assessStar"`      // 评价星星
 	AssessContent   string `json:"assessContent"`   // 评价内容
 }

+ 23 - 1
app/admin/service/sys_user.go

@@ -101,7 +101,6 @@ func (e *SysUser) GetPageByDeptId(c *dto.SysUserGetPageByDeptIdReq, p *actions.D
 // Get 获取SysUser对象
 func (e *SysUser) Get(d *dto.SysUserGetReq, p *actions.DataPermission, userModel *model.SysUser) error {
 	var data model.SysUser
-
 	err := e.Orm.Model(&data).
 		Scopes(actions.UserPermission(data.TableName(), p)).
 		Preload("Dept").
@@ -116,6 +115,29 @@ func (e *SysUser) Get(d *dto.SysUserGetReq, p *actions.DataPermission, userModel
 
 	return nil
 }
+func IdScopesUser(id int) func(db *gorm.DB) *gorm.DB {
+	return func(db *gorm.DB) *gorm.DB {
+		if id == 0 {
+			return db
+		}
+		return db.Where("id = ? ", id)
+	}
+}
+func (e *SysUser) GetUser(id int, userModel *model.SysUser) error {
+	var data model.SysUser
+	var err error
+	err = e.Orm.Model(&data).
+		Scopes(IdScopesUser(id)).
+		First(userModel).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return global.GetNotFoundOrNoPermissionErr
+		}
+		return global.GetFailedErr
+	}
+	return nil
+}
 
 // Insert 创建SysUser对象
 func (e *SysUser) Insert(c *dto.SysUserInsertReq, p *actions.DataPermission) error {

+ 63 - 25
app/admin/service/waybill.go

@@ -28,6 +28,15 @@ type Waybill struct {
 	service.Service
 }
 
+func orStatus(id int) func(db *gorm.DB) *gorm.DB {
+	return func(db *gorm.DB) *gorm.DB {
+		if id == 0 {
+			return db
+		}
+		return db.Where("status = ? ", id).Or("status =? ", model.WaybillStatusoverrule)
+	}
+}
+
 // GetPage 获取Waybill列表
 //
 //	func (e *Waybill) GetPage(c *dto.WaybillGetPageReq, list *[]model.Waybill, count *int64, p *actions.DataPermission) error {
@@ -112,17 +121,12 @@ func (e *Waybill) GetPage(c *dto.WaybillGetPageReq, list *[]model.Waybill, count
 	db := e.Orm.Model(&data).
 		Scopes(
 			cDto.MakeCondition(c.GetNeedSearch()),
+			orStatus(c.Status),
 			actions.Permission(data.TableName(), p),
 		).
 		Preload("CoolerBox").
 		Preload("Delivery").
 		Preload("ReCheck")
-
-	// 如果Status为1,则同时查询status=1和status=7
-	if c.Status == model.WaybillStatusWaitDelivery {
-		db = db.Where("status IN (?)", []int{model.WaybillStatusWaitDelivery, model.WaybillStatusoverrule})
-	}
-
 	// 先计算总条目数
 	if err = db.Count(count).Error; err != nil {
 		e.Log.Errorf("db error: %s", err)
@@ -138,7 +142,6 @@ func (e *Waybill) GetPage(c *dto.WaybillGetPageReq, list *[]model.Waybill, count
 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
 		).Find(list).Error
 	}
-
 	if err != nil {
 		e.Log.Errorf("db error: %s", err)
 		return global.GetFailedErr
@@ -152,17 +155,11 @@ func (e *Waybill) GetUserPage(c *dto.WaybillGetPageReq, list *[]model.Waybill, c
 	// 构建基础查询
 	db := e.Orm.Model(&data).
 		Scopes(
+			orStatus(c.Status),
 			cDto.MakeCondition(c.GetNeedSearch()),
 		)
-
-	// 如果Status为1,则同时查询status=1和status=7
-	if c.Status == model.WaybillStatusWaitDelivery {
-		db = db.Where("status IN (?)", []int{model.WaybillStatusWaitDelivery, model.WaybillStatusoverrule})
-	}
-
 	// 添加用户相关的条件
-	db = db.Where("create_by = ?", p.UserId)
-
+	db = db.Where("delivery_id = ?", p.UserId)
 	// 先计算总条目数
 	if err = db.Count(count).Error; err != nil {
 		e.Log.Errorf("db error: %s", err)
@@ -440,6 +437,40 @@ func (e *Waybill) Audit(c *dto.WaybillUpdateReqaudit, p *actions.DataPermission)
 	}
 	c.Generate(&waybillModel)
 	waybillModel.Status = c.Status
+	waybillModel.ReCheckId = p.UserId
+	err = tx.Updates(&waybillModel).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		return global.UpdateFailedErr
+	}
+	c.Id = waybillModel.Id
+	return nil
+}
+
+// 管理员审核订单
+func (e *Waybill) AdminAudit(c *dto.WaybillAdmin, p *actions.DataPermission) error {
+	var err error
+	tx := e.Orm.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+	var waybillModel = model.Waybill{}
+	// 查询运单是否存在
+	err = e.Orm.Scopes(actions.Permission(waybillModel.TableName(), p)).
+		First(&waybillModel, c.GetId()).Error
+	if err != nil {
+		e.Log.Errorf("db error: %s", err)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return global.UpdateNotFoundOrNoPermissionErr
+		}
+		return global.UpdateFailedErr
+	}
+	c.Generate(&waybillModel)
+	waybillModel.AdminAuditRemark = c.AdminAuditRemark
 	err = tx.Updates(&waybillModel).Error
 	if err != nil {
 		e.Log.Errorf("db error: %s", err)
@@ -567,11 +598,13 @@ func (e *Waybill) Delivery(c *dto.WaybillDeliveryReq, p *actions.DataPermission)
 
 	var coolerBox = model.CoolerBox{}
 	// 查询保温箱信息
-	err = tx.Scopes(actions.Permission(coolerBox.TableName(), p)).
-		First(&coolerBox, c.CoolerBoxId).Error
-	if err != nil {
-		e.Log.Errorf("db error: %s", err)
-		return errors.New("获取保温箱信息失败")
+	if c.CoolerBoxId != 0 {
+		err = tx.Scopes(actions.Permission(coolerBox.TableName(), p)).
+			First(&coolerBox, c.CoolerBoxId).Error
+		if err != nil {
+			e.Log.Errorf("db error: %s", err)
+			return errors.New("获取保温箱信息失败")
+		}
 	}
 
 	for _, id := range c.WaybillIds {
@@ -595,9 +628,14 @@ func (e *Waybill) Delivery(c *dto.WaybillDeliveryReq, p *actions.DataPermission)
 			waybillModel.Status = model.WaybillStatusInDeliverys
 			waybillModel.TamperProofLabel = c.TamperProofLabel
 			waybillModel.TamperProofLabelImg = c.TamperProofLabelImg // 防拆标签
+			waybillModel.DeliveryId = c.DeliveryId
+			waybillModel.AssignmentStatus = 2 // 分配状态 2 已派单
 			waybillModel.CoolerBoxId = c.CoolerBoxId
 			waybillModel.DeliveryTime = model2.Time(time.Now())
 			waybillModel.IceRaftCode = c.IceRaftCode
+			if c.Status == model.WaybillStatusInShippeds {
+				waybillModel.Status = c.Status
+			}
 			err = tx.Save(&waybillModel).Error
 			if err != nil {
 				e.Log.Errorf("db error: %s", err)
@@ -682,7 +720,7 @@ func (e *Waybill) Delivery(c *dto.WaybillDeliveryReq, p *actions.DataPermission)
 
 		}
 
-		// 待配送时状态下才发送短信
+		// 待配送时状态下才发送短信 ------目前不需要发送短信
 		if waybillModeStatus == model.WaybillStatusInDeliverys {
 			ss := sms.NewSMS(conf.ExtConfig.SubMail.Appid, conf.ExtConfig.SubMail.Signature)
 			addr := conf.ExtConfig.Applet.WaybillUrl + url.QueryEscape(lib.AesEncryptCBC(waybillModel.WaybillNo, lib.AesKey))
@@ -692,10 +730,10 @@ func (e *Waybill) Delivery(c *dto.WaybillDeliveryReq, p *actions.DataPermission)
 				err = errors.New("派单短信发送失败,请检查收件人电话是否正确!")
 				return err
 			}
-			waybillModel.SendLog = model.WaybillSendLog{
-				Phone:   waybillModel.ConsigneeAddressPhone,
-				Content: "【冷链送药追溯平台】您的运单正在派送中,点击查看详情:" + addr,
-			}
+			//waybillModel.SendLog = model.WaybillSendLog{
+			//	Phone:   waybillModel.ConsigneeAddressPhone,
+			//	Content: "【冷链送药追溯平台】您的运单正在派送中,点击查看详情:" + addr,
+			//}
 		}
 
 	}