|
@@ -1,7 +1,9 @@
|
|
|
package entity
|
|
|
|
|
|
import (
|
|
|
+ "context"
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"jy/src/jfw/modules/subscribepay/src/config"
|
|
|
"jy/src/jfw/modules/subscribepay/src/pay"
|
|
@@ -11,16 +13,17 @@ import (
|
|
|
"sync"
|
|
|
"time"
|
|
|
|
|
|
+ "app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenter"
|
|
|
+ "app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenterclient"
|
|
|
"app.yhyue.com/moapp/jybase/api"
|
|
|
qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
. "app.yhyue.com/moapp/jybase/date"
|
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
|
"app.yhyue.com/moapp/jypkg/common/src/qfw/util/dataexport"
|
|
|
"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/middleGround"
|
|
|
-
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
+ "github.com/gogf/gf/v2/frame/g"
|
|
|
)
|
|
|
|
|
|
// 剑鱼数据流量包
|
|
@@ -158,6 +161,7 @@ func (this *dataExportPackStruct) GetPackDetailById(packId string) (PackDetail,
|
|
|
|
|
|
// GetAccountMsg 查询账户和企业数据包情况
|
|
|
func (this *dataExportPackStruct) GetAccountMsg(sess *httpsession.Session, userId string) (map[string]interface{}, error) {
|
|
|
+ sessVal := sess.GetMultiple()
|
|
|
//每日限量包
|
|
|
packDetail := map[string]interface{}{}
|
|
|
vipStatus := jy.GetBigVipUserBaseMsg(sess, *config.Middleground)
|
|
@@ -179,33 +183,43 @@ func (this *dataExportPackStruct) GetAccountMsg(sess *httpsession.Session, userI
|
|
|
}
|
|
|
|
|
|
//企业数据导出
|
|
|
- if phone := getAndCacheUserPhone(sess, userId); phone != "" {
|
|
|
- if entId := qutil.IntAll(sess.Get("entId")); entId != 0 {
|
|
|
- var entPack []map[string]interface{}
|
|
|
- var entAllCount int
|
|
|
- res := util.Mysql.FindOne("entniche_info", map[string]interface{}{"id": entId}, "id,phone,name", "")
|
|
|
- if res != nil && len(*res) != 0 {
|
|
|
- entUserId := qutil.IntAll(sess.Get("entUserId"))
|
|
|
- entName, _ := (*res)["name"].(string)
|
|
|
- entPhone, _ := (*res)["phone"].(string)
|
|
|
- if entUserId > 0 && entName != "" && entPhone != "" {
|
|
|
- entAllCount = getCurrEntCount(entName, entPhone) //查询所属企业及账户余额
|
|
|
- limit := util.Mysql.FindOne("entniche_export_limit", map[string]interface{}{"ent_id": entId, "user_id": entUserId}, "data_limit,remain_nums,export_nums", "")
|
|
|
- if limit != nil && len(*limit) > 0 {
|
|
|
- entPack = append(entPack, map[string]interface{}{
|
|
|
- "entId": entId, //企业id
|
|
|
- "entName": entName, //企业名字
|
|
|
- "entAllCount": entAllCount, //企业总条数
|
|
|
- "limitToday": qutil.IntAll((*limit)["data_limit"]), //个人今日限额
|
|
|
- "surplusToday": qutil.IntAll((*limit)["remain_nums"]), //今日剩余
|
|
|
- "usedToday": qutil.IntAll((*limit)["export_nums"]), //今日使用
|
|
|
- })
|
|
|
- }
|
|
|
+ if entId := qutil.Int64All(sessVal["entId"]); entId != 0 {
|
|
|
+ var entPack []map[string]interface{}
|
|
|
+ limit := util.Mysql.SelectBySql(`select a.data_limit,a.export_nums,a.max_nums,a.all_export_nums from jianyu.entniche_export_limit a
|
|
|
+ inner join jianyu.entniche_user aa on (a.user_id=? and a.user_id=aa.id and aa.export_power=1)
|
|
|
+ where exists (select 1 from jianyu.entniche_info b where a.ent_id=b.id and b.status>0) or exists (select 1 from jianyu.entniche_wait_empower c where a.ent_id=c.ent_id and c.product_key='qysjllb' and c.end_time>?)`, qutil.IntAll(sessVal["entUserId"]), NowFormat(Date_Full_Layout))
|
|
|
+ if limit != nil && len(*limit) > 0 {
|
|
|
+ mp := map[string]interface{}{
|
|
|
+ "entId": entId, //企业id
|
|
|
+ "entName": qutil.ObjToString(sessVal["entName"]), //企业名字
|
|
|
+ "entAllCount": getCurrEntCount(entId), //企业总条数
|
|
|
+ }
|
|
|
+ if (*limit)[0]["data_limit"] != nil {
|
|
|
+ data_limit := qutil.IntAll((*limit)[0]["data_limit"]) //个人今日限额
|
|
|
+ export_nums := qutil.IntAll((*limit)[0]["export_nums"])
|
|
|
+ surplusToday := data_limit - export_nums
|
|
|
+ if surplusToday < 0 {
|
|
|
+ surplusToday = 0
|
|
|
}
|
|
|
+ mp["limitToday"] = data_limit
|
|
|
+ mp["surplusToday"] = surplusToday //今日剩余
|
|
|
+ mp["usedToday"] = export_nums //今日使用
|
|
|
}
|
|
|
- if entPack != nil {
|
|
|
- packDetail["entPack"] = entPack
|
|
|
+ if (*limit)[0]["max_nums"] != nil {
|
|
|
+ max_nums := qutil.IntAll((*limit)[0]["max_nums"])
|
|
|
+ all_export_nums := qutil.IntAll((*limit)[0]["all_export_nums"])
|
|
|
+ surplusNums := max_nums - all_export_nums
|
|
|
+ if surplusNums < 0 {
|
|
|
+ surplusNums = 0
|
|
|
+ }
|
|
|
+ mp["maxNums"] = max_nums
|
|
|
+ mp["surplusNums"] = surplusNums
|
|
|
+ mp["usedNums"] = all_export_nums
|
|
|
}
|
|
|
+ entPack = append(entPack, mp)
|
|
|
+ }
|
|
|
+ if entPack != nil {
|
|
|
+ packDetail["entPack"] = entPack
|
|
|
}
|
|
|
}
|
|
|
return packDetail, nil
|
|
@@ -223,144 +237,166 @@ func (this *dataExportPackStruct) GetPersonalAccount(userId string) (senior, nor
|
|
|
}
|
|
|
|
|
|
// GetDataExportRecordList 数据导出记录(包含商机管理导出、每日流量包导出、数据包导出及用户付费直接导出)
|
|
|
-func (this *dataExportPackStruct) GetDataExportRecordList(userId, memberPid string, entId, entUserId, pageNum, pageSize int) (list []map[string]interface{}, total int, err error) {
|
|
|
- if pageSize == 0 {
|
|
|
+func (this *dataExportPackStruct) GetDataExportRecordList(userId, memberPid, userIds string, starttime, endtime, entRole, entId, entDeptId, pageNum, pageSize, payWay int) (list []map[string]interface{}, total int64, err error) {
|
|
|
+ if pageSize <= 0 {
|
|
|
pageSize = 10
|
|
|
}
|
|
|
-
|
|
|
- var searchSql []string
|
|
|
- var searchValue []interface{}
|
|
|
-
|
|
|
- //个人直接支付数据导出
|
|
|
- if userId != "" {
|
|
|
- searchSql = append(searchSql, `(SELECT '' AS queryObj,filter_id AS queryId,user_id AS user_id,'' AS user_name,UNIX_TIMESTAMP( create_time ) AS exportDate,
|
|
|
- 2 AS data_from,data_count AS export_num,-1 AS deduct_num,download_url AS down_url FROM dataexport_order WHERE user_id =? AND order_status =1 AND product_type ='历史数据')`)
|
|
|
- searchValue = append(searchValue, userId)
|
|
|
+ if pageNum <= 0 {
|
|
|
+ pageNum = 1
|
|
|
}
|
|
|
-
|
|
|
- //数据包导出及每日限量包导出
|
|
|
- if userId != "" || memberPid != "" {
|
|
|
- if memberPid == "" { //主账号查询
|
|
|
- searchSql = append(searchSql, `(SELECT '' AS queryObj,query_id AS queryId,useid AS user_id,'' AS user_name,date AS exportDate,2 AS data_from,export_num AS
|
|
|
- export_num,deduct_num AS deduct_num,path AS down_url FROM datapacket_record WHERE master_id = ? )`)
|
|
|
- searchValue = append(searchValue, userId)
|
|
|
- } else { //子账号查询
|
|
|
- searchSql = append(searchSql, `(SELECT '' AS queryObj,query_id AS queryId,useid AS user_id,'' AS user_name,date AS exportDate,2 AS data_from,export_num AS
|
|
|
- export_num,deduct_num AS deduct_num,path AS down_url FROM datapacket_record WHERE useid = ? )`)
|
|
|
- searchValue = append(searchValue, userId)
|
|
|
+ comSql := ``
|
|
|
+ args := []interface{}{}
|
|
|
+ if entRole == 2 {
|
|
|
+ comSql = `from entniche_department_parent b
|
|
|
+ inner join entniche_department_user c on ((b.pid=? or c.dept_id=?) and b.id=c.dept_id)
|
|
|
+ inner join datapacket_record a on (c.user_id=a.ent_user_id) where 1=1`
|
|
|
+ args = append(args, entDeptId, entDeptId)
|
|
|
+ } else {
|
|
|
+ comSql = `from datapacket_record a where `
|
|
|
+ if entId == 0 {
|
|
|
+ if memberPid == "" {
|
|
|
+ comSql += `a.master_id=?`
|
|
|
+ } else {
|
|
|
+ comSql += `a.useid=?`
|
|
|
+ }
|
|
|
+ args = append(args, userId)
|
|
|
+ } else {
|
|
|
+ if entRole == 1 {
|
|
|
+ comSql += `a.ent_id=?`
|
|
|
+ args = append(args, entId)
|
|
|
+ } else {
|
|
|
+ comSql += `a.useid=?`
|
|
|
+ args = append(args, userId)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //企业数据导出
|
|
|
- if entId > 0 && entUserId != 0 {
|
|
|
- if util.Mysql.Count("entniche_user_role", map[string]interface{}{"user_id": entUserId, "role_id": 1}) > 0 {
|
|
|
- //管理员查询
|
|
|
- searchSql = append(searchSql, `(SELECT filter AS queryObj,'' AS queryId,'' AS user_id,user_name AS user_name,UNIX_TIMESTAMP( export_time ) AS exportDate,
|
|
|
- data_source AS data_from,export_num AS export_num,deduct_num AS deduct_num,download_url AS down_url FROM entniche_export_log WHERE ent_id = ? )`)
|
|
|
- searchValue = append(searchValue, entId)
|
|
|
+ if userIds != "" {
|
|
|
+ wh, thisArgs := qutil.WhArgs(strings.Split(userIds, ","))
|
|
|
+ comSql += ` and a.ent_user_id in (` + wh + `)`
|
|
|
+ args = append(args, thisArgs...)
|
|
|
+ }
|
|
|
+ if payWay > 0 {
|
|
|
+ comSql += ` and a.type=?`
|
|
|
+ if payWay == 1 || payWay == 2 {
|
|
|
+ args = append(args, payWay-1)
|
|
|
+ } else if payWay == 3 || payWay == 4 {
|
|
|
+ comSql += ` and a.isSenior=?`
|
|
|
+ args = append(args, 2)
|
|
|
+ if payWay == 3 {
|
|
|
+ args = append(args, 2)
|
|
|
+ } else {
|
|
|
+ args = append(args, 1)
|
|
|
+ }
|
|
|
} else {
|
|
|
- //子账号查询
|
|
|
- searchSql = append(searchSql, `(SELECT filter AS queryObj,'' AS queryId,'' AS user_id,user_name AS user_name,UNIX_TIMESTAMP( export_time ) AS exportDate,
|
|
|
- data_source AS data_from,export_num AS export_num,deduct_num AS deduct_num,download_url AS down_url FROM entniche_export_log WHERE user_id = ? )`)
|
|
|
- searchValue = append(searchValue, entUserId)
|
|
|
+ args = append(args, payWay-2)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- finalSearch := strings.Join(searchSql, ` UNION ALL `)
|
|
|
-
|
|
|
- //log.Printf("sql xxx %s\n", fmt.Sprintf(`SELECT * FROM ( %s ) AS allData ORDER BY exportDate DESC limit ?,? `, finalSearch))
|
|
|
- //log.Printf("values xxx :")
|
|
|
- //for k, v := range append(searchValue, pageNum*pageSize, pageSize) {
|
|
|
- // log.Printf(" [%d]=%v ", k, v)
|
|
|
- //}
|
|
|
- //log.Println()
|
|
|
-
|
|
|
+ if starttime > 0 {
|
|
|
+ comSql += ` and a.date>=?`
|
|
|
+ args = append(args, starttime)
|
|
|
+ }
|
|
|
+ if endtime > 0 {
|
|
|
+ comSql += ` and a.date<=?`
|
|
|
+ args = append(args, endtime)
|
|
|
+ }
|
|
|
+ countSql := `select count(1) as count ` + comSql
|
|
|
+ listSql := `select a.source,a.filter,a.query_id,a.date,a.export_num,a.deduct_num,a.path,a.isSenior,a.type,a.operator ` + comSql + ` order by a.date desc limit ?,?`
|
|
|
//第一页返回总条数
|
|
|
- if pageNum == 0 {
|
|
|
- //log.Printf(`SELECT COUNT(*) FROM ( %s ) AS allData`, finalSearch)
|
|
|
- if total = util.Mysql.QueryCount(fmt.Sprintf(`SELECT COUNT(*) FROM ( %s ) AS allData`, finalSearch), searchValue...); total == 0 {
|
|
|
+ if pageNum == 1 {
|
|
|
+ if total = util.Mysql.CountBySql(countSql, args...); total == 0 {
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
|
total = -1
|
|
|
}
|
|
|
-
|
|
|
+ args = append(args, (pageNum-1)*pageSize, pageSize)
|
|
|
//查询列表
|
|
|
- searchList := util.Mysql.Query(fmt.Sprintf(`SELECT * FROM ( %s ) AS allData ORDER BY exportDate DESC limit ?,? `, finalSearch), append(searchValue, pageNum*pageSize, pageSize)...)
|
|
|
+ searchList := util.Mysql.SelectBySql(listSql, args...)
|
|
|
if searchList == nil || len(*searchList) == 0 {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//格式化返回内容
|
|
|
list = make([]map[string]interface{}, 0, pageSize)
|
|
|
- cacheName := map[string]string{}
|
|
|
for _, row := range *searchList {
|
|
|
//筛选内容
|
|
|
returnRow := make(map[string]interface{})
|
|
|
- if queryId, _ := row["queryId"].(string); queryId != "" {
|
|
|
- returnRow["search"] = getSearchValueById(queryId)
|
|
|
- } else if queryStr, _ := row["queryObj"].(string); queryStr != "" {
|
|
|
- filterMap := map[string]interface{}{}
|
|
|
- if err := json.Unmarshal([]byte(queryStr), &filterMap); err == nil {
|
|
|
- if filterId, _ := filterMap["FilterId"].(string); filterId != "" {
|
|
|
- returnRow["search"] = getSearchValueById(filterId)
|
|
|
+ filterMap := map[string]interface{}{}
|
|
|
+ filter := qutil.ObjToString(row["filter"])
|
|
|
+ if filter != "" {
|
|
|
+ if err := json.Unmarshal([]byte(filter), &filterMap); err == nil {
|
|
|
+ t, _ := filterMap["Time"].(string)
|
|
|
+ if strings.Contains(t, "_") {
|
|
|
+ t1 := strings.Split(t, "_")[0]
|
|
|
+ t2 := strings.Split(t, "_")[1]
|
|
|
+ if len([]rune(t1)) > 10 {
|
|
|
+ t1 = string([]rune(t)[:10])
|
|
|
+ }
|
|
|
+ if len([]rune(t2)) > 10 {
|
|
|
+ t2 = string([]rune(t2)[:10])
|
|
|
+ }
|
|
|
+ t = t1 + "_" + t2
|
|
|
} else {
|
|
|
- filterMap["area"] = filterMap["Area"]
|
|
|
- t, _ := filterMap["Time"].(string)
|
|
|
- if strings.Contains(t, "_") {
|
|
|
- t1 := strings.Split(t, "_")[0]
|
|
|
- t2 := strings.Split(t, "_")[1]
|
|
|
- if len([]rune(t1)) > 10 {
|
|
|
- t1 = string([]rune(t)[:10])
|
|
|
- }
|
|
|
- if len([]rune(t2)) > 10 {
|
|
|
- t2 = string([]rune(t2)[:10])
|
|
|
- }
|
|
|
- t = t1 + "_" + t2
|
|
|
- } else {
|
|
|
- if len([]rune(t)) > 10 {
|
|
|
- t = string([]rune(t)[:10])
|
|
|
- }
|
|
|
+ if len([]rune(t)) > 10 {
|
|
|
+ t = string([]rune(t)[:10])
|
|
|
}
|
|
|
- filterMap["publishtime"] = t
|
|
|
- filterMap["buyerclass"] = filterMap["Buyerclass"]
|
|
|
- delete(filterMap, "Area")
|
|
|
- delete(filterMap, "Time")
|
|
|
- delete(filterMap, "Buyerclass")
|
|
|
- returnRow["search"] = filterMap
|
|
|
}
|
|
|
+ filterMap["area"] = filterMap["Area"]
|
|
|
+ filterMap["publishtime"] = t
|
|
|
+ filterMap["buyerclass"] = filterMap["Buyerclass"]
|
|
|
+ filterMap["id"] = filterMap["Id"]
|
|
|
+ filterMap["comeinfrom"] = filterMap["comeinfrom"]
|
|
|
+ delete(filterMap, "Area")
|
|
|
+ delete(filterMap, "Time")
|
|
|
+ delete(filterMap, "Buyerclass")
|
|
|
+ delete(filterMap, "Id")
|
|
|
+ delete(filterMap, "Comeinfrom")
|
|
|
+ returnRow["search"] = filterMap
|
|
|
}
|
|
|
}
|
|
|
- //查询用户
|
|
|
- if personalName, _ := row["user_name"].(string); personalName != "" {
|
|
|
- returnRow["personal_name"] = personalName
|
|
|
- } else if searchUserId, _ := row["user_id"].(string); searchUserId != "" {
|
|
|
- if _, exists := cacheName[searchUserId]; !exists {
|
|
|
- cacheName[searchUserId] = getUserName(searchUserId)
|
|
|
+ if len(filterMap) == 0 {
|
|
|
+ if queryId, _ := row["query_id"].(string); queryId != "" {
|
|
|
+ returnRow["search"] = getSearchValueById(queryId)
|
|
|
}
|
|
|
- returnRow["personal_name"] = cacheName[searchUserId]
|
|
|
}
|
|
|
+ operator, _ := row["operator"].(string)
|
|
|
+ operator = strings.ReplaceAll(operator, "(", " ")
|
|
|
+ operator = strings.ReplaceAll(operator, ")", "")
|
|
|
+ returnRow["personal_name"] = operator
|
|
|
//导出时间
|
|
|
- returnRow["export_timestamp"] = row["exportDate"]
|
|
|
+ returnRow["export_timestamp"] = row["date"]
|
|
|
//数据来源
|
|
|
- if qutil.IntAll(row["data_from"]) == 1 {
|
|
|
- returnRow["data_from"] = "统一订阅"
|
|
|
+ if qutil.IntAll(row["source"]) == 1 {
|
|
|
+ returnRow["data_from"] = "数据定制导出"
|
|
|
} else {
|
|
|
- returnRow["data_from"] = "用户搜索"
|
|
|
+ returnRow["data_from"] = "数据自助导出"
|
|
|
}
|
|
|
//导出条数
|
|
|
returnRow["export_num"] = qutil.Int64All(row["export_num"])
|
|
|
returnRow["deduct_num"] = qutil.Int64All(row["deduct_num"])
|
|
|
//下载地址
|
|
|
- returnRow["down_url"] = config.Config.WebDomain + qutil.ObjToString(row["down_url"])
|
|
|
-
|
|
|
+ returnRow["down_url"] = config.Config.WebDomain + qutil.ObjToString(row["path"])
|
|
|
+ switch qutil.IntAll(row["type"]) {
|
|
|
+ case 0:
|
|
|
+ returnRow["pay_way"] = "个人支付"
|
|
|
+ case 1:
|
|
|
+ returnRow["pay_way"] = "单日限量数据包"
|
|
|
+ case 2:
|
|
|
+ if qutil.IntAll(row["isSenior"]) == 1 {
|
|
|
+ returnRow["pay_way"] = "个人数据流量包(标准字段包)"
|
|
|
+ } else {
|
|
|
+ returnRow["pay_way"] = "个人数据流量包(高级字段包)"
|
|
|
+ }
|
|
|
+ case 3:
|
|
|
+ returnRow["pay_way"] = "企业数据流量包"
|
|
|
+ }
|
|
|
list = append(list, returnRow)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// DoEntPackRepeatCheck 查询企业去重(旧企业导出逻辑)
|
|
|
-func (this *dataExportPackStruct) DoEntPackRepeatCheck(sess *httpsession.Session, userId, entId, selectId string, selectCount int) (deduct int, err error) {
|
|
|
+func (this *dataExportPackStruct) DoEntPackRepeatCheck(sess *httpsession.Session, userId, selectId string, entId, selectCount int) (deduct int, err error) {
|
|
|
//校验当前用户是否所属此企业
|
|
|
if phone := getAndCacheUserPhone(sess, userId); phone != "" {
|
|
|
res := util.Mysql.FindOne("entniche_user", map[string]interface{}{"phone": phone, "ent_id": entId}, "id,ent_id", "")
|
|
@@ -370,16 +406,9 @@ func (this *dataExportPackStruct) DoEntPackRepeatCheck(sess *httpsession.Session
|
|
|
|
|
|
entUserId := qutil.IntAll((*res)["id"])
|
|
|
entIdInt := qutil.IntAll((*res)["ent_id"])
|
|
|
-
|
|
|
- exportLock.Lock()
|
|
|
- exportLockMap[entIdInt] = &sync.Mutex{}
|
|
|
- entLock := exportLockMap[entIdInt]
|
|
|
- exportLock.Unlock()
|
|
|
- entLock.Lock()
|
|
|
//开始去重
|
|
|
_, newCount, err := dataexport.GetEntDataExportCountIdArr(util.MQFW, util.Mgo_bidding, config.Config.Mongobidding.DbName, config.Config.Elasticsearch,
|
|
|
- selectId, entIdInt, entUserId, middleGround.JyApiConfig.ApiList.EntDedupUrl, config.ExConf.MsgMaxCount)
|
|
|
- entLock.Unlock()
|
|
|
+ selectId, entIdInt, entUserId, g.Cfg().MustGet(context.Background(), "dataPkgRemoveRepeatAddr").String(), config.ExConf.MsgMaxCount)
|
|
|
return newCount, err
|
|
|
}
|
|
|
return -1, fmt.Errorf("未查询所属企业")
|
|
@@ -418,69 +447,81 @@ var (
|
|
|
)
|
|
|
|
|
|
// UseEntPack 企业数据包扣除
|
|
|
-func (this *dataExportPackStruct) UseEntPack(sess *httpsession.Session, userId, entId string, selectId string, exportPhone, exportEmail string) error {
|
|
|
- if phone := getAndCacheUserPhone(sess, userId); phone != "" {
|
|
|
- res := util.Mysql.FindOne("entniche_user", map[string]interface{}{"phone": phone, "ent_id": entId}, "id,ent_id", "")
|
|
|
- if res == nil || len(*res) == 0 {
|
|
|
- return fmt.Errorf("企业校验异常")
|
|
|
- }
|
|
|
- entUserId := qutil.IntAll((*res)["id"])
|
|
|
- entIdInt := qutil.IntAll((*res)["ent_id"])
|
|
|
-
|
|
|
- exportLock.Lock()
|
|
|
- exportLockMap[entIdInt] = &sync.Mutex{}
|
|
|
- entLock := exportLockMap[entIdInt]
|
|
|
- exportLock.Unlock()
|
|
|
- entLock.Lock()
|
|
|
-
|
|
|
- query := map[string]interface{}{"ent_id": entId, "user_id": entUserId}
|
|
|
- remain_nums, export_nums := 0, 0
|
|
|
- limit := util.Mysql.FindOne("entniche_export_limit", query, "data_limit,remain_nums,export_nums", "")
|
|
|
- if limit != nil {
|
|
|
- remain_nums = qutil.IntAll((*limit)["remain_nums"])
|
|
|
- export_nums = qutil.IntAll((*limit)["export_nums"])
|
|
|
+func (this *dataExportPackStruct) UseEntPack(sess *httpsession.Session, selectId string, exportPhone, exportEmail string) error {
|
|
|
+ sessVal := sess.GetMultiple()
|
|
|
+ entId := qutil.IntAll(sessVal["entId"])
|
|
|
+ entUserId := qutil.IntAll(sessVal["entUserId"])
|
|
|
+ userId := qutil.ObjToString(sessVal["userId"])
|
|
|
+ current := dataexport.GetCurrentCount(util.Mysql, util.Mgo_Qyfw, entId)
|
|
|
+ log.Println("企业总条数", current)
|
|
|
+ //开始去重
|
|
|
+ count, newCount, data := dataexport.GetEntDataExportCount(util.MQFW, util.Mgo_bidding, config.Config.Mongobidding.DbName, config.Config.Elasticsearch,
|
|
|
+ selectId, entId, entUserId, false, g.Cfg().MustGet(context.Background(), "dataPkgRemoveRepeatAddr").String(), config.ExConf.MsgMaxCount)
|
|
|
+ if count <= 0 {
|
|
|
+ log.Println(entId, "没有可导出的数据")
|
|
|
+ return errors.New("没有可导出的数据")
|
|
|
+ }
|
|
|
+ data = dataexport.FormatExportDatas(util.MQFWENT, data, config.Config.WebDomain, "2", entId)
|
|
|
+ xlsxUrl := dataexport.GetXlsx(*data, entId, entUserId, config.ExConf.ExcelEntPath)
|
|
|
+ if xlsxUrl == "" {
|
|
|
+ log.Println(entId, "生成xlsx文件失败")
|
|
|
+ return errors.New("生成xlsx文件失败")
|
|
|
+ }
|
|
|
+ if newCount > 0 {
|
|
|
+ resp, err := resourcesCenterclient.NewResourcesCenter(config.JyResourcesCenterClient).JyExportCharge(context.Background(), &resourcesCenter.ChargeReq{
|
|
|
+ EntId: int64(entId),
|
|
|
+ UserId: userId,
|
|
|
+ EntUserId: int64(entUserId),
|
|
|
+ ExportNum: int64(count),
|
|
|
+ DeductNum: int64(newCount),
|
|
|
+ ChargeType: 0, //扣费方式,0: 企业,1: 个人
|
|
|
+ Remark: fmt.Sprintf(`{"queryId":"%s","excelUrl":"%s","exportNum":%d,"exportTimeStamp":%d,"email":"%s","phone":"%s"}`, selectId, xlsxUrl, count, time.Now().Unix(), exportEmail, exportPhone),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ log.Println(entId, "企业数据流量包扣费失败", err)
|
|
|
+ return err
|
|
|
}
|
|
|
-
|
|
|
- count := 0
|
|
|
- newCount := 0
|
|
|
- data := &[]map[string]interface{}{}
|
|
|
-
|
|
|
- current := dataexport.GetCurrentCount(util.Mysql, util.Mgo_Qyfw, entIdInt)
|
|
|
- log.Println("企业总条数", current)
|
|
|
- //开始去重
|
|
|
- count, newCount, data = dataexport.GetEntDataExportCount(util.MQFW, util.Mgo_bidding, config.Config.Mongobidding.DbName, config.Config.Elasticsearch,
|
|
|
- selectId, entIdInt, entUserId, false, middleGround.JyApiConfig.ApiList.EntDedupUrl, config.ExConf.MsgMaxCount)
|
|
|
-
|
|
|
- if newCount > current {
|
|
|
- return fmt.Errorf("企业账户余额不足")
|
|
|
+ if resp.Data != nil && resp.Data.ChargeResult != 1 {
|
|
|
+ log.Println(entId, "企业数据流量包扣费失败", resp.Data.FailMsg)
|
|
|
+ return errors.New(resp.Data.FailMsg)
|
|
|
+ } else if resp.Code != 1 {
|
|
|
+ if resp.Message != "" {
|
|
|
+ log.Println(entId, "企业数据流量包扣费失败", resp.Message)
|
|
|
+ return errors.New(resp.Message)
|
|
|
+ } else {
|
|
|
+ log.Println(entId, "企业数据流量包扣费失败")
|
|
|
+ return errors.New("企业数据流量包扣费失败")
|
|
|
+ }
|
|
|
}
|
|
|
- if newCount > remain_nums {
|
|
|
- return fmt.Errorf("已超出进入导出上限")
|
|
|
+ }
|
|
|
+ //filter := dataexport.Filters{
|
|
|
+ // FilterId: selectId,
|
|
|
+ //}
|
|
|
+ //filterStr, _ := json.Marshal(filter)
|
|
|
+ //dataexport.SaveExportLog(util.Mysql, entIdInt, entUserId, count, newCount, remain_nums, export_nums, xlsxUrl, "2", string(filterStr), exportPhone, exportEmail)
|
|
|
+ //dataexport.DeductNum(util.Mysql, util.Mgo_Qyfw, entIdInt, newCount)
|
|
|
+ util.Mysql.InsertBatch("jianyu.datapacket_record", []string{"infoids", "type", "master_id", "useid", "query_id", "date", "deduct_num", "export_num", "path", "phone", "mail", "isSenior", "ent_id", "ent_user_id", "operator"}, []interface{}{"", 3, userId, userId, selectId, time.Now().Unix(), newCount, count, xlsxUrl, exportPhone, exportEmail, 2, entId, entUserId, fmt.Sprintf("%s(%s)", qutil.ObjToString(sessVal["entUserName"]), qutil.ObjToString(sessVal["phone"]))})
|
|
|
+ cacheResult(nil, xlsxUrl, fmt.Sprintf("entPackResult_%s_%s", userId, selectId))
|
|
|
+ sendPackExportMail(userId, selectId, exportEmail, xlsxUrl)
|
|
|
+ saveArray := []map[string]interface{}{}
|
|
|
+ for _, v := range *data {
|
|
|
+ saveArray = append(saveArray, v)
|
|
|
+ if len(saveArray) == 200 {
|
|
|
+ util.MQFW.SaveBulk("entdataexport", saveArray...)
|
|
|
+ saveArray = []map[string]interface{}{}
|
|
|
}
|
|
|
- go func() {
|
|
|
- data = dataexport.FormatExportDatas(util.MQFWENT, data, config.Config.WebDomain, "2", entIdInt)
|
|
|
- xlsxUrl := dataexport.GetXlsx(*data, entIdInt, entUserId, config.ExConf.ExcelEntPath)
|
|
|
- if xlsxUrl != "" {
|
|
|
- filter := dataexport.Filters{
|
|
|
- FilterId: selectId,
|
|
|
- }
|
|
|
- filterStr, _ := json.Marshal(filter)
|
|
|
- dataexport.SaveExportLog(util.Mysql, entIdInt, entUserId, count, newCount, remain_nums, export_nums, xlsxUrl, "2", string(filterStr), exportPhone, exportEmail)
|
|
|
- dataexport.DeductNum(util.Mysql, util.Mgo_Qyfw, entIdInt, newCount)
|
|
|
- cacheResult(nil, xlsxUrl, fmt.Sprintf("entPackResult_%s_%s", userId, selectId))
|
|
|
- sendPackExportMail(userId, selectId, exportEmail, xlsxUrl)
|
|
|
- for _, v := range *data {
|
|
|
- util.MQFW.Save("entdataexport", v)
|
|
|
- }
|
|
|
- }
|
|
|
- }()
|
|
|
- entLock.Unlock()
|
|
|
+ }
|
|
|
+ if len(saveArray) > 0 {
|
|
|
+ util.MQFW.SaveBulk("entdataexport", saveArray...)
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// UsePersonalPack 个人数据包扣除
|
|
|
-func (this *dataExportPackStruct) UsePersonalPack(userId, selectId, phone, email string, isSenior bool, checkCount int) error {
|
|
|
+func (this *dataExportPackStruct) UsePersonalPack(sess *httpsession.Session, userId, selectId, phone, email string, isSenior bool, checkCount int) error {
|
|
|
+ sessVal := sess.GetMultiple()
|
|
|
+ entId := qutil.Int64All(sessVal["entId"])
|
|
|
+ entUserId := qutil.Int64All(sessVal["entUserId"])
|
|
|
go GetExcelFile(selectId, checkCount, isSenior, func(excelPath string, exportIds []string) {
|
|
|
deduct, err := usePerPack(userId, checkCount, isSenior, &PersonalUsePackRemark{
|
|
|
QueryId: selectId,
|
|
@@ -489,21 +530,24 @@ func (this *dataExportPackStruct) UsePersonalPack(userId, selectId, phone, email
|
|
|
ExportTimeStamp: time.Now().Unix(),
|
|
|
Phone: phone,
|
|
|
Email: email,
|
|
|
- }, exportIds)
|
|
|
+ }, exportIds, entId, entUserId)
|
|
|
if err == nil {
|
|
|
go util.Mysql.Insert("datapacket_record", map[string]interface{}{
|
|
|
- "infoids": strings.Join(exportIds, ","),
|
|
|
- "type": 2,
|
|
|
- "master_id": userId,
|
|
|
- "useid": userId,
|
|
|
- "query_id": selectId,
|
|
|
- "date": time.Now().Unix(),
|
|
|
- "path": excelPath,
|
|
|
- "deduct_num": deduct,
|
|
|
- "export_num": checkCount,
|
|
|
- "phone": phone,
|
|
|
- "mail": email,
|
|
|
- "isSenior": qutil.If(isSenior, 2, 1),
|
|
|
+ "infoids": strings.Join(exportIds, ","),
|
|
|
+ "type": 2,
|
|
|
+ "master_id": userId,
|
|
|
+ "useid": userId,
|
|
|
+ "query_id": selectId,
|
|
|
+ "date": time.Now().Unix(),
|
|
|
+ "path": excelPath,
|
|
|
+ "deduct_num": deduct,
|
|
|
+ "export_num": checkCount,
|
|
|
+ "phone": phone,
|
|
|
+ "mail": email,
|
|
|
+ "isSenior": qutil.If(isSenior, 2, 1),
|
|
|
+ "ent_id": entId,
|
|
|
+ "ent_user_id": entUserId,
|
|
|
+ "operator": fmt.Sprintf("%s(%s)", qutil.ObjToString(sessVal["entUserName"]), qutil.ObjToString(sessVal["phone"])),
|
|
|
})
|
|
|
//发送邮件
|
|
|
go sendPackExportMail(userId, selectId, email, excelPath)
|
|
@@ -534,6 +578,7 @@ func (this *dataExportPackStruct) UseDailyPack(userId, selectId, phone, email st
|
|
|
if vipStatus.Status <= 0 || vipStatus.DailyNum == 0 {
|
|
|
return fmt.Errorf("非法请求")
|
|
|
}
|
|
|
+ sessVal := session.GetMultiple()
|
|
|
go GetExcelFile(selectId, selectCount, true, func(excelPath string, exportIds []string) {
|
|
|
packetMsg := dataexport.GetDataPacketMsg(qutil.InterfaceToStr(qutil.If(vipStatus.Pid == "", userId, vipStatus.Pid)), vipStatus.DailyNum)
|
|
|
//余额扣除
|
|
@@ -542,7 +587,7 @@ func (this *dataExportPackStruct) UseDailyPack(userId, selectId, phone, email st
|
|
|
return err
|
|
|
}
|
|
|
//保存导出记录
|
|
|
- packetMsg.SaveRecord(util.Mysql, userId, selectId, dataexport.BigMemberDaily, exportIds, excelPath, phone, email)
|
|
|
+ packetMsg.SaveRecord(util.Mysql, userId, selectId, dataexport.BigMemberDaily, exportIds, excelPath, phone, email, qutil.Int64All(sessVal["entId"]), qutil.Int64All(sessVal["entUserId"]), 0, fmt.Sprintf("%s(%s)", qutil.ObjToString(sessVal["entUserName"]), qutil.ObjToString(sessVal["phone"])), "")
|
|
|
//发送邮件
|
|
|
go sendPackExportMail(userId, selectId, email, excelPath)
|
|
|
return nil
|
|
@@ -557,17 +602,135 @@ func (this *dataExportPackStruct) UseDailyPack(userId, selectId, phone, email st
|
|
|
}
|
|
|
|
|
|
// PerRechargeList 个人数据包充值记录
|
|
|
-func (this *dataExportPackStruct) PerRechargeList(userId string, pageNum, pageSize int) (int, []map[string]interface{}, error) {
|
|
|
- if pageSize == 0 {
|
|
|
+func (this *dataExportPackStruct) PerRechargeList(userId, userIds, starttime, endtime string, entId, entDeptId, entRole, account, tpe, pageNum, pageSize int) (int, *[]map[string]interface{}) {
|
|
|
+ if pageSize <= 0 {
|
|
|
pageSize = 10
|
|
|
}
|
|
|
- pageNum += 1
|
|
|
- return perPackRecharge(userId, pageNum, pageSize)
|
|
|
+ if pageNum <= 0 {
|
|
|
+ pageNum = 1
|
|
|
+ }
|
|
|
+ comSql := ``
|
|
|
+ args := []interface{}{}
|
|
|
+ if entRole == 2 {
|
|
|
+ comSql = `from entniche_department_parent b
|
|
|
+ inner join entniche_department_user c on ((b.pid=? or c.dept_id=?) and b.id=c.dept_id)
|
|
|
+ inner join jy_user_center.consume_record a on (c.user_id=a.entUserId) where 1=1`
|
|
|
+ args = append(args, entDeptId, entDeptId)
|
|
|
+ } else {
|
|
|
+ comSql = `from jy_user_center.consume_record a where `
|
|
|
+ if entRole == 1 {
|
|
|
+ comSql += `a.entId=?`
|
|
|
+ args = append(args, entId)
|
|
|
+ } else {
|
|
|
+ comSql += `a.userId=?`
|
|
|
+ args = append(args, userId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ comSql += ` and a.name in ('数据流包','数据流包(合并)')`
|
|
|
+ if account > 0 {
|
|
|
+ comSql += ` and a.accountType=?`
|
|
|
+ if account == 1 || account == 2 {
|
|
|
+ args = append(args, 0)
|
|
|
+ comSql += ` and a.resourceType in (?,?)`
|
|
|
+ if account == 1 {
|
|
|
+ args = append(args, "高级字段包", "高级字段包(合并)")
|
|
|
+ } else {
|
|
|
+ args = append(args, "标准字段包", "标准字段包(合并)")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ args = append(args, account-2)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if userIds != "" {
|
|
|
+ wh, thisArgs := qutil.WhArgs(strings.Split(userIds, ","))
|
|
|
+ comSql += ` and a.entUserId in (` + wh + `)`
|
|
|
+ args = append(args, thisArgs...)
|
|
|
+ }
|
|
|
+ if tpe > 0 {
|
|
|
+ comSql += ` and a.userType=?`
|
|
|
+ args = append(args, tpe-1)
|
|
|
+ }
|
|
|
+ if starttime != "" {
|
|
|
+ comSql += ` and a.createTime>=?`
|
|
|
+ args = append(args, starttime)
|
|
|
+ }
|
|
|
+ if endtime != "" {
|
|
|
+ comSql += ` and a.createTime<=?`
|
|
|
+ args = append(args, endtime)
|
|
|
+ }
|
|
|
+ countSql := `select count(1) as count ` + comSql
|
|
|
+ count := util.Mysql.CountBySql(countSql, args...)
|
|
|
+ //
|
|
|
+ listSql := `select a.createTime,a.operator,a.accountType,a.userType,a.number,a.deductionNumb,a.remarks,a.resourceType,a.source ` + comSql + ` order by a.createTime desc limit ?,?`
|
|
|
+ args = append(args, (pageNum-1)*pageSize, pageSize)
|
|
|
+ list := util.Mysql.SelectBySql(listSql, args...)
|
|
|
+ if list != nil {
|
|
|
+ for _, v := range *list {
|
|
|
+ createTime, err := time.ParseInLocation(time.DateTime, qutil.ObjToString(v["createTime"]), time.Local)
|
|
|
+ if err == nil {
|
|
|
+ v["createTime"] = createTime.Unix()
|
|
|
+ }
|
|
|
+ reasonTitle := ""
|
|
|
+ if qutil.IntAll(v["accountType"]) == 1 {
|
|
|
+ v["account"] = "企业数据流量包"
|
|
|
+ } else {
|
|
|
+ v["account"] = fmt.Sprintf("个人数据流量包(%s)", strings.ReplaceAll(qutil.ObjToString(v["resourceType"]), "(合并)", ""))
|
|
|
+ }
|
|
|
+ switch qutil.IntAll(v["userType"]) {
|
|
|
+ case 0:
|
|
|
+ v["type"] = "消费"
|
|
|
+ v["number"] = fmt.Sprintf("-%d", qutil.IntAll(v["deductionNumb"]))
|
|
|
+ switch qutil.IntAll(v["source"]) {
|
|
|
+ case 0:
|
|
|
+ reasonTitle = "数据自助导出"
|
|
|
+ case 1:
|
|
|
+ reasonTitle = "数据定制导出"
|
|
|
+ case 2:
|
|
|
+ reasonTitle = "数据推送"
|
|
|
+ case 3:
|
|
|
+ reasonTitle = "线下历史数据导出"
|
|
|
+ }
|
|
|
+ case 1:
|
|
|
+ v["type"] = "新增"
|
|
|
+ reasonTitle = "充值数据流量包"
|
|
|
+ var orderDetail PackDetailReturn
|
|
|
+ if json.Unmarshal([]byte(qutil.ObjToString(v["remarks"])), &orderDetail) == nil {
|
|
|
+ var etm string
|
|
|
+ if orderDetail.EndTime > 0 { //通过账号合并合并过来的资源,没有有效期和价格
|
|
|
+ etm = FormatDateByInt64(&orderDetail.EndTime, time.DateOnly)
|
|
|
+ } else if err == nil {
|
|
|
+ etm = createTime.AddDate(orderDetail.ValidYear, 0, 0).Format(time.DateOnly)
|
|
|
+ }
|
|
|
+ if etm != "" {
|
|
|
+ v["reasonContent"] = fmt.Sprintf("有效期至:%s", etm)
|
|
|
+ }
|
|
|
+ if orderDetail.GiveCycle > 0 && orderDetail.DisCountId > 0 { //满赠
|
|
|
+ v["number"] = orderDetail.PackNum - orderDetail.GiveCycle
|
|
|
+ v["giveNumber"] = orderDetail.GiveCycle
|
|
|
+ }
|
|
|
+ }
|
|
|
+ v["number"] = fmt.Sprintf("+%d", qutil.IntAll(v["number"]))
|
|
|
+ case 2:
|
|
|
+ v["type"] = "作废"
|
|
|
+ v["number"] = fmt.Sprintf("-%d", qutil.IntAll(v["number"]))
|
|
|
+ reasonTitle = "未使用权益到期失效"
|
|
|
+ }
|
|
|
+ v["reasonTitle"] = reasonTitle
|
|
|
+ v["operator"] = strings.TrimSuffix(strings.ReplaceAll(qutil.ObjToString(v["operator"]), "(", " "), ")")
|
|
|
+ delete(v, "remarks")
|
|
|
+ delete(v, "resourceType")
|
|
|
+ delete(v, "accountType")
|
|
|
+ delete(v, "userType")
|
|
|
+ delete(v, "deductionNumb")
|
|
|
+ delete(v, "source")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return int(count), list
|
|
|
}
|
|
|
|
|
|
// 查询企业账户余额
|
|
|
-func getCurrEntCount(entName, entPhone string) int {
|
|
|
- current, ok := util.Mgo_Qyfw.FindOne("user", map[string]interface{}{"phone": entPhone, "username": entName})
|
|
|
+func getCurrEntCount(entId int64) int {
|
|
|
+ current, ok := util.Mgo_Qyfw.FindOne("user", map[string]interface{}{"entid": entId})
|
|
|
if current == nil || !ok {
|
|
|
return 0
|
|
|
}
|