相关条件的统计
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

962 righe
37 KiB

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