uid(); $page = $request->get('page', 1); $limit = $request->get('limit', 10); $data = Vote::ing()->page($page, $limit)->select()->each(function ($item) use ($request) { $item['sub_vote'] = Vote::votingSub($item['id'], $request->uid()); }); $count = Vote::ing()->count(); $commission_type = sys_config('vote_commission_type', ''); $commission_ratio = sys_config('vote_commission_ratio', 0); $all_commission = 0; $today_commission = 0; $vote_people = UserVote::group('uid')->count(); if ($uid) { $all_commission = UserMoney::getComission($uid, 'USDT_ERC20'); $today_commission = UserMoney::getComission($uid, 'USDT_ERC20', 0, 'today'); } return app('json')->success('ok', compact('data', 'count', 'commission_type', 'commission_ratio', 'all_commission', 'today_commission', 'vote_people')); } /** * 投票详情 * @param $id * @param Request $request * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function detail($id, Request $request) { $uid = $request->uid(); $data = Vote::ing()->where('id', $id)->find()->toArray(); $status = $request->get('status', ''); if ($data) $data['sub_vote'] = Vote::votingSub($id, $request->uid(), $status); if ($uid) { $data['all_commission'] = UserMoney::getComission($uid, 'USDT_ERC20', $id); $data['today_commission'] = UserMoney::getComission($uid, 'USDT_ERC20', $id, 'today'); } $data['commission_type'] = sys_config('vote_commission_type', ''); $data['commission_ratio'] = sys_config('vote_commission_ratio', 0); return app('json')->success('ok', $data); } /** * 参加投票 * @param Request $request * @return mixed */ public function join(Request $request) { // CacheService::redisHandler()->set('1',10086); // CacheService::redisHandler()->get('1'); $user = $request->user(); $uid = $user['uid']; list($num, $id, , $captcha) = UtilService::postMore( [ ['num', 0,], ['id', 0, '', '', 'not_empty_check', '请选择参与的投票'], ['trade_psw', '', '', '', ['not_empty_check', function ($item) use ($user) { // var_dump($user); return md5(md5($item)) == $user['trade_pwd']; }], ['请输入交易密码', '交易密码错误']], ['captcha', ''] ], $request, true); $type = Vote::where('id', $id)->value('money_type'); //TODO 写队列 $price = 0; $list = sys_data('money_type'); foreach ($list as $v) { if ($v['code'] == $type) { $price = $v['price'] ? $v['price'] : CashTradeOrder::averagePrice($v['code']); } } if (bcmul($num, $price, 2) >= 10000) { $verifyCode = CacheService::get('code_' . $user['account']); if (!$verifyCode) return app('json')->fail('请先获取验证码'); $verifyCode = substr($verifyCode, 0, 6); if ($verifyCode != $captcha) return app('json')->fail('验证码错误'); } $wait_id = md5($uid . $id . time() . rand(0, 99999)); (new \crmeb\utils\Vote)->push(['uid' => $uid, 'num' => $num, 'id' => $id, 'wait_id' => $wait_id]); CacheService::set($wait_id, '投票中,请稍候……'); return app('json')->success('已进入投票排队', ['wait_id' => $wait_id]); } public function voteResult($key, Request $request) { $res = CacheService::get($key); $res2 = CacheService::get($key . '_success', false); if ($res) return app('json')->success($res, ['status' => $res2 ? 1 : 0]); else return app('json')->fail('投票查询记录已失效或不存在'); } /** * 我参与的投票列表 * @param Request $request */ public function my_list(Request $request) { $user = $request->user(); $uid = $user['uid']; $page = $request->get('page', 1); $limit = $request->get('limit', 10); $status = $request->get('status', ''); $where = []; if ($status != '') $where['status'] = explode(',', $status); $ids = UserVote::where('uid', $uid)->column('sub_vote_id'); // var_dump($ids); $count = $ids ? VoteSub::where('id', 'in', $ids)->where($where)->count() : 0; // var_dump($count); $list = $ids ? VoteSub::where('id', 'in', $ids)->where($where)->order('add_time', 'desc')->page($page, $limit)->select()->each(function ($item) use ($uid) { $item['parent'] = Vote::where('id', $item['vote_id'])->find(); $item['my'] = UserVote::where('sub_vote_id', $item['id'])->where('uid', $uid)->select(); $item['now_voted'] = UserVote::where('sub_vote_id', $item['id'])->sum('vote_num'); if ($uid) { $item['user_now_voted'] = UserVote::where('uid', $uid)->where('sub_vote_id', $item['id'])->sum('vote_num'); $item['user_now_get'] = UserMoneyOrder::where('to_uid', $uid)->where('from_sub_vote', $item['id'])->sum('money'); } $item['commission_type'] = sys_config('vote_commission_type', ''); $item['commission_ratio'] = sys_config('vote_commission_ratio', 0); $item['_finish_time'] = date('Y-m-d H:i:s',$item['finish_time']); $item['_end_time'] = date('Y-m-d H:i:s',$item['end_time']); $item['_add_time'] = date('Y-m-d H:i:s',$item['add_time']); $item['_success_time'] = date('Y-m-d H:i:s',$item['success_time']); }) : []; $all_commission = 0; $today_commission = 0; if ($uid) { $all_commission = UserMoney::getComission($uid, 'USDT_ERC20'); $today_commission = UserMoney::getComission($uid, 'USDT_ERC20', 0, 'today'); } // var_dump(UserMoney::getLastSql()); return app('json')->success('ok', compact('list', 'count', 'all_commission', 'today_commission')); } }