HomeController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * HomeController.php
  4. * 文件描述
  5. * Created on 2020/8/10 14:37
  6. * Create by Wpeishi
  7. */
  8. namespace App\Http\Controllers\Api\V1;
  9. use App\Exceptions\ApiException;
  10. use App\Helpers\DateHelper;
  11. use App\Http\Controllers\Controller;
  12. use App\Models\AppointmentConfig;
  13. use App\Models\Data;
  14. use App\Models\User;
  15. use App\Models\UserTicket;
  16. use App\Models\Website;
  17. use App\Notifications\InvoicePaid;
  18. use App\Services\DataService;
  19. use App\Services\User\UserService;
  20. use common\Helper\Helper;
  21. use Illuminate\Support\Facades\App;
  22. use Illuminate\Support\Facades\DB;
  23. use Illuminate\Support\Facades\Log;
  24. /**
  25. * 测试专用控制器
  26. * Created on 2020/8/27 15:01
  27. * Create by Wpeishi
  28. */
  29. class HomeController extends Controller
  30. {
  31. public function add()
  32. {
  33. //return date('YmdHis', time()) . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  34. // app()->environment('local');
  35. // dd([12,213,213,123]);
  36. // throw new ApiException('cuola');
  37. // $user = User::first();
  38. // $user->notify(new InvoicePaid());
  39. // return apiJson(123);
  40. // Log::channel('info')->info('任务执行了!'.date('Y-m-d H:i:s'));
  41. // log::info('asdassdasd');
  42. }
  43. public function sms()
  44. {
  45. $user = User::first();
  46. $user->notify(new InvoicePaid());
  47. }
  48. public static function adds($start_time, $end_time, $time_type = 1)
  49. {
  50. Log::channel('info')->info('asdassdassdasdsd');
  51. $count = DB::table('vr_users')
  52. ->where('website_id', '>', 0)
  53. ->whereBetween('become_member_time', [$start_time, $end_time])
  54. ->selectRaw('website_id,count(*) as num')
  55. ->groupBy(['website_id'])->get()->toArray();
  56. Log::channel('info')->info(['type' => 1, 'time_type' => $time_type, 'count_num' => $count]);
  57. return ['type' => 1, 'time_type' => $time_type, 'count_num' => $count];
  58. }
  59. public function testdata()
  60. {
  61. //2020-08-31 09:00:00
  62. $data = date('Y-m-d').' '.AppointmentConfig::query()->first()['start_time'];
  63. return strtotime($data);
  64. return config('easysms.gateways');
  65. return config('api.Kilometer') * config('api.carbon_coefficient');
  66. return
  67. UserTicket::insert([[
  68. 'user_id' => 1,
  69. 'ticket_id' => 1,
  70. 'type' => 0,
  71. 'grant_time' => date('Y-m-d H:i:s',time()),
  72. 'status' => 0,
  73. ],[
  74. 'user_id' => 1,
  75. 'ticket_id' => 1,
  76. 'type' => 0,
  77. 'grant_time' => date('Y-m-d H:i:s',time()),
  78. 'status' => 0,
  79. ]]);
  80. return 123;
  81. // 统计昨天的用户增长数量
  82. $start_time = date("Y-m-d", DateHelper::yesterday());
  83. $end_time = date("Y-m-d", DateHelper::today());
  84. // Log::channel('info')->info('asdassdassdasdsd');
  85. // Log::channel('info')->info([1, 2, 23, 3, 4, 4, 5, 5]);
  86. return self::adds($start_time, $end_time);
  87. // return [$start_time, $end_time];
  88. return DB::table('vr_users')
  89. ->where('website_id', '>', 0)
  90. ->whereBetween('become_member_time', [$start_time, $end_time])
  91. ->selectRaw('website_id,count(*) as num')
  92. ->groupBy(['website_id'])->get()->toArray();
  93. // 统计上周的数据 3 3 3 5 5
  94. $start_time = date("Y-m-d H:i:s", DateHelper::LastWeek()['first_day']);
  95. $end_time = date("Y-m-d H:i:s", DateHelper::LastWeek()['last_day']);
  96. return DB::table('vr_users')
  97. ->where('website_id', '>', 0)
  98. ->whereBetween('become_member_time', [$start_time, $end_time])
  99. // ->get();
  100. ->selectRaw('website_id,count(*) as num')
  101. ->groupBy(['website_id'])->get()->toArray();
  102. //
  103. $start_time = date("Y-m-d", strtotime("-" . 7 . " day"));
  104. $end_time = date("Y-m-d", strtotime("+" . 1 . " day"));
  105. $website_data = Website::query()->get(['id']);
  106. $data = [];
  107. // foreach ($website_data as $k => $v) {
  108. // $data[$v->id] = Data::query()->where(['website_id' => $v->id])->whereBetween('created_at', [$start_time, $end_time])
  109. // ->selectRaw('DATE_FORMAT(created_at,%Y%u) as date,SUM(count_num) as num')
  110. // ->groupBy(['date'])->get()->toArray();
  111. // }
  112. // return array_column($data[2],'num');
  113. $data = [];
  114. foreach ($website_data as $k => $v) {
  115. $data[$v->id] = Data::query()->select('id', 'time_type', 'count_num', 'created_at')
  116. ->where(['website_id' => $v->id, 'time_type' => 1])->orderByDesc('id')->limit(7)->get()->toArray();
  117. }
  118. $return_data = array_column($data[1], 'count_num');
  119. array_push($return_data, 8);
  120. return $return_data;
  121. }
  122. }