where('vote_id', $id); if ($status == 1) $model = VoteSub::ing(false)->where('vote_id', $id)->where('start_time', '>', time()); if ($status == 2) $model = VoteSub::where('vote_id', $id)->where('status', 'in', [2, 4]); $data = $model->select()->each(function ($item) use ($uid) { $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['commission_type'] = sys_config('vote_commission_type', ''); $item['commission_ratio'] = sys_config('vote_commission_ratio', 0); }); return $data; } /** * @param $where * @return array */ public static function getList($where) { $model = new self(); if (isset($where['title']) && $where['title'] != '') { $model->where('id|vote_name', 'like', "%{$where['title']}%"); } if (isset($where['status']) && $where['status'] != '') { $model->where('status', $where['status']); } if (isset($where['money_type']) && $where['money_type'] != '') { $model->where('money_type', $where['money_type']); } $count = $model->count(); $data = $model->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) { switch ($item['status']) { case 1: $item['_status'] = '进行中'; break; case 2: $item['_status'] = '已结束'; break; case 0: $item['_status'] = '未开始'; break; default: $item['_status'] = '未知'; break; } $item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']); }); return compact('count', 'data'); } //获取某用户的详细信息 public static function getInfo($id) { $Info = self::get($id); return [ ['name' => '投票名', 'value' => $Info['vote_name']], ['name' => '投票目标', 'value' => $Info['money_type']], ['name' => '投票总额', 'value' => UserVote::where('vote_id', $id)->sum('vote_num')], ]; } }