123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <?php
- /**
- *
- * @author: xaboy<365615158@qq.com>
- * @day: 2017/11/11
- */
- namespace app\admin\controller\mining;
- use app\admin\controller\AuthController;
- use app\models\lala\LalaPink;
- use app\models\mining\MiningMachine;
- use app\models\mining\UserMiningMachine;
- use crmeb\services\FormBuilder;
- use crmeb\services\JsonService;
- use crmeb\services\UtilService;
- use think\facade\Route;
- /**
- * 用户管理控制器
- * Class User
- * @package app\admin\controller\user
- */
- class Mining extends AuthController
- {
- /**
- * 显示资源列表
- *
- * @return string|\think\Response
- */
- public function index()
- {
- return $this->fetch();
- }
- /**
- * 分组列表
- */
- public function getList()
- {
- $where = UtilService::getMore([
- ['page', 1],
- ['limit', 20],
- ]);
- JsonService::successlayui(MiningMachine::getList((int)$where['page'], (int)$where['limit']));
- }
- /**
- * 添加/修改分组页面
- * @param int $id
- * @return string
- */
- public function add($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']];
- }
- $lala_list = LalaPink::validWhere()->field('id as value,name as label')->select()->toArray();
- $group = MiningMachine::get($id);
- $f = array();
- $f[] = FormBuilder::input('name', '矿机名称', $group ? $group->name : '')->required();
- $f[] = FormBuilder::frameImageOne('logo', '图标', Route::buildUrl('admin/widget.images/index', array('fodder' => 'logo')), $group ? $group->getData('logo') : '')->icon('image')->width('100%')->height('500px');
- $f[] = FormBuilder::frameImages('imgs', '轮播图', Route::buildUrl('admin/widget.images/index', array('fodder' => 'imgs')), $group ? explode(',', $group->getData('imgs')) : [])->maxLength(5)->icon('image')->width('100%')->height('500px');
- $f[] = FormBuilder::select('type', '矿机类型', $group ? (string)$group->type : '1')->setOptions([['value' => 1, 'label' => '算力包'], ['value' => 2, 'label' => '独享矿机'], ['value' => 3, 'label' => '联合挖矿']])->required();
- $f[] = FormBuilder::number('day_get', '每日收益', $group ? $group->day_get : 0)->required()->step(0.00000001);
- $f[] = FormBuilder::select('get_money_type', '收益币种', $group ? $group->get_money_type : '')->setOptions($money_type_select)->required();
- $f[] = FormBuilder::number('stand_time', '等待时间(天)', $group ? $group->stand_time : 0)->required();
- $f[] = FormBuilder::number('cost_money', '购买价格', $group ? $group->cost_money : '')->step(0.00000001)->required();
- $f[] = FormBuilder::select('cost_money_type', '购买币种', $group ? $group->cost_money_type : '')->setOptions($money_type_select)->required();
- $f[] = FormBuilder::number('cost_times', '消耗中奖次数', $group ? $group->cost_times : '')->min(0)->step(1)->required();
- $f[] = FormBuilder::select('lala_id', '所属拼购', (string)($group ? $group->lala_id : ''))->setOptions($lala_list)->required();
- $f[] = FormBuilder::number('stand_money', '质押金', $group ? $group->stand_money : '')->step(0.00000001)->required();
- $f[] = FormBuilder::number('mortgage_money', '可抵押获得', $group ? $group->mortgage_money : '')->step(0.00000001)->required();
- $f[] = FormBuilder::select('mortgage_money_type', '抵押获得币种', $group ? $group->mortgage_money_type : '')->setOptions($money_type_select)->required();
- $f[] = FormBuilder::number('redeem_money', '赎回价格', $group ? $group->redeem_money : '')->step(0.00000001)->required();
- $f[] = FormBuilder::select('redeem_money_type', '赎回币种', $group ? $group->redeem_money_type : '')->setOptions($money_type_select)->required();
- $f[] = FormBuilder::number('redeem_day', '赎回时限(天)', $group ? $group->redeem_day : 0)->required();
- $f[] = FormBuilder::number('stock', '库存', $group ? $group->stock : 0)->step(2)->required();
- $f[] = FormBuilder::number('all_stock', '总库存', $group ? $group->all_stock : 0)->step(2)->required();
- $f[] = FormBuilder::number('first_step_time', '第一阶段时间', $group ? $group->first_step_time : 0)->required();
- $f[] = FormBuilder::number('first_step_get_ratio', '第一阶段释放比例(%)', $group ? $group->first_step_get_ratio : 0)->step(0.01)->required();
- $f[] = FormBuilder::number('second_step_time', '第二阶段时间', $group ? $group->second_step_time : 0)->required();
- $f[] = FormBuilder::number('second_step_get_ratio', '第二阶段释放比例(%)', $group ? $group->second_step_get_ratio : 0)->step(0.01)->required();
- $f[] = FormBuilder::number('third_step_time', '第三阶段时间', $group ? $group->third_step_time : 1)->required()->min(1);
- $f[] = FormBuilder::number('service_ratio', '服务费比例(%)', $group ? $group->service_ratio : 0)->step(0.01)->required();
- $f[] = FormBuilder::number('step', '算力基数(T)', $group ? $group->step : 1)->step(0.01)->required();
- $f[] = FormBuilder::number('elect_fee', '电费', $group ? $group->elect_fee : 1)->step(0.01)->required();
- $f[] = FormBuilder::input('tags', '标签(半角逗号分隔)', $group ? $group->tags : 1);
- $form = FormBuilder::make_post_form('添加矿机产品', $f, Route::buildUrl('save', array('id' => $id)));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- /**
- * 添加/修改
- * @param int $id
- */
- public function save($id = 0)
- {
- $data = UtilService::postMore([
- ['name', ''],
- ['logo', ''],
- ['day_get', 0],
- ['stand_time', 0],
- ['get_money_type', ''],
- ['cost_money_type', ''],
- ['cost_money', 0],
- ['stock', 0],
- ['all_stock', 0],
- ['stand_money', 0],
- ['first_step_time', 0],
- ['first_step_get_ratio', 0],
- ['second_step_time', 0],
- ['second_step_get_ratio', 0],
- ['third_step_time', 0],
- ['service_ratio', 0],
- ['elect_fee', 0],
- ['type', 1],
- ['step', 1],
- ['tags', ''],
- ['cost_times', ''],
- ['lala_id', ''],
- ['mortgage_money_type', ''],
- ['mortgage_money', 0],
- ['redeem_money_type', ''],
- ['redeem_money', 0],
- ['redeem_day', 0],
- ['imgs', []],
- ]);
- $data['imgs'] = implode(',', $data['imgs']);
- if ($id) {
- if ($data['all_stock'] < $data['stock']) {
- JsonService::fail('总库存不小于实际库存!');
- }
- if (MiningMachine::where('id', $id)->update($data)) {
- JsonService::success('修改成功');
- } else {
- JsonService::fail('修改失败或者您没有修改什么!');
- }
- } else {
- if ($data['all_stock'] < $data['stock']) {
- JsonService::fail('总库存不小于实际库存!');
- }
- if ($res = MiningMachine::create($data)) {
- JsonService::success('保存成功', ['id' => $res->id]);
- } else {
- JsonService::fail('保存失败!');
- }
- }
- }
- /**
- * @param $id
- * @return string|void
- * @throws \Exception
- */
- public function detail($id)
- {
- if (!$id) $this->failed('数据不存在');
- $info = MiningMachine::get($id);
- if (!$info) $this->failed('数据不存在!');
- $this->assign([
- 'content' => htmlspecialchars_decode($info['detail']),
- '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 = MiningMachine::get($id);
- if (!$seckill) JsonService::fail('数据不存在!');
- $data['detail'] = request()->post('detail');
- $res = MiningMachine::edit($data, $id);
- if ($res)
- JsonService::successful('修改成功');
- else
- JsonService::fail('修改失败');
- }
- /**
- * 删除
- * @param $id
- * @throws \Exception
- */
- public function delete($id)
- {
- if (!$id) JsonService::fail('数据不存在');
- if (!MiningMachine::be(['id' => $id])) JsonService::fail('数据不存在');
- if (UserMiningMachine::where('mid', $id)->where('status', 'in', [0, 1])->where('paid', 1)->find()) {
- JsonService::fail(MiningMachine::getErrorInfo('矿机尚在使用,无法删除!'));
- }
- if (!MiningMachine::where('id', $id)->update(['is_del' => 1]))
- JsonService::fail(MiningMachine::getErrorInfo('删除失败,请稍候再试!'));
- else
- JsonService::successful('删除成功!');
- }
- public function order()
- {
- $this->assign([
- 'year' => get_month(),
- 'real_name' => $this->request->get('real_name', ''),
- 'status' => $this->request->param('status', ''),
- 'orderCount' => UserMiningMachine::orderCount(),
- ]);
- return $this->fetch();
- }
- /**
- * 获取头部订单金额等信息
- * return json
- */
- public function getBadge()
- {
- $where = UtilService::postMore([
- ['status', ''],
- ['real_name', ''],
- ['data', ''],
- ]);
- JsonService::successful(UserMiningMachine::getBadge($where));
- }
- /**
- * 分组列表
- */
- public function getOrderList()
- {
- $where = UtilService::getMore([
- ['status', ''],
- ['real_name', ''],
- ['data', ''],
- ['page', 1],
- ['limit', 20],
- ]);
- JsonService::successlayui(UserMiningMachine::getList($where));
- }
- }
|