PointPlanController.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\api\controller;
  3. use app\models\point_plan\PointPlan;
  4. use app\models\point_plan\UserPointPlan;
  5. use app\models\trade\CashTradeOrder;
  6. use app\models\vote\Vote;
  7. use app\Request;
  8. use crmeb\services\CacheService;
  9. use crmeb\services\UtilService;
  10. class PointPlanController
  11. {
  12. public function lst(Request $request)
  13. {
  14. $list = PointPlan::where('start_time', '<=', time())->where('is_del', 0)->select()->each(function ($item) {
  15. $item['request_num'] = UserPointPlan::where('plan_id', $item['id'])->where('status', 'in', [0, 1])->where('check_end_time', '>', time())->count();
  16. })->toArray();
  17. return app('json')->success('ok', $list);
  18. }
  19. public function request_point($id, Request $request)
  20. {
  21. $user = $request->user();
  22. $uid = $request->uid();
  23. $info = PointPlan::where('start_time', '<=', time())->where('is_del', 0)->where('id', $id)->find();
  24. if (!$info) {
  25. return app('json')->fail('找不到计划');
  26. }
  27. if (UserPointPlan::where('plan_id', $info['id'])->where('status', 'in', [0, 1])->where('check_end_time', '>', time())->count() >= $info['num']) {
  28. return app('json')->fail('节点已经认购完');
  29. }
  30. if (UserPointPlan::where('uid', $uid)->where('status', 'in', [0, 1])->where('check_end_time', '>', time())->find()) {
  31. return app('json')->fail('已经认购节点了');
  32. }
  33. list(, $captcha) = UtilService::postMore(
  34. [
  35. ['trade_psw', '', '', '', ['not_empty_check', function ($item) use ($user) {
  36. return md5(md5($item)) == $user['trade_pwd'];
  37. }], ['请输入交易密码', '交易密码错误']],
  38. ['captcha', '']
  39. ], $request, true);
  40. $type = $info['buy_money_type'];
  41. $price = 0;
  42. $list = sys_data('money_type');
  43. foreach ($list as $v) {
  44. if ($v['code'] == $type) {
  45. $price = $v['price'] ? $v['price'] : CashTradeOrder::averagePrice($v['code']);
  46. }
  47. }
  48. if (bcmul(bcmul($info['buy_num'], $info['buy_price'], 8), $price, 2) >= 10000) {
  49. $verifyCode = CacheService::get('code_' . $user['account']);
  50. if (!$verifyCode)
  51. return app('json')->fail('请先获取验证码');
  52. $verifyCode = substr($verifyCode, 0, 6);
  53. if ($verifyCode != $captcha)
  54. return app('json')->fail('验证码错误');
  55. }
  56. $res = PointPlan::joinPlan($id, $uid);
  57. if ($res) {
  58. return app('json')->success('认购完成');
  59. } else {
  60. return app('json')->fail('认购失败:' . PointPlan::getErrorInfo('认购错误'));
  61. }
  62. }
  63. public function my_point(Request $request)
  64. {
  65. $res = UserPointPlan::where('uid', $request->uid())
  66. ->where('status', 'in', [0, 1])
  67. // ->where('check_end_time', '>', time())
  68. ->find()->toArray();
  69. if ($res)
  70. $res['plan'] = PointPlan::get($res['plan_id']);
  71. return app('json')->success('ok', $res);
  72. }
  73. }