相关条件的统计
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.

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