/**
  * [活动属性处理接口]
  * @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;
     }
 }
 /**
  * 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]);
 }
Example #3
0
 /**
  * 产品预览
  * @param  array $_POST 产品相关信息
  * @return array $model  显示产品相关信息
  */
 public function actionPreview()
 {
     $form = Yii::$app->request->post('extra');
     //数据过滤
     $tmp = isset($form['detail']) ? $form['detail'] : '';
     $form = array_map('trim', $form);
     $form = array_map('strip_tags', $form);
     $form = array_map('htmlspecialchars', $form);
     $form['detail'] = $tmp;
     // <script>alert('zhanglu');</script>
     //bug处理 限定name 和summary长度
     $form['name'] = mb_substr($form['name'], 0, 20, 'utf-8');
     $form['summary'] = mb_substr($form['summary'], 0, 100, 'utf-8');
     //获取hash值
     $formhash = Yii::$app->request->post('formhash', false);
     //formhash验证
     if (!PublicLibrary::verifyFormhash($formhash)) {
         echo '<script>alert("非法提交!");window.close;</script>';
         exit;
     } else {
         $session = Yii::$app->session;
         $session->isActive ? '' : $session->open();
         $session->set('formhash', $formhash);
         $session->close();
     }
     $user = PublicLibrary::is_login();
     //判断是否登陆
     if (!$user) {
         $this->redirect(['user/login', 'act' => base64_encode("home-page/lists")]);
     }
     //判断产品是否是该用户的
     $mIProductBase = new IProductBase();
     $res = $mIProductBase->isMyProduct($user['uid'], intval($form['id']));
     if (empty($res)) {
         return $this->redirect(['index']);
         exit;
     }
     //判断产品是否是该用户的
     $mIProductBase = new IProductBase();
     if (!$mIProductBase->isMyProduct($user['uid'], $form['id'])) {
         $this->redirect(['home-page/lists', 'uid' => $user['uid']]);
     }
     if (empty($form['summary']) || empty($form['name'])) {
         echo '<script>alert("产品名和简介都不能为空!");window.history.back(-1);</script>';
         exit;
     } else {
         //对i_product_extra表的插入或修改
         $model = IProductExtra::findOne(['product_id' => $form['id']]);
         if ($model == null) {
             $model = new IProductExtra();
             $model->create_time = time();
         }
         $model->product_id = intval($form['id']);
         $model->summary = strip_tags($form['summary']);
         $model->video_url = strip_tags($form['video_url']);
         $model->detail = $form['detail'];
         $model->update_time = time();
         $model->save();
         //对i_product_base表的插入或修改
         $model_base = IProductBase::findOne(['id' => $form['id']]);
         $model_base->update_time = time();
         $model_base->save();
         //album图片上传
         $album = UploadedFile::getInstanceByName('album');
         //试取图片album
         if ($album !== null) {
             //判断图片大小是否符合规定
             if ($album->size > 1048576 || $album->error != 0) {
                 echo '<script>alert("封面图片格式不对或大于1M!");window.history.back(-1);</script>';
                 exit;
             }
             //判断封面图片是否存在,或是修改
             $model = IProductBase::findOne(['id' => $form['id']]);
             $albumPath = $model->album;
             if (!$albumPath) {
                 $rootpath = 'uploads/' . date('Y/m/d') . '/';
                 //图片保存路径
                 file_exists($rootpath) or mkdir($rootpath, 0700, true);
                 //生成图片路径
                 $randname = time() . rand(0, 500);
                 //图片公有名
                 $albumPath = $rootpath . $randname;
                 //封面图路径
             }
             //缩略图入库用
             $tmp = $albumPath;
             $thumbPath = $albumPath . ProductImage::THUMB_SIZE_ONE;
             //缩略图路径
             //生成缩略图
             $width = 312;
             $height = 196;
             $thumbPath = '@frontend/web/' . $thumbPath . '.jpg';
             Image::thumbnail($album->tempName, $width, $height)->save(Yii::getAlias($thumbPath), ['quality' => 100]);
             //原图上传
             $album->saveAs($albumPath . '.jpg');
             $model->album = $albumPath;
             $model->name = strip_tags($form['name']);
             $model->price = strip_tags($form['price']);
             //原价
             $model->status = IProductBase::STATUS_INVALID;
             $model->save();
             //缩略图入库image表
             $mProductImage = new ProductImage();
             $re = $mProductImage->getByTypeAndPid(ProductImage::TYPE_ALBUM, $form['id']);
             //判断图片表中有没有该产品缩略图
             if (empty($re)) {
                 $content = ['product_id' => $form['id'], 'type' => ProductImage::TYPE_ALBUM, 'url' => $tmp, 'create_time' => time()];
                 $mProductImage->imageSave($content);
             }
         } else {
             $model = IProductBase::findOne(['id' => $form['id']]);
             if ($model->album !== '') {
                 $albumPath = $model->album . '.jpg';
                 $thumbPath = $model->album . ProductImage::THUMB_SIZE_ONE . '.jpg';
                 file_exists($albumPath) && unlink($albumPath);
                 file_exists($thumbPath) && unlink($thumbPath);
                 $model->album = '';
             }
             $model->name = strip_tags($form['name']);
             $model->price = strip_tags($form['price']);
             //原价
             $model->status = IProductBase::STATUS_INVALID;
             $model->save();
             //删除缩略图
             $mProductImage = new ProductImage();
             //判断图片表中有没有该产品缩略图
             $re = $mProductImage->getByTypeAndPid(ProductImage::TYPE_ALBUM, $form['id']);
             if (!empty($re)) {
                 $mProductImage->delBypk($re[0]['id']);
             }
         }
         //图片1上传
         $banner1 = UploadedFile::getInstanceByName('bigbanner1');
         //试取图片album
         if ($banner1 !== null) {
             //判断图片大小是否符合规定
             if ($banner1->size > 1048576 * 2 || $banner1->error != 0) {
                 echo '<script>alert("通栏图片格式不对或大于2M!");window.history.back(-1);</script>';
                 exit;
             }
             $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 1]);
             if ($model !== null) {
                 $banner1->saveAs($model->url . '.jpg');
             } else {
                 $rootpath = 'uploads/' . date('Y/m/d') . '/';
                 //图片保存路径
                 file_exists($rootpath) or mkdir($rootpath, 0700, true);
                 //生成图片路径
                 $randname = time() . rand(0, 500);
                 //图片名
                 $bannerPath = $rootpath . $randname;
                 //封面图路径
                 $banner1->saveAs($bannerPath . '.jpg');
                 //保存图片
                 //插入数据
                 $model = new ProductImage();
                 $model->product_id = $form['id'];
                 $model->url = $bannerPath;
                 $model->create_time = time();
                 $model->type = ProductImage::TYPE_BANNER;
                 $model->pos_id = 1;
                 $model->save();
             }
         } else {
             $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 1]);
             if ($model !== null) {
                 file_exists($model->url . '.jpg') && unlink($model->url . '.jpg');
                 $model->delete();
             }
         }
         //图片1在i_product_base 中是否存在
         $modelImage = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 1]);
         $modelBase = IProductBase::findOne(['id' => $form['id']]);
         if ($modelImage !== null) {
             $modelBase->banner_image = $modelImage->url;
             $modelBase->save();
         } else {
             $modelBase->banner_image = '';
             $modelBase->save();
         }
         //图片2上传
         $banner2 = UploadedFile::getInstanceByName('bigbanner2');
         //试取图片album
         if ($banner2 !== null) {
             //判断图片大小是否符合规定
             if ($banner2->size > 1048576 * 2 || $banner2->error != 0) {
                 echo '<script>alert("通栏图片格式不对或大于2M!");window.history.back(-1);</script>';
                 exit;
             }
             $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 2]);
             if ($model !== null) {
                 $banner2->saveAs($model->url . '.jpg');
             } else {
                 $rootpath = 'uploads/' . date('Y/m/d') . '/';
                 //图片保存路径
                 file_exists($rootpath) or mkdir($rootpath, 0700, true);
                 //生成图片路径
                 $randname = time() . rand(0, 500);
                 //图片名
                 $bannerPath = $rootpath . $randname;
                 //封面图路径
                 $banner2->saveAs($bannerPath . '.jpg');
                 //保存图片
                 //插入数据
                 $model = new ProductImage();
                 $model->product_id = $form['id'];
                 $model->url = $bannerPath;
                 $model->create_time = time();
                 $model->type = ProductImage::TYPE_BANNER;
                 $model->pos_id = 2;
                 $model->save();
             }
         } else {
             $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 2]);
             if ($model !== null) {
                 file_exists($model->url . '.jpg') && unlink($model->url . '.jpg');
                 $model->delete();
             }
         }
         //图片3上传
         $banner3 = UploadedFile::getInstanceByName('bigbanner3');
         //试取图片album
         if ($banner3 !== null) {
             //判断图片大小是否符合规定
             if ($banner3->size > 1048576 * 2 || $banner3->error != 0) {
                 echo '<script>alert("通栏图片格式不对或大于2M!");window.history.back(-1);</script>';
                 exit;
             }
             $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 3]);
             if ($model !== null) {
                 $banner3->saveAs($model->url . '.jpg');
             } else {
                 $rootpath = 'uploads/' . date('Y/m/d') . '/';
                 //图片保存路径
                 file_exists($rootpath) or mkdir($rootpath, 0700, true);
                 //生成图片路径
                 $randname = time() . rand(0, 500);
                 //图片名
                 $bannerPath = $rootpath . $randname;
                 //封面图路径
                 $banner3->saveAs($bannerPath . '.jpg');
                 //保存图片
                 //插入数据
                 $model = new ProductImage();
                 $model->product_id = $form['id'];
                 $model->url = $bannerPath;
                 $model->create_time = time();
                 $model->type = ProductImage::TYPE_BANNER;
                 $model->pos_id = 3;
                 $model->save();
             }
         } else {
             $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 3]);
             if ($model !== null) {
                 file_exists($model->url . '.jpg') && unlink($model->url . '.jpg');
                 $model->delete();
             }
         }
     }
     return $this->redirect(['product/view', 'id' => $form['id']]);
     //跳转到完善信息
 }