123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- /**
- * HomeController.php
- * 文件描述
- * Created on 2020/8/10 14:37
- * Create by Wpeishi
- */
- namespace App\Http\Controllers\Api\V1;
- use App\Exceptions\ApiException;
- use App\Helpers\DateHelper;
- use App\Http\Controllers\Controller;
- use App\Models\AppointmentConfig;
- use App\Models\Data;
- use App\Models\User;
- use App\Models\UserTicket;
- use App\Models\Website;
- use App\Notifications\InvoicePaid;
- use App\Services\DataService;
- use App\Services\User\UserService;
- use common\Helper\Helper;
- use Illuminate\Support\Facades\App;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- /**
- * 测试专用控制器
- * Created on 2020/8/27 15:01
- * Create by Wpeishi
- */
- class HomeController extends Controller
- {
- public function add()
- {
- //return date('YmdHis', time()) . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
- // app()->environment('local');
- // dd([12,213,213,123]);
- // throw new ApiException('cuola');
- // $user = User::first();
- // $user->notify(new InvoicePaid());
- // return apiJson(123);
- // Log::channel('info')->info('任务执行了!'.date('Y-m-d H:i:s'));
- // log::info('asdassdasd');
- }
- public function sms()
- {
- $user = User::first();
- $user->notify(new InvoicePaid());
- }
- public static function adds($start_time, $end_time, $time_type = 1)
- {
- Log::channel('info')->info('asdassdassdasdsd');
- $count = DB::table('vr_users')
- ->where('website_id', '>', 0)
- ->whereBetween('become_member_time', [$start_time, $end_time])
- ->selectRaw('website_id,count(*) as num')
- ->groupBy(['website_id'])->get()->toArray();
- Log::channel('info')->info(['type' => 1, 'time_type' => $time_type, 'count_num' => $count]);
- return ['type' => 1, 'time_type' => $time_type, 'count_num' => $count];
- }
- public function testdata()
- {
- //2020-08-31 09:00:00
- $data = date('Y-m-d').' '.AppointmentConfig::query()->first()['start_time'];
- return strtotime($data);
- return config('easysms.gateways');
- return config('api.Kilometer') * config('api.carbon_coefficient');
- return
- UserTicket::insert([[
- 'user_id' => 1,
- 'ticket_id' => 1,
- 'type' => 0,
- 'grant_time' => date('Y-m-d H:i:s',time()),
- 'status' => 0,
- ],[
- 'user_id' => 1,
- 'ticket_id' => 1,
- 'type' => 0,
- 'grant_time' => date('Y-m-d H:i:s',time()),
- 'status' => 0,
- ]]);
- return 123;
- // 统计昨天的用户增长数量
- $start_time = date("Y-m-d", DateHelper::yesterday());
- $end_time = date("Y-m-d", DateHelper::today());
- // Log::channel('info')->info('asdassdassdasdsd');
- // Log::channel('info')->info([1, 2, 23, 3, 4, 4, 5, 5]);
- return self::adds($start_time, $end_time);
- // return [$start_time, $end_time];
- return DB::table('vr_users')
- ->where('website_id', '>', 0)
- ->whereBetween('become_member_time', [$start_time, $end_time])
- ->selectRaw('website_id,count(*) as num')
- ->groupBy(['website_id'])->get()->toArray();
- // 统计上周的数据 3 3 3 5 5
- $start_time = date("Y-m-d H:i:s", DateHelper::LastWeek()['first_day']);
- $end_time = date("Y-m-d H:i:s", DateHelper::LastWeek()['last_day']);
- return DB::table('vr_users')
- ->where('website_id', '>', 0)
- ->whereBetween('become_member_time', [$start_time, $end_time])
- // ->get();
- ->selectRaw('website_id,count(*) as num')
- ->groupBy(['website_id'])->get()->toArray();
- //
- $start_time = date("Y-m-d", strtotime("-" . 7 . " day"));
- $end_time = date("Y-m-d", strtotime("+" . 1 . " day"));
- $website_data = Website::query()->get(['id']);
- $data = [];
- // foreach ($website_data as $k => $v) {
- // $data[$v->id] = Data::query()->where(['website_id' => $v->id])->whereBetween('created_at', [$start_time, $end_time])
- // ->selectRaw('DATE_FORMAT(created_at,%Y%u) as date,SUM(count_num) as num')
- // ->groupBy(['date'])->get()->toArray();
- // }
- // return array_column($data[2],'num');
- $data = [];
- foreach ($website_data as $k => $v) {
- $data[$v->id] = Data::query()->select('id', 'time_type', 'count_num', 'created_at')
- ->where(['website_id' => $v->id, 'time_type' => 1])->orderByDesc('id')->limit(7)->get()->toArray();
- }
- $return_data = array_column($data[1], 'count_num');
- array_push($return_data, 8);
- return $return_data;
- }
- }
|