123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- <?php
- namespace app\admin\controller\ump;
- use app\admin\controller\AuthController;
- use app\admin\model\system\SystemAttachment;
- use app\admin\model\system\SystemUserLevel;
- use app\models\mining\MiningMachine;
- use Exception;
- use crmeb\services\{FormBuilder as Form,
- JsonService,
- UtilService as Util,
- JsonService as Json,
- UtilService
- };
- use FormBuilder\exception\FormBuilderException;
- use think\facade\Route;
- use think\facade\Route as Url;
- use app\models\activity\{Activity as ActivityModel, ActivityJoin};
- /**
- * 图文管理
- * Class WechatNews
- * @package app\admin\controller\wechat
- */
- class Activity extends AuthController
- {
- /**
- * TODO 显示后台管理员添加的图文
- * @return mixed
- * @throws Exception
- */
- public function index()
- {
- $this->assign('count_plan', ActivityModel::count());
- return $this->fetch();
- }
- /**
- * 获取vote表
- *
- * @return void
- */
- public function get_list()
- {
- $where = Util::getMore([
- ['page', 1],
- ['limit', 20],
- ]);
- Json::successlayui(ActivityModel::getList((int)$where['page'], (int)$where['limit']));
- }
- /**
- * 创建form表单
- *
- * @param int $id
- * @return string
- * @throws Exception
- * @throws FormBuilderException
- */
- public function create($id = 0)
- {
- $money_type = sys_data('money_type');
- $money_type_select = [];
- foreach ($money_type as $v) {
- $money_type_select[] = ['label' => $v['name'], 'value' => $v['code']];
- }
- if ($id) $info = ActivityJoin::get($id);
- $field[] = Form::input('name', '活动标题', isset($info) ? $info->name : '')->col(Form::col(24))->required();
- $field[] = Form::number('l1_money', '一级缴纳', isset($info) ? $info->l1_money : '')->step(0.00000001)->col(12)->required();
- $field[] = Form::select('l1_money_type', '缴纳币种', isset($info) ? $info->l1_money_type : '')->options($money_type_select)->col(12)->required();
- $field[] = Form::number('l2_money', '二级缴纳', isset($info) ? $info->l2_money : '')->step(0.00000001)->col(12)->required();
- $field[] = Form::select('l2_money_type', '缴纳币种', isset($info) ? $info->l2_money_type : '')->options($money_type_select)->col(12)->required();
- $field[] = Form::number('l3_money', '三级缴纳', isset($info) ? $info->l3_money : '')->step(0.00000001)->col(12)->required();
- $field[] = Form::select('l3_money_type', '缴纳币种', isset($info) ? $info->l3_money_type : '')->options($money_type_select)->col(12)->required();
- $field[] = Form::number('explode_num', '分裂人数', isset($info) ? $info->explode_num : 0)->min(0)->step(1)->col(12)->required();
- $field[] = Form::radio('group_type', '活动类型', isset($info) ? $info->group_type : 0)->options([['label' => '小公排', 'value' => 0], ['label' => '大公排', 'value' => 1]])->col(12)->required();
- $form = Form::make_post_form('添加计划', $field, Url::buildUrl('save', ['id' => $id]), 2);
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- /**
- * 添加或者修改
- * @param $id
- * @return void
- */
- public function save($id = 0)
- {
- $data = UtilService::postMore([
- ['name', ''],
- ['l1_money', ''],
- ['l1_money_type', 0],
- ['l2_money', ''],
- ['l2_money_type', 0],
- ['l3_money', ''],
- ['l3_money_type', 0],
- ['group_type', 0],
- ['explode_num', ''],
- ]);
- ActivityModel::beginTrans();
- try {
- //修改
- if ($id) {
- if (ActivityModel::edit($data, $id)) {
- ActivityModel::commitTrans();
- JsonService::successful('修改成功');
- } else {
- ActivityModel::rollbackTrans();
- JsonService::fail('修改失败');
- }
- } else {
- //新增
- $res = ActivityModel::create($data);
- if ($res) {
- ActivityModel::commitTrans();
- JsonService::successful('添加成功');
- } else {
- ActivityModel::rollbackTrans();
- JsonService::fail('添加失败');
- }
- }
- } catch (\Exception $e) {
- ActivityModel::rollbackTrans();
- JsonService::fail($e->getMessage());
- }
- }
- /**
- * 会员详情
- */
- public function see($id = '')
- {
- $this->assign([
- 'id' => $id,
- ]);
- return $this->fetch();
- }
- /**
- * 获取voteSub表
- *
- * @return void
- */
- public function get_sub_list()
- {
- $where = Util::getMore([
- ['page', 1],
- ['limit', 20],
- ['id', 0],
- ]);
- Json::successlayui(ActivityJoin::getList($where));
- }
- /**
- * @param $id
- * @return string|void
- * @throws \Exception
- */
- public function detail($id)
- {
- if (!$id) $this->failed('数据不存在');
- $info = ActivityModel::get($id);
- if (!$info) $this->failed('数据不存在!');
- $this->assign([
- 'content' => htmlspecialchars_decode($info['content']),
- 'field' => 'detail',
- 'action' => Route::buildUrl('change_field', ['id' => $id, 'field' => 'detail'])
- ]);
- return $this->fetch('public/edit_content');
- }
- /**
- * @param $id
- */
- public function change_field($id)
- {
- if (!$id) JsonService::fail('数据不存在');
- $seckill = ActivityModel::get($id);
- if (!$seckill) JsonService::fail('数据不存在!');
- $data['content'] = request()->post('detail');
- $res = ActivityModel::edit($data, $id);
- if ($res)
- JsonService::successful('修改成功');
- else
- JsonService::fail('修改失败');
- }
- }
|