Commit 062ac947 by mushishixian

优化

parent fbf63ae9
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -36,7 +36,7 @@ class CheckLogin
$cookie = 'oa_user_id=' . $userId . '; oa_skey=' . $skey;
$rsp=curls($login['check'],'',false,false,$cookie);
$rsp=curl($login['check'],'',false,false,$cookie);
if (!$rsp) {
......
<?php
function apiReturn($errcode=0,$errmsg='ok',$datas=[]){
function apiReturn($errCode = 0, $errMsg = 'ok', $data = [])
{
$data = [
'errcode' => $errcode,
'errmsg' => $errmsg,
'code' => $errcode,
'msg' => $errmsg,
'err_code' => $errCode,
'err_msg' => $errMsg,
'code' => $errCode,
'msg' => $errMsg,
];
if(!empty($datas['total'])){
$data['count'] = $datas['total'];
if (!empty($data['total'])) {
$data['count'] = $data['total'];
}
if(!empty($datas)){
foreach ($datas as $k=>$v){
if (!empty($data)) {
foreach ($data as $k => $v) {
$data[$k] = $v;
}
}
return response()->json($data,200);
return response()->json($data, 200);
}
function curls($url, $params = false, $ispost = 0, $https = 0,$cookie='',$timeout=1000)
function curl($url, $params = false, $isPost = 0, $https = 0, $cookie = '', $timeout = 1000)
{
$httpInfo = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36');
curl_setopt($ch, CURLOPT_USERAGENT,
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch,CURLOPT_REFERER,Config('website.data'));
curl_setopt($ch, CURLOPT_REFERER, Config('website.data'));
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 对认证证书来源的检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在
if ($ispost) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
if ($isPost) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_URL, $url);
......@@ -48,102 +49,109 @@ function curls($url, $params = false, $ispost = 0, $https = 0,$cookie='',$timeou
}
$response = curl_exec($ch);
if ($response === FALSE) {
if ($response === false) {
echo "cURL Error: " . curl_error($ch);
return false;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$httpInfo = array_merge($httpInfo, curl_getinfo($ch));
curl_close($ch);
return $response;
}
//检查权限,仅支持验证单个权限
function perm($userId,$perm1=''){
$permArr=config('perm.perm');
$NotAuth=$permArr['notAuth'];
$AdminID=$permArr['adminGroup'];
if((!in_array($perm1,$NotAuth)) && !in_array($userId,$AdminID)) {//过滤不用鉴权的方法与用户
function perm($userId, $perm1 = '')
{
$permArr = config('perm.perm');
$NotAuth = $permArr['notAuth'];
$AdminID = $permArr['adminGroup'];
if ((!in_array($perm1, $NotAuth)) && !in_array($userId, $AdminID)) {//过滤不用鉴权的方法与用户
$permID = $permArr['id'];
$url = $permArr['url'] . '/' . $userId . '/' . $permID . '?perms=' . $perm1;
$result = json_decode(curl($url, '', 0),true);
if(!isset($result['retcode']) || $result['retcode']!==0 || $result['data']['perms'][$perm1]==false){
$result = json_decode(curl($url, '', 0), true);
if (!isset($result['retcode']) || $result['retcode'] !== 0 || $result['data']['perms'][$perm1] == false) {
return false;
}else{
} else {
return true;
}
}else{
} else {
return true;
}
}
//根据权限生成菜单
function menu($menu,$user){
$perm=chils($menu);
$perm1=implode(',',$perm);
$permArr=config('perm.perm');
$perm=$permArr['id'];
function menu($menu, $user)
{
$perm = chils($menu);
$perm1 = implode(',', $perm);
$permArr = config('perm.perm');
$perm = $permArr['id'];
$url=$permArr['url'].'/'.$user.'/'.$perm.'?perms='.$perm1;
$result=json_decode(curl($url,'',false),true);
if($result['retcode']===0){
$url = $permArr['url'] . '/' . $user . '/' . $perm . '?perms=' . $perm1;
$result = json_decode(curl($url, '', false), true);
if ($result['retcode'] === 0) {
$find=$result['data']['perms'];
$menu=DeleteMenu($menu,$find);
if(!empty($menu) && is_array($menu)){
foreach ($menu as $k=>$v){
$v=(array)$v;
if($v['title']!='Dashboard' && count($v['childs'])==0 && empty($v['href']))
$find = $result['data']['perms'];
$menu = DeleteMenu($menu, $find);
if (!empty($menu) && is_array($menu)) {
foreach ($menu as $k => $v) {
$v = (array)$v;
if ($v['title'] != 'Dashboard' && count($v['childs']) == 0 && empty($v['href'])) {
unset($menu[$k]);
}
}
}
return array_merge($menu);
}else{
} else {
return false;
}
}
//提取菜单
function chils($chils){
$perms=[];
foreach ($chils as $k=>$v){
$perm_a=[];
$perm=[];
if(strlen($v['href'])>2){
$action=explode('/',$v['href']);
$perm[]=end($action);
function chils($chils)
{
$perms = [];
foreach ($chils as $k => $v) {
$perm_a = [];
$perm = [];
if (strlen($v['href']) > 2) {
$action = explode('/', $v['href']);
$perm[] = end($action);
}
if(count($v['childs'])>0){
$perm_a=chils($v['childs']);
if (count($v['childs']) > 0) {
$perm_a = chils($v['childs']);
}
$perms=array_merge($perms,array_merge($perm,$perm_a));
$perms = array_merge($perms, array_merge($perm, $perm_a));
}
return $perms;
}
//删除没有权限的菜单
function DeleteMenu($menu,$find){
foreach ($menu as $k=>$v){
if(strlen($v['href'])>2){
$action=explode('/',$v['href']);
$key=end($action);
if(empty($find[$key]) || $find[$key]==false)
function DeleteMenu($menu, $find)
{
foreach ($menu as $k => $v) {
if (strlen($v['href']) > 2) {
$action = explode('/', $v['href']);
$key = end($action);
if (empty($find[$key]) || $find[$key] == false) {
unset($menu[$k]);
}else{
if(count($v['childs'])>0){
$menu[$k]['childs'] = array_values(DeleteMenu($v['childs'],$find));
}
if(!count($v['childs'])>0 && $v['title'] != '首页') unset($menu[$k]);//为了删除没有下级的目录
} else {
if (count($v['childs']) > 0) {
$menu[$k]['childs'] = array_values(DeleteMenu($v['childs'], $find));
}
if (!count($v['childs']) > 0 && $v['title'] != '首页') {
unset($menu[$k]);
}//为了删除没有下级的目录
}
}
return array_values($menu);
}
//处理iframe的Url
function iframeUrl($Url){
if(strstr($Url, '?') === false){
function iframeUrl($Url)
{
if (strstr($Url, '?') === false) {
$Url .= '?view=iframe';
}else{
} else {
$Url .= '&view=iframe';
}
return $Url;
......
<?php
namespace Common\Exceptions;
use Exception;
use Illuminate\Validation\ValidationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Response;
use PDOException;
use Predis\Connection\ConnectionException;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
ValidationException::class,
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $e
* @return void
*/
public function report(Exception $e)
{
$trace = $e->getTrace();
$class = $trace[0]['class'] ?? '';
$func = $trace[0]['function'] ?? '';
$method = trim($class.'::'.$func, '::');
$report = [
'code' => $this->getCode($e),
'message' => toUtf8($e->getMessage()),
'file' => $e->getFile(),
'line' => $e->getLine(),
'method' => $method,
'request' => json_encode(Request::input()),
'apiUrl' => getUrl(),
'uniqid' => getUnique(true),
];
\LogReport::write(\LogReport::anlyError($report));
parent::report($e);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
$code = $this->getCode($e);
//自动区分错误编码返回内容
if (strlen($code) == 6 && substr($code, 0, 1) == 1) {
return Response()->json(['errcode' => $code, 'errmsg' => toUtf8($e->getMessage())]);
}
$msg = '系统错误,请联系客服处理';
$data = '';
if (env('APP_DEBUG', '') == 'true') {
$msg = toUtf8($e->getMessage());
$log = [toUtf8($e->getMessage()), $e->getFile(), $e->getLine()];
$data = implode(" ", $log);
}
$data .= '#'.Request::getMethod();
//return Response()->json(['errcode' => $code, 'errmsg' => $msg.' :'.$e->getMessage(), 'data' => $data]);
return Response()->json(['errcode' => $code, 'errmsg' => $msg.' #'.getUnique(true), 'data' => $data]);
// return parent::render($request, $e);
}
private function getCode($e)
{
$systemcode = config('website.SystemCode');
if ($e instanceof PDOException) {//数据库连接
$code = errCode(001, 9, $systemcode);
} elseif ($e instanceof ConnectionException) {//redis连接
$code = errCode(002, 9, $systemcode);
} elseif ($e instanceof FatalThrowableError) {//致命错误
$code = errCode(003, 9, $systemcode);
} elseif ($e instanceof NotFoundHttpException || $e instanceof MethodNotAllowedHttpException) {//404
$code = 404;
} else {
$code = $e->getCode() ? $e->getCode() : 500;
}
return $code;
}
}
<?php
namespace Common\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Redis;
class RedisModel extends Model
{
const WRITE_CONNECT_METHOD = ['set', 'del', 'rpush','lpush', 'expire', 'hset', 'hmset', 'hdel','hsetnx','hincrby'];
const WANRING_LEVEL = 1;
const INGORE_LEVEL = 0;
private $read = [];
private $write = [];
private $level = self::WANRING_LEVEL;
public function __construct($level = self::WANRING_LEVEL, $ConnectWrite = 'default', $ConnectRead = 'read')
{
parent::__construct();
$this->level = $level;
$this->read = Redis::connection($ConnectRead);
$this->write = Redis::connection($ConnectWrite);
}
public function __call($method, $args)
{
$cls = &$this;
$tmp = function($method, $args) use ($cls) {
if (strpos($method, 'pipeline_')) {//使用管道
$method = substr($method, 9);
if (in_array($method, $cls::WRITE_CONNECT_METHOD)) {
return $cls->write->pipeline(function ($pipe) use ($args) {
foreach ($args as $arg) {
$pipe->$method(...$arg);
}
});
} else {
try {
return $cls->read->pipeline(function ($pipe) use ($args) {
foreach ($args as $arg) {
$pipe->$method(...$arg);
}
});
} catch (ConnectionException $e) {
return $cls->write->pipeline(function ($pipe) use ($args) {
foreach ($args as $arg) {
$pipe->$method(...$arg);
}
});
}
}
} else {
if (in_array($method, $cls::WRITE_CONNECT_METHOD)) {
return $cls->write->$method(...$args);
} else {
try {
return $cls->read->$method(...$args);
} catch (ConnectionException $e) {
return $cls->write->$method(...$args);
}
}
}
};
if ($this->level == self::WANRING_LEVEL) {//默认告警级别,抛出异常
if (strpos($method, 'catch_') === 0) {
$method = substr($method, 6);
try {
return $tmp($method, $args);
} catch (\Exception $e) {
return null;
}
} else {
return $tmp($method, $args);
}
} else {
try {
return $tmp($method, $args);
} catch (\Exception $e) {
return null;
}
}
}
//管道
public function pipeline_to_hset($data){
return $this->write->pipeline(function ($pipe) use ($data) {
foreach ($data['data'] as $k => $v) {
$pipe->hset($data['key'],$k,$v);
}
});
}
}
<?php
namespace Rpc\Msg;
/**
* Autogenerated by Thrift Compiler (0.11.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
use Thrift\Base\TBase;
use Thrift\Type\TType;
use Thrift\Type\TMessageType;
use Thrift\Exception\TException;
use Thrift\Exception\TProtocolException;
use Thrift\Protocol\TProtocol;
use Thrift\Protocol\TBinaryProtocolAccelerated;
use Thrift\Exception\TApplicationException;
interface MessageIf {
/**
* @param string $str
* @return string
*/
public function MessageApiAction($str);
}
class MessageClient implements \Rpc\Msg\MessageIf {
protected $input_ = null;
protected $output_ = null;
protected $seqid_ = 0;
public function __construct($input, $output=null) {
$this->input_ = $input;
$this->output_ = $output ? $output : $input;
}
public function MessageApiAction($str)
{
$this->send_MessageApiAction($str);
return $this->recv_MessageApiAction();
}
public function send_MessageApiAction($str)
{
$args = new \Rpc\Msg\Message_MessageApiAction_args();
$args->str = $str;
$bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');
if ($bin_accel)
{
thrift_protocol_write_binary($this->output_, 'MessageApiAction', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite());
}
else
{
$this->output_->writeMessageBegin('MessageApiAction', TMessageType::CALL, $this->seqid_);
$args->write($this->output_);
$this->output_->writeMessageEnd();
$this->output_->getTransport()->flush();
}
}
public function recv_MessageApiAction()
{
$bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary');
if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, '\Rpc\Msg\Message_MessageApiAction_result', $this->input_->isStrictRead());
else
{
$rseqid = 0;
$fname = null;
$mtype = 0;
$this->input_->readMessageBegin($fname, $mtype, $rseqid);
if ($mtype == TMessageType::EXCEPTION) {
$x = new TApplicationException();
$x->read($this->input_);
$this->input_->readMessageEnd();
throw $x;
}
$result = new \Rpc\Msg\Message_MessageApiAction_result();
$result->read($this->input_);
$this->input_->readMessageEnd();
}
if ($result->success !== null) {
return $result->success;
}
throw new \Exception("MessageApiAction failed: unknown result");
}
}
// HELPER FUNCTIONS AND STRUCTURES
class Message_MessageApiAction_args {
static $isValidate = false;
static $_TSPEC = array(
1 => array(
'var' => 'str',
'isRequired' => false,
'type' => TType::STRING,
),
);
/**
* @var string
*/
public $str = null;
public function __construct($vals=null) {
if (is_array($vals)) {
if (isset($vals['str'])) {
$this->str = $vals['str'];
}
}
}
public function getName() {
return 'Message_MessageApiAction_args';
}
public function read($input)
{
$xfer = 0;
$fname = null;
$ftype = 0;
$fid = 0;
$xfer += $input->readStructBegin($fname);
while (true)
{
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
if ($ftype == TType::STOP) {
break;
}
switch ($fid)
{
case 1:
if ($ftype == TType::STRING) {
$xfer += $input->readString($this->str);
} else {
$xfer += $input->skip($ftype);
}
break;
default:
$xfer += $input->skip($ftype);
break;
}
$xfer += $input->readFieldEnd();
}
$xfer += $input->readStructEnd();
return $xfer;
}
public function write($output) {
$xfer = 0;
$xfer += $output->writeStructBegin('Message_MessageApiAction_args');
if ($this->str !== null) {
$xfer += $output->writeFieldBegin('str', TType::STRING, 1);
$xfer += $output->writeString($this->str);
$xfer += $output->writeFieldEnd();
}
$xfer += $output->writeFieldStop();
$xfer += $output->writeStructEnd();
return $xfer;
}
}
class Message_MessageApiAction_result {
static $isValidate = false;
static $_TSPEC = array(
0 => array(
'var' => 'success',
'isRequired' => false,
'type' => TType::STRING,
),
);
/**
* @var string
*/
public $success = null;
public function __construct($vals=null) {
if (is_array($vals)) {
if (isset($vals['success'])) {
$this->success = $vals['success'];
}
}
}
public function getName() {
return 'Message_MessageApiAction_result';
}
public function read($input)
{
$xfer = 0;
$fname = null;
$ftype = 0;
$fid = 0;
$xfer += $input->readStructBegin($fname);
while (true)
{
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
if ($ftype == TType::STOP) {
break;
}
switch ($fid)
{
case 0:
if ($ftype == TType::STRING) {
$xfer += $input->readString($this->success);
} else {
$xfer += $input->skip($ftype);
}
break;
default:
$xfer += $input->skip($ftype);
break;
}
$xfer += $input->readFieldEnd();
}
$xfer += $input->readStructEnd();
return $xfer;
}
public function write($output) {
$xfer = 0;
$xfer += $output->writeStructBegin('Message_MessageApiAction_result');
if ($this->success !== null) {
$xfer += $output->writeFieldBegin('success', TType::STRING, 0);
$xfer += $output->writeString($this->success);
$xfer += $output->writeFieldEnd();
}
$xfer += $output->writeFieldStop();
$xfer += $output->writeStructEnd();
return $xfer;
}
}
<?php
namespace Rpc\Msg;
/**
* Autogenerated by Thrift Compiler (0.11.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
use Thrift\Base\TBase;
use Thrift\Type\TType;
use Thrift\Type\TMessageType;
use Thrift\Exception\TException;
use Thrift\Exception\TProtocolException;
use Thrift\Protocol\TProtocol;
use Thrift\Protocol\TBinaryProtocolAccelerated;
use Thrift\Exception\TApplicationException;
interface SendMsgIf {
/**
* @param string $str
* @return string
*/
public function sendMsg($str);
}
class SendMsgClient implements \Rpc\Msg\SendMsgIf {
protected $input_ = null;
protected $output_ = null;
protected $seqid_ = 0;
public function __construct($input, $output=null) {
$this->input_ = $input;
$this->output_ = $output ? $output : $input;
}
public function sendMsg($str)
{
$this->send_sendMsg($str);
return $this->recv_sendMsg();
}
public function send_sendMsg($str)
{
$args = new \Rpc\Msg\SendMsg_sendMsg_args();
$args->str = $str;
$bin_accel = ($this->output_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');
if ($bin_accel)
{
thrift_protocol_write_binary($this->output_, 'sendMsg', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite());
}
else
{
$this->output_->writeMessageBegin('sendMsg', TMessageType::CALL, $this->seqid_);
$args->write($this->output_);
$this->output_->writeMessageEnd();
$this->output_->getTransport()->flush();
}
}
public function recv_sendMsg()
{
$bin_accel = ($this->input_ instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary');
if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, '\Rpc\Msg\SendMsg_sendMsg_result', $this->input_->isStrictRead());
else
{
$rseqid = 0;
$fname = null;
$mtype = 0;
$this->input_->readMessageBegin($fname, $mtype, $rseqid);
if ($mtype == TMessageType::EXCEPTION) {
$x = new TApplicationException();
$x->read($this->input_);
$this->input_->readMessageEnd();
throw $x;
}
$result = new \Rpc\Msg\SendMsg_sendMsg_result();
$result->read($this->input_);
$this->input_->readMessageEnd();
}
if ($result->success !== null) {
return $result->success;
}
throw new \Exception("sendMsg failed: unknown result");
}
}
// HELPER FUNCTIONS AND STRUCTURES
class SendMsg_sendMsg_args {
static $isValidate = false;
static $_TSPEC = array(
1 => array(
'var' => 'str',
'isRequired' => false,
'type' => TType::STRING,
),
);
/**
* @var string
*/
public $str = null;
public function __construct($vals=null) {
if (is_array($vals)) {
if (isset($vals['str'])) {
$this->str = $vals['str'];
}
}
}
public function getName() {
return 'SendMsg_sendMsg_args';
}
public function read($input)
{
$xfer = 0;
$fname = null;
$ftype = 0;
$fid = 0;
$xfer += $input->readStructBegin($fname);
while (true)
{
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
if ($ftype == TType::STOP) {
break;
}
switch ($fid)
{
case 1:
if ($ftype == TType::STRING) {
$xfer += $input->readString($this->str);
} else {
$xfer += $input->skip($ftype);
}
break;
default:
$xfer += $input->skip($ftype);
break;
}
$xfer += $input->readFieldEnd();
}
$xfer += $input->readStructEnd();
return $xfer;
}
public function write($output) {
$xfer = 0;
$xfer += $output->writeStructBegin('SendMsg_sendMsg_args');
if ($this->str !== null) {
$xfer += $output->writeFieldBegin('str', TType::STRING, 1);
$xfer += $output->writeString($this->str);
$xfer += $output->writeFieldEnd();
}
$xfer += $output->writeFieldStop();
$xfer += $output->writeStructEnd();
return $xfer;
}
}
class SendMsg_sendMsg_result {
static $isValidate = false;
static $_TSPEC = array(
0 => array(
'var' => 'success',
'isRequired' => false,
'type' => TType::STRING,
),
);
/**
* @var string
*/
public $success = null;
public function __construct($vals=null) {
if (is_array($vals)) {
if (isset($vals['success'])) {
$this->success = $vals['success'];
}
}
}
public function getName() {
return 'SendMsg_sendMsg_result';
}
public function read($input)
{
$xfer = 0;
$fname = null;
$ftype = 0;
$fid = 0;
$xfer += $input->readStructBegin($fname);
while (true)
{
$xfer += $input->readFieldBegin($fname, $ftype, $fid);
if ($ftype == TType::STOP) {
break;
}
switch ($fid)
{
case 0:
if ($ftype == TType::STRING) {
$xfer += $input->readString($this->success);
} else {
$xfer += $input->skip($ftype);
}
break;
default:
$xfer += $input->skip($ftype);
break;
}
$xfer += $input->readFieldEnd();
}
$xfer += $input->readStructEnd();
return $xfer;
}
public function write($output) {
$xfer = 0;
$xfer += $output->writeStructBegin('SendMsg_sendMsg_result');
if ($this->success !== null) {
$xfer += $output->writeFieldBegin('success', TType::STRING, 0);
$xfer += $output->writeString($this->success);
$xfer += $output->writeFieldEnd();
}
$xfer += $output->writeFieldStop();
$xfer += $output->writeStructEnd();
return $xfer;
}
}
<?php
namespace Rpc\Msg;
/**
* Autogenerated by Thrift Compiler (0.11.0)
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
use Thrift\Base\TBase;
use Thrift\Type\TType;
use Thrift\Type\TMessageType;
use Thrift\Exception\TException;
use Thrift\Exception\TProtocolException;
use Thrift\Protocol\TProtocol;
use Thrift\Protocol\TBinaryProtocolAccelerated;
use Thrift\Exception\TApplicationException;
<?php
namespace Rpc;
use Thrift\Exception\TException;
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TBufferedTransport;
use Thrift\Transport\THttpClient;
use Thrift\Transport\TPhpStream;
use Thrift\TMultiplexedProcessor;
use Thrift\Protocol\TMultiplexedProtocol;
use Thrift\Factory\TBinaryProtocolFactory;
use Thrift\Factory\TTransportFactory;
use Thrift\Server\TServerSocket;
use Thrift\Server\TSimpleServer;
use Thrift\Server\TForkingServer;
use Thrift\Transport\TSocket;
class MsgRpcClient {
public function sendMsg($data){
try {
ini_set('memory_limit', '1024M');
$socket = new TSocket('192.168.2.245', '9988');
$socket->setRecvTimeout(50000);
$socket->setDebug(true);
$transport = new TBufferedTransport($socket, 1024, 1024);
$protocol = new TBinaryProtocol($transport);
$client = new \Rpc\Msg\SendMsgClient(new TMultiplexedProtocol($protocol, "sendMsg"));
$transport->open();
$result = $client->sendMsg(json_encode($data));
print_r($result);
$transport->close();
} catch (TException $tx) {
print_r($tx->getMessage());
}
}
}
\ No newline at end of file
......@@ -6,7 +6,9 @@
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*"
"laravel/framework": "5.2.*",
"ext-json": "*",
"ext-curl": "*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
......@@ -23,8 +25,7 @@
"App\\": "app/"
},
"files": [
"app/Http/function.php",
"common/function.php"
"app/Http/function.php"
]
},
"autoload-dev": {
......
<?php
namespace ScmWmsCommon;
use Closure;
class CheckLogin
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$login = config('website.verification_token');
$token = $request->input('token');
if(!$token){
return response()->json(["errcode" => 502, "errmsg" => "no token"]);
}
$rsp = curl($login,['token' => $token],true);
if(!$rsp){
return response()->json(["errcode" => 503, "errmsg" => "登录验证失败"]);
}
$ret = json_decode($rsp);
if ($ret->errcode != 0) {
return response()->json(["errcode" => $ret->errcode, "errmsg" => $ret->errmsg]);
}
$user = $ret->data;
$request->user = $user;
//还需要处理仓库
$request->store_id = 1;
return $next($request);
}
}
<?php
namespace ScmWmsCommon;
use Illuminate\Database\Eloquent\Model;
use DB;
class SnModel extends Model
{
protected $table = 'numbering_rules';
public $timestamps = false;
public function __construct($connection = false)
{
parent::__construct();
if($connection){
$this->connection= $connection;
}
}
//单号
public function sn($ruleCode)
{
$str = DB::connection($this->connection)->transaction(function() use($ruleCode){
$data = $this->where('rule_code', $ruleCode)->first();
if (!empty($data)) {
$data = $data->toArray();
}
$str = $data['rule_prefix'];
$str_middle = '';
$number = $data['rule_suffix_number'] + 1;
if (!empty($data['rule_mask'])) {
$str_middle = date($data['rule_mask']);
}
$str .= $str_middle;
if ($str_middle != $data['rule_mask_str']) {//重置
$number = $data['rule_suffix'];
$save['rule_mask_str'] = $str_middle;
}
if ($data['rule_suffix_len'] > 0) {
$str .= $this->fillNum($data['rule_suffix_len'], $number);
if ($number != $data['rule_suffix_number']) {
$save['rule_suffix_number'] = $number;
}
if (isset($save)) {
$this->where('rule_id', $data['rule_id'])->update($save);
}
}
return $str;
});
return $str;
}
private function fillNum($len, $num)
{
$str = '';
if ($len > 0) {
$str = str_pad($num, $len, '0', 0);
}
return $str;
}
//生成单号
public function generateNumber($codeId)
{
return $this->sn($codeId);
}
}
......@@ -17,5 +17,4 @@ return array(
'f0906e6318348a765ffb6eb24e0d0938' => $vendorDir . '/laravel/framework/src/Illuminate/Foundation/helpers.php',
'58571171fd5812e6e447dce228f52f4d' => $vendorDir . '/laravel/framework/src/Illuminate/Support/helpers.php',
'cdab8ec77ae0402ce2cb2fdd82a8a401' => $baseDir . '/app/Http/function.php',
'a259deb85a47aeb259b02ded2ed1ff28' => $baseDir . '/common/function.php',
);
......@@ -18,7 +18,6 @@ class ComposerStaticInit2a46e5674e69fd121680370ab820bf2e
'f0906e6318348a765ffb6eb24e0d0938' => __DIR__ . '/..' . '/laravel/framework/src/Illuminate/Foundation/helpers.php',
'58571171fd5812e6e447dce228f52f4d' => __DIR__ . '/..' . '/laravel/framework/src/Illuminate/Support/helpers.php',
'cdab8ec77ae0402ce2cb2fdd82a8a401' => __DIR__ . '/../..' . '/app/Http/function.php',
'a259deb85a47aeb259b02ded2ed1ff28' => __DIR__ . '/../..' . '/common/function.php',
);
public static $prefixLengthsPsr4 = array (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment