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 @@
*平台维护活动分类,方便投票活动整理。
+