瀏覽代碼

bug_fixed_0623

Xingyu Xian 1 周之前
父節點
當前提交
8c87ff4b14

+ 29 - 3
db/cooperate.go

@@ -46,7 +46,7 @@ func GetCooperateInfoByIds(ctx context.Context, supplierId int, cooperateStatus
 }
 
 // UpdateCooperateInfo 更新合作关系状态
-func UpdateCooperateInfo(ctx context.Context, cooperateId int, cooperateStatus int) error {
+func UpdateCooperateInfo(ctx context.Context, cooperateId int, cooperateStatus int, supplierId int, subAccountId int) error {
 	db := GetWriteDB(ctx)
 	whereCondition := gorm_model.EnterpriseSupplierCooperate{CooperateId: cooperateId}
 
@@ -57,7 +57,14 @@ func UpdateCooperateInfo(ctx context.Context, cooperateId int, cooperateStatus i
 		var currentTime time.Time
 		currentTime = time.Now()
 		cooperateInfo.AgreeTime = &currentTime
-		err := db.Model(&gorm_model.YounggeeJob{}).Where(whereCondition).Updates(cooperateInfo).Error
+		if subAccountId != 0 {
+			cooperateInfo.SOperator = subAccountId
+			cooperateInfo.SOperatorType = 2
+		} else {
+			cooperateInfo.SOperator = supplierId
+			cooperateInfo.SOperatorType = 1
+		}
+		err := db.Model(&gorm_model.EnterpriseSupplierCooperate{}).Where(whereCondition).Updates(cooperateInfo).Error
 		if err != nil {
 			return err
 		}
@@ -68,7 +75,14 @@ func UpdateCooperateInfo(ctx context.Context, cooperateId int, cooperateStatus i
 		var currentTime time.Time
 		currentTime = time.Now()
 		cooperateInfo.AgreeTime = &currentTime
-		err := db.Model(&gorm_model.YounggeeJob{}).Where(whereCondition).Updates(cooperateInfo).Error
+		if subAccountId != 0 {
+			cooperateInfo.SOperator = subAccountId
+			cooperateInfo.SOperatorType = 2
+		} else {
+			cooperateInfo.SOperator = supplierId
+			cooperateInfo.SOperatorType = 1
+		}
+		err := db.Model(&gorm_model.EnterpriseSupplierCooperate{}).Where(whereCondition).Updates(cooperateInfo).Error
 		if err != nil {
 			return err
 		}
@@ -91,3 +105,15 @@ func FindCooperateInfoBySupplierAndEnterprise(ctx context.Context, supplierId in
 	}
 	return total, nil
 }
+
+// CountCooperateBySupplierId 合作列表数量统计
+func CountCooperateBySupplierId(ctx context.Context, supplierId int, cooperateStatus int) (int64, error) {
+	db := GetReadDB(ctx)
+	var cooperateNum int64
+	err := db.Model(gorm_model.EnterpriseSupplierCooperate{}).Where("supplier_id = ? and cooperate_status = ?", supplierId, cooperateStatus).Count(&cooperateNum).Error
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[CreateMessageByTask] error read mysql, err:%+v", err)
+		return 0, err
+	}
+	return cooperateNum, nil
+}

+ 1 - 1
handler/agree_enterprise_cooperate.go

@@ -35,7 +35,7 @@ func (h *AgreeCooperateHandler) getResponse() interface{} {
 	return h.resp
 }
 func (h *AgreeCooperateHandler) run() {
-	err := service.Cooperate.AgreeEnterpriseCooperate(h.ctx, h.req.CooperateId)
+	err := service.Cooperate.AgreeEnterpriseCooperate(h.ctx, h.req)
 	if err != nil {
 		h.resp.Status = 40000
 		h.resp.Message = "同意合作邀约失败"

+ 50 - 0
handler/cooperate_count.go

@@ -0,0 +1,50 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service"
+)
+
+func WrapCooperateCountHandler(ctx *gin.Context) {
+	handler := newCooperateCountHandler(ctx)
+	baseRun(handler)
+}
+
+func newCooperateCountHandler(ctx *gin.Context) *CooperateCountHandler {
+	return &CooperateCountHandler{
+		req:  http_model.NewCooperateCountRequest(),
+		resp: http_model.NewCooperateCountResponse(),
+		ctx:  ctx,
+	}
+}
+
+type CooperateCountHandler struct {
+	req  *http_model.CooperateCountRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (h *CooperateCountHandler) getRequest() interface{} {
+	return h.req
+}
+func (h *CooperateCountHandler) getContext() *gin.Context {
+	return h.ctx
+}
+func (h *CooperateCountHandler) getResponse() interface{} {
+	return h.resp
+}
+func (h *CooperateCountHandler) run() {
+	data, err := service.Cooperate.CooperateCount(h.ctx, h.req)
+	if err != nil {
+		h.resp.Status = 40000
+		h.resp.Message = "err"
+		return
+	}
+	h.resp.Status = 20000
+	h.resp.Message = "ok"
+	h.resp.Data = data
+}
+func (h *CooperateCountHandler) checkParam() error {
+	return nil
+}

+ 1 - 0
handler/enterprise_supplier_cooperate.go

@@ -48,6 +48,7 @@ func (h *EnterpriseListHandler) run() {
 	h.resp.Message = "ok"
 	h.resp.Data = enterpriseListData
 }
+
 func (h *EnterpriseListHandler) checkParam() error {
 	return nil
 }

+ 1 - 1
handler/reject_enterprise_cooperate.go

@@ -35,7 +35,7 @@ func (h *RejectCooperateHandler) getResponse() interface{} {
 	return h.resp
 }
 func (h *RejectCooperateHandler) run() {
-	err := service.Cooperate.RejectEnterpriseCooperate(h.ctx, h.req.CooperateId)
+	err := service.Cooperate.RejectEnterpriseCooperate(h.ctx, h.req)
 	if err != nil {
 		h.resp.Status = 40000
 		h.resp.Message = err.Error()

+ 3 - 1
model/http_model/agree_enterprise_cooperate.go

@@ -1,7 +1,9 @@
 package http_model
 
 type AgreeCooperateRequest struct {
-	CooperateId int `json:"cooperate_id"` // 合作表主键ID
+	SupplierId   int `json:"supplierId"`   // 服务商ID
+	SubAccountId int `json:"subAccountId"` // 子账号ID
+	CooperateId  int `json:"cooperate_id"` // 合作表主键ID
 }
 
 type AgreeCooperateData struct {

+ 21 - 0
model/http_model/cooperate_count.go

@@ -0,0 +1,21 @@
+package http_model
+
+type CooperateCountRequest struct {
+	SupplierId int `json:"supplier_id"` // 服务商ID
+}
+
+type CooperateCountData struct {
+	Status1 int64 `json:"status_1"` // 未处理
+	Status2 int64 `json:"status_2"` // 已同意
+	Status3 int64 `json:"status_3"` // 已拒绝
+}
+
+func NewCooperateCountRequest() *CooperateCountRequest {
+	return new(CooperateCountRequest)
+}
+
+func NewCooperateCountResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(CooperateCountData)
+	return resp
+}

+ 9 - 5
model/http_model/enterprise_supplier_cooperate.go

@@ -17,21 +17,25 @@ type EnterpriseSupplierCooperateData struct {
 	EnterpriseId       string `json:"enterprise_id"`        // 商家ID
 	EnterprisePhone    string `json:"enterprise_phone"`     // 商家手机号
 	EnterpriseAuth     int    `json:"enterprise_auth"`      // 商家认证状态,0未认证,1已认证
+	EnterpriseAvatar   string `json:"enterprise_avatar"`    // 商家头像url
+	EnterpriseName     string `json:"enterprise_name"`      // 商家名称
+	WechatNumber       string `json:"wechat_number"`        // 微信号码
+	WechatQrCode       string `json:"wechat_qr_code"`       // 微信二维码url
+	CompanyName        string `json:"company_name"`         // 商家认证公司名称
 	SupplierId         int    `json:"supplier_id"`          // 服务商ID
 	CooperateNum       int    `json:"cooperate_num"`        // 受邀合作次数
 	UploadTalentNum    int    `json:"upload_talent_num"`    // 提报达人数量
 	CooperateTalentNum int    `json:"cooperate_talent_num"` // 合作达人人数
-	SOperator          int    `json:"s_operator"`           // 服务商同意/拒绝邀约操作人
+	SOperator          int    `json:"s_operator"`           // 服务商同意/拒绝邀约操作人Id
+	SOperatorName      string `json:"s_operator_name"`      // 服务商同意/拒绝邀约操作人名称
 	SOperatorType      int    `json:"s_operator_type"`      // 服务商操作人类型:1主账号,2子账号
-	BOperator          string `json:"b_operator"`           // 商家发起入库邀约人
+	BOperator          string `json:"b_operator"`           // 商家发起入库邀约人Id
+	BOperatorName      string `json:"b_operator_name"`      // 商家发起入库邀约人名称
 	BOperatorType      int    `json:"b_operator_type"`      // 商家发起入库邀约人类型:1主账号,2子账号
 	CooperateStatus    int    `json:"cooperate_status"`     // 邀约状态:1待同意,2已同意,3已拒绝
 	CreateTime         string `json:"create_time"`          // 合作邀约时间
 	AgreeTime          string `json:"agree_time"`           // 同意邀约时间
 	RejectTime         string `json:"reject_time"`          // 拒绝邀约时间
-	CompanyName        string `json:"company_name"`         // 商家认证公司名称
-	WechatNumber       string `json:"wechat_number"`        // 微信号码
-	WechatQrCode       string `json:"wechat_qr_code"`       // 微信二维码url
 }
 
 func NewEnterpriseListRequest() *EnterpriseListRequest {

+ 3 - 1
model/http_model/reject_enterprise_cooperate.go

@@ -1,7 +1,9 @@
 package http_model
 
 type RejectCooperateRequest struct {
-	CooperateId int `json:"cooperate_id"` // 合作表主键ID
+	SupplierId   int `json:"supplierId"`   // 服务商ID
+	SubAccountId int `json:"subAccountId"` // 子账号ID
+	CooperateId  int `json:"cooperate_id"` // 合作表主键ID
 }
 
 type RejectCooperateData struct {

+ 1 - 0
route/init.go

@@ -104,6 +104,7 @@ func InitRoute(r *gin.Engine) {
 		c.POST("/enterpriseList", handler.WrapEnterpriseListHandler)   // 商家列表
 		c.POST("/agreeCooperate", handler.WrapAgreeCooperateHandler)   // 同意入库邀请
 		c.POST("/rejectCooperate", handler.WrapRejectCooperateHandler) // 拒绝入库邀请
+		c.POST("/cooperateCount", handler.WrapCooperateCountHandler)   // 合作列表数量
 
 		c.POST("/talentList", handler.WrapTalentListHandler)                   // 达人库达人列表
 		c.POST("/talentData", handler.WrapTalentDataHandler)                   // 达人库核心数据、达人信息查询

+ 43 - 10
service/cooperate.go

@@ -39,14 +39,14 @@ func (*cooperate) GetEnterpriseInfoBySupplierId(ctx context.Context, request *ht
 			cooperateData.SOperatorType = c.SOperatorType
 			cooperateData.BOperator = c.BOperator
 			cooperateData.BOperatorType = c.BOperatorType
-			if cooperateData.CreateTime != "" {
-				cooperateData.CreateTime = conv.MustString(c.CreateTime, "")
+			if c.CreateTime != nil {
+				cooperateData.CreateTime = conv.MustString(c.CreateTime, "")[0:19]
 			}
-			if cooperateData.AgreeTime != "" {
-				cooperateData.AgreeTime = conv.MustString(c.AgreeTime, "")
+			if c.AgreeTime != nil {
+				cooperateData.AgreeTime = conv.MustString(c.AgreeTime, "")[0:19]
 			}
-			if cooperateData.RejectTime != "" {
-				cooperateData.RejectTime = conv.MustString(c.RejectTime, "")
+			if c.RejectTime != nil {
+				cooperateData.RejectTime = conv.MustString(c.RejectTime, "")[0:19]
 			}
 
 			// 1.2. 商家信息
@@ -57,7 +57,17 @@ func (*cooperate) GetEnterpriseInfoBySupplierId(ctx context.Context, request *ht
 			if enterpriseInfo != nil {
 				cooperateData.EnterprisePhone = enterpriseInfo.Phone
 				cooperateData.EnterpriseAuth = enterpriseInfo.AuthStatus
+				cooperateData.EnterpriseAvatar = enterpriseInfo.Avatar
+				cooperateData.EnterpriseName = enterpriseInfo.EnterpriseName
+				cooperateData.BOperatorName = enterpriseInfo.EnterpriseID
+				cooperateData.WechatNumber = enterpriseInfo.WechatNumber
+				cooperateData.WechatQrCode = enterpriseInfo.WechatQrCode
+				cooperateData.CompanyName = enterpriseInfo.BusinessName
 			}
+
+			// 1.3. 服务商信息
+			cooperateData.SOperatorName = conv.MustString(c.SupplierId)
+
 			enterpriseListData.EnterpriseListInfo = append(enterpriseListData.EnterpriseListInfo, cooperateData)
 		}
 
@@ -97,8 +107,8 @@ func (*cooperate) CreateCooperate(ctx context.Context, enterpriseId string, supp
 }
 
 // AgreeEnterpriseCooperate 同意商家合作邀约请求
-func (*cooperate) AgreeEnterpriseCooperate(ctx context.Context, cooperateId int) error {
-	err := db.UpdateCooperateInfo(ctx, cooperateId, 2)
+func (*cooperate) AgreeEnterpriseCooperate(ctx context.Context, req *http_model.AgreeCooperateRequest) error {
+	err := db.UpdateCooperateInfo(ctx, req.CooperateId, 2, req.SupplierId, req.SubAccountId)
 	if err != nil {
 		return err
 	}
@@ -106,10 +116,33 @@ func (*cooperate) AgreeEnterpriseCooperate(ctx context.Context, cooperateId int)
 }
 
 // RejectEnterpriseCooperate 拒绝商家合作邀约请求
-func (*cooperate) RejectEnterpriseCooperate(ctx context.Context, cooperateId int) error {
-	err := db.UpdateCooperateInfo(ctx, cooperateId, 3)
+func (*cooperate) RejectEnterpriseCooperate(ctx context.Context, req *http_model.RejectCooperateRequest) error {
+	err := db.UpdateCooperateInfo(ctx, req.CooperateId, 3, req.SupplierId, req.SubAccountId)
 	if err != nil {
 		return err
 	}
 	return nil
 }
+
+// CooperateCount 合作列表数统计
+func (*cooperate) CooperateCount(ctx context.Context, req *http_model.CooperateCountRequest) (*http_model.CooperateCountData, error) {
+
+	var cooperateCount *http_model.CooperateCountData
+	cooperateCount = &http_model.CooperateCountData{}
+	status1, status1Err := db.CountCooperateBySupplierId(ctx, req.SupplierId, 1)
+	if status1Err != nil {
+		return nil, status1Err
+	}
+	cooperateCount.Status1 = status1
+	status2, status2Err := db.CountCooperateBySupplierId(ctx, req.SupplierId, 2)
+	if status2Err != nil {
+		return nil, status2Err
+	}
+	cooperateCount.Status2 = status2
+	status3, status3Err := db.CountCooperateBySupplierId(ctx, req.SupplierId, 3)
+	if status3Err != nil {
+		return nil, status3Err
+	}
+	cooperateCount.Status3 = status3
+	return cooperateCount, nil
+}