1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace app\mobile\controller;
- use app\common\model\VoteApplyModel;
- use app\common\model\VoteModel;
- use app\mobile\MobileBaseController;
- class Vote extends MobileBaseController
- {
- public function listVote()
- {
- $list = VoteModel::limit(input('limit', 10))
- ->page(input('page', 1))
- ->select();
- ajax_success($list);
- }
- public function detail()
- {
- $id = input('id/d', 0);
- empty($id) && jump('该活动不存在');
- $info = VoteModel::find($id);
- empty($info) && jump('该活动不存在');
- $user_id = get_user_id();
- $apply = VoteApplyModel::where('vote_id', $id)->where('user_id', $user_id)->find();
- $is_apply = 'false';
- $option_name = '';
- if (!empty($apply)) {
- $is_apply = 'true';
- $option_name = $apply['option_name'];
- }
- return view('', [
- 'info' => $info,
- 'is_apply' => $is_apply,
- 'option_name' => $option_name,
- ]);
- }
- public function apply()
- {
- $id = input('id/d', 0);
- empty($id) && ajax_return(1, '该活动不存在');
- $vote = VoteModel::find($id);
- empty($vote) && ajax_return(1, '该活动不存在');
- $option_name = input('option_name', '');
- if (!in_array($option_name, $vote['option'])) {
- ajax_return(1, '该选项不存在,请重新选择');
- }
- $user_id = get_user_id();
- $check = VoteApplyModel::where('vote_id', $id)->where('user_id', $user_id)->find();
- if (!empty($check)) {
- ajax_return(1, '请勿重复提交!');
- }
- VoteApplyModel::create([
- 'vote_id' => $id,
- 'user_id' => $user_id,
- 'option_name' => $option_name,
- ]);
- ajax_return();
- }
- }
|