123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- <?php
- namespace app\admin\controller\point_plan;
- use app\admin\controller\AuthController;
- use app\admin\model\system\SystemAttachment;
- use app\admin\model\system\SystemUserLevel;
- use Exception;
- use crmeb\services\{FormBuilder as Form,
- JsonService,
- UtilService as Util,
- JsonService as Json,
- UtilService
- };
- use FormBuilder\exception\FormBuilderException;
- use think\facade\Route as Url;
- use app\models\point_plan\{PointPlan as PointPlanModel, UserPointPlan};
- /**
- * 图文管理
- * Class WechatNews
- * @package app\admin\controller\wechat
- */
- class PointPlan extends AuthController
- {
- /**
- * TODO 显示后台管理员添加的图文
- * @return mixed
- * @throws Exception
- */
- public function index()
- {
- // $money_type = json_encode(sys_data('money_type'));
- // $this->assign(compact('money_type'));
- $this->assign('count_plan', PointPlanModel::count());
- return $this->fetch();
- }
- /**
- * 获取vote表
- *
- * @return void
- */
- public function get_list()
- {
- $where = Util::getMore([
- ['page', 1],
- ['limit', 20],
- ['title', ''],
- ['status', ''],
- ]);
- Json::successlayui(PointPlanModel::getList($where));
- }
- /**
- * 创建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 = PointPlanModel::get($id);
- $field[] = Form::input('plan_name', '计划标题', isset($info) ? $info->plan_name : '')->col(Form::col(24))->required();
- $field[] = Form::select('release_money_type', '释放币种', isset($info) ? $info->release_money_type : '')->options($money_type_select)->col(24)->required();
- $field[] = Form::select('buy_money_type', '认购币种', isset($info) ? $info->buy_money_type : '')->options($money_type_select)->col(24)->required();
- $field[] = Form::number('buy_num', '认购额度', isset($info) ? $info->buy_num : 0)->min(0)->col(24)->required();
- $field[] = Form::number('buy_price', '认购价格', isset($info) ? $info->buy_price : 0)->step(0.00000001)->col(24)->required();
- $field[] = Form::number('release_ratio', '收益倍数', isset($info) ? $info->release_ratio : 0)->min(0)->col(12)->step(0.01)->required();
- $field[] = Form::number('num', '节点名额', isset($info) ? $info->num : 0)->min(0)->col(12)->required();
- $field[] = Form::number('recommend_num', '考核推荐有效用户', isset($info) ? $info->recommend_num : 0)->min(0)->col(12)->required();
- $field[] = Form::number('group_num', '考核团队有效人数', isset($info) ? $info->group_num : 0)->min(0)->col(12)->required();
- $field[] = Form::number('exam_time', '考核期(天)', isset($info) ? $info->exam_time : 0)->min(0)->col(12)->required();
- $field[] = Form::number('layer_award_ratio', '团队奖比例', isset($info) ? $info->layer_award_ratio : 0)->min(0)->col(12)->required();
- $field[] = Form::number('layer_award_layer', '团队奖层数', isset($info) ? $info->layer_award_layer : 0)->min(0)->col(12)->required();
- $field[] = Form::number('release_day', '释放天数', isset($info) ? $info->release_day : 0)->min(0)->col(12)->required();
- $field[] = Form::dateTime('start_time', '开启认购时间', isset($info) ? date('Y-m-d H:i:s', $info->start_time) : '')->col(12);
- $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([
- ['plan_name', ''],
- ['release_money_type', ''],
- ['buy_money_type', ''],
- ['buy_num', 0],
- ['buy_price', 0],
- ['release_ratio', 0],
- ['num', 0],
- ['recommend_num', 0],
- ['group_num', 0],
- ['exam_time', 0],
- ['layer_award_ratio', 0],
- ['layer_award_layer', 0],
- ['release_day', ''],
- ['start_time', 0],
- ]);
- PointPlanModel::beginTrans();
- if (!$data['start_time']) {
- JsonService::fail('开启认购时间');
- }
- $data['start_time'] = strtotime($data['start_time']);
- try {
- //修改
- if ($id) {
- if (PointPlanModel::edit($data, $id)) {
- PointPlanModel::commitTrans();
- JsonService::successful('修改成功');
- } else {
- PointPlanModel::rollbackTrans();
- JsonService::fail('修改失败');
- }
- } else {
- //新增
- $data['add_time'] = time();
- $res = PointPlanModel::create($data);
- if ($res) {
- PointPlanModel::commitTrans();
- JsonService::successful('添加成功');
- } else {
- PointPlanModel::rollbackTrans();
- JsonService::fail('添加失败');
- }
- }
- } catch (\Exception $e) {
- PointPlanModel::rollbackTrans();
- JsonService::fail($e->getMessage());
- }
- }
- /**
- * 会员详情
- */
- public function see($id = '')
- {
- $this->assign([
- 'id' => $id,
- ]);
- return $this->fetch();
- }
- // /**
- // * 创建form表单
- // *
- // * @param int $id
- // * @return string
- // * @throws Exception
- // * @throws FormBuilderException
- // */
- // public function create_sub($id = 0, $vid = 0)
- // {
- // if (!$id && !$vid) {
- // $this->failed('参数异常');
- // }
- // if ($id) $info = VoteSub::get($id);
- // if (isset($info)) $vid = $info['vote_id'];
- //// var_dump($id);
- // $field[] = Form::hidden('vote_id', $vid);
- // $field[] = Form::input('vote_sub_name', '投票标题', isset($info) ? $info->vote_sub_name : '')->col(Form::col(24))->required();
- // $field[] = Form::number('vote_num', '投票数量', isset($info) ? $info->vote_num : 0)->min(0)->col(12)->step(0.00000001)->required();
- // $field[] = Form::number('max_vote_num', '个人投票上限', isset($info) ? $info->max_vote_num : 0)->min(0)->col(12)->step(0.00000001)->required();
- // $field[] = Form::dateTime('start_time', '开始时间', isset($info) ? date('Y-m-d H:i:s', $info->start_time) : '');
- // $field[] = Form::dateTime('end_time', '结束时间', isset($info) ? date('Y-m-d H:i:s', $info->end_time) : '');
- // if ((isset($info) && $info['status'] != 2 && $info['status'] != 3) || !isset($info))
- // $field[] = Form::radio('status', '状态', isset($info) ? $info->status : 0)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
- // $form = Form::make_post_form('添加子投票', $field, Url::buildUrl('save_sub', ['id' => $id]), 2);
- // $this->assign(compact('form'));
- // return $this->fetch('public/form-builder');
- // }
- // /**
- // * 添加或者修改
- // * @param $id
- // * @return void
- // */
- // public function save_sub($id = 0)
- // {
- // $data = UtilService::postMore([
- // ['vote_sub_name', ''],
- // ['vote_id', ''],
- // ['vote_num', ''],
- // ['max_vote_num', ''],
- // ['end_time', ''],
- // ['start_time', ''],
- // ['status', 0],
- // ]);
- // VoteSub::beginTrans();
- // try {
- // if (!$data['vote_id']) JsonService::fail('请选择投票');
- // if (!$data['start_time']) JsonService::fail('请输入开始时间');
- // if (!$data['end_time']) JsonService::fail('请输入结束时间');
- // $data['start_time'] = strtotime($data['start_time']);
- // $data['end_time'] = strtotime($data['end_time']);
- // if ($data['end_time'] <= $data['start_time']) JsonService::fail('结束时间要大于开始时间');
- // if (!$id) $data['loop'] = VoteSub::where('vote_id', $data['vote_id'])->max('loop') + 1;
- // //修改
- // if ($id) {
- // if (VoteSub::edit($data, $id)) {
- // VoteSub::commitTrans();
- // JsonService::successful('修改成功');
- // } else {
- // VoteSub::rollbackTrans();
- // JsonService::fail('修改失败');
- // }
- // } else {
- // //新增
- // $data['add_time'] = time();
- // $res = VoteSub::create($data);
- // if ($res) {
- // VoteModel::commitTrans();
- // JsonService::successful('添加成功');
- // } else {
- // VoteModel::rollbackTrans();
- // JsonService::fail('添加失败');
- // }
- // }
- // } catch (\Exception $e) {
- // VoteModel::rollbackTrans();
- // JsonService::fail($e->getMessage());
- // }
- // }
- // public function see_people($id = 0)
- // {
- // $this->assign([
- // 'id' => $id,
- // ]);
- // return $this->fetch();
- // }
- //
- // public function people_list()
- // {
- // $where = Util::getMore([
- // ['page', 1],
- // ['limit', 20],
- // ['id', 0],
- // ]);
- // Json::successlayui(UserVote::getUserList($where));
- // }
- /**
- * 获取voteSub表
- *
- * @return void
- */
- public function get_sub_list()
- {
- $where = Util::getMore([
- ['page', 1],
- ['limit', 20],
- ['id', 0],
- ]);
- Json::successlayui(UserPointPlan::getList($where));
- }
- }
|