Ejemplo n.º 1
0
 /**
  * 展示填写活动信息页面
  * @param  int $pid  产品id
  * @param  int $aid  活动aid
  *
  * @return array $menu 产品id渲染到活动页面
  */
 public function actionProductactivity()
 {
     //用户是否登陆
     $user = PublicLibrary::is_login();
     if (!$user) {
         $this->redirect(['user/login']);
     }
     $parr = Yii::$app->request->get();
     $pid = isset($parr['pid']) ? intval($parr['pid']) : '';
     $start_time = isset($parr['start_time']) ? intval($parr['start_time']) : '';
     $aid = intval(ActivityBase::GENERAL_ACTIVITY);
     if ($pid == '' || $aid == '') {
         return $this->redirect(['home-page/lists', 'uid' => $_SESSION['user']['uid']]);
         //跳转到完善信息
     }
     //判断该用户是否发布了这个产品
     $session = Yii::$app->session;
     $uid = intval($_SESSION['user']['uid']);
     //查询现有的活动
     $mActiBase = new ActivityBase();
     $activity = $mActiBase->pk($aid);
     if (!$activity) {
         return $this->redirect(['home-page/lists', 'uid' => $_SESSION['user']['uid']]);
         //跳转到完善信息
     }
     //查询是不是该用户发布的产品
     $model = new IProductBase();
     $res = $model->isMyProduct($uid, $pid);
     $basePrice = isset($res[0]['price']) ? $res[0]['price'] : '';
     if (!$res) {
         return $this->redirect(['home-page/lists', 'uid' => $_SESSION['user']['uid']]);
         //跳转到完善信息
     }
     $session->set('acti_config', $activity['config']);
     //活动属性map
     $mactivitypdt = new ActivityProduct();
     $mArag = new ActivityRelAttrGroup();
     $attrMap = $mArag->getAttrMapping($aid);
     //查询该商品有没有参加过该活动
     $one = $mactivitypdt->isinActivity($uid, $aid, $pid);
     if (!$one) {
         //入库
         $mactivitypdt->product_id = $pid;
         $mactivitypdt->acti_id = $aid;
         $mactivitypdt->user_id = $uid;
         $mactivitypdt->status = ActivityProduct::STATUS_SAVE;
         $mactivitypdt->create_time = time();
         $mactivitypdt->update_time = time();
         $mactivitypdt->save();
         $rel_id = $mactivitypdt['id'];
         //获取刚刚插入到数据库的id
         //插入到活动产品统计表
         $apstart = new ActivityProductStat();
         $data = ['rel_id' => $rel_id, 'acti_id' => $aid, 'product_id' => $pid];
         $apstart->store($data);
     } else {
         //查询过去的填写的数据在页面中显示
         if ($one['status'] == ActivityProduct::STATUS_VERIFYING) {
             //审核中
             return $this->redirect(['home-page/lists', 'uid' => $_SESSION['user']['uid']]);
             //跳转到完善信息
         } else {
             if ($one['status'] == ActivityProduct::STATUS_VERIFY_THROUGH) {
                 //审核通过 可在插入一次数据库
                 //入库
                 $mactivitypdt->product_id = $pid;
                 $mactivitypdt->acti_id = $aid;
                 $mactivitypdt->user_id = $uid;
                 $mactivitypdt->status = ActivityProduct::STATUS_SAVE;
                 $mactivitypdt->save();
                 $rel_id = Yii::$app->db->getLastInsertID();
                 //获取刚刚插入到数据库的id
                 //插入到活动产品统计表
                 $apstart = new ActivityProductStat();
                 $data = ['rel_id' => $rel_id, 'acti_id' => $aid, 'product_id' => $pid];
                 $apstart->store($data);
             } else {
                 $rel_id = $one['id'];
             }
         }
     }
     //如果从专题页带入了开始时间 修改开始时间属性
     if ($start_time) {
         //查询该时间是否被占用
         $timeisset = $mactivitypdt->searchStartime($start_time, ActivityBase::GENERAL_ACTIVITY);
         if (!$timeisset && $start_time > time()) {
             $mActivity = new ActivityBase();
             $acti = $mActivity->pk(7);
             //1是开始时间属性ID
             $baseattr_model = new BaseAttribute();
             $baseattr_model->save($rel_id, $uid, 1, $start_time, $acti['config'], ActivityProductAttrVal::STATUS_FINISHED);
         }
     }
     //查询左侧菜单
     $ActivityAttrGroup = new ActivityAttrGroup();
     $menu = $ActivityAttrGroup->getCompleteStatus($rel_id);
     $ActivityProductAttrVal = new ActivityProductAttrVal();
     $attrval = $ActivityProductAttrVal->getRealAttrVals($rel_id, $aid);
     $attrval = array_merge($attrMap, $attrval);
     if (isset($attrval['album']['val']) && is_array($attrval['album']['val'])) {
         foreach ($attrval['album']['val'] as $key => $value) {
             if ($value['type'] == ProductImage::TYPE_CATIONFIRST) {
                 $fourpimag[] = $value;
             }
             if ($value['type'] == ProductImage::TYPE_CATIONINDE) {
                 $fivepimag[] = $value;
             }
         }
     }
     $this->layout_data = 'uc';
     return $this->render('productactivity', ['pid' => $pid, 'rel_id' => $rel_id, 'menu' => $menu, 'attrMap' => $attrMap, 'attrs' => isset($attrval) ? $attrval : '', 'fourpimag' => isset($fourpimag) ? $fourpimag : '', 'fivepimag' => isset($fivepimag) ? $fivepimag : '', 'price' => $basePrice]);
 }