| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace backend\controllers;
- use common\services\xhArticleService;
- use Yii;
- use yii\web\Controller;
- use yii\filters\AccessControl;
- use yii\helpers\Json;
- use yii\data\Pagination;
- use common\components\qrCodeUtil;
- use common\components\util;
- use common\models\xhArticle;
- use common\services\xhCategoryService;
- use common\services\xhArticleCategoryService;
- class ArticleController extends BackendController
- {
- /**
- * 文章管理
- */
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $query = xhArticle::find();
- $aId = $this->adminId;
- $status = isset($get['status']) ? $get['status'] : -1;
- $query->where(['merchantId' =>$this->merchantId]);
- if(isset($get['status']) && $get['status'] != -1){
- $query->andWhere(['status' => $get['status']]);
- }
- if(isset($get['title']) && !empty($get['title'])){
- $query->andWhere(['like', 'title', $get['title']]);
- }
- $query->orderBy('id desc');
- $countQuery = clone $query;
- $pages = new Pagination(['totalCount' => $countQuery->count(),'pageSize' => 20]);
- $models = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all();
- return $this->render('list', ['models' => $models,'pages' => $pages,'status' => $status]);
- }
- public function actionAdd()
- {
- //取分类
- $categoryList = xhCategoryService::getAll($this->merchantId,1);
- return $this->render('add',['categoryList' => $categoryList]);
- }
- public function actionSaveAdd()
- {
- $post = Yii::$app->request->post();
- $date = date("Y-m-d H:i:s");
- $post['createTime'] = $date;
- $post['merchantId'] = $this->merchantId;
- xhArticleService::addByAdmin($post);
- util::successInfo('添加成功!');
- }
- public function actionEdit()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $article = xhArticleService::getById($id);
- if(empty($article) || $article['merchantId'] != $this->merchantId){
- util::stop('非法访问');
- }
- $articleCategory = xhArticleCategoryService::getCategoryByArticleId($id);
- $categoryList = xhCategoryService::getAll($this->merchantId,1);
- return $this->render('edit',['categoryList' => $categoryList,'article' => $article,'articleCategory' => $articleCategory]);
- }
- public function actionSaveEdit()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'];
- $post['merchantId'] = $this->merchantId;
- unset($post['_csrf']);
- xhArticleService::updateAllById($id,$post,$this->merchantId);
- util::successInfo('修改成功!');
- }
- /**
- * 生成文章的二维码地址
- */
- public function actionShowArticleQrcode()
- {
- $get = Yii::$app->request->get();
- $id = isset($get['id']) ? $get['id'] : 0;
- $url = Yii::$app->params['frontUrl'].'/article/article-detail?id='.$id.'&account='.$this->merchant['id'];
- $merchantId = $this->merchantId;
- $article = xhArticle::getById($id);
- if(empty($article)){
- util::failInfo();
- }
- $logo = Yii::getAlias("@app").'/../images'.$this->merchant['logo'];//取商家的logo
- $imgUrl = qrCodeUtil::generate($url,'backend_article_url_'.$merchantId.'_'.$id,$logo);
- xhArticleService::updateById($id, ['urlQrCode'=>$imgUrl]);
- util::successInfo('success','A0001',['url' => $imgUrl]);
- }
- }
|