189 lines
4.3 KiB
PHP
189 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Collect;
|
|
|
|
|
|
|
|
use App\Models\MerchantLog;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Route;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Validator;
|
|
use AnyUpload;
|
|
use DB;
|
|
|
|
class BaseController extends Controller
|
|
{
|
|
//
|
|
const ADMIN_BLADE_DIR='collect.';
|
|
public $title='采集';
|
|
public $route=[];
|
|
public $pages=[];
|
|
public $model;
|
|
public $share_view=[];
|
|
public $guard_name='';
|
|
public $dblast_id='';
|
|
public $merchant_id;
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
$route_arr=explode('@', Route::currentRouteAction());
|
|
$this->route['controller_name']='\\'.$route_arr[0];
|
|
$this->route['action_name']=$route_arr[1];
|
|
$this->route['controller_base']=str_replace('Controller','',str_replace('App\\Http\\Controllers\\Collect\\','',$route_arr[0]));
|
|
$this->route['blade']=self::ADMIN_BLADE_DIR.strtolower($this->route['controller_base']).'.'.$this->route['action_name'];
|
|
$this->share_view['controller']="\\".$this->route['controller_name'];
|
|
|
|
$this->title=ucwords($this->route['action_name']);
|
|
$this->share_view['title']=$this->title;
|
|
//$this->handleUrl();
|
|
$this->getTable();
|
|
$this->share_view['action_name']=$this->route['action_name'];
|
|
$this->share_view['page']=$this->pages;
|
|
$this->setTitle('采集');
|
|
$this->shareView();
|
|
|
|
|
|
}
|
|
|
|
public function alertError($error_str,$status=1){
|
|
return response()->json( ['error'=>$status,'msg'=>$error_str,'type'=>'validator']);
|
|
}
|
|
|
|
|
|
/**
|
|
* 共享视图资源
|
|
* @return mixed
|
|
*/
|
|
public function shareView(){
|
|
|
|
return view()->share($this->share_view);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* 设置页面标题
|
|
* @param string $title
|
|
*/
|
|
protected function setTitle($title=''){
|
|
$title=$title?$title:$this->pages['name'];
|
|
$this->share_view['title']=$title;
|
|
}
|
|
|
|
|
|
/**
|
|
* 改变自动获取blade
|
|
* @param $path
|
|
* @param int $cover 是否完全覆盖
|
|
* @param int $is_seft 是否在当前的控制下目录
|
|
* @return string
|
|
*/
|
|
protected function setViewPath($path='',$filename='',$cover=0,$is_seft=1)
|
|
{
|
|
if($cover){
|
|
return $this->route['blade']=$path;
|
|
}
|
|
if($is_seft==0)
|
|
{
|
|
return $this->route['blade']=self::ADMIN_BLADE_DIR.$path;
|
|
}
|
|
if($filename!='')
|
|
{
|
|
$this->route['action_name']=$filename;
|
|
}
|
|
if($path)
|
|
{
|
|
return $this->route['blade']=self::ADMIN_BLADE_DIR.$this->route['action_name']=$path.".".$this->route['action_name'];
|
|
}
|
|
return $this->route['blade']=self::ADMIN_BLADE_DIR.strtolower($this->route['controller_base']).'.'.$this->route['action_name'];
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* 取得table
|
|
* @return string
|
|
*/
|
|
protected function getTable(){
|
|
if(gettype($this->setModel())!='object')
|
|
{
|
|
$table='';
|
|
}else
|
|
{
|
|
$table=$this->setModel()->getTable();
|
|
}
|
|
$this->share_view['table_name']=$table;
|
|
$this->shareView();
|
|
return $table;
|
|
}
|
|
|
|
|
|
/**
|
|
* 本页面操作的模型
|
|
*/
|
|
protected function setModel(){
|
|
|
|
}
|
|
|
|
protected function getShow($id){
|
|
$show=$this->setModel()->find($id);
|
|
if(!$show)
|
|
{
|
|
return abort(404);
|
|
}
|
|
view()->share('show',$show);
|
|
|
|
return $this->display($this->shareData($show));
|
|
}
|
|
/**
|
|
* 输出视图
|
|
* @param array $data
|
|
* @return mixed
|
|
*/
|
|
public function display($data=[]){
|
|
|
|
return view($this->route['blade'],$data);
|
|
}
|
|
|
|
public function jsonDebug($json){
|
|
print_r($json);
|
|
|
|
return '';
|
|
}
|
|
|
|
|
|
public function indexData(){
|
|
return [];
|
|
}
|
|
|
|
|
|
//共享创建和编辑数据
|
|
protected function shareData($id=''){
|
|
|
|
return [];
|
|
}
|
|
|
|
public function errorJosn($msg){
|
|
return ['error'=>1,'msg'=>$msg];
|
|
}
|
|
|
|
|
|
|
|
public function jsonMsg($error,$str){
|
|
return response()->json(['error'=>$error,'msg'=>$str]);
|
|
}
|
|
/*********基本控制器资源设置*********/
|
|
|
|
public function __call($method, $parameters)
|
|
{
|
|
|
|
return abort('401',$method.'方法不存在');
|
|
}
|
|
|
|
}
|
|
|