|
@@ -4,6 +4,7 @@ import (
|
|
|
"app.yhyue.com/moapp/jybase/common"
|
|
|
"app.yhyue.com/moapp/jybase/date"
|
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
"fmt"
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
|
IC "jyBXSubscribe/rpc/init"
|
|
@@ -61,6 +62,8 @@ func GetStaffSubscribeList(entId, entUserId int, query string, eStatus, pStatus,
|
|
|
}
|
|
|
// 当检索是否有个人订阅时,因为无法关联查询,需要提前加载员工是否有个人订阅
|
|
|
pSubscribeList := getEntPersonOrderList(entId)
|
|
|
+ // 加载当前企业所有企业分发数据
|
|
|
+ ruleIds := getEntSubscirbeList(entId, userEnt.Dept.Id, userEnt.Role_admin_system)
|
|
|
|
|
|
var sql string = ` FROM (
|
|
|
SELECT
|
|
@@ -120,11 +123,23 @@ WHERE`
|
|
|
queryArr = append(queryArr, ` ( name LIKE ? or phone like ? ) `)
|
|
|
valueArr = append(valueArr, "%"+query+"%", "%"+query+"%")
|
|
|
}
|
|
|
- // 企业订阅过滤
|
|
|
- if eStatus == 1 { //有企业订阅
|
|
|
- queryArr = append(queryArr, ` rule_id is not null `)
|
|
|
- } else if eStatus == -1 { // 无企业订阅
|
|
|
- queryArr = append(queryArr, ` rule_id is null `)
|
|
|
+ // 企业分发过滤
|
|
|
+ if eStatus == 1 && len(ruleIds) == 0 {
|
|
|
+ return 0, nil
|
|
|
+ } else if eStatus != 0 && len(ruleIds) > 0 {
|
|
|
+ tStr := ``
|
|
|
+ for i, v := range ruleIds {
|
|
|
+ if i != 0 {
|
|
|
+ tStr += `,`
|
|
|
+ }
|
|
|
+ tStr += fmt.Sprintf(`"%s"`, v)
|
|
|
+ }
|
|
|
+
|
|
|
+ if eStatus == 1 { //有个人订阅
|
|
|
+ queryArr = append(queryArr, fmt.Sprintf(` rule_id in ( %s ) `, tStr))
|
|
|
+ } else if eStatus == -1 { //无个人订阅
|
|
|
+ queryArr = append(queryArr, fmt.Sprintf(` rule_id not in ( %s ) `, tStr))
|
|
|
+ }
|
|
|
}
|
|
|
// 个人订阅过滤
|
|
|
if pStatus == 1 && len(pSubscribeList) == 0 {
|
|
@@ -194,6 +209,37 @@ func getEntPersonOrderList(entId int) (uIds []int64) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// getEntSubscirbeList 查询企业分发列表
|
|
|
+func getEntSubscirbeList(entId, depId int, isAdmin bool) (rId []string) {
|
|
|
+ //查询是否有企业分发
|
|
|
+ dept_subscribe := IC.MainMysql.Count("entniche_info", map[string]interface{}{"dept_subscribe": 1, "id": entId}) > 0
|
|
|
+ queryMap := map[string]interface{}{
|
|
|
+ "1": "1",
|
|
|
+ }
|
|
|
+ if dept_subscribe && !isAdmin {
|
|
|
+ queryMap = map[string]interface{}{
|
|
|
+ "i_entid": entId,
|
|
|
+ "i_status": 0, //0未删除 1已删除
|
|
|
+ "i_deptid": depId,
|
|
|
+ }
|
|
|
+ } else if isAdmin {
|
|
|
+ queryMap = map[string]interface{}{
|
|
|
+ "i_entid": entId,
|
|
|
+ "i_status": 0, //0未删除 1已删除
|
|
|
+ "i_deptid": map[string]interface{}{
|
|
|
+ "$exists": false,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res, _ := IC.Mgo.Find("entniche_distribute", queryMap, nil, `{"_id":1,"o_area":1,"a_buyerclass":1,"a_items":1}`, false, -1, -1)
|
|
|
+ if len(*res) > 0 {
|
|
|
+ for _, v := range *res {
|
|
|
+ rId = append(rId, mongodb.BsonIdToSId(v["_id"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// GetStaffSubscribeDetail 获取企业个人订阅
|
|
|
func GetStaffSubscribeDetail(entId, uid int64, token string) (rData map[string]interface{}, err error) {
|
|
|
entIdCheck, uidCheck, staffId, ruleId, power, err := decodeSubscribeMsg(token)
|
|
@@ -209,19 +255,32 @@ func GetStaffSubscribeDetail(entId, uid int64, token string) (rData map[string]i
|
|
|
return
|
|
|
}
|
|
|
rData = map[string]interface{}{}
|
|
|
- for _, vipFlag := range strings.Split(power, "_") {
|
|
|
- if vipFlag == "e" {
|
|
|
- //个人订阅商机管理
|
|
|
- if data := getPersonSubscribe(map[string]interface{}{"i_entid": entId, "i_userid": staffId, "i_type": 0}); data != nil && len(data) > 0 {
|
|
|
- rData["个人订阅<br>商机管理"] = data
|
|
|
- }
|
|
|
- } else if vipFlag == "v" || vipFlag == "m" {
|
|
|
- //大会员或超级订阅企业版
|
|
|
- if data := getPersonSubscribe(map[string]interface{}{"i_entid": entId, "i_userid": staffId, "i_type": 1}); data != nil && len(data) > 0 {
|
|
|
- rData[fmt.Sprintf("个人订阅<br>%s", common.If(vipFlag == "v", "超级订阅企业版", "大会员企业版"))] = data
|
|
|
- }
|
|
|
+ nameEntNiche, nameVipMember := "", "" //当只存在大会员或商机管理时 展示个人订阅;当都存在时展示产品信息
|
|
|
+ valueEntNiche, valueVipMember := map[string]interface{}{}, map[string]interface{}{}
|
|
|
+
|
|
|
+ if strings.Index(power, "e") > -1 {
|
|
|
+ //个人订阅商机管理
|
|
|
+ if data := getPersonSubscribe(map[string]interface{}{"i_entid": entId, "i_userid": staffId, "i_type": 0}); data != nil && len(data) > 0 {
|
|
|
+ nameEntNiche = "个人订阅<br>商机管理"
|
|
|
+ valueEntNiche = data
|
|
|
+ }
|
|
|
+ } else if strings.Index(power, "m") > -1 || strings.Index(power, "v") > -1 {
|
|
|
+ //大会员或超级订阅企业版
|
|
|
+ if data := getPersonSubscribe(map[string]interface{}{"i_entid": entId, "i_userid": staffId, "i_type": 1}); data != nil && len(data) > 0 {
|
|
|
+ nameVipMember = fmt.Sprintf("个人订阅<br>%s", common.If(strings.Index(power, "v") > -1, "超级订阅企业版", "大会员企业版"))
|
|
|
+ valueVipMember = data
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if len(valueEntNiche) > 0 && len(valueVipMember) > 0 {
|
|
|
+ rData[nameEntNiche] = valueEntNiche
|
|
|
+ rData[nameVipMember] = valueVipMember
|
|
|
+ } else if len(valueEntNiche) > 0 {
|
|
|
+ rData["个人订阅"] = valueEntNiche
|
|
|
+ } else if len(valueVipMember) > 0 {
|
|
|
+ rData["个人订阅"] = valueVipMember
|
|
|
+ }
|
|
|
+
|
|
|
// 企业自动分发
|
|
|
if ruleId != "" {
|
|
|
if data := getEntDistribute(ruleId, entId, staffId); data != nil && len(data) > 0 {
|