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('修改失败'); } }