Mining.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. $f[] = FormBuilder::number('elect_fee', '电费', $group ? $group->elect_fee : 1)->step(0.01)->required();
  75. $f[] = FormBuilder::input('tags', '标签(半角逗号分隔)', $group ? $group->tags : 1);
  76. $form = FormBuilder::make_post_form('添加矿机产品', $f, Route::buildUrl('save', array('id' => $id)));
  77. $this->assign(compact('form'));
  78. return $this->fetch('public/form-builder');
  79. }
  80. /**
  81. * 添加/修改
  82. * @param int $id
  83. */
  84. public function save($id = 0)
  85. {
  86. $data = UtilService::postMore([
  87. ['name', ''],
  88. ['logo', ''],
  89. ['day_get', 0],
  90. ['stand_time', 0],
  91. ['get_money_type', ''],
  92. ['cost_money_type', ''],
  93. ['cost_money', 0],
  94. ['stock', 0],
  95. ['all_stock', 0],
  96. ['stand_money', 0],
  97. ['first_step_time', 0],
  98. ['first_step_get_ratio', 0],
  99. ['second_step_time', 0],
  100. ['second_step_get_ratio', 0],
  101. ['third_step_time', 0],
  102. ['service_ratio', 0],
  103. ['elect_fee', 0],
  104. ['type', 1],
  105. ['step', 1],
  106. ['tags', ''],
  107. ]);
  108. if ($id) {
  109. if ($data['all_stock'] < $data['stock']) {
  110. JsonService::fail('总库存不小于实际库存!');
  111. }
  112. if (MiningMachine::where('id', $id)->update($data)) {
  113. JsonService::success('修改成功');
  114. } else {
  115. JsonService::fail('修改失败或者您没有修改什么!');
  116. }
  117. } else {
  118. if ($data['all_stock'] < $data['stock']) {
  119. JsonService::fail('总库存不小于实际库存!');
  120. }
  121. if ($res = MiningMachine::create($data)) {
  122. JsonService::success('保存成功', ['id' => $res->id]);
  123. } else {
  124. JsonService::fail('保存失败!');
  125. }
  126. }
  127. }
  128. /**
  129. * @param $id
  130. * @return string|void
  131. * @throws \Exception
  132. */
  133. public function detail($id)
  134. {
  135. if (!$id) $this->failed('数据不存在');
  136. $info = MiningMachine::get($id);
  137. if (!$info) $this->failed('数据不存在!');
  138. $this->assign([
  139. 'content' => htmlspecialchars_decode($info['detail']),
  140. 'field' => 'detail',
  141. 'action' => Route::buildUrl('change_field', ['id' => $id, 'field' => 'detail'])
  142. ]);
  143. return $this->fetch('public/edit_content');
  144. }
  145. /**
  146. * @param $id
  147. */
  148. public function change_field($id)
  149. {
  150. if (!$id) JsonService::fail('数据不存在');
  151. $seckill = MiningMachine::get($id);
  152. if (!$seckill) JsonService::fail('数据不存在!');
  153. $data['detail'] = request()->post('detail');
  154. $res = MiningMachine::edit($data, $id);
  155. if ($res)
  156. JsonService::successful('修改成功');
  157. else
  158. JsonService::fail('修改失败');
  159. }
  160. /**
  161. * 删除
  162. * @param $id
  163. * @throws \Exception
  164. */
  165. public function delete($id)
  166. {
  167. if (!$id) JsonService::fail('数据不存在');
  168. if (!MiningMachine::be(['id' => $id])) JsonService::fail('数据不存在');
  169. if (UserMiningMachine::where('mid', $id)->where('status', 'in', [0, 1])->where('paid', 1)->find()) {
  170. JsonService::fail(MiningMachine::getErrorInfo('矿机尚在使用,无法删除!'));
  171. }
  172. if (!MiningMachine::where('id', $id)->update(['is_del' => 1]))
  173. JsonService::fail(MiningMachine::getErrorInfo('删除失败,请稍候再试!'));
  174. else
  175. JsonService::successful('删除成功!');
  176. }
  177. public function order()
  178. {
  179. $this->assign([
  180. 'year' => get_month(),
  181. 'real_name' => $this->request->get('real_name', ''),
  182. 'status' => $this->request->param('status', ''),
  183. 'orderCount' => UserMiningMachine::orderCount(),
  184. ]);
  185. return $this->fetch();
  186. }
  187. /**
  188. * 获取头部订单金额等信息
  189. * return json
  190. */
  191. public function getBadge()
  192. {
  193. $where = UtilService::postMore([
  194. ['status', ''],
  195. ['real_name', ''],
  196. ['data', ''],
  197. ]);
  198. JsonService::successful(UserMiningMachine::getBadge($where));
  199. }
  200. /**
  201. * 分组列表
  202. */
  203. public function getOrderList()
  204. {
  205. $where = UtilService::getMore([
  206. ['status', ''],
  207. ['real_name', ''],
  208. ['data', ''],
  209. ['page', 1],
  210. ['limit', 20],
  211. ]);
  212. JsonService::successlayui(UserMiningMachine::getList($where));
  213. }
  214. }