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

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