浏览代码

Merge remote-tracking branch 'origin/develop' into develop

lin-jim-leon 5 天之前
父节点
当前提交
9375cf80bb
共有 6 个文件被更改,包括 77 次插入35 次删除
  1. 6 6
      app/controller/bill_controller.go
  2. 8 1
      app/controller/common.go
  3. 17 5
      app/controller/task_controller.go
  4. 33 17
      route/init.go
  5. 7 5
      service/login_auth.go
  6. 6 1
      service/logistics.go

+ 6 - 6
app/controller/bill_controller.go

@@ -39,11 +39,11 @@ func (f BillController) SelectionPay(c *gin.Context) {
 	err1 := service.BillService{}.PaySelection(param)
 	if err1 != nil {
 		if err1.Error() == "状态异常" {
-			returnError(c, 31000, err1.Error())
+			returnSuccessWithMessage(c, 31000, err1.Error(), nil)
 			return
 		}
 		if err1.Error() == "可用余额不足" {
-			returnError(c, 32000, err1.Error())
+			returnSuccessWithMessage(c, 32000, err1.Error(), nil)
 			return
 		}
 		logrus.Errorf("[SelectionPay] call Show err:%+v\n", err)
@@ -83,11 +83,11 @@ func (f BillController) ProjectPay(c *gin.Context) {
 	err1 := service.BillService{}.PayProject(param)
 	if err1 != nil {
 		if err1.Error() == "状态异常" {
-			returnError(c, 31000, err1.Error())
+			returnSuccessWithMessage(c, 31000, err1.Error(), nil)
 			return
 		}
 		if err1.Error() == "可用余额不足" {
-			returnError(c, 32000, err1.Error())
+			returnSuccessWithMessage(c, 32000, err1.Error(), nil)
 			return
 		}
 		logrus.Errorf("[ProjectPay] call Show err:%+v\n", err)
@@ -127,11 +127,11 @@ func (f BillController) LocalLifePay(c *gin.Context) {
 	err1 := service.BillService{}.PayLocalLife(param)
 	if err1 != nil {
 		if err1.Error() == "状态异常" {
-			returnError(c, 31000, err1.Error())
+			returnSuccessWithMessage(c, 31000, err1.Error(), nil)
 			return
 		}
 		if err1.Error() == "可用余额不足" {
-			returnError(c, 32000, err1.Error())
+			returnSuccessWithMessage(c, 32000, err1.Error(), nil)
 			return
 		}
 		logrus.Errorf("[LocalLifePay] call Show err:%+v\n", err)

+ 8 - 1
app/controller/common.go

@@ -6,7 +6,6 @@ type JsonStruct struct {
 	Code int         `json:"code"`
 	Msg  interface{} `json:"msg"`
 	Data interface{} `json:"data"`
-	//Count int64       `json:"count"`
 }
 
 type JsonErrStruct struct {
@@ -19,6 +18,14 @@ func returnSuccess(c *gin.Context, code int, data interface{}) {
 	c.JSON(200, json)
 }
 
+func returnSuccessWithMessage(c *gin.Context, code int, msg string, data interface{}) {
+	if msg == "" {
+		msg = "ok"
+	}
+	json := &JsonStruct{Code: code, Msg: msg, Data: data}
+	c.JSON(200, json)
+}
+
 func returnError(c *gin.Context, code int, msg string) {
 	json := &JsonErrStruct{}
 	if msg == "" {

+ 17 - 5
app/controller/task_controller.go

@@ -60,11 +60,11 @@ func (t TaskController) CreateProduct(c *gin.Context) {
 	productId, err := service.ProductService{}.CreateProduct(data)
 	if err != nil {
 		if err.Error() == "该快手商品已存在!" {
-			returnError(c, 30010, err.Error())
+			returnSuccessWithMessage(c, 30010, err.Error(), nil)
 			return
 		}
 		if err.Error() == "商品主图不能为空!" {
-			returnError(c, 30020, err.Error())
+			returnSuccessWithMessage(c, 30020, err.Error(), nil)
 			return
 		}
 		logrus.Errorf("[CreateProduct] call CreateProduct err:%+v\n", err)
@@ -146,7 +146,7 @@ func (t TaskController) CopySelection(c *gin.Context) {
 	res, err := service.SelectionInfoService{}.CopySelection(data)
 	if err != nil {
 		if err.Error() == "任务不存在" {
-			returnError(c, 30000, err.Error())
+			returnSuccessWithMessage(c, 30000, err.Error(), nil)
 			return
 		}
 		logrus.Errorf("[CopySelection] call CopySelection err:%+v\n", err)
@@ -260,6 +260,10 @@ func (t TaskController) CreateProject(c *gin.Context) {
 		returnError(c, 40000, "Parameter Error: "+err.Error())
 		return
 	}
+	if data.RecruitStrategys == nil || len(data.RecruitStrategys) == 0 {
+		returnSuccessWithMessage(c, 30030, "招募策略不能为空", nil)
+		return
+	}
 	projectId, err := service.ProjectService{}.CreateProject(data)
 	if err != nil {
 		logrus.Errorf("[CreateProject] call CreateProject err:%+v\n", err)
@@ -280,6 +284,10 @@ func (t TaskController) UpdateProject(c *gin.Context) {
 		returnError(c, 40000, "Parameter Error: "+err.Error())
 		return
 	}
+	if data.RecruitStrategys == nil || len(data.RecruitStrategys) == 0 {
+		returnSuccessWithMessage(c, 30030, "招募策略不能为空", nil)
+		return
+	}
 	projectId, err := service.ProjectService{}.UpdateProject(data)
 	if err != nil {
 		logrus.Errorf("[UpdateProject] call UpdateProject err:%+v\n", err)
@@ -300,6 +308,10 @@ func (t TaskController) UpdateProjectTarget(c *gin.Context) {
 		returnError(c, 40000, "Parameter Error: "+err.Error())
 		return
 	}
+	if data.RecruitStrategys == nil || len(data.RecruitStrategys) == 0 {
+		returnSuccessWithMessage(c, 30030, "招募策略不能为空", nil)
+		return
+	}
 	projectId, err := service.ProjectService{}.UpdateProjectTarget(data)
 	if err != nil {
 		logrus.Errorf("[UpdateProject] call UpdateProject err:%+v\n", err)
@@ -342,7 +354,7 @@ func (t TaskController) CopyProject(c *gin.Context) {
 	projectId, err := service.ProjectService{}.CopyProject(data)
 	if err != nil {
 		if err.Error() == "任务不存在" {
-			returnError(c, 30000, err.Error())
+			returnSuccessWithMessage(c, 30000, err.Error(), nil)
 			return
 		}
 		logrus.Errorf("[CopyProject] call CopyProject err:%+v\n", err)
@@ -862,7 +874,7 @@ func (t TaskController) CopyLocalLife(c *gin.Context) {
 	localId, err := service.LocalLifeService{}.CopyLocalLife(data)
 	if err != nil {
 		if err.Error() == "任务不存在" {
-			returnError(c, 30000, err.Error())
+			returnSuccessWithMessage(c, 30000, err.Error(), nil)
 			return
 		}
 		logrus.Errorf("[CreateLocalLife] call CreateLocalLife err:%+v\n", err)

+ 33 - 17
route/init.go

@@ -15,23 +15,9 @@ func InitRoute(r *gin.Engine) {
 	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
 	business := r.Group("/youngee")
 	{
-		business.POST("/register", handler.WrapRegisterHandler)                    // 商家主账号注册
-		business.POST("/sendCode", handler.WrapSendCodeHandler)                    // 发送登录验证码
-		business.POST("/login", handler.WrapCodeLoginHandler)                      // 商家登录
-		business.POST("/subAccount/create", handler.WrapAddNewSubAccountHandler)   // 商家子账号注册
-		business.POST("/subAccount/get", handler.WrapFindAllSubAccountHandler)     // 查找商家全部所属子账号
-		business.POST("/subAccount/delete", handler.WrapDeleteSubAccountHandler)   // 删除商家子账号
-		business.POST("/subAccount/update", handler.WrapFindAllSubAccountHandler)  // 修改商家子账号
-		business.POST("/job/get", handler.WrapFindAllJobHandler)                   // 查找商家全部所属岗位
-		business.POST("/job/create", handler.WrapaddNewJobHandler)                 // 商家新增岗位
-		business.POST("/job/update", handler.WrapupdateJobHandler)                 // 商家修改岗位
-		business.POST("/job/delete", handler.WrapdeleteJobHandler)                 // 商家删除岗位
-		business.POST("/getUserInfo", handler.WrapGetUserInfoHandler)              // 商家用户信息
-		business.POST("/accountInfo/get", handler.WrapGetAccountInfoHandler)       // 账号管理-账号信息查询
-		business.POST("/accountInfo/update", handler.WrapUpdateAccountInfoHandler) // 账号管理-账号信息更新
-		business.POST("/reviewInfo/get", handler.WrapGetReviewInfoHandler)         // 账号管理-认证信息查询
-		business.POST("/contactInfo/get", handler.WrapGetContactInfoHandler)       // 联系方式-查询
-		business.POST("/contactInfo/update", handler.WrapUpdateContactInfoHandler) // 联系方式-更新
+		business.POST("/register", handler.WrapRegisterHandler) // 商家主账号注册
+		business.POST("/sendCode", handler.WrapSendCodeHandler) // 发送登录验证码
+		business.POST("/login", handler.WrapCodeLoginHandler)   // 商家登录
 		business.GET("/test/ping", func(c *gin.Context) {
 			resp := http_model.CommonResponse{
 				Status:  20000,
@@ -41,6 +27,36 @@ func InitRoute(r *gin.Engine) {
 			c.JSON(200, resp)
 		})
 	}
+
+	subAccount := r.Group("/youngee/subAccount")
+	{
+		subAccount.Use(middleware.LoginAuthMiddleware)
+		subAccount.POST("/create", handler.WrapAddNewSubAccountHandler)  // 商家子账号注册
+		subAccount.POST("/get", handler.WrapFindAllSubAccountHandler)    // 查找商家全部所属子账号
+		subAccount.POST("/delete", handler.WrapDeleteSubAccountHandler)  // 删除商家子账号
+		subAccount.POST("/update", handler.WrapFindAllSubAccountHandler) // 修改商家子账号
+	}
+
+	job := r.Group("/youngee/job")
+	{
+		job.Use(middleware.LoginAuthMiddleware)
+		job.POST("/get", handler.WrapFindAllJobHandler)   // 查找商家全部所属岗位
+		job.POST("/create", handler.WrapaddNewJobHandler) // 商家新增岗位
+		job.POST("/update", handler.WrapupdateJobHandler) // 商家修改岗位
+		job.POST("/delete", handler.WrapdeleteJobHandler) // 商家删除岗位
+	}
+
+	accountInfo := r.Group("/youngee")
+	{
+		accountInfo.Use(middleware.LoginAuthMiddleware)
+		accountInfo.POST("/getUserInfo", handler.WrapGetUserInfoHandler)              // 商家用户信息
+		accountInfo.POST("/accountInfo/get", handler.WrapGetAccountInfoHandler)       // 账号管理-账号信息查询
+		accountInfo.POST("/accountInfo/update", handler.WrapUpdateAccountInfoHandler) // 账号管理-账号信息更新
+		accountInfo.POST("/reviewInfo/get", handler.WrapGetReviewInfoHandler)         // 账号管理-认证信息查询
+		accountInfo.POST("/contactInfo/get", handler.WrapGetContactInfoHandler)       // 联系方式-查询
+		accountInfo.POST("/contactInfo/update", handler.WrapUpdateContactInfoHandler) // 联系方式-更新
+	}
+
 	//r.Any("/testDemo", func(c *gin.Context) {
 	//	resp := http_model.CommonResponse{
 	//		Status:  0,

+ 7 - 5
service/login_auth.go

@@ -98,7 +98,7 @@ func (l *loginAuth) AuthCode(ctx context.Context, phone string, code string) (in
 		userData = userInfo
 	}
 
-	token := l.getToken(ctx, phone)
+	token := l.getToken(ctx, phone, userData.Role)
 	var jobData gorm_model.YounggeeJob
 	var accountData gorm_model.YounggeeSubAccount
 	var enterpriseUser gorm_model.Enterprise
@@ -127,7 +127,8 @@ func (l *loginAuth) AuthCode(ctx context.Context, phone string, code string) (in
 				Token:        token,
 				EnterpriseID: enterpriseUserInfo.EnterpriseID,
 			}
-			if sessionErr := l.setSession(ctx, phone, auth); sessionErr != nil {
+			key := phone + userData.Role
+			if sessionErr := l.setSession(ctx, key, auth); sessionErr != nil {
 				fmt.Printf("setSession error\n")
 				return 0, nil, sessionErr
 			}
@@ -159,7 +160,8 @@ func (l *loginAuth) AuthCode(ctx context.Context, phone string, code string) (in
 			}
 			if jobInfo != nil {
 				jobData = *jobInfo
-				if sessionErr := l.setSession(ctx, phone, auth); sessionErr != nil {
+				key := phone + userData.Role
+				if sessionErr := l.setSession(ctx, key, auth); sessionErr != nil {
 					fmt.Printf("setSession error\n")
 					return 0, nil, sessionErr
 				}
@@ -264,9 +266,9 @@ func (l *loginAuth) getSessionAuth(ctx context.Context, phone string) (*redis_mo
 	return auth, nil
 }
 
-func (l *loginAuth) getToken(ctx context.Context, phone string) string {
+func (l *loginAuth) getToken(ctx context.Context, phone string, role string) string {
 	timeSeed := strconv.FormatInt(time.Now().Unix(), 10)
-	token := phone + "." + timeSeed + "." + util.MD5(phone, timeSeed, consts.AuthSalt)
+	token := phone + role + "." + timeSeed + "." + util.MD5(phone+role, timeSeed, consts.AuthSalt)
 	return token
 }
 

+ 6 - 1
service/logistics.go

@@ -3,7 +3,10 @@ package service
 import (
 	"context"
 	"fmt"
+	"gorm.io/gorm"
 	"time"
+	"youngee_b_api/app/dao"
+	"youngee_b_api/app/entity"
 	"youngee_b_api/db"
 	"youngee_b_api/model/gorm_model"
 	"youngee_b_api/model/http_model"
@@ -80,6 +83,8 @@ func (*logistics) Create(ctx context.Context, newLogistics http_model.CreateLogi
 		return nil, err1
 	}
 
+	dao.Db.Model(&entity.Project{ProjectId: *projectId}).Update("delivery_num", gorm.Expr("delivery_num + ?", 1))
+
 	// 查询StrategyID 通过 StrategyID 和 projectId
 	RecruitStrategyId, err2 := db.GetRecruitStrategyIdByTS(ctx, *projectId, StrategyID)
 	if err2 != nil {
@@ -102,7 +107,7 @@ func (*logistics) Create(ctx context.Context, newLogistics http_model.CreateLogi
 		return nil, err
 	}
 	// 修改task_info中任务阶段
-	err = db.UpdateTaskStageByTaskId(ctx, Logistics.TaskID, 2, 5) //修改为待传初稿
+	err = db.UpdateTaskStageByTaskId(ctx, Logistics.TaskID, 2, 5) //修改为已发货
 	if err != nil {
 		logrus.WithContext(ctx).Errorf("[logistics service] call UpdateLogisticsDate error,err:%+v", err)
 		return nil, err