Commit 16429991 by liwotianname

Merge branch 'master' of http://139.199.22.180/tencent/services

parents d2c84da9 c3486a12
<?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\AccountBook\Lib;
use Swoft\Core\ResultInterface;
/**
* The interface of demo service
*
* @method ResultInterface deferIncome(int $storeId, int $money,int $orderId)
* @method ResultInterface deferExpense(int $storeId, int $money,int $orderId)
*/
interface AccountInterface
{
/**
* 流水增加
* @param $storeId
* @param $money
* @param $ordirId
* @return bool
*/
public function Income($storeId, $money, $ordirId);
/**
* 流水减少
* @param $storeId
* @param $money
* @param $ordirId
* @return bool
*/
public function Expense($storeId, $money, $ordirId);
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/8/29
* Time: 12:03
*/
namespace Hdll\Services\Auth\Enum;
class AuthEnum
{
const SCOPE_BUYER = 1; //买家
const SCOPE_EMPLOYEE = 2; //手艺人
const SCOPE_SELLER = 3; //卖家
const SCOPE_ADMIN = 4;//管理员
const AUTH_BACKEND = 100;
const AUTH_FRONTEND = 101;
const AUTH_TYPE_SELLER = 200; //卖家授权
const AUTH_TYPE_EMPLOYEE = 201; //员工授权
const AUTH_TYPE_E_AND_S = 203; //选择授权(用户自己选择进行员工授权还是卖家授权)
const AUTH_TYPE_BUYER = 204; //买家授权
}
\ No newline at end of file
......@@ -9,14 +9,8 @@ namespace Hdll\Services\Auth\Enum;
class AuthError
{
const PARAMETER_ERR = ["msg" => "参数错误", "code" => 500, "errorCode" => 25001];
const TOKEN_ERROR = ["msg" => "token写入失败", "code" => 500, "errorCode" => 25100];
const WX_ERROR = ["msg" => "获取信息失败", "code" => 500, "errorCode" => 25101];
const CONFIG_ERROR = ["msg" => "配置不正确", "code" => 500, "errorCode" => 25102];
const GET_TOKEN_ERROR = ["msg" => "获取token失败", "code" => 500, "errorCode" => 25103];
const NOT_FOUND_USER = ["msg" => "获取用户信息失败", "code" => 404, "errorCode" => 25104];
const GET_TOKEN_ERROR = ["msg" => "获取token失败", "code" => 401, "errorCode" => 25103];
const NOT_FOUND_USER = ["msg" => "获取用户信息失败", "code" => 401, "errorCode" => 25104];
public static function atranslate($message,$param)
......
<?php
/**
* Created by PhpStorm.
* User: lwt
* Date: 2018/7/10
* Time: 13:15
*/
namespace Hdll\Services\Bargain\Enum;
class BargainEnum
{
//订单状态
const STATUS_NORMAL = 10; //待支付
//paystatus
const HAVE_PAY =2;
const PAY_EXCEPTION = 3;
const PAY_REFUND = 4; // 退款
}
\ 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\Bargain\Lib;
use Hdll\Services\Bargain\Enum\BargainEnum;
use Swoft\Core\ResultInterface;
/**
* The interface of demo service
*
* @method ResultInterface deferGetgoodsinfo(int $limit_id)
* @method ResultInterface deferGetBargainInfo(int $limit_id)
*/
interface BargainInterface
{
/**
* 获取砍价商品的 商品信息
* @param int $bargain_id
* @return {
* "name" 名称
* "image" 图片
* "price" 价格
* "activityName" 活动名称
* }
*/
public function getGoodsInfo(
int $stordId, int $bargain_id
);
/**
* 通过商品id 获取是否 有砍价活动
* @param int $storeId
* @param int $goodsId
* @return bool
*
*/
public function getBargainInfo(
int $storeId, int $goodsId
);
/**
* 支付 状态 回馈接口
* @param string $storeId //
* @param int $bargainbranchId // 砍价活动id
* @param int $status // BargainEnum::HAVE_PAY 成功支付 BargainEnum::PAY_EXCEPTION:未支付 (已经过期或者支付异常)
* @return mixed
*/
public function payStatus(
string $storeId,
int $bargainbranchId,
int $status , //
int $orderId);
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/8/31
* Time: 17:25
*/
namespace Hdll\Services\Buyer\Enum;
class BillEnum
{
const STATE_BALANCE_FALSE = 1; //未入账
const STATE_BALANCE_TRUE = 2; //已入账
}
\ No newline at end of file
......@@ -11,4 +11,8 @@ class BuyerEnum
{
const SCORE = 0;
//state
const STATE_NORMAL = 0;
const STATE_FREEZE = 1;
}
\ No newline at end of file
......@@ -13,6 +13,7 @@ use Swoft\Core\ResultInterface;
/**
* @method ResultInterface deferSaveBill(string $token,int $order_id,int $buyer_id,int $store_id,string $order_sn,int $money)
* @method ResultInterface deferGetListByOrderId(int $storeId, int $orderId)
* Interface AgencyInterface
* @package App\Lib
*/
......@@ -20,21 +21,34 @@ interface BillInterface{
/**
* 保存账单数据
* @param int $order_id
* @param int $buyer_id
* @param int $store_id
* @param string $order_sn
* @param int $money
* @param int $orderId //订单id
* @param int $buyerId // 买家id
* @param int $storeId // 店铺id
* @param string $orderSn //订单号
* @param int $money //订单金额
* @return mixed
* @author Administrator
*/
public function saveBill(
int $order_id,
int $buyer_id,
int $store_id,
string $order_sn,
int $orderId,
int $buyerId,
int $storeId,
string $orderSn,
int $money
);
public function getListByOrderId(int $storeId, int $orderId);
public function updateByCondition(int $storeId, array $condition, array $info);
/**
* 退款成功逻辑
*
* @param $storeId
* @param $orderId
* @return mixed
*/
public function refundSuccess($storeId, $orderId);
}
\ No newline at end of file
......@@ -17,9 +17,64 @@ use Swoft\Core\ResultInterface;
*/
interface BuyerInterface
{
/**
* 获取用户信息
*
* @param int $storeId
* @param int $buyerId
* @return mixed
array(8) {
["id"]=> int(1) //买家id
["unionId"]=>string(28) "oyDnT5OYVCQUC9X9ErkDHBNrad90"
["storeId"]=>int(0)//店铺id
["referId"]=>int(0)//推荐人ID
["state"]=>int(0)//买家状态
["nickName"]=>string(0) ""//买家昵称
["openId"]=>string(0) ""//买家openId
["profile"]=>
array(4) {
["realName"]=>string(12) "真实姓名"
["gender"]=>int(1)//性别
["phoneNumber"]=>string(11) "18812345678"//手机号
["birthday"]=>int(0) //生日
}
["commission"]=>
array(3) {
["totalCommission"]=>int(10)//总共提现
["balanceCommission"]=>int(10)//可提现金额
["expectCommission"]=>int(20)//冻结提现金额
}
}
*
*/
public function getUser(int $storeId, int $buyerId);
public function updateProfile(string $token, array $data);
/**
* 更新用户信息
* $updateInfo = [
"realName" => "真实姓名",
"gender" => "性别",
"phoneNumber" => "手机号",
"birthday" => "生日"
];
* @param int $storeId
* @param array $data
* @return mixed
*/
public function updateProfile(int $storeId, array $data);
/**
* 是否已经注册用户
* @param $storeId
* @param $unionid
* @return mixed
*
* 返回值:
* array(3) {
["id"]=> int(1)//买家id
["storeId"]=> int(1) //店铺id
["referId"]=> int(0) //推荐人id
}
*/
public function hasUser($storeId,$unionid);
}
\ No newline at end of file
......@@ -19,13 +19,12 @@ interface CommissionInterface
* @param $storeId
* @param $buyerId
* @param $money
* @return mixed|bool
* @return bool
*/
public function reduceBalanceCommission($storeId, $buyerId, $money);
/**
* 增加可提现金额
*
*
* @param $storeId
* @param $buyerId
* @param $money
......@@ -33,4 +32,33 @@ interface CommissionInterface
*/
public function addBalanceCommission($storeId, $buyerId, $money);
/**
* 增加可提现金额(仅限于对账服务使用,切记!!!)
*
* @param $storeId
* @param $buyerId
* @param $money
* @return bool
*/
public function addBalanceCommissionCompare($storeId, $buyerId, $money);
/**
* 增加累计现金额
*
* @param $storeId
* @param $buyerId
* @param $money
* @return bool
*/
public function addTotalCommission($storeId, $buyerId, $money);
/**
* 增加冻结金额
*
* @param int $storeId
* @param int $orderId
* @return mixed
*/
public function addExpectCommission(int $storeId, int $orderId);
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/30
* Time: 9:50
*/
namespace Hdll\Services\Buyer\Lib;
use Swoft\Core\ResultInterface;
/**
* @method ResultInterface deferDelByStoreId(int $storeId)
* Interface Footprint
* @package Hdll\Services\Buyer\Lib
*/
interface FootprintInterface
{
public function delByStoreId(int $storeId) : bool;
}
\ No newline at end of file
<?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: Argericy
* Date: 2018/7/23
* Time: 15:54
*/
namespace App\Models\Dao;
use App\Models\Entity\{entityName};
use Swoft\Bean\Annotation\Bean;
use Hdll\Services\Common\Exception\CommonException;
/**
* @Bean()
* Class {daoName}
* @package App\Models\Dao
*/
class {daoName}
{
public function create(array $info) : {entityName}
{
${varEntityName} = new {entityName}($info);
$res = ${varEntityName}->save()->getResult();
if ( $res === false ) {
throw new CommonException(["msg" => "数据库操作错误", "code" => 500]);
}
return ${varEntityName};
}
public function selectInfoByCondition(array $condition, array $option)
{
return {entityName}::findAll($condition, $option)->getResult();
}
public function getInfoByCondition(array $condition, array $option)
{
return {entityName}::findOne($condition, $option)->getResult();
}
/**
* 根据条件更新信息
* @param $condition
* @param $updateInfo
* @return mixed
*/
public function updateByCondition(array $condition, array $updateInfo)
{
return {entityName}::updateAll($updateInfo, $condition)->getResult();
}
/**
* 更新一条记录
*
* @param $condition
* @param $updateInfo
* @return mixed
*/
public function updateOne(array $condition, array $updateInfo)
{
return {entityName}::updateOne($updateInfo, $condition)->getResult();
}
public function delOne(array $condition)
{
return {entityName}::deleteOne($condition)->getResult();
}
public function delAll(array $condition)
{
return {entityName}::deleteAll($condition)->getResult();
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Argericy
* Date: 2018/9/29
* Time: 11:35
*/
namespace App\Models\Data;
use App\Models\Dao\{daoName};
use Swoft\Bean\Annotation\Bean;
use Swoft\Bean\Annotation\Inject;
/**
* @Bean()
*
* Class {dataName}
* @package App\Models\Data
*/
class {dataName}
{
/**
* @Inject()
* @var {daoName}
*/
private ${varDaoName};
}
\ 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 App\Commands\Common;
use Swoft\Console\Bean\Annotation\Command;
use Swoft\Console\Bean\Annotation\Mapping;
use Swoft\Console\Input\Input;
use Swoft\Console\Output\Output;
/**
* generate dao,data layer commands
*
* @Command(coroutine=false)
*/
class GenerateCommand
{
/**
* this generate command
*
* @Usage
* generate:dao [options]
*
* @Options
* -n,--n the dao name
* -en,--en the entity name
*
* @Example
* php swoft generate:dao -e entityName [-n daoName]
*
* @param Input $input
* @param Output $output
*
* @Mapping("dao")
*/
public function Dao(Input $input, Output $output)
{
$className = $input->getOpt('n');
$entityName = $input->getOpt('e');
$this->generateDao($output, $className, $entityName);
}
/**
* this generate command
*
* @Usage
* generate:all [options]
*
* @Options
* -n,--n the dao name
* -e,--e the entity name
*
* @Example
* php swoft generate:dao -e entityName [-n dataName] [--dao-name daoName]
*
* @param Input $input
* @param Output $output
*
* @Mapping("all")
*/
public function all(Input $input, Output $output)
{
$dataName = $input->getOpt('n');
$entityName = $input->getOpt('e');
$daoName = $input->getOpt('dao-name');
$appPath = alias('@app');
$dataName = empty($dataName)?$entityName.'Data':$dataName;
//generateDao
$daoName = empty($daoName)?$entityName.'Dao':$daoName;
$this->generateDao($output, $daoName, $entityName);
//generateData
$dataPath = $appPath.'/Models/Data/'.$dataName.'.php';
$templatePath = $appPath.'/Commands/Common/ClassTemplate/Data/ClassTemplate';
$content = file_get_contents($templatePath);
preg_match_all('/(?<={)\w+(?=})/', $content, $vars);
$vars = isset($vars[0])?$vars[0]:[];
foreach ( $vars as $var ) {
if ( strpos($var, 'var') !== false ) {
$name = str_replace('var', '', $var);
$name = lcfirst($name);
$$var = lcfirst($$name);
var_dump($var, $$var);
}
$content = str_replace("{{$var}}", $$var,$content);
}
$dataPath = file_exists($dataPath)?$dataPath.'.gen':$dataPath;
file_put_contents($dataPath, $content);
}
private function generateDao($output,$daoName, $entityName)
{
if ( empty($entityName) ) {
$output->writeln("the entity name is required", true, true);
}
$daoName = empty($daoName)?$entityName.'Dao':$daoName;
$daoPath = alias("@app").'/Models/Dao/'.$daoName.'.php';
$templatePath = alias("@app").'/Commands/Common/ClassTemplate/Dao/ClassTemplate';
$content = file_get_contents($templatePath);
preg_match_all('/(?<={)\w+(?=})/', $content, $vars);
$vars = isset($vars[0])?$vars[0]:[];
foreach ( $vars as $var ) {
if ( strpos($var, 'var') !== false ) {
$name = str_replace('var', '', $var);
$name = lcfirst($name);
$$var = lcfirst($$name);
var_dump($var, $$var);
}
$content = str_replace("{{$var}}", $$var,$content);
}
$daoPath = file_exists($daoPath)?$daoPath.'.gen':$daoPath;
file_put_contents($daoPath,$content);
}
/**
* 解析模板中变量
*
* @param string $content
* @return string
*/
private function parseVar(string $content):string
{
preg_match_all('/(?<={)\w+(?=})/', $content, $vars);
$vars = isset($vars[0])?$vars[0]:[];
foreach ( $vars as $var ) {
if ( strpos($var, 'var') !== false ) {
$name = str_replace('var', '', $var);
$name = lcfirst($name);
$$var = lcfirst($$name);
var_dump($var, $$var);
}
$content = str_replace("{{$var}}", $$var,$content);
}
return $content;
}
}
\ 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);
$search1 = strpos($record['messages'], '[http://testapi.2b3.cn:80/]');
$search2 = strpos($record['messages'], '[http://api.2b3.cn:80/]');
if($search1 !== false || $search2 !== false) {
continue;
}
$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 [
'alisms' => [
'accessKeyId' => 'EjBn9zQxyEkKHyAA',
'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}',
],
],
];
......@@ -90,16 +90,20 @@ class CommonEntity extends Model
}
$request = RequestContext::getRequest();
$testFlag = $request->query('flag');
//获取注解里的table
$res = new \ReflectionClass(static::class);
self::$commentString = $res->getDocComment();
if ( false !== strpos(self::$commentString,"{split}") && App::$isInTest) {
$commentString = $res->getDocComment();
if (
(
false !== strpos($commentString,"{split}")
|| false !== strpos($commentString,"@Split")
)
&& !App::$isInTest) {
$dbNum = self::getDbNum();
$tableName = self::getTableName().'_'.$dbNum;
self::setTableName($tableName);
$tableName = self::getTableName($commentString).'_'.$dbNum;
//self::setTableName($tableName);
return $tableName;
} else {
......@@ -144,9 +148,10 @@ class CommonEntity extends Model
* 获取原始表名
* @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]:'';
}
}
\ 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 Hdll\Services\Common\Enum\TestEnum;
use Hdll\Services\Common\Exception\CommonException;
use Swoft\App;
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 ( ! self::isTesting() ) {
//如果是实体且为分表实体
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];
$defaultTableName = $tableName;
$tableName = $tableName.'_'.self::getDbNum($className);
//设置分表对应的className
EntityCollector::setCollector($tableName, $defaultTableName);
}
}
return $tableName;
}
private function getDbNum($className)
{
$splitCollector = SplitCollector::getCollector();
$splitNum = $splitCollector[$className]['num'];
$data = RequestContext::getContextData();
$storeId = $data['userInfo']['storeId'];
if ( empty($storeId) ) {
throw new CommonException(["msg" => "参数异常,获取店铺信息失败。"]);
}
return $storeId % $splitNum;
}
private function isTesting()
{
/**@var User $user**/
$user = App::getBean(User::class);
return $user->getTestFlag() === TestEnum::TEST_STORE_ID;
}
}
\ No newline at end of file
......@@ -11,10 +11,10 @@
namespace Hdll\Services\Common\Entity;
use Hdll\Services\Auth\Enum\AuthError;
use Hdll\Services\Auth\Exception\AuthException;
use Hdll\Services\Common\Enum\TestEnum;
use Swoft\App;
use Swoft\Bean\Annotation\Bean;
use Swoft\Cache\Cache;
use Swoft\Core\RequestContext;
use Swoft\Redis\Redis;
/**
......@@ -28,139 +28,110 @@ use Swoft\Redis\Redis;
*/
class User
{
private $id=2;
private $nickname;
private $storeId;
private $headImg;
private $token="3333E";
private $cmId;
private $sessionKey;
private $scope;
private $referId;
private $unionid;
private $openId;
public function __construct($token='')
{
}
public function getId()
{
return $this->id;
return $this->getValue('id');
}
public function setTestFlag()
{
$this->setValue('testFlag', TestEnum::TEST_STORE_ID);
}
public function getTestFlag()
{
return $this->getValue('testFlag');
}
public function getNickname()
{
return $this->nickname;
return $this->getValue('nickname');
}
public function getStoreId()
{
return $this->storeId;
return $this->getValue('storeId');
}
public function getHeadImg()
{
return $this->headImg;
return $this->getValue('headImg');
}
public function getToken()
{
return $this->token;
return $this->getValue('token');
}
public function setId($value)
{
return $this->id = $value;
$this->setValue('id', $value);
}
public function setNickname($value)
{
return $this->nickname = $value;
$this->setValue('nickname', $value);
}
public function setStoreId($value)
{
return $this->storeId = $value;
$this->setValue('storeId', $value);
}
public function setHeadImg($value)
{
return $this->headImg = $value;
$this->setValue('headImg', $value);
}
public function setSessionKey($value)
{
$this->sessionKey = $value;
$this->setValue('sessionKey', $value);
}
public function setOpenId($value)
{
$this->openId = $value;
$this->setValue('openid', $value);
}
public function setUnionid($value)
{
$this->unionid = $value;
$this->setValue('unionid', $value);
}
public function setReferId($value)
{
$this->referId = $value;
$this->setValue('referId', $value);
}
public function setScope($value)
{
$this->scope = $value;
$this->setValue('scope', $value);
}
public function setToken($value)
{
if ( empty($value) ) {
return [false,AuthError::GET_TOKEN_ERROR];
}
/**
* @var Redis $redis
*/
$redis = App::getBean(Redis::class);
$info = $redis->get('AUTH:'.$value);
if ( empty($info) ) {
return [false,AuthError::NOT_FOUND_USER];
}
$info = json_decode($info, true);
$this->fill($info);
$this->token = $value;
return true;
$this->setValue('token', $value);
}
public function setCmId($value)
public function setSubStoreId($value)
{
$this->cmId = $value;
$this->setValue('subStoreId', $value);
}
public function getCmId()
public function getSubStoreId()
{
return $this->cmId;
return $this->getValue('subStoreId')??0;
}
public function fill($arr)
{
foreach ($arr as $name => $value) {
......@@ -174,31 +145,67 @@ class User
public function getSessionKey()
{
return $this->sessionKey;
return $this->getValue('sessionKey');
}
public function getOpenId()
{
return $this->openId;
return $this->getValue('openid');
}
public function getUnionid()
{
return $this->unionid;
return $this->getValue('unionid');
}
public function getReferId()
{
return $this->referId;
return $this->getValue('referId');
}
public function getScope()
{
return $this->scope;
return $this->getValue('scope');
}
public function initUser($token)
{
if ( empty($token) ) {
return [false,AuthError::GET_TOKEN_ERROR];
}
$redis = App::getBean(Redis::class);
$info = $redis->get("AUTH:".$token);
if ( empty($info) ) {
return [false,AuthError::NOT_FOUND_USER];
}
$info = json_decode($info, true);
//$this->fill($info);
RequestContext::setContextData(['userInfo' => $info]);
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);
}
}
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/25
* Time: 13:22
*/
namespace Hdll\Services\Common\Enum;
class TestEnum
{
const TEST_STORE_ID = true;
}
......@@ -9,7 +9,7 @@ namespace Hdll\Services\Common\Exception;
class ExceptionParseData
{
public static function parseData(\Exception $e)
public static function parseData(\Throwable $e)
{
if ( is_callable([$e,'getResponse']) ) {
$response = $e->getResponse();
......@@ -19,6 +19,7 @@ class ExceptionParseData
$msg = isset($data['0'])?$data['0']:'';
$data = json_decode($msg,true);
$data = empty($data)?$response:$data;
} else {
$data['msg'] = $e->getMessage();
$data['code'] = 500;
......
......@@ -39,10 +39,8 @@ class Alisms
// 短信模板预设参数
$this->templateParam = $templateParam;
$configurator = \Swoft\App::getBean('config');
$configurator->load('@vendor/hdll/services/src/Common/Config');
$this->config = $configurator->get('alisms');
$commonConfigs = include dirname(__FILE__, 2).'/Config/config.php';
$this->config = $commonConfigs['alisms'];
}
/**
......
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/8/20
* Time: 16:34
*/
namespace Hdll\Services\Common\Lib;
use Swoft\App;
use Swoft\Redis\Operator\Processor\PrefixProcessor;
class Redis extends \Swoft\Redis\Redis
{
private $prefix;
/**
* 设置redis前缀
* @param $prefix
*/
public function setPrefix($prefix)
{
$this->prefix = $prefix;
}
public function call(string $method, array $params)
{
$config = App::getBean(PrefixProcessor::class);
$config->setPrefix($this->prefix);
$res = parent::call($method, $params);
$config->setPrefix(config("redis.prefix",''));
return $res;
}
public function __destruct()
{
$config = App::getBean(PrefixProcessor::class);
$config->setPrefix(config("redis.prefix",''));
}
}
\ No newline at end of file
......@@ -21,11 +21,15 @@ use Hdll\Services\Common\Entity\User;
class Smscode
{
protected $sellerId;
protected $number;
public function __construct()
public function __construct($number = null)
{
$this->sellerId = App::getBean(User::class)->getId();
if($number !== null) {
$this->number = $number;
} else {
$this->number = App::getBean(User::class)->getId();
}
}
/**
......@@ -53,7 +57,7 @@ class Smscode
} else {
$count = 1;
}
$vcode = mt_rand(10000, 99999);
$vcode = mt_rand(1000, 9999);
$alisms = new Alisms(
$signName ?? Alisms::SN_01,
$templateCode ?? Alisms::TPL_01,
......@@ -93,7 +97,7 @@ class Smscode
private function getKey($mobile)
{
return 'smscode:' . md5($this->sellerId . '|' . $mobile);
return 'smscode:' . md5($this->number . '|' . $mobile);
}
}
\ No newline at end of file
......@@ -26,10 +26,8 @@ class Upload
public function __construct(array $config = [])
{
if (empty($config)) {
/**@var Config */
$bConfig = \Swoft\App::getBean('config');
$bConfig->load('@vendor/hdll/services/src/Common/Config');
$config = $bConfig->get('qCloud');
$config = include alias('@vendor/hdll/services/src/Common/Config').'/config.php';
$config = $config['qCloud'];
}
$this->Bucket = $config['Bucket'];
$this->Region = $config['Region'];
......@@ -68,4 +66,27 @@ class Upload
}
return $result;
}
public function uploadStream($stream, $name = '')
{
$cosClient = new Client(
[
'region' => $this->Region,
'credentials' => [
'secretId' => $this->SecretId,
'secretKey' => $this->SecretKey,
]
]
);
try {
$result = $cosClient->Upload(
$this->Bucket,
$name,
$stream
);
} catch (\Exception $e) {
throw new CommonException(['msg' => $e->getMessage()]);
}
return $result;
}
}
\ 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\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Pool\PoolProperties;
use Swoft\Bean\Annotation\Value;
/**
* @Bean()
* the config of service bargain
*/
class AccountBookPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_ACCOUNTBOOK_URI', 'accountbook:8099'));
}
protected $name = 'accountbook';
/**
* Minimum active number of connections
*
* @var int
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
* @var int
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
* @var int
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
* @var int
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
* @var int
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
* @var int
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
* @Value(name="", env="${RPC_BARGAIN_URI}")
* @var array
*/
protected $uri = [
'timelimtbuy:8099',
];
/**
* whether to user provider(consul/etcd/zookeeper)
*
* @var bool
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
* @var string
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
* @var string
*/
protected $provider = '';
}
<?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\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Bean\Annotation\Value;
use Swoft\Pool\PoolProperties;
/**
* the config of service user
*
* @Bean()
*/
class AuthPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_AUTH_URI', 'auth:8099'));
}
/**
* the name of pool
*
*/
protected $name = 'auth';
/**
* Minimum active number of connections
*
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
*
*/
protected $uri = [
"auth:8099",
// "172.21.0.19:8099",
// "172.16.255.39:8099"
];
/**
* whether to user provider(consul/etcd/zookeeper)
*
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
*/
protected $provider = '';
}
<?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\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Pool\PoolProperties;
use Swoft\Bean\Annotation\Value;
/**
* @Bean()
* the config of service bargain
*/
class BargainPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_BARGAIN_URI', 'bargain:8099'));
}
protected $name = 'bargain';
/**
* Minimum active number of connections
*
* @var int
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
* @var int
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
* @var int
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
* @var int
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
* @var int
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
* @var int
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
* @Value(name="", env="${RPC_BARGAIN_URI}")
* @var array
*/
protected $uri = [
'bargain:8099'
];
/**
* whether to user provider(consul/etcd/zookeeper)
*
* @var bool
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
* @var string
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
* @var string
*/
protected $provider = '';
}
......@@ -21,6 +21,13 @@ use Swoft\Pool\PoolProperties;
*/
class BuyerPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_BUYER_URI', 'buyer:8099'));
}
/**
* the name of pool
*
......@@ -61,7 +68,7 @@ class BuyerPoolConfig extends PoolProperties
* the time of connect timeout
*
*/
protected $timeout = 5;
protected $timeout = 200;
/**
* the addresses of connection
......@@ -75,8 +82,7 @@ class BuyerPoolConfig extends PoolProperties
*
*/
protected $uri = [
"172.21.0.12:8099",
"172.16.255.33:8099"
"buyer:8099",
];
/**
......
<?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\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Pool\PoolProperties;
/**
* the config of service coupon
*
* @Bean()
*/
class CouponPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_COUPON_URI', 'coupon:8099'));
}
protected $name = 'coupon';
/**
* Minimum active number of connections
*
* @var int
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
* @var int
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
* @var int
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
* @var int
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
* @var int
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
* @var int
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
* @var array
*/
protected $uri = [];
/**
* whether to user provider(consul/etcd/zookeeper)
*
* @var bool
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
* @var string
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
* @var string
*/
protected $provider = '';
}
<?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\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Pool\PoolProperties;
/**
* the config of service craftsman
*
* @Bean()
*/
class CraftsmanPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_CRAFTSMAN_URI', 'craftsman:8099'));
}
protected $name = 'craftsman';
/**
* Minimum active number of connections
*
* @var int
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
* @var int
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
* @var int
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
* @var int
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
* @var int
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
* @var int
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
* @var array
*/
protected $uri = [];
/**
* whether to user provider(consul/etcd/zookeeper)
*
* @var bool
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
* @var string
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
* @var string
*/
protected $provider = '';
}
......@@ -20,8 +20,15 @@ use Swoft\Pool\PoolProperties;
*/
class GoodsPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
// $this->uri = explode(',', env('RPC_GOODS_URI', '172.21.0.47:8099,172.16.255.235:8099'));
$this->uri = explode(',', env('RPC_GOODS_URI', 'goods:8099'));
}
protected $name = 'seller';
protected $name = 'seller';
/**
* Minimum active number of connections
......@@ -63,7 +70,7 @@ class GoodsPoolConfig extends PoolProperties
*
* @var int
*/
protected $timeout = 5;
protected $timeout = 200;
/**
* the addresses of connection
......
<?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\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Pool\PoolProperties;
/**
* the config of service user
*
* @Bean()
*/
class GroupBookingPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
// $this->uri = explode(',', env('RPC_GROUPBOOKING_URI', '172.21.0.38:8099,172.16.255.27:8099'));
$this->uri = explode(',', env('RPC_GROUPBOOKING_URI', 'group-booking:8099'));
}
protected $name = 'groupBooking';
/**
* Minimum active number of connections
*
* @var int
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
* @var int
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
* @var int
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
* @var int
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
* @var int
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
* @var int
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
*
* @var array
*/
protected $uri = [
'192.168.3.39:8200',
];
/**
* whether to user provider(consul/etcd/zookeeper)
*
* @var bool
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
* @var string
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
* @var string
*/
protected $provider = '';
}
<?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\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Bean\Annotation\Value;
use Swoft\Pool\PoolProperties;
/**
* the config of service user
*
* @Bean()
*/
class NoticePoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_NOTICE_URI', 'notice:8099'));
}
/**
* the name of pool
*
*/
protected $name = 'pay';
/**
* Minimum active number of connections
*
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
*
*/
protected $uri = [
"192.168.3.100:8102",
];
/**
* whether to user provider(consul/etcd/zookeeper)
*
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
*/
protected $provider = '';
}
......@@ -19,6 +19,12 @@ use Swoft\Pool\PoolProperties;
*/
class OrderPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_ORDER_URI', 'order:8099'));
}
protected $name = 'order';
......@@ -27,7 +33,7 @@ class OrderPoolConfig extends PoolProperties
*
* @var int
*/
protected $minActive = 5;
protected $minActive = 15;
/**
* the maximum number of active connections
......@@ -62,7 +68,7 @@ class OrderPoolConfig extends PoolProperties
*
* @var int
*/
protected $timeout = 5;
protected $timeout = 200;
/**
* the addresses of connection
......@@ -77,7 +83,7 @@ class OrderPoolConfig extends PoolProperties
* @var array
*/
protected $uri = [
'192.168.3.100:8084',
'order:8099',
];
/**
......
<?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\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Bean\Annotation\Value;
use Swoft\Pool\PoolProperties;
/**
* the config of service user
*
* @Bean()
*/
class PayPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_PAY_URI', 'pay:8099'));
}
/**
* the name of pool
*
*/
protected $name = 'pay';
/**
* Minimum active number of connections
*
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
*
*/
protected $uri = [
"192.168.3.100:8102",
];
/**
* whether to user provider(consul/etcd/zookeeper)
*
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
*/
protected $provider = '';
}
<?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\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Pool\PoolProperties;
/**
* the config of service user
*
* @Bean()
*/
class ReservationPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_RESERVATION_URI', 'reservation:8099'));
}
protected $name = 'reservation';
/**
* Minimum active number of connections
*
* @var int
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
* @var int
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
* @var int
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
* @var int
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
* @var int
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
* @var int
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
* @var array
*/
protected $uri = [];
/**
* whether to user provider(consul/etcd/zookeeper)
*
* @var bool
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
* @var string
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
* @var string
*/
protected $provider = '';
}
<?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\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Pool\PoolProperties;
/**
* the config of service user
*
* @Bean()
*/
class SchedulePoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_SCHEDULE_URI', 'schedule:8099'));
}
protected $name = 'schedule';
/**
* Minimum active number of connections
*
* @var int
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
* @var int
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
* @var int
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
* @var int
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
* @var int
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
* @var int
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
* @var array
*/
protected $uri = [];
/**
* whether to user provider(consul/etcd/zookeeper)
*
* @var bool
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
* @var string
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
* @var string
*/
protected $provider = '';
}
......@@ -21,6 +21,13 @@ use Swoft\Pool\PoolProperties;
class SellerDistributionPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_SELLER_DISTRIBUTION_URI', 'seller-distribution:8099'));
// $this->uri = explode(',', env('RPC_SELLER_DISTRIBUTION_URI', '172.21.0.17:8099,172.16.255.34:8099'));
}
protected $name = 'sellerDistribution';
/**
......@@ -63,7 +70,7 @@ class SellerDistributionPoolConfig extends PoolProperties
*
* @var int
*/
protected $timeout = 5;
protected $timeout = 200;
/**
* the addresses of connection
......
......@@ -21,6 +21,12 @@ use Swoft\Pool\PoolProperties;
class SellerPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_SELLER_URI', 'seller:8099'));
}
protected $name = 'seller';
/**
......@@ -63,7 +69,7 @@ class SellerPoolConfig extends PoolProperties
*
* @var int
*/
protected $timeout = 5;
protected $timeout = 200;
/**
* the addresses of connection
......@@ -78,7 +84,7 @@ class SellerPoolConfig extends PoolProperties
* @var array
*/
protected $uri = [
'192.168.3.39:8099',
'192.168.3.39:8099'
];
/**
......
<?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\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Pool\PoolProperties;
use Swoft\Bean\Annotation\Value;
/**
* @Bean()
* the config of service bargain
*/
class StateLessPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_STATELESS_URI', 'stateless:8099'));
}
protected $name = 'stateless';
/**
* Minimum active number of connections
*
* @var int
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
* @var int
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
* @var int
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
* @var int
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
* @var int
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
* @var int
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
* @Value(name="", env="${RPC_BARGAIN_URI}")
* @var array
*/
protected $uri = [
'172.21.0.34:8099',
'172.16.255.241:8099',
];
/**
* whether to user provider(consul/etcd/zookeeper)
*
* @var bool
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
* @var string
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
* @var string
*/
protected $provider = '';
}
......@@ -20,6 +20,11 @@ use Swoft\Pool\PoolProperties;
*/
class StorePoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_STORE_URI', 'store:8099'));
}
protected $name = 'storeId';
......@@ -63,7 +68,7 @@ class StorePoolConfig extends PoolProperties
*
* @var int
*/
protected $timeout = 5;
protected $timeout = 200;
/**
* the addresses of connection
......@@ -74,12 +79,9 @@ class StorePoolConfig extends PoolProperties
* '127.0.0.1:88'
* ]
* </pre>
*
* @var array
*/
protected $uri = [
'192.168.3.23:8098',
];
protected $uri = [];
/**
* whether to user provider(consul/etcd/zookeeper)
......
<?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\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Pool\PoolProperties;
use Swoft\Bean\Annotation\Value;
/**
* @Bean()
* the config of service bargain
*/
class TimeLimitBuyPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
$this->uri = explode(',', env('RPC_TIMELIMITBUY_URI', 'timelimitbuy:8099'));
}
protected $name = 'timelimitname';
/**
* Minimum active number of connections
*
* @var int
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
* @var int
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
* @var int
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
* @var int
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
* @var int
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
* @var int
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
* @Value(name="", env="${RPC_BARGAIN_URI}")
* @var array
*/
protected $uri = [
'timelimtbuy:8099',
];
/**
* whether to user provider(consul/etcd/zookeeper)
*
* @var bool
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
* @var string
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
* @var string
*/
protected $provider = '';
}
<?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\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Pool\PoolProperties;
/**
* the config of service WithdrawCash
*
* @Bean()
*/
class TransferPoolConfig extends PoolProperties
{
public function __construct()
{
$this->uri=explode(',',env('RPC_TRANSFER_URI','transfer:8099'));
}
protected $name = 'transfer';
/**
* Minimum active number of connections
*
* @var int
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
* @var int
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
* @var int
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
* @var int
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
* @var int
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
* @var int
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
*
* @var array
*/
protected $uri = [];
/**
* whether to user provider(consul/etcd/zookeeper)
*
* @var bool
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
* @var string
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
* @var string
*/
protected $provider = '';
}
......@@ -21,6 +21,13 @@ use Swoft\Pool\PoolProperties;
class VipPoolConfig extends PoolProperties
{
public function __construct()
{
// 区别本地和线上的RPC服务地址
// $this->uri = explode(',', env('RPC_VIP_URI', '172.21.0.10:8099,172.16.255.196:8099'));
$this->uri = explode(',', env('RPC_VIP_URI', 'vip:8099'));
}
protected $name = 'seller';
/**
......@@ -63,7 +70,7 @@ class VipPoolConfig extends PoolProperties
*
* @var int
*/
protected $timeout = 5;
protected $timeout = 200;
/**
* the addresses of connection
......
<?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\Common\Pool\Config;
use Swoft\Bean\Annotation\Bean;
use Swoft\Pool\PoolProperties;
/**
* the config of service WithdrawCash
*
* @Bean()
*/
class WithdrawCashPoolConfig extends PoolProperties
{
public function __construct()
{
$this->uri=explode(',',env('RPC_WITHDRAWCASH_URI','draw-money:8099'));
}
protected $name = 'withdrawCash';
/**
* Minimum active number of connections
*
* @var int
*/
protected $minActive = 5;
/**
* the maximum number of active connections
*
* @var int
*/
protected $maxActive = 50;
/**
* the maximum number of wait connections
*
* @var int
*/
protected $maxWait = 100;
/**
* Maximum waiting time
*
* @var int
*/
protected $maxWaitTime = 3;
/**
* Maximum idle time
*
* @var int
*/
protected $maxIdleTime = 60;
/**
* the time of connect timeout
*
* @var int
*/
protected $timeout = 200;
/**
* the addresses of connection
*
* <pre>
* [
* '127.0.0.1:88',
* '127.0.0.1:88'
* ]
* </pre>
*
* @var array
*/
protected $uri = [];
/**
* whether to user provider(consul/etcd/zookeeper)
*
* @var bool
*/
protected $useProvider = false;
/**
* the default balancer is random balancer
*
* @var string
*/
protected $balancer = '';
/**
* the default provider is consul provider
*
* @var string
*/
protected $provider = '';
}
<?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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/8/24
* Time: 15:28
*/
namespace Hdll\Services\Coupon\Enum;
class CouponEnum
{
// 优惠券状态:
const STATE_NOT_USED = 1; // 表示优惠券还未使用
const STATE_ORDER_HOLD = 2; // 表示订单下单时已占用,但还未真正使用
const STATE_USED = 3; // 表示优惠券已被使用
}
\ 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\Coupon\Lib;
use Swoft\Core\ResultInterface;
/**
* The interface of coupon service
*
* @method ResultInterface deferCheckCoupon(int $buyerId, int $storeId, int $couponId, int $itemId)
* @method ResultInterface deferGetCouponRecvdList(int $buyerId, int $storeId, int $subStoreId = 0, int $itemId = 0)
* @method ResultInterface deferGetDataByCouponId(int $buyerId, int $storeId, int $couponId)
*/
interface CouponInterface
{
// 优惠券服务的字段说明:
// storeId
// subStoreId
// buyerId 买家ID
// state 状态,1未使用,2已下单还未付款,3已使用过
// couponId 当时领取的原始优惠券Id
// couponName 当时领取的原始优惠券名字
// parValue 优惠券面值
// allowItems 优惠券允许使用的商品列表
// addTime 领取时间
// usedTime 被使用的时间
/**
* 校验优惠券是否可用
*
* @param integer $buyerId
* @param integer $storeId
* @param integer $couponId
* @param integer $itemId
* @return int|boolen 如果可用返回优惠券的面值,不可用返回false
*/
public function checkCoupon(int $buyerId, int $storeId, int $couponId, int $itemId);
/**
* 更新优惠券状态
*
* @param integer $buyerId
* @param integer $storeId
* @param integer $couponId
* @param integer $state 优惠券的状态
* @return int 返回受影响的行数
*/
public function updateCouponState(int $buyerId, int $storeId, int $couponId, int $state);
/**
* 获取顾客领取的优惠券列表
*
* @param integer $buyerId
* @param integer $storeId
* @param integer $subStoreId
* @param integer $itemId
* @return array
*/
public function getCouponRecvdList(int $buyerId, int $storeId, int $subStoreId = 0, int $itemId = 0);
/**
* 根据优惠券ID获取信息
*
* @param integer $buyerId
* @param integer $storeId
* @param integer $couponId
* @return array
*/
public function getDataByCouponId(int $buyerId, int $storeId, int $couponId);
}
\ 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\Craftsman\Lib;
use Swoft\Core\ResultInterface;
/**
* The interface of craftsman service
*
* @method ResultInterface deferGetCraftsmenList(int $storeId, int $subStoreId = 0, int $itemId = 0)
* @method ResultInterface deferGetCraftsmenByUnionId(string $unionId)
* @method ResultInterface deferGetCraftsmenById(int $storeId, int $cmanId)
*/
interface CraftsmanInterface
{
// 店员服务的字段说明:
// name 店员名字
// sex 性别
// mobile 店员手机
// inReview 审核状态,1审核中,2审核通过
// headimg 店员头像
// items 服务项目id列表,逗号隔开
// subStores 子店铺id列表,逗号隔开
// motto 个人签名
// adept 个人擅长说明
// wechat 店员微信号
/**
* 获取店员列表
*
* @param integer $storeId
* @param integer $subStoreId 子店铺Id
* @param integer $itemId 服务项目(商品)id
*
* @return array
*/
public function getCraftsmenList(int $storeId, int $subStoreId = 0, int $itemId = 0);
/**
* 根据unionId获取店员信息
*
* @param string $unionId
* @return array
*/
public function getCraftsmenByUnionId(string $unionId);
/**
* 根据店铺Id和店员Id获取店员信息
*
* @param integer $storeId
* @param integer $cmanId
* @return array
*/
public function getCraftsmenById(int $storeId, int $cmanId);
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/26
* Time: 9:38
*/
namespace Hdll\Services\Feedback\Enum;
class FeedbackEnum
{
const ORIGIN_BUYER = 1; //前台反馈
const ORIGIN_SELLER = 2; //后台反馈
const ORIGINS = [
self::ORIGIN_BUYER,
self::ORIGIN_SELLER,
];
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/26
* Time: 9:42
*/
namespace Hdll\Services\Feedback\Enum;
class ReplyEnum
{
const ORIGIN_USER = 1; //用户回复
const ORIGIN_ADMIN = 2; //管理员回复
const ORIGINS = [
self::ORIGIN_USER,
self::ORIGIN_ADMIN
];
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/8/20
* Time: 15:48
*/
namespace Hdll\Services\Goods\Enum;
class AuthEnum
{
const EVERYONE = 0;//任何人
const BUYER = 1;//买家
const CRAFTSMAN = 2;//手艺人
const SELLER = 3;//卖家
const ADMIN = 4;//管理员
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/26
* Time: 16:00
*/
namespace Hdll\Services\Goods\Enum;
class GoodsEnum{
const ON_OFFER = 0;//出售中
const SOLD_OUT = 1;//下架
const SELL_OUT = 2;//售完
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/26
* Time: 16:00
*/
namespace Hdll\Services\Goods\Enum;
class GoodsEvaluateEnum{
const GOOD = 1;//好评
const MEDIUM = 2;//中评
const BAD = 3;//差评
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/26
* Time: 16:00
*/
namespace Hdll\Services\Goods\Enum;
class StarEnum
{
const STAR = 1;//点赞
const CANCEL = 2;//取消点赞
const HAS_START_KEY = 'hasStar';
const STAR_KEY = 'star';
}
\ No newline at end of file
......@@ -11,29 +11,76 @@ namespace Hdll\Services\Goods\Lib;
use Swoft\Core\ResultInterface;
/**
* @method ResultInterface deferGet($storeId,$id)
* @method ResultInterface deferGetList($storeId,$page,$limit)
* @method ResultInterface deferGet($storeId, $id)
* @method ResultInterface deferIncSales($storeId, $goodsId)
* @method ResultInterface deferDecSales($storeId, $goodsId)
* @method ResultInterface deferGetServiceByGoodsId($storeId, $goodsId)
* @method ResultInterface deferGetReturnVisitByGoodsId($storeId, $goodsId)
* Interface GoodsInterface
* @package Hdll\Services\Goods\Lib
*/
interface GoodsInterface{
interface GoodsInterface
{
/**
* 获取商品
* @param $storeId
* @return [
* 'gcId' 商品类ID
* 'asId' 服务ID
* 'stock' 库存
* 'name' 名称
* 'image' 图片
* 'price' 价格
* 'state' 状态
* 'body' 描述
* 'originalPrice' 原价
* 'sales' 销量
* ]
* @param $id
* @return mixed
* @author Administrator
*/
public function get($storeId,$id);
public function get($storeId, $id);
/**
* 增加商品销量
* 减少商品库存
* @param $storeId
* @param $goodsId
* @return mixed
* @author Administrator
*/
public function incSales($storeId, $goodsId);
/**
* 减少商品销量
* 增加商品库存
* @param $storeId
* @param $goodsId
* @return mixed
* @author Administrator
*/
public function decSales($storeId, $goodsId);
/**
* 获取商品服务
* @param $storeId
* @param $goodsId
* @return mixed
* @author Administrator
*/
public function getServiceByGoodsId($storeId,$goodsId);
/**
* 获取商品列表
* 获取用户回访
* @param $storeId
* @param $page
* @param $limit
* @param $goodsId
* @return mixed
* @author Administrator
*/
public function getList($storeId,$page,$limit);
public function getReturnVisitByGoodsId($storeId, $goodsId);
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/8/20
* Time: 15:48
*/
namespace Hdll\Services\GroupBooking\Enum;
class AuthEnum
{
const EVERYONE = 0;//任何人
const BUYER = 1;//买家
const CRAFTSMAN = 2;//手艺人
const SELLER = 3;//卖家
const ADMIN = 4;//管理员
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/8/8
* Time: 17:20
*/
namespace Hdll\Services\GroupBooking\Enum;
class BranchEnum
{
const START_NOT_PAY = 10;//发起未支付
const START_PAY = 20;//发起已支付
const REACH = 30;//达成条件
const CLOSE= 40;//关闭
const REDIS_ACTIVITY_KEY = "groupBooking";
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/8/8
* Time: 17:20
*/
namespace Hdll\Services\GroupBooking\Enum;
class GroupBookingEnum
{
const ACTIVITY_NOT_START = 1;//未开始
const ACTIVITY_ON = 2;//已开始
const ACTIVITY_OFF = 3;//已结束
const ONLINE = 1;//上线
const DOWNLINE = 2;//下线
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/8/8
* Time: 17:20
*/
namespace Hdll\Services\GroupBooking\Enum;
class RecordEnum
{
const START_NOT_PAY = 10;//未支付
const START_PAY = 20;//已支付
const CLOSED = 30;//已关闭
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/8/8
* Time: 10:43
*/
namespace Hdll\Services\GroupBooking\Lib;
use Swoft\Core\ResultInterface;
/**
* @method ResultInterface deferPaySuccess($orderId)
* @method ResultInterface deferHasActivity($storeId,$goodsId)
* Interface GoodsInterface
* @package Hdll\Services\Goods\Lib
*/
interface GroupBookingInterface{
public function paySuccess($orderId,$storeId);
public function hasActivity($storeId,$goodsId);
/**
* 关闭拼团
* @param $storeId
* @param $buyerId
* @param $orderId
* @return mixed
* @author Administrator
*/
public function closeRecord($storeId, $buyerId, $orderId);
}
\ No newline at end of file
......@@ -14,8 +14,4 @@ class LimitTimeBuyEnum
//订单状态
const STATUS_NORMAL = 10; //待支付
}
\ No newline at end of file
<?php
namespace Hdll\Services\LimitTimeBuy\Enum;
class LimitTimeOrderEnum
{
//订单状态
const STATUS_NORMAL = 1; //待支付 1未支付2已经支付3异常
const STATUS_HAVE_PAY =2; // 已经支付
const STATUS_PAY_EXCEPTION =3; // 支付异常或过期未付
const STATUS_PAY_REFUND =4 ; // 退款
}
\ No newline at end of file
......@@ -10,13 +10,13 @@
namespace Hdll\Services\LimitTimeBuy\Lib;
use Hdll\Services\LimitTimeBuy\Enum\LimitTimeOrderEnum;
use Swoft\Core\ResultInterface;
/**
* The interface of demo service
*
* @method ResultInterface deferBackNum(string $token, int $consignee_id, int $limit_id, int $selected_num, int $order_type, int $goods_id, string $reservation_time = '')
*/
interface LimitTimeBuyInterface
{
......@@ -39,5 +39,46 @@ interface LimitTimeBuyInterface
int $selected_num,
int $order_type,
int $goods_id,
string $reservation_time = '');
string $reservation_time);
/**
* 获取限时购商品的 商品信息
* @param int $limit_id
* @return {
* "name" 名称
* "image" 图片
* "price" 价格
* "activityName" 活动名称
* }
*/
public function getLimitGoods(
int $storeId, int $limitId
);
/**
* 通过商品id 获取是否 有限时购活动
* @param int $storeId
* @param int $goodsId
* @return bool
*
*/
public function getLimitInfo(
int $storeId, int $goodsId
);
/**
* 支付 状态 回馈接口
* @param string $store_id
* @param int $limit_id
* @param int $status // 2.LimitTimeOrderEnum::STATUS_HAVE_PAY 成功支付 3:LimitTimeOrderEnum::STATUS_PAY_EXCEPTION 未支付 (已经过期或者支付异常)4 LimitTimeOrderEnum::STATUS_PAY_REFUND 退款
* @param int $orderId
* @return bool|mixed
* @throws ConException
*/
public function payStatus(
string $store_id,
int $limit_id,
int $status,
int $orderId);
}
\ No newline at end of file
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