| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <?php
- /**
- *
- * @author: wuhaotian<442384644@qq.com>
- * @day: 2019/12/07
- */
- namespace app\admin\controller\vote;
- use app\admin\controller\AuthController;
- use app\admin\model\vote\Vote as GroupModel;
- use app\admin\model\vote\VoteJoin;
- use app\admin\model\vote\VoteOrder;
- use crmeb\services\JsonService;
- use crmeb\services\UtilService;
- use crmeb\services\FormBuilder as Form;
- use think\facade\Route as Url;
- /**
- * Class UserGroup
- * @package app\admin\controller\user
- */
- class Vote extends AuthController
- {
- /**
- * 投票页面
- * @return string
- */
- public function index()
- {
- return $this->fetch();
- }
- /**
- * 投票列表
- */
- public function groupList()
- {
- $where = UtilService::getMore([
- ['page', 1],
- ['limit', 20],
- ]);
- return JsonService::successlayui(GroupModel::getList($where));
- }
- /**
- * 添加/修改分组页面
- * @param int $id
- * @return string
- */
- public function addGroup($id = 0)
- {
- $group = GroupModel::get($id);
- $f = array();
- if (!$group) {
- $f[] = Form::input('title', '投票标题', '');
- $f[] = Form::number('price', '单票价格', 0)->step(0.01);
- $f[] = Form::dateTime('start_time', '开始时间', '');
- $f[] = Form::dateTime('end_time', '结束时间', '');
- // $f[] = Form::input('add_time', '添加事件', $group->getData('start_time'));
- $f[] = Form::radio('status', '状态', 0)->setOptions([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
- // $f[] = Form::input('visit', '访问量', $group->getData('visit'));
- } else {
- $f[] = Form::input('title', '投票标题', $group->getData('title'));
- $f[] = Form::number('price', '单票价格', $group->getData('price'))->step(0.01);
- $f[] = Form::number('day_free', '每日免费票', $group->getData('day_free'))->step(1);
- $f[] = Form::dateTime('start_time', '开始时间', date('Y-m-d H:i:s', $group->getData('start_time')));
- $f[] = Form::dateTime('end_time', '结束时间', date('Y-m-d H:i:s', $group->getData('end_time')));
- // $f[] = Form::input('add_time', '添加事件', $group->getData('start_time'));
- $f[] = Form::radio('status', '状态', (int)$group->getData('status'))->setOptions([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
- }
- $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('saveGroup', array('id' => $id)));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- /**
- * 添加/修改
- * @param int $id
- */
- public function saveGroup($id = 0)
- {
- $data = UtilService::postMore([
- ['title', ''],
- ['start_time', ''],
- ['end_time', ''],
- ['price', ''],
- ['status', ''],
- ['day_free', ''],
- ]);
- $data['start_time'] = strtotime($data['start_time']);
- $data['end_time'] = strtotime($data['end_time']);
- if ($id) {
- if (GroupModel::where('id', $id)->update($data)) {
- return JsonService::success('修改成功');
- } else {
- return JsonService::fail('修改失败或者您没有修改什么!');
- }
- } else {
- $data['add_time'] = time();
- if ($res = GroupModel::create($data)) {
- return JsonService::success('保存成功', ['id' => $res->id]);
- } else {
- return JsonService::fail('保存失败!');
- }
- }
- }
- /**
- * 删除
- * @param $id
- * @throws \Exception
- */
- public function delete($id)
- {
- if (!$id) return $this->failed('数据不存在');
- if (!GroupModel::be(['id' => $id])) return $this->failed('数据不存在');
- if (!GroupModel::where('id', $id)->delete())
- return JsonService::fail(GroupModel::getErrorInfo('删除失败,请稍候再试!'));
- else
- return JsonService::successful('删除成功!');
- }
- public function content($id)
- {
- if (!$id) return $this->failed('数据不存在');
- $product = GroupModel::get($id);
- if (!$product) return Json::fail('数据不存在!');
- $this->assign([
- 'content' => $product->detail,
- 'field' => 'detail',
- 'action' => Url::buildUrl('change_field', ['id' => $id, 'field' => 'detail'])
- ]);
- return $this->fetch('public/edit_content');
- }
- public function change_field($id, $field)
- {
- if (!$id) return $this->failed('数据不存在');
- $bargain = GroupModel::get($id);
- if (!$bargain) return JsonService::fail('数据不存在!');
- if ($field == 'rule') {
- $data['rule'] = request()->post('rule');
- } else {
- $data['detail'] = request()->post('detail');
- }
- $res = GroupModel::edit($data, $id);
- if ($res)
- return JsonService::successful('添加成功');
- else
- return JsonService::fail('添加失败');
- }
- /**
- * 投票页面
- * @return string
- */
- public function join($id)
- {
- $this->assign('id', $id);
- return $this->fetch();
- }
- /**
- * 投票列表
- */
- public function joinList($id)
- {
- $where = UtilService::getMore([
- ['page', 1],
- ['limit', 20],
- ['export', 0],
- ]);
- // $where['vid'] = $id;
- JsonService::successlayui(VoteJoin::getList($id, $where));
- }
- /**
- * 投票页面
- * @return string
- */
- public function log($id)
- {
- $this->assign('id', $id);
- return $this->fetch();
- }
- /**
- * 投票列表
- */
- public function logList($id)
- {
- $where = UtilService::getMore([
- ['page', 1],
- ['limit', 20],
- ]);
- JsonService::successlayui(VoteOrder::getValidList($id, $where));
- }
- public function fail($id)
- {
- if (!VoteJoin::be(['id' => $id, 'status' => 0])) JsonService::fail('操作记录不存在或状态错误!');
- $fail_msg = request()->post('message', '');
- $extract = VoteJoin::get($id);
- if (!$extract) JsonService::fail('操作记录不存在!');
- if ($extract->status == 1) JsonService::fail('已经通过,错误操作!');
- if ($extract->status == 2) JsonService::fail('已经拒绝,请勿重复操作!');
- $res = VoteJoin::where('id', $id)->update(['mark' => $fail_msg, 'status' => 2]);
- if ($res) {
- JsonService::successful('操作成功!');
- } else {
- JsonService::fail('操作失败!');
- }
- }
- public function succ($id)
- {
- if (!VoteJoin::be(['id' => $id, 'status' => 0]))
- JsonService::fail('操作记录不存在或状态错误!');
- VoteJoin::beginTrans();
- $extract = VoteJoin::get($id);
- if (!$extract) JsonService::fail('操作记录不存!');
- if ($extract->status == 1) JsonService::fail('已经通过,请勿重复提现!');
- if ($extract->status == -1) JsonService::fail('已经拒绝,错误操作!');
- $res = VoteJoin::where('id', $id)->update(['status' => 1, 'sub_id' => VoteJoin::where('vid', $extract['vid'])->max('sub_id') + 1]);
- if ($res) {
- VoteJoin::commitTrans();
- JsonService::successful('操作成功!');
- } else {
- VoteJoin::rollbackTrans();
- JsonService::fail('操作失败!');
- }
- }
- }
|