/** * * @return string */ public static function getPRepay($object, Users $weixinuser) { $count = Pic::model()->count("user_id=:user_id", array(":user_id" => $weixinuser->user_id)); if ($count < 20) { Yii::app()->cache->set("qys_pic_save_" . $weixinuser->user_id, $count); $content = "亲爱的用户,已经为你开启保存图片服务,当前已经保存了" . $count . "张,还能保存" . (20 - $count) . "张。"; } else { $content = "亲爱的用户,您已经保存了20张图片,将不再给予保存。"; } WechatCheck::_transmitText($object, $content); }
/** * 微信处理图片 */ public static function fitImage($obj, Users $user) { #判断图片是否开启 $pic_save_status = Yii::app()->cache->get("qys_pic_save_" . $user->user_id); $count = Pic::model()->count("user_id=:user_id", array(":user_id" => $user->user_id)); if ($pic_save_status == false) { $content = "没有开启保存图片功能,该图片不会被服务器保存."; } elseif ($count >= 20) { $content = "图片已经超过20张,不再做保存。"; } else { $count = Pic::model()->count("user_id=:user_id", array(":user_id" => $user->user_id)); #获得图片地址 $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); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Pic the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Pic::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * 选择图片 */ public function actionChangePro() { $this->pageTitle = "修改商品"; $user_id = Yii::app()->user->getId(); if (isset($_GET['id'])) { $product = Product::model()->find("product_id=:pid and product_user_id=:uid", array(":pid" => $_GET['id'], ":uid" => $user_id)); if ($product) { if (isset($_POST) && isset($_POST['Product'])) { #更改数据的处理 $picarray = $_POST['Product']; if (isset($_POST['pic_id'])) { $pic_select = Pic::model()->findByPk($_POST['pic_id'], "user_id=:user_id", array(":user_id" => $user_id)); if ($pic_select) { $picarray['product_s_img'] = $pic_select->pic_s_img; $picarray['product_m_img'] = $pic_select->pic_m_img; $picarray['product_b_img'] = $pic_select->pic_b_img; } } $product->setAttributes($picarray); if ($product->validate() && $product->save()) { $this->redirect(Yii::app()->createUrl('/wechat/product/addProduct')); } } $this->render('product_ch', array("product" => $product)); Yii::app()->end(); } } $this->redirect(Yii::app()->createUrl('/wechat/product/index')); }
} else { echo '暂无图片'; } ?> </div> </div> <div class="row qys_addp_row"> <div class="col-lg-6 col-md-6 col-xs-6 col-sm-6 text-left">更换产品图片:</div> <div class="col-lg-6 col-md-6 col-xs-6 col-sm-6"></div> </div> <div class="row"> <div class="col-lg-12" style="text-align: left;"> <?php #获得当前用户的图片 $user_id = Yii::app()->user->getId(); $imagelist = Pic::model()->findAll("user_id=:user_id", array(":user_id" => $user_id)); foreach ($imagelist as $key => $value) { ?> <label class="radio-inline"> <input type="radio" name="pic_id" value="<?php echo $value->id; ?> "> <img style="width:60px;height:40px;" src="<?php echo $value->pic_s_img; ?> "/> </label> <?php } ?> </div>