Mining.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/11
  6. */
  7. namespace app\admin\controller\mining;
  8. use app\admin\controller\AuthController;
  9. use app\models\mining\MiningMachine;
  10. use app\models\mining\UserMiningMachine;
  11. use crmeb\services\FormBuilder;
  12. use crmeb\services\JsonService;
  13. use crmeb\services\UtilService;
  14. use think\facade\Route;
  15. /**
  16. * 用户管理控制器
  17. * Class User
  18. * @package app\admin\controller\user
  19. */
  20. class Mining extends AuthController
  21. {
  22. /**
  23. * 显示资源列表
  24. *
  25. * @return string|\think\Response
  26. */
  27. public function index()
  28. {
  29. return $this->fetch();
  30. }
  31. /**
  32. * 分组列表
  33. */
  34. public function getList()
  35. {
  36. $where = UtilService::getMore([
  37. ['page', 1],
  38. ['limit', 20],
  39. ]);
  40. JsonService::successlayui(MiningMachine::getList((int)$where['page'], (int)$where['limit']));
  41. }
  42. /**
  43. * 添加/修改分组页面
  44. * @param int $id
  45. * @return string
  46. */
  47. public function add($id = 0)
  48. {
  49. $money_type = sys_data('money_type');
  50. $money_type_select = [];
  51. foreach ($money_type as $v) {
  52. $money_type_select[] = ['label' => $v['name'], 'value' => $v['code']];
  53. }
  54. $group = MiningMachine::get($id);
  55. $f = array();
  56. $f[] = FormBuilder::input('name', '矿机名称', $group ? $group->name : '')->required();
  57. $f[] = FormBuilder::frameImageOne('logo', '图标', Route::buildUrl('admin/widget.images/index', array('fodder' => 'logo')), $group ? $group->getData('logo') : '')->icon('image')->width('100%')->height('500px');
  58. $f[] = FormBuilder::select('type', '矿机类型', $group ? (string)$group->type : '1')->setOptions([['value' => 1, 'label' => '算力包'], ['value' => 2, 'label' => '独享矿机'], ['value' => 3, 'label' => '联合挖矿']])->required();
  59. $f[] = FormBuilder::number('day_get', '每日收益', $group ? $group->day_get : 0)->required()->step(0.00000001);
  60. $f[] = FormBuilder::select('get_money_type', '收益币种', $group ? $group->get_money_type : '')->setOptions($money_type_select)->required();
  61. $f[] = FormBuilder::number('stand_time', '等待时间(天)', $group ? $group->stand_time : 0)->required();
  62. $f[] = FormBuilder::number('cost_money', '购买价格', $group ? $group->cost_money : '')->step(0.00000001)->required();
  63. $f[] = FormBuilder::select('cost_money_type', '购买币种', $group ? $group->cost_money_type : '')->setOptions($money_type_select)->required();
  64. $f[] = FormBuilder::number('stand_money', '质押金', $group ? $group->stand_money : '')->step(0.00000001)->required();
  65. $f[] = FormBuilder::number('stock', '库存', $group ? $group->stock : 0)->step(2)->required();
  66. $f[] = FormBuilder::number('all_stock', '总库存', $group ? $group->all_stock : 0)->step(2)->required();
  67. $f[] = FormBuilder::number('first_step_time', '第一阶段时间', $group ? $group->first_step_time : 0)->required();
  68. $f[] = FormBuilder::number('first_step_get_ratio', '第一阶段释放比例(%)', $group ? $group->first_step_get_ratio : 0)->step(0.01)->required();
  69. $f[] = FormBuilder::number('second_step_time', '第二阶段时间', $group ? $group->second_step_time : 0)->required();
  70. $f[] = FormBuilder::number('second_step_get_ratio', '第二阶段释放比例(%)', $group ? $group->second_step_get_ratio : 0)->step(0.01)->required();
  71. $f[] = FormBuilder::number('third_step_time', '第三阶段时间', $group ? $group->third_step_time : 0)->required();
  72. $f[] = FormBuilder::number('service_ratio', '服务费比例(%)', $group ? $group->service_ratio : 0)->step(0.01)->required();
  73. $f[] = FormBuilder::number('step', '算力基数(T)', $group ? $group->step : 1)->step(0.01)->required();
  74. $form = FormBuilder::make_post_form('添加矿机产品', $f, Route::buildUrl('save', array('id' => $id)));
  75. $this->assign(compact('form'));
  76. return $this->fetch('public/form-builder');
  77. }
  78. /**
  79. * 添加/修改
  80. * @param int $id
  81. */
  82. public function save($id = 0)
  83. {
  84. $data = UtilService::postMore([
  85. ['name', ''],
  86. ['logo', ''],
  87. ['day_get', 0],
  88. ['stand_time', 0],
  89. ['get_money_type', ''],
  90. ['cost_money_type', ''],
  91. ['cost_money', 0],
  92. ['stock', 0],
  93. ['all_stock', 0],
  94. ['stand_money', 0],
  95. ['first_step_time', 0],
  96. ['first_step_get_ratio', 0],
  97. ['second_step_time', 0],
  98. ['second_step_get_ratio', 0],
  99. ['third_step_time', 0],
  100. ['service_ratio', 0],
  101. ['type', 1],
  102. ['step', 1],
  103. ]);
  104. if ($id) {
  105. if ($data['all_stock'] < $data['stock']) {
  106. JsonService::fail('总库存不小于实际库存!');
  107. }
  108. if (MiningMachine::where('id', $id)->update($data)) {
  109. JsonService::success('修改成功');
  110. } else {
  111. JsonService::fail('修改失败或者您没有修改什么!');
  112. }
  113. } else {
  114. if ($data['all_stock'] < $data['stock']) {
  115. JsonService::fail('总库存不小于实际库存!');
  116. }
  117. if ($res = MiningMachine::create($data)) {
  118. JsonService::success('保存成功', ['id' => $res->id]);
  119. } else {
  120. JsonService::fail('保存失败!');
  121. }
  122. }
  123. }
  124. /**
  125. * @param $id
  126. * @return string|void
  127. * @throws \Exception
  128. */
  129. public function detail($id)
  130. {
  131. if (!$id) $this->failed('数据不存在');
  132. $info = MiningMachine::get($id);
  133. if (!$info) $this->failed('数据不存在!');
  134. $this->assign([
  135. 'content' => htmlspecialchars_decode($info['detail']),
  136. 'field' => 'detail',
  137. 'action' => Route::buildUrl('change_field', ['id' => $id, 'field' => 'detail'])
  138. ]);
  139. return $this->fetch('public/edit_content');
  140. }
  141. /**
  142. * @param $id
  143. */
  144. public function change_field($id)
  145. {
  146. if (!$id) JsonService::fail('数据不存在');
  147. $seckill = MiningMachine::get($id);
  148. if (!$seckill) JsonService::fail('数据不存在!');
  149. $data['detail'] = request()->post('detail');
  150. $res = MiningMachine::edit($data, $id);
  151. if ($res)
  152. JsonService::successful('修改成功');
  153. else
  154. JsonService::fail('修改失败');
  155. }
  156. /**
  157. * 删除
  158. * @param $id
  159. * @throws \Exception
  160. */
  161. public function delete($id)
  162. {
  163. if (!$id) JsonService::fail('数据不存在');
  164. if (!MiningMachine::be(['id' => $id])) JsonService::fail('数据不存在');
  165. if (UserMiningMachine::where('mid', $id)->where('status', 'in', [0, 1])->where('paid', 1)->find()) {
  166. JsonService::fail(MiningMachine::getErrorInfo('矿机尚在使用,无法删除!'));
  167. }
  168. if (!MiningMachine::where('id', $id)->update(['is_del' => 1]))
  169. JsonService::fail(MiningMachine::getErrorInfo('删除失败,请稍候再试!'));
  170. else
  171. JsonService::successful('删除成功!');
  172. }
  173. public function order()
  174. {
  175. $this->assign([
  176. 'year' => get_month(),
  177. 'real_name' => $this->request->get('real_name', ''),
  178. 'status' => $this->request->param('status', ''),
  179. 'orderCount' => UserMiningMachine::orderCount(),
  180. ]);
  181. return $this->fetch();
  182. }
  183. /**
  184. * 获取头部订单金额等信息
  185. * return json
  186. */
  187. public function getBadge()
  188. {
  189. $where = UtilService::postMore([
  190. ['status', ''],
  191. ['real_name', ''],
  192. ['data', ''],
  193. ]);
  194. JsonService::successful(UserMiningMachine::getBadge($where));
  195. }
  196. /**
  197. * 分组列表
  198. */
  199. public function getOrderList()
  200. {
  201. $where = UtilService::getMore([
  202. ['status', ''],
  203. ['real_name', ''],
  204. ['data', ''],
  205. ['page', 1],
  206. ['limit', 20],
  207. ]);
  208. JsonService::successlayui(UserMiningMachine::getList($where));
  209. }
  210. }