114 lines
4.1 KiB
PHP
114 lines
4.1 KiB
PHP
![]() |
<?php
|
||
|
namespace app\controllers\channel;
|
||
|
use Illuminate\Support\Facades\DB;
|
||
|
use Yii;
|
||
|
use yii\web\Controller;
|
||
|
use app\models\common\Store;
|
||
|
use app\models\common\Voice;
|
||
|
class VoiceController extends CommonController{
|
||
|
public $enableCsrfValidation = false;
|
||
|
private $shop_id;
|
||
|
public function init(){
|
||
|
parent::init();
|
||
|
$this->shop_id=$this->storeId?:Store::getMainStore($this->wqData['uniacid'])['id'];
|
||
|
$this->shop_id=$this->shop_id?:0;
|
||
|
}
|
||
|
public function actionVoiceList(){
|
||
|
$page=Yii::$app->request->get('page')?Yii::$app->request->get('page'):1;
|
||
|
$num=($page-1)*10;
|
||
|
$limit=10;
|
||
|
$result=axios_request();
|
||
|
$storeId=$result['storeId']?:Store::getMainStore($this->wqData['uniacid'])['id'];
|
||
|
$where=array(
|
||
|
'deleteAt'=>0,
|
||
|
'uniacid'=>$this->wqData['uniacid'],
|
||
|
'storeId'=>$storeId,
|
||
|
);
|
||
|
$data= (new \yii\db\Query())
|
||
|
->from('{{%ybwm_voice_notice}}')
|
||
|
->where($where)
|
||
|
->offset($num)
|
||
|
->limit($limit)
|
||
|
->orderBy('id desc')
|
||
|
->all();
|
||
|
foreach ($data as &$v){
|
||
|
$v['message']=json_decode($v['message'],true);
|
||
|
}
|
||
|
$count=(new \yii\db\Query()) ->from('{{%ybwm_voice_notice}}')->where($where)->count();
|
||
|
//dd($data);die;
|
||
|
return $this->result(1,'成功',$data,$count);
|
||
|
}
|
||
|
public function actionVoiceSave(){
|
||
|
$result=axios_request();
|
||
|
$request = Yii::$app->request;
|
||
|
if($request->isGet){
|
||
|
$query=(new \yii\db\Query())
|
||
|
->from('{{%ybwm_voice_notice}}')
|
||
|
->where(['id'=>$result['id']])
|
||
|
->one();
|
||
|
$query['message']=json_decode($query['message'],true);
|
||
|
return $this->result(1,'成功',$query);
|
||
|
}
|
||
|
if($request->isPost){
|
||
|
$storeId=$result['storeId']?:$this->shop_id;
|
||
|
$data=array(
|
||
|
'type'=>$result['type'],
|
||
|
'message'=>json_encode($result['message']),
|
||
|
'uniacid'=>$this->wqData['uniacid'],
|
||
|
'storeId'=>$storeId,
|
||
|
'createdAt'=>time(),
|
||
|
);
|
||
|
$where=['storeId'=>$storeId,'type'=>$result['type'],'deleteAt'=>0];
|
||
|
$data=filter_array($data);
|
||
|
$query=(new \yii\db\Query())
|
||
|
->from('{{%ybwm_voice_notice}}')
|
||
|
->where($where);
|
||
|
if($result['id']){
|
||
|
$query=$query->andWhere(['<>','id', $result['id']]);
|
||
|
}
|
||
|
$res= $query->one();
|
||
|
if($res){
|
||
|
return $this->result(2,'通知类型不可重复');
|
||
|
}
|
||
|
|
||
|
if($result['id']){
|
||
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_voice_notice}}', $data, ['id'=>$result['id']])->execute();
|
||
|
}else{
|
||
|
|
||
|
$re = YII::$app->db->createCommand()->insert('{{%ybwm_voice_notice}}', $data)->execute();
|
||
|
}
|
||
|
if($re){
|
||
|
return $this->result(1,'成功');
|
||
|
}else{
|
||
|
return $this->result(2,'操作失败');
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function actionVoiceDel(){
|
||
|
$request = Yii::$app->request;
|
||
|
if($request->isPost){
|
||
|
$id=axios_request()['id'];
|
||
|
if(is_array($id)){
|
||
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_voice_notice}}', ['deleteAt'=>time()], ['in','id',$id])->execute();
|
||
|
}else{
|
||
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_voice_notice}}', ['deleteAt'=>time()], ['id'=>$id])->execute();
|
||
|
}
|
||
|
return $this->result(1,'成功');
|
||
|
}
|
||
|
|
||
|
}
|
||
|
public function actionAudition(){
|
||
|
$result=axios_request();
|
||
|
$storeId=$result['storeId']?:$this->shop_id;
|
||
|
$result=Voice::noticeVoice($this->wqData['uniacid'],$storeId,$result['type'],0,0,$result['message']);
|
||
|
//var_dump($result);die;
|
||
|
if(json_decode($result,true)['errcode']==0){
|
||
|
return $this->result(1,'成功');
|
||
|
}else{
|
||
|
return $this->result(2,'失败',json_decode($result,true)['errmsg']);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|