|
@@ -1,100 +1,111 @@
|
|
package entity
|
|
package entity
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "fmt"
|
|
"log"
|
|
"log"
|
|
. "resourceBrushLibrary/config"
|
|
. "resourceBrushLibrary/config"
|
|
|
|
+ "sync"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
"app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenterclient"
|
|
"app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenterclient"
|
|
qu "app.yhyue.com/moapp/jybase/common"
|
|
qu "app.yhyue.com/moapp/jybase/common"
|
|
|
|
+ . "app.yhyue.com/moapp/jybase/date"
|
|
|
|
+ . "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
|
|
)
|
|
)
|
|
|
|
|
|
func OrderResource() {
|
|
func OrderResource() {
|
|
now := time.Now()
|
|
now := time.Now()
|
|
- start := now.Add(-time.Minute * 1).Unix()
|
|
|
|
- //start := now.AddDate(-1, 0, 0).Unix()
|
|
|
|
- log.Println("user", start, now.Unix())
|
|
|
|
|
|
+ end := now.Unix()
|
|
|
|
+ pool := make(chan bool, Config.GivePool)
|
|
|
|
+ wait := &sync.WaitGroup{}
|
|
|
|
+ log.Println("user", TaskConfig.LastTime, end)
|
|
it := Mgo_qfw.GetMgoConn().DB("qfw").C("user").Find(map[string]interface{}{
|
|
it := Mgo_qfw.GetMgoConn().DB("qfw").C("user").Find(map[string]interface{}{
|
|
"i_appid": 2,
|
|
"i_appid": 2,
|
|
"i_vip_status": map[string]interface{}{
|
|
"i_vip_status": map[string]interface{}{
|
|
"$gt": 0,
|
|
"$gt": 0,
|
|
},
|
|
},
|
|
"l_vip_starttime": map[string]interface{}{
|
|
"l_vip_starttime": map[string]interface{}{
|
|
- "$gte": start,
|
|
|
|
- "$lt": now.Unix(),
|
|
|
|
|
|
+ "$gte": TaskConfig.LastTime,
|
|
|
|
+ "$lt": end,
|
|
},
|
|
},
|
|
}).Select(map[string]interface{}{
|
|
}).Select(map[string]interface{}{
|
|
- "_id": 1,
|
|
|
|
- "l_vip_starttime": 1,
|
|
|
|
- }).Sort("_id").Iter()
|
|
|
|
- currentYear, currentMonth, _ := now.Date()
|
|
|
|
- currentLocation := now.Location()
|
|
|
|
- firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation)
|
|
|
|
- lastOfMonth := firstOfMonth.AddDate(0, 1, -1)
|
|
|
|
- endTime := lastOfMonth.Format("2006-01-02")
|
|
|
|
- log.Println("user", it)
|
|
|
|
- for user := make(map[string]interface{}); it.Next(&user); {
|
|
|
|
- //每个用户生成10个附件下载包
|
|
|
|
- userId := qu.InterfaceToStr(user["_id"])
|
|
|
|
- vipTime := time.Unix(qu.Int64All(user["l_vip_starttime"]), 0).Format("2006-01-02")
|
|
|
|
- Purchase.PurchaseUserBalance(resourcesCenterclient.Resources{
|
|
|
|
- AppId: "10000",
|
|
|
|
- UserId: userId,
|
|
|
|
- ResourceType: "附件下载包",
|
|
|
|
- AccountId: userId,
|
|
|
|
- Name: "附件下载包",
|
|
|
|
- Number: number,
|
|
|
|
- Spec: "个",
|
|
|
|
- EndTime: endTime,
|
|
|
|
- VipTime: vipTime,
|
|
|
|
- Model: 3,
|
|
|
|
- })
|
|
|
|
|
|
+ "_id": 1,
|
|
|
|
+ "l_vip_endtime": 1,
|
|
|
|
+ }).Iter()
|
|
|
|
+ endTime := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, 1, -1).Format(Date_Short_Layout)
|
|
|
|
+ for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
|
+ pool <- true
|
|
|
|
+ wait.Add(1)
|
|
|
|
+ go func(user map[string]interface{}) {
|
|
|
|
+ defer qu.Catch()
|
|
|
|
+ defer func() {
|
|
|
|
+ <-pool
|
|
|
|
+ wait.Done()
|
|
|
|
+ }()
|
|
|
|
+ //每个用户生成10个附件下载包
|
|
|
|
+ userId := qu.InterfaceToStr(user["_id"])
|
|
|
|
+ l_vip_endtime := qu.Int64All(user["l_vip_endtime"])
|
|
|
|
+ Purchase.PurchaseUserBalance(resourcesCenterclient.Resources{
|
|
|
|
+ AppId: "10000",
|
|
|
|
+ UserId: userId,
|
|
|
|
+ ResourceType: "附件下载包",
|
|
|
|
+ AccountId: userId,
|
|
|
|
+ Name: "附件下载包",
|
|
|
|
+ Number: number,
|
|
|
|
+ Spec: "个",
|
|
|
|
+ EndTime: endTime,
|
|
|
|
+ VipTime: FormatDateByInt64(&l_vip_endtime, Date_Short_Layout),
|
|
|
|
+ Model: 3,
|
|
|
|
+ })
|
|
|
|
+ }(m)
|
|
}
|
|
}
|
|
//企业版超级订阅处理
|
|
//企业版超级订阅处理
|
|
- log.Println("ent_user", start, now.Unix())
|
|
|
|
|
|
+ log.Println("ent_user", TaskConfig.LastTime, end)
|
|
itEnt := Mgo_qfw.GetMgoConn().DB("qfw").C("ent_user").Find(map[string]interface{}{
|
|
itEnt := Mgo_qfw.GetMgoConn().DB("qfw").C("ent_user").Find(map[string]interface{}{
|
|
"i_vip_status": map[string]interface{}{
|
|
"i_vip_status": map[string]interface{}{
|
|
"$gt": 0,
|
|
"$gt": 0,
|
|
},
|
|
},
|
|
"l_vip_starttime": map[string]interface{}{
|
|
"l_vip_starttime": map[string]interface{}{
|
|
- "$gte": start,
|
|
|
|
- "$lt": now.Unix(),
|
|
|
|
|
|
+ "$gte": TaskConfig.LastTime,
|
|
|
|
+ "$lt": end,
|
|
},
|
|
},
|
|
}).Select(map[string]interface{}{
|
|
}).Select(map[string]interface{}{
|
|
- "_id": 1,
|
|
|
|
- "l_vip_starttime": 1,
|
|
|
|
- "i_entid": 1,
|
|
|
|
- }).Sort("_id").Iter()
|
|
|
|
|
|
+ "_id": 1,
|
|
|
|
+ "l_vip_endtime": 1,
|
|
|
|
+ "i_userid": 1,
|
|
|
|
+ }).Iter()
|
|
log.Println("ent_user", itEnt)
|
|
log.Println("ent_user", itEnt)
|
|
- for user := make(map[string]interface{}); itEnt.Next(&user); {
|
|
|
|
- entId := user["i_entid"]
|
|
|
|
- entData := Mysql.FindOne("entniche_info", map[string]interface{}{
|
|
|
|
- "id": entId,
|
|
|
|
- }, "phone", "")
|
|
|
|
- if entData == nil {
|
|
|
|
- log.Println(entId, "企业已经不存在")
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- phone := (*entData)["phone"]
|
|
|
|
- positionList := Tidb.SelectBySql("select c.id from base_person a INNER JOIN base_user b on a.id=b.person_id and a.contact=? INNER JOIN base_position c on b.id=c.user_id and c.ent_id=? ", phone, entId)
|
|
|
|
- if len(*positionList) > 0 {
|
|
|
|
- userId := qu.InterfaceToStr((*positionList)[0]["id"])
|
|
|
|
|
|
+ for m := make(map[string]interface{}); itEnt.Next(&m); {
|
|
|
|
+ pool <- true
|
|
|
|
+ wait.Add(1)
|
|
|
|
+ go func(user map[string]interface{}) {
|
|
|
|
+ defer qu.Catch()
|
|
|
|
+ defer func() {
|
|
|
|
+ <-pool
|
|
|
|
+ wait.Done()
|
|
|
|
+ }()
|
|
|
|
+ identity := IdentityByEntUserId(Tidb, Mysql, qu.Int64All(user["i_userid"]))
|
|
|
|
+ if identity == nil {
|
|
|
|
+ log.Println("没有找到该用户身份信息", user)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
//每个用户生成10个附件下载包
|
|
//每个用户生成10个附件下载包
|
|
- //企业id查询
|
|
|
|
- vipTime := time.Unix(qu.Int64All(user["l_vip_starttime"]), 0).Format("2006-01-02")
|
|
|
|
|
|
+ l_vip_endtime := qu.Int64All(user["l_vip_endtime"])
|
|
Purchase.PurchaseUserBalance(resourcesCenterclient.Resources{
|
|
Purchase.PurchaseUserBalance(resourcesCenterclient.Resources{
|
|
AppId: "10000",
|
|
AppId: "10000",
|
|
- UserId: userId,
|
|
|
|
|
|
+ UserId: fmt.Sprint(identity.PositionId),
|
|
ResourceType: "附件下载包",
|
|
ResourceType: "附件下载包",
|
|
- AccountId: userId,
|
|
|
|
|
|
+ AccountId: fmt.Sprint(identity.PositionId),
|
|
Name: "附件下载包",
|
|
Name: "附件下载包",
|
|
Number: number,
|
|
Number: number,
|
|
Spec: "个",
|
|
Spec: "个",
|
|
EndTime: endTime,
|
|
EndTime: endTime,
|
|
- VipTime: vipTime,
|
|
|
|
|
|
+ VipTime: FormatDateByInt64(&l_vip_endtime, Date_Short_Layout),
|
|
Model: 3,
|
|
Model: 3,
|
|
})
|
|
})
|
|
- }
|
|
|
|
|
|
+ }(m)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ wait.Wait()
|
|
|
|
+ TaskConfig.LastTime = end
|
|
|
|
+ qu.WriteSysConfig(TaskConfig)
|
|
}
|
|
}
|