1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace app\api\controller\activity;
- use app\models\activity\Activity;
- use app\models\activity\ActivityCheck;
- use app\models\activity\ActivityJoin;
- use app\models\user\User;
- use app\Request;
- use crmeb\services\UtilService;
- class ActivityController
- {
- public function list(Request $request)
- {
- $where = UtilService::getMore([['page', 1], ['limit', 10]], $request);
- return app('json')->success('ok', Activity::getList((int)$where['page'], (int)$where['limit']));
- }
- public function detail($id, Request $request)
- {
- return app('json')->success('ok', Activity::getDetail($id, $request->uid()));
- }
- public function join($id, Request $request)
- {
- $user = User::get($request->uid());
- UtilService::postMore(
- [
- ['trade_psw', '', '', '', ['not_empty_check', function ($item) use ($user) {
- return md5(md5($item)) == $user['trade_pwd'];
- }], ['请输入交易密码', '交易密码错误']],
- ], $request);
- $res = ActivityJoin::join($id, $user['uid']);
- if ($res) {
- return app('json')->success('参与成功');
- } else {
- return app('json')->fail(ActivityJoin::getErrorInfo());
- }
- }
- public function myJoinList(Request $request)
- {
- $user = $request->user();
- $page = $request->get('page/d', 1);
- $page_size = $request->get('limit/d', 10);
- $list = ActivityCheck::where('uid', $user['uid'])->order('add_time', 'desc')->page($page, $page_size)->select()->each(function ($item) {
- if ($item['to_uid'] == 0) {
- $item['checker'] = ['nickname' => '系统', 'uid' => 0];
- } else {
- $item['checker'] = User::getUserInfo($item['to_uid']);
- }
- $item['info'] = Activity::get($item['aid']);
- $item['join_info'] = ActivityJoin::get($item['uaid']);
- });
- $count = ActivityCheck::where('uid', $user['uid'])->count();
- return app('json')->success('ok', compact('list', 'count'));
- }
- public function myChildren($id, Request $request)
- {
- $uid = $request->get('uid', $request->uid());
- $activity = Activity::get('id');
- $last_join = ActivityJoin::where('uid', $uid)->where('aid', $id)->order('add_time', 'desc')->find();
- if (!$last_join) return app('json')->success('ok', ['list' => [], 'count' => 0]);
- $explode_num = $activity['explode_num'];
- $gp_point_list = [];
- for ($i = $explode_num - 2; $i >= -1; $i--) {
- $gp_point_list[] = $last_join['group_num'] * $explode_num - $i;
- }
- $list = ActivityJoin::with('user')->where('group_num', 'in', $gp_point_list)->select();
- if (count($list)) $list = $list->toArray();
- else $list = [];
- $count = 0;
- $joins = [$last_join['group_num']];
- while ($joins) {
- $gp_point_list = [];
- foreach ($joins as $v) {
- for ($i = $explode_num - 2; $i >= -1; $i--) {
- $gp_point_list[] = $v['group_num'] * $explode_num - $i;
- }
- $joins = ActivityJoin::with('user')->where('group_num', 'in', $gp_point_list)->column('group_num');
- $count += count($joins);
- }
- }
- return app('json')->success('ok', compact('list', 'count'));
- }
- }
|