PointPlanController.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\user\UserBill;
  6. use app\Request;
  7. use crmeb\services\CacheService;
  8. use crmeb\services\UtilService;
  9. class PointPlanController
  10. {
  11. public function lst(Request $request)
  12. {
  13. $list = PointPlan::where('start_time', '<=', time())->where('status', 1)->select()->each(function ($item) {
  14. $item['request_num'] = UserPointPlan::where('plan_id', $item['id'])->sum('buy_num');
  15. $item['buy_money_type'] = get_money_name($item['buy_money_type']);
  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. // $num = $request->post('num', 1);
  24. $info = PointPlan::where('start_time', '<=', time())->where('status', 1)->where('id', $id)->find();
  25. if (!$info) {
  26. return app('json')->fail('找不到合伙人节点');
  27. }
  28. list($num,) = UtilService::postMore(
  29. [
  30. ['num', 0],
  31. ['trade_psw', '', '', '', ['not_empty_check', function ($item) use ($user) {
  32. return md5(md5($item)) == $user['trade_pwd'];
  33. }], ['请输入交易密码', '交易密码错误']],
  34. ], $request, true);
  35. if ($num <= 0) return app('json')->fail('认购股数大于0');
  36. if ($info['stock'] < $num) {
  37. return app('json')->fail('节点库存不足');
  38. }
  39. $res = PointPlan::joinPlan($id, $uid, $num);
  40. if ($res) {
  41. return app('json')->success('认购完成');
  42. } else {
  43. return app('json')->fail('认购失败:' . PointPlan::getErrorInfo('认购错误'));
  44. }
  45. }
  46. public function my_point(Request $request)
  47. {
  48. $res = UserPointPlan::where('uid', $request->uid())
  49. // ->where('status', 'in', [0, 1])
  50. // ->where('check_end_time', '>', time())
  51. ->select()->each(function ($item) {
  52. $item['plan'] = PointPlan::get($item['plan_id']);
  53. })->toArray();
  54. return app('json')->success('ok', ['list' => $res,
  55. 'all' => UserBill::where('uid', $request->uid())->where('category', 'LALA')->where('status', 1)->where('type', 'release')->value('SUM(number)'),
  56. 'yesterday' => UserBill::where('uid', $request->uid())->where('category', 'LALA')->where('status', 1)->where('type', 'release')->whereTime('add_time', 'yesterday')->value('SUM(number)'),
  57. 'yesterday_award' => UserBill::where('uid', $request->uid())->where('category', 'LALA')->where('status', 1)->where('type', 'lala_point_award')->whereTime('add_time', 'yesterday')->value('SUM(number)'),
  58. 'all_award' => UserBill::where('uid', $request->uid())->where('category', 'LALA')->where('status', 1)->where('type', 'lala_point_award')->value('SUM(number)'),
  59. 'yesterday_service' => UserBill::where('uid', $request->uid())->where('status', 1)->where('type', 'service_point_award')->group('category')->whereTime('add_time', 'yesterday')->field('SUM(number) as sum,category')->select(),
  60. 'all_service' => UserBill::where('uid', $request->uid())->where('status', 1)->where('type', 'service_point_award')->group('category')->field('SUM(number) as sum,category')->select(),
  61. ]);
  62. }
  63. }