87 lines
2.9 KiB
PHP
Executable File
87 lines
2.9 KiB
PHP
Executable File
<?php
|
||
|
||
# @Author: 嗨噜客(三亚) <fm453>
|
||
# @Date: 2022-04-15 20:22:03
|
||
# @Email: fm453@lukegzs.com
|
||
# @Last modified by: fm453
|
||
# @Last modified time: 2024-07-08T15:48:08+08:00
|
||
# @Copyright: www.hiluker.cn
|
||
//管理员用户入口
|
||
|
||
namespace backend\controllers;
|
||
|
||
use Yii;
|
||
use common\models\Member as User;
|
||
use addons\models\AcUserExt;
|
||
use addons\models\AcStore;
|
||
use addons\models\AcEmployee;
|
||
use yii\web\Controller;
|
||
|
||
class Common extends Controller
|
||
{
|
||
protected $pid = 0;
|
||
protected $user_id = 0;
|
||
protected $site_id = 0;
|
||
protected $store_id = 0;
|
||
protected $employee_id = 0;
|
||
protected $user_info;
|
||
protected $postdata = []; //重新整理一下客户端传输的数据
|
||
protected $imgHttp = true; //图片附件地址生成http(s) //false:不生成http网址; true:仅生成http网址; https:生成https网址
|
||
protected $page = 1; //当前数据分页
|
||
protected $pageSize = 10; //默认数据分页大小
|
||
public $enableCsrfValidation = false;
|
||
//替代常规的_construct 析构函数;其他方法调用前执行
|
||
|
||
public function init()
|
||
{
|
||
parent::init();
|
||
//判断请求内容类型 content-type,支持 json请求
|
||
$postdata = Yii::$app->request->post();
|
||
$headers = Yii::$app->request->headers;
|
||
$contentType = $headers->get('content-type');
|
||
if ($contentType=="application/json") {
|
||
$postdata = json_decode(file_get_contents('php://input'), true);
|
||
}
|
||
$this->postdata = $postdata;
|
||
$session = Yii::$app->session;
|
||
if (isset($postdata['pid'])) {
|
||
if ((int)$postdata['pid']>0) {
|
||
$this->pid = (int)$postdata['pid'];
|
||
$session->set('pid', $this->pid);
|
||
} else {
|
||
$session->set('pid', 0);
|
||
}
|
||
} else {
|
||
$session->set('pid', 0);
|
||
}
|
||
$this->site_id = Yii::$app->params['siteId'];
|
||
if (isset($postdata['user_id']) && (int)$postdata['user_id']>0) {
|
||
$this->user_id = (int)$postdata['user_id'];
|
||
}
|
||
$userModel = new User();
|
||
if ($this->user_id) {
|
||
$res = $userModel->findOne($this->user_id);
|
||
$this->user_info = $res;
|
||
}
|
||
if (isset($postdata['employee_id']) && (int)$postdata['employee_id']>0) {
|
||
$this->employee_id = (int)$postdata['employee_id'];
|
||
}
|
||
|
||
$page = isset($postdata['page']) ? (int)$postdata['page'] : 1;
|
||
$this->page = $page<=0 ? 1 : $page;
|
||
$pageSize = isset($postdata['psize']) ? (int)$postdata['psize'] : 10;
|
||
$this->pageSize = $pageSize<=0 ? 10 : $pageSize;
|
||
}
|
||
|
||
public function result($msg, $data=null, $code=0)
|
||
{
|
||
$return = [];
|
||
$return['code'] = $code;
|
||
$return['msg'] = $msg;
|
||
if ($data) {
|
||
$return['data'] = $data;
|
||
}
|
||
exit(json_encode($return, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT));
|
||
}
|
||
}
|