劲创营---任务项目
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

204 Zeilen
7.3 KiB

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