相关条件的统计
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

hdl_upgrade.go 37 KiB

pirms 1 gada
pirms 3 mēnešiem
pirms 1 gada
pirms 2 mēnešiem
pirms 10 mēnešiem
pirms 3 mēnešiem
pirms 1 gada
pirms 10 mēnešiem
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 10 mēnešiem
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 10 mēnešiem
pirms 1 gada
pirms 10 mēnešiem
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 mēnesi
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 mēnesi
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 3 mēnešiem
pirms 1 mēnesi
pirms 10 mēnešiem
pirms 1 gada
pirms 9 mēnešiem
pirms 9 mēnešiem
pirms 9 mēnešiem
pirms 9 mēnešiem
pirms 9 mēnešiem
pirms 1 gada
pirms 9 mēnešiem
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 mēnesi
pirms 3 mēnešiem
pirms 3 mēnešiem
pirms 3 mēnešiem
pirms 3 mēnešiem
pirms 1 mēnesi
pirms 3 mēnešiem
pirms 1 gada
pirms 10 mēnešiem
pirms 1 gada
pirms 10 mēnešiem
pirms 1 gada
pirms 10 mēnešiem
pirms 1 gada
pirms 10 mēnešiem
pirms 1 gada
pirms 2 mēnešiem
pirms 2 mēnešiem
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 10 mēnešiem
pirms 1 gada
pirms 10 mēnešiem
pirms 1 gada
pirms 2 mēnešiem
pirms 1 gada
pirms 6 mēnešiem
pirms 5 mēnešiem
pirms 6 mēnešiem
pirms 5 mēnešiem
pirms 6 mēnešiem
pirms 5 mēnešiem
pirms 5 mēnešiem
pirms 5 mēnešiem
pirms 6 mēnešiem
pirms 1 gada
pirms 6 mēnešiem
pirms 1 gada
pirms 10 mēnešiem
pirms 10 mēnešiem
pirms 10 mēnešiem
pirms 10 mēnešiem
pirms 10 mēnešiem
pirms 10 mēnešiem
pirms 10 mēnešiem
pirms 10 mēnešiem
pirms 10 mēnešiem
pirms 10 mēnešiem
pirms 6 mēnešiem
pirms 1 gada
pirms 6 mēnešiem
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 6 mēnešiem
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 5 mēnešiem
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
pirms 1 gada
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. package zyos_go_condition_hdl
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db"
  4. "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db/model"
  5. "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/md"
  6. "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/svc"
  7. zhios_condition_statistics_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils"
  8. db2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db"
  9. "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles"
  10. "encoding/json"
  11. "errors"
  12. "fmt"
  13. "time"
  14. "xorm.io/xorm"
  15. )
  16. func CommUpdate(params map[string]string, blockStarChain string, eg *xorm.Engine, dbName string, user *model.User, DataDetail md.DataDetail) (error, bool, int) {
  17. uid := DataDetail.Uid
  18. //判断有没有审核通过或审核中的记录
  19. has, err := db.UserLevelAuditingFindByUid(eg, zhios_condition_statistics_utils.StrToInt(uid))
  20. if err != nil {
  21. return err, false, 0
  22. }
  23. if has != nil {
  24. var msg = "您已审核通过,请勿重复申请"
  25. if has.State == 1 {
  26. msg = "正在审核中,请稍后再查看"
  27. }
  28. return errors.New(msg), false, 0
  29. }
  30. lv := user.Level
  31. result, AutoAudit := CommUplv(params, blockStarChain, eg, dbName, user, lv, DataDetail)
  32. if result == false {
  33. return errors.New("升级失败,请查看任务是否完成"), false, AutoAudit
  34. }
  35. return nil, result, AutoAudit
  36. }
  37. func CommUplv(params map[string]string, blockStarChain string, eg *xorm.Engine, dbName string, user *model.User, lv int, DataDetail md.DataDetail) (bool, int) {
  38. levelExpireAt := user.LevelExpireAt
  39. levelArriveAt := user.LevelArriveAt
  40. oldLevel := user.Level
  41. uid := zhios_condition_statistics_utils.IntToStr(user.Uid)
  42. result, _, payOrdId := IsCompleteSchemeTask(params, blockStarChain, eg, user, DataDetail.AgentType, DataDetail.IsChangeTime, dbName)
  43. AutoAudit := 0
  44. if result {
  45. level, err := db.UserLevelByID(eg, zhios_condition_statistics_utils.StrToInt(DataDetail.AgentType))
  46. if err != nil || level == nil {
  47. return false, 0
  48. }
  49. date := time.Now()
  50. var auditData = model.UserLevelAudit{
  51. Uid: zhios_condition_statistics_utils.StrToInt(uid),
  52. CurrentLevelId: lv,
  53. NextLevelId: zhios_condition_statistics_utils.StrToInt(DataDetail.AgentType),
  54. ConditionType: 2,
  55. AutoAudit: level.AutoAudit,
  56. DateType: 5,
  57. State: 1,
  58. RelateOid: payOrdId,
  59. CreateAt: date,
  60. UpdateAt: date,
  61. LevelDate: level.LevelDate,
  62. }
  63. has, err := db.UserLevelAuditInsertWithEngine(eg, &auditData)
  64. if has == 0 || err != nil {
  65. return false, 0
  66. }
  67. //自动审核
  68. if level.AutoAudit == 1 {
  69. //写入日志
  70. var log = &model.UserLevelChangeLog{
  71. Uid: user.Uid,
  72. BeforeLv: oldLevel,
  73. AfterLv: zhios_condition_statistics_utils.StrToInt(DataDetail.AgentType),
  74. Time: int(time.Now().Unix()),
  75. BeforeLevelExpireAt: levelExpireAt,
  76. AfterLevelExpireAt: user.LevelExpireAt,
  77. BeforeLevelArriveAt: levelArriveAt,
  78. AfterLevelArriveAt: user.LevelArriveAt,
  79. Type: "level_up",
  80. }
  81. fmt.Println(log)
  82. eg.InsertOne(log)
  83. auditData.State = 2
  84. //审核记录修改
  85. if _, err := db.UserLevelAuditUpdateById(eg, auditData.Id, &auditData, "state"); err != nil {
  86. return false, 0
  87. }
  88. t := time.Now()
  89. var expire time.Time
  90. //订单时间修改
  91. amount := ""
  92. if payOrdId > 0 {
  93. ord, err := db.UserLevelOrderById(eg, zhios_condition_statistics_utils.Int64ToStr(payOrdId))
  94. if err != nil {
  95. return false, 0
  96. }
  97. //过期时间在当前时间之前 并且 创建时间跟过期时间不相等 相等的话是永久会员
  98. if ord.ExpireAt.Unix() < t.Unix() && ord.CreateAt.Format("2006-01-02 15:04:05") != ord.ExpireAt.Format("2006-01-02 15:04:05") && ord.DateType != 4 {
  99. return false, 0
  100. }
  101. amount = ord.PayAmount
  102. switch ord.DateType {
  103. case 1:
  104. // 月
  105. expire = t.AddDate(0, 1, 0)
  106. ord.ExpireAt = expire
  107. case 2:
  108. // 季
  109. expire = t.AddDate(0, 3, 0)
  110. ord.ExpireAt = expire
  111. case 3:
  112. // 年
  113. expire = t.AddDate(1, 0, 0)
  114. ord.ExpireAt = expire
  115. case 4:
  116. expire = t
  117. // 永久(设置为与创建时间相同)
  118. ord.ExpireAt = t
  119. }
  120. if _, err := db.UserLevelOrdUpdateOne(eg, ord); err != nil {
  121. return false, 0
  122. }
  123. }
  124. user.Level = zhios_condition_statistics_utils.StrToInt(DataDetail.AgentType)
  125. user.LevelArriveAt = t
  126. if user.FirstArriveAt.IsZero() {
  127. user.FirstArriveAt = t
  128. }
  129. if payOrdId > 0 {
  130. user.LevelExpireAt = expire
  131. } else {
  132. if level.LevelDate == 0 { // 永久
  133. user.LevelExpireAt = t
  134. } else {
  135. user.LevelExpireAt = t.AddDate(0, level.LevelDate, 0)
  136. }
  137. }
  138. //用户等级修改
  139. // 更新user level 和 过期时间
  140. if _, err := db.UserUpdate(eg, user.Uid, user, "level,level_expire_at,level_arrive_at,first_arrive_at"); err != nil {
  141. return false, 0
  142. }
  143. //升级奖励定制
  144. UpgradeReward(eg, user, zhios_condition_statistics_utils.Int64ToStr(payOrdId), amount)
  145. eg.Where("uid=?", user.Uid).Cols("date").Update(&model.OneCirclesUserLvTime{Date: time.Now()})
  146. AutoAudit = 1
  147. var task model.UserLevelUpgradeTask
  148. eg.Where("scheme_id=? and task_type=22", DataDetail.AgentType).Get(&task)
  149. if task.Id > 0 {
  150. eg.Where("uid=?", user.Uid).Cols("is_not_down").Update(&model.User{IsNotDown: 0})
  151. } else {
  152. eg.Where("uid=?", user.Uid).Cols("is_not_down").Update(&model.User{IsNotDown: 1})
  153. }
  154. }
  155. }
  156. return result, AutoAudit
  157. }
  158. func UpgradeReward(eg *xorm.Engine, user *model.User, oid, amount string) {
  159. buyCouponLvReward, _ := db.SysCfgGetOne(eg, "buy_coupon_lv_reward")
  160. if buyCouponLvReward == nil {
  161. return
  162. }
  163. var args = make([]md.BuyCouponLvRewardList, 0)
  164. json.Unmarshal([]byte(buyCouponLvReward.Val), &args)
  165. for _, v := range args {
  166. if zhios_condition_statistics_utils.StrToInt(v.Id) != user.Level || len(v.Reward) == 0 {
  167. continue
  168. }
  169. for _, v1 := range v.Reward {
  170. if zhios_condition_statistics_utils.StrToFloat64(v1.Amount) <= 0 {
  171. continue
  172. }
  173. if v1.Id == "-1" { //优惠券额度
  174. svc.AddCouponRecord(eg, user, "ordinary", v1.Amount)
  175. }
  176. if zhios_condition_statistics_utils.StrToInt(v1.Id) > 0 {
  177. svc.AddCoin(eg, zhios_condition_statistics_utils.StrToFloat64(v1.Amount), "升级赠送", oid, 1, 188, user.Uid, zhios_condition_statistics_utils.StrToInt(v1.Id), amount)
  178. }
  179. }
  180. }
  181. }
  182. // IsCompleteSchemeTask 根据传入的 level 判断是否可以升级
  183. func IsCompleteSchemeTask(params map[string]string, blockStarChain string, engine *xorm.Engine, user *model.User, level, IsChangeTime, dbName string) (bool, bool, int64) {
  184. uid := zhios_condition_statistics_utils.IntToStr(user.Uid)
  185. userLevel, err := db.UserLevelByID(engine, user.Level)
  186. if err != nil {
  187. return false, false, 0
  188. }
  189. becomeLevel, err := db.UserLevelByID(engine, level)
  190. if err != nil {
  191. return false, false, 0
  192. }
  193. if userLevel == nil {
  194. if level == "" {
  195. level = "1"
  196. }
  197. } else {
  198. if becomeLevel.LevelWeight <= userLevel.LevelWeight && IsChangeTime != "1" {
  199. return false, false, 0
  200. }
  201. }
  202. //获取用户等级方案内容
  203. schemeTasks, err := db.BatchSelectUserLevelUpgradeTasks(engine, map[string]interface{}{
  204. "key": "scheme_id",
  205. "value": becomeLevel.Id,
  206. })
  207. if err != nil {
  208. return false, false, 0
  209. }
  210. return CheckSchemeTasksComplete(params, blockStarChain, engine, schemeTasks, uid, becomeLevel, level, "", dbName)
  211. }
  212. func CheckSchemeTasksComplete(params map[string]string, blockStarChain string, engine *xorm.Engine, tasks *[]model.UserLevelUpgradeTask, uid interface{}, scheme *model.UserLevel, level string, regionalId, dbName string) (bool, bool, int64) {
  213. //分离出 必做/选做 途径(任务组) && 分离出 必做/选做
  214. var tasksGroup []map[string]interface{}
  215. mustTasks := make(map[string][]interface{})
  216. selectTasks := make(map[string][]interface{})
  217. var (
  218. hasLevelPay = false
  219. LevelPayOrdId int64
  220. )
  221. allLvMap := db.UserLevelByAllMap(engine)
  222. for _, item := range *tasks {
  223. var temp = map[string]interface{}{}
  224. temp["id"] = item.Id
  225. temp["pid"] = item.Pid
  226. temp["schemeId"] = item.SchemeId
  227. temp["isMustTask"] = item.IsMustTask
  228. temp["taskType"] = item.TaskType
  229. temp["taskTypeLevelId"] = item.TaskTypeLevelId
  230. temp["withinDays"] = item.WithinDays
  231. temp["finishCount"] = item.FinishCount
  232. temp["payLevels"] = item.PayLevels
  233. temp["finish_task_num"] = item.FinishTaskNum
  234. if item.Pid == 0 && item.IsMustTask == 1 {
  235. temp["is_must"] = "1"
  236. tasksGroup = append(tasksGroup, temp)
  237. }
  238. if item.Pid == 0 && item.IsMustTask != 1 {
  239. temp["is_must"] = "0"
  240. tasksGroup = append(tasksGroup, temp)
  241. }
  242. name := GetTaskName(item.TaskType)
  243. finish, hasPay, payOrdId := GetFinishCount(params, blockStarChain, engine, uid, &item, level, regionalId, allLvMap, dbName)
  244. total := "" // 总共需完成的数
  245. if item.TaskType == 6 {
  246. // 当是付费条件是否,total的指标只能是1
  247. total = "1"
  248. hasLevelPay = hasPay
  249. LevelPayOrdId = payOrdId
  250. } else if item.TaskType == 26 {
  251. total = "1"
  252. } else {
  253. total = item.FinishCount
  254. }
  255. if item.TaskType == 19 {
  256. total = zhios_condition_statistics_utils.IntToStr(zhios_condition_statistics_utils.StrToInt(total) + 1)
  257. }
  258. temp["name"] = name
  259. temp["total"] = total //需完成数
  260. temp["finish"] = finish //已完成数
  261. //fmt.Println("finish:::::::::::::", finish)
  262. //fmt.Println("total:::::::::::::", total)
  263. if zhios_condition_statistics_utils.AnyToFloat64(finish) >= zhios_condition_statistics_utils.AnyToFloat64(total) {
  264. temp["result"] = "1"
  265. } else {
  266. temp["result"] = "0"
  267. }
  268. if item.Pid != 0 && item.IsMustTask == 1 {
  269. mustTasks[zhios_condition_statistics_utils.AnyToString(item.Pid)] = append(mustTasks[zhios_condition_statistics_utils.AnyToString(item.Pid)], temp)
  270. }
  271. if item.Pid != 0 && item.IsMustTask == 0 {
  272. selectTasks[zhios_condition_statistics_utils.AnyToString(item.Pid)] = append(selectTasks[zhios_condition_statistics_utils.AnyToString(item.Pid)], temp)
  273. }
  274. }
  275. alreadyCompleteTasksGroup := 0 // 完成“选做途径”数量
  276. for _, v := range tasksGroup {
  277. fmt.Println(">>>>>>>>>>>>>>>>>>>>", v)
  278. if v["finish_task_num"] == nil {
  279. v["finishCount"] = 0
  280. }
  281. //处理必做途径
  282. if zhios_condition_statistics_utils.AnyToString(v["isMustTask"]) == "1" {
  283. if mustTasks[zhios_condition_statistics_utils.AnyToString(v["id"])] != nil {
  284. needFinishTaskNum := v["finish_task_num"] // 需完成选做任务数
  285. alreadyFinishTaskNum := 0 // 已完成选做任务数
  286. for _, vv := range mustTasks[zhios_condition_statistics_utils.AnyToString(v["id"])] {
  287. tmp := vv.(map[string]interface{})
  288. // 必做任务 且 未完成
  289. if tmp["isMustTask"] == 1 && tmp["result"] != "1" {
  290. return false, hasLevelPay, LevelPayOrdId
  291. }
  292. // 非必做任务 且 已完成
  293. if tmp["isMustTask"] != 1 && tmp["result"] == "1" {
  294. alreadyFinishTaskNum++
  295. }
  296. }
  297. // 需完成选做任务数 大于 已完成选做任务数
  298. if zhios_condition_statistics_utils.AnyToInt64(needFinishTaskNum) > zhios_condition_statistics_utils.AnyToInt64(alreadyFinishTaskNum) {
  299. return false, hasLevelPay, LevelPayOrdId
  300. }
  301. }
  302. }
  303. //处理选做途径
  304. if selectTasks[zhios_condition_statistics_utils.AnyToString(v["id"])] != nil {
  305. needFinishTaskNum := v["finish_task_num"] // 需完成选做任务数
  306. alreadyFinishTaskNum := 0 // 已完成选做任务数
  307. alreadyFinishMustTask := true // 是否已完成必做任务
  308. for _, vv := range selectTasks[zhios_condition_statistics_utils.AnyToString(v["id"])] {
  309. tmp := vv.(map[string]interface{})
  310. // 非必做任务 且 已完成
  311. if tmp["isMustTask"] != "1" && tmp["result"] == "1" {
  312. alreadyFinishTaskNum++
  313. }
  314. // 必做任务 且 未完成
  315. if tmp["isMustTask"] == "1" && tmp["result"] != "1" {
  316. alreadyFinishMustTask = false
  317. }
  318. }
  319. // 已完成必做任务 且 需完成选做任务数 小于等于 已完成选做任务数
  320. if alreadyFinishMustTask && zhios_condition_statistics_utils.AnyToInt64(needFinishTaskNum) <= zhios_condition_statistics_utils.AnyToInt64(alreadyFinishTaskNum) {
  321. alreadyCompleteTasksGroup++
  322. }
  323. }
  324. }
  325. //方案中设定的 需完成“选做途径”数 与 实际完成“选做途径”数 比较
  326. if scheme.ChoosableNum > alreadyCompleteTasksGroup {
  327. return false, hasLevelPay, LevelPayOrdId
  328. }
  329. return true, hasLevelPay, LevelPayOrdId
  330. }
  331. // GetTaskName is 获取任务名
  332. func GetTaskName(id int) string {
  333. switch id {
  334. case 1:
  335. return "累计自购订单总数"
  336. case 2:
  337. return "累计到账佣金"
  338. case 3:
  339. return "累计直推粉丝数量"
  340. case 4:
  341. return "累计团队有效直推人数"
  342. case 5:
  343. return "累计团队符合相应等级的人数"
  344. case 11:
  345. return "累计直推符合相应等级的人数"
  346. case 6:
  347. return "月付价格"
  348. case 7:
  349. return "季付价格"
  350. case 8:
  351. return "年付价格"
  352. case 9:
  353. return "永久价格"
  354. case 10:
  355. return "累计自购消费金额"
  356. case 12:
  357. return "累计团队消费金额"
  358. case 13:
  359. return "累计小市场团队符合等级人数"
  360. case 15:
  361. return "直推前N个店铺营业额"
  362. case 17:
  363. return "团队N条线中各有N个相应等级用户"
  364. case 18:
  365. return "小区累计自营消费金额"
  366. case 20:
  367. return "累计收益(结算)"
  368. case 22:
  369. return "连续活跃"
  370. default:
  371. return "无效名称"
  372. }
  373. }
  374. //
  375. // GetFinishCount is 计算规定时间内完成的指标的数量
  376. func GetFinishCount(params map[string]string, blockStarChain string, engine *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask, level string, regionalId string, allLvMap map[int]*model.UserLevel, dbName string) (string, bool, int64) {
  377. t := time.Now()
  378. hasPay := false
  379. var payOrdId int64
  380. switch task.TaskType {
  381. case 26:
  382. userLevel, _ := db.UserLevelByID(engine, task.TaskTypeLevelId)
  383. user, _ := db2.UserFindByID(engine, uid)
  384. count := "0"
  385. if user != nil && userLevel != nil {
  386. userLevel1, _ := db.UserLevelByID(engine, user.Level)
  387. if userLevel1 != nil && userLevel1.LevelWeight >= userLevel.LevelWeight {
  388. count = "1"
  389. }
  390. }
  391. return count, hasPay, payOrdId
  392. case 20:
  393. var money float64 = 0
  394. shownewFinTotal, _ := db.SysCfgGetOne(engine, "shownew_fin_total2")
  395. if shownewFinTotal != nil && shownewFinTotal.Val == "1" {
  396. var userStatistics model.UserStatistics
  397. engine.Where("uid=?", uid).Get(&userStatistics)
  398. money = zhios_condition_statistics_utils.StrToFloat64(userStatistics.ImportFinTotal) + zhios_condition_statistics_utils.StrToFloat64(userStatistics.FinTotal)
  399. } else {
  400. sumWhere := engine.Where("type=0 and uid=?", uid)
  401. mallSumWhere := engine.Where("uid=? AND type=? and ord_title=?", uid, 1, "订单退款")
  402. deSum2Where := engine.Where("uid=? AND type=? and ord_type=?", uid, 0, "withdraw")
  403. deSum3Where := engine.Where("uid=? AND type=? and ord_title like ?", uid, 1, "%扣除%")
  404. stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location())
  405. etime := t
  406. if task.WithinDays > 0 {
  407. sqlStr4 := fmt.Sprintf(" %s >'%s' AND %s < '%s'", "create_at", stime.Format("2006-01-02 15:04:05"), "create_at", etime.Format("2006-01-02 15:04:05"))
  408. sumWhere = sumWhere.And(sqlStr4)
  409. mallSumWhere = mallSumWhere.And(sqlStr4)
  410. deSum2Where = deSum2Where.And(sqlStr4)
  411. deSum3Where = deSum3Where.And(sqlStr4)
  412. }
  413. sum, _ := sumWhere.Sum(&model.FinUserFlow{}, "amount")
  414. mallSum, _ := mallSumWhere.Sum(&model.FinUserFlow{}, "amount")
  415. deSum2, _ := deSum2Where.Sum(&model.FinUserFlow{}, "amount")
  416. deSum3, _ := deSum3Where.Sum(&model.FinUserFlow{}, "amount")
  417. dsCheck, _ := db.SysCfgGetOne(engine, "ds_check")
  418. money = sum - deSum2 - deSum3 + mallSum
  419. if dsCheck != nil && dsCheck.Val == "1" {
  420. sess := engine.Where("uid=? ", uid).In("state", []string{"1", "2"})
  421. where1 := ""
  422. if task.WithinDays > 0 {
  423. sqlStr4 := fmt.Sprintf(" %s >'%s' AND %s < '%s'", "create_at", stime.Format("2006-01-02 15:04:05"), "create_at", etime.Format("2006-01-02 15:04:05"))
  424. where1 = fmt.Sprintf("AND %s >'%d' AND %s < '%d'", "ol.create_at", stime.Unix(), "ol.create_at", etime.Unix())
  425. sess = sess.And(sqlStr4)
  426. }
  427. withdrawingSuccess, _ := sess.Sum(&model.FinWithdrawApply{}, "amount")
  428. sql := "SELECT cast(SUM(LEFT(olr.amount,LENGTH(olr.amount)-2)) as decimal(50,4)) AS amount FROM ord_list_relate olr JOIN ord_list ol ON olr.oid = ol.ord_id WHERE olr.level=0 and olr.uid = " + zhios_condition_statistics_utils.AnyToString(uid) + " " + where1 + " AND ol.state IN (0,1,2,3) and ol.is_transfer=1;"
  429. nativeString, _ := db.QueryNativeString(engine, sql)
  430. money = withdrawingSuccess
  431. for _, v := range nativeString {
  432. money += zhios_condition_statistics_utils.StrToFloat64(v["amount"])
  433. }
  434. }
  435. }
  436. return zhios_condition_statistics_utils.Float64ToStr(money), hasPay, payOrdId
  437. case 22:
  438. lvTime := db.GetOneCirclesUserLvTime(engine, uid)
  439. stime := time.Date(t.Year(), t.Month(), t.Day()-1, 0, 0, 0, 0, t.Location()).Format("2006-01-02")
  440. if lvTime != nil && lvTime.Date.IsZero() == false {
  441. stime = lvTime.Date.Format("2006-01-02")
  442. }
  443. etime := t.Format("2006-01-02")
  444. if params["is_view"] == "1" {
  445. if lvTime == nil || (lvTime != nil && lvTime.Date.IsZero()) {
  446. stime = t.Format("2006-01-02")
  447. }
  448. etime = time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, t.Location()).Format("2006-01-02")
  449. }
  450. _, days, activity := one_circles.CalcUserContinuousDailyActivityDays(engine, dbName, int(zhios_condition_statistics_utils.AnyToInt64(uid)), stime, etime)
  451. if activity == false {
  452. days = 0
  453. }
  454. return zhios_condition_statistics_utils.IntToStr(days), hasPay, payOrdId
  455. case 23:
  456. // 累计新人免单自购数
  457. total, err := db.OrderListCountByUIDByOrderTypeByTimeNew(engine, uid, "free", task)
  458. if err != nil {
  459. return "", hasPay, payOrdId
  460. }
  461. return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId
  462. case 24:
  463. // 累计自购消费金额
  464. var total float64 = 0
  465. var err error
  466. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) {
  467. total, err = db.OrderListSumByUIDByOrderTypeByTimeNew(engine, uid, "free", task)
  468. if err != nil {
  469. return "", hasPay, payOrdId
  470. }
  471. }
  472. return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2)), hasPay, payOrdId
  473. case 1:
  474. // 累计自购数
  475. total, err := db.OrderListCountByUIDByOrderTypeByTimeNew(engine, uid, "", task)
  476. if err != nil {
  477. return "", hasPay, payOrdId
  478. }
  479. mallTotal, err := db.MallOrdWithCountNew(engine, uid, task)
  480. if err != nil {
  481. return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId
  482. }
  483. total += mallTotal
  484. o2oTotal, err := db.O2oOrdWithCountNew(engine, uid, task)
  485. if err != nil {
  486. return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId
  487. }
  488. total += o2oTotal
  489. b2cTotal, err := db.B2cOrdWithCountNew(engine, uid, task)
  490. if err != nil {
  491. return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId
  492. }
  493. total += b2cTotal
  494. return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId
  495. case 10:
  496. // 累计自购消费金额
  497. var total float64 = 0
  498. var err error
  499. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) {
  500. total, err = db.OrderListSumByUIDByOrderTypeByTimeNew(engine, uid, "", task)
  501. if err != nil {
  502. return "", hasPay, payOrdId
  503. }
  504. }
  505. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "2", "8", "9"}) {
  506. orderType := 0
  507. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"8", "9"}) {
  508. orderType = task.TaskTypePvd
  509. }
  510. secondTotal, err := db.MallOrdWithSumNew(engine, uid, orderType, task)
  511. if err != nil {
  512. return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId
  513. }
  514. total += secondTotal
  515. }
  516. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "3"}) {
  517. secondTotal, err := db.O2oOrdWithSumNew(engine, uid, task)
  518. if err != nil {
  519. return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId
  520. }
  521. total += secondTotal
  522. }
  523. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "4"}) {
  524. secondTotal, err := db.B2cOrdWithSumNew(engine, uid, task)
  525. if err != nil {
  526. return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId
  527. }
  528. total += secondTotal
  529. }
  530. return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2)), hasPay, payOrdId
  531. case 2, 25:
  532. // 累计自购佣金
  533. sum, err := db.OrderRelateListByTimeByStateNew(engine, uid, task)
  534. if err != nil {
  535. return "", hasPay, payOrdId
  536. }
  537. mallSum, err := db.MallOrderRelateListByTimeByStateNew(engine, uid, task)
  538. if err != nil {
  539. return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId
  540. }
  541. sum += mallSum
  542. o2oSum, err := db.O2oOrderRelateListByTimeByStateNew(engine, uid, task)
  543. if err != nil {
  544. return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId
  545. }
  546. sum += o2oSum
  547. b2cSum, err := db.B2cOrderRelateListByTimeByStateNew(engine, uid, task)
  548. if err != nil {
  549. return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId
  550. }
  551. sum += b2cSum
  552. return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId
  553. case 3:
  554. // 累计直推人数
  555. stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-1-02 15:04:05")
  556. etime := t.Format("2006-1-02 15:04:05")
  557. sqlTpl := `SELECT count(*) as count
  558. FROM user_relate as up
  559. LEFT JOIN user as u ON u.uid=up.uid
  560. WHERE %s and up.level=1;`
  561. var condStr string
  562. if task.WithinDays <= 0 {
  563. condStr = fmt.Sprintf("up.parent_uid=%s ", zhios_condition_statistics_utils.AnyToString(uid))
  564. } else {
  565. condStr = fmt.Sprintf("up.parent_uid=%s AND u.create_at>'%s' AND u.create_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), stime, etime)
  566. }
  567. sql := fmt.Sprintf(sqlTpl, condStr)
  568. results, err := db.QueryNativeString(engine, sql)
  569. if err != nil {
  570. return "", hasPay, payOrdId
  571. }
  572. count := ""
  573. if len(results) > 0 {
  574. count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
  575. }
  576. return count, hasPay, payOrdId
  577. case 4:
  578. // 累计团队有效直推人数
  579. stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-1-02 15:04:05")
  580. etime := t.Format("2006-1-02 15:04:05")
  581. sqlTpl := `SELECT count(*) as count
  582. FROM user_relate as up
  583. LEFT JOIN user as u ON u.uid=up.uid
  584. LEFT JOIN user_profile as ups ON up.uid=ups.uid
  585. WHERE %s and up.level=1;`
  586. var condStr string
  587. if task.WithinDays <= 0 {
  588. condStr = fmt.Sprintf("up.parent_uid=%s and ups.is_verify=%d", zhios_condition_statistics_utils.AnyToString(uid), 1)
  589. } else {
  590. condStr = fmt.Sprintf("up.parent_uid=%s AND u.create_at>'%s' AND u.create_at<'%s' and ups.is_verify=%d", zhios_condition_statistics_utils.AnyToString(uid), stime, etime, 1)
  591. }
  592. sql := fmt.Sprintf(sqlTpl, condStr)
  593. results, err := db.QueryNativeString(engine, sql)
  594. if err != nil {
  595. return "", hasPay, payOrdId
  596. }
  597. count := ""
  598. if len(results) > 0 {
  599. count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
  600. }
  601. return count, hasPay, payOrdId
  602. case 5:
  603. // 累计团队符合相应等级的人数
  604. stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-1-02 15:04:05")
  605. etime := t.Format("2006-1-02 15:04:05")
  606. sqlTpl := `SELECT count(*) as count
  607. FROM user_relate as ur
  608. LEFT JOIN user as u ON u.uid=ur.uid
  609. LEFT JOIN user_level ul on u.level=ul.id
  610. WHERE %s;`
  611. levelList := allLvMap[task.TaskTypeLevelId]
  612. levelWeight := 0
  613. if levelList != nil {
  614. levelWeight = levelList.LevelWeight
  615. }
  616. var condStr string
  617. if task.WithinDays <= 0 {
  618. condStr = fmt.Sprintf("ur.parent_uid=%s AND ul.level_weight>='%s' ", zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight))
  619. if blockStarChain == "1" {
  620. condStr = fmt.Sprintf("ur.parent_uid=%s AND ul.level_weight>='%s' ", zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight))
  621. }
  622. } else {
  623. condStr = fmt.Sprintf("ur.parent_uid=%s AND ul.level_weight>='%s' AND u.create_at>'%s' AND u.create_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), stime, etime)
  624. if blockStarChain == "1" {
  625. condStr = fmt.Sprintf("ur.parent_uid=%s AND ul.level_weight>='%s' AND u.level_arrive_at>'%s' AND u.level_arrive_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), stime, etime)
  626. }
  627. }
  628. sql := fmt.Sprintf(sqlTpl, condStr)
  629. fmt.Println(sql)
  630. results, err := db.QueryNativeString(engine, sql)
  631. if err != nil {
  632. return "", hasPay, payOrdId
  633. }
  634. count := ""
  635. if len(results) > 0 {
  636. count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
  637. }
  638. return count, hasPay, payOrdId
  639. case 11:
  640. // 累计直推符合相应等级的人数
  641. stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-1-02 15:04:05")
  642. etime := t.Format("2006-1-02 15:04:05")
  643. sqlTpl := `SELECT count(*) as count
  644. FROM user_relate as ur
  645. LEFT JOIN user as u ON u.uid=ur.uid
  646. LEFT JOIN user_level ul on u.level=ul.id
  647. WHERE %s;`
  648. levelList := allLvMap[task.TaskTypeLevelId]
  649. levelWeight := 0
  650. if levelList != nil {
  651. levelWeight = levelList.LevelWeight
  652. }
  653. var condStr string
  654. if task.WithinDays <= 0 {
  655. condStr = fmt.Sprintf("ur.parent_uid=%s AND ur.level=%s AND ul.level_weight>='%s' ", zhios_condition_statistics_utils.AnyToString(uid), "1", zhios_condition_statistics_utils.IntToStr(levelWeight))
  656. if blockStarChain == "1" {
  657. condStr = fmt.Sprintf("ur.parent_uid=%s AND ur.level=%s AND ul.level_weight>='%s' ", zhios_condition_statistics_utils.AnyToString(uid), "1", zhios_condition_statistics_utils.IntToStr(levelWeight))
  658. }
  659. } else {
  660. condStr = fmt.Sprintf("ur.parent_uid=%s AND ur.level=%s AND ul.level_weight>='%s' AND u.create_at>'%s' AND u.create_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), "1", zhios_condition_statistics_utils.IntToStr(levelWeight), stime, etime)
  661. if blockStarChain == "1" {
  662. condStr = fmt.Sprintf("ur.parent_uid=%s AND ur.level=%s AND ul.level_weight>='%s' AND u.level_arrive_at>'%s' AND u.level_arrive_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), "1", zhios_condition_statistics_utils.IntToStr(levelWeight), stime, etime)
  663. }
  664. }
  665. sql := fmt.Sprintf(sqlTpl, condStr)
  666. fmt.Println(sql)
  667. results, err := db.QueryNativeString(engine, sql)
  668. if err != nil {
  669. return "", hasPay, payOrdId
  670. }
  671. count := ""
  672. if len(results) > 0 {
  673. count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
  674. }
  675. return count, hasPay, payOrdId
  676. case 21:
  677. // 累计所有下级
  678. stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-1-02 15:04:05")
  679. etime := t.Format("2006-1-02 15:04:05")
  680. sqlTpl := `SELECT count(*) as count
  681. FROM user_relate as ur
  682. LEFT JOIN user as u ON u.uid=ur.uid
  683. WHERE %s;`
  684. var condStr string
  685. if task.WithinDays <= 0 {
  686. condStr = fmt.Sprintf("ur.parent_uid=%s ", zhios_condition_statistics_utils.AnyToString(uid))
  687. } else {
  688. condStr = fmt.Sprintf("ur.parent_uid=%s AND u.create_at>'%s' AND u.create_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), stime, etime)
  689. }
  690. sql := fmt.Sprintf(sqlTpl, condStr)
  691. fmt.Println(sql)
  692. results, err := db.QueryNativeString(engine, sql)
  693. if err != nil {
  694. return "", hasPay, payOrdId
  695. }
  696. count := ""
  697. if len(results) > 0 {
  698. count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
  699. }
  700. return count, hasPay, payOrdId
  701. case 12: //累计团队消费金额
  702. var total float64 = 0
  703. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "2", "8", "9"}) {
  704. secondTotal, _ := db.MallOrderTeamRelateListByTimeByStateNew(engine, uid, task)
  705. total += secondTotal
  706. }
  707. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "3"}) {
  708. secondTotal, _ := db.O2oOrderTeamRelateListByTimeByStateNew(engine, uid, task)
  709. total += secondTotal
  710. }
  711. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "4"}) {
  712. secondTotal, _ := db.B2cOrderTeamRelateListByTimeByStateNew(engine, uid, task)
  713. total += secondTotal
  714. }
  715. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) {
  716. secondTotal, _ := db.OrderTeamRelateListByTimeByStateNew(engine, uid, task)
  717. total += secondTotal
  718. }
  719. return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2)), hasPay, payOrdId
  720. case 13:
  721. //小市场团队符合条件人数
  722. smallUid := TotalSmallTeam(engine, zhios_condition_statistics_utils.AnyToString(uid))
  723. sqlTpl := `SELECT count(*) as count
  724. FROM user_relate as ur
  725. LEFT JOIN user as u ON u.uid=ur.uid
  726. WHERE %s;`
  727. condStr := fmt.Sprintf("ur.parent_uid=%s AND u.level='%s' ", smallUid, zhios_condition_statistics_utils.IntToStr(task.TaskTypeLevelId))
  728. sql := fmt.Sprintf(sqlTpl, condStr)
  729. results, err := db.QueryNativeString(engine, sql)
  730. if err != nil {
  731. return "", hasPay, payOrdId
  732. }
  733. count := ""
  734. if len(results) > 0 {
  735. count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
  736. }
  737. return count, hasPay, payOrdId
  738. case 15:
  739. if task.TaskTypeCount == 0 {
  740. return "0", hasPay, payOrdId
  741. }
  742. //stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-01-02 15:04:05")
  743. //etime := t.Format("2006-01-02 15:04:05")
  744. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"1"}) { //o2o
  745. sqlTpl := `SELECT os.id
  746. FROM user_relate ur
  747. LEFT JOIN o2o_merchant om ON ur.uid = om.uid
  748. LEFT JOIN o2o_store os on om.id=os.store_manager
  749. WHERE ur.parent_uid = ?
  750. AND ur.level =1 ORDER BY ur.invite_time asc LIMIT 0,?;
  751. `
  752. var ids = make([]string, 0)
  753. result, err := db.QueryNativeString(engine, sqlTpl, uid, task.TaskTypeCount)
  754. if err == nil {
  755. for _, v := range result {
  756. ids = append(ids, v["id"])
  757. }
  758. }
  759. if len(ids) > 0 {
  760. sum, _ := engine.In("belong_store_id", ids).In("state", []string{"3", "4"}).Sum(&model.O2oOrd{}, "cost_price")
  761. sum1, _ := engine.In("belong_store_id", ids).Sum(&model.O2oPayToMerchant{}, "actual_pay_amount")
  762. return zhios_condition_statistics_utils.Float64ToStrByPrec(sum+sum1, 4), hasPay, payOrdId
  763. }
  764. }
  765. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"2"}) { //b2c
  766. sqlTpl := `SELECT os.id
  767. FROM user_relate ur
  768. LEFT JOIN o2o_merchant om ON ur.uid = om.uid
  769. LEFT JOIN b2c_ord os on om.id=os.store_manager
  770. WHERE ur.parent_uid = ?
  771. AND ur.level =1 ORDER BY ur.invite_time asc LIMIT 0,?;
  772. `
  773. var ids = make([]string, 0)
  774. result, err := db.QueryNativeString(engine, sqlTpl, uid, task.TaskTypeCount)
  775. if err == nil {
  776. for _, v := range result {
  777. ids = append(ids, v["id"])
  778. }
  779. }
  780. if len(ids) > 0 {
  781. sum, _ := engine.In("belong_store_id", ids).In("state", []string{"4"}).Sum(&model.B2cOrd{}, "cost_price")
  782. return zhios_condition_statistics_utils.Float64ToStrByPrec(sum, 4), hasPay, payOrdId
  783. }
  784. }
  785. return "0", hasPay, payOrdId
  786. case 6:
  787. hasPay = true
  788. //TODO::根据 RegionalAgentSchemeTask 表中的 task_id 判断是否完成付费任务
  789. regionalAgentUserOrd, err := db.UserLevelOrderByTaskId(engine, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(task.Id))
  790. if err != nil {
  791. return "", hasPay, payOrdId
  792. }
  793. if regionalAgentUserOrd != nil {
  794. if regionalAgentUserOrd.ExpireAt.Unix() < t.Unix() && regionalAgentUserOrd.CreateAt.Format("2006-01-02 15:04:05") != regionalAgentUserOrd.ExpireAt.Format("2006-01-02 15:04:05") && regionalAgentUserOrd.DateType != 4 {
  795. return "0", hasPay, payOrdId
  796. }
  797. payOrdId = regionalAgentUserOrd.Id
  798. return "1", hasPay, payOrdId
  799. } else {
  800. return "0", hasPay, payOrdId
  801. }
  802. return "1", hasPay, payOrdId
  803. case 17:
  804. stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-01-02 15:04:05")
  805. etime := t.Format("2006-01-02 15:04:05")
  806. // 团队N条线中各有N个相应等级用户
  807. sqlTpl := `select ur.parent_uid,COUNT(*) as count FROM user_relate ur
  808. LEFT JOIN user u on u.uid=ur.uid
  809. LEFT JOIN user_level ul on u.level=ul.id
  810. where ur.parent_uid in(SELECT uid FROM user_relate WHERE parent_uid=%s and level=1 ) and ul.level_weight>=%s %s GROUP BY ur.parent_uid;`
  811. levelList := allLvMap[task.TaskTypeLevelId]
  812. levelWeight := 0
  813. if levelList != nil {
  814. levelWeight = levelList.LevelWeight
  815. }
  816. sql := ""
  817. if task.WithinDays <= 0 {
  818. sql = fmt.Sprintf(sqlTpl, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), "")
  819. } else {
  820. sql = fmt.Sprintf(sqlTpl, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), "and u.level_arrive_at>='"+stime+"' and u.level_arrive_at<='"+etime+"'")
  821. }
  822. results, err := db.QueryNativeString(engine, sql)
  823. if err != nil {
  824. return "", hasPay, payOrdId
  825. }
  826. sqlTpl1 := `select ur.uid FROM user_relate ur
  827. LEFT JOIN user u on u.uid=ur.uid
  828. LEFT JOIN user_level ul on u.level=ul.id
  829. where ur.parent_uid=%s and ur.level=1 and ul.level_weight>=%s %s ;`
  830. sql1 := ""
  831. if task.WithinDays <= 0 {
  832. sql1 = fmt.Sprintf(sqlTpl1, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), "")
  833. } else {
  834. sql1 = fmt.Sprintf(sqlTpl1, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), "and u.level_arrive_at>='"+stime+"' and u.level_arrive_at<='"+etime+"'")
  835. }
  836. results1, err1 := db.QueryNativeString(engine, sql1)
  837. if err1 != nil {
  838. return "", hasPay, payOrdId
  839. }
  840. var firstList = make(map[string]string)
  841. if len(results1) > 0 {
  842. for _, v := range results1 {
  843. firstList[v["uid"]] = "1"
  844. }
  845. }
  846. if len(results) > 0 {
  847. for _, v := range results {
  848. firstList[v["parent_uid"]] = zhios_condition_statistics_utils.IntToStr(zhios_condition_statistics_utils.StrToInt(v["count"]) + zhios_condition_statistics_utils.StrToInt(firstList[v["parent_uid"]]))
  849. }
  850. }
  851. count := 0
  852. if len(firstList) > 0 {
  853. for _, v := range firstList {
  854. if zhios_condition_statistics_utils.StrToInt(v) >= task.TaskTypeSecondCount && task.TaskTypeSecondCount > 0 {
  855. count++
  856. }
  857. }
  858. }
  859. return zhios_condition_statistics_utils.IntToStr(count), hasPay, payOrdId
  860. case 18:
  861. stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Format("2006-01-02 15:04:05")
  862. etime := t.Format("2006-01-02 15:04:05")
  863. // 小区消费金额
  864. sqlTpl := `SELECT SUM(molr.goods_price) as price FROM mall_ord_list_relate molr
  865. LEFT JOIN mall_ord mo on mo.ord_id=molr.oid and mo.state in (%s)
  866. WHERE molr.uid in(SELECT uid FROM user_relate WHERE parent_uid=%s and level=1) %s GROUP BY molr.uid ;`
  867. state := "1,2,3"
  868. if task.TaskTypePvd == 1 {
  869. state = "2,3"
  870. }
  871. if task.TaskTypePvd == 2 {
  872. state = "3"
  873. }
  874. sql := ""
  875. if task.WithinDays <= 0 {
  876. sql = fmt.Sprintf(sqlTpl, state, zhios_condition_statistics_utils.AnyToString(uid), "")
  877. } else {
  878. sql = fmt.Sprintf(sqlTpl, state, zhios_condition_statistics_utils.AnyToString(uid), "and mo.create_time>='"+stime+"' and mo.create_time<='"+etime+"'")
  879. }
  880. results, err := db.QueryNativeString(engine, sql)
  881. if err != nil {
  882. return "", hasPay, payOrdId
  883. }
  884. var count float64 = 0
  885. if len(results) > 0 {
  886. var max float64 = 0
  887. for _, v := range results {
  888. if zhios_condition_statistics_utils.StrToFloat64(v["price"]) > max {
  889. max = zhios_condition_statistics_utils.StrToFloat64(v["price"])
  890. }
  891. count += zhios_condition_statistics_utils.StrToFloat64(v["price"])
  892. }
  893. count -= max
  894. }
  895. return zhios_condition_statistics_utils.Float64ToStrByPrec(count, 2), hasPay, payOrdId
  896. case 19:
  897. teamCountMinData, _ := db.SysCfgGetOne(engine, "team_count_min")
  898. teamCountMin := 15
  899. if teamCountMinData != nil {
  900. teamCountMin = zhios_condition_statistics_utils.StrToInt(teamCountMinData.Val)
  901. }
  902. teamtotal := db.GetUserTeamTotal(engine, zhios_condition_statistics_utils.AnyToString(uid))
  903. var count = 0
  904. if teamtotal != nil && teamtotal.FirstCount >= teamCountMin && teamtotal.SecondCount >= teamCountMin {
  905. count++
  906. }
  907. sql := `SELECT * FROM user_profile up
  908. LEFT JOIN user_team_total utt ON utt.uid=up.uid
  909. WHERE up.parent_uid=? and utt.first_count>=? and utt.second_count>=?
  910. `
  911. nativeString, _ := db.QueryNativeString(engine, sql, zhios_condition_statistics_utils.AnyToString(uid), teamCountMin, teamCountMin)
  912. if len(nativeString) > 0 {
  913. count += len(nativeString)
  914. }
  915. return zhios_condition_statistics_utils.IntToStr(count), hasPay, payOrdId
  916. default:
  917. return "", hasPay, payOrdId
  918. }
  919. }