ActivityController.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\api\controller\activity;
  3. use app\models\activity\Activity;
  4. use app\models\activity\ActivityCheck;
  5. use app\models\activity\ActivityJoin;
  6. use app\models\user\User;
  7. use app\Request;
  8. use crmeb\services\UtilService;
  9. class ActivityController
  10. {
  11. public function list(Request $request)
  12. {
  13. $where = UtilService::getMore([['page', 1], ['limit', 10]], $request);
  14. return app('json')->success('ok', Activity::getList((int)$where['page'], (int)$where['limit']));
  15. }
  16. public function detail($id, Request $request)
  17. {
  18. return app('json')->success('ok', Activity::getDetail($id, $request->uid()));
  19. }
  20. public function join($id, Request $request)
  21. {
  22. $user = User::get($request->uid());
  23. UtilService::postMore(
  24. [
  25. ['trade_psw', '', '', '', ['not_empty_check', function ($item) use ($user) {
  26. return md5(md5($item)) == $user['trade_pwd'];
  27. }], ['请输入交易密码', '交易密码错误']],
  28. ], $request);
  29. $res = ActivityJoin::join($id, $user['uid']);
  30. if ($res) {
  31. return app('json')->success('参与成功');
  32. } else {
  33. return app('json')->fail(ActivityJoin::getErrorInfo());
  34. }
  35. }
  36. public function myJoinList(Request $request)
  37. {
  38. $user = $request->user();
  39. $page = $request->get('page/d', 1);
  40. $page_size = $request->get('limit/d', 10);
  41. $list = ActivityCheck::where('uid', $user['uid'])->order('add_time', 'desc')->page($page, $page_size)->select()->each(function ($item) {
  42. if ($item['to_uid'] == 0) {
  43. $item['checker'] = ['nickname' => '系统', 'uid' => 0];
  44. } else {
  45. $item['checker'] = User::getUserInfo($item['to_uid']);
  46. }
  47. $item['info'] = Activity::get($item['aid']);
  48. $item['join_info'] = ActivityJoin::get($item['uaid']);
  49. });
  50. $count = ActivityCheck::where('uid', $user['uid'])->count();
  51. return app('json')->success('ok', compact('list', 'count'));
  52. }
  53. public function myChildren($id, Request $request)
  54. {
  55. $uid = $request->get('uid', $request->uid());
  56. $activity = Activity::get('id');
  57. $last_join = ActivityJoin::where('uid', $uid)->where('aid', $id)->order('add_time', 'desc')->find();
  58. if (!$last_join) return app('json')->success('ok', ['list' => [], 'count' => 0]);
  59. $explode_num = $activity['explode_num'];
  60. $gp_point_list = [];
  61. for ($i = $explode_num - 2; $i >= -1; $i--) {
  62. $gp_point_list[] = $last_join['group_num'] * $explode_num - $i;
  63. }
  64. $list = ActivityJoin::with('user')->where('group_num', 'in', $gp_point_list)->select();
  65. if (count($list)) $list = $list->toArray();
  66. else $list = [];
  67. $count = 0;
  68. $joins = [$last_join['group_num']];
  69. while ($joins) {
  70. $gp_point_list = [];
  71. foreach ($joins as $v) {
  72. for ($i = $explode_num - 2; $i >= -1; $i--) {
  73. $gp_point_list[] = $v['group_num'] * $explode_num - $i;
  74. }
  75. $joins = ActivityJoin::with('user')->where('group_num', 'in', $gp_point_list)->column('group_num');
  76. $count += count($joins);
  77. }
  78. }
  79. return app('json')->success('ok', compact('list', 'count'));
  80. }
  81. }