更新:获取关联认证的商家信息
parent
edb870b4d6
commit
f55272ed06
|
@ -7,7 +7,11 @@ use app\repository\BusinessRepository;
|
||||||
use app\repository\DictionaryRepository;
|
use app\repository\DictionaryRepository;
|
||||||
use app\validate\BusinessValidate;
|
use app\validate\BusinessValidate;
|
||||||
use think\exception\ValidateException;
|
use think\exception\ValidateException;
|
||||||
use app\model\Business as BusinessModel;
|
use app\model\{
|
||||||
|
Business as BusinessModel,
|
||||||
|
Account as AccountModel
|
||||||
|
};
|
||||||
|
use think\response\Json;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商家端:商家
|
* 商家端:商家
|
||||||
|
@ -122,5 +126,76 @@ class Business extends Base
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前账号所属商家的信息
|
||||||
|
* 适用范围:商户账号 或 商户员工账号
|
||||||
|
*/
|
||||||
|
public function getMyBusinessInfo()
|
||||||
|
{
|
||||||
|
$accountId = $this->request->user['user_id'] ?? 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$account = AccountRepository::getInstance()->findById($accountId, [], function ($q) {
|
||||||
|
return $q->with(['business', 'parent']);
|
||||||
|
});
|
||||||
|
if (empty($account)) {
|
||||||
|
return $this->json(4004, '无效请求!');
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
if ($account['type'] == AccountModel::type_staff) {
|
||||||
|
// 员工账号
|
||||||
|
$businessCode = $account['parent']['business_code'] ?? '';
|
||||||
|
if (!empty($businessCode)) {
|
||||||
|
$business = BusinessRepository::getInstance()->findOneByWhere(['code' => $businessCode]);
|
||||||
|
if ($business) {
|
||||||
|
$result = $business->toArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = arrayKeysExcludeFilter($result, ['pay_account', 'total_recharge']);
|
||||||
|
|
||||||
|
} elseif(!empty($account['business'])) {
|
||||||
|
// 商户认证信息
|
||||||
|
$result = $account['business']->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($result)) {
|
||||||
|
$result = DictionaryRepository::getInstance()->parseAreaText($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = arrayKeysExcludeFilter($result, ['update_time']);
|
||||||
|
return $this->json(0, 'success', $result);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->json(5001, '商家信息查询失败!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取商家信息(已认证通过的商户)
|
||||||
|
* @return Json
|
||||||
|
*/
|
||||||
|
public function getBusinessInfo()
|
||||||
|
{
|
||||||
|
$businessCode = $this->request->param('businessCode/s', '');
|
||||||
|
|
||||||
|
$busRepo = BusinessRepository::getInstance();
|
||||||
|
try {
|
||||||
|
$business = $busRepo->findOneByWhere(['code' => $businessCode, 'state' => BusinessModel::state_on]);
|
||||||
|
if (empty($business)) {
|
||||||
|
return $this->json(4004, '没有相关的商户!');
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = $business->toArray();
|
||||||
|
$list = DictionaryRepository::getInstance()->parseAreaText($list);
|
||||||
|
$disableFields = ['is_delete', 'update_time', 'total_recharge', 'balance', 'is_assign', 'agency_code',
|
||||||
|
'reason', 'pay_account', 'business_license'
|
||||||
|
];
|
||||||
|
$result = arrayKeysExcludeFilter($list, $disableFields);
|
||||||
|
return $this->json(0, 'success', $result);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->json(5004, '商家信息查询失败!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ namespace app\controller\api;
|
||||||
use app\exception\RepositoryException;
|
use app\exception\RepositoryException;
|
||||||
use app\model\Account;
|
use app\model\Account;
|
||||||
use app\repository\AccountRepository;
|
use app\repository\AccountRepository;
|
||||||
|
use app\repository\BusinessRepository;
|
||||||
use app\repository\CouponRepository;
|
use app\repository\CouponRepository;
|
||||||
use app\service\File;
|
use app\service\File;
|
||||||
use app\service\Jwt;
|
use app\service\Jwt;
|
||||||
|
@ -132,6 +133,7 @@ class User extends Base
|
||||||
try {
|
try {
|
||||||
$accountRepo = AccountRepository::getInstance();
|
$accountRepo = AccountRepository::getInstance();
|
||||||
$couponRepo = CouponRepository::getInstance();
|
$couponRepo = CouponRepository::getInstance();
|
||||||
|
$busRepo = BusinessRepository::getInstance();
|
||||||
|
|
||||||
$account = $accountRepo->findById($accountId, [], function ($q) {
|
$account = $accountRepo->findById($accountId, [], function ($q) {
|
||||||
return $q->with(['business', 'parent']);
|
return $q->with(['business', 'parent']);
|
||||||
|
@ -174,26 +176,44 @@ class User extends Base
|
||||||
'couponCount' => $couponCount,
|
'couponCount' => $couponCount,
|
||||||
];
|
];
|
||||||
|
|
||||||
// 商户认证记录
|
|
||||||
if (!empty($account['business'])) {
|
if ($account['type'] == Account::type_staff) {
|
||||||
|
// 员工
|
||||||
|
$businessCode = $account['parent']['business_code'] ?? '';
|
||||||
|
if (!empty($businessCode)) {
|
||||||
|
$business = $busRepo->findOneByWhere(['code' => $businessCode]);
|
||||||
|
if ($business) {
|
||||||
|
$personalRes['business'] = [
|
||||||
|
'code' => $business['code'],
|
||||||
|
'businessName' => $business['business_name'],
|
||||||
|
'state' => $business['state'],
|
||||||
|
'reason' => $business['reason'],
|
||||||
|
'balance' => $business['balance'],
|
||||||
|
'enable' => $business['enable'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$personalRes['parent'] = [];
|
||||||
|
if (!empty($account['parent'])) {
|
||||||
|
$personalRes['parent'] = [
|
||||||
|
'avatar' => File::convertCompleteFileUrl($account['parent']['avatar_url']),
|
||||||
|
'nickName' => $account['parent']['nick_name'],
|
||||||
|
'userType' => $account['parent']['type'],
|
||||||
|
'userTypeDes' => Account::accountTypeDescList()[$account['parent']['type']] ?? '',
|
||||||
|
'couponCount' => 0,
|
||||||
|
'businessCode' => $account['parent']['business_code'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif(!empty($account['business'])) {
|
||||||
|
// 商户认证记录
|
||||||
$personalRes['business'] = [
|
$personalRes['business'] = [
|
||||||
'state' => $account['business']['state'],
|
'state' => $account['business']['state'],
|
||||||
'reason' => $account['business']['reason'],
|
'reason' => $account['business']['reason'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 员工
|
|
||||||
if ($account['type'] == Account::type_staff && !empty($account['parent'])) {
|
|
||||||
$personalRes['parent'] = [
|
|
||||||
'avatar' => File::convertCompleteFileUrl($account['parent']['avatar_url']),
|
|
||||||
'nickName' => $account['parent']['nick_name'],
|
|
||||||
'userType' => $account['parent']['type'],
|
|
||||||
'userTypeDes' => Account::accountTypeDescList()[$account['parent']['type']] ?? '',
|
|
||||||
'couponCount' => 0,
|
|
||||||
'businessCode' => $account['parent']['business_code'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->json(0, 'success', $personalRes);
|
return $this->json(0, 'success', $personalRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
namespace app\repository;
|
namespace app\repository;
|
||||||
|
|
||||||
|
|
||||||
|
use app\model\Area;
|
||||||
use app\model\BusinessCircle;
|
use app\model\BusinessCircle;
|
||||||
use app\model\Category;
|
use app\model\Category;
|
||||||
use app\model\Model;
|
use app\model\Model;
|
||||||
|
@ -100,4 +101,52 @@ class DictionaryRepository extends Repository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 省市区地址配置数据
|
||||||
|
*/
|
||||||
|
public function findAreaList(array $where = [])
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return Area::where($where)->select();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return new Collection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过地址编号查询地址信息
|
||||||
|
* @param string $areaCode
|
||||||
|
* @return Area|array|\think\Model|null
|
||||||
|
*/
|
||||||
|
public function findAreaInfo(string $areaCode)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return Area::where('code', $areaCode)->find();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析地址编码
|
||||||
|
* [province, city, county]
|
||||||
|
*/
|
||||||
|
public function parseAreaText(array $list, array $areaList = []): array
|
||||||
|
{
|
||||||
|
if (empty($list)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($areaList)) {
|
||||||
|
$areaList = $this->findAreaList()->column('name', 'code');
|
||||||
|
}
|
||||||
|
|
||||||
|
$list['province_text'] = (!isset($list['province']) || empty($list['province'])) ? '' : ($areaList[$list['province']] ?? '');
|
||||||
|
$list['city_text'] = (!isset($list['city']) || empty($list['city'])) ? '' : ($areaList[$list['city']] ?? '');
|
||||||
|
$list['county_text'] = (!isset($list['county']) || empty($list['county'])) ? '' : ($areaList[$list['county']] ?? '');
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue