|
@@ -1,7 +1,9 @@
|
|
|
package service
|
|
|
|
|
|
import (
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
+ "gorm.io/gorm"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
"youngee_b_api/app/dao"
|
|
@@ -233,10 +235,14 @@ func (s CooperationService) GetSupplierInTargetTaskList(param *vo.SupplierSearch
|
|
|
// 去除当前project_id、supplier_id已在 s_project_info中的数据
|
|
|
var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
|
|
|
for _, enterpriseSupplier := range enterpriseSupplierCooperates {
|
|
|
- var sProject *entity.SProjectInfo
|
|
|
- _ = dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).Find(&sProject).Error
|
|
|
- if sProject == nil {
|
|
|
- resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
|
|
|
+ var sProject entity.SProjectInfo
|
|
|
+ err1 := dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sProject).Error
|
|
|
+ if err1 != nil {
|
|
|
+ if errors.Is(err1, gorm.ErrRecordNotFound) {
|
|
|
+ resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
|
|
|
+ } else {
|
|
|
+ // 其他错误
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
enterpriseSupplierCooperates = resEnterpriseSuppliers
|
|
@@ -245,10 +251,14 @@ func (s CooperationService) GetSupplierInTargetTaskList(param *vo.SupplierSearch
|
|
|
// 去除当前 local_id、supplier_id 已在 s_local_info中的数据
|
|
|
var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
|
|
|
for _, enterpriseSupplier := range enterpriseSupplierCooperates {
|
|
|
- var sLocalLifeInfo *entity.SLocalLifeInfo
|
|
|
- _ = dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).Find(&sLocalLifeInfo).Error
|
|
|
- if sLocalLifeInfo == nil {
|
|
|
- resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
|
|
|
+ var sLocalLifeInfo entity.SLocalLifeInfo
|
|
|
+ err2 := dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sLocalLifeInfo).Error
|
|
|
+ if err2 != nil {
|
|
|
+ if errors.Is(err2, gorm.ErrRecordNotFound) {
|
|
|
+ resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
|
|
|
+ } else {
|
|
|
+ // 其他错误
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
enterpriseSupplierCooperates = resEnterpriseSuppliers
|
|
@@ -355,13 +365,51 @@ func (t CooperationService) GetSupplierInTargetCount(param *vo.SupplierSearchInT
|
|
|
var invitableNum int64 // 可邀约
|
|
|
var invitingNum int64 // 邀约中
|
|
|
var cooperatingNum int64 // 合作中
|
|
|
- dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = ?", param.EnterpriseId, 2).Count(&invitableNum)
|
|
|
+
|
|
|
if param.TaskType == 2 {
|
|
|
// 品牌种草
|
|
|
+ var enterpriseSupplierCooperates []*entity.EnterpriseSupplierCooperate
|
|
|
+ query := dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = 2", param.EnterpriseId)
|
|
|
+ err := query.Select("supplier_id").Find(&enterpriseSupplierCooperates).Error
|
|
|
+ var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
|
|
|
+ if err == nil {
|
|
|
+ // 去除当前project_id、supplier_id已在 s_project_info中的数据
|
|
|
+ for _, enterpriseSupplier := range enterpriseSupplierCooperates {
|
|
|
+ var sProject entity.SProjectInfo
|
|
|
+ err1 := dao.Db.Debug().Model(&entity.SProjectInfo{}).Where("project_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sProject).Error
|
|
|
+ if err1 != nil {
|
|
|
+ if errors.Is(err1, gorm.ErrRecordNotFound) {
|
|
|
+ resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
|
|
|
+ } else {
|
|
|
+ // 其他错误
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ invitableNum = int64(len(resEnterpriseSuppliers))
|
|
|
dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? AND s_project_status = ?", param.TaskId, 1).Count(&invitingNum)
|
|
|
dao.Db.Model(&entity.SProjectInfo{}).Where("project_id = ? AND s_project_status = ?", param.TaskId, 2).Count(&cooperatingNum)
|
|
|
} else if param.TaskType == 3 {
|
|
|
// 本地生活
|
|
|
+ var enterpriseSupplierCooperates []*entity.EnterpriseSupplierCooperate
|
|
|
+ query := dao.Db.Model(&entity.EnterpriseSupplierCooperate{}).Where("enterprise_id = ? AND cooperate_status = 2", param.EnterpriseId)
|
|
|
+ err := query.Select("supplier_id").Find(&enterpriseSupplierCooperates).Error
|
|
|
+ var resEnterpriseSuppliers []*entity.EnterpriseSupplierCooperate
|
|
|
+ if err == nil {
|
|
|
+ // 去除当前local_id、supplier_id已在 s_local_info中的数据
|
|
|
+ for _, enterpriseSupplier := range enterpriseSupplierCooperates {
|
|
|
+ var sLocalLifeInfo entity.SLocalLifeInfo
|
|
|
+ err1 := dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? and supplier_id = ?", param.TaskId, enterpriseSupplier.SupplierId).First(&sLocalLifeInfo).Error
|
|
|
+ if err1 != nil {
|
|
|
+ if errors.Is(err1, gorm.ErrRecordNotFound) {
|
|
|
+ resEnterpriseSuppliers = append(resEnterpriseSuppliers, enterpriseSupplier)
|
|
|
+ } else {
|
|
|
+ // 其他错误
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ invitableNum = int64(len(resEnterpriseSuppliers))
|
|
|
dao.Db.Model(&entity.SLocalLifeInfo{}).Where("local_id = ? AND s_local_status = ?", param.TaskId, 1).Count(&invitingNum)
|
|
|
dao.Db.Model(&entity.SProjectInfo{}).Where("local_id = ? AND s_local_status = ?", param.TaskId, 2).Count(&cooperatingNum)
|
|
|
|