示例#1
0
 public function showData()
 {
     foreach (IProductBase::find()->batch(10) as $products) {
         print_r($products);
         exit;
         // $customers is an array of 10 or fewer Customer objects
     }
 }
 /**
  * Action getProductNumber
  * @param $options  ID集合 
  */
 function getProductNumber($options)
 {
     $mProductBase = new IProductBase();
     $result = $mProductBase->find()->select(['uid', 'count(id) as num'])->where(['status' => 4]);
     if (empty($options)) {
         $result = $result->groupBy('uid');
     } else {
         if (is_array($options)) {
             $conditions = "`uid` in (" . implode(',', $options) . ")";
             $result = $result->andwhere($conditions)->groupBy('uid');
         }
     }
     $results = $result->asArray()->all();
     return $results;
 }
示例#3
0
 public function actionQuery()
 {
     $query = IProductBase::find()->andFilterWhere(['id' => 2, 'type' => '1'])->all();
     print_r($query);
 }
示例#4
0
 public function myProducts($uid)
 {
     $conditions = ['uid' => $uid, 'status' => IProductBase::STATUS_VERIFEND];
     $ac = IProductBase::find()->select(['id', 'name', 'album'])->where($conditions)->orderBy(['id' => SORT_DESC]);
     $res = $ac->asArray()->all();
     if ($res !== null) {
         return $res;
     } else {
         return false;
     }
 }
示例#5
0
 /**
  * Action Pager
  */
 public function actionPager()
 {
     $mProductBase = new IProductBase();
     /*
     $dataProvider = new ActiveDataProvider([
         'query' => $mProductBase->find()->where(['status' => 1]),
         'pagination' => [
             'pagesize' => 10
         ]
     ]);
     var_dump($dataProvider);
     */
     $data = IProductBase::find()->where(['status' => 1]);
     $pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => '2']);
     return $this->render('pager', ['pages' => $pages]);
 }
 public function Apstat()
 {
     $re = IProductBase::find()->with('aproduct')->with('apstat')->where(['id' => 38])->asArray()->one();
     echo "string";
     print_r($re);
 }
示例#7
0
 /**
  * 检测专业字段图片是否存在
  * @return  [description]
  */
 protected function check()
 {
     $thumb = true;
     //是否有相应缩略图
     $attribute = "album_new";
     //检测字段 空行不检测
     //检测model
     $arr1 = $model = IProductBase::find()->where($attribute . " != :string", [':string' => ""])->all();
     foreach ($arr1 as $k => $v) {
         $real = Yii::getAlias("@frontend/web/" . $v[$attribute]);
         $real = str_replace("\\", "/", $real);
         $orange = $real . ".jpg";
         if (file_exists($orange)) {
             $row = $v['id'] . "--图片存在";
         } else {
             $row = $v['id'] . "--|不存在该图片|--" . $v[$attribute];
         }
         if ($thumb) {
             $thumbPath = $real . ".thumb_312x196.jpg";
             if (file_exists($thumbPath)) {
                 $row .= "--缩略图yes--";
             } else {
                 $row .= "--缩略图no--";
             }
         }
         echo $row . "\n";
     }
 }
示例#8
0
 /**
  * 获取分页数据  ----暂未使用,
  *
  * @param int $pager 当前页
  * @param boolean $isExecute 是否执行查询
  *
  * @return ActiveRecord
  */
 public function getFounderPage($pager = 1, $isExecute = true)
 {
     $result;
     //查询审核通过的产品的用户uid集合
     $puids = IProductBase::find()->select('uid')->distinct()->where('uid > 0 and status=' . IProductBase::STATUS_VERIFEND)->asArray()->all();
     foreach ($puids as $key => $value) {
         $ids[] = $value['uid'];
     }
     if (empty($ids) || !is_array($ids)) {
         return $result;
     }
     $startnum = ($pager - 1) * self::PAGE_SIZE;
     $result = self::find()->select(['uid', 'username', 'nickname', 'truename', 'avatar', 'province', 'city', 'update_at'])->where(['uid' => $puids, 'is_del' => self::STATUS_MEMBERIS_DEL])->with(['iproduct' => function ($query) {
         return $query->select(['id', 'title', 'album', 'uid'])->where(['status' => IProductBase::STATUS_VERIFEND])->orderBy(['update_time' => SORT_DESC]);
     }])->with(['memberstar' => function ($query) {
         return $query->select(['uid', 'follow_num', 'pfollow_allnum']);
     }])->with(['province' => function ($query) {
         return $query->select(['id', 'name']);
     }])->with(['city' => function ($query) {
         return $query->select(['id', 'name']);
     }])->offset($startnum)->limit(self::PAGE_SIZE)->orderBy(['uid' => SORT_DESC]);
     if ($isExecute == true) {
         $result = $result->asArray()->all();
     }
     return $result;
 }
示例#9
0
 /**
  * 产品更新 [发布/修改/预览]
  * @param  [int] $id [产品id]
  * @return  [array] $product [产品相关信息]
  * @return  [int] $id [产品id]
  * @return  [string] $url [地址]
  * @return  [string] $formhash [哈希值验证]
  */
 public function actionRenew()
 {
     $form = Yii::$app->request->post('extra');
     // print_r($form);exit;
     //获取hash值
     $formhash = Yii::$app->request->post('formhash', false);
     $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;
     }
     //formhash验证
     if (!PublicLibrary::verifyFormhash($formhash)) {
         echo '<script>alert("非法提交!");window.history.back(-1);</script>';
         exit;
     }
     if (empty($form['apply_role']) || empty($form['user_oriented_age'])) {
         echo '<script>alert("代言角色和面向群体都不能为空!");window.history.back(-1);</script>';
         exit;
     }
     if (isset($form)) {
         if (empty($form['summary']) || empty($form['name'])) {
             echo '<script>alert("产品名和简介都不能为空!");window.history.back(-1);</script>';
             exit;
         } else {
             //上传封面图片
             if ($_FILES['album']['name'] != '') {
                 if ($_FILES['album']['size'] > ProductImage::MAX_SIZE || $_FILES['album']['error'] != 0) {
                     echo '<script>alert("封面图片格式不对或大于1M!");window.history.back(-1);</script></script>';
                     exit;
                 }
             }
             //album图片上传
             $album = UploadedFile::getInstanceByName('album');
             //试取图片album
             if ($album !== null) {
                 //判断图片大小是否符合规定
                 if ($album->size > ProductImage::MAX_SIZE || $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;
                     //封面图路径
                 }
                 $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->save();
             }
             //上传封面图片结束
             //banner1上传
             $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->pos_id = 1;
                     $model->save();
                 }
             }
             //图片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();
             }
             //banner1上传结束
             //banner2上传
             if ($_FILES['bigbanner2']['name'] != '') {
                 if ($_FILES['bigbanner2']['size'] > 1048576 * 2 || $_FILES['bigbanner2']['error'] != 0) {
                     echo '<script>alert("通栏第二张图片格式不对或大于2M!");window.history.back(-1);</script></script>';
                     exit;
                 }
             }
             //图片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 = intval($form['id']);
                     $model->url = $bannerPath;
                     $model->create_time = time();
                     $model->pos_id = 2;
                     $model->save();
                 }
             }
             //banner2上传结束
             //banner3上传
             if ($_FILES['bigbanner3']['name'] != '') {
                 if ($_FILES['bigbanner3']['size'] > 1048576 * 2 || $_FILES['bigbanner3']['error'] != 0) {
                     echo '<script>alert("通栏第三张图片格式不对或大于2M!");window.history.back(-1);</script></script>';
                     exit;
                 }
             }
             //图片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 = intval($form['id']);
                     $model->url = $bannerPath;
                     $model->create_time = time();
                     $model->pos_id = 3;
                     $model->save();
                 }
             }
             //banner3上传结束
             //对i_product_base表的修改
             //年龄段的处理
             $age = isset($form['user_oriented_age']) ? $form['user_oriented_age'] : array();
             if (!$age) {
                 $age_nums = 0;
             } else {
                 $age_nums = array_sum($age);
             }
             $IProductBase = new IProductBase();
             //状态判断
             $act = Yii::$app->request->get();
             //判断产品是的状态
             $res = IProductBase::find()->select('status')->where('id = :id', [':id' => $form['id']])->asArray()->one();
             $session = Yii::$app->session;
             $session->isActive ? '' : $session->open();
             $MemberStat = new MemberStat();
             if (!empty($act['act'])) {
                 if ($act['act'] == 'save') {
                     //点击保存
                     if ($res['status'] == IProductBase::STATUS_VERIFEND) {
                         //去过是发布状态 用户统计表产品减一
                         $MemberStat->decr($session['user']['uid'], 'product_num');
                     }
                     $status = IProductBase::STATUS_VERIFING;
                 } elseif ($act['act'] == 'view') {
                     //点击预览
                     if ($res['status'] != IProductBase::STATUS_VERIFEND) {
                         $status = IProductBase::STATUS_INVALID;
                         //保持预览状态
                     } else {
                         $status = IProductBase::STATUS_VERIFEND;
                         //过去是发布状态,保持原状态
                     }
                 }
             } else {
                 if ($res['status'] != IProductBase::STATUS_VERIFEND) {
                     //去过不是发布状态 用户统计表产品加一
                     $MemberStat->incr($session['user']['uid'], 'product_num');
                 }
                 $status = IProductBase::STATUS_VERIFEND;
             }
             $datab = ['id' => intval($form['id']), 'type' => intval($form['tid']), 'apply_role' => intval($form['apply_role']), 'user_oriented_gender' => intval($form['user_oriented_gender']), 'user_oriented_age' => $age_nums, 'name' => strip_tags($form['name']), 'price' => strip_tags($form['price']), 'province' => strip_tags($form['province']), 'city' => strip_tags($form['city']), 'status' => $status, 'update_time' => time()];
             $base = $IProductBase->store($datab);
             if (!$base) {
                 echo '<script>alert("非法提交!");window.history.back(-1);</script>';
                 exit;
             }
             $detaile = PublicLibrary::msg_safe($form['detail']);
             //对i_product_extra表的插入或修改
             $data = ['product_id' => intval($form['id']), 'summary' => strip_tags($form['summary']), 'video_url' => strip_tags($form['video_url']), 'detail' => $detaile, 'update_time' => time()];
             $IProductExtra = new IProductExtra();
             $extra = $IProductExtra->store($data);
             if (!$extra) {
                 echo '<script>alert("非法提交!");window.history.back(-1);</script>';
                 exit;
             }
             $session = Yii::$app->session;
             $session->isActive ? '' : $session->open();
             if (!empty($act['act']) && $act['act'] == 'view') {
                 return $this->redirect(['product/view', 'id' => $form['id']]);
                 //跳转到产品详细页
             } else {
                 return $this->redirect(['home-page/lists', 'uid' => $_SESSION['user']['uid'], 'pid' => $form['id']]);
                 //跳转到个人中心
             }
         }
     } else {
         echo '<script>alert("非法提交!");window.history.back(-1);</script>';
         exit;
     }
 }