UpdateUserActualSubscribeNum.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tandunzhao
  5. * Date: 2017/11/20
  6. * Time: 下午5:26
  7. */
  8. namespace App\Console\Commands;
  9. use App\Modules\User\Services\UserSubscribeBehaviorStatsService;
  10. use DB;
  11. use GuzzleHttp\Client;
  12. use Illuminate\Console\Command;
  13. use Log;
  14. use Redis;
  15. class UpdateUserActualSubscribeNum extends Command
  16. {
  17. /**
  18. * 执行命令 php artisan force_user_active
  19. *
  20. * The name and signature of the console command.
  21. *
  22. * @var string
  23. */
  24. protected $signature = 'updateUserSubNum';
  25. /**
  26. * The console command description.
  27. *
  28. * @var string
  29. */
  30. protected $description = '更新强关号实际新增粉丝';
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. $lists = UserSubscribeBehaviorStatsService::getList(date('Y-m-d',strtotime('-1 day')));
  39. foreach ($lists as $list){
  40. $new_user_num_raw = self::getOfficialAccountFansNum($list->appid,$list->date,$list->date);
  41. $new_user_num = 0;
  42. $cancel_user_num = 0;
  43. if(isset($new_user_num_raw['user_summary']['list']) && count($new_user_num_raw['user_summary']['list'])>0){
  44. $new_user_num = $new_user_num_raw['user_summary']['list'][0]['new_user'];
  45. $cancel_user_num = $new_user_num_raw['user_summary']['list'][0]['cancel_user'];
  46. }
  47. $list->yesterday_actual_new_user = $new_user_num;
  48. $list->yesterday_actual_sub_num = $new_user_num-$cancel_user_num;
  49. //\Log::info(json_encode($new_user_num_raw));
  50. //\Log::info($new_user_num);
  51. $list->save();
  52. }
  53. }
  54. private static function getOfficialAccountFansNum($appid,$start_date,$end_date){
  55. $client = New Client(['base_uri' => env('MEDIA_API_BASE_URI')]);
  56. $response = $client->request('GET','get_gzh_statistics',['query'=>['gzh_app_id'=>$appid,'from_date'=>$start_date,'to_date'=>$end_date]]);
  57. $res = json_decode($response->getBody(),true);
  58. //if(isset($res['']))
  59. return $res['data'];
  60. }
  61. }