Exemplo n.º 1
0
 /**
  * 数据解析
  *
  * @param string $data 产品相册图片数据
  *  - $data内容应该为JSON Encode后的字符串序列
  * @return boolean|array
  *  - 为boolean时只能为FALSE,表示数据解析失败
  *  - 为array时表示指定产品相册图片信息,结构如下:
  *  ~~~
  *  [
  *      [
  *          'id' => '图片ID',
  *          'url' => '图片URL',
  *          'desc' => 图片描述'
  *      ]
  *      // 产品的其他图片.....
  *  ]
  *  ~~~
  */
 public function parse2o($data)
 {
     // XXX: 需要进行Model层封装
     /*
     return ProductImage::find()->where([
         'product_id' => $data['product_id'],
         'type' => ProductImage::TYPE_CATIONINDE,
     ])->
     asArray()->
     all();
     */
     return ProductImage::find()->where(['and', 'product_id=' . $data['product_id'], ['or', 'type=' . ProductImage::TYPE_CATIONINDE, 'type=' . ProductImage::TYPE_CATIONFIRST, 'type=' . ProductImage::TYPE_GOODPRODUCT]])->asArray()->all();
     //return $data ? json_decode($data['attr_val'], true) : FALSE;
 }
Exemplo n.º 2
0
 public function actionDetail()
 {
     $slug = Yii::$app->request->get('slug');
     if ($product = Product::findOne(['slug' => $slug, 'is_active' => 1])) {
         $this->link_canonical = $product->getLink();
         if (!Redirect::compareUrl($this->link_canonical)) {
             $this->redirect($this->link_canonical);
         }
         $product_images = ProductImage::find()->where(['product_id' => $product->id])->all();
         if ($this->is_mobile && !$this->is_tablet) {
             $product_image_suffix = ProductImage::$image_resizes['mobile'];
         } else {
             if ($this->is_tablet) {
                 $product_image_suffix = ProductImage::$image_resizes['tablet'];
             } else {
                 $product_image_suffix = ProductImage::$image_resizes['desktop'];
             }
         }
         return $this->render('detail', ['product' => $product, 'product_images' => $product_images, 'product_image_suffix' => $product_image_suffix]);
     } else {
         Redirect::go();
     }
 }
Exemplo n.º 3
0
 /**
  * 365活动生成专题页
  * @param $rel_id int 产品活动ID
  * @测试地址:http://test.idaiyan.cn/activity/generationh5?rel_id=32837
  * @测试地址:http://dev.idaiyan.cn/activity/generationh5?rel_id=32821
  */
 public function actionGenerationh5()
 {
     $parr = Yii::$app->request->get();
     $rel_id = isset($parr['rel_id']) && $parr['rel_id'] && is_numeric($parr['rel_id']) ? intval($parr['rel_id']) : $this->redirect(['product/index']);
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     if (!empty($_SESSION['user']['uid'])) {
         $uid = $_SESSION['user']['uid'];
         //查询用户有没有购买该商品
         $model_order = new Order();
         $res = $model_order->Mycheckpay($uid, $rel_id);
         if ($res) {
             if ($res['ispay'] == 1) {
                 //订单完成 ,已经购买
                 $isready = 1;
             } else {
                 $isready = 2;
                 //下过订单,还没有支付
             }
         } else {
             $isready = 0;
         }
         $user = $_SESSION['user'];
     } else {
         $uid = 0;
         $isready = 0;
         $user = array();
     }
     // print_r($user);exit;
     $status = ActivityProduct::STATUS_VERIFY_THROUGH;
     $activityproduct_model = new ActivityProduct();
     $actdetail = $activityproduct_model->getDetailBypk($rel_id);
     if (!$actdetail) {
         return $this->redirect(['product']);
         exit;
     }
     $actdetail['product']['user_oriented_age'] = str_pad($actdetail['product']['user_oriented_age'], 4, '0', STR_PAD_LEFT);
     $acprattr_model = new ActivityProductAttrVal();
     $acprattr = $acprattr_model->getRealAttrVals($rel_id, 7);
     if (isset($acprattr['end_time']['val'])) {
         $acprattr['end_time']['val'] = explode('-', $acprattr['end_time']['val']);
     }
     if (!empty($acprattr['video']['val']['video_url'])) {
         if (substr($acprattr['video']['val']['video_url'], 0, 4) == 'http') {
             $acprattr['video']['val']['video_url'] = Yii::$app->util->generalVideo($acprattr['video']['val']['video_url']);
         }
     }
     $_SESSION['activityProduct']['price'] = isset($acprattr['discount_price']['val']['price']) ? $acprattr['discount_price']['val']['price'] : '1';
     // echo "<pre>";
     // print_r($actdetail);
     // exit;
     //查询该产品  type=4 的 图片  用在 首屏背景图那里
     $mpimg = new ProductImage();
     $fourimg = $mpimg->getByTypeAndPid(ProductImage::TYPE_CATIONFIRST, $actdetail['product_id']);
     $this->layout = false;
     return $this->render('generationh5', ['actdetail' => $actdetail, 'acprattr' => $acprattr, 'fourimg' => $fourimg, 'uid' => $uid, 'user' => $user, 'isready' => $isready]);
 }
Exemplo n.º 4
0
 /**
  * 对于search的补充,对search一对多关系的添加
  *
  * @param  array $ids 产品id号数组
  *
  * @return array $ex  产品对应的活动,图片信息
  */
 public function extrDAta($ids = [])
 {
     if (is_array($ids) && $ids) {
         $ex = self::find()->select([IProductBase::tableName() . '.id'])->with(['image' => function ($query) {
             return $query->select(['product_id', 'url'])->where([ProductImage::tableName() . '.type' => ProductImage::TYPE_ALBUM]);
         }, 'aproduct' => function ($query) {
             return $query->select(['id', 'acti_id', 'product_id', 'start_time', 'end_time', 'status'])->with('apstat');
         }])->where(['id' => $ids])->indexBy('id')->asArray()->all();
         return $ex;
     }
     $ex = [];
     return $ex;
 }
Exemplo n.º 5
0
 /**
  * [活动属性处理接口]
  * @param array $data 数据
  *  [
  *      'rel_id' => '活动产品关联ID',
  *      'attrid' => '属性ID',
  *      'attrval' => '属性值',
  *      'type' => '活动产品关联ID',
  *      'id' => '图鉴属性ID',
  *      'delid' => '图鉴属性ID',
  *      'title' => '图片标题',
  *      'desc' => '图片描述',
  *      'pimage' => '图片',
  *  ]
  * @return [json_encode]     [0,1001]
  * 00 执行成功,已完成
  * 01 执行成功,未完成
  * 02 删除成功
  * 1001 未登录
  * 1004 参数错误
  * 1005 图片上传错误
  */
 public function actionAttrprocess()
 {
     //判断登陆
     $user = yii::$app->util->isLogin();
     if ($user) {
         $uid = $user['uid'];
     } else {
         echo PublicLibrary::format_res_encode('1001', 'the user no landing or no ajax!');
         exit;
     }
     $date = Yii::$app->request->post();
     $date = array_map('trim', $date);
     $date = array_map('strip_tags', $date);
     $rel_id = isset($date['rel_id']) ? intval($date['rel_id']) : 0;
     $attrid = isset($date['attrid']) ? intval($date['attrid']) : 0;
     $attval = isset($date['attrval']) ? $date['attrval'] : '';
     $type = isset($date['type']) ? $date['type'] : '';
     $delid = isset($date['delid']) ? intval($date['delid']) : '';
     //用活动产品id 获取活动id
     $mpactivity = new ActivityProduct();
     $pcone = $mpactivity->pk($rel_id);
     //当前用户和产品活动发布用户不同
     if (empty($pcone) || $uid != $pcone['user_id'] || $pcone['status'] == ActivityProduct::STATUS_VERIFYING) {
         echo yii::$app->util->formatResEncode('1003', 'user or status error!');
         exit;
     }
     $acti_id = $pcone->acti_id ? $pcone->acti_id : 0;
     $product_id = $pcone->product_id ? $pcone->product_id : 0;
     if (empty($rel_id) || empty($attrid) || empty($acti_id) || empty($product_id)) {
         echo yii::$app->util->formatResEncode('1004', 'params error');
         exit;
     }
     //查询属性基础信息
     $mattrbase = new ActivityAttrBase();
     $attr = $mattrbase->pk($attrid);
     if (!empty($type)) {
         $attribute = [];
         $content = [];
         $sign = false;
         //添加标示
         $comsta = false;
         //完成度标示
         $delstat = false;
         //删除标识
         if ($type == "image") {
             $pimage_model = new ProductImage();
             //删除
             if ($delid) {
                 if ($pimage_model->delBypk($delid)) {
                     $delstat = true;
                 }
             } else {
                 $imgstatus = false;
                 $pos_id = 100;
                 //图片上传
                 $pimage = UploadedFile::getInstanceByName('pimage');
                 if ($pimage !== null) {
                     //判断图片大小是否符合规定
                     if ($pimage->size > ProductImage::MAX_SIZE || $pimage->error != 0) {
                         echo yii::$app->util->formatResEncode('1005', 'image error');
                         exit;
                     }
                     $rootpath = 'uploads/' . date('Y/m/d') . '/';
                     //图片保存路径
                     file_exists($rootpath) or mkdir($rootpath, 0777, true);
                     //生成图片路径
                     $randname = time() . rand(0, 500);
                     //图片公有名
                     $setpimage_path = $rootpath . $randname;
                     //图路径
                     move_uploaded_file($pimage->tempName, $setpimage_path . '.jpg');
                     //生成缩略图
                     $sreturn = $this->smallimg($setpimage_path, 200, 125);
                     //产品详细
                     $pimage_path = $sreturn ? $setpimage_path . ProductImage::THUMB_PDETIAL : $setpimage_path . '.jpg';
                     $content['url'] = $setpimage_path;
                     $imgstatus = true;
                 }
                 //填写描述
                 if (!empty($date['id']) && !empty($date['desc'])) {
                     $content['desc'] = $date['desc'];
                     $imgstatus = true;
                 }
                 //填写标题
                 if (!empty($date['id']) && !empty($date['title'])) {
                     $content['title'] = $date['title'];
                     $imgstatus = true;
                 }
                 if ($imgstatus) {
                     $content['product_id'] = $product_id;
                     $content['type'] = $pos_id;
                     if (isset($date['id']) && !empty($date['id'])) {
                         $content['id'] = intval($date['id']);
                         $imgid = $pimage_model->imageSave($content);
                     } else {
                         $pimid = $pimage_model->getByTypeAndPid($pos_id, $product_id);
                         //详细图文介绍 图片个数不超过9个,超过9个不做新增操作
                         if (count($pimid) < 9 && $pos_id == 100) {
                             // var_dump($date);die;
                             $imgid = $pimage_model->imageSave($content);
                         }
                     }
                     if (isset($imgid) && $imgid > 0) {
                         $sign = $imgid;
                         //判断该条信息是否完整
                         if ($pimage_model->iscomplete($imgid, "title")) {
                             $complete = array('id' => $imgid, 'is_complete' => ProductImage::IS_COMPLETE);
                             if ($pimage_model->imageSave($complete)) {
                                 $comsta = true;
                             }
                         }
                     }
                 }
             }
         }
         if ($type == "video") {
             // var_dump($date);die;
             $pvideo_model = new ProductVideo();
             if (isset($date['video_url'])) {
                 if (!empty($date['video_url'])) {
                     $content['video_url'] = $date['video_url'];
                     //$content['video_url'] = Yii::$app->util->generalVideo($date['video_url']);
                 }
                 $content['uid'] = $uid;
                 $content['product_id'] = $product_id;
                 if (isset($date['id']) && !empty($date['id'])) {
                     $content['id'] = $date['id'];
                     $videoid = $pvideo_model->store($content);
                     // $sign = $videoid;
                 } else {
                     //一个产品的视频属性 只能存在一条,如果已经存在,不做新增操作, 返回存在的id值,
                     $rvid = $pvideo_model->getByPid($product_id, true);
                     if (!$rvid) {
                         $videoid = $pvideo_model->store($content);
                     } else {
                         $videoid = isset($rvid['id']) ? $rvid['id'] : '';
                     }
                 }
                 if ($videoid) {
                     $sign = $videoid;
                     $comsta = true;
                 }
             }
         }
         if ($delstat) {
             //+TOOD 删除 修改 产品属性值 表数据操作
             echo yii::$app->util->formatResEncode('02', 'deletet success');
             exit;
         } else {
             if ($sign) {
                 $baseattr_model = new BaseAttribute();
                 $imgurl = isset($pimage_path) ? $pimage_path : '';
                 $videoid = isset($videoid) ? intval($videoid) : 1;
                 if ($comsta) {
                     $btas = $baseattr_model->save($rel_id, $uid, $attrid, $videoid, false, 1);
                     echo yii::$app->util->formatResEncode('00', 'success', array('id' => $sign, 'imgurl' => $imgurl));
                     exit;
                 } else {
                     $btas = $baseattr_model->save($rel_id, $uid, $attrid, $videoid, false, 0);
                     echo yii::$app->util->formatResEncode('01', 'success', array('id' => $sign, 'imgurl' => $imgurl));
                     exit;
                 }
             }
         }
     } else {
         $mbaseattr = new BaseAttribute();
         $btas = $mbaseattr->save($rel_id, $uid, $attrid, $attval, false, 1);
         echo yii::$app->util->formatResEncode('0', 'success');
         exit;
     }
 }
Exemplo n.º 6
0
 /**
  * @return ActiveQuery
  */
 public function getProductImages()
 {
     return $this->hasMany(ProductImage::className(), ['product_id' => 'id']);
 }
Exemplo n.º 7
0
 /**
  * 图片上传接口(备用)
  * @param  int $product_id 产品id
  * @param  string $type    图片类型
  * @param  string $pos_id 图片位置标识
  * @return  string address 图片位置
  */
 public function actionUploadimage()
 {
     //判断登陆
     $user = PublicLibrary::is_login();
     //if ($user && PublicLibrary::is_ajax()) {
     if ($user) {
         $uid = $user['uid'];
     } else {
         echo PublicLibrary::format_res_encode('1001', 'the user no landing or no ajax!');
         exit;
         //json 格式
     }
     $form = Yii::$app->request->post();
     $type = isset($form['type']) ? $form['type'] : '';
     $pos_id = isset($form['pos_id']) ? $form['pos_id'] : '';
     $product_id = isset($form['product_id']) ? $form['product_id'] : '';
     if (!$product_id) {
         echo PublicLibrary::format_res_encode('1002', 'no this product!');
         exit;
         //json 格式
     }
     //album图片上传
     $album = UploadedFile::getInstanceByName('album');
     //获取图片album
     if ($album !== null) {
         //判断图片大小是否符合规定
         if ($album->size > ProductImage::MAX_SIZE || $album->error != 0) {
             echo PublicLibrary::format_res_encode('1003', 'More than size!');
             exit;
             //json 格式
         }
         if ($type == '1') {
             //产品基础表
             $fld = 'album';
             //判断封面图片是否存在,或是修改
             $model = new IProductBase();
             if ($product_id) {
                 $model = IProductBase::findOne(['id' => $form['product_id']]);
                 if (!$model) {
                     $model = new IProductBase();
                 }
             }
             $model->type = $form['type'];
         } elseif ($type == '2') {
             //产品图片表
             $fld = 'url';
             $model = ProductImage::findOne(['product_id' => $form['product_id'], 'pos_id' => $pos_id]);
             //通过产品id和图片位置判断有没有改图片
             if ($model) {
                 $model->update_time = time();
             } else {
                 $model = new ProductImage();
                 $model->create_time = time();
                 $model->update_time = time();
             }
             $model->pos_id = $form['pos_id'];
             $model->type = $form['type'];
             $model->product_id = $form['product_id'];
             //当位置为1时 修改base表的banner字段
         }
         $albumPath = $model->{$fld};
         if (!$albumPath) {
             $rootpath = 'uploads/' . date('Y/m/d') . '/';
             //图片保存路径
             file_exists($rootpath) or mkdir($rootpath, 0700, true);
             //生成图片路径
             $randname = time() . rand(0, 500);
             //图片公有名
             $albumPath = $rootpath . $randname;
             //封面图路径
         }
         if ($type == '1') {
             $thumbPath = $albumPath . ProductImage::THUMB_SIZE_ONE;
             //缩略图路径
             $returnPath = $thumbPath . '.jpg';
             //生成缩略图
             $width = 312;
             $height = 196;
             $thumbPath = '@frontend/web/' . $thumbPath . '.jpg';
             Image::thumbnail($album->tempName, $width, $height)->save(Yii::getAlias($thumbPath), ['quality' => 100]);
         } else {
             $returnPath = $albumPath . '.jpg';
         }
         //原图上传
         $album->saveAs($albumPath . '.jpg');
         $model->{$fld} = $albumPath;
         $model->save();
         echo PublicLibrary::format_res_encode('1000', 'successful!', $returnPath);
         exit;
         //json 格式
     } else {
         echo PublicLibrary::format_res_encode('1004', 'no file!');
         exit;
         //json 格式
     }
 }