| 
					
				 | 
			
			
				@@ -29,38 +29,116 @@ type Waybill struct { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 // GetPage 获取Waybill列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//	func (e *Waybill) GetPage(c *dto.WaybillGetPageReq, list *[]model.Waybill, count *int64, p *actions.DataPermission) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		var err error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		var data model.Waybill 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		if c.PageSize == 9999 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			err = e.Orm.Model(&data). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				Scopes( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//					cDto.MakeCondition(c.GetNeedSearch()), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//					actions.Permission(data.TableName(), p), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				Preload("CoolerBox"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				Preload("Delivery"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				Preload("ReCheck"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				Find(list).Limit(-1).Offset(-1). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				Count(count).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				e.Log.Errorf("db error: %s", err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				return global.GetFailedErr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		err = e.Orm.Model(&data). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			Scopes( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				cDto.MakeCondition(c.GetNeedSearch()), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				cDto.Paginate(c.GetPageSize(), c.GetPageIndex()), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				actions.Permission(data.TableName(), p), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			Preload("CoolerBox"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			Preload("Delivery"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			Preload("ReCheck"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			Find(list).Limit(-1).Offset(-1). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			Count(count).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			e.Log.Errorf("db error: %s", err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			return global.GetFailedErr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//	func (e *Waybill) GetUserPage(c *dto.WaybillGetPageReq, list *[]model.Waybill, count *int64, p *actions.DataPermission) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		var err error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		var data model.Waybill 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		if c.PageSize == 9999 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			err = e.Orm.Model(&data). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				Scopes( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//					cDto.MakeCondition(c.GetNeedSearch()), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				Where("create_by = ?", p.UserId). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				Find(list).Limit(-1).Offset(-1). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				Count(count).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				e.Log.Errorf("db error: %s", err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				return global.GetFailedErr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		err = e.Orm.Model(&data). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			Scopes( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				cDto.MakeCondition(c.GetNeedSearch()), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//				cDto.Paginate(c.GetPageSize(), c.GetPageIndex()), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			Where("delivery_id = ? or re_check_id = ? or create_by = ?", p.UserId, p.UserId, p.UserId). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			Preload("CoolerBox"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			Preload("Delivery"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			Preload("ReCheck"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			Find(list).Limit(-1).Offset(-1). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			Count(count).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			e.Log.Errorf("db error: %s", err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//			return global.GetFailedErr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//		return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 func (e *Waybill) GetPage(c *dto.WaybillGetPageReq, list *[]model.Waybill, count *int64, p *actions.DataPermission) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	var err error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	var data model.Waybill 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if c.PageSize == 9999 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		err = e.Orm.Model(&data). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			Scopes( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				cDto.MakeCondition(c.GetNeedSearch()), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				actions.Permission(data.TableName(), p), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			Preload("CoolerBox"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			Preload("Delivery"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			Preload("ReCheck"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			Find(list).Limit(-1).Offset(-1). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			Count(count).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			e.Log.Errorf("db error: %s", err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			return global.GetFailedErr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	err = e.Orm.Model(&data). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// 构建基础查询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	db := e.Orm.Model(&data). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		Scopes( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			cDto.MakeCondition(c.GetNeedSearch()), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			actions.Permission(data.TableName(), p), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		Preload("CoolerBox"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		Preload("Delivery"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		Preload("ReCheck"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		Find(list).Limit(-1).Offset(-1). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		Count(count).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		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) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return global.GetFailedErr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// 如果PageSize设置为9999,则不分页 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if c.PageSize == 9999 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		err = db.Find(list).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		// 应用分页 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		err = db.Scopes( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		).Find(list).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		e.Log.Errorf("db error: %s", err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return global.GetFailedErr 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -70,32 +148,41 @@ func (e *Waybill) GetPage(c *dto.WaybillGetPageReq, list *[]model.Waybill, count 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 func (e *Waybill) GetUserPage(c *dto.WaybillGetPageReq, list *[]model.Waybill, count *int64, p *actions.DataPermission) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	var err error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	var data model.Waybill 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if c.PageSize == 9999 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		err = e.Orm.Model(&data). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			Scopes( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				cDto.MakeCondition(c.GetNeedSearch()), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			Where("create_by = ?", p.UserId). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			Find(list).Limit(-1).Offset(-1). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			Count(count).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			e.Log.Errorf("db error: %s", err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			return global.GetFailedErr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	err = e.Orm.Model(&data). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// 构建基础查询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	db := e.Orm.Model(&data). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		Scopes( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			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) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// 先计算总条目数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err = db.Count(count).Error; err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		e.Log.Errorf("db error: %s", err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return global.GetFailedErr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// 如果PageSize设置为9999,则不分页 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if c.PageSize == 9999 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		err = db.Find(list).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		// 应用分页 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		err = db.Scopes( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			cDto.Paginate(c.GetPageSize(), c.GetPageIndex()), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		Where("delivery_id = ? or re_check_id = ? or create_by = ?", p.UserId, p.UserId, p.UserId). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		Preload("CoolerBox"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		Preload("Delivery"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		Preload("ReCheck"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		Find(list).Limit(-1).Offset(-1). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		Count(count).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Preload("CoolerBox"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Preload("Delivery"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Preload("ReCheck"). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			Find(list).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		e.Log.Errorf("db error: %s", err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return global.GetFailedErr 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -328,9 +415,10 @@ func (e *Waybill) Update(c *dto.WaybillUpdateReq, p *actions.DataPermission) err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	c.Id = waybillModel.Id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-func (e *Waybill) UpdateStatus(c *dto.WaybillUpdateStatusReq, p *actions.DataPermission) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	var err error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 审核订单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+func (e *Waybill) Audit(c *dto.WaybillUpdateReqaudit, p *actions.DataPermission) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	var err error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	tx := e.Orm.Begin() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	defer func() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		if err != nil { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -339,7 +427,6 @@ func (e *Waybill) UpdateStatus(c *dto.WaybillUpdateStatusReq, p *actions.DataPer 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			tx.Commit() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	}() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	var waybillModel = model.Waybill{} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 查询运单是否存在 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	err = e.Orm.Scopes(actions.Permission(waybillModel.TableName(), p)). 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -351,17 +438,57 @@ func (e *Waybill) UpdateStatus(c *dto.WaybillUpdateStatusReq, p *actions.DataPer 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return global.UpdateFailedErr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	c.Generate(&waybillModel) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	err = tx.Save(&waybillModel).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	waybillModel.Status = c.Status 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	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) UpdateStatus(c *dto.UpdateStatusReq, p *actions.DataPermission) error { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	var err error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	tx := e.Orm.Begin() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	defer func() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			tx.Rollback() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			tx.Commit() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	}() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// 查询运单是否存在 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	for _, v := range c.Id { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		var waybillModel = model.Waybill{} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		err = e.Orm.Scopes(actions.Permission(waybillModel.TableName(), p)). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			First(&waybillModel, v).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			e.Log.Errorf("db error: %s", err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			if errors.Is(err, gorm.ErrRecordNotFound) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				return global.UpdateNotFoundOrNoPermissionErr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return global.UpdateFailedErr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		waybillModel.Status = c.Status 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		err = tx.Table(waybillModel.TableName()).Where("id=?", v).Update("status", c.Status).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			e.Log.Errorf("db error: %s", err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			return global.UpdateFailedErr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	//err = tx.Save(&waybillModel).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	//if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	//	e.Log.Errorf("db error: %s", err) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	//	return global.UpdateFailedErr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	//} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	//c.Id = waybillModel.Id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 // 派单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 func (e *Waybill) Delivery(c *dto.WaybillDeliveryReq, p *actions.DataPermission) error { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -460,11 +587,14 @@ func (e *Waybill) Delivery(c *dto.WaybillDeliveryReq, p *actions.DataPermission) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			return global.UpdateFailedErr 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//派单时添加 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		waybillModeStatus := waybillModel.Status 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		if waybillModel.Status == model.WaybillStatusWaitDelivery || 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			(waybillModel.Status == model.WaybillStatusInDelivery && waybillModel.CoolerBoxId != c.CoolerBoxId) || 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			(waybillModel.Status == model.WaybillStatusInDelivery && !lib.StrListEqual(c.IceRaftCode, c.OldIceRaftCode)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			waybillModel.Status = model.WaybillStatusInDelivery 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if waybillModel.Status == model.WaybillStatusInDeliverys || 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			(waybillModel.Status == model.WaybillStatusInDeliverys && waybillModel.CoolerBoxId != c.CoolerBoxId) || 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			(waybillModel.Status == model.WaybillStatusInDeliverys && !lib.StrListEqual(c.IceRaftCode, c.OldIceRaftCode)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			waybillModel.Status = model.WaybillStatusInDeliverys 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			waybillModel.TamperProofLabel = c.TamperProofLabel 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			waybillModel.TamperProofLabelImg = c.TamperProofLabelImg // 防拆标签 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			waybillModel.CoolerBoxId = c.CoolerBoxId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			waybillModel.DeliveryTime = model2.Time(time.Now()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			waybillModel.IceRaftCode = c.IceRaftCode 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -476,7 +606,7 @@ func (e *Waybill) Delivery(c *dto.WaybillDeliveryReq, p *actions.DataPermission) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			// 查询任务 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			var logistics model.WaybillLogistics 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			err = tx.Model(&logistics).Where("waybill_no = ? and status = ?", waybillModel.WaybillNo, model.WaybillStatusInDelivery). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			err = tx.Model(&logistics).Where("waybill_no = ? and status = ?", waybillModel.WaybillNo, model.WaybillStatusInDeliverys). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 				Last(&logistics).Error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 				if errors.Is(err, gorm.ErrRecordNotFound) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -552,8 +682,8 @@ func (e *Waybill) Delivery(c *dto.WaybillDeliveryReq, p *actions.DataPermission) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		// 待派单状态下才发送短信 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		if waybillModeStatus == model.WaybillStatusWaitDelivery { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		// 待配送时状态下才发送短信 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		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)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			res, err1 := ss.SmsXSend(waybillModel.ConsigneeAddressPhone, addr) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -653,13 +783,17 @@ func (e *Waybill) Receipt(c *dto.WaybillReceiptReq, p *actions.DataPermission) e 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return err 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if waybillModel.Status == model.WaybillStatusReceipt || waybillModel.Status == model.WaybillStatusRejection { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if waybillModel.Status == model.WaybillStatusReceipts || waybillModel.Status == model.WaybillStatusRejections { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	waybillModel.Status = c.Status 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	waybillModel.RejectionReason = c.RejectionReason 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	waybillModel.ReceiptTime = model2.Time(time.Now()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	waybillModel.ReceiptImg = c.ReceiptImg 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	waybillModel.Receiptsign = c.Receiptsign 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	waybillModel.PaymentStatus = c.PaymentStatus 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	waybillModel.PaymentType = c.PaymentType 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	waybillModel.PaymentRemark = c.PaymentRemark 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	waybillModel.AssessContent = c.AssessContent 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	waybillModel.AssessStar = c.AssessStar 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	waybillModel.DeliveryDuration = int(time.Now().Sub(waybillModel.DeliveryTime.Local()).Minutes()) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -783,14 +917,14 @@ func (e *Waybill) GetBasicsStats(c *dto.WaybillStatsReq, p *actions.DataPermissi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 今日总运单数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	e.Orm.Model(&data).Scopes(actions.Permission(data.TableName(), p)).Where("order_time between ? and ?", todayStartTime, todayEndTime).Count(&res.TodayNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// 待派单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// 待确定 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	e.Orm.Model(&data).Scopes(actions.Permission(data.TableName(), p)).Where("status = ?", model.WaybillStatusWaitDelivery).Count(&res.WaitDeliveryNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 配送中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	e.Orm.Model(&data).Scopes(actions.Permission(data.TableName(), p)).Where("status = ?", model.WaybillStatusInDelivery).Count(&res.InDeliveryNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	// 已送达 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	e.Orm.Model(&data).Scopes(actions.Permission(data.TableName(), p)).Where("status = ?", model.WaybillStatusReceipt).Count(&res.ReceiptNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	e.Orm.Model(&data).Scopes(actions.Permission(data.TableName(), p)).Where("status = ?", model.WaybillStatusInDeliverys).Count(&res.InDeliveryNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// 已签收 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	e.Orm.Model(&data).Scopes(actions.Permission(data.TableName(), p)).Where("status = ?", model.WaybillStatusReceipts).Count(&res.ReceiptNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 已取消 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	e.Orm.Model(&data).Scopes(actions.Permission(data.TableName(), p)).Where("status = ?", model.WaybillStatusRejection).Count(&res.RejectionNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	e.Orm.Model(&data).Scopes(actions.Permission(data.TableName(), p)).Where("status = ?", model.WaybillStatusRejections).Count(&res.RejectionNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 获取本月,上月数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	e.Orm.Model(&data).Select("date_format(order_time,'%Y%m') date,count(1) as count ").Scopes(actions.Permission(data.TableName(), p)). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		Where("order_time between ? and ?", monthStartTime, now).Group("date").Find(&monthCount) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -939,13 +1073,13 @@ func (e *Waybill) GetUserBasicsStats(c *dto.WaybillStatsReq, p *actions.DataPerm 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		Where("status = ?", model.WaybillStatusWaitDelivery).Count(&res.WaitDeliveryNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 配送中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	e.Orm.Model(&data).Scopes(actions.Permission(data.TableName(), p), scopes). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		Where("status = ?", model.WaybillStatusInDelivery).Count(&res.InDeliveryNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Where("status = ?", model.WaybillStatusInDeliverys).Count(&res.InDeliveryNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 已送达 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	e.Orm.Model(&data).Scopes(actions.Permission(data.TableName(), p), scopes). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		Where("status = ?", model.WaybillStatusReceipt).Count(&res.ReceiptNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Where("status = ?", model.WaybillStatusReceipts).Count(&res.ReceiptNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 已取消 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	e.Orm.Model(&data).Scopes(actions.Permission(data.TableName(), p), scopes). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		Where("status = ?", model.WaybillStatusRejection).Count(&res.RejectionNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Where("status = ?", model.WaybillStatusRejections).Count(&res.RejectionNum) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 获取本月,上月数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	e.Orm.Model(&data).Select("date_format(order_time,'%Y%m') date,count(1) as count ").Scopes(actions.Permission(data.TableName(), p), scopes). 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		Where("order_time between ? and ?", monthStartTime, now).Group("date").Find(&monthCount) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1108,7 +1242,7 @@ func (e *Waybill) GetAllData(c *dto.WaybillGetByWaybillNoReq) ([]nats_server.Dev 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 未签收,不返回数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if waybill.Status != model.WaybillStatusReceipt { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if waybill.Status != model.WaybillStatusReceipts { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		return dataList, waybillPDF, nil 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1175,7 +1309,7 @@ func (e *Waybill) GetAllData(c *dto.WaybillGetByWaybillNoReq) ([]nats_server.Dev 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 						break 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 					} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-				if waybill.Status == model.WaybillStatusReceipt { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				if waybill.Status == model.WaybillStatusReceipts { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 					for k := len(list) - 1; k >= 0; k-- { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 						if v.T_id == list[k].T_id { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 							if taskList[i].Id == lastWaybillTask.Id && list[k].T_time != taskList[i].EndTime.String() && !time.Time(taskList[i].EndTime).IsZero() { 
			 |