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

488 lines
17 KiB

  1. package hdl
  2. import (
  3. "applet/app/comm/db"
  4. "applet/app/comm/e"
  5. "applet/app/comm/svc"
  6. "applet/app/comm/utils"
  7. md2 "applet/app/operator/md"
  8. "applet/app/store/md"
  9. "code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/implement"
  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 CenterBase(c *gin.Context) {
  16. user := svc.GetUser(c)
  17. allTaskCount, _ := svc.MasterDb(c).Where("uid=?", user.Info.Uid).Count(&models.CampTaskOperatorTask{})
  18. sql := `SELECT SUM(ctupor.amount) as amount,SUM(IF(ctupor.uid=%d,ctupo.payment,0)) as own_payment,SUM(IF(ctupor.uid=%d,1,0)) as own_count,SUM(IF(ctupor.uid=%d,ctupor.amount,0)) as own_amount,ctupor.level FROM camp_task_user_promotion_order_relate ctupor
  19. LEFT JOIN camp_task_user_promotion_order ctupo on ctupo.oid=ctupor.oid
  20. WHERE ctupor.oid in(select oid from camp_task_user_promotion_order_relate where uid=%d ) GROUP BY ctupor.level`
  21. sql = fmt.Sprintf(sql, user.Info.Uid, user.Info.Uid, user.Info.Uid, user.Info.Uid)
  22. nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  23. var firstAmount float64 = 0
  24. var secondAmount float64 = 0
  25. var ownAmount float64 = 0
  26. var count = 0
  27. var sum float64 = 0
  28. for _, v := range nativeString {
  29. if v["level"] == "0" {
  30. firstAmount += utils.StrToFloat64(v["amount"])
  31. }
  32. if v["level"] == "1" {
  33. secondAmount += utils.StrToFloat64(v["amount"])
  34. }
  35. ownAmount += utils.StrToFloat64(v["own_amount"])
  36. sum += utils.StrToFloat64(v["own_payment"])
  37. count += utils.StrToInt(v["own_count"])
  38. }
  39. firstLv := "0"
  40. secondLv := "0"
  41. thirdLv := "0"
  42. sql1 := `SELECT COUNT(*) as count,u.level FROM user_relate ur
  43. LEFT JOIN user u on u.uid=ur.uid
  44. WHERE ur.parent_uid=%d GROUP BY u.level`
  45. sql1 = fmt.Sprintf(sql1, user.Info.Uid)
  46. nativeString1, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  47. for _, v := range nativeString1 {
  48. if v["level"] == "0" {
  49. firstLv = v["count"]
  50. }
  51. if v["level"] == "1" {
  52. secondLv = v["count"]
  53. }
  54. if v["level"] == "2" {
  55. thirdLv = v["count"]
  56. }
  57. }
  58. totalList := []map[string]string{
  59. {"name": "名下团长", "value": secondLv, "unit": "人", "type": "", "is_light": "0"},
  60. {"name": "名下普通用户", "value": firstLv, "unit": "人", "type": "", "is_light": "0"},
  61. {"name": "佣金总金额", "value": utils.Float64ToStr(sum), "unit": "¥", "type": "", "is_light": "1"},
  62. {"name": "推广总订单数", "value": utils.IntToStr(count), "unit": "", "type": "", "is_light": "0"},
  63. {"name": "我的分成", "value": utils.Float64ToStr(ownAmount), "unit": "¥", "type": "", "is_light": "1"},
  64. }
  65. if user.Info.Level == 3 {
  66. totalList = []map[string]string{
  67. {"name": "名下运营商", "value": thirdLv, "unit": "人", "type": "operator_detail", "is_light": "0"},
  68. {"name": "佣金总金额", "value": utils.Float64ToStr(sum), "unit": "¥", "type": "", "is_light": "1"},
  69. {"name": "推广总订单数", "value": utils.IntToStr(count), "unit": "", "type": "", "is_light": "0"},
  70. {"name": "我的分成", "value": utils.Float64ToStr(ownAmount), "unit": "¥", "type": "", "is_light": "1"},
  71. {"name": "项目数据", "value": "", "unit": "", "type": "project_detail", "is_light": "0"},
  72. }
  73. }
  74. myTask := make([]map[string]string, 0)
  75. NewCampTaskOperatorTaskDb := implement.NewCampTaskOperatorTaskDb(svc.MasterDb(c))
  76. myTaskList, _, _ := NewCampTaskOperatorTaskDb.FindCampTaskOperatorTaskGroup(user.Info.Uid, 1, 5, "")
  77. if myTaskList != nil {
  78. for _, v := range myTaskList {
  79. tmp := map[string]string{
  80. "id": utils.IntToStr(v.CampTaskOperatorTask.TaskId),
  81. "name": v.Name,
  82. "icon": svc.ImageFormat(c, v.Logo),
  83. }
  84. myTask = append(myTask, tmp)
  85. }
  86. }
  87. res := map[string]interface{}{
  88. "total_list": totalList,
  89. "my_task_count": utils.Int64ToStr(allTaskCount),
  90. "my_task": myTask,
  91. }
  92. e.OutSuc(c, res, nil)
  93. return
  94. }
  95. func CenterList(c *gin.Context) {
  96. var args md2.OperatorTaskReq
  97. if err := c.ShouldBindJSON(&args); err != nil {
  98. e.OutErr(c, e.ERR_INVALID_ARGS)
  99. return
  100. }
  101. user := svc.GetUser(c)
  102. where := ""
  103. if args.SettleStateType != "" {
  104. where += " and ctupo.settle_state=" + args.SettleStateType
  105. }
  106. if args.Cid != "" {
  107. where += " and ctl.first_cid=" + args.Cid
  108. }
  109. if args.TaskId != "" {
  110. where += " and ctupo.task_id=" + args.TaskId
  111. }
  112. if args.ApplyType != "" {
  113. where += " and ctupo.state=" + args.ApplyType
  114. }
  115. if args.StartTime != "" {
  116. where += " and ctupo.create_time>='" + args.StartTime + "'"
  117. }
  118. if args.EndTime != "" {
  119. where += " and ctupo.create_time<>>='" + args.EndTime + "'"
  120. }
  121. sqlCount := `select count(*) as count FROM camp_task_user_promotion_order_relate ctupor
  122. LEFT JOIN camp_task_user_promotion_order ctupo on ctupo.oid=ctupor.oid
  123. LEFT JOIN camp_task_list ctl on ctupo.task_id=ctl.id
  124. WHERE ctupor.uid=%d %s`
  125. sqlCount = fmt.Sprintf(sqlCount, user.Info.Uid, where)
  126. nativeStringCount, _ := db.QueryNativeString(svc.MasterDb(c), sqlCount)
  127. var total = 0
  128. hotTask := make([]map[string]string, 0)
  129. for _, v := range nativeStringCount {
  130. total = utils.StrToInt(v["count"])
  131. }
  132. sql := `select ctl.name as task_name,ul.level_name,ctc.name as cate_name,ctupo.payment,ctupor.oid,ctupo.name as user_name,ctupo.phone as user_phone,
  133. ctupo.state,ctupo.settle_state,ctupo.create_time,ctupor.amount
  134. FROM camp_task_user_promotion_order_relate ctupor
  135. LEFT JOIN camp_task_user_promotion_order ctupo on ctupo.oid=ctupor.oid
  136. LEFT JOIN camp_task_list ctl on ctupo.task_id=ctl.id
  137. LEFT JOIN user_level ul on ctupo.user_lv=ul.id
  138. LEFT JOIN camp_task_cate ctc on ctl.first_cid=ctc.id
  139. WHERE ctupor.uid=%d %s order by ctupo.id desc %s`
  140. sql = fmt.Sprintf(sql, user.Info.Uid, where, "limit "+utils.IntToStr((utils.StrToInt(args.P)-1)*utils.StrToInt(args.Size))+","+args.Size)
  141. nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  142. stateType := []string{"审核中", "审核通过", "审核拒绝"}
  143. settleStateType := []string{"未结算", "结算成功", "结算失败"}
  144. for _, v := range nativeString {
  145. tmp := map[string]string{
  146. "task_name": v["task_name"],
  147. "level_name": v["level_name"],
  148. "cate_name": v["cate_name"],
  149. "oid": v["oid"],
  150. "user_name": v["user_name"],
  151. "user_phone": v["user_phone"],
  152. "state": v["state"],
  153. "state_str": stateType[utils.StrToInt(v["state"])],
  154. "settle_state_str": settleStateType[utils.StrToInt(v["settle_state"])],
  155. "settle_state": v["settle_state"],
  156. "create_time": v["create_time"],
  157. "amount": v["amount"],
  158. }
  159. hotTask = append(hotTask, tmp)
  160. }
  161. task := make([]map[string]string, 0)
  162. taskList := make([]models.CampTaskList, 0)
  163. svc.MasterDb(c).Where("is_delete=?", 0).OrderBy("sort desc,id desc").Find(&taskList)
  164. for _, v := range taskList {
  165. tmp := map[string]string{
  166. "name": v.Name, "value": utils.IntToStr(v.Id),
  167. }
  168. task = append(task, tmp)
  169. }
  170. taskCate := make([]map[string]string, 0)
  171. taskCateList := make([]models.CampTaskCate, 0)
  172. svc.MasterDb(c).Where(" is_show=?", 1).OrderBy("sort desc,id desc").Find(&taskCateList)
  173. for _, v := range taskCateList {
  174. if v.Pid > 0 {
  175. continue
  176. }
  177. tmp := map[string]string{
  178. "name": v.Name, "value": utils.IntToStr(v.Id),
  179. }
  180. taskCate = append(taskCate, tmp)
  181. }
  182. res := map[string]interface{}{
  183. "cate_list": taskCate,
  184. "task_cate_list": task,
  185. "settle_state_type": []map[string]string{
  186. {"name": "未结算", "value": "0"},
  187. {"name": "已结算", "value": "1"},
  188. {"name": "结算拒绝", "value": "2"},
  189. },
  190. "state_type": []map[string]string{
  191. {"name": "未审核", "value": "0"},
  192. {"name": "审核成功", "value": "1"},
  193. {"name": "审核拒绝", "value": "2"},
  194. },
  195. "total": total, "list": hotTask,
  196. }
  197. e.OutSuc(c, res, nil)
  198. return
  199. }
  200. func CenterOperatorList(c *gin.Context) {
  201. var args md2.OperatorTaskReq
  202. if err := c.ShouldBindJSON(&args); err != nil {
  203. e.OutErr(c, e.ERR_INVALID_ARGS)
  204. return
  205. }
  206. user := svc.GetUser(c)
  207. total := 0
  208. hotTask := make([]map[string]string, 0)
  209. sql := `SELECT
  210. u.nickname,
  211. u.uid,
  212. u.level_expire_at,
  213. u.level_arrive_at,
  214. COUNT(CASE WHEN u1.level = 0 THEN 1 END) as firstLv,
  215. COUNT(CASE WHEN u1.level = 1 THEN 1 END) as secondLv
  216. FROM user_relate ur
  217. LEFT JOIN user u ON u.uid = ur.uid
  218. LEFT JOIN user_relate ur1 ON ur1.parent_uid = ur.uid
  219. LEFT JOIN user u1 ON u1.uid = ur1.uid
  220. WHERE ur.parent_uid = %d AND u.level = 2
  221. GROUP BY u.uid, u.nickname, u.level_expire_at, u.level_arrive_at
  222. ORDER BY u.uid DESC %s`
  223. sql = fmt.Sprintf(sql, user.Info.Uid, "limit "+utils.IntToStr((utils.StrToInt(args.P)-1)*utils.StrToInt(args.Size))+","+args.Size)
  224. nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  225. for _, v := range nativeString {
  226. timer := "0天"
  227. leave := utils.TimeStdParseUnix(v["level_expire_at"]) - time.Now().Unix()
  228. if leave > 0 {
  229. timer = utils.Int64ToStr(leave/86400) + "天"
  230. }
  231. if v["level_expire_at"] == v["level_arrive_at"] {
  232. timer = "永久"
  233. }
  234. commission, _ := svc.MasterDb(c).Where("uid=?", v["uid"]).Sum(&models.CampTaskUserPromotionOrderRelate{}, "amount")
  235. orderCount, _ := svc.MasterDb(c).Where("uid=?", v["uid"]).Count(&models.CampTaskUserPromotionOrderRelate{})
  236. tmp := map[string]string{
  237. "uid": v["uid"],
  238. "nickname": v["nickname"],
  239. "timer": timer,
  240. "first_lv_count": v["firstLv"],
  241. "second_lv_count": v["secondLv"],
  242. "order_count": utils.Int64ToStr(orderCount),
  243. "commission": utils.Float64ToStr(commission),
  244. }
  245. hotTask = append(hotTask, tmp)
  246. }
  247. sqlCount := `SELECT COUNT(*) as count,u.level FROM user_relate ur
  248. LEFT JOIN user u on u.uid=ur.uid
  249. WHERE ur.parent_uid=%d and u.level=2`
  250. sqlCount = fmt.Sprintf(sqlCount, user.Info.Uid)
  251. nativeStringCount, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  252. for _, v := range nativeStringCount {
  253. total = utils.StrToInt(v["count"])
  254. }
  255. res := map[string]interface{}{
  256. "total": total, "list": hotTask,
  257. }
  258. e.OutSuc(c, res, nil)
  259. return
  260. }
  261. func CenterOperatorDetailList(c *gin.Context) {
  262. var args md2.OperatorTaskReq
  263. if err := c.ShouldBindJSON(&args); err != nil {
  264. e.OutErr(c, e.ERR_INVALID_ARGS)
  265. return
  266. }
  267. total := 0
  268. hotTask := make([]map[string]string, 0)
  269. sql := `SELECT u.nickname,u.uid,u.phone,u.create_at
  270. FROM user_relate ur
  271. LEFT JOIN user u on u.uid=ur.uid
  272. WHERE ur.parent_uid=%s and u.level=%s order by u.uid desc %s`
  273. sql = fmt.Sprintf(sql, args.Uid, args.Level, "limit "+utils.IntToStr((utils.StrToInt(args.P)-1)*utils.StrToInt(args.Size))+","+args.Size)
  274. nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  275. for _, v := range nativeString {
  276. tmp := map[string]string{
  277. "uid": v["uid"],
  278. "nickname": v["nickname"],
  279. "phone": v["phone"],
  280. "create_time": v["create_at"],
  281. }
  282. hotTask = append(hotTask, tmp)
  283. }
  284. sqlCount := `SELECT COUNT(*) as count,u.level FROM user_relate ur
  285. LEFT JOIN user u on u.uid=ur.uid
  286. WHERE ur.parent_uid=%s and u.level=%s`
  287. sqlCount = fmt.Sprintf(sqlCount, args.Uid, args.Level)
  288. nativeStringCount, _ := db.QueryNativeString(svc.MasterDb(c), sqlCount)
  289. for _, v := range nativeStringCount {
  290. total = utils.StrToInt(v["count"])
  291. }
  292. res := map[string]interface{}{
  293. "total": total, "list": hotTask,
  294. }
  295. e.OutSuc(c, res, nil)
  296. return
  297. }
  298. func CenterOperatorDetailTaskList(c *gin.Context) {
  299. var args md2.OperatorTaskReq
  300. if err := c.ShouldBindJSON(&args); err != nil {
  301. e.OutErr(c, e.ERR_INVALID_ARGS)
  302. return
  303. }
  304. where := ""
  305. if args.SettleStateType != "" {
  306. where += " and ctupo.settle_state=" + args.SettleStateType
  307. }
  308. if args.Cid != "" {
  309. where += " and ctl.first_cid=" + args.Cid
  310. }
  311. if args.TaskId != "" {
  312. where += " and ctupo.task_id=" + args.TaskId
  313. }
  314. if args.ApplyType != "" {
  315. where += " and ctupo.state=" + args.ApplyType
  316. }
  317. if args.StartTime != "" {
  318. where += " and ctupo.create_time>='" + args.StartTime + "'"
  319. }
  320. if args.EndTime != "" {
  321. where += " and ctupo.create_time<>>='" + args.EndTime + "'"
  322. }
  323. sqlCount := `select count(*) as count FROM camp_task_user_promotion_order_relate ctupor
  324. LEFT JOIN camp_task_user_promotion_order ctupo on ctupo.oid=ctupor.oid
  325. LEFT JOIN camp_task_list ctl on ctupo.task_id=ctl.id
  326. WHERE ctupor.uid=%s %s`
  327. sqlCount = fmt.Sprintf(sqlCount, args.Uid, where)
  328. nativeStringCount, _ := db.QueryNativeString(svc.MasterDb(c), sqlCount)
  329. var total = 0
  330. hotTask := make([]map[string]string, 0)
  331. for _, v := range nativeStringCount {
  332. total = utils.StrToInt(v["count"])
  333. }
  334. sql := `select ctl.name as task_name,ul.level_name,ctc.name as cate_name,ctupo.payment,ctupor.oid,ctupo.name as user_name,ctupo.phone as user_phone,
  335. ctupo.state,ctupo.settle_state,ctupo.create_time,ctupor.amount
  336. FROM camp_task_user_promotion_order_relate ctupor
  337. LEFT JOIN camp_task_user_promotion_order ctupo on ctupo.oid=ctupor.oid
  338. LEFT JOIN camp_task_list ctl on ctupo.task_id=ctl.id
  339. LEFT JOIN user_level ul on ctupo.user_lv=ul.id
  340. LEFT JOIN camp_task_cate ctc on ctl.first_cid=ctc.id
  341. WHERE ctupor.uid=%s %s order by ctupo.id desc %s`
  342. sql = fmt.Sprintf(sql, args.Uid, where, "limit "+utils.IntToStr((utils.StrToInt(args.P)-1)*utils.StrToInt(args.Size))+","+args.Size)
  343. nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  344. stateType := []string{"审核中", "审核通过", "审核拒绝"}
  345. settleStateType := []string{"未结算", "结算成功", "结算失败"}
  346. for _, v := range nativeString {
  347. tmp := map[string]string{
  348. "task_name": v["task_name"],
  349. "level_name": v["level_name"],
  350. "cate_name": v["cate_name"],
  351. "oid": v["oid"],
  352. "user_name": v["user_name"],
  353. "user_phone": v["user_phone"],
  354. "state": v["state"],
  355. "state_str": stateType[utils.StrToInt(v["state"])],
  356. "settle_state_str": settleStateType[utils.StrToInt(v["settle_state"])],
  357. "settle_state": v["settle_state"],
  358. "create_time": v["create_time"],
  359. "amount": v["amount"],
  360. }
  361. hotTask = append(hotTask, tmp)
  362. }
  363. task := make([]map[string]string, 0)
  364. taskList := make([]models.CampTaskList, 0)
  365. svc.MasterDb(c).Where("is_delete=?", 0).OrderBy("sort desc,id desc").Find(&taskList)
  366. for _, v := range taskList {
  367. tmp := map[string]string{
  368. "name": v.Name, "value": utils.IntToStr(v.Id),
  369. }
  370. task = append(task, tmp)
  371. }
  372. taskCate := make([]map[string]string, 0)
  373. taskCateList := make([]models.CampTaskCate, 0)
  374. svc.MasterDb(c).Where(" is_show=?", 1).OrderBy("sort desc,id desc").Find(&taskCateList)
  375. for _, v := range taskCateList {
  376. if v.Pid > 0 {
  377. continue
  378. }
  379. tmp := map[string]string{
  380. "name": v.Name, "value": utils.IntToStr(v.Id),
  381. }
  382. taskCate = append(taskCate, tmp)
  383. }
  384. res := map[string]interface{}{
  385. "cate_list": taskCate,
  386. "task_cate_list": task,
  387. "settle_state_type": []map[string]string{
  388. {"name": "未结算", "value": "0"},
  389. {"name": "已结算", "value": "1"},
  390. {"name": "结算拒绝", "value": "2"},
  391. },
  392. "state_type": []map[string]string{
  393. {"name": "未审核", "value": "0"},
  394. {"name": "审核成功", "value": "1"},
  395. {"name": "审核拒绝", "value": "2"},
  396. },
  397. "total": total, "list": hotTask,
  398. }
  399. e.OutSuc(c, res, nil)
  400. return
  401. }
  402. func CenterOperatorProjectList(c *gin.Context) {
  403. var args md2.OperatorTaskReq
  404. if err := c.ShouldBindJSON(&args); err != nil {
  405. e.OutErr(c, e.ERR_INVALID_ARGS)
  406. return
  407. }
  408. user := svc.GetUser(c)
  409. where := ""
  410. if args.ApplyType != "" {
  411. where += " and ctpul.state=" + args.ApplyType
  412. }
  413. if args.StartTime != "" {
  414. where += " and ctpul.create_time>='" + args.StartTime + "'"
  415. }
  416. if args.EndTime != "" {
  417. where += " and ctpul.create_time<>>='" + args.EndTime + "'"
  418. }
  419. sqlCount := `select count(*) as count FROM camp_task_project_user_like ctpul
  420. WHERE uid in(select uid from user_relate where parent_uid=%d) %s`
  421. sqlCount = fmt.Sprintf(sqlCount, user.Info.Uid, where)
  422. nativeStringCount, _ := db.QueryNativeString(svc.MasterDb(c), sqlCount)
  423. var total = 0
  424. hotTask := make([]map[string]string, 0)
  425. for _, v := range nativeStringCount {
  426. total = utils.StrToInt(v["count"])
  427. }
  428. sql := `select ctpul.state,ctpl.name as project_name,u.nickname,u.phone,ctpul.create_time,ctpul.remark,ctpul.id
  429. FROM camp_task_project_user_like ctpul
  430. LEFT JOIN camp_task_project_list ctpl on ctpul.project_id=ctpl.id
  431. LEFT JOIN user u on ctpul.uid=u.uid
  432. WHERE ctpul.uid in(select uid from user_relate where parent_uid=%d) %s order by ctpul.id desc %s`
  433. sql = fmt.Sprintf(sql, args.Uid, where, "limit "+utils.IntToStr((utils.StrToInt(args.P)-1)*utils.StrToInt(args.Size))+","+args.Size)
  434. nativeString, _ := db.QueryNativeString(svc.MasterDb(c), sql)
  435. stateType := []string{"审核中", "审核通过", "审核拒绝"}
  436. for _, v := range nativeString {
  437. tmp := map[string]string{
  438. "project_name": v["project_name"],
  439. "id": v["id"],
  440. "user_name": v["nickname"],
  441. "user_phone": v["phone"],
  442. "state": v["state"],
  443. "state_str": stateType[utils.StrToInt(v["state"])],
  444. "create_time": v["create_time"],
  445. "remark": v["remark"],
  446. }
  447. hotTask = append(hotTask, tmp)
  448. }
  449. res := map[string]interface{}{
  450. "state_type": []map[string]string{
  451. {"name": "未审核", "value": "0"},
  452. {"name": "审核成功", "value": "1"},
  453. {"name": "审核拒绝", "value": "2"},
  454. },
  455. "total": total, "list": hotTask,
  456. }
  457. e.OutSuc(c, res, nil)
  458. return
  459. }
  460. func CenterOperatorProjectDel(c *gin.Context) {
  461. var args md.DirectorDelReq
  462. if err := c.ShouldBindJSON(&args); err != nil {
  463. e.OutErr(c, e.ERR_INVALID_ARGS)
  464. return
  465. }
  466. svc.MasterDb(c).In("id", args.Ids).Delete(&models.CampTaskProjectUserLike{})
  467. e.OutSuc(c, "success", nil)
  468. return
  469. }
  470. func CenterOperatorProjectRemark(c *gin.Context) {
  471. var args md.DirectorDelReq
  472. if err := c.ShouldBindJSON(&args); err != nil {
  473. e.OutErr(c, e.ERR_INVALID_ARGS)
  474. return
  475. }
  476. svc.MasterDb(c).In("id", args.Ids).Cols("remark").Update(&models.CampTaskProjectUserLike{Remark: args.Remark})
  477. e.OutSuc(c, "success", nil)
  478. return
  479. }