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