LalaPinkController.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. namespace app\api\controller\activity;
  3. use app\models\lala\AutoPink;
  4. use app\models\lala\LalaPink;
  5. use app\models\lala\LalaPinkJoin;
  6. use app\models\lala\LalaPinkLog;
  7. use app\models\lala\LalaSpExchange;
  8. use app\models\lala\UserAutoPink;
  9. use app\models\mining\UserMiningMachine;
  10. use app\models\user\User;
  11. use app\Request;
  12. use crmeb\services\UtilService;
  13. class LalaPinkController
  14. {
  15. public function lst(Request $request)
  16. {
  17. list($page, $limit) = UtilService::getMore([['page', 1], ['limit', 10]], $request, true);
  18. return app('json')->success('ok', ['list' => LalaPink::getList([], $page, $limit)]);
  19. }
  20. public function detail($id, Request $request)
  21. {
  22. list($page, $limit) = UtilService::getMore([['page', 1], ['limit', 10]], $request, true);
  23. $lala_pink_open = sys_config('lala_pink_open');
  24. $lala_pink_close = sys_config('lala_pink_close');
  25. // $next_pink = LalaPinkLog::max('add_time') + 7200;
  26. $open_times = open_times();
  27. //上次开奖
  28. $last_log = LalaPinkLog::order('add_time', 'desc')->find();
  29. //下次开奖
  30. $next_pink = [];
  31. $next_next_pink = [];
  32. foreach ($open_times as $k => $v) {
  33. if ($v['value'] > time() && $v['value'] > $last_log['add_time']) {
  34. $next_pink = $v;
  35. $next_next_pink = $open_times[$k + 1];
  36. break;
  37. }
  38. }
  39. $data = LalaPink::validWhere()->where('id', $id)->find()->toArray();
  40. if ($data['ticket_money_type'] != 'LALA') {
  41. $money_types = sys_data('money_type');
  42. $origin_ratio = 0;
  43. $target_ratio = 0;
  44. foreach ($money_types as $v) {
  45. if ($v['code'] == $data['ticket_money_type']) {
  46. $origin_ratio = $v['usdt_price'];
  47. if ($origin_ratio == 0) {
  48. $origin_ratio = get_huobi_price($v['code']);
  49. }
  50. }
  51. if ($v['code'] == 'LALA') {
  52. $target_ratio = get_lala_ratio();
  53. }
  54. }
  55. $ratio = bcdiv($origin_ratio, $target_ratio, 14);
  56. $data['ticket'] = bcmul($data['ticket'], $ratio, 8);
  57. $data['ticket_money_type'] = 'LALA';
  58. }
  59. $data['ticket_money_type_name'] = get_money_name($data['ticket_money_type']);
  60. $data['cost_money_type_name'] = get_money_name($data['cost_money_type']);
  61. $data['cost_2_money_type_name'] = get_money_name($data['cost_2_money_type']);
  62. $data['bingo_money_type_name'] = get_money_name($data['bingo_money_type']);
  63. $data['sp_exchange_origin'] = get_money_name($data['sp_exchange_origin']);
  64. $data['sp_exchange_target'] = get_money_name($data['sp_exchange_target']);
  65. $data['_ticket'] = ($data['ticket'] * 1) . $data['ticket_money_type'];
  66. return app('json')->success('ok', [
  67. 'luck_point' => LalaPinkJoin::where('paid', 1)->where('lala_id', $id)->where('status', 1)->where('uid', $request->uid())->count(),
  68. 'exchange_point' => LalaSpExchange::where('lala_id', $id)->where('uid', $request->uid())->sum('cost_time') + UserMiningMachine::where('uid', $request->uid())->where('paid', 1)->where('lala_id', $id)->sum('cost_times'),
  69. 'close_join' => sys_config('lala_pink_close_join_before_open'),
  70. 'open_times' => open_times(),
  71. 'next_pink' => $next_pink,
  72. 'next_pink_status' => false != LalaPinkJoin::where('paid', 1)->where('lala_id', $id)->where('status', 0)->where('uid', $request->uid())->find(),
  73. 'next_next_pink' => $next_next_pink,
  74. 'lala_pink_open' => $lala_pink_open,
  75. 'lala_pink_close' => $lala_pink_close,
  76. 'data' => $data,
  77. 'history_list' => LalaPinkJoin::group('group_id')->field('group_id,COUNT(id) as counts,AVG(open_time) as open_time,AVG(group_num) as group_num')->order('open_time desc')->page((int)$page, (int)$limit)->select(),
  78. ]);
  79. }
  80. public function join($id, Request $request)
  81. {
  82. $user = User::get($request->uid());
  83. UtilService::postMore(
  84. [
  85. ['trade_psw', '', '', '', ['not_empty_check', function ($item) use ($user) {
  86. return md5(md5($item)) == $user['trade_pwd'];
  87. }], ['请输入交易密码', '交易密码错误']],
  88. ], $request);
  89. $cost_type = $request->post('cost_type', '');
  90. $res = LalaPinkJoin::join($request->uid(), $id, $cost_type);
  91. if (!$res) {
  92. return app('json')->fail(LalaPinkJoin::getErrorInfo('参与失败'));
  93. } else {
  94. return app('json')->success('参与成功,等待开奖!');
  95. }
  96. }
  97. public function joinList(Request $request)
  98. {
  99. list($page, $limit, $id) = UtilService::getMore([['page', 1], ['limit', 10], ['id', '']], $request, true);
  100. return app('json')->success('ok', LalaPinkJoin::getList(['uid' => $request->uid(), 'id' => $id], $page, $limit));
  101. }
  102. public function joinDetail($id, Request $request)
  103. {
  104. return app('json')->success('ok', LalaPinkJoin::getDetail(['uid' => $request->uid(), 'id' => $id]));
  105. }
  106. public function spExchange($id, Request $request)
  107. {
  108. $res = LalaPink::spExchange($request->uid(), $id);
  109. if (!$res) {
  110. return app('json')->fail(LalaPink::getErrorInfo('兑换失败'));
  111. } else {
  112. return app('json')->success('兑换成功');
  113. }
  114. }
  115. public function spExchangeList($id, Request $request)
  116. {
  117. list($page, $limit) = UtilService::getMore([['page', 1], ['limit', 10]], $request, true);
  118. return app('json')->success(LalaPink::getExchangeList($id, $request->uid(), $page, $limit));
  119. }
  120. //自动拼团列表
  121. public function autoPinkList(Request $request)
  122. {
  123. list($page, $limit, $lala_id) = UtilService::getMore([['page', 1], ['limit', 10], ['lala_id', '']], $request, true);
  124. $where['lala_id'] = $lala_id;
  125. return app('json')->success(AutoPink::getList($where, $page, $limit));
  126. }
  127. //自动拼团详情
  128. public function autoPinkDetail($id, Request $request)
  129. {
  130. $info = AutoPink::validWhere()->find($id);
  131. if ($info) $info = $info->toArray();
  132. if ($info) $info['money_type'] = get_money_name($info['money_type']);
  133. if ($info) {
  134. $time = time();
  135. do {
  136. $info['my'] = UserAutoPink::where('uid', $request->uid())->where('auto_id', $id)->where('add_time', '<', $time)->order('add_time', 'desc')->find();
  137. $time = $info['my'] ? $info['my']['add_time'] : 0;
  138. if ($info['my']['is_forever'] || $info['my']['valid_time'] > time()) break;
  139. } while ($info['my']);
  140. }
  141. if ($info) $info['lalas'] = LalaPink::where('id', 'in', explode(',', $info['lala_id']))->select()->toArray();
  142. return app('json')->success('ok', $info);
  143. }
  144. //开通自动拼团
  145. public function openAutoPink($id, Request $request)
  146. {
  147. $user = User::get($request->uid());
  148. UtilService::postMore(
  149. [
  150. ['trade_psw', '', '', '', ['not_empty_check', function ($item) use ($user) {
  151. return md5(md5($item)) == $user['trade_pwd'];
  152. }], ['请输入交易密码', '交易密码错误']],
  153. ], $request);
  154. $res = UserAutoPink::open($request->uid(), $id);
  155. if (!$res) {
  156. return app('json')->fail(LalaPinkJoin::getErrorInfo('开通失败'));
  157. } else {
  158. return app('json')->success('已开通');
  159. }
  160. }
  161. //修改自动拼团状态
  162. public function switchAutoPinkStatus($id, Request $request)
  163. {
  164. $info = UserAutoPink::where('uid', $request->uid())->where('id', $id)->find();
  165. if (!$info) {
  166. return app('json')->fail('开通记录不存在');
  167. }
  168. if (!$info['is_forever'] && $info['valid_time'] < time()) return app('json')->fail('自动拼购已到期');
  169. if ($info['status']) {
  170. $res = UserAutoPink::where('id', $id)->update(['status' => 0]);
  171. } else {
  172. $res = UserAutoPink::where('id', $id)->update(['status' => 1]);
  173. }
  174. if (!$res) {
  175. return app('json')->fail(LalaPinkJoin::getErrorInfo('操作失败'));
  176. } else {
  177. return app('json')->success('操作成功');
  178. }
  179. }
  180. }