123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/23
- * Time: 下午12:35
- */
- namespace backend\controllers;
- use Yii;
- use yii\log\FileTarget;
- use backend\base\Help;
- class TinifyimgController extends \yii\web\Controller
- {
- public $enableCsrfValidation = false;
- /*
- * 用于异步压缩图片
- * */
- public function actionImgcompress()
- {
- $input = Yii::$app->request->post();
- $model = new \backend\server\TinyPng();
- Yii::info(json_encode($input));
- $model->CompressImg($input);
- }
- /*
- * 报名数据接口
- */
- public function actionSignup()
- {
- $input = Yii::$app->request->post();
- $model = new \common\models\Enroll();
- $row = $model->getList($input);
- if($row['data'])
- {
- $equipmentArr = [1=>'m', 2=>'pc'];
- $ip = array_column($row['data'],'ip');
- $m = new \common\models\HttpRecord();
- $IpRecord = $m->GetList(['ip'=>$ip,'create_at'=>$input['add_time']]);
- $ipArr = [];
- if($IpRecord)
- {
- foreach ($IpRecord as &$val)
- {
- $val['add_time'] = date('Y-m-d H:i',$val['create_at']);
- $ipArr[$val['ip']][] = $val;
- }
- }
- $mobile = (new \common\models\EnrollSource())->TypeColumn(1);
- $pc = (new \common\models\EnrollSource())->TypeColumn(2);
- foreach ($row['data'] as &$v)
- {
- if (isset($pc[$v['source']]) && $v['equipment'] == 2) {
- $v['source'] = $pc[$v['source']];
- }
- if (isset($mobile[$v['source']]) && $v['equipment'] == 1)
- {
- $v['source'] = $mobile[$v['source']];
- }
- $v['equipment'] = $equipmentArr[$v['equipment']];
- if(isset($ipArr[$v['ip']]))
- {
- $v['ip_record'][] = $ipArr[$v['ip']][0];
- foreach ($ipArr[$v['ip']] as $item)
- {
- if($v['create_at'] == $item['create_at'])
- {
- $v['ip_record'][] = $item;
- }
- }
- }
- if(empty($v['city_name']))
- {
- $referer = urldecode($v['ip_record'][1]['referer']);
- $refererQuery = parse_url($referer);
- if(isset($refererQuery['query']))
- {
- $UrlParams = self::ConvertUrlQuery($refererQuery['query']);
- }
- if(isset($UrlParams['city']) || isset($UrlParams['py']))
- {
- $v['city_name'] = \common\models\CategoryCity::find()->andWhere(['del'=>1])->andWhere(['id'=>$UrlParams['city']])->one()['city_name'];
- }else{
- $UrlPath = explode('/',$refererQuery['path']);
- //相册
- if(strpos($refererQuery['path'],'house') !== false && strpos($refererQuery['path'],'album') !== false){
- foreach ($UrlPath as $album)
- {
- if(is_numeric($album))
- {
- $hid = \common\models\House::find()->andWhere(['id'=>$album])->one();
- }
- }
- }
- //户型
- if(strpos($refererQuery['path'],'house') !== false && strpos($refererQuery['path'],'type') !== false){
- foreach ($UrlPath as $type)
- {
- if(is_numeric($type))
- {
- $hid = \common\models\House::find()->andWhere(['id'=>$type])->one();
- }
- }
- }
- //楼盘首页
- if(strpos($refererQuery['path'],'house') !== false && strpos($refererQuery['path'],'-') !== false){
- foreach ($UrlPath as $house)
- {
- if(strpos($house,'-') !== false )
- {
- $hid = \common\models\House::find()->andWhere(['id'=>explode('-',$house)[1]])->one();
- }
- }
- }
- if(isset($hid) && !empty($hid))
- {
- $v['city_name'] = \common\models\CategoryCity::findOne($hid['city'])['city_name'];
- }
- }
- }
- }
- return Help::JsonCode(Help::SUCCESS,'成功',$row['data']);
- }
- return Help::JsonCode(Help::ERROR,'暂无数据');
- }
- public static function ConvertUrlQuery($query)
- {
- $queryParts = explode('&', $query);
- $params = array();
- foreach ($queryParts as $param) {
- $item = explode('=', $param);
- $params[$item[0]] = $item[1];
- }
- return $params;
- }
- /*
- * 用于发送邮件
- * */
- public function actionSendemail()
- {
- $input = Yii::$app->request->post();
- $email = new \common\api\EmailServer();
- // Yii::info(json_encode($input));
- $model = new \common\models\Enroll();
- $row = $model->FindById($input['id']);
- $arr = [];
- $arr['tel'] = $row['mobile'];
- $arr['sid'] = 2;
- if(!empty($row['hid']))
- {
- $house = new \common\models\House();
- $HouseName = $house->FindById($row['hid']);
- if(!empty($HouseName))
- {
- $arr['ascription'] = $HouseName['name'];
- $city = new \common\models\CategoryCity();
- $cityName = $city->FindById($HouseName['city']);
- if(!empty($cityName))
- {
- $arr['city'] = $cityName['city_name'];
- }
- }
- }
- $curl = new \linslin\yii2\curl\Curl();
- $response = $curl->reset()
- ->setOption(
- CURLOPT_POSTFIELDS,
- $arr
- )
- ->post('http://jixiaoadmin.pinfangw.com/.php?m=Home&c=Stats&a=SignUp');
- $result = $email->SendOut($input['email'],$input['title'],$input['content']);
- if($result === true)
- {
- if(!empty($input['id']))
- {
- $row->state = 2;
- $row->save(false);
- }
- }
- // $input = Yii::$app->request->post();
- // $email = new \common\api\EmailServer();
- // $result = $email->SendOut($input['email'],$input['title'],$input['content']);
- // if($result == true)
- // {
- // if(!empty($input['id']))
- // {
- // $model = new \common\models\Enroll();
- // $row = $model->FindById($input['id']);
- // $row->state = 2;
- // $row->save(false);
- // }
- // }
- }
- }
|