12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace app\admin\controller;
- use app\admin\AdminBaseController;
- use app\common\model\VoteApplyModel;
- use app\common\model\VoteModel;
- use app\common\service\QrcodeService;
- use app\common\validate\VoteValidate;
- use think\exception\ValidateException;
- class Vote extends AdminBaseController
- {
- /**
- * 列表
- */
- public function index()
- {
- return view();
- }
- public function listVote()
- {
- $list = VoteModel::limit(input('limit'))->page(input('page'))->select();
- $count = VoteModel::count();
- if ($count == 0) {
- ajax_return(1, '未查询到数据');
- }
- list_return($list, $count);
- }
- /**
- * 编辑
- */
- public function voteForm()
- {
- $id = input('id/d, 0');
- $info = VoteModel::find($id);
- return view('', [
- 'info' => $info,
- ]);
- }
- public function editVote()
- {
- $data = input('post.');
- try {
- validate(VoteValidate::class)->check($data);
- } catch (ValidateException $e) {
- ajax_return(1, $e->getError());
- }
- if (empty($data['id'])) {
- VoteModel::create($data);
- } else {
- VoteModel::update($data, ['id' => $data['id']]);
- }
- ajax_return();
- }
- public function delVote()
- {
- $id = input('id/d');
- $check = VoteApplyModel::where('vote_id', $id)->find();
- if (!empty($check)) {
- ajax_return(1, '已有投票的活动无法删除!');
- }
- VoteModel::destroy($id);
- ajax_return();
- }
- /**
- * 二维码
- */
- public function qrcodeVote()
- {
- $id = input('id/d', 0);
- $file_name = "/vote_{$id}.png";
- $link = url('/mobile/vote/detail') . '?id=' . $id;
- $file_url = QrcodeService::getQrcode($file_name, $link);
- ajax_return(0, '', $file_url);
- }
- }
|