劲创营---任务项目
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

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