9 changed files with 252 additions and 2 deletions
-
88app/Commons/Log.php
-
8app/Controller/AbstractController.php
-
20app/Controller/StoreController.php
-
60app/Controller/TestController.php
-
28app/Model/Store.php
-
42app/Request/StoreApplyEntryRequest.php
-
2composer.json
-
5config/autoload/dependencies.php
-
1config/routes.php
@ -0,0 +1,88 @@ |
|||
<?php |
|||
|
|||
namespace App\Commons; |
|||
use Hyperf\Guzzle\ClientFactory; |
|||
|
|||
class Log |
|||
{ |
|||
/** |
|||
* @var \Hyperf\Guzzle\ClientFactory |
|||
*/ |
|||
private $clientFactory; |
|||
|
|||
public function __construct(ClientFactory $clientFactory) |
|||
{ |
|||
$this->clientFactory = $clientFactory; |
|||
} |
|||
|
|||
public function getClient() |
|||
{ |
|||
// $options 等同于 GuzzleHttp\Client 构造函数的 $config 参数
|
|||
$options = [ |
|||
'timeout' => 2.0, |
|||
]; |
|||
// $client 为协程化的 GuzzleHttp\Client 对象
|
|||
$client = $this->clientFactory->create($options); |
|||
|
|||
return $client; |
|||
} |
|||
|
|||
public function event($labels=null,$datas){ |
|||
|
|||
co(function () use ($labels,$datas){ |
|||
|
|||
$client = $this->getClient(); |
|||
$kv = []; |
|||
foreach ($datas as $key => $value) { |
|||
$kv[] = $key."=".$value; |
|||
} |
|||
$pushLabels = []; |
|||
|
|||
$event_name = 'event_'.env('APP_ENV'); |
|||
if(!empty($labels)) $pushLabels[$event_name] = $labels; |
|||
|
|||
/* |
|||
* data format: |
|||
curl -v -H "Content-Type: application/json" -XPOST -s "http://39.96.12.39:3100/loki/api/v1/push" --data-raw \ |
|||
'{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1596274538882028800", "fizzbuzz" ] ] }]}' |
|||
*/ |
|||
$ts = $this->getMsecTime() . '000000'; |
|||
$datas = implode("&",$kv); |
|||
$values = [[$ts,$datas]]; |
|||
$app_name = env('APP_NAME').'_'.env('APP_ENV'); |
|||
|
|||
$pushLabels['app']= $app_name; |
|||
$pushDatas = [ |
|||
'streams'=>[ |
|||
[ |
|||
'stream'=>$pushLabels, |
|||
'values'=>$values, |
|||
] |
|||
] |
|||
]; |
|||
$client->post( |
|||
'http://39.96.12.39:3100/loki/api/v1/push', |
|||
[ |
|||
'headers'=>[ |
|||
'Content-Type'=>'application/json' |
|||
], |
|||
'body' => json_encode($pushDatas) |
|||
] |
|||
); |
|||
//var_dump(json_encode($pushDatas) );
|
|||
}); |
|||
} |
|||
|
|||
|
|||
public function push($datas){ |
|||
$this->event(null,$datas); |
|||
} |
|||
|
|||
public function getMsecTime() |
|||
{ |
|||
list($msec, $sec) = explode(' ', microtime()); |
|||
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); |
|||
return $msectime; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Controller; |
|||
|
|||
use App\Request\StoreApplyEntryRequest; |
|||
|
|||
class StoreController extends BaseController |
|||
{ |
|||
|
|||
/** |
|||
* 申请入驻 |
|||
*/ |
|||
public function applyEntry(StoreApplyEntryRequest $request) |
|||
{ |
|||
|
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
namespace App\Controller; |
|||
|
|||
|
|||
use Hyperf\HttpServer\Contract\RequestInterface; |
|||
use Hyperf\HttpServer\Annotation\AutoController; |
|||
use Hyperf\Utils\Coroutine; |
|||
use Hyperf\Utils\ApplicationContext; |
|||
use Hyperf\Task\TaskExecutor; |
|||
use Hyperf\Task\Task; |
|||
use App\TaskWorker\SSDBTask; |
|||
use App\Commons\Log; |
|||
|
|||
/** |
|||
* @AutoController() |
|||
* Class TestController |
|||
* @package App\Controller |
|||
*/ |
|||
class TestController extends AbstractController |
|||
{ |
|||
private $name = 'default action'; |
|||
|
|||
|
|||
public function index1(RequestInterface $request) |
|||
{ |
|||
// $container = ApplicationContext::getContainer();
|
|||
// $exec = $container->get(TaskExecutor::class);
|
|||
// $result = $exec->execute(new Task([MethodTask::class, 'handle'], [Coroutine::id()]));
|
|||
|
|||
// $client = ApplicationContext::getContainer()->get(SSDBTask::class);
|
|||
// $result = $client->exec("set","bar","1234");
|
|||
// $result = $client->exec("get","bar");
|
|||
|
|||
// $client = ApplicationContext::getContainer()->get(MethodTask::class);
|
|||
// $result = $client->handle("set");
|
|||
|
|||
|
|||
//$log = ApplicationContext::getContainer()->get(Log::class);
|
|||
$log = $this->log; |
|||
|
|||
$log->push(['test'=>1,'user_id'=>290,'msg'=>'order']); |
|||
$log->event('t1',['test'=>1,'user_id'=>290,'msg'=>'order']); |
|||
|
|||
//$this->name = 'index1 action '. $result;
|
|||
return $this->name; |
|||
} |
|||
|
|||
public function index2(RequestInterface $request) |
|||
{ |
|||
$this->name = 'index2 action'; |
|||
return $this->name; |
|||
} |
|||
|
|||
public function index3(RequestInterface $request) |
|||
{ |
|||
return $this->name; |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
<?php |
|||
|
|||
declare (strict_types=1); |
|||
namespace App\Model; |
|||
|
|||
/** |
|||
*/ |
|||
class Store extends Model |
|||
{ |
|||
/** |
|||
* The table associated with the model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $table = 'ims_cjdc_store'; |
|||
/** |
|||
* The attributes that are mass assignable. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $fillable = []; |
|||
/** |
|||
* The attributes that should be cast to native types. |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $casts = []; |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App\Request; |
|||
|
|||
use Hyperf\Validation\Request\FormRequest; |
|||
|
|||
class StoreApplyEntryRequest extends FormRequest |
|||
{ |
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
*/ |
|||
public function authorize(): bool |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
*/ |
|||
public function rules(): array |
|||
{ |
|||
return [ |
|||
'name' => 'required|nonempty', |
|||
'market_id' => 'required|nonempty', |
|||
'md_type' => 'required|nonempty', |
|||
'address' => 'required|nonempty', |
|||
'coordinates' => 'required|nonempty', |
|||
'details' => 'required|nonempty', |
|||
'link_name' => 'required|nonempty', |
|||
'link_tel' => 'required|nonempty', |
|||
'tel' => 'required|nonempty', |
|||
'logo' => 'required|nonempty', |
|||
'fm_img' => 'required|nonempty', |
|||
'zm_img' => 'required|nonempty', |
|||
'yyzz' => 'required|nonempty', |
|||
'user_id' => 'required|nonempty', |
|||
'mm_user_id' => 'required|nonempty', |
|||
]; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue