作者 唐旭辉

调整

@@ -83,3 +83,33 @@ func (c *AuditController) AuditInfo() { @@ -83,3 +83,33 @@ func (c *AuditController) AuditInfo() {
83 msg = protocol.NewReturnResponse(list, err) 83 msg = protocol.NewReturnResponse(list, err)
84 return 84 return
85 } 85 }
  86 +
  87 +//AllowForbidAudit 开启、关闭 机会
  88 +//@router /v1/audit/allow_forbid
  89 +func (c *AuditController) AllowForbidAudit() {
  90 + var msg *protocol.ResponseMessage
  91 + defer func() {
  92 + c.ResposeJson(msg)
  93 + }()
  94 + type Parameter struct {
  95 + ChanceId string `json:"chance_id"`
  96 + Status int `json:"status"` //[1:开启机会][2:关闭机会]
  97 + }
  98 + var param Parameter
  99 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  100 + log.Error("json 解析失败", err)
  101 + msg = protocol.BadRequestParam("1")
  102 + return
  103 + }
  104 + chanceid, _ := strconv.ParseInt(param.ChanceId, 10, 64)
  105 + companyId := c.GetCompanyId()
  106 + var err error
  107 + switch param.Status {
  108 + case 1:
  109 + err = serveaudit.AllowChanceEnableStatus(chanceid, companyId)
  110 + case 2:
  111 + err = serveaudit.ForbidChanceEnableStatus(chanceid, companyId)
  112 + }
  113 + msg = protocol.NewReturnResponse(nil, err)
  114 + return
  115 +}
@@ -71,13 +71,13 @@ var ChanceReviewStatusMap = map[int]string{ @@ -71,13 +71,13 @@ var ChanceReviewStatusMap = map[int]string{
71 71
72 //有效状态 0:无效 1:有效 72 //有效状态 0:无效 1:有效
73 const ( 73 const (
74 - ChanceEnableStatusYes int = 1  
75 - ChanceEnableStatusNo int = 0 74 + ChanceEnableStatusYes int8 = 1
  75 + ChanceEnableStatusNo int8 = 0
76 ) 76 )
77 77
78 -var ChanceEnableStatusMap = map[int]string{  
79 - 0: "无效",  
80 - 1: "有效", 78 +var ChanceEnableStatusMap = map[int8]string{
  79 + ChanceEnableStatusNo: "无效",
  80 + ChanceEnableStatusYes: "有效",
81 } 81 }
82 82
83 // AddChance insert a new Chance into database and returns 83 // AddChance insert a new Chance into database and returns
@@ -239,6 +239,7 @@ type RequestAuditList struct { @@ -239,6 +239,7 @@ type RequestAuditList struct {
239 CreateTimeBegin int `json:"create_time_begin"` // 239 CreateTimeBegin int `json:"create_time_begin"` //
240 CreateTimeEnd int `json:"create_time_end"` // 240 CreateTimeEnd int `json:"create_time_end"` //
241 Code string `json:"code"` //机会编码 241 Code string `json:"code"` //机会编码
  242 + UserName string `json:"user_name"` //提交人姓名
242 } 243 }
243 244
244 type ResponseAuditList struct { 245 type ResponseAuditList struct {
@@ -248,8 +249,7 @@ type ResponseAuditList struct { @@ -248,8 +249,7 @@ type ResponseAuditList struct {
248 249
249 type RspAuditList struct { 250 type RspAuditList struct {
250 Id string `json:"id"` //机会的id 251 Id string `json:"id"` //机会的id
251 - TemplateCode string `json:"template_code"`  
252 - ChanceTypeCode string `json:"chance_type_code"` 252 + Code string `json:"code"`
253 ChanceType string `json:"chance_type"` //一级分类 253 ChanceType string `json:"chance_type"` //一级分类
254 TemplateName string `json:"template_name"` //二级分类 254 TemplateName string `json:"template_name"` //二级分类
255 UserName string `json:"user_name"` // 提交人 255 UserName string `json:"user_name"` // 提交人
@@ -259,7 +259,7 @@ type RspAuditList struct { @@ -259,7 +259,7 @@ type RspAuditList struct {
259 PublishStatusName string `json:"publish_status_name"` // 259 PublishStatusName string `json:"publish_status_name"` //
260 ReviewStatus int `json:"review_status"` //审批状态 260 ReviewStatus int `json:"review_status"` //审批状态
261 ReviewStatusName string `json:"review_status_name"` 261 ReviewStatusName string `json:"review_status_name"`
262 - EnableStatus int `json:"enable_status"` 262 + EnableStatus int8 `json:"enable_status"`
263 EnableStatusName string `json:"enable_status_name"` 263 EnableStatusName string `json:"enable_status_name"`
264 } 264 }
265 265
@@ -101,6 +101,7 @@ func init() { @@ -101,6 +101,7 @@ func init() {
101 beego.NSRouter("/list", &controllers.AuditController{}, "post:AuditList"), 101 beego.NSRouter("/list", &controllers.AuditController{}, "post:AuditList"),
102 beego.NSRouter("/list/before", &controllers.AuditController{}, "post:AuditListBefore"), 102 beego.NSRouter("/list/before", &controllers.AuditController{}, "post:AuditListBefore"),
103 beego.NSRouter("/info", &controllers.AuditController{}, "post:AuditInfo"), 103 beego.NSRouter("/info", &controllers.AuditController{}, "post:AuditInfo"),
  104 + beego.NSRouter("/allow_forbid", &controllers.AuditController{}, "post:AllowForbidAudit"),
104 ), 105 ),
105 ) 106 )
106 107
@@ -20,11 +20,10 @@ type SqlData struct { @@ -20,11 +20,10 @@ type SqlData struct {
20 PublishStatus int `orm:"column(publish_status)"` 20 PublishStatus int `orm:"column(publish_status)"`
21 CreateAt time.Time `orm:"column(create_at);type(timestamp)"` 21 CreateAt time.Time `orm:"column(create_at);type(timestamp)"`
22 ReviewStatus int `orm:"column(review_status)"` 22 ReviewStatus int `orm:"column(review_status)"`
23 - EnableStatus int `orm:"column(enable_status)"` 23 + EnableStatus int8 `orm:"column(enable_status)"`
24 DiscoveryScore string `orm:"column(discovery_score)"` 24 DiscoveryScore string `orm:"column(discovery_score)"`
25 CommentTotal string `orm:"column(comment_total)"` 25 CommentTotal string `orm:"column(comment_total)"`
26 Code string `orm:"column(code)"` 26 Code string `orm:"column(code)"`
27 - TemplateName string `orm:"column(template_name)"`  
28 } 27 }
29 28
30 func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64) (protocol.ResponseAuditList, error) { 29 func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64) (protocol.ResponseAuditList, error) {
@@ -46,13 +45,13 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 @@ -46,13 +45,13 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64
46 } 45 }
47 datasql.WriteString(`SELECT a.id,a.user_id,a.department_id,a.audit_template_id,a.chance_type_id 46 datasql.WriteString(`SELECT a.id,a.user_id,a.department_id,a.audit_template_id,a.chance_type_id
48 ,a.publish_status,a.create_at,a.review_status,a.enable_status 47 ,a.publish_status,a.create_at,a.review_status,a.enable_status
49 - ,a.discovery_score,a.comment_total,b.name AS template_name ,b.code 48 + ,a.discovery_score,a.comment_total ,a.code,d.nick_name
50 FROM chance AS a 49 FROM chance AS a
51 - JOIN audit_template AS b on a.audit_template_id = b.id 50 + JOIN user_company AS c ON c.id = a.user_id
  51 + JOIN user AS d ON c.user_id = d.id
52 where a.company_id=? `) 52 where a.company_id=? `)
53 53
54 - countsql.WriteString(`SELECT count(*) FROM chance as a  
55 - JOIN audit_template AS b on a.audit_template_id = b.id 54 + countsql.WriteString(`SELECT count(*) FROM chance as a
56 where a.company_id=? `) 55 where a.company_id=? `)
57 cond = append(cond, companyid) 56 cond = append(cond, companyid)
58 if param.ChanceTypeId > 0 { 57 if param.ChanceTypeId > 0 {
@@ -99,8 +98,14 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 @@ -99,8 +98,14 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64
99 countsql.WriteString(s) 98 countsql.WriteString(s)
100 } 99 }
101 if len(param.Code) > 0 { 100 if len(param.Code) > 0 {
102 - cond = append(cond, param.Code)  
103 - s := ` And b.code=? ` 101 + cond = append(cond, "%"+param.Code+"%")
  102 + s := ` And a.code like ? `
  103 + datasql.WriteString(s)
  104 + countsql.WriteString(s)
  105 + }
  106 + if len(param.UserName) > 0 {
  107 + cond = append(cond, "%"+param.UserName+"%")
  108 + s := ` And d.nick_name like ? `
104 datasql.WriteString(s) 109 datasql.WriteString(s)
105 countsql.WriteString(s) 110 countsql.WriteString(s)
106 } 111 }
@@ -129,8 +134,7 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 @@ -129,8 +134,7 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64
129 PublishStatusName: models.ChancePublishStatusMap[v.PublishStatus], 134 PublishStatusName: models.ChancePublishStatusMap[v.PublishStatus],
130 ReviewStatus: v.ReviewStatus, 135 ReviewStatus: v.ReviewStatus,
131 ReviewStatusName: models.ChanceReviewStatusMap[v.ReviewStatus], 136 ReviewStatusName: models.ChanceReviewStatusMap[v.ReviewStatus],
132 - TemplateCode: v.Code,  
133 - TemplateName: v.TemplateName, 137 + Code: v.Code,
134 } 138 }
135 139
136 if t < 0 { 140 if t < 0 {
@@ -146,7 +150,9 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64 @@ -146,7 +150,9 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64
146 } 150 }
147 if ct, err := models.GetChanceTypeById(v.ChanceTypeId); err == nil { 151 if ct, err := models.GetChanceTypeById(v.ChanceTypeId); err == nil {
148 item.ChanceType = ct.Name 152 item.ChanceType = ct.Name
149 - item.ChanceTypeCode = ct.Code 153 + }
  154 + if tp, err := models.GetAuditTemplateById(v.AuditTemplateId); err == nil {
  155 + item.TemplateName = tp.Name
150 } 156 }
151 returnData.List = append(returnData.List, item) 157 returnData.List = append(returnData.List, item)
152 158
@@ -268,3 +274,51 @@ func getAuditFlowLog(chanceid int64) ([]protocol.ChanceFlowLog, error) { @@ -268,3 +274,51 @@ func getAuditFlowLog(chanceid int64) ([]protocol.ChanceFlowLog, error) {
268 err = utils.ExecuteQueryAll(&flowLogs, datasql, chanceid) 274 err = utils.ExecuteQueryAll(&flowLogs, datasql, chanceid)
269 return flowLogs, err 275 return flowLogs, err
270 } 276 }
  277 +
  278 +func AllowChanceEnableStatus(chanceid int64, companyid int64) error {
  279 + var (
  280 + err error
  281 + chanceinfo *models.Chance
  282 + )
  283 + chanceinfo, err = models.GetChanceById(chanceid)
  284 + if err != nil {
  285 + log.Error("获取机会数据失败:%s", err)
  286 + return protocol.NewErrWithMessage("1")
  287 + }
  288 + if chanceinfo.CompanyId != companyid {
  289 + log.Error("机会的公司不匹配")
  290 + return protocol.NewErrWithMessage("1")
  291 + }
  292 + chanceinfo.EnableStatus = models.ChanceEnableStatusYes
  293 + chanceinfo.UpdateAt = time.Now()
  294 + err = models.UpdateChanceById(chanceinfo, []string{"EnableStatus", "UpdateAt"})
  295 + if err != nil {
  296 + log.Error("更新机会数据失败:%s", err)
  297 + return protocol.NewErrWithMessage("1")
  298 + }
  299 + return nil
  300 +}
  301 +
  302 +func ForbidChanceEnableStatus(chanceid int64, companyid int64) error {
  303 + var (
  304 + err error
  305 + chanceinfo *models.Chance
  306 + )
  307 + chanceinfo, err = models.GetChanceById(chanceid)
  308 + if err != nil {
  309 + log.Error("获取机会数据失败:%s", err)
  310 + return protocol.NewErrWithMessage("1")
  311 + }
  312 + if chanceinfo.CompanyId != companyid {
  313 + log.Error("机会的公司不匹配")
  314 + return protocol.NewErrWithMessage("1")
  315 + }
  316 + chanceinfo.EnableStatus = models.ChanceEnableStatusNo
  317 + chanceinfo.UpdateAt = time.Now()
  318 + err = models.UpdateChanceById(chanceinfo, []string{"EnableStatus", "UpdateAt"})
  319 + if err != nil {
  320 + log.Error("更新机会数据失败:%s", err)
  321 + return protocol.NewErrWithMessage("1")
  322 + }
  323 + return nil
  324 +}
@@ -495,3 +495,9 @@ func SmsCodeCheck(phone string, code string) error { @@ -495,3 +495,9 @@ func SmsCodeCheck(phone string, code string) error {
495 redisdata.SetCaptchAuth(phone, resp.Data.CaptchaCertificate) 495 redisdata.SetCaptchAuth(phone, resp.Data.CaptchaCertificate)
496 return nil 496 return nil
497 } 497 }
  498 +
  499 +//InitPermission 登录时权限初始化
  500 +func InitPermission(usercompanyid int, userid int64) error {
  501 + // datasql = ``
  502 + return nil
  503 +}
@@ -94,7 +94,7 @@ type CheckOpp struct { @@ -94,7 +94,7 @@ type CheckOpp struct {
94 //OptionOpportunity 机会管理 高级权限设置 94 //OptionOpportunity 机会管理 高级权限设置
95 type OptionOpportunity struct { 95 type OptionOpportunity struct {
96 Check int `json:"check"` 96 Check int `json:"check"`
97 - CheckMap map[int]int `json:"-"` 97 + CheckMap map[int]int `json:"check_map,omitempty"`
98 CheckOption CheckOpp `json:"check_option"` 98 CheckOption CheckOpp `json:"check_option"`
99 EditSorce int `json:"edit_sorce"` 99 EditSorce int `json:"edit_sorce"`
100 EditPublicStatus int `json:"edit_public_status"` 100 EditPublicStatus int `json:"edit_public_status"`