作者 yangfu

上传修改

... ... @@ -429,3 +429,173 @@ select count(0) from (
}
return
}
//type4 查看所有机会
func ValidChanceAll(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
// sql := `select a.*,b.images,speechs,videos
//from (
//select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total from chance
//where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or id<?) and enable_status=1
//order by create_at desc
//limit ?
//) a left JOIN chance_data b on a.id =b.chance_id`
// //if public==protocol.pu
//
// sqlCount := fmt.Sprintf(`select count(0) from (
//select id from chance
//where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and enable_status=1
//order by create_at desc
//) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId)
// if err = utils.ExecuteQueryOne(&total, sqlCount, cid); err != nil {
// return
// }
// if v != nil {
// if err = utils.ExecuteQueryAll(v, sql, cid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize); err != nil {
// return
// }
// }
return
}
//type3 特定部门机会
func ValidChanceSpecialDepartment(uid, chanceIds string, v interface{}) (err error) {
sql := fmt.Sprintf(`
select * from (
##指定部门-机会提交的部门
##select chance_id from chance
##where id in (v) and department_id in (v)
##UNION
##本人
##select chance_id from chance
##where user_id = v and id in (v)
##UNION
##我审核
select DISTINCT chance_id from audit_flow_process where uid =%v and chance_id in (%v)
)
`, chanceIds)
if v != nil {
if err = utils.ExecuteQueryAll(v, sql); err != nil {
return
}
}
return
}
//type2 对我所在部门公开的机会 公司公开的机会
func ValidtChancePublicCompany(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) {
sql := fmt.Sprintf(`
select a.*,b.images,speechs,videos from (
select * from (
##公司公开的机会
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from chance
where company_id = %v and publish_status = 2
UNION
##指定部门-机会公开的部门
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from (
select DISTINCT chance_id from chance_department where department_id in (%v)
)a inner join chance b on a.chance_id = b.id
UNION
##本人
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from chance
where user_id = %v
UNION
##我审核
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from (
select DISTINCT chance_id from audit_flow_process where uid =%v
) a inner join chance b on a.chance_id = b.id
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or id<%v) and a.enable_status=1
order by create_at desc
limit %v
) a left JOIN chance_data b on a.id =b.chance_id
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize)
sqlCount := fmt.Sprintf(`
select count(0) from (
##公司公开的机会
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from chance
where company_id = %v and publish_status = 2
UNION
##指定部门-机会公开的部门
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from (
select DISTINCT chance_id from chance_department where department_id in (%v)
)a inner join chance b on a.chance_id = b.id
UNION
##本人
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from chance
where user_id = %v
UNION
##我审核
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from (
select DISTINCT chance_id from audit_flow_process where uid =%v
) a inner join chance b on a.chance_id = b.id
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId)
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
return
}
if v != nil {
if err = utils.ExecuteQueryAll(v, sql); err != nil {
return
}
}
return
}
//type1 禁止查看所有机会
func ValidChanceMyself(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`
select a.*,b.images,speechs,videos from (
select * from (
##本人
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from chance
where user_id = %v
UNION
##我审核
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from (
select DISTINCT chance_id from audit_flow_process where uid =%v
) a inner join chance b on a.chance_id = b.id
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or id<%v) and a.enable_status=1
order by create_at desc
limit %v
) a left JOIN chance_data b on a.id =b.chance_id
`, uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize)
sqlCount := fmt.Sprintf(`
select count(0) from (
##本人
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from chance
where user_id = %v
UNION
##我审核
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from (
select DISTINCT chance_id from audit_flow_process where uid =%v
) a inner join chance b on a.chance_id = b.id
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1
`, uid, uid, chanceTypeId, chanceTypeId)
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
return
}
if v != nil {
if err = utils.ExecuteQueryAll(v, sql); err != nil {
return
}
}
return
}
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/models"
"opp/protocol"
)
//机会池
... ... @@ -41,3 +42,47 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int,
}
return
}
func GetChanceValidPermission(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, items []protocol.CommonListItem) (total int, err error) {
var (
check int
specialDIds []int64
userDIds []int64
chanceIds []int64
)
if op, e := GetUserPermission(uid); e == nil {
for i := range op.CheckOption.Departments {
specialDIds = append(specialDIds, op.CheckOption.Departments[i].Id)
}
check = op.Check
}
if len(specialDIds) == 0 {
specialDIds = append(specialDIds, 0)
}
for i := range items {
chanceIds = append(chanceIds, items[i].Chance.Id) // 机会列表
}
//log.Debug(fmt.Sprintf("user:%v check:%v", uid, check))
for i := range items {
switch check {
case OpportunityCheckLv1:
if items[i].Chance.Provider.UserId == uid {
continue
}
case OpportunityCheckLv2:
if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil {
log.Error(err)
return
}
case OpportunityCheckLv3:
case OpportunityCheckLv4:
default:
}
}
return
}
... ...