|
@@ -5,558 +5,137 @@
|
|
|
package member
|
|
|
|
|
|
import (
|
|
|
+ "encoding/hex"
|
|
|
"fmt"
|
|
|
- "github.com/bluemonday-master"
|
|
|
"github.com/go-xweb/xweb"
|
|
|
"gopkg.in/mgo.v2/bson"
|
|
|
"log"
|
|
|
"net/http"
|
|
|
coreconfig "qfw/coreconfig"
|
|
|
- "qfw/coreutil"
|
|
|
- "qfw/redpackage"
|
|
|
"qfw/util"
|
|
|
"qfw/util/credit"
|
|
|
"qfw/util/elastic"
|
|
|
. "qfw/util/fsw"
|
|
|
"qfw/util/mongodb"
|
|
|
- msg "qfw/util/msg"
|
|
|
+ mongodbutil "qfw/util/mongodbutil"
|
|
|
"qfw/util/redis"
|
|
|
- qrpc "qfw/util/rpc"
|
|
|
yps "qfw/yellowpage"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-type K map[string]interface{}
|
|
|
type Yellowpage struct {
|
|
|
*xweb.Action
|
|
|
- editEnterprise xweb.Mapper `xweb:"/member/yellowpage/edit/enterprise/(\\w+)"` //编辑
|
|
|
- dosave xweb.Mapper `xweb:"/member/yellowpage/dosave/enterprise"` //保存企业黄页信息
|
|
|
- showEnterprise xweb.Mapper `xweb:"/member/yellowpage/show/enterprise/(\\w+)"` //显示企黄页信息
|
|
|
- showService xweb.Mapper `xweb:"/member/yellowpage/show/showService/(\\w+)"` //显示添加服务页面
|
|
|
- editService xweb.Mapper `xweb:"/member/yellowpage/edit/showService/(\\w+)"` //编辑服务页面
|
|
|
- upLoadEntImg xweb.Mapper `xweb:"POST /member/yellowpage/upLoadEntImg"` //上传企业相关图片
|
|
|
+ editEnterprise xweb.Mapper `xweb:"/member/enterprise/edit"` //编辑
|
|
|
+ showEnterprise xweb.Mapper `xweb:"/member/enterprise/show"` //显示企黄页信息
|
|
|
+ save xweb.Mapper `xweb:"/member/enterprise/save"` //保存企业黄页信息
|
|
|
+ upLoadEntImg xweb.Mapper `xweb:"POST /member/enterprise/upLoadEntImg"` //上传企业相关图片
|
|
|
+ follow xweb.Mapper `xweb:"POST /member/enterprise/follow"` //关注企业
|
|
|
+ wxFollow xweb.Mapper `xweb:"POST /wx/member/enterprise/follow"` //手机关注企业
|
|
|
+ isFollowed xweb.Mapper `xweb:"POST /member/enterprise/isFollowed"` //查询关注状态
|
|
|
+ entCount xweb.Mapper `xweb:"POST /member/enterprise/entcount"` //查询关注企业数量
|
|
|
|
|
|
- addService xweb.Mapper `xweb:"/member/yellowpage/add/service/addservice"` //增加服务
|
|
|
- delservice xweb.Mapper `xweb:"POST /member/service/delservice"` //删除数据
|
|
|
- findservice xweb.Mapper `xweb:"POST /member/service/findservice"` //查找要修改数据
|
|
|
- removeservice xweb.Mapper `xweb:"POST /member/service/removeservice"` //下架服务
|
|
|
}
|
|
|
|
|
|
const ESTYPE string = "enterprise"
|
|
|
|
|
|
-//修改前找到此服务
|
|
|
-func (u *Yellowpage) Findservice() error {
|
|
|
- if u.Method() == "POST" {
|
|
|
- id := u.GetString("id")
|
|
|
- res := map[string]interface{}{}
|
|
|
- res["data"] = mongodb.FindById("service", id, `{"id":0}`)
|
|
|
- u.ServeJson(&res)
|
|
|
- }
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-//删除服务
|
|
|
-func (u *Yellowpage) Delservice() error {
|
|
|
- if u.Method() == "POST" {
|
|
|
- if checkuser(u) == false {
|
|
|
- u.ServeJson(&map[string]interface{}{
|
|
|
- "msg": "用户没有通过审核",
|
|
|
- })
|
|
|
- return nil
|
|
|
- }
|
|
|
- //判断是否能删除
|
|
|
- id := u.GetString("id")
|
|
|
- entid := u.GetSession("entid")
|
|
|
- index := "service"
|
|
|
- itype := "service"
|
|
|
- query := &map[string]interface{}{
|
|
|
- "_id": bson.ObjectIdHex(id),
|
|
|
- "s_enterpriseid": entid,
|
|
|
- }
|
|
|
- //先删除mongodb中数据
|
|
|
- b, _ := CheckAuth(K{"_id": id})
|
|
|
-
|
|
|
- if b == false {
|
|
|
- u.ServeJson(&map[string]interface{}{
|
|
|
- "msg": "删除失败,请确定没有未处理的预约以及用户都已评论!",
|
|
|
- })
|
|
|
- return nil
|
|
|
- }
|
|
|
- flag := mongodb.Del("service", query)
|
|
|
- if flag {
|
|
|
- //再删除elasticsearch中的数据
|
|
|
- redis.DelByCodePattern("enterprise", "service-"+entid.(string)+"-*")
|
|
|
- flag2 := elastic.DelById(index, itype, id)
|
|
|
- if flag2 {
|
|
|
- u.ServeJson(&map[string]interface{}{
|
|
|
- "msg": "删除服务成功!",
|
|
|
- })
|
|
|
-
|
|
|
- } else {
|
|
|
- u.ServeJson(&map[string]interface{}{
|
|
|
- "msg": "删除服务失败!",
|
|
|
- })
|
|
|
- }
|
|
|
- //Insertservicenames(entid.(string))
|
|
|
- } else {
|
|
|
- u.ServeJson(&map[string]interface{}{
|
|
|
- "msg": "删除服务失败!",
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-//下架服务
|
|
|
-func (u *Yellowpage) Removeservice() error {
|
|
|
- if u.Method() == "POST" {
|
|
|
- //判断用户是否审核通过
|
|
|
- if checkuser(u) == false {
|
|
|
- u.ServeJson(&map[string]interface{}{
|
|
|
- "msg": "用户没有通过审核",
|
|
|
- })
|
|
|
- return nil
|
|
|
- }
|
|
|
- //判断是否能下架
|
|
|
- id := u.GetString("id")
|
|
|
- entid := u.GetSession("entid")
|
|
|
- index := "service"
|
|
|
- itype := "service"
|
|
|
- query := &map[string]interface{}{
|
|
|
- "_id": bson.ObjectIdHex(id),
|
|
|
- "s_enterpriseid": entid,
|
|
|
- }
|
|
|
- //先删除mongodb中数据
|
|
|
- b, _ := CheckAuth(K{"_id": id})
|
|
|
-
|
|
|
- if b == false {
|
|
|
- u.ServeJson(&map[string]interface{}{
|
|
|
- "msg": "下架失败,请确定没有未处理的预约以及用户都已评论!",
|
|
|
- })
|
|
|
- return nil
|
|
|
- }
|
|
|
- obj := *mongodb.FindOne("service", query)
|
|
|
- if len(obj) > 0 {
|
|
|
- sid := strings.Split(fmt.Sprintf("%s", obj["_id"]), `"`)[1]
|
|
|
- flag := mongodb.Update("service", `{"_id":"`+sid+`"}`, bson.M{"$set": bson.M{"i_status": 1}}, false, false)
|
|
|
- if flag {
|
|
|
- redis.DelByCodePattern("enterprise", "service-"+entid.(string)+"-*")
|
|
|
- //修改elasticsearch中的数据
|
|
|
- isUpdate := elastic.UpdateNewDoc(index, itype, mongodb.FindById("service", sid, nil))
|
|
|
-
|
|
|
- if isUpdate {
|
|
|
- u.ServeJson(&map[string]interface{}{
|
|
|
- "msg": "下架成功!",
|
|
|
- })
|
|
|
-
|
|
|
- } else {
|
|
|
- u.ServeJson(&map[string]interface{}{
|
|
|
- "msg": "下架服务失败!",
|
|
|
- })
|
|
|
- }
|
|
|
- //Insertservicenames(entid.(string))
|
|
|
- } else {
|
|
|
- u.ServeJson(&map[string]interface{}{
|
|
|
- "msg": "下架服务失败!",
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-//编辑企业黄页的信息
|
|
|
-func (yp *Yellowpage) EditEnterprise(id string) error {
|
|
|
- //判断用户是否登录,如果没有登录直接返回首页
|
|
|
- if yp.GetSession("userId") == nil {
|
|
|
- return yp.Redirect("/")
|
|
|
- }
|
|
|
- id = strings.Split(id, "#")[0]
|
|
|
-
|
|
|
- yp.T["entinfo"] = yps.GetEntInfo(id)
|
|
|
-
|
|
|
- yp.T["entid"] = id
|
|
|
-
|
|
|
- return yp.Render("/member/editenterprise.html", &yp.T)
|
|
|
-}
|
|
|
-
|
|
|
-//保存企业黄页的信息
|
|
|
-func (yp *Yellowpage) Dosave() error {
|
|
|
- var info string = "保存成功"
|
|
|
- var status string = "y"
|
|
|
- //判断用户是否登录,如果没有登录直接返回首页
|
|
|
- if yp.GetSession("userId") == nil {
|
|
|
- return yp.Redirect("/")
|
|
|
+func (u *Yellowpage) EntCount() {
|
|
|
+ sessionId := u.GetSession("userId")
|
|
|
+ if sessionId == "" {
|
|
|
+ u.ServeJson("0")
|
|
|
+ } else {
|
|
|
+ log.Println(sessionId)
|
|
|
+ c := *mongodb.Find("follow_enterprise", bson.M{"s_userid": sessionId}, nil, nil, false, -1, -1)
|
|
|
+ u.ServeJson(len(c))
|
|
|
}
|
|
|
|
|
|
- data := make(map[string]interface{})
|
|
|
-
|
|
|
- var entid string = yp.GetString("id")
|
|
|
- //过滤XSS
|
|
|
- s_synopsis := Repl(yp.GetStringComm("s_synopsis"))
|
|
|
-
|
|
|
- html := strings.ToLower(s_synopsis)
|
|
|
- p := bluemonday.UGCPolicy()
|
|
|
- p.AllowElements("s", "blockquote", "sup", "sub", "ol", "li", "ul", "b", "div", "strong", "p", "table", "span", "em", "u", "td", "tr", "tbody", "th", "thead", "i")
|
|
|
- p.AllowAttrs("style", "align", "width", "height").OnElements("s", "blockquote", "sup", "sub", "ol", "li", "ul", "b", "div", "strong", "p", "table", "span", "em", "u", "td", "tr", "tbody", "th", "thead", "i")
|
|
|
-
|
|
|
- html = p.Sanitize(html)
|
|
|
- s_synopsis = html
|
|
|
-
|
|
|
- data["s_synopsis"] = s_synopsis
|
|
|
-
|
|
|
- data["s_persion"] = Repl(yp.GetString("s_persion"))
|
|
|
- data["s_mobile"] = Repl(yp.GetString("s_mobile"))
|
|
|
- data["s_enturl"] = Repl(yp.GetString("s_enturl"))
|
|
|
- data["s_qq"] = Repl(yp.GetString("s_qq"))
|
|
|
- data["s_weixin"] = Repl(yp.GetString("s_weixin"))
|
|
|
- province, _ := yp.GetInt("province")
|
|
|
- data["i_province"] = province
|
|
|
- city, _ := yp.GetInt("city")
|
|
|
- data["i_city"] = city
|
|
|
- area, _ := yp.GetInt("area")
|
|
|
- data["i_area"] = area
|
|
|
- data["s_address"] = Repl(yp.GetString("s_address"))
|
|
|
-
|
|
|
- dataSet := map[string]interface{}{
|
|
|
- "$set": data,
|
|
|
- }
|
|
|
- //向mongodb库中写数据
|
|
|
- flag := mongodb.Update(ESTYPE, "{'_id':'"+entid+"'}", &dataSet, false, false)
|
|
|
- redis.Del("enterprise", "enterpriseInfo_"+entid)
|
|
|
- redis.Del("enterprise", "enterpriseInfo_user_"+entid)
|
|
|
- elastic.UpdateEntDoc(entid)
|
|
|
- redis.DelByCodePattern("enterprise", "ipcity_*")
|
|
|
- if !flag {
|
|
|
- status = "n"
|
|
|
- info = "保存信息失败"
|
|
|
- } else { //首次创建企业名片,送积分
|
|
|
- if !credit.AIsHasDo(credit.A_CJMP, util.Int64All(yp.GetSession("credit_a"))) {
|
|
|
- credit.UpuserCreditSession(util.ObjToString(yp.GetSession("userId")), credit.A_CJMP, "A", nil, yp.Action)
|
|
|
- }
|
|
|
- }
|
|
|
- return yp.Write("{\"info\":\"" + info + "\",\"status\":\"" + status + "\"}")
|
|
|
}
|
|
|
|
|
|
-//用户登录后转到黄页选择模板与编辑黄页界面
|
|
|
-func (yp *Yellowpage) ShowEnterprise(id string) error {
|
|
|
- if yp.GetSession("userId") == nil {
|
|
|
- return yp.Redirect("/")
|
|
|
- }
|
|
|
+//我的黄页
|
|
|
+func (yp *Yellowpage) ShowEnterprise() error {
|
|
|
//判断用户是否审核通过
|
|
|
if checkuser(yp) == false {
|
|
|
return yp.Redirect("/member/accountset/index", http.StatusFound)
|
|
|
}
|
|
|
- id = strings.Split(id, "#")[0]
|
|
|
-
|
|
|
- yp.T["entinfo"] = yps.GetEntInfo(id)
|
|
|
-
|
|
|
- yp.T["entid"] = id
|
|
|
- yp.T["serviceClassify"] = coreconfig.ServiceClassify
|
|
|
-
|
|
|
- opLocD := yp.GetSession("opLocDistrict")
|
|
|
- yp.T["opLocDistrict"] = opLocD
|
|
|
- return yp.Render("/member/showenterprise.html", &yp.T)
|
|
|
+ return yps.CommonEntInfo(yp.Action, yp.GetSession("entid").(string), 1, false)
|
|
|
}
|
|
|
|
|
|
-//显示增加编辑服务页面
|
|
|
-func (yp *Yellowpage) ShowService(id string) error {
|
|
|
- //判断用户是否登录,如果没有登录直接返回首页
|
|
|
- if yp.GetSession("userId") == nil {
|
|
|
- return yp.Redirect("/")
|
|
|
- }
|
|
|
- yp.T["entid"] = id
|
|
|
- yp.T["serviceName"] = "添加产品服务信息"
|
|
|
- yp.T["serviceClassify"] = coreconfig.ServiceClassify
|
|
|
-
|
|
|
- yp.T["entinfo"] = yps.GetEntInfo(id)
|
|
|
- opLocD := yp.GetSession("opLocDistrict")
|
|
|
- yp.T["opLocDistrict"] = opLocD
|
|
|
- return yp.Render("/member/editservice.html", &yp.T)
|
|
|
-}
|
|
|
-
|
|
|
-//编辑服务页面
|
|
|
-func (yp *Yellowpage) EditService(id string) error {
|
|
|
- //判断用户是否登录,如果没有登录直接返回首页
|
|
|
- if yp.GetSession("userId") == nil {
|
|
|
- return yp.Redirect("/")
|
|
|
- }
|
|
|
+//编辑企业黄页的信息
|
|
|
+func (yp *Yellowpage) EditEnterprise() error {
|
|
|
//判断用户是否审核通过
|
|
|
if checkuser(yp) == false {
|
|
|
return yp.Redirect("/member/accountset/index", http.StatusFound)
|
|
|
}
|
|
|
- yp.T["serviceName"] = "编辑产品服务信息"
|
|
|
- yp.T["serviceClassify"] = coreconfig.ServiceClassify
|
|
|
-
|
|
|
- opLocD := yp.GetSession("opLocDistrict")
|
|
|
- yp.T["opLocDistrict"] = opLocD
|
|
|
-
|
|
|
- res := mongodb.FindById("service", id, `{"id":0}`)
|
|
|
- //res["f_price"] = fmt.Sprintf("%.2f", res["f_price"])
|
|
|
- yp.T["service"] = &res
|
|
|
- tmp := (*res)
|
|
|
- serentid := tmp["s_enterpriseid"].(string)
|
|
|
- //格式化价格
|
|
|
- if tmp["f_price"] == nil {
|
|
|
- yp.T["price"] = 0
|
|
|
- } else {
|
|
|
- price := fmt.Sprintf("%.2f", tmp["f_price"])
|
|
|
- yp.T["price"] = price
|
|
|
- }
|
|
|
-
|
|
|
- yp.T["entinfo"] = yps.GetEntInfo(serentid)
|
|
|
- yp.T["entid"] = serentid
|
|
|
- //根据服务ID获取服务信息
|
|
|
-
|
|
|
- return yp.Render("/member/editservice.html", &yp.T)
|
|
|
+ return yps.CommonEntInfo(yp.Action, yp.GetSession("entid").(string), 2, false)
|
|
|
}
|
|
|
|
|
|
-//编辑与保存企业黄页中添加服务信息
|
|
|
-func (yp *Yellowpage) AddService() error {
|
|
|
- var info string = "保存成功"
|
|
|
- var status string = "y"
|
|
|
- var isshows = ""
|
|
|
-
|
|
|
- enterpriseid := yp.GetSession("entid").(string)
|
|
|
- enterprisename := yp.GetSession("entname").(string)
|
|
|
- //行政区划
|
|
|
- opLocD := yp.GetSession("opLocDistrict")
|
|
|
- identType := yp.GetSession("identType")
|
|
|
- comauthenttype := yp.GetSession("comauthenttype")
|
|
|
- serviceid := yp.GetString("serviceid")
|
|
|
- sname := Repl(yp.GetString("servicename"))
|
|
|
- firstservicetype := Repl(yp.GetString("s_firstservicetype"))
|
|
|
- secondservicetype := Repl(yp.GetString("s_secondservicetype"))
|
|
|
- phone := yp.GetString("s_phone")
|
|
|
- province := yp.GetString("province")
|
|
|
- city := yp.GetString("city")
|
|
|
- area := yp.GetString("area")
|
|
|
-
|
|
|
- //当只选择了省
|
|
|
- if len(city) == 1 || len(city) == 0 {
|
|
|
- opLocD = province
|
|
|
- } else {
|
|
|
- opLocD = area
|
|
|
- }
|
|
|
- //是否只选择了市
|
|
|
- if len(area) == 1 || len(area) == 0 {
|
|
|
- opLocD = city
|
|
|
- } else {
|
|
|
- opLocD = area
|
|
|
- }
|
|
|
-
|
|
|
- userid := yp.GetSession("userId")
|
|
|
- username := yp.GetString("username")
|
|
|
- images := yp.GetString("imgurl")
|
|
|
- price, _ := yp.GetFloat("s_price")
|
|
|
- s_introduvtion := Repl(yp.GetStringComm("s_introduvtion"))
|
|
|
- //获取复选框中的信息
|
|
|
- isshow := yp.GetSlice("isshow")
|
|
|
- for _, v := range isshow {
|
|
|
- isshows = v + "," + isshows
|
|
|
- }
|
|
|
- doc := make(map[string]interface{})
|
|
|
- doc["s_name"] = sname
|
|
|
- doc["s_pservicecode"] = firstservicetype
|
|
|
- doc["s_servicecode"] = secondservicetype
|
|
|
- doc["s_name"] = sname
|
|
|
- //检面议是否选中
|
|
|
- if price == 0 {
|
|
|
- doc["s_pricemy"] = "1"
|
|
|
+//保存企业黄页的信息
|
|
|
+func (yp *Yellowpage) Save() error {
|
|
|
+ status := "n"
|
|
|
+ s_persion := Repl(yp.GetString("s_persion"))
|
|
|
+ //联系人不能为空
|
|
|
+ if s_persion == "" {
|
|
|
+ status = "personError"
|
|
|
} else {
|
|
|
- doc["f_price"] = price
|
|
|
- doc["s_pricemy"] = "0"
|
|
|
- }
|
|
|
- doc["f_price"] = price
|
|
|
- doc["s_introduction"] = s_introduvtion
|
|
|
- doc["s_createuserid"] = userid
|
|
|
- doc["s_createusername"] = username
|
|
|
- doc["s_images"] = images
|
|
|
- doc["l_createdate"] = time.Now().Unix()
|
|
|
- //时间戳
|
|
|
- doc["l_timestamp"] = time.Now().Unix()
|
|
|
- if len(serviceid) == 0 {
|
|
|
- //点击数
|
|
|
- doc["i_hits"] = 0
|
|
|
- //预约数
|
|
|
- doc["i_appcounts"] = 0
|
|
|
- //成交数
|
|
|
- doc["i_sales"] = 0
|
|
|
- //评论数
|
|
|
- doc["i_comments"] = 0
|
|
|
- //总分
|
|
|
- doc["i_score"] = 0
|
|
|
- }
|
|
|
-
|
|
|
- //企业信息
|
|
|
- doc["s_enterpriseid"] = enterpriseid
|
|
|
- doc["s_enterprisename"] = enterprisename
|
|
|
- doc["s_phone"] = phone
|
|
|
- doc["s_isshow"] = isshows
|
|
|
- doc["s_opLocDistrict"] = opLocD //行政区划代码
|
|
|
- doc["i_identType"] = identType //认证状态
|
|
|
- doc["i_comauthenttype"] = comauthenttype //企业认证标识:1:营业执照;2:企业名片;3:企业邮箱
|
|
|
- doc["i_status"] = 0
|
|
|
- var tempFlag = false
|
|
|
- //当服务ID不为空的时候执行编辑方法
|
|
|
- if len(serviceid) > 0 {
|
|
|
- docSet := map[string]interface{}{
|
|
|
- "$set": doc,
|
|
|
- }
|
|
|
- //更新服务
|
|
|
- //判断是否能删除
|
|
|
-
|
|
|
- b, _ := CheckAuth(K{"_id": serviceid})
|
|
|
- if b == false {
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
- flag := mongodb.Update("service", "{'_id':'"+serviceid+"'}", &docSet, false, false)
|
|
|
- //更新企业表,服务表
|
|
|
- if flag {
|
|
|
- //将数据存到elastic中
|
|
|
- doc["_id"] = serviceid
|
|
|
- tempFlag = true
|
|
|
- //更新服务表到elastic
|
|
|
- elastic.UpdateNewDoc("service", "service", mongodb.FindById("service", serviceid, nil))
|
|
|
-
|
|
|
+ data := make(map[string]interface{})
|
|
|
+ data["s_persion"] = s_persion
|
|
|
+ entid := yp.GetSession("entid").(string)
|
|
|
+ data["s_persion"] = Repl(yp.GetString("s_persion"))
|
|
|
+ data["s_mobile"] = Repl(yp.GetString("s_mobile"))
|
|
|
+ data["s_enturl"] = Repl(yp.GetString("s_enturl"))
|
|
|
+ data["s_qq"] = Repl(yp.GetString("s_qq"))
|
|
|
+ data["s_weixin"] = Repl(yp.GetString("s_weixin"))
|
|
|
+ data["s_email"] = Repl(yp.GetString("s_email"))
|
|
|
+ province, _ := yp.GetInt("i_province")
|
|
|
+ data["i_province"] = province
|
|
|
+ city, _ := yp.GetInt("i_city")
|
|
|
+ data["i_city"] = city
|
|
|
+ area, _ := yp.GetInt("i_area")
|
|
|
+ data["i_area"] = area
|
|
|
+ data["s_address"] = Repl(yp.GetString("s_address"))
|
|
|
+ //权重
|
|
|
+ atrrTitle := coreconfig.SysConfig.AtrrTitle
|
|
|
+ web := mongodb.FindById(ESTYPE, entid, `{"_id":-1,"attrWeight":1}`)
|
|
|
+ var attrWeight []byte
|
|
|
+ if tmp, ok := (*web)["attrWeight"].(string); ok {
|
|
|
+ attrWeight, _ = hex.DecodeString(tmp)
|
|
|
+ } else {
|
|
|
+ attrWeight = make([]byte, 30)
|
|
|
}
|
|
|
-
|
|
|
- } else {
|
|
|
- doc["i_status"] = 0
|
|
|
- _id := mongodb.Save("service", doc)
|
|
|
- doc["_id"] = _id
|
|
|
- tempFlag = len(_id) > 0
|
|
|
- //发服务送积分
|
|
|
- if tempFlag {
|
|
|
- if credit.AIsHasDo(credit.A_FFW, util.Int64All(yp.GetSession("credit_a"))) {
|
|
|
- credit.UpuserCreditSession(yp.GetSession("userId").(string), credit.B_FFW, "B", nil, yp.Action)
|
|
|
+ for k, v := range atrrTitle {
|
|
|
+ arr, _ := v.([]interface{})
|
|
|
+ index := util.IntAll(arr[0])
|
|
|
+ weight := util.IntAll(arr[1])
|
|
|
+ if weight < int(attrWeight[index]) {
|
|
|
+ delete(data, k)
|
|
|
} else {
|
|
|
- credit.UpuserCreditSession(yp.GetSession("userId").(string), credit.A_FFW, "A", nil, yp.Action)
|
|
|
- credit.UpuserCreditSession(yp.GetSession("userId").(string), credit.B_FFW, "B", nil, yp.Action)
|
|
|
+ attrWeight[index] = byte(weight)
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- currentuser := mongodb.FindById("user", yp.GetSession("userId").(string), nil)
|
|
|
- log.Println(currentuser)
|
|
|
- if len(*currentuser) != 0 && (*currentuser)["s_provider"] == nil {
|
|
|
- mongodb.Update("user", `{"_id":"`+yp.GetSession("userId").(string)+`"}`, `{"$set":{"s_provider":1}}`, true, false)
|
|
|
- }
|
|
|
- log.Println((*currentuser)["s_provider"])
|
|
|
- if tempFlag {
|
|
|
- //删除缓存信息
|
|
|
- redis.Del("enterprise", "enterpriseInfo_"+enterpriseid)
|
|
|
- redis.Del("enterprise", "enterpriseInfo_user_"+enterpriseid)
|
|
|
- redis.DelByCodePattern("enterprise", "service-"+enterpriseid+"-*")
|
|
|
- //将数据存到elastic中
|
|
|
- flag2 := elastic.UpdateNewDoc("service", "service", doc)
|
|
|
- //Insertservicenames(enterpriseid)
|
|
|
- if !flag2 {
|
|
|
- status = "n"
|
|
|
+ data["attrWeight"] = hex.EncodeToString(attrWeight)
|
|
|
+ dataSet := map[string]interface{}{
|
|
|
+ "$set": data,
|
|
|
}
|
|
|
- } else {
|
|
|
- status = "n"
|
|
|
- }
|
|
|
- //如果是新增操作,进入发红包逻辑
|
|
|
- if len(serviceid) == 0 && tempFlag && false {
|
|
|
- //活动有效日期
|
|
|
- valid := time.Now().After(time.Unix(coreconfig.RedPackage.StartDate, 0)) && time.Now().Before(time.Unix(coreconfig.RedPackage.EndDate, 0))
|
|
|
- //判断用户是否是第一次发服务
|
|
|
- valid = valid && mongodb.Count("service", `{"s_createuserid":"`+userid.(string)+`"}`) == 1
|
|
|
- //判断注册日期,必须在活动日期之间
|
|
|
- if valid {
|
|
|
- userInfo := mongodb.FindById("user", userid.(string), `{"l_registedate":1,"s_m_openid":1,"i_identificationtype":1,"i_identificationway":1}`)
|
|
|
- var openid, nickName string
|
|
|
- if nickNameTmp := yp.GetSession("nickName"); nickNameTmp != nil && nickNameTmp.(string) != "" {
|
|
|
- nickName = nickNameTmp.(string)
|
|
|
- } else {
|
|
|
- nickName = enterprisename
|
|
|
- }
|
|
|
- if openidTmp := (*userInfo)["s_m_openid"]; openidTmp != nil && openidTmp.(string) != "" {
|
|
|
- openid = openidTmp.(string)
|
|
|
- } else {
|
|
|
- valid = false
|
|
|
- }
|
|
|
- if l_registedate, ok := (*userInfo)["l_registedate"].(int64); valid && ok {
|
|
|
- registeDate := time.Unix(l_registedate, 0)
|
|
|
- //必须是活动期间注册的用户
|
|
|
- valid = registeDate.After(time.Unix(coreconfig.RedPackage.StartDate, 0)) && registeDate.Before(time.Unix(coreconfig.RedPackage.EndDate, 0))
|
|
|
- //认证通过
|
|
|
- valid = valid && util.IntAll((*userInfo)["i_identificationway"]) == 1
|
|
|
- //个人认证不发红包
|
|
|
- valid = valid && util.IntAll((*userInfo)["i_identificationtype"]) != 2
|
|
|
- //判断该用户是否有红包记录,如果没有并且之前验证通过就发红包
|
|
|
- valid = valid && mongodb.Count("redpackage", `{"s_openid":"`+openid+`"}`) == 0
|
|
|
- } else {
|
|
|
- valid = false
|
|
|
- }
|
|
|
- if valid {
|
|
|
- //第一次发红包
|
|
|
- yp.SetSession("firstredtype", "y")
|
|
|
- go func() {
|
|
|
- //发微信消息
|
|
|
- title := coreconfig.RedPackage.Weixin["successtitle"].(string)
|
|
|
- remark := coreconfig.RedPackage.Weixin["successremark"].(string)
|
|
|
- detail := coreconfig.RedPackage.Weixin["sendname"].(string)
|
|
|
- coreutil.SendManagerNotifyMsg(&qrpc.NotifyMsg{Openid: openid, Title: title, Detail: detail, Remark: remark})
|
|
|
- //邮件过来的用户才可以发红包
|
|
|
- if promotion := mongodb.FindOne("promotion_log", `{"s_uid":"`+userid.(string)+`"}`); promotion != nil && len(*promotion) > 0 && (*promotion)["s_type"] != nil && (*promotion)["s_type"].(string) == "email" {
|
|
|
- //红包一天内5000个,0:00--8:00之间不能发红包
|
|
|
- today := time.Now()
|
|
|
- if today.After(time.Date(today.Year(), today.Month(), today.Day(), 8, 0, 0, 0, time.Local)) && mongodb.Count("redpackage", bson.M{"i_year": today.Year(), "i_month": today.Month(), "i_day": today.Day()}) <= 5000 {
|
|
|
- amount := redpackage.GetAmount() * 100 //“元”转换为“分”,程序随机获取的红包金额以“元”为单位,微信红包以“分”为单位
|
|
|
- bm := qrpc.BonusMsg{Mchbillno: fmt.Sprint(today.Unix()),
|
|
|
- Sendname: coreconfig.RedPackage.Weixin["sendname"].(string),
|
|
|
- Reopenid: openid,
|
|
|
- Totalamount: amount,
|
|
|
- Totalnum: 1,
|
|
|
- Wishing: coreconfig.RedPackage.Weixin["wishing"].(string),
|
|
|
- Actname: coreconfig.RedPackage.Weixin["actname"].(string),
|
|
|
- Remark: coreconfig.RedPackage.Weixin["remark"].(string),
|
|
|
- }
|
|
|
- //红包发送成功
|
|
|
- if coreutil.PayBonus(&bm) {
|
|
|
- //发站内消息
|
|
|
- m := &msg.Msg{
|
|
|
- Msgtype: 1,
|
|
|
- Title: coreconfig.RedPackage.Msg["title"].(string),
|
|
|
- Content: coreconfig.RedPackage.Msg["content"].(string),
|
|
|
- ReceiveId: userid.(string),
|
|
|
- }
|
|
|
- m.SaveMsg()
|
|
|
- //保存红包成功记录
|
|
|
- redpackage := make(bson.M)
|
|
|
- redpackage["s_userid"] = userid.(string)
|
|
|
- redpackage["s_username"] = nickName
|
|
|
- redpackage["s_openid"] = openid
|
|
|
- redpackage["s_billno"] = bm.Mchbillno
|
|
|
- redpackage["s_name"] = bm.Actname
|
|
|
- redpackage["i_amount"] = amount
|
|
|
- redpackage["l_createdate"] = today.Unix()
|
|
|
- redpackage["i_year"] = today.Year()
|
|
|
- redpackage["i_month"] = today.Month()
|
|
|
- redpackage["i_day"] = today.Day()
|
|
|
- mongodb.Save("redpackage", redpackage)
|
|
|
- }
|
|
|
- } else {
|
|
|
- //保存红包失败记录
|
|
|
- redpackage := make(bson.M)
|
|
|
- redpackage["s_userid"] = userid.(string)
|
|
|
- redpackage["s_username"] = nickName
|
|
|
- redpackage["s_openid"] = openid
|
|
|
- redpackage["l_createdate"] = today.Unix()
|
|
|
- redpackage["i_year"] = today.Year()
|
|
|
- redpackage["i_month"] = today.Month()
|
|
|
- redpackage["i_day"] = today.Day()
|
|
|
- mongodb.Save("reissueredpackage", redpackage)
|
|
|
- }
|
|
|
+ //向mongodb库中写数据
|
|
|
+ if mongodb.Update(ESTYPE, "{'_id':'"+entid+"'}", &dataSet, false, false) {
|
|
|
+ status = "y"
|
|
|
+ go func() {
|
|
|
+ util.Try(func() {
|
|
|
+ redis.Del("enterprise", "enterpriseInfo_"+entid)
|
|
|
+ redis.DelByCodePattern("enterprise", "ipcity_*")
|
|
|
+ elastic.UpdateEntDoc(entid)
|
|
|
+ //首次创建企业名片,送积分
|
|
|
+ if !credit.AIsHasDo(credit.A_CJMP, util.Int64All(yp.GetSession("credit_a"))) {
|
|
|
+ credit.UpuserCreditSession(util.ObjToString(yp.GetSession("userId")), credit.A_CJMP, "A", nil, yp.Action)
|
|
|
}
|
|
|
- }()
|
|
|
- }
|
|
|
+ }, func(e interface{}) {
|
|
|
+ log.Println(e)
|
|
|
+ })
|
|
|
+ }()
|
|
|
}
|
|
|
}
|
|
|
- return yp.Write("{\"info\":\"" + info + "\",\"status\":\"" + status + "\"}")
|
|
|
+ yp.ServeJson(&map[string]interface{}{"status": status})
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -652,3 +231,79 @@ func (yp *Yellowpage) UpLoadEntImg() error {
|
|
|
return yp.Write("n")
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+//手机关注企业
|
|
|
+func (yp *Yellowpage) WxFollow() error {
|
|
|
+ entName := yp.GetString("entName")
|
|
|
+ userId := yp.GetSession("userId").(string)
|
|
|
+ status := "N"
|
|
|
+ if len(userId) > 0 {
|
|
|
+ e := mongodbutil.FindOne("enterprise", coreconfig.SysConfig.EntMongodbAlias, coreconfig.SysConfig.EntMongodbName, `{"EntName":"`+entName+`"}`)
|
|
|
+ if (*e)["_id"] != nil {
|
|
|
+ entId := strings.Split(fmt.Sprintf("%s", (*e)["_id"]), `"`)[1]
|
|
|
+ if mongodb.Count("follow_enterprise", `{"s_userid":"`+userId+`"}`) >= coreconfig.SysConfig.FollowEnterprise {
|
|
|
+ status = "M"
|
|
|
+ } else if mongodb.Count("follow_enterprise", `{"s_userid":"`+userId+`","s_entid":"`+entId+`"}`) == 0 {
|
|
|
+ userInfo := yp.GetSession("userInfo").(*map[string]interface{})
|
|
|
+ if len(mongodb.Save("follow_enterprise", bson.M{
|
|
|
+ "s_userid": userId,
|
|
|
+ "s_entid": entId,
|
|
|
+ "s_m_openid": (*userInfo)["s_m_openid"],
|
|
|
+ "l_createdate": time.Now().Unix(),
|
|
|
+ })) > 0 {
|
|
|
+ status = "Y"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ yp.ServeJson(bson.M{"status": status})
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+//关注企业
|
|
|
+func (yp *Yellowpage) Follow() error {
|
|
|
+ defer util.Catch()
|
|
|
+ entId := yp.GetString("entId")
|
|
|
+ flag, _ := yp.GetBool("flag")
|
|
|
+ userId := yp.GetSession("userId").(string)
|
|
|
+ status := "n"
|
|
|
+ if flag {
|
|
|
+ data := mongodb.FindOne("follow_enterprise", `{"s_userid":"`+userId+`","s_entid":"`+entId+`"}`)
|
|
|
+ if data != nil && len(*data) > 0 {
|
|
|
+ (*data)["s_followid"] = util.BsonIdToSId((*data)["_id"])
|
|
|
+ delete((*data), "_id")
|
|
|
+ mongodb.Save("follow_enterprise_back", data)
|
|
|
+ }
|
|
|
+ if mongodb.Del("follow_enterprise", `{"s_userid":"`+userId+`","s_entid":"`+entId+`"}`) {
|
|
|
+ status = "y"
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if mongodb.Count("follow_enterprise", `{"s_userid":"`+userId+`"}`) >= coreconfig.SysConfig.FollowEnterprise {
|
|
|
+ status = "m"
|
|
|
+ } else if mongodb.Count("follow_enterprise", `{"s_userid":"`+userId+`","s_entid":"`+entId+`"}`) == 0 {
|
|
|
+ userInfo := yp.GetSession("userInfo").(*map[string]interface{})
|
|
|
+ if len(mongodb.Save("follow_enterprise", bson.M{
|
|
|
+ "s_userid": userId,
|
|
|
+ "s_entid": entId,
|
|
|
+ "s_m_openid": (*userInfo)["s_m_openid"],
|
|
|
+ "l_createdate": time.Now().Unix(),
|
|
|
+ })) > 0 {
|
|
|
+ status = "y"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ yp.ServeJson(bson.M{"status": status})
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+//是否关注
|
|
|
+func (yp *Yellowpage) IsFollowed() error {
|
|
|
+ entId := yp.GetString("entId")
|
|
|
+ userId := yp.GetSession("userId").(string)
|
|
|
+ status := "n"
|
|
|
+ if mongodb.Count("follow_enterprise", `{"s_userid":"`+userId+`","s_entid":"`+entId+`"}`) > 0 {
|
|
|
+ status = "y"
|
|
|
+ }
|
|
|
+ yp.ServeJson(bson.M{"status": status})
|
|
|
+ return nil
|
|
|
+}
|