|
- 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"
- zhios_condition_statistics_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils"
- zhios_condition_statistics_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/utils/logx"
- "fmt"
- "time"
- "xorm.io/xorm"
- )
-
- // 累计自购数
- func OwnBuyTotal(engine *xorm.Engine, uid interface{}, task map[string]string, t time.Time) string {
-
- stime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), t.Hour(), 0, 0, 0, t.Location()).Unix()
- etime := t.Unix()
- //联盟结算后的
- total, err := db.OrderListCountByUIDByOrderTypeByTime(engine, uid, 0, []string{"1", "2", "3", "5"}, stime, etime)
- if err != nil {
- zhios_condition_statistics_logx.Warn(err)
- return ""
- }
- mallStime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), t.Hour(), 0, 0, 0, t.Location())
- mallEtime := t
- //确认收货的才算
- 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"))
- if err != nil {
- zhios_condition_statistics_logx.Warn(err)
- return zhios_condition_statistics_utils.Int64ToStr(total)
- }
- total += mallTotal
- //确认收货的才算
- b2cTotal, err := db.B2cOrdByTimeWithCount(engine, uid, 0, []string{"3", "4"}, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05"))
- if err != nil {
- zhios_condition_statistics_logx.Warn(err)
- return zhios_condition_statistics_utils.Int64ToStr(total)
- }
- total += b2cTotal
- return zhios_condition_statistics_utils.Int64ToStr(total)
- }
-
- // 累计已结算佣金
- func SettleOrderSum(engine *xorm.Engine, uid interface{}, task map[string]string, t time.Time) string {
-
- stime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), t.Hour(), 0, 0, 0, t.Location()).Unix()
- etime := t.Unix()
- // 用户分佣的订单
- idAmountMap, err := db.OrderRelateListByTimeByState(engine, uid, []string{"1", "2", "3", "5"}, stime, etime)
- if err != nil {
- zhios_condition_statistics_logx.Warn(err)
- return ""
- }
- var sum float64
- for _, item := range *idAmountMap {
- sum += item
- }
- mallStime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), t.Hour(), 0, 0, 0, t.Location())
- mallEtime := t
- _, mallSum, err := db.MallOrderRelateListByTimeByState(engine, uid, 3, mallStime, mallEtime)
- if err != nil {
- zhios_condition_statistics_logx.Warn(err)
- return zhios_condition_statistics_utils.Float64ToStr(sum)
- }
- sum += mallSum
- return zhios_condition_statistics_utils.Float64ToStr(sum)
- }
-
- func ExtendCount(engine *xorm.Engine, uid interface{}, task map[string]string, t time.Time) string {
-
- // 累计直推人数
- stime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), 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;`
- 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 {
- zhios_condition_statistics_logx.Warn(err)
- return ""
- }
- count := ""
- if len(results) > 0 {
- count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
- }
- return count
- }
- func TeamCount(engine *xorm.Engine, uid interface{}, task map[string]string, t time.Time) string {
-
- // 累计团队有效直推人数
- stime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), 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;`
- 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 {
- zhios_condition_statistics_logx.Warn(err)
- return ""
- }
- count := ""
- if len(results) > 0 {
- count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
- }
- return count
- }
-
- // 累计团队符合相应等级的人数
-
- func TeamByLvCount(engine *xorm.Engine, uid interface{}, task map[string]string, t time.Time) string {
-
- stime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), 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;`
- condStr := fmt.Sprintf("ur.parent_uid=%s AND u.level='%s' AND u.create_at>'%s' AND u.create_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), task["task_type_level_id"], stime, etime)
- sql := fmt.Sprintf(sqlTpl, condStr)
- results, err := db.QueryNativeString(engine, sql)
- if err != nil {
- zhios_condition_statistics_logx.Warn(err)
- return ""
- }
- count := ""
- if len(results) > 0 {
- count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
- }
- return count
- }
-
- // 累计直推符合相应等级的人数
-
- func ExtendByLvCount(engine *xorm.Engine, uid interface{}, task map[string]string, t time.Time) string {
-
- stime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), 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;`
- condStr := fmt.Sprintf("ur.parent_uid=%s AND ur.level=%s AND u.level='%s' AND u.create_at>'%s' AND u.create_at<'%s'", zhios_condition_statistics_utils.AnyToString(uid), "1", task["TaskTypeLevelId"], stime, etime)
- sql := fmt.Sprintf(sqlTpl, condStr)
- results, err := db.QueryNativeString(engine, sql)
- if err != nil {
- zhios_condition_statistics_logx.Warn(err)
- return ""
- }
- count := ""
- if len(results) > 0 {
- count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
- }
- return count
- }
-
- // 累计自购消费金额
-
- func OwnbuySum(engine *xorm.Engine, uid interface{}, task map[string]string, t time.Time) string {
- var total float64 = 0
- var err error
- if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"0", "1"}) {
- stime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), t.Hour(), 0, 0, 0, t.Location()).Unix()
- etime := t.Unix()
- total, err = db.OrderListPaidPriceByUIDByOrderTypeByTime(engine, uid, 0, []string{"1", "2", "3", "5"}, stime, etime, 0)
- if err != nil {
- zhios_condition_statistics_logx.Warn(err)
- return ""
- }
-
- }
- if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"0", "2", "8", "9"}) {
- mallStime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), t.Hour(), 0, 0, 0, t.Location())
- mallEtime := t
- orderType := 0
- if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"8", "9"}) {
- orderType = zhios_condition_statistics_utils.StrToInt(task["task_type_pvd"])
- }
- //确认收货的才算
- mallTotal, err := db.MallOrdByTime(engine, uid, orderType, []string{"3"}, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05"), "", 0)
- if err != nil {
- zhios_condition_statistics_logx.Warn(err)
- return zhios_condition_statistics_utils.Float64ToStr(total)
- }
- total += mallTotal
- }
- if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"0", "3"}) {
- mallStime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), t.Hour(), 0, 0, 0, t.Location())
- mallEtime := t
- //确认收货的才算
- o2oTotal, err := db.O2oOrdByTime(engine, uid, 0, []string{"3"}, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05"), 0)
- if err != nil {
- zhios_condition_statistics_logx.Warn(err)
- return zhios_condition_statistics_utils.Float64ToStr(total)
- }
- total += o2oTotal
- o2oTotal1, err := db.O2oOrdPayToMerchantByTime(engine, uid, 0, "1", mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05"), 0)
- if err != nil {
- zhios_condition_statistics_logx.Warn(err)
- return zhios_condition_statistics_utils.Float64ToStr(total)
- }
- total += o2oTotal1
- }
- if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"0", "4"}) {
- mallStime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), t.Hour(), 0, 0, 0, t.Location())
- mallEtime := t
- //确认收货的才算
- b2cTotal, err := db.B2cOrdByTime(engine, uid, 0, []string{"3"}, mallStime.Format("2006-01-02 15:04:05"), mallEtime.Format("2006-01-02 15:04:05"), 0)
- if err != nil {
- zhios_condition_statistics_logx.Warn(err)
- return zhios_condition_statistics_utils.Float64ToStr(total)
- }
- total += b2cTotal
- }
- return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2))
- }
-
- //累计团队消费金额
- func TeamBuySum(engine *xorm.Engine, uid interface{}, task map[string]string, t time.Time) string {
-
- var total float64 = 0
- if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"0", "2", "8", "9"}) {
- sqlTpl := `SELECT SUM(ol.cost_price) AS amount
- FROM mall_ord_list_relate olr
- JOIN mall_ord ol ON olr.oid = ol.ord_id
- WHERE olr.uid = ?
- AND ol.state =3 and olr.level>0 ?;
- `
- str := ""
- if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"8", "9"}) {
- str += " and ol.order_type=" + task["task_type_pvd"]
- }
- result, err := db.QueryNativeString(engine, sqlTpl, uid, str)
- if err == nil {
- total += zhios_condition_statistics_utils.StrToFloat64(result[0]["amount"])
- }
- }
- if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"0", "3"}) {
-
- o2oSqlTpl := `SELECT SUM(ol.cost_price) AS amount
- FROM o2o_ord_list_relate olr
- JOIN o2o_ord ol ON olr.oid = ol.ord_id
- WHERE olr.uid = ?
- AND ol.state =3 and olr.level>0;
- `
- o2oResult, err := db.QueryNativeString(engine, o2oSqlTpl, uid)
- if err == nil {
- total += zhios_condition_statistics_utils.StrToFloat64(o2oResult[0]["amount"])
- }
- }
- if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"0", "4"}) {
-
- b2cSqlTpl := `SELECT SUM(ol.cost_price) AS amount
- FROM b2c_ord_list_relate olr
- JOIN b2c_ord ol ON olr.oid = ol.ord_id
- WHERE olr.uid = ?
- AND ol.state =3 and olr.level>0;
- `
- b2cResult, err := db.QueryNativeString(engine, b2cSqlTpl, uid)
- if err == nil {
- total += zhios_condition_statistics_utils.StrToFloat64(b2cResult[0]["amount"])
- }
- }
- if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []string{"0", "1"}) {
-
- guideSqlTpl := `SELECT SUM(ol.paid_price) AS amount
- FROM ord_list_relate olr
- JOIN ord_list ol ON olr.oid = ol.ord_id
- WHERE olr.uid = ?
- AND ol.state in(1,2,3,5) and olr.level>0;
- `
- guideResult, err := db.QueryNativeString(engine, guideSqlTpl, uid)
- if err == nil {
- total += zhios_condition_statistics_utils.StrToFloat64(guideResult[0]["amount"])
- }
- }
- return zhios_condition_statistics_utils.Float64ToStr(zhios_condition_statistics_utils.FloatFormat(total, 2))
- }
-
- //小市场团队符合条件人数
- func SmallTeamSum(engine *xorm.Engine, uid interface{}, task map[string]string, t time.Time) string {
-
- //小市场团队符合条件人数
- 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, task["task_type_level_id"])
- sql := fmt.Sprintf(sqlTpl, condStr)
- results, err := db.QueryNativeString(engine, sql)
- if err != nil {
- zhios_condition_statistics_logx.Warn(err)
- return ""
- }
- count := ""
- if len(results) > 0 {
- count = zhios_condition_statistics_utils.AnyToString(results[0]["count"])
- }
- return count
- }
- func ExtendStoreCount(engine *xorm.Engine, uid interface{}, task map[string]string, t time.Time) string {
-
- if zhios_condition_statistics_utils.StrToInt(task["task_type_count"]) == 0 {
- return "0"
- }
-
- if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []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["task_type_count"])
- 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)
- }
- }
- if zhios_condition_statistics_utils.InArr(task["task_type_pvd"], []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["task_type_count"])
- 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)
- }
- }
- return "0"
- }
- func PayData(engine *xorm.Engine, uid interface{}, task map[string]string, t time.Time, hasPay bool, payOrdId int64) (string, bool, int64) {
- hasPay = true
- //TODO::根据 RegionalAgentSchemeTask 表中的 task_id 判断是否完成付费任务
- regionalAgentUserOrd, err := db.UserLevelOrderByTaskId(engine, zhios_condition_statistics_utils.AnyToString(uid), task["id"])
- if err != nil {
- _ = zhios_condition_statistics_logx.Warn(err)
- 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
- }
-
- func TotalSmallTeam(eg *xorm.Engine, uid string) string {
-
- sqlTpl := `SELECT sum(cstp.team_all_ord_price)+sum(cstp.my_ord_price) as amount,u.uid
- FROM user_profile u
- LEFT JOIN more_mall_outstanding_achievement cstp ON (cstp.uid =u.uid)
- WHERE u.parent_uid=%s GROUP BY u.uid ORDER BY amount desc,u.uid asc`
- sql := fmt.Sprintf(sqlTpl, uid)
- results, err := db.QueryNativeString(eg, sql)
- if err != nil {
- return "0"
- }
- if len(results) > 1 {
- return results[1]["uid"]
- }
- return "0"
- }
- func GetOwnTaskVideoNum(eg *xorm.Engine, uid interface{}, task map[string]string, t time.Time) string {
- stime := time.Date(t.Year(), t.Month(), t.Day()-zhios_condition_statistics_utils.StrToInt(task["within_days"]), t.Hour(), 0, 0, 0, t.Location()).Format("20060102")
- if zhios_condition_statistics_utils.StrToInt(task["within_days"]) == 0 {
- stime = "0"
- }
- etime := time.Now().Format("20060102")
- sess := eg.Where("uid=? and time>=? and time<=? and task_type=? and task_id>0", uid, stime, etime, 3)
- sum, _ := sess.Sum(&model.TaskVideoNum{}, "count")
- return zhios_condition_statistics_utils.Int64ToStr(int64(sum))
- }
|