package client import ( qu "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/encrypt" "app.yhyue.com/moapp/jybase/go-xweb/xweb" "app.yhyue.com/moapp/jybase/mongodb" "encoding/json" "fmt" "github.com/lauyoume/gopinyin" "go.mongodb.org/mongo-driver/bson" "regexp" . "seplatform/util" "strconv" "time" ) type Client struct { *xweb.Action index xweb.Mapper `xweb:"/client/index"` //客户首页 cuserRuleDel xweb.Mapper `xweb:"/client/rule/del"` //删除规则 adminIndex xweb.Mapper `xweb:"/admin/index"` //管理员首页 personnelIndex xweb.Mapper `xweb:"/personnel/index"` //员工首页 cuserRuleCreate xweb.Mapper `xweb:"/client/rule/create"` //新建规则 cuserRuleEdit xweb.Mapper `xweb:"/client/rule/edit"` //修改规则 exportLog xweb.Mapper `xweb:"/client/exportLog"` //导出页面 } var ( replaceField_detail = map[string]bool{`"title"`: true, `"projectname.pname"`: true} reg_detail = regexp.MustCompile("\"fields\":\\[([^]]*detail[^]]*)\\]") reg_single = regexp.MustCompile("\"query\":\"[^\"{:]\"") ) func (this *Client) AdminIndex() { defer qu.Catch() user := this.GetSession("user").(map[string]interface{}) entId := qu.IntAll(user["ent_id"]) // entUserId := qu.IntAll(user["id"]) // appid := qu.ObjToString(user["appid"]) // phone := qu.ObjToString(user["phone"]) entUserArr := JyMysql.Find("entniche_user", map[string]interface{}{"ent_id": entId, "export_power": 1}, "", "id desc", -1, -1) if entUserArr != nil && *entUserArr != nil && len(*entUserArr) > 0 { for _, v := range *entUserArr { userId := qu.IntAll(v["id"]) deptmentUser := JyMysql.FindOne("entniche_department_user", map[string]interface{}{"user_id": userId}, "dept_id", "") if deptmentUser != nil && *deptmentUser != nil { dId := qu.IntAll((*deptmentUser)["dept_id"]) v["departId"] = dId deptment := JyMysql.FindOne("entniche_department", map[string]interface{}{"id": dId}, "name", "") if deptment != nil && *deptment != nil { dName := qu.ObjToString((*deptment)["name"]) v["departName"] = dName } } v["id"] = encrypt.SE.EncodeString(strconv.Itoa(userId)) } this.T["entUserArr"] = *entUserArr } this.Render("/client/adminIndex.html") } func (this *Client) PersonnelIndex() { defer qu.Catch() id := this.GetString("id") if this.Method() == "POST" { start, _ := this.GetInt("start") limit, _ := this.GetInt("length") draw, _ := this.GetInt("draw") entUserId := 0 user := this.GetSession("user").(map[string]interface{}) if id == "" { entUserId = qu.IntAll(user["id"]) } else { entUserId, _ = strconv.Atoi(encrypt.SE.DecodeString(id)) } entId := qu.IntAll(user["ent_id"]) count := Mgo.Count("entniche_rule", map[string]interface{}{"entId": entId, "entUserId": entUserId}) entRuleArr, ok := Mgo.Find("entniche_rule", map[string]interface{}{"entId": entId, "entUserId": entUserId}, `{"_id":-1}`, nil, false, int(start), int(limit)) if ok && entRuleArr != nil && *entRuleArr != nil && len(*entRuleArr) > 0 { for _, v := range *entRuleArr { ruleid := mongodb.BsonIdToSId(v["_id"]) v["_id"] = encrypt.SE.EncodeString(ruleid) } this.ServeJson(map[string]interface{}{ "draw": draw, "data": *entRuleArr, "recordsFiltered": count, "recordsTotal": count, }) } else { this.ServeJson(map[string]interface{}{ "draw": draw, "data": nil, "recordsFiltered": 0, "recordsTotal": 0, }) } } else { this.T["id"] = id entUserId := 0 user := this.GetSession("user").(map[string]interface{}) if id == "" { entUserId = qu.IntAll(user["id"]) } else { entUserId, _ = strconv.Atoi(encrypt.SE.DecodeString(id)) } entId := qu.IntAll(user["ent_id"]) leftNumData := JyMysql.FindOne("user_account", map[string]interface{}{"user_id": entUserId, "ent_id": entId}, "left_num", "") left := 0 if leftNumData != nil && *leftNumData != nil { left = int((*leftNumData)["left_num"].(int64)) } this.T["left"] = left this.Render("/client/personnelIndex.html", &this.T) } } // 对外客户删除 部门规则 func (c *Client) CuserRuleDel() { defer qu.Catch() _id := c.GetString("_id") b := Mgo.Del("entniche_rule", map[string]interface{}{"_id": mongodb.StringTOBsonId(encrypt.SE.DecodeString(_id))}) c.ServeJson(map[string]interface{}{ "rep": b, }) } func (c *Client) CuserRuleCreate() { defer qu.Catch() if c.Method() == "POST" { user := c.GetSession("user").(map[string]interface{}) data := GetPostForm(c.Request) entstr := c.GetString("entUserId") entUserId, err := strconv.Atoi(entstr) if err != nil { entUserId = 0 } o_rules := []map[string]interface{}{} o_rulesStr := data["o_rules"].(string) json.Unmarshal([]byte(o_rulesStr), &o_rules) data["o_rules"] = o_rules id := qu.ObjToString(data["id"]) delete(data, "id") delete(data, "ids") if qu.IntAll(data["i_esquerytype"]) == 1 { //自动生成es esStr := Utiltags(data) data["s_esquery"] = esStr data["s_esquery_search"] = filter(esStr) } i_createtime := time.Now().Unix() data["i_updatetime"] = i_createtime data["s_updateuser"] = user["name"] var rep = false if id == "" { //新建 if entUserId == 0 { data["entUserId"] = qu.IntAll(user["id"]) } else { data["entUserId"] = entUserId } data["entId"] = qu.IntAll(user["ent_id"]) data["appid"] = qu.ObjToString(user["appid"]) data["i_createtime"] = i_createtime data["s_createuser"] = user["name"] s_namekey := gopinyin.Convert(qu.ObjToString(data["s_name"]), false) data["s_namekey"] = s_namekey data["b_delete"] = false data["s_dataid"] = SEPreview.EncodeString(fmt.Sprintf("%v", i_createtime) + s_namekey + fmt.Sprintln(user["ent_id"])) id = Mgo.Save("entniche_rule", data) if id != "" { rep = true } else { rep = false } } else { if entUserId == 0 { data["entUserId"] = qu.IntAll(user["id"]) } else { data["entUserId"] = entUserId } data["appid"] = qu.ObjToString(user["appid"]) data["entId"] = qu.IntAll(user["ent_id"]) query := bson.M{ "_id": mongodb.StringTOBsonId(id), } rep = Mgo.Update("entniche_rule", query, bson.M{"$set": data}, false, false) } c.ServeJson(map[string]interface{}{ "id": id, "rep": rep, "s_esquery": data["s_esquery"], "s_dataid": data["s_dataid"], }) } else { user := c.GetSession("user").(map[string]interface{}) c.T["did"] = user["ent_id"] c.T["cid"] = user["id"] entstr := encrypt.SE.DecodeString(c.GetString("entUserId")) c.T["entUserId"], _ = strconv.Atoi(entstr) c.T["province"] = Province c.T["city"] = ProvinceCitys c.T["district"] = CityDistricts c.T["topTypeArr"] = TopTypeArr c.T["subTypeArr"] = SubTypeArr c.T["matchTypeMap"] = MatchTypeMap c.T["matchTypeMap2"] = MatchTypeMap2 c.T["existField"] = ExistFiled c.T["buyerClass"] = BuyerClass c.T["buyerClassMap"] = BuyerClassMap c.T["scopeClass"] = ScopeClassMap c.T["preview_href"] = PreviewHref c.Render("client/cuser_rule_create.html", &c.T) } } func (c *Client) CuserRuleEdit() { defer qu.Catch() id := encrypt.SE.DecodeString(c.GetString("id")) query := bson.M{"_id": mongodb.StringTOBsonId(id)} data, _ := Mgo.FindOneByField("entniche_rule", query, `{}`) (*data)["id"] = mongodb.BsonIdToSId((*data)["_id"]) c.T["cid"] = (*data)["s_userid"] c.T["ids"] = qu.ObjToString((*data)["s_departid"]) + "," + qu.ObjToString((*data)["s_userid"]) c.T["data"] = *data c.T["province"] = Province c.T["city"] = ProvinceCitys c.T["district"] = CityDistricts c.T["topTypeArr"] = TopTypeArr c.T["subTypeArr"] = SubTypeArr c.T["matchTypeMap"] = MatchTypeMap c.T["matchTypeMap2"] = MatchTypeMap2 c.T["existField"] = ExistFiled c.T["buyerClass"] = BuyerClass c.T["buyerClassMap"] = BuyerClassMap c.T["scopeClass"] = ScopeClassMap c.T["preview_href"] = PreviewHref c.Render("client/cuser_rule_edit.html", &c.T) } func (this *Client) DataPreview() { this.Render("client/preview.html") } func (this *Client) ExportLog() { if this.Method() == "POST" { id, _ := this.GetInt("id") start, _ := this.GetInt("start") limit, _ := this.GetInt("length") draw, _ := this.GetInt("draw") sqls := fmt.Sprintf("select count(1) from user_expend_record where user_id = %d", id) count := JyMysql.CountBySql(sqls) if count > 0 { sql := fmt.Sprintf("select * from user_expend_record where user_id = %d order by id desc limit %d,%d", id, start, limit) exportLog := JyMysql.SelectBySql(sql) for _, v := range *exportLog { data := JyMysql.FindOne("entniche_export_log", map[string]interface{}{"id": v["export_id"]}, "user_name,export_num,deduct_num,download_url", "") if data != nil && *data != nil { v["export_num"] = (*data)["export_num"] v["deduct_num"] = (*data)["deduct_num"] v["download_url"] = (*data)["download_url"] v["user_name"] = (*data)["user_name"] } } this.ServeJson(map[string]interface{}{ "draw": draw, "data": *exportLog, "recordsFiltered": count, "recordsTotal": count, }) } else { this.ServeJson(map[string]interface{}{ "draw": draw, "data": nil, "recordsFiltered": 0, "recordsTotal": 0, }) } } else { id, _ := strconv.Atoi(encrypt.SE.DecodeString(this.GetString("id"))) this.T["id"] = id this.Render("client/exportLog.html", &this.T) } }