作者 yangfu

权限修改

... ... @@ -34,8 +34,14 @@ type Chance struct {
AuditLevel int `orm:"column(audit_level)" description:"当前审批步骤"`
ApproveTime time.Time `orm:"column(approve_time);type(timestamp)" description:"审批时间"`
Code string `orm:"column(code)" description:"机会编码 一级编码+二级编码"`
Status int8 `orm:"column(status)" description:"状态 1:开启 2:关闭 "`
}
const (
ChanceStatusOpen = 1 //开启
ChanceStatusClose = 2 //关闭
)
func (t *Chance) TableName() string {
return "chance"
}
... ... @@ -105,7 +111,7 @@ func DeleteChance(id int64) (err error) {
func GetChanceMyChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := `select a.*,b.images,speechs,videos
from (
select id,user_id,create_at,update_at,approve_time chance_approve_time,source_content,approve_data,review_status from chance
select id,user_id,create_at,update_at,approve_time chance_approve_time,source_content,approve_data,review_status,enable_status,status from chance
where user_id=? and company_id=? and review_status in (?) and (?=0 or id<?)
) a left JOIN chance_data b on a.id =b.chance_id
order by update_at desc
... ... @@ -129,7 +135,7 @@ where user_id=? and company_id=? and review_status in (%v)
func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
select a.*,b.user_id,b.source_content,b.enable_status,b.review_status,b.create_at,b.update_at,b.approve_time chance_approve_time from (
select a.*,b.user_id,b.source_content,b.enable_status,b.review_status,b.create_at,b.update_at,b.approve_time chance_approve_time,b.status from (
select id,approve_time,approve_data,uid,chance_id,approve_message,update_at process_create_time
from audit_flow_process where uid=? and enable_status =1 and review_status in (%v) and (?=0 or id<?)
)a left outer join chance b on a.chance_id = b.id
... ... @@ -152,7 +158,7 @@ from audit_flow_process where uid=? and enable_status =1 and review_status in (%
func GetChanceCollect(uid int64, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total,b.publish_status from (
select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total,b.publish_status,b.status from (
select id collect_id,source_id,update_at collect_time,chance_id from chance_favorite where (0=? or id<?) and user_id =? and enable_status=1
and source_type=1
and (mark_flag&2)>0
... ... @@ -175,7 +181,7 @@ limit ?`)
func GetChanceThumbUp(uid int64, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total,b.publish_status from (
select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total,b.publish_status,b.status from (
select id collect_id,source_id,update_at collect_time from chance_favorite where (0=? or id<?) and user_id =? and enable_status=1
and source_type=1
and (mark_flag&1)>0
... ...
... ... @@ -195,7 +195,8 @@ type ChanceItemOrm struct {
Videos string `orm:"column(videos)"`
ReviewStatus int `orm:"column(review_status)"` //审核状态 1:待审核 2:被退回 3:已通过
ApproveData string `json:"approveData"` //审核数据
ApproveData string `json:"approveData"` //审核数据
Status int `orm:"column(status)"` //状态 1:开启 2:关闭
}
/*MyApproveChance 我审核的机会*/
... ... @@ -221,6 +222,7 @@ type ChanceApproveItemOrm struct {
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
ReviewStatus int `orm:"column(review_status)"`
Status int `orm:"column(status)"`
Id int64 `orm:"column(id)"` //审核id
ApproveTime time.Time `orm:"column(approve_time)"`
... ... @@ -293,6 +295,7 @@ type ChanceCollectItemOrm struct {
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
PublishStatus int `orm:"column(publish_status)"` //公开状态
Status int `orm:"column(status)"`
//ApproveData string `json:"approveData"` //审核数据
TemplateId int `orm:"column(audit_template_id)"`
... ... @@ -321,6 +324,7 @@ type ChanceThumbUpItemOrm struct {
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
PublishStatus int `orm:"column(publish_status)"` //公开状态
Status int `orm:"column(status)"` //公开状态
//ApproveData string `json:"approveData"` //审核数据
TemplateId int `orm:"column(audit_template_id)"`
... ...
... ... @@ -373,6 +373,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
ReviewStatus: protocol.ReviewStatusAuditging,
DepartmentId: request.RelatedDepartment,
Code: fmt.Sprintf("%v%v", chanceType.Code, template.Code),
Status: models.ChanceStatusOpen,
}
//生成提交记录
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header.UserId, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
... ... @@ -536,7 +537,7 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
log.Info(fmt.Sprintf("机会编辑 is_publish:%v chance.review_status:%v 是否是本人:%v", request.IsPublish, chance.ReviewStatus, chance.UserId == header.UserId))
}
//1.需要验证角色权限 2是否是审核人 3.是否是本人
if chance.ReviewStatus != protocol.ReviewStatusPass { //chance.UserId != header.UserId
if chance.ReviewStatus != protocol.ReviewStatusPass && chance.UserId != header.UserId { //chance.UserId != header.UserId
err = protocol.NewErrWithMessage(5206)
log.Error(fmt.Sprintf("user:%v 无权限操作机会 chance:%v", header.UserId, chance.Id))
return
... ... @@ -1305,6 +1306,9 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
jsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
if chance.Status == models.ChanceStatusClose {
commItem.ChanceStatus = protocol.ChanceStatusClose
}
commItem.ReviewStatus = chance.ReviewStatus
if request.ReviewStatus == protocol.ReviewStatusPass {
var approveData protocol.ApproveData
... ... @@ -1410,11 +1414,13 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
chance := myChances[i]
commItem := protocol.CommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
}
if chance.Status == models.ChanceStatusClose {
commItem.ChanceStatus = protocol.ChanceStatusClose
} else {
}
if chance.ChanceUserId > 0 {
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(chance.ChanceUserId, header.CompanyId, err)
... ... @@ -1491,11 +1497,14 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect
commItem := &protocol.CommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
commItem.ChanceId = chance.ChanceId
if len(chance.SourceContent) == 0 { //机会删除
if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
}
if chance.Status == models.ChanceStatusClose { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
} else {
}
if chance.ChanceUserId > 0 {
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
... ... @@ -1515,6 +1524,7 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect
commItem.Chance = item
}
}
commItem.ReviewStatus = chance.ReviewStatus
{
var chanceData = protocol.ChanceData{
... ... @@ -1565,11 +1575,13 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp
commItem := &protocol.CommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
commItem.ChanceId = chance.ChanceId
if len(chance.SourceContent) == 0 { //机会删除
if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
}
if chance.Status == models.ChanceStatusClose { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
} else {
}
if chance.ChanceUserId > 0 {
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
... ... @@ -1921,6 +1933,13 @@ func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequ
}
//判断机会权限
if request.ChanceId > 0 {
if chance.Status == models.ChanceStatusClose || chance.EnableStatus == 0 { //机会关闭 / 删除
rsp.EditChance = 0
rsp.EditPublicStatus = 0
rsp.EditScore = 0
log.Debug(fmt.Sprintf("用户:%v chance_id:%v 机会关闭/删除 无权限", header.UserId, chance.Id))
return
}
if chance, err = models.GetChanceById(request.ChanceId); err != nil {
err = protocol.NewErrWithMessage(5101)
return
... ... @@ -1928,13 +1947,16 @@ func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequ
//本人
if chance.UserId == header.UserId {
//审核通过 或者 已经被人审核过 就不能编辑了
if len(chance.ApproveData) > 0 || chance.ReviewStatus == protocol.ReviewStatusPass {
if len(chance.ApproveData) > 0 && chance.ReviewStatus == protocol.ReviewStatusAuditging { //审批中 且有人审批 本人不可编辑
rsp.EditChance = 0
} else if chance.ReviewStatus == protocol.ReviewStatusAuditging { //未有人审核过
rsp.EditChance = 1
rsp.EditPublicStatus = 0
rsp.EditScore = 0
}
if chance.ReviewStatus == protocol.ReviewStatusPass {
rsp.EditScore = 1
}
return
} else {
if chance.ReviewStatus == protocol.ReviewStatusReturn { //退回的机会不可编辑
... ...
... ... @@ -357,7 +357,7 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance
commItem.Score = approveData.Score
}
}
if len(chance.Data) > 0 { //获取评分
if len(chance.Data) > 0 && chance.ReviewStatus == protocol.ReviewStatusPass { //获取评分
var msgData *protocol.MsgData
utils.JsonUnmarshal(chance.Data, &msgData)
commItem.Score = msgData.Score
... ... @@ -621,36 +621,39 @@ func H5AnnouncementSubmit(header *protocol.RequestHeader, request *protocol.Anno
err = protocol.NewErrWithMessage(2060)
return
}
//获取回答详情数据
if bulletinAnswer, err = models.GetBulletinQuestionAnswerBy(request.Id, int64(request.Uid)); err == nil {
bulletinAnswer.Answer = common.AssertJson(protocol.Answer{
EditContent: request.EditContent,
VoteResults: request.VoteResults,
})
bulletinAnswer.UpdateAt = time.Now()
if err = models.UpdateBulletinQuestionAnswerById(bulletinAnswer); err != nil {
return
}
return
}
orm := orm.NewOrm()
orm.Begin()
{
bulletinAnswer = &models.BulletinQuestionAnswer{
Answer: common.AssertJson(&protocol.Answer{
VoteResults: request.VoteResults,
var e error
//获取回答详情数据
if bulletinAnswer, e = models.GetBulletinQuestionAnswerBy(request.Id, int64(request.Uid)); e == nil {
bulletinAnswer.Answer = common.AssertJson(protocol.Answer{
EditContent: request.EditContent,
}),
BulletinId: bulletin.Id,
BulletinQuestionId: request.VoteId,
Uid: request.Uid,
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
if _, err = orm.Insert(bulletinAnswer); err != nil {
log.Error(err)
orm.Rollback()
return
VoteResults: request.VoteResults,
})
bulletinAnswer.UpdateAt = time.Now()
if e = models.UpdateBulletinQuestionAnswerById(bulletinAnswer); e != nil {
log.Error(e)
orm.Rollback()
return
}
} else {
bulletinAnswer = &models.BulletinQuestionAnswer{
Answer: common.AssertJson(&protocol.Answer{
VoteResults: request.VoteResults,
EditContent: request.EditContent,
}),
BulletinId: bulletin.Id,
BulletinQuestionId: request.VoteId,
Uid: request.Uid,
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
if _, err = orm.Insert(bulletinAnswer); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
}
{
... ...