53 lines
1.7 KiB
PHP
53 lines
1.7 KiB
PHP
<?php
|
|
namespace app\controllers\merchantApi;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Yii;
|
|
use yii\web\Controller;
|
|
class CommonController extends Controller{
|
|
public $enableCsrfValidation = false;
|
|
protected $wqData=[];
|
|
private $typeInfo = array(
|
|
'mini' => 1,
|
|
'weChat' => 2,
|
|
'ali' => 3,
|
|
'baidu' => 4,
|
|
'h5' => 5,
|
|
'pc' => 6,
|
|
'toutiao' => 7,
|
|
);
|
|
function init(){
|
|
parent::init();
|
|
$this->wqData['uniacid'] = Yii::$app->request->headers->get('uniacid');
|
|
if(Yii::$app->params['isDev']==false) {
|
|
$apply = (new \yii\db\Query())
|
|
->from('{{%ybwm_apply}}')
|
|
->where('id=:id AND status=1 AND end_time>:end_time', [':id' => $this->wqData['uniacid'], ':end_time' => time()])->one();
|
|
if (!$apply) {
|
|
echo json_encode([
|
|
'code' => 2,
|
|
'msg' => '平台不存在或已过期'
|
|
]);
|
|
exit();
|
|
}
|
|
}
|
|
$this->wqData['module'] = Yii::$app->request->headers->get('module');
|
|
$this->wqData['appType'] = $this->typeInfo[Yii::$app->request->headers->get('appType')];//应用类型
|
|
$this->wqData['userId'] = Yii::$app->request->headers->get('userId');//应用类型
|
|
if (!$this->wqData['uniacid'] || !$this->wqData['appType']) {
|
|
echo json_encode([
|
|
'code' => 2,
|
|
'msg' => '非法请求'
|
|
]);
|
|
exit();
|
|
}
|
|
}
|
|
public function result($code=1,$msg='成功',$data=[],$count=null){
|
|
return json_encode([
|
|
'code'=>$code,
|
|
'msg'=>$msg,
|
|
'data'=>$data,
|
|
'count'=>(int)$count
|
|
]);
|
|
}
|
|
}
|