示例#1
0
 /**
  * 发布动态
  */
 public function actionTrends()
 {
     if (!isset($_POST['uid']) || !$_POST['uid']) {
         $this->_exit($this->_error['20007'], '20007');
     }
     if (!(isset($_POST['content']) && isset($_POST['image'])) || !($_POST['image'] || $_POST['content'])) {
         $this->_exit($this->_error['20056'], '20056');
     }
     if (!isset($_POST['area']) || !$_POST['area']) {
         $this->_exit($this->_error['20042'], '20042');
     }
     $uid = trim($_POST['uid']);
     $content = trim($_POST['content']);
     $area = trim($_POST['area']);
     $imgdata = $_POST['image'] ? trim($_POST['image']) : file_get_contents('php://input');
     if ($imgdata) {
         $ms = date('Ym', time());
         $path = Yii::app()->basePath . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'trends' . DIRECTORY_SEPARATOR . $ms . DIRECTORY_SEPARATOR;
         $imgName = MD5(time() . $this->getPostCode()) . '.jpg';
         if (!is_dir($path)) {
             mkdir($path, 0755, true);
         }
         $newFilePath = $path . $imgName;
         $newFile = fopen($newFilePath, 'w');
         fwrite($newFile, $imgdata);
         fclose($newFile);
         $fileName = $ms . DIRECTORY_SEPARATOR . $imgName;
         include Yii::app()->basePath . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'ResizeImage.php';
         $m = new ResizeImage();
         $m->ResizeImg($newFilePath, '230', '230', '0', $path . '230x230-' . $imgName);
         $m->ResizeImg($newFilePath, '120', '120', '0', $path . '120x120-' . $imgName);
     } else {
         $fileName = '';
     }
     $img = trim($fileName);
     $res = Trends::model()->addTrends($uid, $area, $content, $img);
     if ($res) {
         $this->_exit($this->_error['20000'], '20000', array('img' => self::HOST_HTTP_TRENDS . str_replace('\\', '/', $img), 'tid' => $res), 'trends');
     }
     $this->_exit($this->_error['21000'], '21000');
 }
示例#2
0
 /**
  *  完善用户信息
  */
 public function actionGetInfo()
 {
     if (!isset($_POST['uid']) || !$_POST['uid']) {
         $this->_exit($this->_error['20007'], '20007');
     }
     if (!isset($_POST['lng']) || !$_POST['lng']) {
         $this->_exit($this->_error['20008'], '20008');
     }
     if (!isset($_POST['lat']) || !$_POST['lat']) {
         $this->_exit($this->_error['20009'], '20009');
     }
     if (!isset($_POST['mac']) || !$_POST['mac']) {
         $this->_exit($this->_error['20028'], '20028');
     }
     if (!isset($_POST['iostoken'])) {
         $this->_exit($this->_error['20034'], '20034');
     }
     $params = array();
     $data = $_POST['pic'] ? trim($_POST['pic']) : file_get_contents("php://input");
     $params['nickname'] = $_POST['nickname'] ? trim($_POST['nickname']) : '';
     $params['sex'] = $_POST['sex'] ? trim($_POST['sex']) : '0';
     $params['age'] = $_POST['age'] ? trim($_POST['age']) : '';
     $params['uid'] = trim($_POST['uid']);
     $params['lng'] = trim($_POST['lng']);
     $params['lat'] = trim($_POST['lat']);
     if ($data) {
         $ms = date('Ym', time());
         $path = Yii::app()->basePath . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'head_img' . DIRECTORY_SEPARATOR . $ms . DIRECTORY_SEPARATOR;
         $imgName = MD5(time() . $this->getPostCode()) . '.jpg';
         if (!is_dir($path)) {
             mkdir($path, 0755, true);
         }
         $newFilePath = $path . $imgName;
         $newFile = fopen($newFilePath, 'w');
         fwrite($newFile, $data);
         fclose($newFile);
         $fileName = $ms . DIRECTORY_SEPARATOR . $imgName;
         include Yii::app()->basePath . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'ResizeImage.php';
         $m = new ResizeImage();
         $m->ResizeImg($newFilePath, '120', '120', '0', $path . '120x120-' . $imgName);
         $m->ResizeImg($newFilePath, '80', '80', '0', $path . '80x80-' . $imgName);
     } else {
         $fileName = '';
     }
     $params['pic'] = trim($fileName);
     $mac = trim($_POST['mac']);
     $params['iostoken'] = $_POST['iostoken'] ? str_replace(' ', '', trim($_POST['iostoken'])) : '';
     $params['defaultcoins'] = 200;
     $token = substr(md5($params['uid'] . $mac), 0, 16);
     $time = time() + 7 * 24 * 3600;
     $res = User::model()->updateUser($params);
     if ($res['user'] || $res['coord'] || $res['userinfo'] || $res['usercoins']) {
         $r = User::model()->haveToken($params['uid']);
         if ($r) {
             if ($r['time'] < time()) {
                 User::model()->loginOut($r['uid']);
                 $this->_exit($this->_error['20010'], '20010');
             }
             $this->_exit($this->_error['20000'], '20000', $r['value'], 'token');
         } else {
             $stat = User::model()->insertToken($params['uid'], $token, $time);
             if ($stat) {
                 $this->_exit($this->_error['20000'], '20000', $token, 'token');
             }
         }
     }
     $this->_exit($this->_error['21000'], '21000');
 }