2021-12-14 13:34:42 +08:00
package model
2021-12-23 17:43:27 +08:00
import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
)
2021-12-14 13:34:42 +08:00
type ManageCompany struct {
* model . ManageCompany
}
2021-12-23 17:43:27 +08:00
// ManageCompanyProduct 产品信息
type ManageCompanyProduct struct {
* model . TechnologyProduct
VisitCount int ` json:"visit_count" `
IsCollect uint64 ` json:"is_collect" `
CollectCount int ` json:"collect_count" `
}
// Product 产品信息
func ( m * ManageCompany ) Product ( id , uid uint64 , page , pageSize int , count * int64 ) ( [ ] * ManageCompanyProduct , error ) {
2021-12-27 11:48:44 +08:00
mNewUserCollect := model . NewUserCollect ( )
2021-12-23 17:43:27 +08:00
db := orm . GetDB ( ) . Table ( model . NewUserCompany ( ) . TableName ( ) + " u_c" ) .
Select ( "p.id" , "p.title" , "p.image" , "p.industry" , "p.maturity" , "p.lead_standard" , "p.cooperation_mode" ,
"p.keyword" , "v.count AS visit_count" , "IFNULL(c_u.id, 0) AS is_collect" , "c.count AS collect_count" ) .
Joins ( fmt . Sprintf ( "LEFT JOIN %s AS p ON u_c.uid = p.uid AND p.shelf_status = %d AND p.status = %d AND p.is_deleted = %d" ,
model . NewTechnologyProduct ( ) . TableName ( ) , model . ShelfStatusForUp , model . TechnologyProductStatusForAgree , model . DeleteStatusForNot ) ) .
2021-12-27 11:48:44 +08:00
Joins ( fmt . Sprintf ( "LEFT JOIN (SELECT object_id, SUM(count) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS v ON p.id = v.object_id" ,
model . NewUserVisit ( ) . TableName ( ) , model . UserVisitKindForTechnologyProduct , model . DeleteStatusForNot ) ) .
Joins ( fmt . Sprintf ( "LEFT JOIN (SELECT object_id, COUNT(id) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS c ON p.id = c.object_id" ,
model . NewUserCollect ( ) . TableName ( ) , model . UserCollectKindForTechnologyProduct , model . DeleteStatusForNot ) ) .
Joins ( fmt . Sprintf ( "LEFT JOIN %s AS c_u ON p.id = c_u.product_id AND c_u.uid = %d AND c_u.kind = %d AND c_u.is_deleted = %d" ,
mNewUserCollect . TableName ( ) , uid , model . UserCollectKindForTechnologyProduct , model . DeleteStatusForNot ) ) .
2021-12-23 17:43:27 +08:00
Joins ( fmt . Sprintf ( "" ) ) .
Where ( "u_c.company_id = ?" , id ) .
Where ( "u_c.invalid_status = ?" , model . InvalidStatusForNot ) .
Where ( "u_c.is_deleted = ?" , model . DeleteStatusForNot )
out := make ( [ ] * ManageCompanyProduct , 0 )
if err := db . Count ( count ) . Error ; err != nil {
return nil , err
}
if err := db . Order ( "p.id " + model . OrderModeToDesc ) . Offset ( ( page - 1 ) * pageSize ) . Limit ( pageSize ) . Scan ( & out ) . Error ; err != nil {
return nil , err
}
return out , nil
}
2022-01-11 17:24:38 +08:00
// Distribution 分布信息
func ( m * ManageCompany ) Distribution ( province , city string ) ( [ ] * DataAreaDistributionInfo , error ) {
out := make ( [ ] * DataAreaDistributionInfo , 0 )
db := orm . GetDB ( ) . Table ( m . TableName ( ) ) .
Select ( "province" , "city" , "district" , "GROUP_CONCAT(industry SEPARATOR '&') AS industry" ) .
Group ( "province" ) . Group ( "city" ) . Group ( "district" )
err := db . Order ( "province " + model . OrderModeToAsc ) . Order ( "city " + model . OrderModeToAsc ) . Order ( "district " + model . OrderModeToAsc ) .
Where ( "examine_status = ?" , model . ExamineStatusForAgree ) .
Scan ( & out ) . Error
return out , err
}
2021-12-14 13:34:42 +08:00
func NewManageCompany ( ) * ManageCompany {
return & ManageCompany { model . NewManageCompany ( ) }
}