Compare commits

..

No commits in common. "f55272ed06a03161cbdbe03515484edacec48f17" and "19e762187ca64e5dccea3b64bb0ed447ab3829e6" have entirely different histories.

4 changed files with 19 additions and 160 deletions

View File

@ -7,11 +7,7 @@ use app\repository\BusinessRepository;
use app\repository\DictionaryRepository;
use app\validate\BusinessValidate;
use think\exception\ValidateException;
use app\model\{
Business as BusinessModel,
Account as AccountModel
};
use think\response\Json;
use app\model\Business as BusinessModel;
/**
* 商家端:商家
@ -126,76 +122,5 @@ 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, '商家信息查询失败!');
}
}
}

View File

@ -112,6 +112,7 @@ class Dictionary extends Base
*/
public function getBusinessTypeList(): Json
{
$recursionChildren = $this->request->param('recursion/d', 0);
$pid = $this->request->param('pid/d', 0);
$whereMap = [];
@ -123,7 +124,9 @@ class Dictionary extends Base
$items = $repo->getBusinessTypeList($whereMap, [], null, ['pid'=>'asc']);
$list = $items->toArray();
if ($recursionChildren > 0) {
$list = $repo->recursionChildrenList($list, $pid, 'pid', 'id');
}
return $this->json(0, 'success', $list);
}

View File

@ -4,7 +4,6 @@ namespace app\controller\api;
use app\exception\RepositoryException;
use app\model\Account;
use app\repository\AccountRepository;
use app\repository\BusinessRepository;
use app\repository\CouponRepository;
use app\service\File;
use app\service\Jwt;
@ -133,7 +132,6 @@ class User extends Base
try {
$accountRepo = AccountRepository::getInstance();
$couponRepo = CouponRepository::getInstance();
$busRepo = BusinessRepository::getInstance();
$account = $accountRepo->findById($accountId, [], function ($q) {
return $q->with(['business', 'parent']);
@ -176,26 +174,16 @@ class User extends Base
'couponCount' => $couponCount,
];
if ($account['type'] == Account::type_staff) {
// 员工
$businessCode = $account['parent']['business_code'] ?? '';
if (!empty($businessCode)) {
$business = $busRepo->findOneByWhere(['code' => $businessCode]);
if ($business) {
// 商户认证记录
if (!empty($account['business'])) {
$personalRes['business'] = [
'code' => $business['code'],
'businessName' => $business['business_name'],
'state' => $business['state'],
'reason' => $business['reason'],
'balance' => $business['balance'],
'enable' => $business['enable'],
'state' => $account['business']['state'],
'reason' => $account['business']['reason'],
];
}
}
$personalRes['parent'] = [];
if (!empty($account['parent'])) {
// 员工
if ($account['type'] == Account::type_staff && !empty($account['parent'])) {
$personalRes['parent'] = [
'avatar' => File::convertCompleteFileUrl($account['parent']['avatar_url']),
'nickName' => $account['parent']['nick_name'],
@ -206,14 +194,6 @@ class User extends Base
];
}
} elseif(!empty($account['business'])) {
// 商户认证记录
$personalRes['business'] = [
'state' => $account['business']['state'],
'reason' => $account['business']['reason'],
];
}
return $this->json(0, 'success', $personalRes);
}

View File

@ -2,7 +2,6 @@
namespace app\repository;
use app\model\Area;
use app\model\BusinessCircle;
use app\model\Category;
use app\model\Model;
@ -101,52 +100,4 @@ 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;
}
}