|
@@ -2,9 +2,15 @@ package service
|
|
|
|
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
|
|
+ "fmt"
|
|
|
|
+ "time"
|
|
"youngee_b_api/db"
|
|
"youngee_b_api/db"
|
|
"youngee_b_api/model/gorm_model"
|
|
"youngee_b_api/model/gorm_model"
|
|
"youngee_b_api/model/http_model"
|
|
"youngee_b_api/model/http_model"
|
|
|
|
+
|
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
|
+ "github.com/issue9/conv"
|
|
|
|
+ "github.com/sirupsen/logrus"
|
|
)
|
|
)
|
|
|
|
|
|
var Logistics *logistics
|
|
var Logistics *logistics
|
|
@@ -12,55 +18,85 @@ var Logistics *logistics
|
|
type logistics struct {
|
|
type logistics struct {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 在物流信息表插入记录
|
|
func (*logistics) Create(ctx context.Context, newLogistics http_model.CreateLogisticsRequest) (*http_model.CreateLogisticsData, error) {
|
|
func (*logistics) Create(ctx context.Context, newLogistics http_model.CreateLogisticsRequest) (*http_model.CreateLogisticsData, error) {
|
|
ThingsType := newLogistics.ThingsType
|
|
ThingsType := newLogistics.ThingsType
|
|
RecruitStrategyID := newLogistics.RecruitStrategyID
|
|
RecruitStrategyID := newLogistics.RecruitStrategyID
|
|
Logistics := gorm_model.YoungeeTaskLogistics{
|
|
Logistics := gorm_model.YoungeeTaskLogistics{
|
|
- LogisticsID: newLogistics.LogisticsID,
|
|
|
|
- TaskID: newLogistics.TaskID,
|
|
|
|
- ThingsType: ThingsType,
|
|
|
|
|
|
+ LogisticsID: newLogistics.LogisticsID,
|
|
|
|
+ TaskID: newLogistics.TaskID,
|
|
|
|
+ ThingsType: int64(ThingsType),
|
|
|
|
+ ExplorestoreStarttime: time.Now(),
|
|
|
|
+ ExplorestoreEndtime: time.Now(),
|
|
|
|
+ DeliveryTime: time.Now(),
|
|
|
|
+ SignedTime: time.Now(),
|
|
}
|
|
}
|
|
|
|
+ fmt.Println("ThingsType:", ThingsType)
|
|
//实物
|
|
//实物
|
|
if ThingsType == 1 {
|
|
if ThingsType == 1 {
|
|
Logistics.CompanyName = newLogistics.CompanyName
|
|
Logistics.CompanyName = newLogistics.CompanyName
|
|
- Logistics.DeliveryTime = newLogistics.DeliveryTime
|
|
|
|
- } else if ThingsType == 2 {
|
|
|
|
|
|
+ Logistics.LogisticsNumber = newLogistics.LogisticsNumber
|
|
|
|
+ Logistics.DeliveryTime = time.Now()
|
|
|
|
+ } else if ThingsType == 3 {
|
|
|
|
+ fmt.Println("开始时间:", newLogistics.ExplorestoreStarttime)
|
|
Logistics.ExplorestoreStarttime = newLogistics.ExplorestoreStarttime
|
|
Logistics.ExplorestoreStarttime = newLogistics.ExplorestoreStarttime
|
|
Logistics.ExplorestoreEndtime = newLogistics.ExplorestoreEndtime
|
|
Logistics.ExplorestoreEndtime = newLogistics.ExplorestoreEndtime
|
|
- Logistics.ExplorestorePeriod = newLogistics.ExplorestorePeriod
|
|
|
|
|
|
+ // Logistics.ExplorestorePeriod = newLogistics.ExplorestorePeriod
|
|
} else {
|
|
} else {
|
|
Logistics.CouponCodeInformation = newLogistics.CouponCodeInformation
|
|
Logistics.CouponCodeInformation = newLogistics.CouponCodeInformation
|
|
}
|
|
}
|
|
|
|
+
|
|
logisticsID, err := db.CreateLogistics(ctx, Logistics, RecruitStrategyID)
|
|
logisticsID, err := db.CreateLogistics(ctx, Logistics, RecruitStrategyID)
|
|
if err != nil {
|
|
if err != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[logistics service] call CreateLogistics error,err:%+v", err)
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ // 修改招募策略中已发货待发货数量
|
|
|
|
+ err = db.UpdateLogisticsNumber(ctx, RecruitStrategyID, 1, -1, 0)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[logistics service] call UpdateLogisticsNumber error,err:%+v", err)
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
+ // 修改task_info中发货状态
|
|
|
|
+ err = db.UpdateLogisticsStatus(ctx, Logistics.TaskID, 2)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[logistics service] call UpdateLogisticsStatus error,err:%+v", err)
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 对应招募策略待发货--,已发货++
|
|
|
|
+
|
|
res := &http_model.CreateLogisticsData{
|
|
res := &http_model.CreateLogisticsData{
|
|
LogisticsID: *logisticsID,
|
|
LogisticsID: *logisticsID,
|
|
}
|
|
}
|
|
return res, nil
|
|
return res, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 修改物流信息表
|
|
func (*logistics) Update(ctx context.Context, newLogistics http_model.CreateLogisticsRequest) (*http_model.CreateLogisticsData, error) {
|
|
func (*logistics) Update(ctx context.Context, newLogistics http_model.CreateLogisticsRequest) (*http_model.CreateLogisticsData, error) {
|
|
ThingsType := newLogistics.ThingsType
|
|
ThingsType := newLogistics.ThingsType
|
|
Logistics := gorm_model.YoungeeTaskLogistics{
|
|
Logistics := gorm_model.YoungeeTaskLogistics{
|
|
- LogisticsID: newLogistics.LogisticsID,
|
|
|
|
- TaskID: newLogistics.TaskID,
|
|
|
|
- ThingsType: ThingsType,
|
|
|
|
|
|
+ LogisticsID: newLogistics.LogisticsID,
|
|
|
|
+ TaskID: newLogistics.TaskID,
|
|
|
|
+ ThingsType: int64(ThingsType),
|
|
|
|
+ DeliveryTime: time.Now(),
|
|
|
|
+ SignedTime: time.Now(),
|
|
}
|
|
}
|
|
//实物
|
|
//实物
|
|
if ThingsType == 1 {
|
|
if ThingsType == 1 {
|
|
Logistics.CompanyName = newLogistics.CompanyName
|
|
Logistics.CompanyName = newLogistics.CompanyName
|
|
- Logistics.DeliveryTime = newLogistics.DeliveryTime
|
|
|
|
- } else if ThingsType == 2 {
|
|
|
|
|
|
+ Logistics.LogisticsNumber = newLogistics.LogisticsNumber
|
|
|
|
+ } else if ThingsType == 3 {
|
|
|
|
+ fmt.Println("开始时间:", newLogistics.ExplorestoreStarttime)
|
|
Logistics.ExplorestoreStarttime = newLogistics.ExplorestoreStarttime
|
|
Logistics.ExplorestoreStarttime = newLogistics.ExplorestoreStarttime
|
|
Logistics.ExplorestoreEndtime = newLogistics.ExplorestoreEndtime
|
|
Logistics.ExplorestoreEndtime = newLogistics.ExplorestoreEndtime
|
|
- Logistics.ExplorestorePeriod = newLogistics.ExplorestorePeriod
|
|
|
|
|
|
+ // Logistics.ExplorestorePeriod = newLogistics.ExplorestorePeriod
|
|
} else {
|
|
} else {
|
|
Logistics.CouponCodeInformation = newLogistics.CouponCodeInformation
|
|
Logistics.CouponCodeInformation = newLogistics.CouponCodeInformation
|
|
}
|
|
}
|
|
logisticsID, err := db.UpdateLogistics(ctx, Logistics)
|
|
logisticsID, err := db.UpdateLogistics(ctx, Logistics)
|
|
if err != nil {
|
|
if err != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[logistics service] call UpdateLogistics error,err:%+v", err)
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
res := &http_model.CreateLogisticsData{
|
|
res := &http_model.CreateLogisticsData{
|
|
@@ -68,3 +104,45 @@ func (*logistics) Update(ctx context.Context, newLogistics http_model.CreateLogi
|
|
}
|
|
}
|
|
return res, nil
|
|
return res, nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// 签收
|
|
|
|
+func (*logistics) SignForReceipt(ctx *gin.Context, data http_model.SignForReceiptRequest) interface{} {
|
|
|
|
+ for _, value := range data.TaskStrategyIds {
|
|
|
|
+ taskId := conv.MustInt64(value.TaskId)
|
|
|
|
+ strategyId := conv.MustInt64(value.StrategyId)
|
|
|
|
+ err := db.UpdateLogisticsStatus(ctx, taskId, 3)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[project service] call UpdateLogisticsStatus error,err:%+v", err)
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 签收时间
|
|
|
|
+ err = db.SignForReceipt(ctx, taskId)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[project service] call SignForReceipt error,err:%+v", err)
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ projectId, err1 := db.GetProjectIdByTaskId(ctx, taskId)
|
|
|
|
+ if err1 != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[project service] call GetProjectIdByTaskId error,err:%+v", err1)
|
|
|
|
+ return err1
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 查询recruitStrategyID 通过 StrategyID 和 projectId
|
|
|
|
+ recruitStrategyId, err2 := db.GetRecruitStrategyIdByTS(ctx, *projectId, strategyId)
|
|
|
|
+ if err2 != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[project service] call GetRecruitStrategyIdByTS error,err:%+v", err1)
|
|
|
|
+ return err2
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 修改招募策略中已签收数量
|
|
|
|
+ err = db.UpdateLogisticsNumber(ctx, *recruitStrategyId, 0, 0, 1)
|
|
|
|
+ if err != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[project service] call UpdateLogisticsNumber error,err:%+v", err)
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+}
|