diff --git a/app/admin/controller/vote/Vote.php b/app/admin/controller/vote/Vote.php new file mode 100644 index 0000000..78de27c --- /dev/null +++ b/app/admin/controller/vote/Vote.php @@ -0,0 +1,116 @@ +request->isAjax()) { + $get = $this->request->get(); + $lists = VoteLogic::lists($get); + return JsonServer::success("获取成功", $lists); + } + + return view(''); + } + + /** + * @NOTES: 添加帮助类 + * @author: 张无忌 + */ + public function add() + { + if ($this->request->isAjax()) { + $post = $this->request->post(); + $res = VoteLogic::add($post); + if ($res === false) { + $error = VoteLogic::getError() ?: '新增失败'; + return JsonServer::error($error); + } + return JsonServer::success('新增成功'); + } + + + return view(''); + } + + /** + * @NOTES: 编辑帮助分类 + * @author: 张无忌 + */ + public function edit() + { + if ($this->request->isAjax()) { + $post = $this->request->post(); + $res = VoteLogic::edit($post); + if ($res === false) { + $error = VoteLogic::getError() ?: '编辑失败'; + return JsonServer::error($error); + } + return JsonServer::success('编辑成功'); + } + + + $id = $this->request->get('id'); + $detail = VoteLogic::detail($id); + + return view('', [ + 'detail' => $detail, + ]); + } + + /** + * @NOTES: 删除帮助分类 + * @author: 张无忌 + */ + public function del() + { + if ($this->request->isAjax()) { + $id = $this->request->post('id'); + $res = VoteLogic::del($id); + if ($res === false) { + $error = VoteLogic::getError() ?: '删除失败'; + return JsonServer::error($error); + } + return JsonServer::success('删除成功'); + } + + return JsonServer::error('异常'); + } + + /** + * @Notes: 隐藏帮助分类 + * @Author: 张无忌 + */ + public function status() + { + if ($this->request->isAjax()) { + $id = $this->request->post('id'); + $status = $this->request->post('status'); + $res = VoteLogic::status($id,$status); + if ($res === false) { + $error = VoteLogic::getError() ?: '操作失败'; + return JsonServer::error($error); + } + return JsonServer::success('操作成功'); + } + + return JsonServer::success('异常'); + } +} \ No newline at end of file diff --git a/app/admin/controller/vote/VotePlayer.php b/app/admin/controller/vote/VotePlayer.php new file mode 100644 index 0000000..57955c7 --- /dev/null +++ b/app/admin/controller/vote/VotePlayer.php @@ -0,0 +1,122 @@ +request->isAjax()) { + $get = $this->request->get(); + $lists = VotePlayerLogic::lists($get); + return JsonServer::success("获取成功", $lists); + } + + return view('', [ + 'votes' => VoteLogic::getVotes() + ]); + } + + /** + * @NOTES: 添加帮助类 + * @author: 张无忌 + */ + public function add() + { + if ($this->request->isAjax()) { + $post = $this->request->post(); + $res = VotePlayerLogic::add($post); + if ($res === false) { + $error = VotePlayerLogic::getError() ?: '新增失败'; + return JsonServer::error($error); + } + return JsonServer::success('新增成功'); + } + + + return view('', [ + 'votes' => VoteLogic::getVotes() + ]); + } + + /** + * @NOTES: 编辑帮助分类 + * @author: 张无忌 + */ + public function edit() + { + if ($this->request->isAjax()) { + $post = $this->request->post(); + $res = VotePlayerLogic::edit($post); + if ($res === false) { + $error = VotePlayerLogic::getError() ?: '编辑失败'; + return JsonServer::error($error); + } + return JsonServer::success('编辑成功'); + } + + + $id = $this->request->get('id'); + $detail = VotePlayerLogic::detail($id); + + return view('', [ + 'detail' => $detail, + 'votes' => VoteLogic::getVotes() + ]); + } + + /** + * @NOTES: 删除帮助分类 + * @author: 张无忌 + */ + public function del() + { + if ($this->request->isAjax()) { + $id = $this->request->post('id'); + $res = VotePlayerLogic::del($id); + if ($res === false) { + $error = VotePlayerLogic::getError() ?: '删除失败'; + return JsonServer::error($error); + } + return JsonServer::success('删除成功'); + } + + return JsonServer::error('异常'); + } + + /** + * @Notes: 隐藏帮助分类 + * @Author: 张无忌 + */ + public function status() + { + if ($this->request->isAjax()) { + $id = $this->request->post('id'); + $status = $this->request->post('status'); + $res = VotePlayerLogic::status($id,$status); + if ($res === false) { + $error = VotePlayerLogic::getError() ?: '操作失败'; + return JsonServer::error($error); + } + return JsonServer::success('操作成功'); + } + + return JsonServer::success('异常'); + } +} \ No newline at end of file diff --git a/app/admin/logic/vote/VoteLogic.php b/app/admin/logic/vote/VoteLogic.php new file mode 100644 index 0000000..4e23933 --- /dev/null +++ b/app/admin/logic/vote/VoteLogic.php @@ -0,0 +1,215 @@ +field(true) + ->where($where) + ->order('add_time', 'desc') + ->paginate([ + 'page' => $get['page'], + 'list_rows' => $get['limit'], + 'var_page' => 'page' + ]) + ->toArray(); + + + + foreach ($lists['data'] as &$item) { + $item['start_time'] = $item['start_time']? date("Y-m-d H:i:s",$item['start_time']):""; + $item['end_time'] = $item['end_time']? date("Y-m-d H:i:s",$item['end_time']):""; + $item['add_time'] = $item['add_time']? date("Y-m-d H:i:s",$item['add_time']):""; + $item['is_rank'] = $item['is_rank'] ? '显示' : '隐藏'; + $item['is_redo'] = $item['is_redo']==0 ? '当天不可重复' : ($item['is_redo']==1?"全部不重复":"可重复"); + $item['vote_str'] = ($item['vote_type']==0 ? '每天' : '总共').$item['vote_num']."票"; + $item['status'] = $item['status'] ? '显示' : '隐藏'; + + } + return ['count'=>$lists['total'], 'lists'=>$lists['data']]; + } catch (Exception $e) { + return ['error'=>$e->getMessage()]; + } + } + + /** + * @Notes: 资料详细 + * @Author: + * @param $id + * @return array + */ + public static function detail($id) + { + $model = new Vote(); + $detail = $model->field(true)->findOrEmpty($id)->toArray(); + $detail['start_time'] = $detail['start_time']? date("Y-m-d H:i:s",$detail['start_time']):""; + $detail['end_time'] = $detail['end_time']? date("Y-m-d H:i:s",$detail['end_time']):""; + $detail['images_arr'] = $detail['images']? explode(",",$detail['images']):[]; + return $detail; + } + + /** + * @Notes: 添加帮助 + * @Author: + * @param $post + * @return bool + */ + public static function add($post) + { + try { + if(isset($post['goods_image']) && count($post['goods_image']) ){ + $post['images'] = implode(",",$post['goods_image']); + } + Vote::create([ + 'title' => $post['title'], + 'image' => $post['image'] ?? '', + 'video' => $post['video'] ?? '', + 'images' => $post['images'] ?? '', + 'notice' => $post['notice'] ?? '', + 'content' => $post['content'] ?? '', + 'start_time' => $post['start_time'] ? strtotime($post['start_time']) : 0, + 'end_time' => $post['end_time'] ? strtotime($post['end_time']) : 0, + 'is_rank' => $post['is_rank'] ?? 1, + 'is_redo' => $post['is_redo'] ?? 0, + 'province_id' => $post['province_id'] ?? 0, + 'vote_type' => $post['vote_type'] ?? 0, + 'vote_num' => $post['vote_num'] ?? 0, + 'base_visit' => $post['base_visit'] ?? 0, + 'status' => $post['status'] ?? 1, + 'vote_total' => 0, + 'views' => 0, + 'add_time' => time(), + ]); + + return true; + } catch (\Exception $e) { + static::$error = $e->getMessage(); + return false; + } + } + + /** + * @Notes: 编辑帮助 + * @Author: 张无忌 + * @param $post + * @return bool + */ + public static function edit($post) + { + try { + if(isset($post['goods_image']) && count($post['goods_image'])){ + $post['images'] = implode(",",$post['goods_image']); + } + Vote::update([ + 'title' => $post['title'], + 'image' => $post['image'] ?? '', + 'video' => $post['video'] ?? '', + 'images' => $post['images'] ?? '', + 'notice' => $post['notice'] ?? '', + 'content' => $post['content'] ?? '', + 'start_time' => $post['start_time'] ? strtotime($post['start_time']) : 0, + 'end_time' => $post['end_time'] ? strtotime($post['end_time']) : 0, + 'is_rank' => $post['is_rank'] ?? 1, + 'is_redo' => $post['is_redo'] ?? 0, + 'province_id' => $post['province_id'] ?? 0, + 'vote_type' => $post['vote_type'] ?? 0, + 'vote_num' => $post['vote_num'] ?? 0, + 'base_visit' => $post['base_visit'] ?? 0, + 'status' => $post['status'] ?? 1, + 'update_time' => time(), + ], ['id'=>$post['id']]); + return true; + } catch (\Exception $e) { + static::$error = $e->getMessage(); + return false; + } + } + + /** + * @Notes: 删除 + * @Author: + * @param $id + * @return bool + */ + public static function del($id) + { + try { + Vote::update([ + 'del' => 1, + 'update_time' => time() + ], ['id'=>$id]); + + return true; + } catch (\Exception $e) { + static::$error = $e->getMessage(); + return false; + } + } + + /** + * @Notes: 隐藏 + * @Author: 张无忌 + * @param $id + * @return bool + */ + public static function status($id,$status) + { + try { + Vote::update([ + 'status' => $status, + 'update_time' => time() + ], ['id'=>$id]); + + return true; + } catch (\Exception $e) { + static::$error = $e->getMessage(); + return false; + } + } + + + /** + * @Notes: 获取分类 + * @Author: 张无忌 + * @return array + */ + public static function getVotes() + { + try { + $model = new Vote(); + return $model->field(true) + ->where(['del'=>0, 'status'=>1]) + ->order('id', 'desc') + ->select() + ->toArray(); + + } catch (\Exception $e) { + return []; + } + } + +} \ No newline at end of file diff --git a/app/admin/logic/vote/VotePlayerLogic.php b/app/admin/logic/vote/VotePlayerLogic.php new file mode 100644 index 0000000..1842005 --- /dev/null +++ b/app/admin/logic/vote/VotePlayerLogic.php @@ -0,0 +1,176 @@ +field(true) + ->where($where) + ->with(['vote']) + ->order('id', 'desc') + ->paginate([ + 'page' => $get['page'], + 'list_rows' => $get['limit'], + 'var_page' => 'page' + ]) + ->toArray(); + + foreach ($lists['data'] as &$item) { + $item['vote_title'] = $item['vote']['title'] ?? ''; + $item['add_time'] = $item['add_time']? date("Y-m-d H:i:s",$item['add_time']):""; + $item['status'] = $item['status'] ? '显示' : '隐藏'; + } + return ['count'=>$lists['total'], 'lists'=>$lists['data']]; + } catch (Exception $e) { + return ['error'=>$e->getMessage()]; + } + } + + /** + * @Notes: 资料详细 + * @Author: + * @param $id + * @return array + */ + public static function detail($id) + { + $model = new VotePlayer(); + $detail = $model->field(true)->findOrEmpty($id)->toArray(); + $detail['images_arr'] = $detail['images']? explode(",",$detail['images']):[]; + return $detail; + } + + /** + * @Notes: 添加帮助 + * @Author: + * @param $post + * @return bool + */ + public static function add($post) + { + try { + if(isset($post['goods_image']) && count($post['goods_image'])){ + $post['images'] = implode(",",$post['goods_image']); + } + VotePlayer::create([ + 'vote_id' => $post['vote_id']??0, + 'name' => $post['name'], + 'avatar' => $post['avatar'] ?? '', + 'video' => $post['video'] ?? '', + 'images' => $post['images'] ?? '', + 'intro' => $post['intro'] ?? '', + 'vote_num' => $post['vote_num'] ?? 0, + 'base_visit' => $post['base_visit'] ?? 0, + 'status' => $post['status'] ?? 1, + 'vote_total' => 0, + 'views' => 0, + 'add_time' => time(), + ]); + + return true; + } catch (\Exception $e) { + static::$error = $e->getMessage(); + return false; + } + } + + /** + * @Notes: 编辑帮助 + * @Author: 张无忌 + * @param $post + * @return bool + */ + public static function edit($post) + { + try { + if(isset($post['goods_image']) && count($post['goods_image'])){ + $post['images'] = implode(",",$post['goods_image']); + } + VotePlayer::update([ + 'vote_id' => $post['vote_id']??0, + 'name' => $post['name'], + 'avatar' => $post['avatar'] ?? '', + 'video' => $post['video'] ?? '', + 'images' => $post['images'] ?? '', + 'intro' => $post['intro'] ?? '', + 'vote_num' => $post['vote_num'] ?? 0, + 'base_visit' => $post['base_visit'] ?? 0, + 'status' => $post['status'] ?? 1, + 'update_time' => time(), + ], ['id'=>$post['id']]); + return true; + } catch (\Exception $e) { + static::$error = $e->getMessage(); + return false; + } + } + + /** + * @Notes: 删除 + * @Author: + * @param $id + * @return bool + */ + public static function del($id) + { + try { + VotePlayer::update([ + 'del' => 1, + 'update_time' => time() + ], ['id'=>$id]); + + return true; + } catch (\Exception $e) { + static::$error = $e->getMessage(); + return false; + } + } + + /** + * @Notes: 隐藏 + * @Author: 张无忌 + * @param $id + * @return bool + */ + public static function status($id,$status) + { + try { + VotePlayer::update([ + 'status' => $status, + 'update_time' => time() + ], ['id'=>$id]); + + return true; + } catch (\Exception $e) { + static::$error = $e->getMessage(); + return false; + } + } +} \ No newline at end of file diff --git a/app/admin/view/vote/vote/add.html b/app/admin/view/vote/vote/add.html new file mode 100644 index 0000000..6dc0987 --- /dev/null +++ b/app/admin/view/vote/vote/add.html @@ -0,0 +1,304 @@ +{layout name="layout2" /} + + +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
建议尺寸:500*500像
+
+
+ +
+ + +
+
+ + 建议尺寸:800*800像素,最多上传5张 +
+ + +
+ + +
+
+ + 活动视频,在投票详情页面播放。(限制30m内) +
+ +
+ +
+ + +
+
+ +
+ +
+ + + +
+
+ +
+ +
+ + +
+ +
+
+ +
+ +
+ +
+ +
+ +
+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+ + +
+ +
+
+
+ + \ No newline at end of file diff --git a/app/admin/view/vote/vote/edit.html b/app/admin/view/vote/vote/edit.html new file mode 100644 index 0000000..da42536 --- /dev/null +++ b/app/admin/view/vote/vote/edit.html @@ -0,0 +1,327 @@ +{layout name="layout2" /} + + +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
建议尺寸:500*500像
+
+
+ +
+ +
+ {foreach $detail['images_arr'] as $val} +
+ img + +
x
+
+ {/foreach} + +
+
+
+ + 建议尺寸:800*800像素,最多上传5张 +
+ + +
+ +
+ +
+
+
+ + 活动视频,在投票详情页面播放。(限制30m内) +
+ +
+ +
+ + +
+
+ +
+ +
+ + + + +
+
+ +
+ +
+ + +
+
+
+ +
+ +
+ +
+ + + +
+ +
+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+ + +
+ +
+
+
+ + \ No newline at end of file diff --git a/app/admin/view/vote/vote/lists.html b/app/admin/view/vote/vote/lists.html new file mode 100644 index 0000000..bad95a3 --- /dev/null +++ b/app/admin/view/vote/vote/lists.html @@ -0,0 +1,207 @@ +{layout name="layout1" /} + +
+
+ +
+
+
+ +
+

*投票活动。

+

*最新发布的在前。

+
+
+
+
+ + +
+
+
+ +
+ +
+
+
+ 搜索 + 重置 +
+
+
+ + +
+ + +
+ + + +
+ +
+
+ + \ No newline at end of file diff --git a/app/admin/view/vote/vote_player/add.html b/app/admin/view/vote/vote_player/add.html new file mode 100644 index 0000000..1cf0576 --- /dev/null +++ b/app/admin/view/vote/vote_player/add.html @@ -0,0 +1,221 @@ +{layout name="layout2" /} + + +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
建议尺寸:500*500像
+
+
+ +
+ + +
+
+ + 建议尺寸:800*800像素,最多上传5张 +
+ + +
+ + +
+
+ + 宣传视频,在投票详情页面播放。(限制30m内) +
+ + +
+ +
+ +
+
+ + +
+ +
+ + +
+
+ +
+ +
+ +
+
+ +
+ +
+
+
+ + \ No newline at end of file diff --git a/app/admin/view/vote/vote_player/edit.html b/app/admin/view/vote/vote_player/edit.html new file mode 100644 index 0000000..7d90e4f --- /dev/null +++ b/app/admin/view/vote/vote_player/edit.html @@ -0,0 +1,282 @@ +{layout name="layout2" /} + + +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
建议尺寸:500*500像
+
+
+ +
+ +
+ {foreach $detail['images_arr'] as $val} +
+ img + +
x
+
+ {/foreach} + +
+
+
+ + 建议尺寸:800*800像素,最多上传5张 +
+ + +
+ +
+ +
+
+
+ + 宣传视频,在投票详情页面播放。(限制30m内) +
+ + + +
+ +
+ +
+
+ + +
+ +
+ + +
+ +
+ +
+ +
+ +
+
+ +
+ +
+
+
+ + \ No newline at end of file diff --git a/app/admin/view/vote/vote_player/lists.html b/app/admin/view/vote/vote_player/lists.html new file mode 100644 index 0000000..dabe615 --- /dev/null +++ b/app/admin/view/vote/vote_player/lists.html @@ -0,0 +1,215 @@ +{layout name="layout1" /} + +
+
+ +
+
+
+ +
+

*投票活动选手。

+

*最新发布的在前。

+
+
+
+
+ + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ 搜索 + 重置 +
+
+
+ + +
+ + +
+ + + +
+ +
+
+ + \ No newline at end of file diff --git a/app/api/controller/Article.php b/app/api/controller/Article.php index 07f9b0a..3b30d13 100644 --- a/app/api/controller/Article.php +++ b/app/api/controller/Article.php @@ -11,17 +11,8 @@ use app\common\server\JsonServer; class Article extends Api { - public $like_not_need_login = ['category', 'lists', 'detail']; - /** - * @Notes: 文章分类 - * @Author: 张无忌 - */ - public function category() - { - $get = $this->request->get(); - $lists = ArticleLogic::category($get); - return JsonServer::success('获取成功', $lists); - } + public $like_not_need_login = ['lists', 'detail']; + /** * @Notes: 文章列表 diff --git a/app/api/controller/Vote.php b/app/api/controller/Vote.php new file mode 100644 index 0000000..d36f821 --- /dev/null +++ b/app/api/controller/Vote.php @@ -0,0 +1,88 @@ +request->get(); + $get['page_no'] = $this->page_no; + $get['page_size'] = $this->page_size; + $lists = VoteLogic::lists($get); + return JsonServer::success('获取成功', $lists); + } + + /** + * @Notes: 文章详细 + * @Author: 张无忌 + */ + public function detail() + { + $id = $this->request->get('id'); + $detail = VoteLogic::detail($id,$this->user_id); + return JsonServer::success('获取成功', $detail); + } + + + /** + * @Notes: 文章详细 + * @Author: 张无忌 + */ + public function players() + { + $get = $this->request->get(); + $get['page_no'] = $this->page_no; + $get['page_size'] = $this->page_size; + $detail = VoteLogic::players($get,$this->user_id); + return JsonServer::success('获取成功', $detail); + } + + /** + * @Notes: 文章详细 + * @Author: 张无忌 + */ + public function playerDetail() + { + $id = $this->request->get('id'); + $detail = VoteLogic::playersDetail($id,$this->user_id); + return JsonServer::success('获取成功', $detail); + } + + /** + * @Notes: 文章详细 + * @Author: 张无忌 + */ + public function vote() + { + $id = $this->request->get('id'); + $detail = VoteLogic::vote($id,$this->user_id); + return JsonServer::success('获取成功', $detail); + } + + /** + * @Notes: 文章详细 + * @Author: 张无忌 + */ + public function rank() + { + $get = $this->request->get(); + $lists = VoteLogic::rank($get); + return JsonServer::success('获取成功', $lists); + } + +} \ No newline at end of file diff --git a/app/api/logic/VoteLogic.php b/app/api/logic/VoteLogic.php new file mode 100644 index 0000000..d8892e2 --- /dev/null +++ b/app/api/logic/VoteLogic.php @@ -0,0 +1,343 @@ + 'asc' + ]; + + $model = new Vote(); + + $count = $model->alias('a')->where($where)->count(); + + $list = $model->alias('b') + ->where($where) + ->order($order) + ->page($get['page_no'], $get['page_size']) + ->select() + ->toArray(); + + foreach ($list as &$item) { + $item['status_show'] = $item['start_time']>time()?"未开始":($item['end_time'] $list, + 'page_no' => $get['page_no'], + 'page_size' => $get['page_size'], + 'count' => $count, + 'more' => $more + ]; + return $data; + + } catch (\Exception $e) { + return ['error'=>$e->getMessage()]; + } + } + + /** + * @Notes: 文章列表 + * @Author: 张无忌 + * @param $get + * @return array + */ + public static function rank($get) + { + + $where = [ + ['status', '=', 1], + ['vote_id',"=",$get['id']] + ]; + $order = [ + 'vote_num' => 'desc', + 'views' => 'desc' + ]; + + $model = new VotePlayer(); + + + $list = $model->alias('b') + ->where($where) + ->order($order) + ->limit(50) + ->select() + ->toArray(); + + $data = [ + 'list' => $list + ]; + return $data; + } + + /** + * @Notes: 文章详细 + * @Author: 张无忌 + * @param $id + * @return array + */ + public static function detail($id,$uid) + { + $article = Vote::field('*')->where('id', $id)->findOrEmpty(); + $palers = new VotePlayer(); + if($article->isEmpty()) { + $article = []; + }else{ + $article->views = $article->views + 1; + $article->save(); + $article = $article->toArray(); + $article['status_show'] = $article['start_time']]*>(.*?)<\/a>/i'; + $replacement = ''; + $article['content'] = preg_replace($pattern, $replacement, $article['content']); + $article['views'] = $article['views'] +$article['base_visit'] ; +// $article['images'] = explode(",",$article['images']); + if($article['images'] ){ + $article['images'] = explode(",",$article['images']); + }else{ + $article['images'] = []; + } + + + $article['player_count'] = $palers->where("vote_id","=",$id)->where("status",'=',1)->where("del","=",0)->count(); + } + + return $article; + } + + public static function players($get,$uid) + { + $article = Vote::field('*')->where('id', $get['id'])->findOrEmpty(); + + $where = [ + ['status', '=', 1], + ['vote_id',"=",$get['id']] + ]; + if(!empty($get['keyword']) && trim($get['keyword'])){ + $where[] = ['name',"like","%{$get['keyword']}%"]; + } + $order = [ + 'add_time' => 'asc' + ]; + + $model = new VotePlayer(); + + $count = $model->alias('a')->where($where)->count(); + + $list = $model->alias('b') + ->where($where) + ->order($order) + ->page($get['page_no'], $get['page_size']) + ->select() + ->toArray(); + foreach ($list as &$item) { + $item['can_vote'] = VoteLogic::getPlayerVoteStatus($article['id'],$item['id'],$uid,$article['is_redo']); + } + + $more = is_more($count, $get['page_no'], $get['page_size']); + $data = [ + 'list' => $list, + 'page_no' => $get['page_no'], + 'page_size' => $get['page_size'], + 'count' => $count, + 'more' => $more + ]; + return $data; + } + + public static function playersDetail($id,$uid) + { + $article = VotePlayer::field('*')->where('id', $id)->findOrEmpty(); + $vote = Vote::field('*')->where('id', $article['vote_id'])->findOrEmpty(); + $mode = new VotePlayer(); + if($article->isEmpty()) { + $article = []; + }else{ + $article->views = $article->views + 1; + $article->save(); + $article = $article->toArray(); + $article['can_vote'] = VoteLogic::getPlayerVoteStatus($vote['id'],$article['id'],$uid,$vote['is_redo']); + $article['user_vote_count'] = VoteLogic::getUserPlayerVoteNums($vote['id'],$uid,$vote['vote_type']); + $article['title'] = $vote['title']; + $article['start_time'] = $vote['start_time']; + $article['end_time'] = $vote['end_time']; + if($article['images'] ){ + $article['images'] = explode(",",$article['images']); + }else{ + $article['images'] = []; + } + + $article['rank'] = $mode->where('vote_id', $article['vote_id'])->where("vote_num",">",$article['vote_num'])->count() + 1; + if($article['rank']>1){ + $last = $mode->field("*")->where('vote_id', $article['vote_id'])->where("vote_num",">",$article['vote_num'])->order("vote_num","asc")->limit(1)->select(); + $article['rank_last'] = $last[0]['vote_num'] - $article['vote_num']; + }else{ + $article['rank_last'] = 0; + } + + } + + return $article; + } + + + public static function vote($id,$uid) + { + $article = VotePlayer::field('*')->where('id', $id)->findOrEmpty(); + $vote = Vote::field('*')->where('id', $article['vote_id'])->findOrEmpty(); + if($article->isEmpty() || $vote->isEmpty()) { + return [ + 'msg' => '投票成功', + 'data' => 1 + ]; + } + $can_vote = VoteLogic::getPlayerVoteStatus($vote['id'],$article['id'],$uid,$vote['is_redo']); + $user_count = VoteLogic::getUserPlayerVoteNums($vote['id'],$uid,$vote['vote_type']); + if( !$can_vote ) { + return [ + 'msg' => '您已经给TA投过票啦!!', + 'data' => 0 + ]; + } + + if($vote['vote_num']<=$user_count){ + return [ + 'msg' => '您'.($vote['vote_type']==0?'今日':'所有').'的投票数量已达上限!!', + 'data' => 0 + ]; + } + + $data = [ + "user_id" => $uid, + "vid" => $vote['id'], + "pid" => $article['id'], + "create_time" => time(), + "update_time" => time(), + ]; + $voteLog = new VoteLog(); + $res = $voteLog->insert($data); + if($res){ + + //总投票数和选手投票数+1 + $article->vote_num = $article->vote_num + 1; + $article->save(); + + $vote->vote_total = $vote->vote_total + 1; + $vote->save(); + return [ + 'msg' => '投票成功', + 'data' => 1 + ]; + + }else{ + return [ + 'msg' => '投票失败', + 'data' => 0 + ]; + } + } + + + public static function getPlayerVoteStatus($id=0,$player_id=0,$uid=0,$is_redo=0){ + $voteLog = new VoteLog(); + $can_vote = 1; + //当天不重复 统计当天是否给该选手投过票即可 + if($is_redo == 0 ){ + $where = [ + ["vid","=",$id], + ["pid","=",$player_id], + ["user_id","=",$uid], + ["create_time",">",strtotime(date("Y-m-d"))] + ]; + + $count = $voteLog->where($where)->count(); + if($count){ + $can_vote = 0; + } + }else if($is_redo = 1){ // 全部不重复 则统计活动该用户是否给过选手投票 + $where = [ + ["vid","=",$id], + ["pid","=",$player_id], + ["user_id","=",$uid], + ]; + + $count = $voteLog->where($where)->count(); + if($count){ + $can_vote = 0; + } + } + return $can_vote; + } + + public static function getUserPlayerVoteNums($id=0,$uid=0,$vote_type=0){ + $voteLog = new VoteLog(); + $count = 0; + //当天不重复 统计当天是否给该选手投过票即可 + if($vote_type == 0 ){ + $where = [ + ["vid","=",$id], + ["user_id","=",$uid], + ["create_time",">",strtotime(date("Y-m-d"))] + ]; + $count = $voteLog->where($where)->count(); + }else if($vote_type = 1){ // 全部不重复 则统计活动该用户是否给过选手投票 + $where = [ + ["vid","=",$id], + ["user_id","=",$uid], + ]; + $count = $voteLog->where($where)->count(); + } + return $count; + } + + +} \ No newline at end of file diff --git a/app/common/enum/MenuEnum.php b/app/common/enum/MenuEnum.php index 1b2b238..a3764aa 100644 --- a/app/common/enum/MenuEnum.php +++ b/app/common/enum/MenuEnum.php @@ -278,6 +278,14 @@ class MenuEnum{ 'is_tab' => 0, 'link_type' => 1, ], + [ + 'index' => 2001, + 'name' => '投票活动', + 'link' => '/bundle/pages/vote/index', + 'is_tab' => 0, + 'link_type' => 1, + ], + ]; //个人中心菜单 @@ -412,6 +420,14 @@ class MenuEnum{ 'link_type' => 1, 'menu_type' => 1, ], + [ + 'index' => 2001, + 'name' => '投票活动', + 'link' => '/bundle/pages/vote/index', + 'is_tab' => 0, + 'link_type' => 1, + 'menu_type' => 1, + ], ]; /** diff --git a/app/common/model/vote/Vote.php b/app/common/model/vote/Vote.php new file mode 100644 index 0000000..29378a4 --- /dev/null +++ b/app/common/model/vote/Vote.php @@ -0,0 +1,14 @@ +hasOne('Vote', 'id', 'vote_id'); + } + +} \ No newline at end of file diff --git a/runtime/admin/temp/5b260d0cf2418d25963f5356b8c5e275.php b/runtime/admin/temp/5b260d0cf2418d25963f5356b8c5e275.php index 786e611..5e2334b 100644 --- a/runtime/admin/temp/5b260d0cf2418d25963f5356b8c5e275.php +++ b/runtime/admin/temp/5b260d0cf2418d25963f5356b8c5e275.php @@ -1,4 +1,4 @@ - + @@ -74,7 +74,7 @@ ,url: "?type=" ,accept: "images" ,exts: "jpg|png|gif|bmp|jpeg|ico|doc|mp4|mp3" - ,size: 4096 + ,size: 409600 ,data : { "cid": curCid, "type": "" diff --git a/runtime/cache/39/c32ced6a3806745d665754c8c9b590.php b/runtime/cache/39/c32ced6a3806745d665754c8c9b590.php index 3b4363c..7293855 100644 --- a/runtime/cache/39/c32ced6a3806745d665754c8c9b590.php +++ b/runtime/cache/39/c32ced6a3806745d665754c8c9b590.php @@ -1,4 +1,4 @@ -a:1:{s:13:"config_server";N;} \ No newline at end of file +a:1:{s:13:"config_server";i:10;} \ No newline at end of file diff --git a/runtime/cache/92/6f395ddd8765b472a0fbd028892199.php b/runtime/cache/92/6f395ddd8765b472a0fbd028892199.php index 652d732..93ce588 100644 --- a/runtime/cache/92/6f395ddd8765b472a0fbd028892199.php +++ b/runtime/cache/92/6f395ddd8765b472a0fbd028892199.php @@ -1,4 +1,4 @@ -a:1:{i:0;s:75:"E:\waibao\ahbcqz\server\runtime\cache\c3\c9c276ef335cf7635d9a292d2b5e0f.php";} \ No newline at end of file +a:3:{i:0;s:75:"E:\waibao\ahbcqz\server\runtime\cache\c3\c9c276ef335cf7635d9a292d2b5e0f.php";i:1;s:75:"E:\waibao\ahbcqz\server\runtime\cache\14\6c96737a90efca9b6c3e57ab3d261f.php";i:2;s:75:"E:\waibao\ahbcqz\server\runtime\cache\4f\788e6bc203331566420281fb43e5e6.php";} \ No newline at end of file diff --git a/runtime/cache/c0/e314e4f9ca31c325f6c44453324aaa.php b/runtime/cache/c0/e314e4f9ca31c325f6c44453324aaa.php index 3b4363c..d7abbd1 100644 --- a/runtime/cache/c0/e314e4f9ca31c325f6c44453324aaa.php +++ b/runtime/cache/c0/e314e4f9ca31c325f6c44453324aaa.php @@ -1,4 +1,4 @@ -a:1:{s:13:"config_server";N;} \ No newline at end of file +a:1:{s:13:"config_server";s:35:"PCHBZ-UAUKB-QZ2U5-NJVKY-YIXSS-SOF5K";} \ No newline at end of file