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

пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  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. default:
  325. return "无效名称"
  326. }
  327. }
  328. //
  329. // GetFinishCount is 计算规定时间内完成的指标的数量
  330. func GetFinishCount(blockStarChain string, engine *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask, level string, regionalId string, allLvMap map[int]*model.UserLevel) (string, bool, int64) {
  331. t := time.Now()
  332. hasPay := false
  333. var payOrdId int64
  334. switch task.TaskType {
  335. case 1:
  336. // 累计自购数
  337. stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Unix()
  338. etime := t.Unix()
  339. mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location())
  340. mallEtime := t
  341. var total int64
  342. var err error
  343. //联盟结算后的
  344. if task.WithinDays <= 0 {
  345. total, err = db.OrderListCountByUIDByOrderType(engine, uid, 0, []string{"3", "5"})
  346. if err != nil {
  347. return "", hasPay, payOrdId
  348. }
  349. //确认收货的才算
  350. mallTotal, err := db.MallOrdWithCount(engine, uid, 0, []string{"3"})
  351. if err != nil {
  352. return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId
  353. }
  354. total += mallTotal
  355. } else {
  356. total, err = db.OrderListCountByUIDByOrderTypeByTime(engine, uid, 0, []string{"3", "5"}, stime, etime)
  357. if err != nil {
  358. return "", hasPay, payOrdId
  359. }
  360. //确认收货的才算
  361. 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"))
  362. if err != nil {
  363. return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId
  364. }
  365. total += mallTotal
  366. }
  367. return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId
  368. case 10:
  369. // 累计自购消费金额
  370. var total float64 = 0
  371. var err error
  372. if task.WithinDays <= 0 {
  373. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) {
  374. state := []string{"3", "5"}
  375. if task.OrdState == 1 { //已付款
  376. state = []string{"0", "1", "2", "3", "5"}
  377. }
  378. if task.OrdState == 2 { //已完成
  379. state = []string{"1", "2", "3", "5"}
  380. }
  381. total, err = db.OrderListPaidPriceByUIDByOrderType(engine, uid, 0, state)
  382. if err != nil {
  383. return "", hasPay, payOrdId
  384. }
  385. }
  386. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "2", "8", "9"}) {
  387. orderType := 0
  388. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"8", "9"}) {
  389. orderType = task.TaskTypePvd
  390. }
  391. state := []string{"3"}
  392. if task.OrdState == 1 { //已付款
  393. state = []string{"1", "2", "3"}
  394. }
  395. if task.OrdState == 2 { //已完成
  396. state = []string{"3"}
  397. }
  398. //确认收货的才算
  399. mallTotal, err := db.MallOrd(engine, uid, orderType, state)
  400. if err != nil {
  401. return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId
  402. }
  403. total += mallTotal
  404. }
  405. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "3"}) {
  406. state := []string{"3"}
  407. if task.OrdState == 1 { //已付款
  408. state = []string{"1", "2", "3"}
  409. }
  410. if task.OrdState == 2 { //已完成
  411. state = []string{"3"}
  412. }
  413. //确认收货的才算
  414. o2oTotal, err := db.O2oOrd(engine, uid, 0, state)
  415. if err != nil {
  416. return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId
  417. }
  418. total += o2oTotal
  419. o2oTotal1, err := db.O2oOrdPayToMerchant(engine, uid, 0, "1,4")
  420. if err != nil {
  421. return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId
  422. }
  423. total += o2oTotal1
  424. }
  425. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "4"}) {
  426. state := []string{"3"}
  427. if task.OrdState == 1 { //已付款
  428. state = []string{"1", "2", "3"}
  429. }
  430. if task.OrdState == 2 { //已完成
  431. state = []string{"3"}
  432. }
  433. //确认收货的才算
  434. b2cTotal, err := db.B2cOrd(engine, uid, 0, state)
  435. if err != nil {
  436. return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId
  437. }
  438. total += b2cTotal
  439. }
  440. } else {
  441. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) {
  442. stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Unix()
  443. etime := t.Unix()
  444. state := []string{"3", "5"}
  445. if task.OrdState == 1 { //已付款
  446. state = []string{"0", "1", "2", "3", "5"}
  447. }
  448. if task.OrdState == 2 { //已完成
  449. state = []string{"1", "2", "3", "5"}
  450. }
  451. total, err = db.OrderListPaidPriceByUIDByOrderTypeByTime(engine, uid, 0, state, stime, etime)
  452. if err != nil {
  453. return "", hasPay, payOrdId
  454. }
  455. }
  456. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "2", "8", "9"}) {
  457. mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location())
  458. mallEtime := t
  459. orderType := 0
  460. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"8", "9"}) {
  461. orderType = task.TaskTypePvd
  462. }
  463. state := []string{"3"}
  464. if task.OrdState == 1 { //已付款
  465. state = []string{"1", "2", "3"}
  466. }
  467. if task.OrdState == 2 { //已完成
  468. state = []string{"3"}
  469. }
  470. //确认收货的才算
  471. 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))
  472. if err != nil {
  473. return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId
  474. }
  475. total += mallTotal
  476. }
  477. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "3"}) {
  478. mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location())
  479. mallEtime := t
  480. state := []string{"3"}
  481. if task.OrdState == 1 { //已付款
  482. state = []string{"1", "2", "3"}
  483. }
  484. if task.OrdState == 2 { //已完成
  485. state = []string{"3"}
  486. }
  487. //确认收货的才算
  488. o2oTotal, err := db.O2oOrdByTime(engine, uid, 0, state, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05"))
  489. if err != nil {
  490. return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId
  491. }
  492. total += o2oTotal
  493. 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"))
  494. if err != nil {
  495. return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId
  496. }
  497. total += o2oTotal1
  498. }
  499. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "4"}) {
  500. mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location())
  501. mallEtime := t
  502. state := []string{"3"}
  503. if task.OrdState == 1 { //已付款
  504. state = []string{"1", "2", "3"}
  505. }
  506. if task.OrdState == 2 { //已完成
  507. state = []string{"3"}
  508. }
  509. //确认收货的才算
  510. b2cTotal, err := db.B2cOrdByTime(engine, uid, 0, state, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05"))
  511. if err != nil {
  512. return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId
  513. }
  514. total += b2cTotal
  515. }
  516. }
  517. return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2)), hasPay, payOrdId
  518. case 2:
  519. // 累计已结算佣金
  520. stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location()).Unix()
  521. etime := t.Unix()
  522. mallStime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location())
  523. mallEtime := t
  524. var sum float64
  525. if task.WithinDays <= 0 {
  526. // 用户分佣的订单
  527. idAmountMap, err := db.OrderRelateListByState(engine, uid, "3,5")
  528. if err != nil {
  529. return "", hasPay, payOrdId
  530. }
  531. for _, item := range *idAmountMap {
  532. sum += item
  533. }
  534. _, mallSum, err := db.MallOrderRelateListByState(engine, uid, 3)
  535. if err != nil {
  536. return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId
  537. }
  538. sum += mallSum
  539. } else {
  540. // 用户分佣的订单
  541. idAmountMap, err := db.OrderRelateListByTimeByState(engine, uid, "3,5", stime, etime)
  542. if err != nil {
  543. return "", hasPay, payOrdId
  544. }
  545. for _, item := range *idAmountMap {
  546. sum += item
  547. }
  548. _, mallSum, err := db.MallOrderRelateListByTimeByState(engine, uid, 3, mallStime, mallEtime)
  549. if err != nil {
  550. return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId
  551. }
  552. sum += mallSum
  553. }
  554. return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId
  555. case 3:
  556. // 累计直推人数
  557. 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")
  558. etime := t.Format("2006-1-02 15:04:05")
  559. sqlTpl := `SELECT count(*) as count
  560. FROM user_profile as up
  561. LEFT JOIN user as u ON u.uid=up.uid
  562. WHERE %s;`
  563. var condStr string
  564. if task.WithinDays <= 0 {
  565. condStr = fmt.Sprintf("up.parent_uid=%s ", zhios_condition_statistics_utils.AnyToString(uid))
  566. } else {
  567. 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)
  568. }
  569. sql := fmt.Sprintf(sqlTpl, condStr)
  570. results, err := db.QueryNativeString(engine, sql)
  571. if err != nil {
  572. return "", hasPay, payOrdId
  573. }
  574. count := ""
  575. if len(results) > 0 {
  576. count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
  577. }
  578. return count, hasPay, payOrdId
  579. case 4:
  580. // 累计团队有效直推人数
  581. 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")
  582. etime := t.Format("2006-1-02 15:04:05")
  583. sqlTpl := `SELECT count(*) as count
  584. FROM user_profile as up
  585. LEFT JOIN user as u ON u.uid=up.uid
  586. WHERE %s;`
  587. var condStr string
  588. if task.WithinDays <= 0 {
  589. condStr = fmt.Sprintf("up.parent_uid=%s and up.is_verify=%d", zhios_condition_statistics_utils.AnyToString(uid), 1)
  590. } else {
  591. 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)
  592. }
  593. sql := fmt.Sprintf(sqlTpl, condStr)
  594. results, err := db.QueryNativeString(engine, sql)
  595. if err != nil {
  596. return "", hasPay, payOrdId
  597. }
  598. count := ""
  599. if len(results) > 0 {
  600. count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
  601. }
  602. return count, hasPay, payOrdId
  603. case 5:
  604. // 累计团队符合相应等级的人数
  605. 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")
  606. etime := t.Format("2006-1-02 15:04:05")
  607. sqlTpl := `SELECT count(*) as count
  608. FROM user_relate as ur
  609. LEFT JOIN user as u ON u.uid=ur.uid
  610. LEFT JOIN user_level ul on u.level=ul.id
  611. WHERE %s;`
  612. levelList := allLvMap[task.TaskTypeLevelId]
  613. levelWeight := 0
  614. if levelList != nil {
  615. levelWeight = levelList.LevelWeight
  616. }
  617. var condStr string
  618. if task.WithinDays <= 0 {
  619. condStr = fmt.Sprintf("ur.parent_uid=%s AND ul.level_weight>='%s' ", zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight))
  620. if blockStarChain == "1" {
  621. condStr = fmt.Sprintf("ur.parent_uid=%s AND ul.level_weight>='%s' ", zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight))
  622. }
  623. } else {
  624. 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)
  625. if blockStarChain == "1" {
  626. 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)
  627. }
  628. }
  629. sql := fmt.Sprintf(sqlTpl, condStr)
  630. fmt.Println(sql)
  631. results, err := db.QueryNativeString(engine, sql)
  632. if err != nil {
  633. return "", hasPay, payOrdId
  634. }
  635. count := ""
  636. if len(results) > 0 {
  637. count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
  638. }
  639. return count, hasPay, payOrdId
  640. case 11:
  641. // 累计直推符合相应等级的人数
  642. 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")
  643. etime := t.Format("2006-1-02 15:04:05")
  644. sqlTpl := `SELECT count(*) as count
  645. FROM user_relate as ur
  646. LEFT JOIN user as u ON u.uid=ur.uid
  647. LEFT JOIN user_level ul on u.level=ul.id
  648. WHERE %s;`
  649. levelList := allLvMap[task.TaskTypeLevelId]
  650. levelWeight := 0
  651. if levelList != nil {
  652. levelWeight = levelList.LevelWeight
  653. }
  654. var condStr string
  655. if task.WithinDays <= 0 {
  656. 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))
  657. if blockStarChain == "1" {
  658. 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))
  659. }
  660. } else {
  661. 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)
  662. if blockStarChain == "1" {
  663. 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)
  664. }
  665. }
  666. sql := fmt.Sprintf(sqlTpl, condStr)
  667. fmt.Println(sql)
  668. results, err := db.QueryNativeString(engine, sql)
  669. if err != nil {
  670. return "", hasPay, payOrdId
  671. }
  672. count := ""
  673. if len(results) > 0 {
  674. count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
  675. }
  676. return count, hasPay, payOrdId
  677. case 12: //累计团队消费金额
  678. var total float64 = 0
  679. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "2", "8", "9"}) {
  680. sqlTpl := `SELECT SUM(ol.cost_price) AS amount
  681. FROM mall_ord_list_relate olr
  682. JOIN mall_ord ol ON olr.oid = ol.ord_id
  683. WHERE olr.uid = ?
  684. AND ol.state =3 and olr.level>0 %s;
  685. `
  686. str := ""
  687. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"8", "9"}) {
  688. str += " and ol.order_type=" + zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd)
  689. }
  690. sqlTpl = fmt.Sprintf(sqlTpl, str)
  691. result, err := db.QueryNativeString(engine, sqlTpl, uid, str)
  692. if err == nil {
  693. total += zhios_condition_statistics_utils.StrToFloat64(result[0]["amount"])
  694. }
  695. }
  696. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "3"}) {
  697. o2oSqlTpl := `SELECT SUM(ol.cost_price) AS amount
  698. FROM o2o_ord_list_relate olr
  699. JOIN o2o_ord ol ON olr.oid = ol.ord_id
  700. WHERE olr.uid = ?
  701. AND ol.state =3 and olr.level>0;
  702. `
  703. o2oResult, err := db.QueryNativeString(engine, o2oSqlTpl, uid)
  704. if err == nil {
  705. total += zhios_condition_statistics_utils.StrToFloat64(o2oResult[0]["amount"])
  706. }
  707. }
  708. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "4"}) {
  709. b2cSqlTpl := `SELECT SUM(ol.cost_price) AS amount
  710. FROM b2c_ord_list_relate olr
  711. JOIN b2c_ord ol ON olr.oid = ol.ord_id
  712. WHERE olr.uid = ?
  713. AND ol.state =3 and olr.level>0;
  714. `
  715. b2cResult, err := db.QueryNativeString(engine, b2cSqlTpl, uid)
  716. if err == nil {
  717. total += zhios_condition_statistics_utils.StrToFloat64(b2cResult[0]["amount"])
  718. }
  719. }
  720. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) {
  721. guideSqlTpl := `SELECT SUM(ol.paid_price) AS amount
  722. FROM ord_list_relate olr
  723. JOIN ord_list ol ON olr.oid = ol.ord_id
  724. WHERE olr.uid = ?
  725. AND ol.state in(3,5) and olr.level>0;
  726. `
  727. guideResult, err := db.QueryNativeString(engine, guideSqlTpl, uid)
  728. if err == nil {
  729. total += zhios_condition_statistics_utils.StrToFloat64(guideResult[0]["amount"])
  730. }
  731. }
  732. return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2)), hasPay, payOrdId
  733. case 13:
  734. //小市场团队符合条件人数
  735. smallUid := TotalSmallTeam(engine, zhios_condition_statistics_utils.AnyToString(uid))
  736. sqlTpl := `SELECT count(*) as count
  737. FROM user_relate as ur
  738. LEFT JOIN user as u ON u.uid=ur.uid
  739. WHERE %s;`
  740. condStr := fmt.Sprintf("ur.parent_uid=%s AND u.level='%s' ", smallUid, zhios_condition_statistics_utils.IntToStr(task.TaskTypeLevelId))
  741. sql := fmt.Sprintf(sqlTpl, condStr)
  742. results, err := db.QueryNativeString(engine, sql)
  743. if err != nil {
  744. return "", hasPay, payOrdId
  745. }
  746. count := ""
  747. if len(results) > 0 {
  748. count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
  749. }
  750. return count, hasPay, payOrdId
  751. case 15:
  752. if task.TaskTypeCount == 0 {
  753. return "0", hasPay, payOrdId
  754. }
  755. //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")
  756. //etime := t.Format("2006-01-02 15:04:05")
  757. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"1"}) { //o2o
  758. sqlTpl := `SELECT os.id
  759. FROM user_relate ur
  760. LEFT JOIN o2o_merchant om ON ur.uid = om.uid
  761. LEFT JOIN o2o_store os on om.id=os.store_manager
  762. WHERE ur.parent_uid = ?
  763. AND ur.level =1 ORDER BY ur.invite_time asc LIMIT 0,?;
  764. `
  765. var ids = make([]string, 0)
  766. result, err := db.QueryNativeString(engine, sqlTpl, uid, task.TaskTypeCount)
  767. if err == nil {
  768. for _, v := range result {
  769. ids = append(ids, v["id"])
  770. }
  771. }
  772. if len(ids) > 0 {
  773. sum, _ := engine.In("belong_store_id", ids).In("state", []string{"3", "4"}).Sum(&model.O2oOrd{}, "cost_price")
  774. sum1, _ := engine.In("belong_store_id", ids).Sum(&model.O2oPayToMerchant{}, "actual_pay_amount")
  775. return zhios_condition_statistics_utils.Float64ToStrByPrec(sum+sum1, 4), hasPay, payOrdId
  776. }
  777. }
  778. if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"2"}) { //b2c
  779. sqlTpl := `SELECT os.id
  780. FROM user_relate ur
  781. LEFT JOIN o2o_merchant om ON ur.uid = om.uid
  782. LEFT JOIN b2c_ord os on om.id=os.store_manager
  783. WHERE ur.parent_uid = ?
  784. AND ur.level =1 ORDER BY ur.invite_time asc LIMIT 0,?;
  785. `
  786. var ids = make([]string, 0)
  787. result, err := db.QueryNativeString(engine, sqlTpl, uid, task.TaskTypeCount)
  788. if err == nil {
  789. for _, v := range result {
  790. ids = append(ids, v["id"])
  791. }
  792. }
  793. if len(ids) > 0 {
  794. sum, _ := engine.In("belong_store_id", ids).In("state", []string{"4"}).Sum(&model.B2cOrd{}, "cost_price")
  795. return zhios_condition_statistics_utils.Float64ToStrByPrec(sum, 4), hasPay, payOrdId
  796. }
  797. }
  798. return "0", hasPay, payOrdId
  799. case 6:
  800. hasPay = true
  801. //TODO::根据 RegionalAgentSchemeTask 表中的 task_id 判断是否完成付费任务
  802. regionalAgentUserOrd, err := db.UserLevelOrderByTaskId(engine, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(task.Id))
  803. if err != nil {
  804. return "", hasPay, payOrdId
  805. }
  806. if regionalAgentUserOrd != nil {
  807. 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 {
  808. return "0", hasPay, payOrdId
  809. }
  810. payOrdId = regionalAgentUserOrd.Id
  811. return "1", hasPay, payOrdId
  812. } else {
  813. return "0", hasPay, payOrdId
  814. }
  815. return "1", hasPay, payOrdId
  816. case 17:
  817. 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")
  818. etime := t.Format("2006-01-02 15:04:05")
  819. // 团队N条线中各有N个相应等级用户
  820. sqlTpl := `select ur.parent_uid,COUNT(*) as count FROM user_relate ur
  821. LEFT JOIN user u on u.uid=ur.uid
  822. LEFT JOIN user_level ul on u.level=ul.id
  823. 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;`
  824. levelList := allLvMap[task.TaskTypeLevelId]
  825. levelWeight := 0
  826. if levelList != nil {
  827. levelWeight = levelList.LevelWeight
  828. }
  829. sql := ""
  830. if task.WithinDays <= 0 {
  831. sql = fmt.Sprintf(sqlTpl, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), "")
  832. } else {
  833. 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+"'")
  834. }
  835. results, err := db.QueryNativeString(engine, sql)
  836. if err != nil {
  837. return "", hasPay, payOrdId
  838. }
  839. sqlTpl1 := `select ur.uid 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=%s and ur.level=1 and ul.level_weight>=%s %s ;`
  843. sql1 := ""
  844. if task.WithinDays <= 0 {
  845. sql1 = fmt.Sprintf(sqlTpl1, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), "")
  846. } else {
  847. 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+"'")
  848. }
  849. results1, err1 := db.QueryNativeString(engine, sql1)
  850. if err1 != nil {
  851. return "", hasPay, payOrdId
  852. }
  853. var firstList = make(map[string]string)
  854. if len(results1) > 0 {
  855. for _, v := range results1 {
  856. firstList[v["uid"]] = "1"
  857. }
  858. }
  859. if len(results) > 0 {
  860. for _, v := range results {
  861. 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"]]))
  862. }
  863. }
  864. count := 0
  865. if len(firstList) > 0 {
  866. for _, v := range firstList {
  867. if zhios_condition_statistics_utils.StrToInt(v) >= task.TaskTypeSecondCount && task.TaskTypeSecondCount > 0 {
  868. count++
  869. }
  870. }
  871. }
  872. return zhios_condition_statistics_utils.IntToStr(count), hasPay, payOrdId
  873. case 18:
  874. 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")
  875. etime := t.Format("2006-01-02 15:04:05")
  876. // 小区消费金额
  877. sqlTpl := `SELECT SUM(molr.goods_price) as price FROM mall_ord_list_relate molr
  878. LEFT JOIN mall_ord mo on mo.ord_id=molr.oid and mo.state in (%s)
  879. WHERE molr.uid in(SELECT uid FROM user_relate WHERE parent_uid=%s and level=1) %s GROUP BY molr.uid ;`
  880. state := "1,2,3"
  881. if task.TaskTypePvd == 1 {
  882. state = "2,3"
  883. }
  884. if task.TaskTypePvd == 2 {
  885. state = "3"
  886. }
  887. sql := ""
  888. if task.WithinDays <= 0 {
  889. sql = fmt.Sprintf(sqlTpl, state, zhios_condition_statistics_utils.AnyToString(uid), "")
  890. } else {
  891. sql = fmt.Sprintf(sqlTpl, state, zhios_condition_statistics_utils.AnyToString(uid), "and mo.create_time>='"+stime+"' and mo.create_time<='"+etime+"'")
  892. }
  893. results, err := db.QueryNativeString(engine, sql)
  894. if err != nil {
  895. return "", hasPay, payOrdId
  896. }
  897. var count float64 = 0
  898. if len(results) > 0 {
  899. var max float64 = 0
  900. for _, v := range results {
  901. if zhios_condition_statistics_utils.StrToFloat64(v["price"]) > max {
  902. max = zhios_condition_statistics_utils.StrToFloat64(v["price"])
  903. }
  904. count += zhios_condition_statistics_utils.StrToFloat64(v["price"])
  905. }
  906. count -= max
  907. }
  908. return zhios_condition_statistics_utils.Float64ToStrByPrec(count, 2), hasPay, payOrdId
  909. case 19:
  910. teamCountMinData, _ := db.SysCfgGetOne(engine, "team_count_min")
  911. teamCountMin := 15
  912. if teamCountMinData != nil {
  913. teamCountMin = zhios_condition_statistics_utils.StrToInt(teamCountMinData.Val)
  914. }
  915. teamtotal := db.GetUserTeamTotal(engine, zhios_condition_statistics_utils.AnyToString(uid))
  916. var count = 0
  917. if teamtotal != nil && teamtotal.FirstCount >= teamCountMin && teamtotal.SecondCount >= teamCountMin {
  918. count++
  919. }
  920. sql := `SELECT * FROM user_profile up
  921. LEFT JOIN user_team_total utt ON utt.uid=up.uid
  922. WHERE up.parent_uid=? and utt.first_count>=? and utt.second_count>=?
  923. `
  924. nativeString, _ := db.QueryNativeString(engine, sql, zhios_condition_statistics_utils.AnyToString(uid), teamCountMin, teamCountMin)
  925. if len(nativeString) > 0 {
  926. count += len(nativeString)
  927. }
  928. return zhios_condition_statistics_utils.IntToStr(count), hasPay, payOrdId
  929. default:
  930. return "", hasPay, payOrdId
  931. }
  932. }