123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2017/7/24
- * Time: 11:32
- */
- namespace console\controllers;
- use common\library\ZM_Geohash;
- use common\models\Building;
- use common\models\User;
- use yii\console\Controller;
- use yii\web\HttpException;
- class GenerationController extends Controller{
- public function actionSetCompany(){
- }
- /**
- * 生成工地信息
- * @return bool
- */
- public function actionSetNearby(){
- $datas = UserInfo::find()->where('username like "2000%"');
- $initLat = 24.49;
- $initLong = 118.18;
- $genhash = new ZM_Geohash();
- $time = time();
- foreach($datas->batch(100) as $userdatas){
- foreach($userdatas as $data){
- if(mt_rand(0,10)>8){ //不是所有都添加
- $model = $data->nearby;
- if(empty($model)){
- $model = new NearbyUser();
- $model->userid = $data->id;
- $model->create_at = $time;
- }
- $model->latitude = bcadd($initLat,bcdiv(mt_rand(-200,200),1999,6),6);
- $model->longitude = bcadd($initLong,bcdiv(mt_rand(-200,200),1999,6),6);
- $model->code = $genhash->encode($model->latitude,$model->longitude);
- $model->update_at = $time-mt_rand(1,3600);
- if(!$model->save()){
- echo 'not finished!';
- return false;
- }
- }
- }
- unset($data);
- }
- echo 'finished end.';
- }
- public function actionUser(){
- $this->generationUser(11);
- }
- public function actionBuilding(){
- $this->generationBuilding('0592',20);
- }
- public function generationUser($count){
- for($i=0;$i<$count;$i++){
- $model= new User();
- $model->username = 'test'.$i;
- $model->email =$model->username.'@qq.com';
- $model->setPassword('test'.$i);
- $model->generateAuthKey();
- $model->created_at = time();
- $model->updated_at = time();
- if($model->validate() && $model->save()){
- }else{
- return new HttpException(402,'Initialize account failed ');
- }
- }
- }
- public function generationBuilding($city,$count =10){
- $initLat = 24.49;
- $initLong = 118.18;
- $time = time();
- $genhash = new ZM_Geohash();
- for($i = 1;$i<$count;$i++){
- $building = new Building();
- $building->uid = rand(1,10);
- $building->status = 1;
- $building->created_at = $time;
- $building->updated_at = time();
- $building->latitude = bcadd($initLat,bcdiv(mt_rand(-200,200),1999,6),6);
- $building->longitude = bcadd($initLong,bcdiv(mt_rand(-200,200),1999,6),6);
- $building->hashcode = $genhash->encode($building->latitude,$building->longitude);
- $building->type = $this->randValue(array('1','2'));
- $building->opening_begin = $time;
- $building->opening_end = $time+(24*3600)*30;
- $building->contact = '电话:114';
- $building->stage = $this->randValue(array('竣工','拆改','水电','防水','泥瓦','木工','油漆'));
- $building->pattern = $this->randValue(array('半包','全包','拎包入住'));
- $building->budget = 10.2;
- $building->style = $this->randValue(array('欧式','中国风','现代简约','地中海','新古典','田园','日式'));
- $building->city =$city;
- $building->district =$city;
- $building->address = '地址';
- $building->layout = $this->randValue(array('二室一厅','一室一厅','三室一厅'));
- $building->acreage = $this->randValue(array('120','180','220'));
- if($building->validate() && $building->save()){
- echo $building->id;
- }else{
- var_dump( $building->getErrors());
- return false;
- }
- }
- }
- private function randValue($array){
- $rand_key = array_rand($array,1);
- return $array[$rand_key];
- }
- }
|