MiningController.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace app\api\controller\mining;
  3. use app\models\lala\LalaPink;
  4. use app\models\lala\LalaPinkJoin;
  5. use app\models\lala\LalaSpExchange;
  6. use app\models\mining\MiningMachine;
  7. use app\models\mining\UserMining;
  8. use app\models\mining\UserMiningMachine;
  9. use app\models\user\User;
  10. use app\models\user\UserBill;
  11. use app\Request;
  12. use crmeb\services\CacheService;
  13. use crmeb\services\UtilService;
  14. use think\db\exception\DataNotFoundException;
  15. use think\db\exception\DbException;
  16. use think\db\exception\ModelNotFoundException;
  17. class MiningController
  18. {
  19. public function mining_index(Request $request)
  20. {
  21. $type = $request->get('type', 'XCH');
  22. $all = UserMiningMachine::where('get_money_type', 'in', $type)->where('uid', $request->uid())->sum('num');
  23. $doing = UserMiningMachine::where('get_money_type', 'in', $type)->where('uid', $request->uid())->where('status', 'in', [1, 2])->sum('num');
  24. $stand = UserMiningMachine::where('get_money_type', 'in', $type)->where('uid', $request->uid())->where('status', 0)->sum('num');
  25. $umids = UserMiningMachine::where('uid', $request->uid())->column('id');
  26. $all_mining = UserMining::where('get_money_type', 'in', $type)->where('umid', 'in', $umids)->sum('get_money');
  27. $all_lock = UserMining::where('get_money_type', 'in', $type)->where('umid', 'in', $umids)->sum('lock_money');
  28. return app('json')->success('ok', compact('all', 'doing', 'stand', 'all_mining', 'all_lock'));
  29. }
  30. /**
  31. * 算力产品
  32. * @param Request $request
  33. * @return mixed
  34. */
  35. public function lst(Request $request)
  36. {
  37. $page = $request->get('page', 1);
  38. $limit = $request->get('limit', 10);
  39. $uid = $request->get('uid', $request->uid());
  40. $get_money_type = $request->get('get_money_type', '');
  41. $type = $request->get('type', '');
  42. return app('json')->success('ok', MiningMachine::getList($page, $limit, ['get_money_type' => $get_money_type, 'type' => $type, 'uid' => $uid]));
  43. }
  44. /**
  45. * @param $id
  46. * @param Request $request
  47. * @return mixed
  48. * @throws DataNotFoundException
  49. * @throws DbException
  50. * @throws ModelNotFoundException
  51. */
  52. public function detail($id, Request $request)
  53. {
  54. $res = MiningMachine::valid()->where('id', $id)->find()->toArray();
  55. $money_type = init_money_type();
  56. $res['_day_get'] = $res['day_get'] . $money_type[$res['get_money_type']] . '/T';
  57. $res['_cost_money'] = $res['cost_money'] . $money_type[$res['cost_money_type']];
  58. $res['_stand_money'] = $res['stand_money'] . $money_type[$res['get_money_type']];
  59. $res['lala'] = LalaPink::get($res['lala_id']);
  60. $res['luck_point'] = LalaPinkJoin::where('paid', 1)->where('lala_id', $res['lala_id'])->where('status', 1)->where('uid', $request->uid())->count();
  61. $res['exchange_point'] = LalaSpExchange::where('lala_id', $res['lala_id'])->where('uid', $request->uid())->sum('cost_time') + UserMiningMachine::where('uid', $request->uid())->where('paid', 1)->where('lala_id', $id)->sum('cost_times');
  62. $res['tags'] = explode(',', $res['tags']);
  63. $res['_cost_money_type'] = $money_type[$res['cost_money_type']];
  64. $res['get_money_type'] = $money_type[$res['get_money_type']];
  65. $res['cost_money_type'] = $money_type[$res['cost_money_type']];
  66. return app('json')->success('ok', $res);
  67. }
  68. public function buy($id, Request $request)
  69. {
  70. $user = $request->user();
  71. list($num,) = UtilService::postMore(
  72. [
  73. ['num', 0,],
  74. ['trade_psw', '', '', '', ['not_empty_check', function ($item) use ($user) {
  75. // var_dump($user);
  76. return md5(md5($item)) == $user['trade_pwd'];
  77. }], ['请输入交易密码', '交易密码错误']],
  78. ], $request, true);
  79. $res = MiningMachine::buyMachine($id, $request->uid(), $num);
  80. if ($res) {
  81. return app('json')->success('购买成功');
  82. } else {
  83. return app('json')->fail(MiningMachine::getErrorInfo());
  84. }
  85. }
  86. public function my(Request $request)
  87. {
  88. $where = UtilService::getMore([
  89. ['page', 1],
  90. ['limit', 10],
  91. ]);
  92. $where['uid'] = $request->uid();
  93. return app('json')->success('ok', UserMiningMachine::getList($where));
  94. }
  95. public function newList(Request $request)
  96. {
  97. $where = UtilService::getMore([
  98. ['page', 1],
  99. ['limit', 10],
  100. ]);
  101. $userStair = [];
  102. $users = [$request->uid()];
  103. while ($users) {
  104. $users = User::where('spread_uid', 'in', $users)->column('uid');
  105. if ($users) $userStair = array_merge($userStair, $users);
  106. }
  107. $where['uid'] = $userStair;
  108. return app('json')->success('ok', UserMiningMachine::getList($where));
  109. }
  110. public function mining_get(Request $request)
  111. {
  112. $where = UtilService::getMore([
  113. ['page', 1],
  114. ['limit', 10],
  115. ['type', 'XCH']
  116. ]);
  117. $where['uid'] = $request->uid();
  118. $umid = UserMiningMachine::where('uid', $where['uid'])->column('id');
  119. return app('json')->success('ok', [
  120. 'all_get' => UserMining::where('get_money_type', $where['type'])->where('umid', 'in', $umid)->sum('get_money'),
  121. 'all_recommend' => UserBill::where('category', $where['type'])->where('uid', $where['uid'])->where('type', 'group_create_brokerage')->where('status', 1)->sum('number'),
  122. 'today_recommend' => UserBill::where('category', $where['type'])->where('uid', $where['uid'])->where('type', 'group_create_brokerage')->where('status', 1)->whereTime('add_time', 'today')->sum('number'),
  123. 'all_unlock' => UserMining::where('get_money_type', $where['type'])->where('umid', 'in', $umid)->sum('unlock'),
  124. 'all_unstand' => UserMining::where('get_money_type', $where['type'])->where('umid', 'in', $umid)->sum('unstand'),
  125. 'all_lock' => UserMining::where('get_money_type', $where['type'])->where('umid', 'in', $umid)->sum('lock_money'),
  126. 'stand' => UserMiningMachine::where('get_money_type', $where['type'])->where('uid', $where['uid'])->sum('stand_money'),
  127. 'list' => UserMining::getList($where)
  128. ]);
  129. }
  130. public function mortgage($id, Request $request)
  131. {
  132. $user = $request->user();
  133. UtilService::postMore(
  134. [
  135. ['trade_psw', '', '', '', ['not_empty_check', function ($item) use ($user) {
  136. // var_dump($user);
  137. return md5(md5($item)) == $user['trade_pwd'];
  138. }], ['请输入交易密码', '交易密码错误']],
  139. ], $request, true);
  140. $res = UserMiningMachine::mortgageMachine($id, $request->uid());
  141. if ($res) {
  142. return app('json')->success('抵押成功');
  143. } else {
  144. return app('json')->fail(UserMiningMachine::getErrorInfo());
  145. }
  146. }
  147. public function redeem($id, Request $request)
  148. {
  149. $user = $request->user();
  150. UtilService::postMore(
  151. [
  152. ['trade_psw', '', '', '', ['not_empty_check', function ($item) use ($user) {
  153. // var_dump($user);
  154. return md5(md5($item)) == $user['trade_pwd'];
  155. }], ['请输入交易密码', '交易密码错误']],
  156. ], $request, true);
  157. $res = UserMiningMachine::redeemMachine($id, $request->uid());
  158. if ($res) {
  159. return app('json')->success('购买成功');
  160. } else {
  161. return app('json')->fail(UserMiningMachine::getErrorInfo());
  162. }
  163. }
  164. }