Nav apraksta

AdzoneCreate.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php namespace App\Console\Commands;
  2. use Illuminate\Console\Command;
  3. use Symfony\Component\Console\Input\InputOption;
  4. use Symfony\Component\Console\Input\InputArgument;
  5. use TopClient;
  6. use DB;
  7. use Redis;
  8. use TbkAdzoneCreateRequest;
  9. class AdzoneCreate extends Command {
  10. protected $signature = 'AdzoneCreate';
  11. /**
  12. * The console command description.
  13. *
  14. * @var string
  15. */
  16. protected $description = '店家收集';
  17. public function handle()
  18. {
  19. $this->AdzoneCreate();
  20. }
  21. public function AdzoneCreateApi($name){
  22. $c = new TopClient;
  23. $c->appkey = "23260528";
  24. $c->secretKey = "842fc308fb5f95b1250581f664cdcde8";
  25. $req = new TbkAdzoneCreateRequest;
  26. $req->setSiteId("11458219");
  27. $req->setAdzoneName($name);
  28. $resp = $c->execute($req);
  29. $resp=(array)$resp;
  30. if(array_key_exists("data",$resp)){
  31. $pmodel=(array)$resp['data'];
  32. if(array_key_exists("model",$pmodel)){
  33. $adzoneArr=explode("_",$pmodel['model']);
  34. $data['name']=$name;
  35. $data['adzone_id']=$adzoneArr[count($adzoneArr)-1];
  36. $data['create_at']=date("Y-m-d",time());
  37. $data['update_at']=date("Y-m-d",time());
  38. DB::table("adzone")->insert($data);
  39. return $adzoneArr[count($adzoneArr)-1];
  40. }else{
  41. return "";
  42. }
  43. }else{
  44. return "";
  45. }
  46. }
  47. //
  48. public function AdzoneCreate(){
  49. set_time_limit(0);
  50. ini_set('memory_limit','1024M');
  51. $AdzoneListName="tbk:adzoneList";
  52. $lastAdzone=DB::table("adzone")->orderBy("id","desc")->first();
  53. if(count($lastAdzone)>0){
  54. $adzoneName=$lastAdzone->name;
  55. preg_match("/\d+/",$adzoneName,$adzoneNameArr);
  56. $api_last=$adzoneNameArr[0];
  57. $api_last=intval($api_last)+1;
  58. }else{
  59. $api_last=1;
  60. }
  61. for($i=0;$i<500;$i++){
  62. $api_all="api_".$api_last;
  63. $adzoneId=$this->AdzoneCreateApi($api_all);
  64. $redis=new Redis();
  65. $redis->connect(config('constants.REDIS_IP'),config('constants.REDIS_PORT'));
  66. $redis->auth(config('constants.REDIS_PASSWORD'));
  67. $redis->rpush($AdzoneListName,$adzoneId);
  68. $api_last+=1;
  69. if($api_last%20==0){
  70. sleep(5);
  71. }
  72. }
  73. }
  74. }