|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963 |
- package zyos_go_condition_hdl
-
- import (
- "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db/model"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/md"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/svc"
- zhios_condition_statistics_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils"
- db2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles"
- "encoding/json"
- "errors"
- "fmt"
- "time"
- "xorm.io/xorm"
- )
-
- func CommUpdate(params map[string]string, blockStarChain string, eg *xorm.Engine, dbName string, user *model.User, DataDetail md.DataDetail) (error, bool, int) {
- uid := DataDetail.Uid
- //判断有没有审核通过或审核中的记录
- has, err := db.UserLevelAuditingFindByUid(eg, zhios_condition_statistics_utils.StrToInt(uid))
- if err != nil {
- return err, false, 0
- }
- if has != nil {
- var msg = "您已审核通过,请勿重复申请"
- if has.State == 1 {
- msg = "正在审核中,请稍后再查看"
- }
- return errors.New(msg), false, 0
- }
- lv := user.Level
- result, AutoAudit := CommUplv(params, blockStarChain, eg, dbName, user, lv, DataDetail)
- if result == false {
- return errors.New("升级失败,请查看任务是否完成"), false, AutoAudit
- }
- return nil, result, AutoAudit
- }
- func CommUplv(params map[string]string, blockStarChain string, eg *xorm.Engine, dbName string, user *model.User, lv int, DataDetail md.DataDetail) (bool, int) {
- levelExpireAt := user.LevelExpireAt
- levelArriveAt := user.LevelArriveAt
- oldLevel := user.Level
- uid := zhios_condition_statistics_utils.IntToStr(user.Uid)
- result, _, payOrdId := IsCompleteSchemeTask(params, blockStarChain, eg, user, DataDetail.AgentType, DataDetail.IsChangeTime, dbName)
- AutoAudit := 0
- if result {
- level, err := db.UserLevelByID(eg, zhios_condition_statistics_utils.StrToInt(DataDetail.AgentType))
- if err != nil || level == nil {
- return false, 0
- }
- date := time.Now()
- var auditData = model.UserLevelAudit{
- Uid: zhios_condition_statistics_utils.StrToInt(uid),
- CurrentLevelId: lv,
- NextLevelId: zhios_condition_statistics_utils.StrToInt(DataDetail.AgentType),
- ConditionType: 2,
- AutoAudit: level.AutoAudit,
- DateType: 5,
- State: 1,
- RelateOid: payOrdId,
- CreateAt: date,
- UpdateAt: date,
- LevelDate: level.LevelDate,
- }
- has, err := db.UserLevelAuditInsertWithEngine(eg, &auditData)
- if has == 0 || err != nil {
- return false, 0
- }
- //自动审核
- if level.AutoAudit == 1 {
- //写入日志
- var log = &model.UserLevelChangeLog{
- Uid: user.Uid,
- BeforeLv: oldLevel,
- AfterLv: zhios_condition_statistics_utils.StrToInt(DataDetail.AgentType),
- Time: int(time.Now().Unix()),
- BeforeLevelExpireAt: levelExpireAt,
- AfterLevelExpireAt: user.LevelExpireAt,
- BeforeLevelArriveAt: levelArriveAt,
- AfterLevelArriveAt: user.LevelArriveAt,
- Type: "level_up",
- }
- fmt.Println(log)
- eg.InsertOne(log)
- auditData.State = 2
- //审核记录修改
- if _, err := db.UserLevelAuditUpdateById(eg, auditData.Id, &auditData, "state"); err != nil {
- return false, 0
- }
- t := time.Now()
- var expire time.Time
- //订单时间修改
- amount := ""
- if payOrdId > 0 {
- ord, err := db.UserLevelOrderById(eg, zhios_condition_statistics_utils.Int64ToStr(payOrdId))
- if err != nil {
- return false, 0
- }
- //过期时间在当前时间之前 并且 创建时间跟过期时间不相等 相等的话是永久会员
- 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 {
- return false, 0
- }
- amount = ord.PayAmount
- switch ord.DateType {
- case 1:
- // 月
- expire = t.AddDate(0, 1, 0)
- ord.ExpireAt = expire
- case 2:
- // 季
- expire = t.AddDate(0, 3, 0)
- ord.ExpireAt = expire
- case 3:
- // 年
- expire = t.AddDate(1, 0, 0)
- ord.ExpireAt = expire
- case 4:
- expire = t
- // 永久(设置为与创建时间相同)
- ord.ExpireAt = t
- }
- if _, err := db.UserLevelOrdUpdateOne(eg, ord); err != nil {
- return false, 0
- }
- }
- user.Level = zhios_condition_statistics_utils.StrToInt(DataDetail.AgentType)
- user.LevelArriveAt = t
- if user.FirstArriveAt.IsZero() {
- user.FirstArriveAt = t
- }
- if payOrdId > 0 {
- user.LevelExpireAt = expire
- } else {
- if level.LevelDate == 0 { // 永久
- user.LevelExpireAt = t
- } else {
- user.LevelExpireAt = t.AddDate(0, level.LevelDate, 0)
- }
- }
- //用户等级修改
- // 更新user level 和 过期时间
- if _, err := db.UserUpdate(eg, user.Uid, user, "level,level_expire_at,level_arrive_at,first_arrive_at"); err != nil {
- return false, 0
- }
- //升级奖励定制
- UpgradeReward(eg, user, zhios_condition_statistics_utils.Int64ToStr(payOrdId), amount)
- eg.Where("uid=?", user.Uid).Cols("date").Update(&model.OneCirclesUserLvTime{Date: time.Now()})
- AutoAudit = 1
- var task model.UserLevelUpgradeTask
- eg.Where("scheme_id=? and task_type=22", DataDetail.AgentType).Get(&task)
- if task.Id > 0 {
- eg.Where("uid=?", user.Uid).Cols("is_not_down").Update(&model.User{IsNotDown: 0})
- } else {
- eg.Where("uid=?", user.Uid).Cols("is_not_down").Update(&model.User{IsNotDown: 1})
- }
- }
-
- }
- return result, AutoAudit
- }
- func UpgradeReward(eg *xorm.Engine, user *model.User, oid, amount string) {
- buyCouponLvReward, _ := db.SysCfgGetOne(eg, "buy_coupon_lv_reward")
- if buyCouponLvReward == nil {
- return
- }
- var args = make([]md.BuyCouponLvRewardList, 0)
- json.Unmarshal([]byte(buyCouponLvReward.Val), &args)
- for _, v := range args {
- if zhios_condition_statistics_utils.StrToInt(v.Id) != user.Level || len(v.Reward) == 0 {
- continue
- }
- for _, v1 := range v.Reward {
- if zhios_condition_statistics_utils.StrToFloat64(v1.Amount) <= 0 {
- continue
- }
- if v1.Id == "-1" { //优惠券额度
- svc.AddCouponRecord(eg, user, "ordinary", v1.Amount)
- }
- if zhios_condition_statistics_utils.StrToInt(v1.Id) > 0 {
- svc.AddCoin(eg, zhios_condition_statistics_utils.StrToFloat64(v1.Amount), "升级赠送", oid, 1, 188, user.Uid, zhios_condition_statistics_utils.StrToInt(v1.Id), amount)
- }
- }
- }
-
- }
-
- // IsCompleteSchemeTask 根据传入的 level 判断是否可以升级
- func IsCompleteSchemeTask(params map[string]string, blockStarChain string, engine *xorm.Engine, user *model.User, level, IsChangeTime, dbName string) (bool, bool, int64) {
- uid := zhios_condition_statistics_utils.IntToStr(user.Uid)
- userLevel, err := db.UserLevelByID(engine, user.Level)
- if err != nil {
- return false, false, 0
- }
- becomeLevel, err := db.UserLevelByID(engine, level)
- if err != nil {
- return false, false, 0
- }
- if userLevel == nil {
- if level == "" {
- level = "1"
- }
- } else {
- if becomeLevel.LevelWeight <= userLevel.LevelWeight && IsChangeTime != "1" {
- return false, false, 0
- }
- }
- //获取用户等级方案内容
-
- schemeTasks, err := db.BatchSelectUserLevelUpgradeTasks(engine, map[string]interface{}{
- "key": "scheme_id",
- "value": becomeLevel.Id,
- })
- if err != nil {
- return false, false, 0
- }
-
- return CheckSchemeTasksComplete(params, blockStarChain, engine, schemeTasks, uid, becomeLevel, level, "", dbName)
- }
-
- func CheckSchemeTasksComplete(params map[string]string, blockStarChain string, engine *xorm.Engine, tasks *[]model.UserLevelUpgradeTask, uid interface{}, scheme *model.UserLevel, level string, regionalId, dbName string) (bool, bool, int64) {
- //分离出 必做/选做 途径(任务组) && 分离出 必做/选做
- var tasksGroup []map[string]interface{}
- mustTasks := make(map[string][]interface{})
- selectTasks := make(map[string][]interface{})
- var (
- hasLevelPay = false
- LevelPayOrdId int64
- )
- allLvMap := db.UserLevelByAllMap(engine)
- for _, item := range *tasks {
- var temp = map[string]interface{}{}
- temp["id"] = item.Id
- temp["pid"] = item.Pid
- temp["schemeId"] = item.SchemeId
- temp["isMustTask"] = item.IsMustTask
- temp["taskType"] = item.TaskType
- temp["taskTypeLevelId"] = item.TaskTypeLevelId
- temp["withinDays"] = item.WithinDays
- temp["finishCount"] = item.FinishCount
- temp["payLevels"] = item.PayLevels
- temp["finish_task_num"] = item.FinishTaskNum
-
- if item.Pid == 0 && item.IsMustTask == 1 {
- temp["is_must"] = "1"
- tasksGroup = append(tasksGroup, temp)
- }
- if item.Pid == 0 && item.IsMustTask != 1 {
- temp["is_must"] = "0"
- tasksGroup = append(tasksGroup, temp)
- }
-
- name := GetTaskName(item.TaskType)
-
- finish, hasPay, payOrdId := GetFinishCount(params, blockStarChain, engine, uid, &item, level, regionalId, allLvMap, dbName)
- total := "" // 总共需完成的数
- if item.TaskType == 6 {
- // 当是付费条件是否,total的指标只能是1
- total = "1"
- hasLevelPay = hasPay
- LevelPayOrdId = payOrdId
- } else if item.TaskType == 26 {
- total = "1"
- } else {
- total = item.FinishCount
- }
- if item.TaskType == 19 {
- total = zhios_condition_statistics_utils.IntToStr(zhios_condition_statistics_utils.StrToInt(total) + 1)
- }
- temp["name"] = name
- temp["total"] = total //需完成数
- temp["finish"] = finish //已完成数
- //fmt.Println("finish:::::::::::::", finish)
- //fmt.Println("total:::::::::::::", total)
- if zhios_condition_statistics_utils.AnyToFloat64(finish) >= zhios_condition_statistics_utils.AnyToFloat64(total) {
- temp["result"] = "1"
- } else {
- temp["result"] = "0"
- }
- if item.Pid != 0 && item.IsMustTask == 1 {
- mustTasks[zhios_condition_statistics_utils.AnyToString(item.Pid)] = append(mustTasks[zhios_condition_statistics_utils.AnyToString(item.Pid)], temp)
- }
- if item.Pid != 0 && item.IsMustTask == 0 {
- selectTasks[zhios_condition_statistics_utils.AnyToString(item.Pid)] = append(selectTasks[zhios_condition_statistics_utils.AnyToString(item.Pid)], temp)
- }
- }
-
- alreadyCompleteTasksGroup := 0 // 完成“选做途径”数量
- for _, v := range tasksGroup {
- fmt.Println(">>>>>>>>>>>>>>>>>>>>", v)
- if v["finish_task_num"] == nil {
- v["finishCount"] = 0
- }
-
- //处理必做途径
- if zhios_condition_statistics_utils.AnyToString(v["isMustTask"]) == "1" {
- if mustTasks[zhios_condition_statistics_utils.AnyToString(v["id"])] != nil {
- needFinishTaskNum := v["finish_task_num"] // 需完成选做任务数
- alreadyFinishTaskNum := 0 // 已完成选做任务数
- for _, vv := range mustTasks[zhios_condition_statistics_utils.AnyToString(v["id"])] {
- tmp := vv.(map[string]interface{})
- // 必做任务 且 未完成
- if tmp["isMustTask"] == 1 && tmp["result"] != "1" {
- return false, hasLevelPay, LevelPayOrdId
- }
- // 非必做任务 且 已完成
- if tmp["isMustTask"] != 1 && tmp["result"] == "1" {
- alreadyFinishTaskNum++
- }
- }
- // 需完成选做任务数 大于 已完成选做任务数
- if zhios_condition_statistics_utils.AnyToInt64(needFinishTaskNum) > zhios_condition_statistics_utils.AnyToInt64(alreadyFinishTaskNum) {
- return false, hasLevelPay, LevelPayOrdId
- }
- }
- }
- //处理选做途径
- if selectTasks[zhios_condition_statistics_utils.AnyToString(v["id"])] != nil {
- needFinishTaskNum := v["finish_task_num"] // 需完成选做任务数
- alreadyFinishTaskNum := 0 // 已完成选做任务数
- alreadyFinishMustTask := true // 是否已完成必做任务
- for _, vv := range selectTasks[zhios_condition_statistics_utils.AnyToString(v["id"])] {
- tmp := vv.(map[string]interface{})
- // 非必做任务 且 已完成
- if tmp["isMustTask"] != "1" && tmp["result"] == "1" {
- alreadyFinishTaskNum++
- }
- // 必做任务 且 未完成
- if tmp["isMustTask"] == "1" && tmp["result"] != "1" {
- alreadyFinishMustTask = false
- }
- }
-
- // 已完成必做任务 且 需完成选做任务数 小于等于 已完成选做任务数
- if alreadyFinishMustTask && zhios_condition_statistics_utils.AnyToInt64(needFinishTaskNum) <= zhios_condition_statistics_utils.AnyToInt64(alreadyFinishTaskNum) {
- alreadyCompleteTasksGroup++
- }
- }
- }
-
- //方案中设定的 需完成“选做途径”数 与 实际完成“选做途径”数 比较
- if scheme.ChoosableNum > alreadyCompleteTasksGroup {
- return false, hasLevelPay, LevelPayOrdId
- }
- return true, hasLevelPay, LevelPayOrdId
- }
-
- // GetTaskName is 获取任务名
- func GetTaskName(id int) string {
- switch id {
- case 1:
- return "累计自购订单总数"
- case 2:
- return "累计到账佣金"
- case 3:
- return "累计直推粉丝数量"
- case 4:
- return "累计团队有效直推人数"
- case 5:
- return "累计团队符合相应等级的人数"
- case 11:
- return "累计直推符合相应等级的人数"
- case 6:
- return "月付价格"
- case 7:
- return "季付价格"
- case 8:
- return "年付价格"
- case 9:
- return "永久价格"
- case 10:
- return "累计自购消费金额"
- case 12:
- return "累计团队消费金额"
- case 13:
- return "累计小市场团队符合等级人数"
- case 15:
- return "直推前N个店铺营业额"
- case 17:
- return "团队N条线中各有N个相应等级用户"
- case 18:
- return "小区累计自营消费金额"
- case 20:
- return "累计收益(结算)"
- case 22:
- return "连续活跃"
- default:
- return "无效名称"
- }
- }
-
- //
-
- // GetFinishCount is 计算规定时间内完成的指标的数量
- func GetFinishCount(params map[string]string, blockStarChain string, engine *xorm.Engine, uid interface{}, task *model.UserLevelUpgradeTask, level string, regionalId string, allLvMap map[int]*model.UserLevel, dbName string) (string, bool, int64) {
- t := time.Now()
- hasPay := false
- var payOrdId int64
- switch task.TaskType {
- case 26:
- userLevel, _ := db.UserLevelByID(engine, task.TaskTypeLevelId)
- user, _ := db2.UserFindByID(engine, uid)
- count := "0"
- if user != nil && userLevel != nil {
- userLevel1, _ := db.UserLevelByID(engine, user.Level)
- if userLevel1 != nil && userLevel1.LevelWeight >= userLevel.LevelWeight {
- count = "1"
- }
- }
- return count, hasPay, payOrdId
- case 20:
- var money float64 = 0
- shownewFinTotal, _ := db.SysCfgGetOne(engine, "shownew_fin_total2")
- if shownewFinTotal != nil && shownewFinTotal.Val == "1" {
- var userStatistics model.UserStatistics
- engine.Where("uid=?", uid).Get(&userStatistics)
- money = zhios_condition_statistics_utils.StrToFloat64(userStatistics.ImportFinTotal) + zhios_condition_statistics_utils.StrToFloat64(userStatistics.FinTotal)
- } else {
- sumWhere := engine.Where("type=0 and uid=?", uid)
- mallSumWhere := engine.Where("uid=? AND type=? and ord_title=?", uid, 1, "订单退款")
- deSum2Where := engine.Where("uid=? AND type=? and ord_type=?", uid, 0, "withdraw")
- deSum3Where := engine.Where("uid=? AND type=? and ord_title like ?", uid, 1, "%扣除%")
- stime := time.Date(t.Year(), t.Month(), t.Day()-task.WithinDays, t.Hour(), 0, 0, 0, t.Location())
- etime := t
- if task.WithinDays > 0 {
- sqlStr4 := fmt.Sprintf(" %s >'%s' AND %s < '%s'", "create_at", stime.Format("2006-01-02 15:04:05"), "create_at", etime.Format("2006-01-02 15:04:05"))
- sumWhere = sumWhere.And(sqlStr4)
- mallSumWhere = mallSumWhere.And(sqlStr4)
- deSum2Where = deSum2Where.And(sqlStr4)
- deSum3Where = deSum3Where.And(sqlStr4)
- }
- sum, _ := sumWhere.Sum(&model.FinUserFlow{}, "amount")
- mallSum, _ := mallSumWhere.Sum(&model.FinUserFlow{}, "amount")
- deSum2, _ := deSum2Where.Sum(&model.FinUserFlow{}, "amount")
- deSum3, _ := deSum3Where.Sum(&model.FinUserFlow{}, "amount")
- dsCheck, _ := db.SysCfgGetOne(engine, "ds_check")
- money = sum - deSum2 - deSum3 + mallSum
- if dsCheck != nil && dsCheck.Val == "1" {
- sess := engine.Where("uid=? ", uid).In("state", []string{"1", "2"})
- where1 := ""
- if task.WithinDays > 0 {
- sqlStr4 := fmt.Sprintf(" %s >'%s' AND %s < '%s'", "create_at", stime.Format("2006-01-02 15:04:05"), "create_at", etime.Format("2006-01-02 15:04:05"))
- where1 = fmt.Sprintf("AND %s >'%d' AND %s < '%d'", "ol.create_at", stime.Unix(), "ol.create_at", etime.Unix())
- sess = sess.And(sqlStr4)
- }
- withdrawingSuccess, _ := sess.Sum(&model.FinWithdrawApply{}, "amount")
- sql := "SELECT cast(SUM(LEFT(olr.amount,LENGTH(olr.amount)-2)) as decimal(50,4)) AS amount FROM ord_list_relate olr JOIN ord_list ol ON olr.oid = ol.ord_id WHERE olr.level=0 and olr.uid = " + zhios_condition_statistics_utils.AnyToString(uid) + " " + where1 + " AND ol.state IN (0,1,2,3) and ol.is_transfer=1;"
- nativeString, _ := db.QueryNativeString(engine, sql)
- money = withdrawingSuccess
- for _, v := range nativeString {
- money += zhios_condition_statistics_utils.StrToFloat64(v["amount"])
- }
- }
- }
-
- return zhios_condition_statistics_utils.Float64ToStr(money), hasPay, payOrdId
- case 22:
- lvTime := db.GetOneCirclesUserLvTime(engine, uid)
- stime := time.Date(t.Year(), t.Month(), t.Day()-1, 0, 0, 0, 0, t.Location()).Format("2006-01-02")
- if lvTime != nil && lvTime.Date.IsZero() == false {
- stime = lvTime.Date.Format("2006-01-02")
- }
- etime := t.Format("2006-01-02")
- if params["is_view"] == "1" {
- if lvTime == nil || (lvTime != nil && lvTime.Date.IsZero()) {
- stime = t.Format("2006-01-02")
- }
- etime = time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, t.Location()).Format("2006-01-02")
- }
- _, days, activity := one_circles.CalcUserContinuousDailyActivityDays(engine, dbName, int(zhios_condition_statistics_utils.AnyToInt64(uid)), stime, etime)
- if activity == false {
- days = 0
- }
- return zhios_condition_statistics_utils.IntToStr(days), hasPay, payOrdId
- case 23:
- // 累计新人免单自购数
- total, err := db.OrderListCountByUIDByOrderTypeByTimeNew(engine, uid, "free", task)
- if err != nil {
- return "", hasPay, payOrdId
- }
- return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId
- case 24:
- // 累计自购消费金额
-
- var total float64 = 0
- var err error
- if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) {
- total, err = db.OrderListSumByUIDByOrderTypeByTimeNew(engine, uid, "free", task)
- if err != nil {
- return "", hasPay, payOrdId
- }
- }
- return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2)), hasPay, payOrdId
-
- case 1:
- // 累计自购数
- total, err := db.OrderListCountByUIDByOrderTypeByTimeNew(engine, uid, "", task)
- if err != nil {
- return "", hasPay, payOrdId
- }
- mallTotal, err := db.MallOrdWithCountNew(engine, uid, task)
- if err != nil {
- return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId
- }
- total += mallTotal
- o2oTotal, err := db.O2oOrdWithCountNew(engine, uid, task)
- if err != nil {
- return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId
- }
- total += o2oTotal
- b2cTotal, err := db.B2cOrdWithCountNew(engine, uid, task)
- if err != nil {
- return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId
- }
- total += b2cTotal
- return zhios_condition_statistics_utils.Int64ToStr(total), hasPay, payOrdId
- case 10:
- // 累计自购消费金额
-
- var total float64 = 0
- var err error
- if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) {
- total, err = db.OrderListSumByUIDByOrderTypeByTimeNew(engine, uid, "", task)
- if err != nil {
- return "", hasPay, payOrdId
- }
- }
- if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "2", "8", "9"}) {
- orderType := 0
- if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"8", "9"}) {
- orderType = task.TaskTypePvd
- }
- secondTotal, err := db.MallOrdWithSumNew(engine, uid, orderType, task)
- if err != nil {
- return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId
- }
- total += secondTotal
- }
- if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "3"}) {
- secondTotal, err := db.O2oOrdWithSumNew(engine, uid, task)
- if err != nil {
- return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId
- }
- total += secondTotal
- }
- if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "4"}) {
- secondTotal, err := db.B2cOrdWithSumNew(engine, uid, task)
- if err != nil {
- return zhios_condition_statistics_utils.Float64ToStr(total), hasPay, payOrdId
- }
- total += secondTotal
- }
-
- return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2)), hasPay, payOrdId
-
- case 2, 25:
- // 累计自购佣金
- sum, err := db.OrderRelateListByTimeByStateNew(engine, uid, task)
- if err != nil {
- return "", hasPay, payOrdId
- }
-
- mallSum, err := db.MallOrderRelateListByTimeByStateNew(engine, uid, task)
- if err != nil {
- return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId
- }
- sum += mallSum
- o2oSum, err := db.O2oOrderRelateListByTimeByStateNew(engine, uid, task)
- if err != nil {
- return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId
- }
- sum += o2oSum
- b2cSum, err := db.B2cOrderRelateListByTimeByStateNew(engine, uid, task)
- if err != nil {
- return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId
- }
- sum += b2cSum
-
- return zhios_condition_statistics_utils.Float64ToStr(sum), hasPay, payOrdId
- case 3:
- // 累计直推人数
- 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")
- etime := t.Format("2006-1-02 15:04:05")
- sqlTpl := `SELECT count(*) as count
- FROM user_relate as up
- LEFT JOIN user as u ON u.uid=up.uid
- WHERE %s and up.level=1;`
- var condStr string
- if task.WithinDays <= 0 {
- condStr = fmt.Sprintf("up.parent_uid=%s ", zhios_condition_statistics_utils.AnyToString(uid))
- } else {
- 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)
- }
- sql := fmt.Sprintf(sqlTpl, condStr)
- results, err := db.QueryNativeString(engine, sql)
- if err != nil {
- return "", hasPay, payOrdId
- }
- count := ""
- if len(results) > 0 {
- count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
- }
- return count, hasPay, payOrdId
- case 4:
- // 累计团队有效直推人数
- 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")
- etime := t.Format("2006-1-02 15:04:05")
- sqlTpl := `SELECT count(*) as count
- FROM user_relate as up
- LEFT JOIN user as u ON u.uid=up.uid
- LEFT JOIN user_profile as ups ON up.uid=ups.uid
- WHERE %s and up.level=1;`
- var condStr string
- if task.WithinDays <= 0 {
- condStr = fmt.Sprintf("up.parent_uid=%s and ups.is_verify=%d", zhios_condition_statistics_utils.AnyToString(uid), 1)
-
- } else {
- condStr = fmt.Sprintf("up.parent_uid=%s AND u.create_at>'%s' AND u.create_at<'%s' and ups.is_verify=%d", zhios_condition_statistics_utils.AnyToString(uid), stime, etime, 1)
- }
- sql := fmt.Sprintf(sqlTpl, condStr)
- results, err := db.QueryNativeString(engine, sql)
- if err != nil {
- return "", hasPay, payOrdId
- }
- count := ""
- if len(results) > 0 {
- count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
- }
- return count, hasPay, payOrdId
- case 5:
- // 累计团队符合相应等级的人数
- 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")
- etime := t.Format("2006-1-02 15:04:05")
- sqlTpl := `SELECT count(*) as count
- FROM user_relate as ur
- LEFT JOIN user as u ON u.uid=ur.uid
- LEFT JOIN user_level ul on u.level=ul.id
- WHERE %s;`
- levelList := allLvMap[task.TaskTypeLevelId]
- levelWeight := 0
- if levelList != nil {
- levelWeight = levelList.LevelWeight
- }
- var condStr string
- if task.WithinDays <= 0 {
- condStr = fmt.Sprintf("ur.parent_uid=%s AND ul.level_weight>='%s' ", zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight))
- if blockStarChain == "1" {
- condStr = fmt.Sprintf("ur.parent_uid=%s AND ul.level_weight>='%s' ", zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight))
- }
- } else {
- 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)
- if blockStarChain == "1" {
- 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)
- }
- }
- sql := fmt.Sprintf(sqlTpl, condStr)
- fmt.Println(sql)
- results, err := db.QueryNativeString(engine, sql)
- if err != nil {
-
- return "", hasPay, payOrdId
- }
- count := ""
- if len(results) > 0 {
- count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
- }
- return count, hasPay, payOrdId
- case 11:
- // 累计直推符合相应等级的人数
- 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")
- etime := t.Format("2006-1-02 15:04:05")
-
- sqlTpl := `SELECT count(*) as count
- FROM user_relate as ur
- LEFT JOIN user as u ON u.uid=ur.uid
- LEFT JOIN user_level ul on u.level=ul.id
- WHERE %s;`
- levelList := allLvMap[task.TaskTypeLevelId]
- levelWeight := 0
- if levelList != nil {
- levelWeight = levelList.LevelWeight
- }
- var condStr string
- if task.WithinDays <= 0 {
- 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))
- if blockStarChain == "1" {
- 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))
- }
- } else {
- 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)
-
- if blockStarChain == "1" {
- 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)
- }
- }
- sql := fmt.Sprintf(sqlTpl, condStr)
- fmt.Println(sql)
-
- results, err := db.QueryNativeString(engine, sql)
- if err != nil {
-
- return "", hasPay, payOrdId
- }
- count := ""
- if len(results) > 0 {
- count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
- }
- return count, hasPay, payOrdId
- case 21:
- // 累计所有下级
- 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")
- etime := t.Format("2006-1-02 15:04:05")
-
- sqlTpl := `SELECT count(*) as count
- FROM user_relate as ur
- LEFT JOIN user as u ON u.uid=ur.uid
- WHERE %s;`
- var condStr string
- if task.WithinDays <= 0 {
- condStr = fmt.Sprintf("ur.parent_uid=%s ", zhios_condition_statistics_utils.AnyToString(uid))
- } else {
- condStr = fmt.Sprintf("ur.parent_uid=%s AND u.create_at>'%s' AND u.create_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), stime, etime)
- }
- sql := fmt.Sprintf(sqlTpl, condStr)
- fmt.Println(sql)
-
- results, err := db.QueryNativeString(engine, sql)
- if err != nil {
-
- return "", hasPay, payOrdId
- }
- count := ""
- if len(results) > 0 {
- count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
- }
- return count, hasPay, payOrdId
- case 12: //累计团队消费金额
- var total float64 = 0
- if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "2", "8", "9"}) {
- secondTotal, _ := db.MallOrderTeamRelateListByTimeByStateNew(engine, uid, task)
- total += secondTotal
- }
- if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "3"}) {
-
- secondTotal, _ := db.O2oOrderTeamRelateListByTimeByStateNew(engine, uid, task)
- total += secondTotal
- }
- if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "4"}) {
-
- secondTotal, _ := db.B2cOrderTeamRelateListByTimeByStateNew(engine, uid, task)
- total += secondTotal
- }
- if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"0", "1"}) {
- secondTotal, _ := db.OrderTeamRelateListByTimeByStateNew(engine, uid, task)
- total += secondTotal
- }
- return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2)), hasPay, payOrdId
- case 13:
- //小市场团队符合条件人数
- smallUid := TotalSmallTeam(engine, zhios_condition_statistics_utils.AnyToString(uid))
- sqlTpl := `SELECT count(*) as count
- FROM user_relate as ur
- LEFT JOIN user as u ON u.uid=ur.uid
- WHERE %s;`
- condStr := fmt.Sprintf("ur.parent_uid=%s AND u.level='%s' ", smallUid, zhios_condition_statistics_utils.IntToStr(task.TaskTypeLevelId))
- sql := fmt.Sprintf(sqlTpl, condStr)
- results, err := db.QueryNativeString(engine, sql)
- if err != nil {
-
- return "", hasPay, payOrdId
- }
- count := ""
- if len(results) > 0 {
- count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
- }
- return count, hasPay, payOrdId
- case 15:
- if task.TaskTypeCount == 0 {
- return "0", hasPay, payOrdId
- }
- //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")
- //etime := t.Format("2006-01-02 15:04:05")
- if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"1"}) { //o2o
- sqlTpl := `SELECT os.id
- FROM user_relate ur
- LEFT JOIN o2o_merchant om ON ur.uid = om.uid
- LEFT JOIN o2o_store os on om.id=os.store_manager
- WHERE ur.parent_uid = ?
- AND ur.level =1 ORDER BY ur.invite_time asc LIMIT 0,?;
- `
- var ids = make([]string, 0)
- result, err := db.QueryNativeString(engine, sqlTpl, uid, task.TaskTypeCount)
- if err == nil {
- for _, v := range result {
- ids = append(ids, v["id"])
- }
- }
- if len(ids) > 0 {
- sum, _ := engine.In("belong_store_id", ids).In("state", []string{"3", "4"}).Sum(&model.O2oOrd{}, "cost_price")
- sum1, _ := engine.In("belong_store_id", ids).Sum(&model.O2oPayToMerchant{}, "actual_pay_amount")
- return zhios_condition_statistics_utils.Float64ToStrByPrec(sum+sum1, 4), hasPay, payOrdId
- }
- }
- if zhios_condition_statistics_utils.InArr(zhios_condition_statistics_utils.IntToStr(task.TaskTypePvd), []string{"2"}) { //b2c
- sqlTpl := `SELECT os.id
- FROM user_relate ur
- LEFT JOIN o2o_merchant om ON ur.uid = om.uid
- LEFT JOIN b2c_ord os on om.id=os.store_manager
- WHERE ur.parent_uid = ?
- AND ur.level =1 ORDER BY ur.invite_time asc LIMIT 0,?;
- `
- var ids = make([]string, 0)
- result, err := db.QueryNativeString(engine, sqlTpl, uid, task.TaskTypeCount)
- if err == nil {
- for _, v := range result {
- ids = append(ids, v["id"])
- }
- }
- if len(ids) > 0 {
- sum, _ := engine.In("belong_store_id", ids).In("state", []string{"4"}).Sum(&model.B2cOrd{}, "cost_price")
- return zhios_condition_statistics_utils.Float64ToStrByPrec(sum, 4), hasPay, payOrdId
- }
- }
- return "0", hasPay, payOrdId
- case 6:
- hasPay = true
- //TODO::根据 RegionalAgentSchemeTask 表中的 task_id 判断是否完成付费任务
- regionalAgentUserOrd, err := db.UserLevelOrderByTaskId(engine, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(task.Id))
- if err != nil {
- return "", hasPay, payOrdId
- }
- if regionalAgentUserOrd != nil {
- 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 {
- return "0", hasPay, payOrdId
- }
- payOrdId = regionalAgentUserOrd.Id
- return "1", hasPay, payOrdId
- } else {
- return "0", hasPay, payOrdId
- }
-
- return "1", hasPay, payOrdId
- case 17:
- 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")
- etime := t.Format("2006-01-02 15:04:05")
- // 团队N条线中各有N个相应等级用户
- sqlTpl := `select ur.parent_uid,COUNT(*) as count FROM user_relate ur
- LEFT JOIN user u on u.uid=ur.uid
- LEFT JOIN user_level ul on u.level=ul.id
- 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;`
-
- levelList := allLvMap[task.TaskTypeLevelId]
- levelWeight := 0
- if levelList != nil {
- levelWeight = levelList.LevelWeight
- }
- sql := ""
- if task.WithinDays <= 0 {
- sql = fmt.Sprintf(sqlTpl, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), "")
- } else {
- 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+"'")
- }
-
- results, err := db.QueryNativeString(engine, sql)
- if err != nil {
-
- return "", hasPay, payOrdId
- }
- sqlTpl1 := `select ur.uid FROM user_relate ur
- LEFT JOIN user u on u.uid=ur.uid
- LEFT JOIN user_level ul on u.level=ul.id
- where ur.parent_uid=%s and ur.level=1 and ul.level_weight>=%s %s ;`
- sql1 := ""
- if task.WithinDays <= 0 {
- sql1 = fmt.Sprintf(sqlTpl1, zhios_condition_statistics_utils.AnyToString(uid), zhios_condition_statistics_utils.IntToStr(levelWeight), "")
- } else {
- 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+"'")
- }
- results1, err1 := db.QueryNativeString(engine, sql1)
- if err1 != nil {
- return "", hasPay, payOrdId
- }
- var firstList = make(map[string]string)
- if len(results1) > 0 {
- for _, v := range results1 {
- firstList[v["uid"]] = "1"
- }
- }
- if len(results) > 0 {
- for _, v := range results {
- 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"]]))
- }
- }
- count := 0
- if len(firstList) > 0 {
- for _, v := range firstList {
- if zhios_condition_statistics_utils.StrToInt(v) >= task.TaskTypeSecondCount && task.TaskTypeSecondCount > 0 {
- count++
- }
- }
- }
- return zhios_condition_statistics_utils.IntToStr(count), hasPay, payOrdId
- case 18:
- 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")
- etime := t.Format("2006-01-02 15:04:05")
- // 小区消费金额
- sqlTpl := `SELECT SUM(molr.goods_price) as price FROM mall_ord_list_relate molr
- LEFT JOIN mall_ord mo on mo.ord_id=molr.oid and mo.state in (%s)
- WHERE molr.uid in(SELECT uid FROM user_relate WHERE parent_uid=%s and level=1) %s GROUP BY molr.uid ;`
- state := "1,2,3"
- if task.TaskTypePvd == 1 {
- state = "2,3"
- }
- if task.TaskTypePvd == 2 {
- state = "3"
- }
- sql := ""
- if task.WithinDays <= 0 {
- sql = fmt.Sprintf(sqlTpl, state, zhios_condition_statistics_utils.AnyToString(uid), "")
- } else {
- sql = fmt.Sprintf(sqlTpl, state, zhios_condition_statistics_utils.AnyToString(uid), "and mo.create_time>='"+stime+"' and mo.create_time<='"+etime+"'")
- }
- results, err := db.QueryNativeString(engine, sql)
- if err != nil {
-
- return "", hasPay, payOrdId
- }
- var count float64 = 0
- if len(results) > 0 {
- var max float64 = 0
- for _, v := range results {
- if zhios_condition_statistics_utils.StrToFloat64(v["price"]) > max {
- max = zhios_condition_statistics_utils.StrToFloat64(v["price"])
- }
- count += zhios_condition_statistics_utils.StrToFloat64(v["price"])
- }
- count -= max
- }
-
- return zhios_condition_statistics_utils.Float64ToStrByPrec(count, 2), hasPay, payOrdId
- case 19:
- teamCountMinData, _ := db.SysCfgGetOne(engine, "team_count_min")
- teamCountMin := 15
- if teamCountMinData != nil {
- teamCountMin = zhios_condition_statistics_utils.StrToInt(teamCountMinData.Val)
- }
- teamtotal := db.GetUserTeamTotal(engine, zhios_condition_statistics_utils.AnyToString(uid))
- var count = 0
- if teamtotal != nil && teamtotal.FirstCount >= teamCountMin && teamtotal.SecondCount >= teamCountMin {
- count++
- }
- sql := `SELECT * FROM user_profile up
- LEFT JOIN user_team_total utt ON utt.uid=up.uid
- WHERE up.parent_uid=? and utt.first_count>=? and utt.second_count>=?
- `
- nativeString, _ := db.QueryNativeString(engine, sql, zhios_condition_statistics_utils.AnyToString(uid), teamCountMin, teamCountMin)
- if len(nativeString) > 0 {
- count += len(nativeString)
- }
- return zhios_condition_statistics_utils.IntToStr(count), hasPay, payOrdId
- default:
- return "", hasPay, payOrdId
- }
- }
|