123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- package client
- import (
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/go-xweb/xweb"
- "app.yhyue.com/moapp/jybase/mongodb"
- "cmplatform/util"
- "go.mongodb.org/mongo-driver/bson"
- "strings"
- "time"
- )
- type Client struct {
- *xweb.Action
- index xweb.Mapper `xweb:"/client/index"` //客户首页
- cuserRule xweb.Mapper `xweb:"/client/cuser/rule/list"` //规则列表 部门
- cuserRuleSetup xweb.Mapper `xweb:"/client/cuser/rule/setup"` //设置是否启用
- cuserRuleDel xweb.Mapper `xweb:"/client/cuser/rule/Del"` //删除规则
- departDel xweb.Mapper `xweb:"/client/depart/del"` //删除部门
- departEdit xweb.Mapper `xweb:"/client/depart/edit"` //保存和修改部门
- setupDepart xweb.Mapper `xweb:"/client/customer/setup"` //部门列表中启用、禁用
- cuserRuleEdit xweb.Mapper `xweb:"/client/cuser/rule/Edit"`
- //同步
- synEuser xweb.Mapper `xweb:"/client/cuser/synchronous"`
- }
- func (this *Client) Index() {
- id := this.GetString("id")
- query := map[string]interface{}{}
- query["_id"] = mongodb.StringTOBsonId(id)
- data, _ := util.Mgo.FindOneByField("cuser", query, `{}`)
- depart, _ := util.Mgo.Find("cuserdepart", map[string]interface{}{"s_userid": id, "b_delete": false}, nil, nil, false, -1, -1)
- (*data)["_id"] = mongodb.BsonIdToSId((*data)["_id"])
- // if (*data)["i_state"] == 1 {
- tagRule, _ := util.Mgo.Find("eusertagrule", map[string]interface{}{"s_userid": id, "b_delete": false}, nil, nil, false, -1, -1)
- this.T["tagrule"] = *tagRule
- appid := common.ObjToString((*data)["s_appid"])
- mails, _ := util.MgoCus.FindOneByField("user", map[string]interface{}{"appid": appid}, `{"mails":1,"username":1}`)
- this.T["mails"] = mails
- // }
- this.T["data"] = *data
- this.T["depart"] = *depart
- this.Render("/client/index.html")
- }
- // 对外客户部门规则列表
- func (c *Client) CuserRule() {
- defer common.Catch()
- ids := strings.Split(c.GetString("ids"), ",")
- if c.Method() == "POST" {
- start, _ := c.GetInt("start")
- limit, _ := c.GetInt("length")
- draw, _ := c.GetInt("draw")
- searchStr := c.GetString("search[value]")
- search := strings.TrimSpace(searchStr)
- query := bson.M{
- "s_userid": ids[1],
- "s_departid": ids[0],
- "b_delete": false,
- }
- if search != "" {
- query["$or"] = []interface{}{
- bson.M{"s_name": bson.M{"$regex": search}},
- }
- }
- data, _ := util.Mgo.Find("cuserdepartrule", query, `{"i_createtime":-1}`, nil, false, int(start), int(limit))
- count := util.Mgo.Count("cuserdepartrule", query)
- c.ServeJson(map[string]interface{}{
- "draw": draw,
- "data": data,
- "recordsFiltered": count,
- "recordsTotal": count,
- })
- } else {
- c.T["did"] = ids[0] //部门id
- c.T["cid"] = ids[1] //客户id
- users, ok := util.Mgo.FindOne("cuser", map[string]interface{}{"_id": mongodb.StringTOBsonId(ids[1]), "b_delete": false})
- downloadRule := 0
- if users != nil && ok {
- downloadRule = common.IntAll((*users)["i_downloadRule"])
- }
- c.T["i_downloadRule"] = downloadRule // 导出规则开关
- c.T["preview_href"] = util.PreviewHref
- c.Render("client/cuser_rule_list.html", &c.T)
- }
- }
- // 对外客户部门规则设置是否启用
- func (c *Client) CuserRuleSetup() {
- defer common.Catch()
- if c.Method() == "POST" {
- _id := c.GetString("_id")
- i_isuse, _ := c.GetInt("i_isuse")
- set := bson.M{
- "$set": bson.M{
- "i_isuse": i_isuse,
- },
- }
- b := util.Mgo.UpdateById("cuserdepartrule", _id, set)
- c.ServeJson(map[string]interface{}{
- "rep": b,
- })
- }
- }
- // 对外客户删除 部门规则
- func (c *Client) CuserRuleDel() {
- defer common.Catch()
- _id := c.GetString("_id")
- set := bson.M{
- "$set": bson.M{
- "b_delete": true,
- },
- }
- b := util.Mgo.UpdateById("cuserdepartrule", _id, set)
- c.ServeJson(map[string]interface{}{
- "rep": b,
- })
- }
- // 删除部门
- func (c *Client) DepartDel() {
- defer common.Catch()
- _id := c.GetString("id")
- ids := strings.Split(_id, ",")
- update := [][]map[string]interface{}{}
- for _, v := range ids {
- query := bson.M{
- "s_departid": v,
- "b_delete": false,
- }
- count := util.Mgo.Count("cuserdepartrule", query)
- if count > 0 {
- c.ServeJson(map[string]interface{}{
- "rep": false,
- "rea": false,
- })
- return
- } else {
- idAndSet := []map[string]interface{}{}
- idAndSet = append(idAndSet, bson.M{"_id": mongodb.StringTOBsonId(v)}) //查询条件
- idAndSet = append(idAndSet, bson.M{"$set": bson.M{"b_delete": true}}) //修改的数据
- update = append(update, idAndSet)
- /*update = append(update, []map[string]interface{}{
- map[string]interface{}{
- "_id": mongodb.StringTOBsonId(v),
- },
- map[string]interface{}{
- "$set": map[string]interface{}{
- "b_delete": true,
- },
- },
- })*/
- }
- }
- b := util.Mgo.UpdateBulk("cuserdepart", update...)
- c.ServeJson(map[string]interface{}{
- "rep": b,
- })
- }
- // 保存部门
- func (c *Client) DepartEdit() {
- defer common.Catch()
- data := util.GetPostForm(c.Request)
- id := common.ObjToString(data["id"])
- var b = true
- if id == "" {
- data["i_createtime"] = time.Now().Unix()
- data["i_updatetime"] = time.Now().Unix()
- data["b_delete"] = false
- _id := util.Mgo.Save("cuserdepart", data)
- if _id == "" {
- b = false
- }
- } else {
- set := bson.M{
- "$set": data,
- }
- data["i_updatetime"] = time.Now().Unix()
- b = util.Mgo.UpdateById("cuserdepart", id, set)
- }
- c.ServeJson(map[string]interface{}{
- "rep": b,
- })
- }
- // 部门启用、停用
- func (c *Client) SetupDepart() {
- defer common.Catch()
- if c.Method() == "POST" {
- _id := c.GetString("_id")
- i_isuse, _ := c.GetInt("i_isuse")
- nowtime := time.Now().Unix()
- set := bson.M{
- "$set": bson.M{
- "i_updatetime": nowtime,
- "i_isuse": i_isuse,
- },
- }
- b := util.Mgo.UpdateById("cuserdepart", _id, set)
- if b {
- //部门下的规则
- update := [][]map[string]interface{}{}
- ruleMap, _ := util.Mgo.Find("cuserdepartrule", bson.M{"s_userid": _id}, nil, nil, false, -1, -1)
- for _, v := range *ruleMap {
- idAndSet := []map[string]interface{}{}
- idAndSet = append(idAndSet, bson.M{"_id": v["_id"]}) //查询条件
- idAndSet = append(idAndSet, bson.M{"i_isuse": i_isuse, "i_updatetime": nowtime}) //修改的数据
- update = append(update, idAndSet)
- }
- b = util.Mgo.UpdateBulk("cuserdepartrule", update...)
- }
- c.ServeJson(map[string]interface{}{
- "rep": b,
- })
- }
- }
- // 点击规则列表中编辑按钮
- func (c *Client) CuserRuleEdit() {
- defer common.Catch()
- id := c.GetString("id")
- query := bson.M{"_id": mongodb.StringTOBsonId(id)}
- data, _ := util.Mgo.FindOneByField("cuserdepartrule", query, `{}`)
- (*data)["id"] = mongodb.BsonIdToSId((*data)["_id"])
- userData, _ := util.Mgo.FindById("cuser", common.ObjToString((*data)["s_userid"]), nil)
- (*data)["i_exact"] = (*userData)["i_exact"]
- c.T["cid"] = (*data)["s_userid"]
- c.T["ids"] = common.ObjToString((*data)["s_departid"]) + "," + common.ObjToString((*data)["s_userid"])
- c.T["data"] = *data
- c.T["province"] = util.Province
- c.T["city"] = util.ProvinceCitys
- c.T["district"] = util.CityDistricts
- c.T["topTypeArr"] = util.TopTypeArr
- c.T["subTypeArr"] = util.SubTypeArr
- c.T["matchTypeMap"] = util.MatchTypeMap
- c.T["matchTypeMap2"] = util.MatchTypeMap2
- c.T["existField"] = util.ExistFiled
- c.T["buyerClass"] = util.BuyerClass
- c.T["buyerClassMap"] = util.BuyerClassMap
- c.T["scopeClass"] = util.ScopeClassMap
- c.Render("client/cuser_rule_edit.html", &c.T)
- }
- // 同步
- func (c *Client) SynEuser() {
- defer common.Catch()
- _id := c.GetString("_id")
- cuser, _ := util.Mgo.FindById("cuser", _id, nil)
- nowTime := time.Now().Unix()
- (*cuser)["i_lastsynctime"] = nowTime //同步时间
- set := bson.M{
- "$set": bson.M{
- "i_lastsynctime": nowTime,
- },
- }
- b := util.Mgo.Update("cuser", bson.M{"_id": mongodb.StringTOBsonId(_id)}, set, false, false)
- if !b {
- c.ServeJson(map[string]interface{}{
- "rep": b,
- })
- return
- }
- delete(*cuser, "_id")
- b = util.Mgo.Update("euser", bson.M{"_id": mongodb.StringTOBsonId(_id)}, bson.M{"$set": *cuser}, true, false)
- if !b {
- c.ServeJson(map[string]interface{}{
- "rep": b,
- })
- return
- }
- departMap, _ := util.Mgo.Find("cuserdepart", bson.M{"s_userid": _id}, nil, nil, false, -1, -1)
- //util.Mgo.SaveBulk("euserdepart", *departMap...)
- for _, v := range *departMap {
- if count := util.Mgo.Count("euserdepart", map[string]interface{}{"_id": v["_id"]}); count > 0 {
- util.Mgo.Update("euserdepart", map[string]interface{}{"_id": v["_id"]}, map[string]interface{}{"$set": v}, false, false)
- } else {
- util.Mgo.SaveByOriID("euserdepart", v)
- }
- }
- ruleMap, _ := util.Mgo.Find("cuserdepartrule", bson.M{"s_userid": _id}, nil, nil, false, -1, -1)
- for _, v := range *ruleMap {
- if count := util.Mgo.Count("euserdepartrule", map[string]interface{}{"_id": v["_id"]}); count > 0 {
- util.Mgo.Update("euserdepartrule", map[string]interface{}{"_id": v["_id"]}, map[string]interface{}{"$set": v}, false, false)
- } else {
- util.Mgo.SaveByOriID("euserdepartrule", v)
- }
- }
- c.ServeJson(map[string]interface{}{
- "rep": b,
- })
- }
|