TinifyimgController.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/23
  6. * Time: 下午12:35
  7. */
  8. namespace backend\controllers;
  9. use Yii;
  10. use yii\log\FileTarget;
  11. use backend\base\Help;
  12. class TinifyimgController extends \yii\web\Controller
  13. {
  14. public $enableCsrfValidation = false;
  15. /*
  16. * 用于异步压缩图片
  17. * */
  18. public function actionImgcompress()
  19. {
  20. $input = Yii::$app->request->post();
  21. $model = new \backend\server\TinyPng();
  22. Yii::info(json_encode($input));
  23. $model->CompressImg($input);
  24. }
  25. /*
  26. * 报名数据接口
  27. */
  28. public function actionSignup()
  29. {
  30. $input = Yii::$app->request->post();
  31. $model = new \common\models\Enroll();
  32. $row = $model->getList($input);
  33. if($row['data'])
  34. {
  35. $equipmentArr = [1=>'m', 2=>'pc'];
  36. $ip = array_column($row['data'],'ip');
  37. $m = new \common\models\HttpRecord();
  38. $IpRecord = $m->GetList(['ip'=>$ip,'create_at'=>$input['add_time']]);
  39. $ipArr = [];
  40. if($IpRecord)
  41. {
  42. foreach ($IpRecord as &$val)
  43. {
  44. $val['add_time'] = date('Y-m-d H:i',$val['create_at']);
  45. $ipArr[$val['ip']][] = $val;
  46. }
  47. }
  48. $mobile = (new \common\models\EnrollSource())->TypeColumn(1);
  49. $pc = (new \common\models\EnrollSource())->TypeColumn(2);
  50. foreach ($row['data'] as &$v)
  51. {
  52. if (isset($pc[$v['source']]) && $v['equipment'] == 2) {
  53. $v['source'] = $pc[$v['source']];
  54. }
  55. if (isset($mobile[$v['source']]) && $v['equipment'] == 1)
  56. {
  57. $v['source'] = $mobile[$v['source']];
  58. }
  59. $v['equipment'] = $equipmentArr[$v['equipment']];
  60. if(isset($ipArr[$v['ip']]))
  61. {
  62. $v['ip_record'][] = $ipArr[$v['ip']][0];
  63. foreach ($ipArr[$v['ip']] as $item)
  64. {
  65. if($v['create_at'] == $item['create_at'])
  66. {
  67. $v['ip_record'][] = $item;
  68. }
  69. }
  70. }
  71. if(empty($v['city_name']))
  72. {
  73. $referer = urldecode($v['ip_record'][1]['referer']);
  74. $refererQuery = parse_url($referer);
  75. if(isset($refererQuery['query']))
  76. {
  77. $UrlParams = self::ConvertUrlQuery($refererQuery['query']);
  78. }
  79. if(isset($UrlParams['city']) || isset($UrlParams['py']))
  80. {
  81. $v['city_name'] = \common\models\CategoryCity::find()->andWhere(['del'=>1])->andWhere(['id'=>$UrlParams['city']])->one()['city_name'];
  82. }else{
  83. $UrlPath = explode('/',$refererQuery['path']);
  84. //相册
  85. if(strpos($refererQuery['path'],'house') !== false && strpos($refererQuery['path'],'album') !== false){
  86. foreach ($UrlPath as $album)
  87. {
  88. if(is_numeric($album))
  89. {
  90. $hid = \common\models\House::find()->andWhere(['id'=>$album])->one();
  91. }
  92. }
  93. }
  94. //户型
  95. if(strpos($refererQuery['path'],'house') !== false && strpos($refererQuery['path'],'type') !== false){
  96. foreach ($UrlPath as $type)
  97. {
  98. if(is_numeric($type))
  99. {
  100. $hid = \common\models\House::find()->andWhere(['id'=>$type])->one();
  101. }
  102. }
  103. }
  104. //楼盘首页
  105. if(strpos($refererQuery['path'],'house') !== false && strpos($refererQuery['path'],'-') !== false){
  106. foreach ($UrlPath as $house)
  107. {
  108. if(strpos($house,'-') !== false )
  109. {
  110. $hid = \common\models\House::find()->andWhere(['id'=>explode('-',$house)[1]])->one();
  111. }
  112. }
  113. }
  114. if(isset($hid) && !empty($hid))
  115. {
  116. $v['city_name'] = \common\models\CategoryCity::findOne($hid['city'])['city_name'];
  117. }
  118. }
  119. }
  120. }
  121. return Help::JsonCode(Help::SUCCESS,'成功',$row['data']);
  122. }
  123. return Help::JsonCode(Help::ERROR,'暂无数据');
  124. }
  125. public static function ConvertUrlQuery($query)
  126. {
  127. $queryParts = explode('&', $query);
  128. $params = array();
  129. foreach ($queryParts as $param) {
  130. $item = explode('=', $param);
  131. $params[$item[0]] = $item[1];
  132. }
  133. return $params;
  134. }
  135. /*
  136. * 用于发送邮件
  137. * */
  138. public function actionSendemail()
  139. {
  140. $input = Yii::$app->request->post();
  141. $email = new \common\api\EmailServer();
  142. // Yii::info(json_encode($input));
  143. $model = new \common\models\Enroll();
  144. $row = $model->FindById($input['id']);
  145. $arr = [];
  146. $arr['tel'] = $row['mobile'];
  147. $arr['sid'] = 2;
  148. if(!empty($row['hid']))
  149. {
  150. $house = new \common\models\House();
  151. $HouseName = $house->FindById($row['hid']);
  152. if(!empty($HouseName))
  153. {
  154. $arr['ascription'] = $HouseName['name'];
  155. $city = new \common\models\CategoryCity();
  156. $cityName = $city->FindById($HouseName['city']);
  157. if(!empty($cityName))
  158. {
  159. $arr['city'] = $cityName['city_name'];
  160. }
  161. }
  162. }
  163. $curl = new \linslin\yii2\curl\Curl();
  164. $response = $curl->reset()
  165. ->setOption(
  166. CURLOPT_POSTFIELDS,
  167. $arr
  168. )
  169. ->post('http://jixiaoadmin.pinfangw.com/.php?m=Home&c=Stats&a=SignUp');
  170. $result = $email->SendOut($input['email'],$input['title'],$input['content']);
  171. if($result === true)
  172. {
  173. if(!empty($input['id']))
  174. {
  175. $row->state = 2;
  176. $row->save(false);
  177. }
  178. }
  179. // $input = Yii::$app->request->post();
  180. // $email = new \common\api\EmailServer();
  181. // $result = $email->SendOut($input['email'],$input['title'],$input['content']);
  182. // if($result == true)
  183. // {
  184. // if(!empty($input['id']))
  185. // {
  186. // $model = new \common\models\Enroll();
  187. // $row = $model->FindById($input['id']);
  188. // $row->state = 2;
  189. // $row->save(false);
  190. // }
  191. // }
  192. }
  193. }