예제 #1
0
 /**
  * 好产品详细页
  * @author song
  * @param int $rel_id 活动产品id
  *
  * @return
  * */
 public function actionDetail()
 {
     $rel_id = Yii::$app->request->get('rel_id');
     $rel_id = intval($rel_id);
     if ($rel_id > 0) {
         //查询活动产品详细
         $mActivityProduct = new ActivityProduct();
         $actproduct = $mActivityProduct->getDetailBypk($rel_id);
         if (!$actproduct && $actproduct['status'] != 3) {
             Yii::$app->util->msg('审核未通过,请联系管理员!');
             exit;
         }
         //查询活动产品属性
         $mapattrval = new ActivityProductAttrVal();
         $attrval = $mapattrval->getRealAttrVals($rel_id, ActivityBase::GOOD_PRODUCT);
         //投票信息
         $city = isset($attrval['division']['val']) ? $attrval['division']['val'] : '';
         $poll_type_id = PollType::GOODPRODUCT_TYPE;
         $mpoll = new poll();
         $pollone = $mpoll->getPollByCity($city, $poll_type_id);
         //投票项信息
         $moption = new polloption();
         $optione = $moption->getOptionByowner($pollone['poll_id'], $rel_id);
         //var_dump($optione);
         //exit;
         //增加页面访问量
         $ActivityProductStat_model = new ActivityProductStat();
         $ActivityProductStat_model->incr($rel_id, 'page_views');
         //产品类型
         $IProductType = new IProductType();
         $Ptype = $IProductType->product_type_list();
         $Ptype = ArrayHelper::map($Ptype, 'id', 'name');
         $Ptype[6] = "";
         //页面当name为『其他』时,不然显示
         // print_r($Ptype);exit;
         //            echo '<pre>';
         //            print_r($actproduct);
         // print_r($attrval);
         // exit;
         //数据过滤
         if (isset($attrval['pokedex']['val']) && is_array($attrval['pokedex']['val'])) {
             $tmp = [];
             foreach ($attrval['pokedex']['val'] as $v) {
                 if (!empty($v['title']) && !empty($v['desc']) && !empty($v['url'])) {
                     $tmp[] = $v;
                 }
             }
             $attrval['pokedex']['val'] = $tmp;
         }
         $this->layout = false;
         return $this->render('detail', ['attrval' => $attrval, 'product' => $actproduct, 'optione' => $optione, 'type' => $Ptype, 'goodproduct_city' => ActivityBase::GOODPRODUCT_CITY]);
     }
 }
예제 #2
0
 /**
  * 365活动生成专题页
  * @param $rel_id int 产品活动ID
  */
 public function actionGenerationPage()
 {
     $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']);
     $status = ActivityProduct::STATUS_VERIFY_THROUGH;
     $activityproduct_model = new ActivityProduct();
     // XXX: 注释代码有用,业务逻辑还需要优化
     $user = PublicLibrary::is_login();
     if ($user && isset($user['uid'])) {
         $status = false;
     }
     $actprod = $activityproduct_model->getByIdAndStatus($rel_id, $status);
     if ($actprod) {
         if ($user && isset($user['uid'])) {
             $status = $user['uid'] == $actprod['user_id'] ? false : ActivityProduct::STATUS_VERIFY_THROUGH;
             if ($actprod['status'] != ActivityProduct::STATUS_VERIFY_THROUGH) {
                 //审核状态
                 if ($user['uid'] != $actprod['user_id']) {
                     $this->redirect(['product/index']);
                 }
             } else {
                 $status = ActivityProduct::STATUS_VERIFY_THROUGH;
             }
         } else {
             if ($actprod['status'] != ActivityProduct::STATUS_VERIFY_THROUGH) {
                 $this->redirect(['product/index']);
             } else {
                 $status = ActivityProduct::STATUS_VERIFY_THROUGH;
             }
         }
     } else {
         $this->redirect(['product/index']);
     }
     $actdetail = $activityproduct_model->getDetailBypk($rel_id);
     // print_r($actdetail['product']['user_oriented_age']);exit;
     // $actdetail['product']['user_oriented_age'] = str_split($actdetail['product']['user_oriented_age']);
     // echo "<pre>";
     // print_r($actdetail);
     // exit;
     $acprattr_model = new ActivityProductAttrVal();
     $acprattr = $acprattr_model->getRealAttrVals($rel_id, 2);
     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']);
         }
     }
     //查询该产品  type=4 的 图片  用在 首屏背景图那里
     $mpimg = new ProductImage();
     $fourimg = $mpimg->getByTypeAndPid(ProductImage::TYPE_CATIONFIRST, $actdetail['product_id']);
     // var_dump($fourimg);
     // exit;
     // //产品基本信息表,获取产品图片 显示在第二屏产品图片那里
     // $mpbase = new IProductBase();
     // $pbase = $mpbase->getAllTypesByIds($actdetail['product_id']);
     //增加页面访问量
     $ActivityProductStat_model = new ActivityProductStat();
     $ActivityProductStat_model->incr($rel_id, 'page_views');
     // print_r($actprod);exit;
     $this->layout = false;
     return $this->render('generationpage', ['actdetail' => $actdetail, 'acprattr' => $acprattr, 'fourimg' => $fourimg, 'actprod' => $actprod]);
 }
예제 #3
0
 /**
  * [关注]
  * @param  [int] $product_id [产品id]
  * @param  [int] $rel_id 活动产品ID  如果存在则是 更新活动产品统计
  * @param  [int] $type [1,2]
  * 1 关注     2 取消关注
  *
  * @return [json_encode]     [0,1]
  * 0 执行成功 1001 参数错误 1002 系统繁忙
  * 关注接口:http://idaiyan_new.cn/frontend/web/index.php?r=product/user_id=24&product=4291&type=1
  * 取消接口:http://idaiyan_new.cn/frontend/web/index.php?r=product/user_id=24&product=4302&type=2
  */
 public function actionFollow()
 {
     //判断登陆
     $user = PublicLibrary::is_login();
     if ($user && PublicLibrary::is_ajax()) {
         $uid = $user['uid'];
     } else {
         echo PublicLibrary::format_res_encode('1002', 'login or not ajax error !');
         exit;
     }
     // $uid = 25;
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     $form = Yii::$app->request->post();
     $id = isset($form['id']) ? intval($form['id']) : '';
     $product_id = isset($form['product_id']) ? intval($form['product_id']) : $id;
     $type = isset($form['type']) ? intval($form['type']) : '';
     $rel_id = isset($form['rel_id']) ? intval($form['rel_id']) : '';
     //活动产品id
     //用活动产品id 获取活动ID 产品ID
     if ($rel_id) {
         $pactivity_model = new ActivityProduct();
         $pactivity = $pactivity_model->pk($rel_id);
         $activity_id = $pactivity->acti_id ? $pactivity->acti_id : 0;
         $product_id = $pactivity->product_id ? $pactivity->product_id : 0;
     }
     //用户不能关注自己产品
     if (!isset($product_id)) {
         $mActivityProduct = new ActivityProduct();
         $result = $mActivityProduct->pk($rel_id);
         $product_id = $result->product_id;
     }
     $productBase = new IProductBase();
     if ($productBase->isMyProduct($uid, $product_id)) {
         echo PublicLibrary::format_res_encode('1004', '自己不能关注自己的产品');
         exit;
     }
     $pbase = IProductBase::findOne($product_id);
     $pbaseuid = $pbase['uid'];
     // $rel_id = 24576;
     // $type = 2;
     // //用活动产品id 获取活动ID 产品ID
     // if ($rel_id) {
     //     $pactivity_model = new ActivityProduct();
     //     $pactivity = $pactivity_model->pk($rel_id);
     //     $activity_id = $pactivity->acti_id ? $pactivity->acti_id : 0;
     //     $product_id = $pactivity->product_id ? $pactivity->product_id : 0;
     // }
     if (empty($product_id)) {
         echo PublicLibrary::format_res_encode('1003', 'param error !');
         exit;
     }
     $model_Base = new ProductFollow();
     $Mpfollow = new ProductFollow();
     //对follow_num增减
     $follow_num = new IProductStat();
     $Mapstar = new ActivityProductStat();
     $Mmemberstat = new MemberStat();
     if ($type == ProductFollow::API_FOLLOW) {
         if ($rel_id) {
             //设置关注的产品id集 session
             $follow_activ_product = $session['follow_activ_product'] ? $session['follow_activ_product'] : array();
             array_push($follow_activ_product, $rel_id);
             $session['follow_activ_product'] = $follow_activ_product;
             $activityfollow = $Mpfollow->activityfollow($rel_id, $product_id, $activity_id, $uid);
             if ($activityfollow == ProductFollow::FOLLOW_OP_SUCC) {
                 $Mapstar->incr($rel_id, 'follow_num');
             }
         }
         // //设置关注的产品id集 session
         // $follow_productids = $session['follow_product'];
         // array_push($follow_productids, $product_id);
         // $session['follow_product'] = $follow_productids;
         $follow = $model_Base->follow($product_id, $uid);
         if ($follow === ProductFollow::FOLLOW_OP_SUCC || $follow === true) {
             //设置关注的产品id集 session
             $follow_productids = $session['follow_product'] ? $session['follow_product'] : array('');
             array_push($follow_productids, $product_id);
             $session['follow_product'] = $follow_productids;
             $follow_num = $follow_num->modify('follow_num', $product_id);
             //增加 产品统计表 该产品关注数
             $Mmemberstat->incr($pbaseuid, 'pfollow_allnum');
             //增加 用户统计表 产品关注总数字段
         } else {
             if ($follow === ProductFollow::FOLLOW_OP_EXISTS) {
                 // 获取该产品关注数
                 $follow_num = count($model_Base->getFollowUsers($product_id));
             }
         }
     } else {
         if ($rel_id) {
             //设置关注的产品id集 session
             $follow_activ_product = $session['follow_activ_product'] ? $session['follow_activ_product'] : array();
             $key = array_search($rel_id, $follow_activ_product);
             unset($follow_activ_product[$key]);
             $session['follow_activ_product'] = $follow_activ_product;
             $follow = $activityunfollow = $Mpfollow->activityunfollow($rel_id, $product_id, $activity_id, $uid);
             //var_dump($activityunfollow);die;
             if ($activityunfollow === true) {
                 $Mapstar->decr($rel_id, 'follow_num');
             }
             $follow_num = count($model_Base->getFollowUsers($product_id));
         } else {
             // //设置关注的产品id集 session
             // $follow_productids = $session['follow_product'];
             // $key = array_search($product_id, $follow_productids);
             // unset($follow_productids[$key]);
             // $session['follow_product'] = $follow_productids;
             $follow = $model_Base->unfollow($product_id, $uid);
             if ($follow === ProductFollow::FOLLOW_OP_SUCC || $follow === true) {
                 //设置关注的产品id集 session
                 $follow_productids = $session['follow_product'] ? $session['follow_product'] : array('');
                 $key = array_search($product_id, $follow_productids);
                 unset($follow_productids[$key]);
                 $session['follow_product'] = $follow_productids;
                 $follow_num = $follow_num->modify('follow_num', $product_id, 1, FALSE);
                 //减少该产品关注数
                 $Mmemberstat->decr($pbaseuid, 'pfollow_allnum');
                 //减少 用户统计表 产品关注总数字段
             } else {
                 if ($follow === ProductFollow::FOLLOW_OP_CANCELLED) {
                     //设置关注的产品id集 session
                     $follow_productids = $session['follow_product'] ? $session['follow_product'] : array('');
                     $key = array_search($product_id, $follow_productids);
                     unset($follow_productids[$key]);
                     $session['follow_product'] = $follow_productids;
                     // 获取该产品关注数
                     $follow_num = count($model_Base->getFollowUsers($product_id));
                 }
             }
         }
     }
     if ($follow) {
         //用户信息
         $member = new Member();
         $user = $member->getByUid($pbaseuid);
         $pfollow_allnum = $user['memberstar']['pfollow_allnum'];
         //被关注商品数
         $pfollow_num = $user['memberstar']['follow_num'];
         $renqi = isset($user['memberstar']) && is_array($user['memberstar']) ? array_sum($user['memberstar']) : 0;
         echo PublicLibrary::format_res_encode('0', 'success', array('follow_num' => $follow_num, 'renqi' => $renqi, 'pfollow_allnum' => $pfollow_allnum));
         //echo PublicLibrary::format_res_encode('0', 'success', array('follow_num'=> json_encode($session['follow_product'])));
     } else {
         echo PublicLibrary::format_res_encode('1001', 'params error');
     }
 }