Ejemplo n.º 1
0
 /**
  * 微信处理图片
  */
 public static function fitImage($obj, Users $user)
 {
     #判断图片是否开启
     $pic_save_status = \Yii::$app->cache->get("qys_pic_save_" . $user->user_id);
     $count = Pic::find()->where("user_id=:user_id", array(":user_id" => $user->user_id))->count("*");
     if ($pic_save_status == false) {
         $content = "没有开启保存图片功能,该图片不会被服务器保存.";
     } elseif ($count >= 20) {
         $content = "图片已经超过20张,不再做保存。";
     } else {
         $count = Pic::find()->where("user_id=:user_id", array(":user_id" => $user->user_id))->count("*");
         #获得图片地址
         $pic = file_get_contents($obj->PicUrl);
         $picname = time() . "_" . $user->user_id . ($count + 1) . ".gif";
         $pic_path = Yii::getPathOfAlias('webroot') . '/date/uplaod/';
         $pic_show_path = '/date/uplaod/';
         file_put_contents($pic_path . $picname, $pic);
         if (file_exists($pic_path . $picname)) {
             #小图保存
             $simage = Yii::app()->image->load($pic_path . $picname);
             $simage->resize(80, 80);
             $simage->save($pic_path . "s_" . $picname);
             #中图保存
             $mimage = Yii::app()->image->load($pic_path . $picname);
             $mimage->resize(240, 240);
             $mimage->save($pic_path . "m_" . $picname);
             #大图保存
             $bimage = Yii::app()->image->load($pic_path . $picname);
             $bimage->save($pic_path . "b_" . $picname);
             $userPic = new Pic();
             $picArray = array('user_id' => $user->user_id, 'pic_type' => 0, 'pic_s_img' => $pic_show_path . "s_" . $picname, 'pic_m_img' => $pic_show_path . "m_" . $picname, 'pic_b_img' => $pic_show_path . "n_" . $picname);
             $userPic->setAttributes($picArray);
             if ($userPic->validate() && $userPic->save()) {
                 $content = "图片已经保存。";
             } else {
                 $content = "图片保存失败,请重新发送。";
             }
         } else {
             $content = "保存失败。";
         }
         unlink($pic_path . $picname);
     }
     WechatCheck::_transmitText($obj, $content);
 }
Ejemplo n.º 2
0
 /**
  * 删除图片
  */
 public function actionDeletepropic()
 {
     $user_id = \Yii::$app->user->getId();
     $p_params = Yii::$app->request->get();
     $delPic = Pic::find()->where(" id=:id AND user_id=:user_id ", [":id" => $p_params['id'], ":user_id" => $user_id])->one();
     if (!$delPic) {
         throw new NotFoundHttpException(Yii::t('app', 'Page not found'));
     }
     if ($delPic->delete()) {
         Yii::$app->response->getHeaders()->set('Vary', 'Accept');
         Yii::$app->response->format = Response::FORMAT_JSON;
         @unlink(Yii::$app->getBasePath() . '/web' . $delPic->pic_s_img);
         @unlink(Yii::$app->getBasePath() . '/web' . $delPic->pic_m_img);
         @unlink(Yii::$app->getBasePath() . '/web' . $delPic->pic_b_img);
         $response['files'][] = ['name' => TRUE];
     } else {
         $response[] = ['error' => '删除失败'];
     }
     return $response;
 }
Ejemplo n.º 3
0
 /**
  * 选择商品图片
  * @return type
  */
 public function actionSelectimg()
 {
     $p_param = \Yii::$app->request->get();
     $user_id = \Yii::$app->user->getId();
     if (isset($p_param['id'])) {
         $oneLogistics = Logistics::find()->where("id=:id", [':id' => $p_param['id']])->one();
         if ($oneLogistics) {
             //图片选择处理
             if (isset($_POST['Logistics'])) {
                 if (is_numeric($_POST['Logistics']['logis_s_img'])) {
                     #获得图片
                     $selectpic = Pic::find()->where('user_id=:user_id AND id=:id', [':user_id' => $user_id, ':id' => $_POST['Logistics']['logis_s_img']])->one();
                     if ($selectpic) {
                         $oneLogistics->setAttribute('logis_s_img', $selectpic->pic_s_img);
                         $oneLogistics->setAttribute('logis_m_img', $selectpic->pic_m_img);
                         $oneLogistics->setAttribute('logis_b_img', $selectpic->pic_b_img);
                         if ($oneLogistics->update()) {
                             $error = '更改成功';
                             $notices = array('type' => 2, 'msgtitle' => '操作成功', 'message' => $error, 'backurl' => Url::toRoute('/member/logistics/index'), 'backtitle' => '返回');
                             \Yii::$app->getSession()->setFlash('wechat_fail', array($notices));
                             $this->redirect(Url::toRoute('/public/notices'));
                             \Yii::$app->end();
                         }
                     }
                 }
             }
             $query = Pic::find()->where('user_id=:user_id AND pic_type=2', [':user_id' => $user_id])->orderBy(" id desc ");
             $countQuery = clone $query;
             $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '9']);
             $models = $query->offset($pages->offset)->limit($pages->limit)->all();
             return $this->render('logistics_selectimg', ['model' => $oneLogistics, 'models' => $models, 'pages' => $pages]);
             \Yii::$app->end();
         }
     }
     $error = '不存在此信息';
     $notices = array('type' => 2, 'msgtitle' => '错误的操作', 'message' => $error, 'backurl' => Url::toRoute('/member/logistics/index'), 'backtitle' => '返回');
     \Yii::$app->getSession()->setFlash('wechat_fail', array($notices));
     $this->redirect(Url::toRoute('/public/notices'));
 }
Ejemplo n.º 4
0
 public function actionIndex()
 {
     $user = \Yii::$app->user->getIdentity();
     $post = \Yii::$app->request->post();
     //图片选择处理
     if (isset($post['User'])) {
         if (is_numeric($post['User']['litpic'])) {
             #获得图片
             $selectpic = Pic::find()->where('user_id=:user_id AND id=:id', [':user_id' => $user->user_id, ':id' => $post['User']['litpic']])->one();
             if ($selectpic) {
                 $user->setAttribute('litpic', $selectpic->pic_s_img);
                 if ($user->update()) {
                     $error = '更改成功';
                     $notices = array('type' => 2, 'msgtitle' => '操作成功', 'message' => $error, 'backurl' => Url::toRoute('/member/user/index'), 'backtitle' => '返回');
                     Yii::$app->getSession()->setFlash('wechat_fail', array($notices));
                     $this->redirect(Url::toRoute('/public/notices'));
                     Yii::$app->end();
                 }
             }
         }
     }
     //获得头像类型图片
     $query = Pic::find()->where('user_id=:user_id AND pic_type=1', [':user_id' => $user->user_id])->orderBy(" id desc ");
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '9']);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('user_index', ['model' => $user, 'models' => $models, 'pages' => $pages]);
     \Yii::$app->end();
 }