Commit 7770c257 by liwotianname

Merge branch 'master' of http://git.2b3.cn/tencent/services

parents c9a191ec b510526a
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/18
* Time: 13:58
*/
namespace Hdll\Services\BuyerDistribution\Enum;
class DistributionEnum
{
const STATE_BALANCE_FALSE = 0; //未入账
const STATE_BALANCE_TRUE = 1; //已入账
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/12
* Time: 13:32
*/
namespace Hdll\Services\Common\Bean\Annotation;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* @Annotation
* @Target({"ALL"})
* Class Auth
* @package App\Bean\Annotation
*/
class Auth
{
private $scope=0;
private $option='==';
public function __construct(array $values)
{
if (isset($values['scope'])) {
$this->scope = $values['scope'];
}
if (isset($values['option'])) {
$this->option = $values['option'];
}
}
public function setScope($scope)
{
return $this->scope = $scope;
}
public function setOption($option)
{
return $this->option = $option;
}
public function getScope()
{
return $this->scope;
}
public function getOption()
{
return $this->option;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/12
* Time: 13:32
*/
namespace Hdll\Services\Common\Bean\Annotation;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* @Annotation
* @Target("ALL")
* Class Auth
* @package App\Bean\Annotation
*/
class Split
{
private $num=100;
public function __construct(array $values)
{
if (isset($values['num'])) {
$this->num = $values['num'];
}
}
public function setNum($num)
{
$this->num = $num;
}
public function getNum()
{
return $this->num;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/12
* Time: 13:44
*/
namespace Hdll\Services\Common\Bean\Collector;
use Hdll\Services\Common\Bean\Annotation\Auth;
use Swoft\Bean\CollectorInterface;
class AuthCollector implements CollectorInterface
{
/**
* @var array
*/
private static $auth = [];
public static function collect(string $className,
$objectAnnotation = null,
string $propertyName = '',
string $methodName = '',
$propertyValue = null)
{
if ($objectAnnotation instanceof Auth) {
$scope = $objectAnnotation->getScope();
$option = $objectAnnotation->getOption();
if ( $methodName ==='' ) {
self::$auth[$className]['scope'] = $scope;
self::$auth[$className]['option'] = $option;
} else {
self::$auth[$className]['methods'][$methodName]['scope'] = $scope;
self::$auth[$className]['methods'][$methodName]['option'] = $option;
}
}
}
public static function getCollector()
{
return self::$auth;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/12
* Time: 13:44
*/
namespace Hdll\Services\Common\Bean\Collector;
use Hdll\Services\Common\Bean\Annotation\Split;
use Swoft\Bean\CollectorInterface;
use Swoft\Db\Bean\Collector\EntityCollector;
class SplitCollector implements CollectorInterface
{
/**
* @var array
*/
private static $split = [];
public static function collect(string $className,
$objectAnnotation = null,
string $propertyName = '',
string $methodName = '',
$propertyValue = null)
{
if ($objectAnnotation instanceof Split) {
$entityCollector = EntityCollector::getCollector();
self::$split[$className]['table'] = $entityCollector[$className]['table']['name'];
self::$split[$className]['num'] = $objectAnnotation->getNum();
self::$split['map'][$className] = $entityCollector[$className]['table']['name'];
}
}
public static function getCollector()
{
return self::$split;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/12
* Time: 13:43
*/
namespace Hdll\Services\Common\Bean\Parser;
use Hdll\Services\Common\Bean\Collector\AuthCollector;
use Swoft\Bean\Annotation\Scope;
use Swoft\Bean\Parser\AbstractParser;
/**
* @uses AuthParser
* Class AuthParser
* @package App\Bean\Parser
*/
class AuthParser extends AbstractParser
{
public function parser(string $className,
$objectAnnotation = null,
string $propertyName = '',
string $methodName = '',
$propertyValue = null)
{
AuthCollector::collect($className, $objectAnnotation, $propertyName, $methodName, $propertyValue);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/12
* Time: 13:43
*/
namespace Hdll\Services\Common\Bean\Parser;
use Hdll\Services\Common\Bean\Collector\SplitCollector;
use Swoft\Bean\Annotation\Scope;
use Swoft\Bean\Parser\AbstractParser;
/**
* @uses SplitParser
* Class AuthParser
* @package App\Bean\Parser
*/
class SplitParser extends AbstractParser
{
public function parser(string $className,
$objectAnnotation = null,
string $propertyName = '',
string $methodName = '',
$propertyValue = null)
{
$beanName = $className;
$scope = Scope::SINGLETON;
SplitCollector::collect($className, $objectAnnotation, $propertyName, $methodName, $propertyValue);
return [$beanName, $scope, ""];
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/13
* Time: 13:28
*/
namespace Hdll\Services\Common\Bean\Wrapper;
use Hdll\Services\Common\Bean\Annotation\Auth;
use Swoft\Bean\Wrapper\AbstractWrapper;
class AuthWrapper extends AbstractWrapper
{
/**
* @var array 解析哪些注解(类级)
*/
protected $classAnnotations = [
Auth::class
];
/**
* @var array 解析哪些注解(属性级)
*/
protected $propertyAnnotations = [
Auth::class
]
;
/**
* @var array 解析哪些注解(方法级)
*/
protected $methodAnnotations = [
Auth::class
];
/**
* 是否解析类注解
* @param array $annotations
* @return bool
*/
public function isParseClassAnnotations(array $annotations): bool
{
return true;
}
/**
* 是否解析属性注解
* @param array $annotations
* @return bool
*/
public function isParsePropertyAnnotations(array $annotations): bool
{
return true;
}
/**
* 是否解析方法注解
* @param array $annotations
* @return bool
*/
public function isParseMethodAnnotations(array $annotations): bool
{
return true;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/13
* Time: 13:28
*/
namespace Hdll\Services\Common\Bean\Wrapper;
use Hdll\Services\Common\Bean\Annotation\Split;
use Swoft\Bean\Wrapper\AbstractWrapper;
class SplitWrapper extends AbstractWrapper
{
/**
* @var array 解析哪些注解(类级)
*/
protected $classAnnotations = [
Split::class
];
/**
* @var array 解析哪些注解(属性级)
*/
protected $propertyAnnotations = [
Split::class
]
;
/**
* @var array 解析哪些注解(方法级)
*/
protected $methodAnnotations = [
Split::class
];
/**
* 是否解析类注解
* @param array $annotations
* @return bool
*/
public function isParseClassAnnotations(array $annotations): bool
{
return true;
}
/**
* 是否解析属性注解
* @param array $annotations
* @return bool
*/
public function isParsePropertyAnnotations(array $annotations): bool
{
return true;
}
/**
* 是否解析方法注解
* @param array $annotations
* @return bool
*/
public function isParseMethodAnnotations(array $annotations): bool
{
return true;
}
}
\ No newline at end of file
<?php
/**
* Auto generated from CLS.proto at 2018-09-07 06:03:23
*
* cls package
*/
namespace Hdll\Services\Common\ClsLogger\Cls {
/**
* Log message
*/
class Log extends \ProtobufMessage
{
/* Field index constants */
const TIME = 1;
const CONTENTS = 2;
/* @var array Field descriptors */
protected static $fields = array(
self::TIME => array(
'name' => 'time',
'required' => true,
'type' => \ProtobufMessage::PB_TYPE_INT,
),
self::CONTENTS => array(
'name' => 'contents',
'repeated' => true,
'type' => '\Hdll\Services\Common\ClsLogger\Cls\Log_Content'
),
);
/**
* Constructs new message container and clears its internal state
*/
public function __construct()
{
$this->reset();
}
/**
* Clears message values and sets default ones
*
* @return null
*/
public function reset()
{
$this->values[self::TIME] = null;
$this->values[self::CONTENTS] = array();
}
/**
* Returns field descriptors
*
* @return array
*/
public function fields()
{
return self::$fields;
}
/**
* Sets value of 'time' property
*
* @param integer $value Property value
*
* @return null
*/
public function setTime($value)
{
return $this->set(self::TIME, $value);
}
/**
* Returns value of 'time' property
*
* @return integer
*/
public function getTime()
{
$value = $this->get(self::TIME);
return $value === null ? (integer)$value : $value;
}
/**
* Appends value to 'contents' list
*
* @param \Hdll\Services\Common\ClsLogger\Cls\Log_Content $value Value to append
*
* @return null
*/
public function appendContents(\Hdll\Services\Common\ClsLogger\Cls\Log_Content $value)
{
return $this->append(self::CONTENTS, $value);
}
/**
* Clears 'contents' list
*
* @return null
*/
public function clearContents()
{
return $this->clear(self::CONTENTS);
}
/**
* Returns 'contents' list
*
* @return \Hdll\Services\Common\ClsLogger\Cls\Log_Content[]
*/
public function getContents()
{
return $this->get(self::CONTENTS);
}
/**
* Returns 'contents' iterator
*
* @return \ArrayIterator
*/
public function getContentsIterator()
{
return new \ArrayIterator($this->get(self::CONTENTS));
}
/**
* Returns element from 'contents' list at given offset
*
* @param int $offset Position in list
*
* @return \Hdll\Services\Common\ClsLogger\Cls\Log_Content
*/
public function getContentsAt($offset)
{
return $this->get(self::CONTENTS, $offset);
}
/**
* Returns count of 'contents' list
*
* @return int
*/
public function getContentsCount()
{
return $this->count(self::CONTENTS);
}
}
}
\ No newline at end of file
<?php
/**
* Auto generated from CLS.proto at 2018-09-07 06:03:23
*
* cls package
*/
namespace Hdll\Services\Common\ClsLogger\Cls {
/**
* LogGroup message
*/
class LogGroup extends \ProtobufMessage
{
/* Field index constants */
const LOGS = 1;
const CONTEXTFLOW = 2;
const FILENAME = 3;
const SOURCE = 4;
/* @var array Field descriptors */
protected static $fields = array(
self::LOGS => array(
'name' => 'logs',
'repeated' => true,
'type' => '\Hdll\Services\Common\ClsLogger\Cls\Log'
),
self::CONTEXTFLOW => array(
'name' => 'contextFlow',
'required' => false,
'type' => \ProtobufMessage::PB_TYPE_STRING,
),
self::FILENAME => array(
'name' => 'filename',
'required' => false,
'type' => \ProtobufMessage::PB_TYPE_STRING,
),
self::SOURCE => array(
'name' => 'source',
'required' => false,
'type' => \ProtobufMessage::PB_TYPE_STRING,
),
);
/**
* Constructs new message container and clears its internal state
*/
public function __construct()
{
$this->reset();
}
/**
* Clears message values and sets default ones
*
* @return null
*/
public function reset()
{
$this->values[self::LOGS] = array();
$this->values[self::CONTEXTFLOW] = null;
$this->values[self::FILENAME] = null;
$this->values[self::SOURCE] = null;
}
/**
* Returns field descriptors
*
* @return array
*/
public function fields()
{
return self::$fields;
}
/**
* Appends value to 'logs' list
*
* @param \Hdll\Services\Common\ClsLogger\Cls\Log $value Value to append
*
* @return null
*/
public function appendLogs(\Hdll\Services\Common\ClsLogger\Cls\Log $value)
{
return $this->append(self::LOGS, $value);
}
/**
* Clears 'logs' list
*
* @return null
*/
public function clearLogs()
{
return $this->clear(self::LOGS);
}
/**
* Returns 'logs' list
*
* @return \Hdll\Services\Common\ClsLogger\Cls\Log[]
*/
public function getLogs()
{
return $this->get(self::LOGS);
}
/**
* Returns 'logs' iterator
*
* @return \ArrayIterator
*/
public function getLogsIterator()
{
return new \ArrayIterator($this->get(self::LOGS));
}
/**
* Returns element from 'logs' list at given offset
*
* @param int $offset Position in list
*
* @return \Hdll\Services\Common\ClsLogger\Cls\Log
*/
public function getLogsAt($offset)
{
return $this->get(self::LOGS, $offset);
}
/**
* Returns count of 'logs' list
*
* @return int
*/
public function getLogsCount()
{
return $this->count(self::LOGS);
}
/**
* Sets value of 'contextFlow' property
*
* @param string $value Property value
*
* @return null
*/
public function setContextFlow($value)
{
return $this->set(self::CONTEXTFLOW, $value);
}
/**
* Returns value of 'contextFlow' property
*
* @return string
*/
public function getContextFlow()
{
$value = $this->get(self::CONTEXTFLOW);
return $value === null ? (string)$value : $value;
}
/**
* Sets value of 'filename' property
*
* @param string $value Property value
*
* @return null
*/
public function setFilename($value)
{
return $this->set(self::FILENAME, $value);
}
/**
* Returns value of 'filename' property
*
* @return string
*/
public function getFilename()
{
$value = $this->get(self::FILENAME);
return $value === null ? (string)$value : $value;
}
/**
* Sets value of 'source' property
*
* @param string $value Property value
*
* @return null
*/
public function setSource($value)
{
return $this->set(self::SOURCE, $value);
}
/**
* Returns value of 'source' property
*
* @return string
*/
public function getSource()
{
$value = $this->get(self::SOURCE);
return $value === null ? (string)$value : $value;
}
}
}
\ No newline at end of file
<?php
/**
* Auto generated from CLS.proto at 2018-09-07 06:03:23
*
* cls package
*/
namespace Hdll\Services\Common\ClsLogger\Cls {
/**
* LogGroupList message
*/
class LogGroupList extends \ProtobufMessage
{
/* Field index constants */
const LOGGROUPLIST = 1;
/* @var array Field descriptors */
protected static $fields = array(
self::LOGGROUPLIST => array(
'name' => 'logGroupList',
'repeated' => true,
'type' => '\Hdll\Services\Common\ClsLogger\Cls\LogGroup'
),
);
/**
* Constructs new message container and clears its internal state
*/
public function __construct()
{
$this->reset();
}
/**
* Clears message values and sets default ones
*
* @return null
*/
public function reset()
{
$this->values[self::LOGGROUPLIST] = array();
}
/**
* Returns field descriptors
*
* @return array
*/
public function fields()
{
return self::$fields;
}
/**
* Appends value to 'logGroupList' list
*
* @param \Hdll\Services\Common\ClsLogger\Cls\LogGroup $value Value to append
*
* @return null
*/
public function appendLogGroupList(\Hdll\Services\Common\ClsLogger\Cls\LogGroup $value)
{
return $this->append(self::LOGGROUPLIST, $value);
}
/**
* Clears 'logGroupList' list
*
* @return null
*/
public function clearLogGroupList()
{
return $this->clear(self::LOGGROUPLIST);
}
/**
* Returns 'logGroupList' list
*
* @return \Hdll\Services\Common\ClsLogger\Cls\LogGroup[]
*/
public function getLogGroupList()
{
return $this->get(self::LOGGROUPLIST);
}
/**
* Returns 'logGroupList' iterator
*
* @return \ArrayIterator
*/
public function getLogGroupListIterator()
{
return new \ArrayIterator($this->get(self::LOGGROUPLIST));
}
/**
* Returns element from 'logGroupList' list at given offset
*
* @param int $offset Position in list
*
* @return \Hdll\Services\Common\ClsLogger\Cls\LogGroup
*/
public function getLogGroupListAt($offset)
{
return $this->get(self::LOGGROUPLIST, $offset);
}
/**
* Returns count of 'logGroupList' list
*
* @return int
*/
public function getLogGroupListCount()
{
return $this->count(self::LOGGROUPLIST);
}
}
}
\ No newline at end of file
<?php
/**
* Auto generated from CLS.proto at 2018-09-07 06:03:23
*
* cls package
*/
namespace Hdll\Services\Common\ClsLogger\Cls {
/**
* Content message embedded in Log message
*/
class Log_Content extends \ProtobufMessage
{
/* Field index constants */
const KEY = 1;
const VALUE = 2;
/* @var array Field descriptors */
protected static $fields = array(
self::KEY => array(
'name' => 'key',
'required' => true,
'type' => \ProtobufMessage::PB_TYPE_STRING,
),
self::VALUE => array(
'name' => 'value',
'required' => true,
'type' => \ProtobufMessage::PB_TYPE_STRING,
),
);
/**
* Constructs new message container and clears its internal state
*/
public function __construct()
{
$this->reset();
}
/**
* Clears message values and sets default ones
*
* @return null
*/
public function reset()
{
$this->values[self::KEY] = null;
$this->values[self::VALUE] = null;
}
/**
* Returns field descriptors
*
* @return array
*/
public function fields()
{
return self::$fields;
}
/**
* Sets value of 'key' property
*
* @param string $value Property value
*
* @return null
*/
public function setKey($value)
{
return $this->set(self::KEY, $value);
}
/**
* Returns value of 'key' property
*
* @return string
*/
public function getKey()
{
$value = $this->get(self::KEY);
return $value === null ? (string)$value : $value;
}
/**
* Sets value of 'value' property
*
* @param string $value Property value
*
* @return null
*/
public function setValue($value)
{
return $this->set(self::VALUE, $value);
}
/**
* Returns value of 'value' property
*
* @return string
*/
public function getValue()
{
$value = $this->get(self::VALUE);
return $value === null ? (string)$value : $value;
}
}
}
\ No newline at end of file
<?php
namespace Hdll\Services\Common\ClsLogger;
use Swoft\App;
use Swoole\Coroutine;
use Swoole\Coroutine\MySQL\Exception;
use Swoft\HttpClient\Client;
use Hdll\Services\Common\ClsLogger\Cls\LogGroupList;
use Hdll\Services\Common\ClsLogger\Cls\LogGroup;
use Hdll\Services\Common\ClsLogger\Cls\Log_Content;
use Hdll\Services\Common\ClsLogger\Cls\Log;
class ClsLog
{
const TOPICID_ERROR = '11b19b11-c6b3-45fc-ab1a-7a531558fb57';
const TOPICID_NOTICE = 'b84f9396-d17a-4e61-88a8-11e032755732';
public static function error($msgText, $key = ''){
$key = empty($key) ? APP_NAME : APP_NAME.':'.$key;
$pbData = self::createPbData($key, $msgText);
return self::uploadToCls(self::TOPICID_ERROR, $pbData);
}
public static function notice($msgText, $key = '') {
$key = empty($key) ? APP_NAME : APP_NAME.':'.$key;
$pbData = self::createPbData($key, $msgText);
return self::uploadToCls(self::TOPICID_NOTICE, $pbData);
}
private static function createPbData($key, $value)
{
$logGroupList = new LogGroupList;
$logGroup = new LogGroup;
$log = new Log;
$logContent = new Log_Content;
$logContent->setKey($key);
$logContent->setValue($value);
$log->appendContents($logContent);
$log->setTime(time());
$logGroup->appendLogs($log);
$logGroup->setSource(APP_NAME);
$logGroupList->appendLogGroupList($logGroup);
return $logGroupList->serializeToString();
}
private static function uploadToCls($topicId, $pbData) {
$authorization = ClsSignature::create();
$uri = 'http://ap-beijing.cls.myqcloud.com/structuredlog?topic_id='.$topicId;
$res = (new Client)->post($uri, [
'headers' => [
'Host' => 'ap-beijing.cls.myqcloud.com',
'Authorization' => $authorization,
'Content-Type' => 'application/x-protobuf',
],
'body'=>$pbData,
'timeout' => 20,
]);
if($res->getResponse()->getStatusCode() != 200) {
$msg = '上传腾讯云日志服务失败:'.$res->getResult();
self::writeClsErrors($msg);
return false;
}
return true;
}
/**
* 腾讯日志服务上传时产生错误,这种错误需要记录在本地文件
*
* @return void
*/
private static function writeClsErrors($messageText) {
$filename = 'cls_error.log';
$logFile = \alias('@runtime').'/logs/'.$filename;
if (App::isCoContext()) {
// 协程写
go(function () use ($logFile, $messageText) {
$res = Coroutine::writeFile($logFile, $messageText, FILE_APPEND);
if ($res === false) {
throw new \InvalidArgumentException("Unable to append to log file: {$filename}");
}
});
} else {
$fp = fopen($logFile, 'a');
if ($fp === false) {
throw new \InvalidArgumentException("Unable to append to log file: {$filename}");
}
flock($fp, LOCK_EX);
fwrite($fp, $messageText);
flock($fp, LOCK_UN);
fclose($fp);
}
}
}
<?php
namespace Hdll\Services\Common\ClsLogger;
class ClsSignature
{
public static function create(){
$signTime = (time()-10).';'.(time()+300);
$configs = include dirname(__FILE__, 2).'/Config/config.php';
$sha1edHttpString = sha1("post\n/structuredlog\n\n\n");
$stringToSign = "sha1\n{$signTime}\n{$sha1edHttpString}\n";
$signKey = hash_hmac('sha1', $signTime, $configs['cls']['secretKey']);
$signature = hash_hmac('sha1', $stringToSign, $signKey);
$authorization = 'q-sign-algorithm=sha1&q-ak='.$configs['cls']['secretId']
."&q-sign-time={$signTime}&q-key-time={$signTime}&q-header-list=&q-url-param-list=&q-signature={$signature}";
return $authorization;
}
}
<?php
namespace Hdll\Services\Common\ClsLogger;
use Monolog\Handler\AbstractProcessingHandler;
use Swoft\App;
use Swoole\Coroutine;
/**
* 自定义日志处理器,记录到腾讯云Cls
*
* @uses LogHandler
*/
class LogHandler extends AbstractProcessingHandler
{
/**
* @var array 输出包含日志级别集合
*/
protected $levels = [];
/**
* @var string 对应腾讯CLS的主题ID
*/
protected $topicId;
/**
* 批量输出日志
*
* @param array $records 日志记录集合
*
* @return bool
*/
public function handleBatch(array $records)
{
$records = $this->recordFilter($records);
if (empty($records)) {
return true;
}
$lines = array_column($records, 'formatted');
$this->write($lines);
}
/**
* 输出到腾讯云CLS
*
* @param array $records 日志记录集合
*/
protected function write(array $records)
{
$messageText = implode(" __||__ ", $records);
if($this->topicId == ClsLog::TOPICID_ERROR) {
ClsLog::error($messageText);
} else if($this->topicId == ClsLog::TOPICID_NOTICE) {
ClsLog::notice($messageText);
}
}
/**
* 记录过滤器
*
* @param array $records 日志记录集合
*
* @return array
*/
private function recordFilter(array $records)
{
$messages = [];
foreach ($records as $record) {
if (!isset($record['level'])) {
continue;
}
if (!$this->isHandling($record)) {
continue;
}
$record = $this->processRecord($record);
$record['formatted'] = $this->getFormatter()->format($record);
$messages[] = $record;
}
return $messages;
}
/**
* check是否输出日志
*
* @param array $record
*
* @return bool
*/
public function isHandling(array $record)
{
if (empty($this->levels)) {
return true;
}
return in_array($record['level'], $this->levels);
}
}
#线上环境公共配置项:
...@@ -11,5 +11,10 @@ return [ ...@@ -11,5 +11,10 @@ return [
'alisms' => [ 'alisms' => [
'accessKeyId' => 'EjBn9zQxyEkKHyAA', 'accessKeyId' => 'EjBn9zQxyEkKHyAA',
'accessKeySecret' => 'AN276rwCcqCkFUVt1GLCbAy8jnj52t', 'accessKeySecret' => 'AN276rwCcqCkFUVt1GLCbAy8jnj52t',
] ],
'cls' => [
'appid' => '1257143824 ',
'secretId' => 'AKIDseHj18kua0KTSJ4g9SadbVEnEUZVjvPj',
'secretKey' => 'IPL5g5PaaSAzd6NSO8gEmLxcN4pTzJSQ',
],
]; ];
\ No newline at end of file
<?php
/*
* This file is part of Swoft.
* (c) Swoft <group@swoft.org>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
'clsErrorLogHandler' => [
'class' => \Hdll\Services\Common\ClsLogger\LogHandler::class,
'topicId' => \Hdll\Services\Common\ClsLogger\ClsLog::TOPICID_ERROR,
'formatter' => '${lineFormatter}',
'levels' => [
\Swoft\Log\Logger::ERROR,
\Swoft\Log\Logger::WARNING,
\Swoft\Log\Logger::CRITICAL,
],
],
'clsNoticeLogHandler' => [
'class' => \Hdll\Services\Common\ClsLogger\LogHandler::class,
'topicId' => \Hdll\Services\Common\ClsLogger\ClsLog::TOPICID_NOTICE,
'formatter' => '${lineFormatter}',
'levels' => [
\Swoft\Log\Logger::NOTICE,
\Swoft\Log\Logger::INFO,
\Swoft\Log\Logger::DEBUG,
\Swoft\Log\Logger::TRACE,
],
],
'logger' => [
'name' => APP_NAME,
'enable' => true,
'flushInterval' => 100,
'flushRequest' => true,
'handlers' => [
'${clsErrorLogHandler}',
'${clsNoticeLogHandler}',
],
],
];
...@@ -93,12 +93,17 @@ class CommonEntity extends Model ...@@ -93,12 +93,17 @@ class CommonEntity extends Model
//获取注解里的table //获取注解里的table
$res = new \ReflectionClass(static::class); $res = new \ReflectionClass(static::class);
self::$commentString = $res->getDocComment(); $commentString = $res->getDocComment();
if ( false !== strpos(self::$commentString,"{split}") && !App::$isInTest) { if (
(
false !== strpos($commentString,"{split}")
|| false !== strpos($commentString,"@Split")
)
&& !App::$isInTest) {
$dbNum = self::getDbNum(); $dbNum = self::getDbNum();
$tableName = self::getTableName().'_'.$dbNum; $tableName = self::getTableName($commentString).'_'.$dbNum;
self::setTableName($tableName); //self::setTableName($tableName);
return $tableName; return $tableName;
} else { } else {
...@@ -143,9 +148,10 @@ class CommonEntity extends Model ...@@ -143,9 +148,10 @@ class CommonEntity extends Model
* 获取原始表名 * 获取原始表名
* @return string * @return string
*/ */
protected static function getTableName() protected static function getTableName($commentString = '')
{ {
preg_match('/(?<=Table\(name=").*(?="\))/', self::$commentString, $matches); $commentString = $commentString === ''?self::$commentString:$commentString;
preg_match('/(?<=Table\(name=").*(?="\))/', $commentString, $matches);
return $tableName = isset($matches[0])?$matches[0]:''; return $tableName = isset($matches[0])?$matches[0]:'';
} }
} }
\ No newline at end of file
<?php
/**
* This file is part of Swoft.
*
* @link https://swoft.org
* @document https://doc.swoft.org
* @contact group@swoft.org
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
*/
namespace Swoft\Db;
use Hdll\Services\Common\Entity\Split;
/**
* Query
*/
class Query
{
/**
* Query查询分表处理
* @param string $tableName
* @param string|null $alias
* @return QueryBuilder
* @throws Exception\DbException
*/
public static function table(string $tableName, string $alias = null): QueryBuilder
{
$query = new QueryBuilder();
//初始化分表
$tableName = Split::initSplit($tableName, $query);
$query = $query->table($tableName, $alias);
return $query;
}
}
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/18
* Time: 10:21
*/
namespace Hdll\Services\Common\Entity;
use Hdll\Services\Common\Bean\Collector\SplitCollector;
use Swoft\Core\RequestContext;
use Swoft\Db\Bean\Collector\EntityCollector;
use Swoft\Db\QueryBuilder;
class Split
{
public static function initSplit($tableName, QueryBuilder $query)
{
$collector = SplitCollector::getCollector();//分表搜集器
if ( $collector['map'] !== null && is_array($collector['map'])) {
$map = array_flip($collector['map']);
}
//如果是实体且为分表实体
if (strpos($tableName, '\\') !== false && isset($collector[$tableName])) {
$className = $tableName;
$tableName = $collector[$tableName]['table'];
$entityCollector = EntityCollector::getCollector();
//设置分表对应的className
EntityCollector::setCollector($tableName.'_'.self::getDbNum($className), $tableName);
//获取分表名
$tableName = $tableName.'_'.self::getDbNum($className);
//设置分表类型
$query->selectInstance($entityCollector[$className]['instance']);
} elseif ( isset($map[$tableName]) ) { //非实体且分表
$className = $map[$tableName];
$defaultTbleName = $tableName;
$tableName = $tableName.'_'.self::getDbNum($className);
//设置分表对应的className
EntityCollector::setCollector($tableName, $defaultTbleName);
}
return $tableName;
}
private function getDbNum($className)
{
$splitCollector = SplitCollector::getCollector();
$splitNum = $splitCollector[$className]['num'];
$data = RequestContext::getContextData();
$storeId = $data['userInfo']['storeId'];
return $storeId % $splitNum;
}
}
\ No newline at end of file
...@@ -13,6 +13,7 @@ namespace Hdll\Services\Common\Entity; ...@@ -13,6 +13,7 @@ namespace Hdll\Services\Common\Entity;
use Hdll\Services\Auth\Enum\AuthError; use Hdll\Services\Auth\Enum\AuthError;
use Hdll\Services\Common\Lib\Redis; use Hdll\Services\Common\Lib\Redis;
use Swoft\Bean\Annotation\Bean; use Swoft\Bean\Annotation\Bean;
use Swoft\Core\RequestContext;
/** /**
* 用户实体 * 用户实体
...@@ -25,106 +26,86 @@ use Swoft\Bean\Annotation\Bean; ...@@ -25,106 +26,86 @@ use Swoft\Bean\Annotation\Bean;
*/ */
class User class User
{ {
private $id;
private $nickname;
private $storeId;
private $headImg;
private $token;
private $sessionKey;
private $scope;
private $referId;
private $unionid;
private $openId;
public function __construct($token='') public function __construct($token='')
{ {
} }
public function getId() public function getId()
{ {
return $this->id; return $this->getValue('id');
} }
public function getNickname() public function getNickname()
{ {
return $this->nickname; return $this->getValue('nickname');
} }
public function getStoreId() public function getStoreId()
{ {
return $this->storeId; return $this->getValue('storeId');
} }
public function getHeadImg() public function getHeadImg()
{ {
return $this->headImg; return $this->getValue('headImg');
} }
public function getToken() public function getToken()
{ {
return $this->token; return $this->getValue('token');
} }
public function setId($value) public function setId($value)
{ {
return $this->id = $value; $this->setValue('id', $value);
} }
public function setNickname($value) public function setNickname($value)
{ {
return $this->nickname = $value; $this->setValue('nickname', $value);
} }
public function setStoreId($value) public function setStoreId($value)
{ {
return $this->storeId = $value; $this->setValue('storeId', $value);
} }
public function setHeadImg($value) public function setHeadImg($value)
{ {
return $this->headImg = $value; $this->setValue('headImg', $value);
} }
public function setSessionKey($value) public function setSessionKey($value)
{ {
$this->sessionKey = $value; $this->setValue('sessionKey', $value);
} }
public function setOpenId($value) public function setOpenId($value)
{ {
$this->openId = $value; $this->setValue('openid', $value);
} }
public function setUnionid($value) public function setUnionid($value)
{ {
$this->unionid = $value; $this->setValue('unionid', $value);
} }
public function setReferId($value) public function setReferId($value)
{ {
$this->referId = $value; $this->setValue('referId', $value);
} }
public function setScope($value) public function setScope($value)
{ {
$this->scope = $value; $this->setValue('scope', $value);
} }
public function setToken($value) public function setToken($value)
{ {
$this->token = $value; $this->setValue('token', $value);
} }
...@@ -141,28 +122,28 @@ class User ...@@ -141,28 +122,28 @@ class User
public function getSessionKey() public function getSessionKey()
{ {
return $this->sessionKey; return $this->getValue('sessionKey');
} }
public function getOpenId() public function getOpenId()
{ {
return $this->openId; return $this->getValue('openid');
} }
public function getUnionid() public function getUnionid()
{ {
return $this->unionid; return $this->getValue('unionid');
} }
public function getReferId() public function getReferId()
{ {
return $this->referId; return $this->getValue('referId');
} }
public function getScope() public function getScope()
{ {
return $this->scope; return $this->getValue('scope');
} }
...@@ -184,13 +165,28 @@ class User ...@@ -184,13 +165,28 @@ class User
} }
$info = json_decode($info, true); $info = json_decode($info, true);
$this->fill($info); //$this->fill($info);
RequestContext::setContextData(['userInfo' => $info]);
return true; return true;
} }
private function getValue($key)
{
$data = RequestContext::getContextData();
return $data['userInfo'][$key]??'';
}
private function setValue($key, $value='')
{
$userInfo = [];
$userInfo['userInfo'][$key] = $value;
RequestContext::removeContextDataByChildKey('userInfo', $key);
RequestContext::setContextData($userInfo);
}
} }
...@@ -69,7 +69,7 @@ class AuthPoolConfig extends PoolProperties ...@@ -69,7 +69,7 @@ class AuthPoolConfig extends PoolProperties
* the time of connect timeout * the time of connect timeout
* *
*/ */
protected $timeout = 5; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -71,7 +71,7 @@ class BargainPoolConfig extends PoolProperties ...@@ -71,7 +71,7 @@ class BargainPoolConfig extends PoolProperties
* *
* @var int * @var int
*/ */
protected $timeout = 5; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -68,7 +68,7 @@ class BuyerPoolConfig extends PoolProperties ...@@ -68,7 +68,7 @@ class BuyerPoolConfig extends PoolProperties
* the time of connect timeout * the time of connect timeout
* *
*/ */
protected $timeout = 5; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -70,7 +70,7 @@ class GoodsPoolConfig extends PoolProperties ...@@ -70,7 +70,7 @@ class GoodsPoolConfig extends PoolProperties
* *
* @var int * @var int
*/ */
protected $timeout = 5; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -69,7 +69,7 @@ class GroupBookingPoolConfig extends PoolProperties ...@@ -69,7 +69,7 @@ class GroupBookingPoolConfig extends PoolProperties
* *
* @var int * @var int
*/ */
protected $timeout = 5; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -67,7 +67,7 @@ class NoticePoolConfig extends PoolProperties ...@@ -67,7 +67,7 @@ class NoticePoolConfig extends PoolProperties
* the time of connect timeout * the time of connect timeout
* *
*/ */
protected $timeout = 50; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -67,7 +67,7 @@ class PayPoolConfig extends PoolProperties ...@@ -67,7 +67,7 @@ class PayPoolConfig extends PoolProperties
* the time of connect timeout * the time of connect timeout
* *
*/ */
protected $timeout = 50; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -68,7 +68,7 @@ class ReservationPoolConfig extends PoolProperties ...@@ -68,7 +68,7 @@ class ReservationPoolConfig extends PoolProperties
* *
* @var int * @var int
*/ */
protected $timeout = 15; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -68,7 +68,7 @@ class SchedulePoolConfig extends PoolProperties ...@@ -68,7 +68,7 @@ class SchedulePoolConfig extends PoolProperties
* *
* @var int * @var int
*/ */
protected $timeout = 15; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -70,7 +70,7 @@ class SellerDistributionPoolConfig extends PoolProperties ...@@ -70,7 +70,7 @@ class SellerDistributionPoolConfig extends PoolProperties
* *
* @var int * @var int
*/ */
protected $timeout = 5; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -69,7 +69,7 @@ class SellerPoolConfig extends PoolProperties ...@@ -69,7 +69,7 @@ class SellerPoolConfig extends PoolProperties
* *
* @var int * @var int
*/ */
protected $timeout = 5; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -66,7 +66,7 @@ class StateLessPoolConfig extends PoolProperties ...@@ -66,7 +66,7 @@ class StateLessPoolConfig extends PoolProperties
* *
* @var int * @var int
*/ */
protected $timeout = 5; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -68,7 +68,7 @@ class StorePoolConfig extends PoolProperties ...@@ -68,7 +68,7 @@ class StorePoolConfig extends PoolProperties
* *
* @var int * @var int
*/ */
protected $timeout = 15; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -68,7 +68,7 @@ class TimeLimitBuyPoolConfig extends PoolProperties ...@@ -68,7 +68,7 @@ class TimeLimitBuyPoolConfig extends PoolProperties
* *
* @var int * @var int
*/ */
protected $timeout = 5; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -67,7 +67,7 @@ class TransferPoolConfig extends PoolProperties ...@@ -67,7 +67,7 @@ class TransferPoolConfig extends PoolProperties
* *
* @var int * @var int
*/ */
protected $timeout = 5; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -70,7 +70,7 @@ class VipPoolConfig extends PoolProperties ...@@ -70,7 +70,7 @@ class VipPoolConfig extends PoolProperties
* *
* @var int * @var int
*/ */
protected $timeout = 5; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
...@@ -67,7 +67,7 @@ class WithdrawCashPoolConfig extends PoolProperties ...@@ -67,7 +67,7 @@ class WithdrawCashPoolConfig extends PoolProperties
* *
* @var int * @var int
*/ */
protected $timeout = 5; protected $timeout = 200;
/** /**
* the addresses of connection * the addresses of connection
......
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/14
* Time: 10:00
*/
namespace Hdll\Services\Common\Traits;
trait EntityCollectorTrait
{
public static function setCollector($tableName, $defaultTableName)
{
return ! isset(self::$entities[$tableName]) && self::$entities[$tableName] = &self::$entities[$defaultTableName];
}
}
\ No newline at end of file
...@@ -19,11 +19,14 @@ class NoticeEnum ...@@ -19,11 +19,14 @@ class NoticeEnum
//买家小程序消息推送 //买家小程序消息推送
const TYPE_MINI_FRONTEND_SEND= 101; const TYPE_MINI_FRONTEND_SEND= 101;
const TYPE_MP_SEND= 102;
const SEND_TYPES = [ const SEND_TYPES = [
self::TYPE_MINI_BACKEND_SEND, self::TYPE_MINI_BACKEND_SEND,
self::TYPE_TENCENT_SMS, self::TYPE_TENCENT_SMS,
self::TYPE_MINI_FRONTEND_SEND self::TYPE_MINI_FRONTEND_SEND,
self::TYPE_MP_SEND,
]; ];
......
...@@ -58,6 +58,25 @@ interface NoticeInterface ...@@ -58,6 +58,25 @@ interface NoticeInterface
] ]
]; ];
* *
* 微信公众号发送实例
$data[NoticeEnum::TYPE_MP_SEND] = [
'touser' => 'o3lFcs8xoWfQUlhzTiP5uZI6A7Hc', //这里要填写公众号的openId
'template_id' => 'zwUBuoKVRJkumLwGkippA46XfmLsmwJD906HC-wqOks',
'miniprogram' => [
'appid' => 'wx3b3b2df942634cdd', //小程序appid
'pagepath' => 'pages/start/start'//小程序页面
],
'data' => [
'first' => 'first',
'keyword1' => '姓名',
'keyword2' => '1213456',
'keyword3' => '测试门店',
'keyword4' => '门店地址',
'keyword5' => 'test',
'remark' => 'remark'
]
];
*
* @param array $sendTypes * @param array $sendTypes
* @param array $data * @param array $data
* @param int $sendTime //发送时间,立即返送填0 * @param int $sendTime //发送时间,立即返送填0
......
...@@ -30,6 +30,10 @@ class OrderEnum ...@@ -30,6 +30,10 @@ class OrderEnum
const TYPE_LIMIT = 2; //限时购订单 const TYPE_LIMIT = 2; //限时购订单
const TYPE_COLLECTION = 3; //拼团 const TYPE_COLLECTION = 3; //拼团
//对账锁定
const LOCK = 1; //订单锁定
const ORDER_TYPES = [ const ORDER_TYPES = [
self::TYPE_GOODS, self::TYPE_GOODS,
self::TYPE_CUT_PRICE, self::TYPE_CUT_PRICE,
......
...@@ -15,7 +15,7 @@ use Swoft\Core\ResultInterface; ...@@ -15,7 +15,7 @@ use Swoft\Core\ResultInterface;
* method ResultInterface deferReduceBalance($sellerId, $money) * method ResultInterface deferReduceBalance($sellerId, $money)
* method ResultInterface deferAddTotal($sellerId, $money) * method ResultInterface deferAddTotal($sellerId, $money)
* method ResultInterface deferReduceTotal($sellerId, $money) * method ResultInterface deferReduceTotal($sellerId, $money)
* method ResultInterface deferListByOrderId($storeId, $orderId) * method ResultInterface deferListByOrderId($storeId, $orderId,$sellerId)
* Interface SellerDistributionInterface * Interface SellerDistributionInterface
* @package App\Lib * @package App\Lib
*/ */
...@@ -85,8 +85,19 @@ interface SellerDistributionInterface{ ...@@ -85,8 +85,19 @@ interface SellerDistributionInterface{
* 获取分销记录 * 获取分销记录
* @param $storeId * @param $storeId
* @param $orderId * @param $orderId
* @param $sellerId
* @return mixed
* @author Administrator
*/
public function listByOrderId($storeId, $orderId,$sellerId);
/**
* 更细对账表
* @param $storeId
* @param $id
* @param $balanceState 0 未对帐 1 已对账
* @return mixed * @return mixed
* @author Administrator * @author Administrator
*/ */
public function listByOrderId($storeId, $orderId); public function updateBill($storeId,$id,$balanceState);
} }
\ No newline at end of file
<?php
/**
* This file is part of Swoft.
*
* @link https://swoft.org
* @document https://doc.swoft.org
* @contact group@swoft.org
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
*/
namespace Hdll\Services\Store\Lib;
use Swoft\Core\ResultInterface;
/**
* The interface of store-settings service
*
* @method ResultInterface deferGetSettings(int $storeId)
*/
interface SettingsInterface
{
/**
* 获取店铺基础设置项
*
* @Number(name="storeId")
* @param int $storeId
* @return array
*/
public function getSettings(int $storeId);
}
\ No newline at end of file
...@@ -20,7 +20,7 @@ use Swoft\Core\ResultInterface; ...@@ -20,7 +20,7 @@ use Swoft\Core\ResultInterface;
* @method ResultInterface deferGetStoreBySellerId(int $sellerId) * @method ResultInterface deferGetStoreBySellerId(int $sellerId)
* @method ResultInterface deferUpdateStore(int $storeId, array $data) * @method ResultInterface deferUpdateStore(int $storeId, array $data)
* @method ResultInterface deferDeleteStore(int $storeId) * @method ResultInterface deferDeleteStore(int $storeId)
* @method ResultInterface deferGetWxacodeUrl(int $type, string $page, string $scene) * @method ResultInterface deferGetWxacodeUrl(int $storeId, int $type, string $page, string $scene)
*/ */
interface StoreInterface interface StoreInterface
{ {
...@@ -87,6 +87,6 @@ interface StoreInterface ...@@ -87,6 +87,6 @@ interface StoreInterface
* @param string $scene 通过小程序码传递的参数 * @param string $scene 通过小程序码传递的参数
* @return string 成功返回小程序码的图片资源名(腾讯云存储的资源名,如:store_wxacode/9a414ff3b4c478a36c2ba7df563ee88b.png) * @return string 成功返回小程序码的图片资源名(腾讯云存储的资源名,如:store_wxacode/9a414ff3b4c478a36c2ba7df563ee88b.png)
*/ */
public function getWxacodeUrl(int $type, string $page, string $scene); public function getWxacodeUrl(int $storeId, int $type, string $page, string $scene);
} }
\ No newline at end of file
...@@ -11,8 +11,6 @@ class VipEnum{ ...@@ -11,8 +11,6 @@ class VipEnum{
const VIP_TOTAL_FEE = 10;//价格 const VIP_TOTAL_FEE = 10;//价格
const PAY_NOTIFY = 'http://www.baidu.com';
const STATUS_UNPAID = 10;//未支付 const STATUS_UNPAID = 10;//未支付
const STATUS_PAID = 20;//已支付 const STATUS_PAID = 20;//已支付
......
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 to comment