|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- 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, "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, "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
- 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, "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_profile as up
- LEFT JOIN user as u ON u.uid=up.uid
- WHERE %s;`
- 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_profile as up
- LEFT JOIN user as u ON u.uid=up.uid
- WHERE %s;`
- 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)
- 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, "2,3,5", stime, etime)
- 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, "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.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, "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.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"))
- 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, "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.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(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"
- }
|