劲创营---任务项目
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

208 行
7.5 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. 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 %s group by ctls.id order by ctls.extend_num desc,ctls.id desc %s`
  54. where := ""
  55. if args["cid"] != "" {
  56. where = " and ctls.first_cid=" + args["cid"]
  57. }
  58. sql = fmt.Sprintf(sql, user.Info.Uid, topUid, where, "limit "+utils.IntToStr((utils.StrToInt(args["p"])-1)*10)+",10")
  59. nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  60. list := make([]map[string]string, 0)
  61. for _, v := range nativeString {
  62. basePrice, _, _, _, _ := CommPrice(c, v["price"])
  63. tmp := map[string]string{
  64. "id": v["id"],
  65. "name": v["name"],
  66. "extend_num": v["extend_num"],
  67. "icon": svc.ImageFormat(c, v["logo"]),
  68. "price": basePrice,
  69. }
  70. list = append(list, tmp)
  71. }
  72. re := map[string]interface{}{
  73. "list": list,
  74. }
  75. e.OutSuc(c, re, nil)
  76. return
  77. }
  78. func TaskIncome(c *gin.Context) {
  79. user := svc.GetUser(c)
  80. today := utils.GetTimeRange("today")
  81. sql := `SELECT SUM(ctupor.amount) as amount,SUM(IF( 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), sql1)
  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. }