|
@@ -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,
|
|
|
+ //}
|
|
|
}
|
|
|
|
|
|
}
|