From 407a7bf21d0be117b470179d84a7b674cf9c76f6 Mon Sep 17 00:00:00 2001 From: zwesy Date: Thu, 2 Dec 2021 10:49:50 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E5=95=86=E5=AE=B6=E8=AE=A4=E8=AF=81=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=B8=BA1=E4=B8=AA=E7=BB=9F=E4=B8=80=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Business.php | 124 ++++-------------------------- app/model/Business.php | 13 +--- app/validate/BusinessValidate.php | 10 +-- 3 files changed, 17 insertions(+), 130 deletions(-) diff --git a/app/controller/api/Business.php b/app/controller/api/Business.php index 3712ab1..df2527c 100644 --- a/app/controller/api/Business.php +++ b/app/controller/api/Business.php @@ -18,14 +18,11 @@ use app\model\Business as BusinessModel; class Business extends Base { /** - * 商家注册 - * - * 方式1:注册为自然商家 - * 由系统后台工作人员审核 + * 商家认证注册 * * 重新编辑注册则覆盖之前的审核信息,并重新进行审核 */ - public function registerByNormal() + public function registerBusiness() { $params = [ 'type'=> $this->request->param('type/d', 0), @@ -41,6 +38,7 @@ class Business extends Base 'county'=> $this->request->param('county', ''), 'business_address' => $this->request->param('business_address', ''), 'business_circle_id' => $this->request->param('business_circle_id/d', 0), + 'agency_code' => $this->request->param('agency_code', ''), ]; $accountId = $this->request->user['user_id'] ?? 0; @@ -57,7 +55,7 @@ class Business extends Base throw new ValidateException('无效请求!'); } - if (!$validate->scene('registerByNormal')->check($params)) { + if (!$validate->scene('apiRegister')->check($params)) { throw new ValidateException($validate->getError()); } @@ -74,6 +72,15 @@ class Business extends Base $params['business_circle'] = $businessCircle['name']; } + if (!empty($params['agency_code'])) { + $agencyBusiness = $busRepo->findOneByWhere(['code'=> $params['agency_code'], 'is_agency'=> self::BOOL_TRUE, 'state' => BusinessModel::state_on]); + if (empty($agencyBusiness) || $agencyBusiness['is_delete'] == self::BOOL_TRUE) { + throw new ValidateException('没有相关的代理商记录!'); + } elseif ($agencyBusiness['enable'] == self::BOOL_TRUE) { + throw new ValidateException('该代理商已被封禁!'); + } + } + $business = null; if (isset($account['business_code']) && !empty($account['business_code'])) { $business = $busRepo->findOneByWhere(['code'=> $account['business_code']]); @@ -115,110 +122,5 @@ class Business extends Base } } - /** - * 商家注册 - * - * 方式2:注册为平台代理商下的商家 - * 由平台代理商工作人员审核 - * - * 重新编辑注册则覆盖之前的审核信息,并重新进行审核 - */ - public function registerByAgency() - { - $params = [ - 'type'=> $this->request->param('type/d', 0), - 'business_name'=> $this->request->param('business_name', ''), - 'business_subtitle'=> $this->request->param('business_subtitle', ''), - 'business_license'=> $this->request->param('business_license', ''), - 'contact_name'=> $this->request->param('contact_name', ''), - 'contact_phone'=> $this->request->param('contact_phone', ''), - 'lat'=> $this->request->param('lat', ''), - 'lng'=> $this->request->param('lng', ''), - 'province'=> $this->request->param('province', ''), - 'city'=> $this->request->param('city', ''), - 'county'=> $this->request->param('county', ''), - 'business_address' => $this->request->param('business_address', ''), - 'business_circle_id' => $this->request->param('business_circle_id/d', 0), - 'agency_code' => $this->request->param('agency_code', ''), - ]; - - $accountId = $this->request->user['user_id'] ?? 0; - - try { - $validate = new BusinessValidate(); - $busRepo = BusinessRepository::getInstance(); - $dicRepo = DictionaryRepository::getInstance(); - $accountRepo = AccountRepository::getInstance(); - - $account = $accountRepo->findById($accountId); - if (empty($account)) { - throw new ValidateException('无效请求!'); - } - - if (!$validate->scene('registerByAgency')->check($params)) { - throw new ValidateException($validate->getError()); - } - - $businessCategory = $dicRepo->findBusinessTypeById($params['type']); - if (empty($businessCategory)) { - throw new ValidateException('请选择正确的商家分类信息!'); - } - - if ($params['business_circle_id'] > 0) { - $businessCircle = $dicRepo->findBusinessCircleById($params['business_circle_id']); - if (empty($businessCircle)) { - throw new ValidateException('请选择正确的商圈信息!'); - } - $params['business_circle'] = $businessCircle['name']; - } - - $agencyBusiness = $busRepo->findOneByWhere(['code'=> $params['agency_code'], 'is_agency'=> self::BOOL_TRUE, 'state' => BusinessModel::state_on]); - if (empty($agencyBusiness) || $agencyBusiness['is_delete'] == self::BOOL_TRUE) { - throw new ValidateException('没有相关的平台商记录!'); - } elseif ($agencyBusiness['enable'] == self::BOOL_TRUE) { - throw new ValidateException('该平台商已被封禁!'); - } - - $business = null; - if (isset($account['business_code']) && !empty($account['business_code'])) { - $business = $busRepo->findOneByWhere(['code'=> $account['business_code']]); - } - - $params['create_time'] = date('Y-m-d H:i:s'); - $params['is_delete'] = 0; - $params['state'] = BusinessModel::state_reviewing; - $params['enable'] = 0; - $params['type_name'] = $businessCategory['name']; - - if ($business) { - if ($business['state'] == BusinessModel::state_reviewing) { - throw new ValidateException('商户认证审批中,请勿重复提交!'); - } - - // 更新审批信息,重新审批 - $params['update_time'] = date('Y-m-d H:i:s'); - $business = $business->save($params); - - } else { - // 添加审批记录 - $businessCode = createUuid(); - $params['code'] = $businessCode; - $business = $busRepo->create($params); - if (!$business) { - throw new RepositoryException('服务器繁忙!商户认证申请提交失败!'); - } - - $account->save(['business_code' => $businessCode]); - } - - $result = $busRepo->formatFrontBusinessInfo($business->toArray(), [2]); - return $this->json(0, 'success', $result); - } catch (ValidateException $e) { - return $this->json(4001, $e->getError()); - } catch (RepositoryException | \Exception $e) { - return $this->json(5001, '服务器繁忙!商户认证申请提交失败!'); - } - } - } \ No newline at end of file diff --git a/app/model/Business.php b/app/model/Business.php index e3707cf..c9a57ac 100644 --- a/app/model/Business.php +++ b/app/model/Business.php @@ -11,7 +11,7 @@ class Business extends Base const state_off = 2; /** - * @remarks 代理商、平台代理商、渠道商等词组均描述的是平台商,因此文案统一为【平台商】 + * @remarks 代理商、平台商、平台代理商、渠道商等词组均描述的是代理商,因此文案统一为【代理商】 */ public function category() @@ -19,20 +19,11 @@ class Business extends Base return $this->hasOne(Category::class, 'id',"type"); } - /** - * 关联的平台商 - * - * @return HasOne - */ - public function agency(): HasOne - { - return $this->hasOne(Business::class, 'agency_code', "code"); - } - public function account() { return $this->hasOne(Account::class, 'business_code',"code"); } + public function agency() { return $this->hasOne(self::class,"code","agency_code"); diff --git a/app/validate/BusinessValidate.php b/app/validate/BusinessValidate.php index ca97dfb..f5661d7 100644 --- a/app/validate/BusinessValidate.php +++ b/app/validate/BusinessValidate.php @@ -25,7 +25,6 @@ class BusinessValidate extends Validate 'background|商家背景图' => 'max:250', 'business_circle_id' => 'egt:0', - 'agency_code' => 'require|length:32', ]; protected $message = [ @@ -38,18 +37,13 @@ class BusinessValidate extends Validate 'lng.between' => '地址定位信息错误,请重新定位!', 'business_circle_id.egt' => '请选择所属商圈!', - 'agency_code.require' => '请选择需要加入的商家!', - 'agency_code.length' => '加入的商家参数错误!', ]; protected $scene = [ // 认证商家 - 'registerByNormal' => ['type', 'business_name', 'business_subtitle', 'business_license', 'contact_name', 'contact_phone', + 'apiRegister' => ['type', 'business_name', 'business_subtitle', 'business_license', 'contact_name', 'contact_phone', 'lat', 'lng', 'province', 'city', 'county', 'business_address', 'business_circle_id'], - // 加入平台代理商 - 'registerByAgency' => ['type', 'business_name', 'business_subtitle', 'business_license', 'contact_name', 'contact_phone', - 'lat', 'lng', 'province', 'city', 'county', 'business_address', 'business_circle_id', 'agency_code'], // 商家编辑可编辑资料(基本信息修改需要审核通过后才能变更) - 'apiEdit' => ['lat', 'lng', 'province', 'city', 'county', 'business_address', 'characteristic', 'background', 'business_circle_id'], + 'apiEdit' => ['lat', 'lng', 'province', 'city', 'county', 'business_address', 'characteristic', 'background', 'business_circle_id'], ]; } \ No newline at end of file From edb870b4d60635f130654d72751d4cd39a4c0beb Mon Sep 17 00:00:00 2001 From: zwesy Date: Thu, 2 Dec 2021 11:01:51 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E8=8E=B7=E5=8F=96=E5=95=86=E5=AE=B6=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Dictionary.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controller/api/Dictionary.php b/app/controller/api/Dictionary.php index b228750..ecd3d81 100644 --- a/app/controller/api/Dictionary.php +++ b/app/controller/api/Dictionary.php @@ -112,7 +112,6 @@ class Dictionary extends Base */ public function getBusinessTypeList(): Json { - $recursionChildren = $this->request->param('recursion/d', 0); $pid = $this->request->param('pid/d', 0); $whereMap = []; @@ -124,9 +123,7 @@ class Dictionary extends Base $items = $repo->getBusinessTypeList($whereMap, [], null, ['pid'=>'asc']); $list = $items->toArray(); - if ($recursionChildren > 0) { - $list = $repo->recursionChildrenList($list, $pid, 'pid', 'id'); - } + $list = $repo->recursionChildrenList($list, $pid, 'pid', 'id'); return $this->json(0, 'success', $list); } From f55272ed06a03161cbdbe03515484edacec48f17 Mon Sep 17 00:00:00 2001 From: zwesy Date: Thu, 2 Dec 2021 15:51:47 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=85=B3=E8=81=94=E8=AE=A4=E8=AF=81=E7=9A=84=E5=95=86?= =?UTF-8?q?=E5=AE=B6=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Business.php | 77 ++++++++++++++++++++++++- app/controller/api/User.php | 48 ++++++++++----- app/repository/DictionaryRepository.php | 49 ++++++++++++++++ 3 files changed, 159 insertions(+), 15 deletions(-) diff --git a/app/controller/api/Business.php b/app/controller/api/Business.php index df2527c..2e6e529 100644 --- a/app/controller/api/Business.php +++ b/app/controller/api/Business.php @@ -7,7 +7,11 @@ use app\repository\BusinessRepository; use app\repository\DictionaryRepository; use app\validate\BusinessValidate; 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, '商家信息查询失败!'); + } + } } \ No newline at end of file diff --git a/app/controller/api/User.php b/app/controller/api/User.php index c98dfaf..bf48f84 100644 --- a/app/controller/api/User.php +++ b/app/controller/api/User.php @@ -4,6 +4,7 @@ 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; @@ -132,6 +133,7 @@ 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']); @@ -174,26 +176,44 @@ class User extends Base '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'] = [ 'state' => $account['business']['state'], '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); } diff --git a/app/repository/DictionaryRepository.php b/app/repository/DictionaryRepository.php index bb533b6..a6eae2f 100644 --- a/app/repository/DictionaryRepository.php +++ b/app/repository/DictionaryRepository.php @@ -2,6 +2,7 @@ namespace app\repository; +use app\model\Area; use app\model\BusinessCircle; use app\model\Category; 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; + } + } \ No newline at end of file