劲创营---任务项目
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.

svc_my_task.go 7.4 KiB

2 週之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package svc
  2. import (
  3. "applet/app/comm/db"
  4. "applet/app/comm/e"
  5. "applet/app/comm/svc"
  6. "applet/app/comm/utils"
  7. "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/lib/comm_plan"
  8. md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md"
  9. svc2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/svc"
  10. "fmt"
  11. "github.com/gin-gonic/gin"
  12. "time"
  13. )
  14. func TaskIncomeList(c *gin.Context) {
  15. var args map[string]string
  16. if err := c.ShouldBindJSON(&args); err != nil {
  17. e.OutErr(c, e.ERR_INVALID_ARGS)
  18. return
  19. }
  20. user := svc.GetUser(c)
  21. sql := `SELECT SUM(ctupor.amount) as amount,ctl.name FROM camp_task_user_promotion_order_relate ctupor
  22. LEFT JOIN camp_task_user_promotion_order ctupo on ctupo.oid=ctupor.oid
  23. LEFT JOIN camp_task_list ctl on ctl.id=ctupo.task_id
  24. 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`
  25. sql = fmt.Sprintf(sql, user.Info.Uid, "limit "+utils.IntToStr((utils.StrToInt(args["p"])-1)*10)+",10")
  26. nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  27. list := make([]map[string]string, 0)
  28. for _, v := range nativeString {
  29. tmp := map[string]string{
  30. "name": v["name"], "amount": v["amount"],
  31. }
  32. list = append(list, tmp)
  33. }
  34. res := map[string]interface{}{
  35. "list": list,
  36. }
  37. e.OutSuc(c, res, nil)
  38. }
  39. func TaskIncomeTaskList(c *gin.Context) {
  40. var args map[string]string
  41. if err := c.ShouldBindJSON(&args); err != nil {
  42. e.OutErr(c, e.ERR_INVALID_ARGS)
  43. return
  44. }
  45. user := svc.GetUser(c)
  46. sql := `
  47. SELECT ctls.*,ct.id as op_id FROM camp_task_operator_task ct
  48. LEFT JOIN camp_task_list ctls on ctls.id=ct.task_id
  49. where ctls.first_cid in(
  50. SELECT ctl.first_cid FROM camp_task_user_promotion_qrcode ctupo
  51. LEFT JOIN camp_task_list ctl on ctl.id=ctupo.task_id
  52. 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`
  53. sql = fmt.Sprintf(sql, user.Info.Uid)
  54. nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  55. list := make([]map[string]string, 0)
  56. for _, v := range nativeString {
  57. basePrice, _, _, _, _ := CommPrice(c, v["price"])
  58. tmp := map[string]string{
  59. "id": v["op_id"],
  60. "name": v["name"],
  61. "extend_num": v["extend_num"],
  62. "icon": svc.ImageFormat(c, v["logo"]),
  63. "price": basePrice,
  64. }
  65. list = append(list, tmp)
  66. }
  67. re := map[string]interface{}{
  68. "list": list,
  69. }
  70. e.OutSuc(c, re, nil)
  71. return
  72. }
  73. func TaskIncome(c *gin.Context) {
  74. var args map[string]string
  75. if err := c.ShouldBindJSON(&args); err != nil {
  76. e.OutErr(c, e.ERR_INVALID_ARGS)
  77. return
  78. }
  79. user := svc.GetUser(c)
  80. today := utils.GetTimeRange("today")
  81. 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
  82. LEFT JOIN camp_task_user_promotion_order ctupo on ctupo.oid=ctupor.oid
  83. WHERE ctupor.uid=%d `
  84. sql = fmt.Sprintf(sql, time.Unix(today["start"], 0).Format("2006-01-02 15:04:05"), user.Info.Uid)
  85. nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  86. allPayment := "0"
  87. todayPayment := "0"
  88. for _, v := range nativeString {
  89. allPayment = v["amount"]
  90. todayPayment = v["today_amount"]
  91. }
  92. res := map[string]interface{}{
  93. "total_list": []map[string]string{
  94. {"name": "累计总收益(元)", "value": allPayment},
  95. {"name": "今日收益(元)", "value": todayPayment},
  96. },
  97. }
  98. e.OutSuc(c, res, nil)
  99. return
  100. }
  101. func TaskMyTotal(c *gin.Context) {
  102. var args map[string]string
  103. if err := c.ShouldBindJSON(&args); err != nil {
  104. e.OutErr(c, e.ERR_INVALID_ARGS)
  105. return
  106. }
  107. user := svc.GetUser(c)
  108. sql := `SELECT COUNT(*) as count,SUM(ctupor.amount) as amount FROM camp_task_user_promotion_order_relate ctupor
  109. LEFT JOIN camp_task_user_promotion_order ctupo on ctupo.oid=ctupor.oid
  110. WHERE ctupor.uid=%d and ctupo.task_id=%s and ctupo.settle_time like '%s'`
  111. sql = fmt.Sprintf(sql, user.Info.Uid, args["task_id"], args["date"]+"%")
  112. nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  113. orderCount := "0"
  114. settlePayment := "0"
  115. for _, v := range nativeString {
  116. orderCount = v["count"]
  117. settlePayment = v["amount"]
  118. }
  119. sql1 := `SELECT COUNT(*) as count,SUM(ctupor.amount) as amount FROM camp_task_user_promotion_order_relate ctupor
  120. LEFT JOIN camp_task_user_promotion_order ctupo on ctupo.oid=ctupor.oid
  121. WHERE ctupor.uid=%d and ctupo.task_id=%s and ctupo.settle_time is null`
  122. sql1 = fmt.Sprintf(sql1, user.Info.Uid, args["task_id"])
  123. nativeString1, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  124. waitPayment := "0"
  125. for _, v := range nativeString1 {
  126. waitPayment = v["amount"]
  127. }
  128. res := map[string]interface{}{
  129. "order_count": orderCount,
  130. "total_list": []map[string]string{
  131. {"name": "已结算(元)", "value": settlePayment},
  132. {"name": "总待结算(元)", "value": waitPayment},
  133. },
  134. }
  135. e.OutSuc(c, res, nil)
  136. return
  137. }
  138. func TaskMyList(c *gin.Context) {
  139. var args map[string]string
  140. if err := c.ShouldBindJSON(&args); err != nil {
  141. e.OutErr(c, e.ERR_INVALID_ARGS)
  142. return
  143. }
  144. user := svc.GetUser(c)
  145. where := "ctupo.uid=" + utils.IntToStr(user.Info.Uid)
  146. if args["cid"] != "" {
  147. where += " and ctl.first_cid=" + args["cid"]
  148. }
  149. sql := `SELECT ctl.* FROM camp_task_user_promotion_qrcode ctupo
  150. LEFT JOIN camp_task_list ctl on ctl.id=ctupo.task_id
  151. WHERE %s GROUP BY ctupo.task_id ORDER BY ctl.id desc %s`
  152. sql = fmt.Sprintf(sql, where, "limit "+utils.IntToStr((utils.StrToInt(args["p"])-1)*10)+",10")
  153. nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  154. list := make([]map[string]interface{}, 0)
  155. settleType := []string{"T+1结算", "T+7结算", "T+30结算"}
  156. for _, v := range nativeString {
  157. //basePrice, firstPrice, secondPrice, thirdPrice, fourPrice := CommPrice(c, v["price"])
  158. basePrice, _, _, _, _ := CommPrice(c, v["price"])
  159. tmp := map[string]interface{}{
  160. "id": v["id"],
  161. "name": v["name"],
  162. "price": basePrice,
  163. "label": []string{settleType[utils.StrToInt(v["settle_type"])]},
  164. "icon": svc.ImageFormat(c, v["logo"]),
  165. }
  166. list = append(list, tmp)
  167. }
  168. res := map[string]interface{}{
  169. "list": list,
  170. }
  171. e.OutSuc(c, res, nil)
  172. return
  173. }
  174. func CommPrice(c *gin.Context, price string) (string, string, string, string, string) {
  175. firstPrice := "0"
  176. secondPrice := "0"
  177. thirdPrice := "0"
  178. fourPrice := "0"
  179. basePrice := ""
  180. plan, commission1, virtualCoinMoneyRate := svc2.GetAllPlan(svc.MasterDb(c), c.GetString("mid"))
  181. rmd := &md2.CommissionParam{}
  182. cfg, _ := svc2.GetPlanCfg(svc.MasterDb(c), "camp_task", c.GetString("mid"), plan, commission1, virtualCoinMoneyRate, rmd)
  183. user, _ := svc.GetDefaultUser(c, c.GetHeader("Authorization"))
  184. if cfg != nil {
  185. fee, _, _, _ := svc2.CommFee(utils.StrToFloat64(price), cfg, "commission", rmd)
  186. tmpPrice, _, _, _ := comm_plan.CalReturnAmountAndRatio(0, 0, 0, "own", fee, 0, cfg)
  187. firstPrice = utils.Float64ToStr(tmpPrice)
  188. tmpPrice1, _, _, _ := comm_plan.CalReturnAmountAndRatio(1, 0, 0, "own", fee, 0, cfg)
  189. secondPrice = utils.Float64ToStr(tmpPrice1)
  190. tmpPrice2, _, _, _ := comm_plan.CalReturnAmountAndRatio(2, 0, 0, "own", fee, 0, cfg)
  191. thirdPrice = utils.Float64ToStr(tmpPrice2)
  192. tmpPrice3, _, _, _ := comm_plan.CalReturnAmountAndRatio(3, 0, 0, "own", fee, 0, cfg)
  193. fourPrice = utils.Float64ToStr(tmpPrice3)
  194. }
  195. if user != nil {
  196. tmpPrice := []string{firstPrice, secondPrice, thirdPrice, fourPrice}
  197. s := tmpPrice[user.Info.Level]
  198. if s != "" {
  199. basePrice = s
  200. }
  201. }
  202. return basePrice, firstPrice, secondPrice, thirdPrice, fourPrice
  203. }