diff --git a/app/admin/controller/vote/Vote.php b/app/admin/controller/vote/Vote.php index 78de27c..c8fe9e0 100644 --- a/app/admin/controller/vote/Vote.php +++ b/app/admin/controller/vote/Vote.php @@ -8,6 +8,7 @@ use app\admin\logic\content\HelpCategoryLogic; use app\admin\logic\content\HelpLogic; use app\admin\logic\content\ResourceCategoryLogic; use app\admin\logic\content\ResourceLogic; +use app\admin\logic\vote\VoteCategoryLogic; use app\admin\logic\vote\VoteLogic; use app\admin\validate\content\HelpValidate; use app\common\basics\AdminBase; @@ -27,7 +28,9 @@ class Vote extends AdminBase return JsonServer::success("获取成功", $lists); } - return view(''); + return view('',[ + 'category' => VoteCategoryLogic::getCategory(), + ]); } /** @@ -47,7 +50,7 @@ class Vote extends AdminBase } - return view(''); + return view('',['category' => VoteCategoryLogic::getCategory(),]); } /** @@ -72,6 +75,7 @@ class Vote extends AdminBase return view('', [ 'detail' => $detail, + 'category' => VoteCategoryLogic::getCategory(), ]); } diff --git a/app/admin/controller/vote/VoteCategory.php b/app/admin/controller/vote/VoteCategory.php new file mode 100644 index 0000000..d0bd6e5 --- /dev/null +++ b/app/admin/controller/vote/VoteCategory.php @@ -0,0 +1,110 @@ +request->isAjax()) { + $get = $this->request->get(); + $lists = VoteCategoryLogic::lists($get); + return JsonServer::success("获取成功", $lists); + } + + return view(); + } + + /** + * @NOTES: 添加资源分类 + * @author: 张无忌 + */ + public function add() + { + if ($this->request->isAjax()) { + $post = $this->request->post(); + $res = VoteCategoryLogic::add($post); + if ($res === false) { + $error = VoteCategoryLogic::getError() ?: '新增失败'; + return JsonServer::error($error); + } + return JsonServer::success('新增成功'); + } + return view(''); + } + + /** + * @NOTES: 编辑分类 + * @author: 张无忌 + */ + public function edit() + { + if ($this->request->isAjax()) { + $post = $this->request->post(); + $res = VoteCategoryLogic::edit($post); + if ($res === false) { + $error = VoteCategoryLogic::getError() ?: '编辑失败'; + return JsonServer::error($error); + } + return JsonServer::success('编辑成功'); + } + + $id = $this->request->get('id'); + return view('', [ + 'detail' => VoteCategoryLogic::detail($id) + ]); + } + + /** + * @NOTES: 删除分类 + * @author: 张无忌 + */ + public function del() + { + if ($this->request->isAjax()) { + $id = $this->request->post('id'); + $res = VoteCategoryLogic::del($id); + if ($res === false) { + $error = VoteCategoryLogic::getError() ?: '删除失败'; + return JsonServer::error($error); + } + return JsonServer::success('删除成功'); + } + + return JsonServer::error('异常'); + } + + /** + * @Notes: 隐藏分类 + * @Author: 张无忌 + */ + public function hide() + { + if ($this->request->isAjax()) { + $id = $this->request->post('id'); + $res = VoteCategoryLogic::hide($id); + if ($res === false) { + $error = VoteCategoryLogic::getError() ?: '操作失败'; + return JsonServer::error($error); + } + return JsonServer::success('操作成功'); + } + + return JsonServer::success('异常'); + } +} \ No newline at end of file diff --git a/app/admin/logic/vote/VoteCategoryLogic.php b/app/admin/logic/vote/VoteCategoryLogic.php new file mode 100644 index 0000000..a67a6e6 --- /dev/null +++ b/app/admin/logic/vote/VoteCategoryLogic.php @@ -0,0 +1,160 @@ +field(true) + ->where($where) + ->order('id', 'desc') + ->paginate([ + 'page' => $get['page'], + 'list_rows' => $get['limit'], + 'var_page' => 'page' + ]) + ->toArray(); + + foreach ($lists['data'] as &$item) { + $item['is_show'] = $item['is_show'] ? '启用' : '停用'; + } + + return ['count'=>$lists['total'], 'lists'=>$lists['data']]; + } catch (Exception $e) { + return ['error'=>$e->getMessage()]; + } + } + + /** + * @Notes: 获取分类 + * @Author: 张无忌 + * @return array + */ + public static function getCategory($pid=0) + { + try { + $model = new VoteCategory(); + return $model->field(true) + ->where(['del'=>0, 'is_show'=>1]) + ->order('id', 'desc') + ->select() + ->toArray(); + + } catch (\Exception $e) { + return []; + } + } + + /** + * 获取文章分类详细 + * @param $id + * @return array + */ + public static function detail($id) + { + $model = new VoteCategory(); + return $model->field(true)->findOrEmpty($id)->toArray(); + } + + /** + * 添加分类 + * @param $post + * @return bool + */ + public static function add($post) + { + try { + VoteCategory::create([ + 'name' => $post['name'], + 'is_show' => $post['is_show'] + ]); + + return true; + } catch (\Exception $e) { + static::$error = $e->getMessage(); + return false; + } + } + + /** + * 编辑分类 + * @param $post + * @return bool + */ + public static function edit($post) + { + try { + + VoteCategory::update([ + 'name' => $post['name'], + 'is_show' => $post['is_show'] + ], ['id'=>$post['id']]); + + return true; + } catch (\Exception $e) { + static::$error = $e->getMessage(); + return false; + } + } + + /** + * 删除分类 + * @param $id + * @return bool + */ + public static function del($id) + { + try { + VoteCategory::update([ + 'del' => 1 + ], ['id'=>$id]); + + return true; + } catch (\Exception $e) { + static::$error = $e->getMessage(); + return false; + } + } + + /** + * @Notes: 隐藏 + * @Author: 张无忌 + * @param $id + * @return bool + */ + public static function hide($id) + { + try { + $model = new VoteCategory(); + $category = $model->findOrEmpty($id)->toArray(); + + VoteCategory::update([ + 'is_show' => !$category['is_show'], + '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/logic/vote/VoteLogic.php b/app/admin/logic/vote/VoteLogic.php index 4e23933..23a73b0 100644 --- a/app/admin/logic/vote/VoteLogic.php +++ b/app/admin/logic/vote/VoteLogic.php @@ -26,10 +26,13 @@ class VoteLogic extends Logic if (!empty($get['title']) and trim($get['title'])!='') $where[] = ['title', 'like', '%'.$get['title'].'%']; + if (!empty($get['cid']) and is_numeric($get['cid'])) + $where[] = ['cid', '=', $get['cid']]; $model = new Vote(); $lists = $model->field(true) ->where($where) + ->with(['category']) ->order('add_time', 'desc') ->paginate([ 'page' => $get['page'], @@ -39,8 +42,8 @@ class VoteLogic extends Logic ->toArray(); - foreach ($lists['data'] as &$item) { + $item['category'] = $item['category']['name'] ?? '未知'; $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']):""; @@ -85,6 +88,7 @@ class VoteLogic extends Logic $post['images'] = implode(",",$post['goods_image']); } Vote::create([ + 'cid' => $post['cid'], 'title' => $post['title'], 'image' => $post['image'] ?? '', 'video' => $post['video'] ?? '', @@ -125,6 +129,7 @@ class VoteLogic extends Logic $post['images'] = implode(",",$post['goods_image']); } Vote::update([ + 'cid' => $post['cid'], 'title' => $post['title'], 'image' => $post['image'] ?? '', 'video' => $post['video'] ?? '', diff --git a/app/admin/logic/vote/VotePlayerLogic.php b/app/admin/logic/vote/VotePlayerLogic.php index 1842005..f33802a 100644 --- a/app/admin/logic/vote/VotePlayerLogic.php +++ b/app/admin/logic/vote/VotePlayerLogic.php @@ -8,6 +8,7 @@ use app\common\basics\Logic; use app\common\model\vote\Vote; use app\common\model\vote\VotePlayer; use Exception; +use think\Db; class VotePlayerLogic extends Logic { @@ -90,10 +91,17 @@ class VotePlayerLogic extends Logic 'base_visit' => $post['base_visit'] ?? 0, 'status' => $post['status'] ?? 1, 'vote_total' => 0, + 'base_vote' =>$post['base_visit'] ?? 0, 'views' => 0, 'add_time' => time(), ]); - + $vote_p = new VotePlayer(); + $vote = new Vote(); + $count = $vote_p->where(['status','=',1])->where('vote_id','=',$post['vote_id'])->sum("base_vote"); + $update = [ + "base_vote" => $count + ]; + $vote->where('id','=',$post['vote_id'])->update($update); return true; } catch (\Exception $e) { static::$error = $e->getMessage(); @@ -122,9 +130,19 @@ class VotePlayerLogic extends Logic 'intro' => $post['intro'] ?? '', 'vote_num' => $post['vote_num'] ?? 0, 'base_visit' => $post['base_visit'] ?? 0, + 'base_vote' => $post['base_vote'] ?? 0, 'status' => $post['status'] ?? 1, 'update_time' => time(), ], ['id'=>$post['id']]); + + $vote_p = new VotePlayer(); + $vote = new Vote(); + $count = $vote_p->where('status','=',1)->where('vote_id','=',$post['vote_id'])->sum("base_vote"); + $update = [ + "base_vote" => $count + ]; + $vote->where('id','=',$post['vote_id'])->update($update); + return true; } catch (\Exception $e) { static::$error = $e->getMessage(); @@ -146,6 +164,14 @@ class VotePlayerLogic extends Logic 'update_time' => time() ], ['id'=>$id]); + $vote_p = new VotePlayer(); + $vote = new Vote(); + $count = $vote_p->where(['status','=',1])->where('vote_id','=',$id)->sum("base_vote"); + $update = [ + "base_vote" => $count + ]; + $vote->where('id','=',$id)->update($update); + return true; } catch (\Exception $e) { static::$error = $e->getMessage(); @@ -167,10 +193,18 @@ class VotePlayerLogic extends Logic 'update_time' => time() ], ['id'=>$id]); + $vote_p = new VotePlayer(); + $vote = new Vote(); + $count = $vote_p->where(['status','=',1])->where('vote_id','=',$id)->sum("base_vote"); + $update = [ + "base_vote" => $count + ]; + $vote->where('id','=',$id)->update($update); + 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 index 6dc0987..11cc77c 100644 --- a/app/admin/view/vote/vote/add.html +++ b/app/admin/view/vote/vote/add.html @@ -73,6 +73,18 @@
+ +
+ +
+
+ +
diff --git a/app/admin/view/vote/vote/edit.html b/app/admin/view/vote/vote/edit.html index da42536..9c00f94 100644 --- a/app/admin/view/vote/vote/edit.html +++ b/app/admin/view/vote/vote/edit.html @@ -73,6 +73,18 @@
+ +
+ +
+
+ +
diff --git a/app/admin/view/vote/vote/lists.html b/app/admin/view/vote/vote/lists.html index bad95a3..10acdf1 100644 --- a/app/admin/view/vote/vote/lists.html +++ b/app/admin/view/vote/vote/lists.html @@ -19,12 +19,23 @@
- +
+ +
+ +
+
+ @@ -62,6 +73,7 @@ like.tableLists("#like-table-lists", "{:url()}", [ {field:"id", width:60, title:"ID"} ,{field:"title", width:200, align:"center", title:"标题"} + ,{field:"category", width:150, align:"center", title:"活动分类"} ,{field:"image", width:100, align:"center", title:"封面图", templet:"#table-image"} ,{field:"start_time", width:180, align:"center", title:"开始时间"} ,{field:"end_time", width:180, align:"center", title:"结束时间"} @@ -69,6 +81,7 @@ ,{field:"is_redo", width:150, align:"center", title:"重复投票"} ,{field:"vote_str", width:180, align:"center", title:"投票规则"} ,{field:"vote_total", width:180, align:"center", title:"投票数"} + ,{field:"base_vote", width:180, align:"center", title:"虚拟投票数"} ,{field:"views", width:180, align:"center", title:"浏览数"} ,{field:"status", width:180, align:"center", title:"状态"} ,{field:"add_time", width:180, align:"center", title:"创建时间"} @@ -204,4 +217,4 @@ }) - \ No newline at end of file + diff --git a/app/admin/view/vote/vote_category/add.html b/app/admin/view/vote/vote_category/add.html new file mode 100644 index 0000000..f360b7b --- /dev/null +++ b/app/admin/view/vote/vote_category/add.html @@ -0,0 +1,24 @@ +{layout name="layout2" /} +
+
+ +
+ +
+ +
+
+ +
+ +
+ + +
+
+ +
+ +
+
+
\ No newline at end of file diff --git a/app/admin/view/vote/vote_category/edit.html b/app/admin/view/vote/vote_category/edit.html new file mode 100644 index 0000000..e41d6a8 --- /dev/null +++ b/app/admin/view/vote/vote_category/edit.html @@ -0,0 +1,23 @@ +{layout name="layout2" /} +
+
+
+ +
+ +
+
+ +
+ +
+ + +
+
+ +
+ +
+
+
\ No newline at end of file diff --git a/app/admin/view/vote/vote_category/lists.html b/app/admin/view/vote/vote_category/lists.html new file mode 100644 index 0000000..5e28b6a --- /dev/null +++ b/app/admin/view/vote/vote_category/lists.html @@ -0,0 +1,151 @@ +{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 index 1cf0576..ca2b5ff 100644 --- a/app/admin/view/vote/vote_player/add.html +++ b/app/admin/view/vote/vote_player/add.html @@ -129,6 +129,13 @@
+
+ +
+ +
+
+
@@ -218,4 +225,4 @@ }); }) - \ 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 index 7d90e4f..b0b2a4d 100644 --- a/app/admin/view/vote/vote_player/edit.html +++ b/app/admin/view/vote/vote_player/edit.html @@ -153,7 +153,12 @@
- +
+ +
+ +
+
@@ -279,4 +284,4 @@ ); }) - \ 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 index dabe615..ece022a 100644 --- a/app/admin/view/vote/vote_player/lists.html +++ b/app/admin/view/vote/vote_player/lists.html @@ -76,7 +76,8 @@ ,{field:"name", width:200, align:"center", title:"姓名"} ,{field:"image", width:100, align:"center", title:"封面图", templet:"#table-image"} ,{field:"intro", width:180, align:"center", title:"参赛介绍"} - ,{field:"vote_num", width:180, align:"center", title:"投票数"} + ,{field:"vote_num", width:180, align:"center", title:"真实投票数"} + ,{field:"base_vote", width:180, align:"center", title:"虚拟投票数"} ,{field:"views", width:180, align:"center", title:"浏览数"} ,{field:"status", width:180, align:"center", title:"状态"} ,{field:"add_time", width:180, align:"center", title:"创建时间"} @@ -212,4 +213,4 @@ }) - \ No newline at end of file + diff --git a/app/api/controller/Vote.php b/app/api/controller/Vote.php index d36f821..d35f759 100644 --- a/app/api/controller/Vote.php +++ b/app/api/controller/Vote.php @@ -6,13 +6,25 @@ namespace app\api\controller; use app\api\logic\ArticleLogic; +use app\api\logic\ResourceLogic; use app\api\logic\VoteLogic; use app\common\basics\Api; use app\common\server\JsonServer; class Vote extends Api { - public $like_not_need_login = ['lists', 'detail','players','playerDetail','rank','vote']; + public $like_not_need_login = ['category','lists', 'detail','players','playerDetail','rank','vote']; + + /** + * @Notes: 文章分类 + * @Author: 张无忌 + */ + public function category() + { + $get = $this->request->get(); + $lists = VoteLogic::category($get); + return JsonServer::success('获取成功', $lists); + } /** * @Notes: 文章列表 diff --git a/app/api/logic/VoteLogic.php b/app/api/logic/VoteLogic.php index d8892e2..d8d2260 100644 --- a/app/api/logic/VoteLogic.php +++ b/app/api/logic/VoteLogic.php @@ -12,6 +12,7 @@ use app\common\model\content\ResourceCategory; use app\common\model\user\User; use app\common\model\user\UserResource; use app\common\model\vote\Vote; +use app\common\model\vote\VoteCategory; use app\common\model\vote\VoteLog; use app\common\model\vote\VotePlayer; use app\common\server\AreaServer; @@ -21,6 +22,32 @@ use think\Db; class VoteLogic extends Logic { + /** + * @Notes: 资料分类 + * @Author: 张无忌 + * @param $get + * @return array + */ + public static function category($get) + { + try { + $model = new VoteCategory(); + $where = []; + + if(isset($get['pid']) ){ + $where[] = ['pid','=',$get['pid']]; + } + + return $model->field(['id', 'name']) + ->where([ + ['del', '=', 0], + ['is_show', '=', 1] + ])->where($where)->select()->toArray(); + + } catch (\Exception $e) { + return ['error'=>$e->getMessage()]; + } + } /** * @Notes: 文章列表 @@ -33,9 +60,12 @@ class VoteLogic extends Logic try { $where = [ - ['status', '=', 1] - + ['status', '=', 1], + ['del', '=', 0], ]; + if(isset($get['cid']) && $get['cid']){ + $where[] = ['cid', '=', $get['cid']]; + } $order = [ 'add_time' => 'asc' ]; @@ -91,7 +121,7 @@ class VoteLogic extends Logic ['vote_id',"=",$get['id']] ]; $order = [ - 'vote_num' => 'desc', +// 'vote_num' => 'desc', 'views' => 'desc' ]; @@ -100,11 +130,16 @@ class VoteLogic extends Logic $list = $model->alias('b') ->where($where) + ->orderRaw("vote_num+base_vote desc") ->order($order) ->limit(50) ->select() ->toArray(); + foreach ($list as &$item ){ + $item['vote_num'] = $item['vote_num'] + $item['base_vote']; + } + $data = [ 'list' => $list ]; @@ -147,7 +182,7 @@ class VoteLogic extends Logic $article['images'] = []; } - + $article['vote_total'] = $article['vote_total'] + $article['base_vote']; $article['player_count'] = $palers->where("vote_id","=",$id)->where("status",'=',1)->where("del","=",0)->count(); } @@ -181,6 +216,7 @@ class VoteLogic extends Logic ->toArray(); foreach ($list as &$item) { $item['can_vote'] = VoteLogic::getPlayerVoteStatus($article['id'],$item['id'],$uid,$article['is_redo']); + $item['vote_num'] = $item['vote_num'] + $item['base_vote']; } $more = is_more($count, $get['page_no'], $get['page_size']); @@ -216,14 +252,21 @@ class VoteLogic extends Logic $article['images'] = []; } - $article['rank'] = $mode->where('vote_id', $article['vote_id'])->where("vote_num",">",$article['vote_num'])->count() + 1; + //->where("vote_num",">",$article['vote_num']) + $article['rank'] = $mode->where('vote_id', $article['vote_id'])->where('(vote_num+base_vote)>'.($article['vote_num']+$article['base_vote']))->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']; + $last = $mode->field("*")->where('vote_id', $article['vote_id']) + ->where('(vote_num+base_vote)>'.($article['vote_num']+$article['base_vote'])) +// ->where("vote_num",">",$article['vote_num']) + ->orderRaw("vote_num+base_vote asc") + ->limit(1)->select(); + $article['rank_last'] = ($last[0]['vote_num'] +$last[0]['base_vote'] ) - ($article['vote_num']+$article['base_vote']); }else{ $article['rank_last'] = 0; } + $article['vote_num'] = $article['vote_num'] + $article['base_vote']; + } return $article; @@ -340,4 +383,4 @@ class VoteLogic extends Logic } -} \ No newline at end of file +} diff --git a/app/common/enum/MenuEnum.php b/app/common/enum/MenuEnum.php index a3764aa..87c508b 100644 --- a/app/common/enum/MenuEnum.php +++ b/app/common/enum/MenuEnum.php @@ -286,6 +286,7 @@ class MenuEnum{ 'link_type' => 1, ], + ]; //个人中心菜单 @@ -463,4 +464,4 @@ class MenuEnum{ } return []; } -} \ No newline at end of file +} diff --git a/app/common/model/vote/Vote.php b/app/common/model/vote/Vote.php index 29378a4..64cc1bf 100644 --- a/app/common/model/vote/Vote.php +++ b/app/common/model/vote/Vote.php @@ -9,6 +9,14 @@ use app\common\basics\Models; class Vote extends Models { + /** + * @Notes: 关联资源分类模型 + * @Author: + */ + public function category() + { + return $this->hasOne('VoteCategory', 'id', 'cid'); + } } \ No newline at end of file diff --git a/app/common/model/vote/VoteCategory.php b/app/common/model/vote/VoteCategory.php new file mode 100644 index 0000000..a2f9336 --- /dev/null +++ b/app/common/model/vote/VoteCategory.php @@ -0,0 +1,12 @@ +