相关条件的统计
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_upgrade.go 34 KiB

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