78 lines
2.7 KiB
PHP
78 lines
2.7 KiB
PHP
<?php
|
|
namespace app\controllers\channel;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Yii;
|
|
class AdController extends CommonController{
|
|
//广告列表
|
|
public function actionAdList(){
|
|
$result=axios_request();
|
|
$page=$result['page']?:1;
|
|
$num=($page-1)*10;
|
|
$limit=10;
|
|
$table=(new \yii\db\Query())
|
|
->select('id,name,icon,from_unixtime(createdAt) createdAt,display,sort')
|
|
->from('{{%ybwm_core_ad}}')
|
|
->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid'],'location'=>$result['location']]);
|
|
$list=$table
|
|
->offset($num)
|
|
->limit($limit)
|
|
->orderBy('id desc')
|
|
->all();
|
|
$count=$table->count();
|
|
return $this->result(1, '成功',$list,$count);
|
|
}
|
|
//保存广告
|
|
public function actionSaveAd(){
|
|
$result=axios_request();
|
|
$request = Yii::$app->request;
|
|
if($request->isGet){
|
|
$info=(new \yii\db\Query())
|
|
->from('{{%ybwm_core_ad}}')
|
|
->where('id=:id',[':id'=>$result['id']])->one();
|
|
return $this->result(1, '成功',$info);
|
|
}
|
|
if(!$result['name']){
|
|
return $this->result(2,'广告名称不能为空!');
|
|
}
|
|
if(!$result['icon']){
|
|
return $this->result(2,'广告图片不能为空!');
|
|
}
|
|
$data['name']=$result['name'];
|
|
$data['icon']=$result['icon'];
|
|
$data['display']=$result['display'];
|
|
$data['sort']=$result['sort'];
|
|
$data['location']=$result['location'];
|
|
if($result['id']){
|
|
$data['changeAt']=time();
|
|
$re = Yii::$app->db->createCommand()->update('{{%ybwm_core_ad}}', $data, 'id=:id', ['id' =>$result['id']])->execute();
|
|
}else{
|
|
$data['uniacid']=$this->wqData['uniacid'];
|
|
$data['createdAt']=time();
|
|
$re=Yii::$app->db->createCommand()->insert('{{%ybwm_core_ad}}', $data)->execute();
|
|
}
|
|
if($re){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
//修改广告
|
|
public function actionModifyAd(){
|
|
$post=axios_request();
|
|
if($post['type']==1){
|
|
//显示隐藏
|
|
$data['display']=$post['display'];
|
|
}
|
|
if($post['type']==2){
|
|
//删除
|
|
$data['deleteAt']=time();
|
|
}
|
|
$data['changeAt']=time();
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_core_ad}}', $data, 'id=:id', ['id' =>$post['id']])->execute();
|
|
if($res){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
} |