Mining.php 10 KB

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