public function command()
 {
     $connection = \Yii::$app->db;
     // $schema = $connection->getSchema();
     // $tables = $schema->getTableNames();
     // print_r($tables);exit;
     $re = $connection->createCommand()->addColumn(IProductBase::tableName(), 'zhanglu', 'string');
     // var_dump($connection);exit;
     // var_dump(IProductBase::tableName());exit;
     // $re = \Yii::$app->command->addColumn(IProductBase::tableName(), 'zhanglu', 'string');
     // $re = $re->getSql();
     var_dump($re);
 }
 /**
  * 活动产品关联搜索
  * @param  array  $options 搜索条件
  * [
  *     'page' => '页码',
  *     'product_name' => '产品名',
  *     'user_name' => '发布人姓名',
  *     'nickname' => '发布人昵称',
  *     'mobile' => '电话',
  *     'status' => '活动状态',
  *     'activity' => '活动',
  * ]
  * @return [type]          [description]
  */
 public function search($options = [])
 {
     $df = ['page' => 1, 'product_name' => '', 'user_name' => '', 'nickname' => '', 'mobile' => '', 'status' => 0, 'activity' => 0];
     $options = array_merge($df, $options);
     $statusFields = [self::STATUS_SAVE, self::STATUS_VERIFYING, self::STATUS_VERIFY_THROUGH, self::STATUS_VERIFY_NOTTHROUGH];
     $activitiesFields = ['7' => '365', '8' => '一呼百应', '9' => '中国好产品'];
     $activitiesFields = array_keys($activitiesFields);
     $options['status'] = in_array($options['status'], $statusFields) ? $options['status'] : 0;
     $options['activity'] = in_array($options['activity'], $activitiesFields) ? $options['activity'] : 0;
     $choose = [self::tableName() . '.status ' => $options['status'], self::tableName() . '.acti_id ' => $options['activity']];
     $choose = array_filter($choose);
     $offset = ($options['page'] - 1) * self::ACT_PAGESIZE;
     $data = self::find()->joinWith(['member' => function ($query) {
         $query->select([Member::tableName() . '.uid', Member::tableName() . '.truename', Member::tableName() . '.nickname', Member::tableName() . '.mobile', Member::tableName() . '.email']);
     }, 'activity' => function ($query) {
         $query->select([ActivityBase::tableName() . '.id', ActivityBase::tableName() . '.subject', ActivityBase::tableName() . '.summary']);
     }, 'product' => function ($query) {
         $query->select([IProductBase::tableName() . '.id', IProductBase::tableName() . '.name']);
     }])->where(self::tableName() . '.status != :del', [':del' => self::STATUS_INVALID])->andFilterWhere(['like', IProductBase::tableName() . '.name', $options['product_name']])->andFilterWhere(['like', Member::tableName() . '.truename', $options['user_name']])->andFilterWhere(['like', Member::tableName() . '.nickname', $options['nickname']])->andFilterWhere(['like', Member::tableName() . '.mobile', $options['mobile']])->andFilterWhere($choose)->offset($offset)->limit(self::ACT_PAGESIZE)->orderBy([self::tableName() . '.id' => SORT_DESC]);
     return $data;
 }
Exemple #3
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;
 }
 /**
  * [产品详情]
  * @param  int $id 产品id
  * @return array     产品信息渲染到页面view
  */
 public function actionView($id)
 {
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     //判断产品是否发布
     $base = IProductBase::find()->select('status,uid')->where('id = :id', [':id' => $id])->asArray()->one();
     if (!empty($_SESSION['user'])) {
         if ($base['status'] != IProductBase::STATUS_VERIFEND) {
             if ($base['uid'] != $_SESSION['user']['uid']) {
                 return $this->redirect(['index']);
                 //跳转到完善信息
             }
         }
     } else {
         if ($base['status'] != IProductBase::STATUS_VERIFEND) {
             return $this->redirect(['index']);
             //跳转到完善信息
         }
     }
     //增加总访问量
     $mProductStat = new IProductStat();
     $mProductStat->modify('page_views', $id, 1, true);
     //访问日志
     $mViewsLog = new ViewsLog();
     $mViewsLog->modify($id, ViewsLog::PRODUCT_TYPE);
     //增加周访问量,月访问量
     $week_num = $mViewsLog->ViewsNum($id, ViewsLog::PRODUCT_TYPE, 7);
     $month_num = $mViewsLog->ViewsNum($id, ViewsLog::PRODUCT_TYPE, 30);
     $mProductStat->modifyviewnum('week_views', $id, $week_num);
     $mProductStat->modifyviewnum('month_views', $id, $month_num);
     //基础数据和扩展数据查询
     $re = IProductBase::find()->With('extra', 'stat')->where(IProductBase::tableName() . '.id = :id', [':id' => $id])->asArray()->one();
     //该产品用户共发布产品数
     $presentNum = IProductBase::find()->where(['uid' => $re['uid'], 'status' => IProductBase::STATUS_VERIFEND])->count();
     //喜欢此产品用户
     $model = new ProductFollow();
     $loves = $model->getFollowUsers($id);
     //产品发布人头像及姓名
     $model = new Member();
     $user = $model->find()->select(['avatar', 'nickname'])->where(['uid' => $re['uid']])->asArray()->one();
     //参加活动
     $model = new ActivityProduct();
     //        print_r($id);exit;
     $actives = $model->getActivityDetail($id);
     // $actives = $model->getActivitiseById($id);
     // print_r($actives);exit;
     foreach ($actives as $key => $value) {
         if ($value['acti_id'] == 8) {
             $mBaiyingShare = new BaiyingShare();
             $number = $mBaiyingShare->getShareNum($value['id']);
         }
         if ($value['acti_id'] == 9) {
             $rel_id = $value['id'];
         }
     }
     //活动map
     $activityBase = new ActivityBase();
     $activesMap = $activityBase->getActivityMap();
     if (isset($rel_id)) {
         //投票信息
         $city = "上海";
         $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);
     }
     return $this->render('view', ['re' => $re, 'present_num' => $presentNum, 'actives' => $actives, 'now' => time(), 'number' => isset($number) ? intval($number) : '', 'loves' => $loves, 'user' => $user, 'activesMap' => $activesMap, 'optione' => isset($optione) ? $optione : '']);
 }