Commit d14cc342 by xmy

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

parents 55e10d24 b1ba4950
......@@ -8,6 +8,9 @@
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;
......@@ -22,32 +25,36 @@ class Split
$map = array_flip($collector['map']);
}
//如果是实体且为分表实体
if (strpos($tableName, '\\') !== false && isset($collector[$tableName])) {
$className = $tableName;
$tableName = $collector[$tableName]['table'];
if ( ! self::isTesting() ) {
//如果是实体且为分表实体
if (strpos($tableName, '\\') !== false && isset($collector[$tableName])) {
$className = $tableName;
$tableName = $collector[$tableName]['table'];
$entityCollector = EntityCollector::getCollector();
$entityCollector = EntityCollector::getCollector();
//设置分表对应的className
EntityCollector::setCollector($tableName.'_'.self::getDbNum($className), $tableName);
//设置分表对应的className
EntityCollector::setCollector($tableName.'_'.self::getDbNum($className), $tableName);
//获取分表名
$tableName = $tableName.'_'.self::getDbNum($className);
//获取分表名
$tableName = $tableName.'_'.self::getDbNum($className);
//设置分表类型
$query->selectInstance($entityCollector[$className]['instance']);
//设置分表类型
$query->selectInstance($entityCollector[$className]['instance']);
} elseif ( isset($map[$tableName]) ) { //非实体且分表
$className = $map[$tableName];
$defaultTbleName = $tableName;
$tableName = $tableName.'_'.self::getDbNum($className);
//设置分表对应的className
EntityCollector::setCollector($tableName, $defaultTbleName);
} elseif ( isset($map[$tableName]) ) { //非实体且分表
$className = $map[$tableName];
$defaultTbleName = $tableName;
$tableName = $tableName.'_'.self::getDbNum($className);
//设置分表对应的className
EntityCollector::setCollector($tableName, $defaultTbleName);
}
}
return $tableName;
}
......@@ -57,6 +64,17 @@ class Split
$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,6 +11,7 @@
namespace Hdll\Services\Common\Entity;
use Hdll\Services\Auth\Enum\AuthError;
use Hdll\Services\Common\Enum\TestEnum;
use Hdll\Services\Common\Lib\Redis;
use Swoft\Bean\Annotation\Bean;
use Swoft\Core\RequestContext;
......@@ -35,6 +36,16 @@ class User
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->getValue('nickname');
......
<?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;
}
......@@ -18,6 +18,7 @@ use Swoft\Core\ResultInterface;
* @method ResultInterface deferIsCertified(int $storeId)
* @method ResultInterface deferGetStoreByStoreId(int $storeId)
* @method ResultInterface deferGetStoreBySellerId(int $sellerId)
* @method ResultInterface deferGetStoreByMobile(int $mobile, array $fields = [])
* @method ResultInterface deferUpdateStore(int $storeId, array $data)
* @method ResultInterface deferDeleteStore(int $storeId)
* @method ResultInterface deferGetWxacodeUrl(int $storeId, int $type, string $page, string $scene)
......@@ -49,6 +50,15 @@ interface StoreInterface
public function getStoreBySellerId(int $sellerId);
/**
* 根据注册手机号获取店铺信息
*
* @param integer $mobile
* @param array $fields 要查询的字段列表 :['id','storeName','addTime']
* @return array
*/
public function getStoreByMobile(int $mobile, array $fields = []);
/**
* 根据店铺ID修改店铺信息
*
* @param integer $storeId
......
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