Commit fe82acd3 by feixiang

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

parents 882123a4 5a70340f
# 1.0.49
- 添加配置读取类
# 1.0.48
- 添加卖家关系保存接口
# 1.0.47
- 商品服务接口修改
# 1.0.46
......
......@@ -8,7 +8,8 @@
}
],
"require": {
"qcloud/cos-sdk-v5": ">=1.0"
"qcloud/cos-sdk-v5": ">=1.0",
"catfan/medoo": "^1.6"
},
"autoload": {
"psr-4": {
......
#线上环境公共配置项:
<?php
namespace Hdll\Services\Common\Config;
use Swoft\Redis\Redis;
use Swoft\App;
class CfgCenter
{
/**
* 读取指定的配置项
* (所有配置项,需预先添加到数据库中)
* 方法一:
* $value = CfgCenter::get('qCloud>Weapp>Region');
* var_dump($value); // 输出:ap-shanghai
* 方法二:
* $cfgdata = CfgCenter::get('qCloud');
* var_dump($cfgdata->Weapp->Region); // 输出:ap-shanghai
*
* @param string $keyStr
* @return mixed
*/
public static function get($keyStr)
{
$keyArr = self::parseKeyStr($keyStr);
$rkey = implode(":", $keyArr);
$redis = App::getBean(Redis::class);
$data = $redis->get("CONFIG_CENTER:".$rkey);
if($data === null) {
$res = self::dbFetch($keyStr);
if($res) {
if(is_object($res[1])) {
$val = json_encode($res[1]);
} else {
$val = $res[1];
}
$redis->set("CONFIG_CENTER:".$res[0], $val);
return $res[1];
}
}
$obj = json_decode($data);
if($obj && is_object($obj)) {
return $obj;
}
return $data;
}
protected static function dbFetch($keyStr)
{
$keyArr = self::parseKeyStr($keyStr);
$name = array_shift($keyArr);
$result = self::dbConnect()->select("config", ['name','value'], ['name'=>$name]);
if(!isset($result[0]['value'])) {
return;
}
$valObj = json_decode($result[0]['value']);
if(!is_object($valObj)) {
return;
}
$keys = '';
foreach($keyArr as $key) {
if(!isset($valObj->$key)) {
return;
}
$keys .= $key.':';
$valObj = $valObj->$key;
}
$rkey = $name.':'.trim($keys,':');
return [trim($rkey,':'), $valObj];
}
protected static function dbConnect()
{
if(\env('ENVIRONMENT', '') == '') {
// 返回线上数据库连接
return new \Medoo\Medoo([
'database_type' => 'mysql',
'database_name' => 'config_center',
'server' => '172.21.0.12',
'username' => 'configer',
'password' => 'Cfgsu#2390f*_',
'charset' => 'utf8'
]);
} else {
// 返回测试数据库连接
return new \Medoo\Medoo([
'database_type' => 'mysql',
'database_name' => 'config_center',
'server' => '192.168.3.202',
'username' => 'hdller',
'password' => 'Hdlltest888',
'charset' => 'utf8'
]);
}
}
protected static function parseKeyStr($keyStr)
{
$keyArr = explode(">", trim($keyStr, '>'));
foreach($keyArr as $k => $v) {
$v = trim($v);
if($v == "") {
unset($keyArr[$k]);
} else {
$keyArr[$k] = $v;
}
}
if(empty($keyArr)) {
throw new \Exception("[CfgCenter]未指定合法的Key");
}
return $keyArr;
}
}
<?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}',
],
],
];
......@@ -12,13 +12,14 @@ use Swoft\Core\ResultInterface;
/**
* @method ResultInterface deferSave($referId, $unionId, $openId, $nickName, $headImgUrl)
* @method ResultInterface deferGet($id,$fields=['*'])
* @method ResultInterface deferGetByUnionId($unionId,$fields=['*'])
* @method ResultInterface deferGetByStoreId($storeId,$fields=['*'])
* @method ResultInterface deferUpdate($id,$data)
* @method ResultInterface deferGet($id, $fields = ['*'])
* @method ResultInterface deferGetByUnionId($unionId, $fields = ['*'])
* @method ResultInterface deferGetByStoreId($storeId, $fields = ['*'])
* @method ResultInterface deferUpdate($id, $data)
* @method ResultInterface deferCountDistributionNum($sellerId)
* @method ResultInterface deferGetByIds(array $ids, $fields = ['*'])
* @method ResultInterface deferGetAndUpdateOpenId($unionId,$openId)
* @method ResultInterface deferGetAndUpdateOpenId($unionId, $openId)
* @method ResultInterface deferSaveRelation($sellerId)
* Interface SellerInterface
* @package App\Lib
*/
......@@ -44,7 +45,7 @@ interface SellerInterface
* @return mixed
* @author Administrator
*/
public function get($id,$fields=['*']);
public function get($id, $fields = ['*']);
/**
* @param $unionId
......@@ -52,7 +53,7 @@ interface SellerInterface
* @return mixed
* @author Administrator
*/
public function getByUnionId($unionId,$fields=['*']);
public function getByUnionId($unionId, $fields = ['*']);
/**
* @param $condition
......@@ -67,7 +68,7 @@ interface SellerInterface
* @return mixed
* @author Administrator
*/
public function update($condition,$data);
public function update($condition, $data);
/**
* @param $storeId
......@@ -83,5 +84,7 @@ interface SellerInterface
public function getByIds(array $ids, $fields = ['*']);
public function getAndUpdateOpenId($unionId,$openId);
public function getAndUpdateOpenId($unionId, $openId);
public function saveRelation($sellerId);
}
\ 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