|
- package svc
-
- import (
- "applet/app/comm/db"
- "applet/app/comm/e"
- "applet/app/comm/svc"
- "applet/app/comm/utils"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/lib/comm_plan"
- md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md"
- svc2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/svc"
- "fmt"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- func TaskIncomeList(c *gin.Context) {
- var args map[string]string
- if err := c.ShouldBindJSON(&args); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS)
- return
- }
- user := svc.GetUser(c)
- sql := `SELECT SUM(ctupor.amount) as amount,ctl.name FROM camp_task_user_promotion_order_relate ctupor
- LEFT JOIN camp_task_user_promotion_order ctupo on ctupo.oid=ctupor.oid
- LEFT JOIN camp_task_list ctl on ctl.id=ctupo.task_id
- WHERE ctupor.uid=%d and ctupo.settle_time like '2025-09%' GROUP BY ctupo.task_id ORDER BY ctupo.settle_time desc,ctupo.id desc %s`
- sql = fmt.Sprintf(sql, user.Info.Uid, "limit "+utils.IntToStr((utils.StrToInt(args["p"])-1)*10)+",10")
- nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
- list := make([]map[string]string, 0)
- for _, v := range nativeString {
- tmp := map[string]string{
- "name": v["name"], "amount": v["amount"],
- }
- list = append(list, tmp)
- }
- res := map[string]interface{}{
- "list": list,
- }
- e.OutSuc(c, res, nil)
- }
- func TaskIncomeTaskList(c *gin.Context) {
- var args map[string]string
- if err := c.ShouldBindJSON(&args); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS)
- return
- }
- user := svc.GetUser(c)
- sql := `
- SELECT ctls.*,ct.id as op_id FROM camp_task_operator_task ct
- LEFT JOIN camp_task_list ctls on ctls.id=ct.task_id
- where ctls.first_cid in(
- SELECT ctl.first_cid FROM camp_task_user_promotion_qrcode ctupo
- LEFT JOIN camp_task_list ctl on ctl.id=ctupo.task_id
- WHERE ctupo.uid=%d GROUP BY ctupo.task_id ) and ctls.up_down_state=1 and ctls.num>0 order by ctls.extend_num desc,ctls.id desc limit 5`
- sql = fmt.Sprintf(sql, user.Info.Uid)
- nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
- list := make([]map[string]string, 0)
- for _, v := range nativeString {
- basePrice, _, _, _, _ := CommPrice(c, v["price"])
- tmp := map[string]string{
- "id": v["op_id"],
- "name": v["name"],
- "extend_num": v["extend_num"],
- "icon": svc.ImageFormat(c, v["logo"]),
- "price": basePrice,
- }
- list = append(list, tmp)
- }
- re := map[string]interface{}{
- "list": list,
- }
- e.OutSuc(c, re, nil)
- return
- }
- func TaskIncome(c *gin.Context) {
- var args map[string]string
- if err := c.ShouldBindJSON(&args); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS)
- return
- }
- user := svc.GetUser(c)
- today := utils.GetTimeRange("today")
- sql := `SELECT SUM(ctupor.amount) as amount,SUM(IF(and ctupo.settle_time >= '%s',ctupor.amount,0) as today_amount FROM camp_task_user_promotion_order_relate ctupor
- LEFT JOIN camp_task_user_promotion_order ctupo on ctupo.oid=ctupor.oid
- WHERE ctupor.uid=%d `
- sql = fmt.Sprintf(sql, time.Unix(today["start"], 0).Format("2006-01-02 15:04:05"), user.Info.Uid)
- nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
- allPayment := "0"
- todayPayment := "0"
- for _, v := range nativeString {
- allPayment = v["amount"]
- todayPayment = v["today_amount"]
- }
- res := map[string]interface{}{
- "total_list": []map[string]string{
- {"name": "累计总收益(元)", "value": allPayment},
- {"name": "今日收益(元)", "value": todayPayment},
- },
- }
- e.OutSuc(c, res, nil)
- return
- }
- func TaskMyTotal(c *gin.Context) {
- var args map[string]string
- if err := c.ShouldBindJSON(&args); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS)
- return
- }
- user := svc.GetUser(c)
-
- sql := `SELECT COUNT(*) as count,SUM(ctupor.amount) as amount FROM camp_task_user_promotion_order_relate ctupor
- LEFT JOIN camp_task_user_promotion_order ctupo on ctupo.oid=ctupor.oid
- WHERE ctupor.uid=%d and ctupo.task_id=%s and ctupo.settle_time like '%s'`
- sql = fmt.Sprintf(sql, user.Info.Uid, args["task_id"], args["date"]+"%")
- nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
- orderCount := "0"
- settlePayment := "0"
- for _, v := range nativeString {
- orderCount = v["count"]
- settlePayment = v["amount"]
- }
- sql1 := `SELECT COUNT(*) as count,SUM(ctupor.amount) as amount FROM camp_task_user_promotion_order_relate ctupor
- LEFT JOIN camp_task_user_promotion_order ctupo on ctupo.oid=ctupor.oid
- WHERE ctupor.uid=%d and ctupo.task_id=%s and ctupo.settle_time is null`
- sql1 = fmt.Sprintf(sql1, user.Info.Uid, args["task_id"])
- nativeString1, _ := db.QueryNativeString(svc.MasterDb(c), sql)
- waitPayment := "0"
- for _, v := range nativeString1 {
- waitPayment = v["amount"]
- }
- res := map[string]interface{}{
- "order_count": orderCount,
- "total_list": []map[string]string{
- {"name": "已结算(元)", "value": settlePayment},
- {"name": "总待结算(元)", "value": waitPayment},
- },
- }
- e.OutSuc(c, res, nil)
- return
- }
- func TaskMyList(c *gin.Context) {
- var args map[string]string
- if err := c.ShouldBindJSON(&args); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS)
- return
- }
- user := svc.GetUser(c)
- where := "ctupo.uid=" + utils.IntToStr(user.Info.Uid)
- if args["cid"] != "" {
- where += " and ctl.first_cid=" + args["cid"]
- }
-
- sql := `SELECT ctl.* FROM camp_task_user_promotion_qrcode ctupo
- LEFT JOIN camp_task_list ctl on ctl.id=ctupo.task_id
- WHERE %s GROUP BY ctupo.task_id ORDER BY ctl.id desc %s`
- sql = fmt.Sprintf(sql, where, "limit "+utils.IntToStr((utils.StrToInt(args["p"])-1)*10)+",10")
- nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
-
- list := make([]map[string]interface{}, 0)
- settleType := []string{"T+1结算", "T+7结算", "T+30结算"}
- for _, v := range nativeString {
- //basePrice, firstPrice, secondPrice, thirdPrice, fourPrice := CommPrice(c, v["price"])
- basePrice, _, _, _, _ := CommPrice(c, v["price"])
- tmp := map[string]interface{}{
- "id": v["id"],
- "name": v["name"],
- "price": basePrice,
- "label": []string{settleType[utils.StrToInt(v["settle_type"])]},
- "icon": svc.ImageFormat(c, v["logo"]),
- }
- list = append(list, tmp)
- }
- res := map[string]interface{}{
- "list": list,
- }
- e.OutSuc(c, res, nil)
- return
- }
- func CommPrice(c *gin.Context, price string) (string, string, string, string, string) {
- firstPrice := "0"
- secondPrice := "0"
- thirdPrice := "0"
- fourPrice := "0"
- basePrice := ""
- plan, commission1, virtualCoinMoneyRate := svc2.GetAllPlan(svc.MasterDb(c), c.GetString("mid"))
- rmd := &md2.CommissionParam{}
- cfg, _ := svc2.GetPlanCfg(svc.MasterDb(c), "camp_task", c.GetString("mid"), plan, commission1, virtualCoinMoneyRate, rmd)
- user, _ := svc.GetDefaultUser(c, c.GetHeader("Authorization"))
- if cfg != nil {
- fee, _, _, _ := svc2.CommFee(utils.StrToFloat64(price), cfg, "commission", rmd)
- tmpPrice, _, _, _ := comm_plan.CalReturnAmountAndRatio(0, 0, 0, "own", fee, 0, cfg)
- firstPrice = utils.Float64ToStr(tmpPrice)
- tmpPrice1, _, _, _ := comm_plan.CalReturnAmountAndRatio(1, 0, 0, "own", fee, 0, cfg)
- secondPrice = utils.Float64ToStr(tmpPrice1)
- tmpPrice2, _, _, _ := comm_plan.CalReturnAmountAndRatio(2, 0, 0, "own", fee, 0, cfg)
- thirdPrice = utils.Float64ToStr(tmpPrice2)
- tmpPrice3, _, _, _ := comm_plan.CalReturnAmountAndRatio(3, 0, 0, "own", fee, 0, cfg)
- fourPrice = utils.Float64ToStr(tmpPrice3)
- }
- if user != nil {
- tmpPrice := []string{firstPrice, secondPrice, thirdPrice, fourPrice}
- s := tmpPrice[user.Info.Level]
- if s != "" {
- basePrice = s
- }
- }
- return basePrice, firstPrice, secondPrice, thirdPrice, fourPrice
- }
|