123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <?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 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 as Url;
- use app\models\point_plan\{PointPlan as PointPlanModel, UserPointPlan};
- class PointPlan extends AuthController
- {
-
- public function index()
- {
- $this->assign('count_plan', PointPlanModel::count());
- return $this->fetch();
- }
-
- public function get_list()
- {
- $where = Util::getMore([
- ['page', 1],
- ['limit', 20],
- ['title', ''],
- ['status', ''],
- ]);
- Json::successlayui(PointPlanModel::getList($where));
- }
-
- 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']];
- }
- $level = SystemUserLevel::setWhere(['is_show' => 1])->field('name as label,id as value')->select()->toArray();
- $level = array_merge([['value' => 0, 'label' => '不赠送']], $level);
- $machine = MiningMachine::valid()->field('name as label,id as value')->select()->toArray();
- $machine = array_merge([['value' => 0, 'label' => '不赠送']], $machine);
- if ($id) $info = PointPlanModel::get($id);
- $field[] = Form::input('plan_name', '计划标题', isset($info) ? $info->plan_name : '')->col(Form::col(24))->required();
- $field[] = Form::number('release_money', '释放币量', isset($info) ? $info->release_money : '')->step(0.00000001)->col(24)->required();
- $field[] = Form::select('release_money_type', '释放币种', isset($info) ? $info->release_money_type : '')->options($money_type_select)->col(24)->required();
- $field[] = Form::number('release_days', '释放天数', isset($info) ? $info->release_days : 0)->min(0)->col(12)->required();
- $field[] = Form::select('buy_money_type', '认购币种', isset($info) ? $info->buy_money_type : '')->options($money_type_select)->col(24)->required();
- $field[] = Form::number('buy_price', '认购价格', isset($info) ? $info->buy_price : 0)->step(0.00000001)->col(24)->required();
- $field[] = Form::number('stock', '库存', isset($info) ? $info->stock : 0)->min(0)->step(0.01)->col(12)->required();
- $field[] = Form::number('all_stock', '总库存', isset($info) ? $info->all_stock : 0)->min(0)->step(0.01)->col(12)->required();
- $field[] = Form::select('give_level', '赠送等级', (string)(isset($info) ? $info->give_level : 0))->options($level)->col(12)->required();
- $field[] = Form::select('give_mining_machine', '赠送矿机', (string)(isset($info) ? $info->give_mining_machine : 0))->options($machine)->col(12)->required();
- $field[] = Form::number('give_mining_machine_num', '赠送矿机算力', isset($info) ? $info->give_mining_machine_num : 0)->step(0.01)->col(12)->required();
- $field[] = Form::number('ticket_ratio', '门票分红(%)', isset($info) ? $info->ticket_ratio : 0)->min(0)->step(0.01)->col(12)->required();
- $field[] = Form::number('service_ratio', '手续费分红(%)', isset($info) ? $info->service_ratio : 0)->min(0)->step(0.01)->col(12)->required();
- $field[] = Form::radio('status', '状态', isset($info) ? $info->status : 0)->options([['label' => '等待', 'value' => 0], ['label' => '开启', 'value' => 1], ['label' => '结束', 'value' => 2]])->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');
- }
-
- public function save($id = 0)
- {
- $data = UtilService::postMore([
- ['plan_name', ''],
- ['release_money', ''],
- ['release_money_type', 0],
- ['release_days', 0],
- ['buy_money_type', ''],
- ['buy_price', 0],
- ['stock', 0],
- ['all_stock', 0],
- ['give_level', 0],
- ['give_mining_machine', 0],
- ['give_mining_machine_num', 0],
- ['ticket_ratio', 0],
- ['service_ratio', 0],
- ['status', 0],
- ]);
- PointPlanModel::beginTrans();
- if ($data['stock'] > $data['all_stock']) {
- JsonService::fail('库存不大于总库存');
- }
- try {
-
- if ($id) {
- if ($data['status']) $data['start_time'] = time();
- if (PointPlanModel::edit($data, $id)) {
- PointPlanModel::commitTrans();
- JsonService::successful('修改成功');
- } else {
- PointPlanModel::rollbackTrans();
- JsonService::fail('修改失败');
- }
- } else {
-
- $data['add_time'] = time();
- if ($data['status']) $data['start_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();
- }
-
- public function get_sub_list()
- {
- $where = Util::getMore([
- ['page', 1],
- ['limit', 20],
- ['id', 0],
- ]);
- Json::successlayui(UserPointPlan::getList($where));
- }
- }
|