1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace backend\controllers;
- use common\models\ApiShare;
- use common\models\Share;
- use yii;
- use yii\filters\AccessControl;
- /**
- * 推广管理
- * @package backend\controllers
- */
- class ShareController extends BaseController
- {
- public $layout = 'iframe';
- const PAGESIZE = 20;//分页数
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'actions' => [],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- ],
- ],
- ];
- }
- /**
- *列表
- * @return string
- */
- public function actionIndex()
- {
- $search =['start'=>'','end'=>'','role'=>''];
- $search['start'] = Yii::$app->request->get('start');
- $search['end'] = Yii::$app->request->get('end');
- $search['role'] = Yii::$app->request->get('role');
- $models = Share::find()->where(['status'=>Share::STATUS_YES]);
- if(!empty($search['start']))
- $models->andWhere("c_time > :start",[':start'=>strtotime($search['start'])]);
- if(!empty($search['end']))
- $models->andWhere("c_time < :end",[':end'=>strtotime($search['end'])+(3600*24-1)]);
- if($search['role']!='')
- $models->andWhere("role = :role",[':role'=>$search['role']]);
- $pages = new yii\data\Pagination(["totalCount" => $models->count(), "pageSize" => self::PAGESIZE]);
- $models = $models->offset($pages->offset)->limit($pages->limit)->orderBy("id DESC")->all();
- return $this->render('index', ['models' => $models, 'pages' => $pages,'name'=>'免费报价列表','search'=>$search]);
- }
- /**
- * 删除推广信息
- */
- public function actionDel()
- {
- $id = Yii::$app->request->post('id');
- $model = Share::find()->where(['id'=>$id])->one();
- $result = ['sign'=>1,'msg'=>'删除成功'];
- if(!empty($model))
- {
- $model->status = Share::STATUS_NO;
- if(!$model->save())
- $result= ['sign'=>0,'msg'=>'删除失败'];
- }else{
- $result= ['sign'=>0,'msg'=>'找不到该记录'];
- }
- return json_encode($result);
- }
- /**
- * 小程序推荐列表
- */
- public function actionApiList()
- {
- $models = ApiShare::find();
- $pages = new yii\data\Pagination(["totalCount" => $models->count(), "pageSize" => self::PAGESIZE]);
- $models = $models->with("user")->with('suser')->offset($pages->offset)->limit($pages->limit)->orderBy("id DESC")->all();
- return $this->render('apilist',['name'=>'推荐列表','models'=>$models,'pages' => $pages]);
- }
- }
|