143 lines
3.3 KiB
PHP
143 lines
3.3 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
*
|
|
*
|
|
*
|
|
* Date: 2021/9/22
|
|
* Time: 13:37
|
|
*/
|
|
|
|
namespace business\common\controllers\components;
|
|
|
|
use app\common\exceptions\AppException;
|
|
|
|
use app\common\exceptions\ShopException;
|
|
use app\common\facades\Setting;
|
|
use app\common\middleware\BasicInformation;
|
|
use app\common\middleware\SingleLogin;
|
|
use app\common\services\Check;
|
|
use app\common\services\PermissionService;
|
|
use app\common\services\Session;
|
|
|
|
use app\common\services\Utils;
|
|
use app\common\traits\JsonTrait;
|
|
use app\common\traits\MessageTrait;
|
|
use app\common\traits\PermissionTrait;
|
|
use app\common\traits\TemplateTrait;
|
|
use app\platform\modules\system\models\SystemSetting;
|
|
use business\common\services\SettingService;
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
/**
|
|
* controller基类
|
|
*
|
|
* Author:
|
|
* Date: 21/02/2017
|
|
* Time: 21:20
|
|
*/
|
|
class BaseController extends Controller
|
|
{
|
|
use DispatchesJobs, MessageTrait, ValidatesRequests, TemplateTrait, PermissionTrait, JsonTrait;
|
|
|
|
const SESSION_EXPIRE = 2160000;
|
|
|
|
/**
|
|
* controller中执行报错需要回滚的action数组
|
|
* @var array
|
|
*/
|
|
public $transactionActions = [];
|
|
|
|
public $apiErrMsg = [];
|
|
|
|
public $apiData = [];
|
|
|
|
protected $isPublic = false;
|
|
|
|
public $business_id;
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
$this->setCookie();
|
|
}
|
|
|
|
public function preAction()
|
|
{
|
|
$this->business_id = SettingService::getBusinessId();
|
|
}
|
|
|
|
protected function formatValidationErrors(Validator $validator)
|
|
{
|
|
return $validator->errors()->all();
|
|
}
|
|
|
|
public function callAction($method, $parameters)
|
|
{
|
|
if (method_exists($this, 'preAction')) {
|
|
call_user_func_array([$this, 'preAction'], $parameters);
|
|
}
|
|
return parent::callAction($method, $parameters); // TODO: Change the autogenerated stub
|
|
}
|
|
|
|
public function getIgnoreAction()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function getPublicAction()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* url参数验证
|
|
*
|
|
* @param array $rules
|
|
* @param Request|null $request
|
|
* @param array $messages
|
|
* @param array $customAttributes
|
|
*
|
|
* @throws AppException
|
|
*/
|
|
public function validate(array $rules, Request $request = null, array $messages = [], array $customAttributes = [])
|
|
{
|
|
if (!isset($request)) {
|
|
$request = request();
|
|
}
|
|
$validator = $this->getValidationFactory()->make($request->all(), $rules, $messages, $customAttributes);
|
|
|
|
if ($validator->fails()) {
|
|
throw new AppException($validator->errors()->first());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 设置Cookie存储
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function setCookie()
|
|
{
|
|
$session_id = '';
|
|
|
|
if (isset($_COOKIE[session_name()])) {
|
|
$session_id = $_COOKIE[session_name()];
|
|
}
|
|
|
|
if (empty($session_id)) {
|
|
$session_id = md5(\YunShop::app()->uniacid . ':' . random(20));
|
|
setcookie(session_name(), $session_id);
|
|
}
|
|
|
|
session_id($session_id);
|
|
Session::factory(\YunShop::app()->uniacid);
|
|
}
|
|
|
|
|
|
}
|