Compare commits

...

2 Commits

Author SHA1 Message Date
zwesy a47ef3b410 更新:冲突解决 2021-11-30 18:54:45 +08:00
zwesy 11fe3636d7 更新:商家注册-2种方式接口 2021-11-30 18:52:02 +08:00
9 changed files with 388 additions and 22 deletions

View File

@ -48,4 +48,17 @@ class Base extends BaseController
return json($result);
}
/**
* 取消程序运行时间和内存限制
* max_execution_time PHP程序最大执行时间限制单位
* memory_limit 此次的最大运行内存 单位字节Byte
* set_time_limit 当前操作最长执行时间限制(单位:秒)
*/
protected function cancelTimeLimit(int $maxExecTime = 0, int $memory = -1, int $timeOut = 0)
{
ini_set('max_execution_time', $maxExecTime);
ini_set("memory_limit", $memory);
set_time_limit($timeOut);
}
}

View File

@ -1,6 +1,14 @@
<?php
namespace app\controller\api;
use app\exception\RepositoryException;
use app\repository\AccountRepository;
use app\repository\BusinessRepository;
use app\repository\DictionaryRepository;
use app\validate\BusinessValidate;
use think\exception\ValidateException;
use app\model\Business as BusinessModel;
/**
* 商家端:商家
*
@ -9,5 +17,208 @@ namespace app\controller\api;
*/
class Business extends Base
{
/**
* 商家注册
*
* 方式1注册为自然商家
* 由系统后台工作人员审核
*
* 重新编辑注册则覆盖之前的审核信息,并重新进行审核
*/
public function registerByNormal()
{
$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),
];
$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('registerByNormal')->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'];
}
$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());
return $this->json(0, 'success', $result);
} catch (ValidateException $e) {
return $this->json(4001, $e->getError());
} catch (RepositoryException | \Exception $e) {
return $this->json(5001, '服务器繁忙!商户认证申请提交失败!');
}
}
/**
* 商家注册
*
* 方式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, '服务器繁忙!商户认证申请提交失败!');
}
}
}

View File

@ -49,12 +49,31 @@ class Dictionary extends Base
public function getBusinessCircle(): Json
{
$items = DictionaryRepository::getInstance()->getAllBusinessCircleList();
$items->each(function ($item) {
$areaText = '';
if (!empty($item['province_text'])) {
$areaText = $item['province_text'].'·';
}
if (!empty($item['city_text']) && $item['city_text'] != '市辖区') {
$areaText .= $item['city_text'].'·';
}
if (!empty($item['county_text'])) {
$areaText .= $item['county_text'];
}
$item['name_text'] = $item['name'];
if (!empty($areaText)) {
$item['name_text'] = $item['name'] . '「'.$areaText.'」';
}
return $item;
});
return $this->json(0, 'success', $items);
}
/**
* 获取代理机构(渠道代理商)列表
* (来源商家表中的渠道代理商)
* 获取代理机构(代理商)关联的商家列表
* (来源商家表中的代理商)
*
* $size 0 表示不分页,获取所有数据
*
@ -75,7 +94,7 @@ class Dictionary extends Base
$fields = ['id', 'code', 'business_name', 'business_subtitle', 'business_license',
'lat', 'lng', 'business_address', 'contact_name', 'contact_phone',
'create_time', 'type', 'type_name', 'characteristic', 'intro',
'business_circle', 'business_circle_id', 'background', 'score'
'business_circle', 'business_circle_id', 'background', 'score',
];
$repo = BusinessRepository::getInstance();
@ -88,7 +107,6 @@ class Dictionary extends Base
}
}
/**
* 获取商家分类
*/

View File

@ -40,7 +40,11 @@ class Upload extends Base
}
$this->validate = new VUpload();
$this->uploadPath = Config::get('filesystem.disks.local.url');
if(is_writable(app()->getRootPath() . 'public' . $this->uploadPath)){
$savePath = app()->getRootPath() . 'public' . $this->uploadPath;
if (!is_dir($savePath)) {
@mkdir($savePath, 0777);
}
if(is_writable($savePath)){
$this->uploadPathIsWritable = true;
}
@ -69,8 +73,6 @@ class Upload extends Base
$return['src'] = $src;
$return['name'] = $file->getOriginalName();
//加入上传文件表
File::add($file, $src, 'file');
} catch (\Exception $e) {
return $this->json(4003, $e->getMessage());
}
@ -93,7 +95,7 @@ class Upload extends Base
if (empty($image)) {
return $this->json(4001, '请上传图片文件');
}
$md5 = $image->md5();//文件md5
if($this->validate->checkImage($image)){
try{
if(!$this->uploadPathIsWritable){
@ -105,9 +107,7 @@ class Upload extends Base
if($this->isCompress){
Image::resize($src);
}
//加入上传文件表
File::add($image, $src,$md5);
} catch (\Exception $e) {
return $this->json(4003, $e->getMessage());
}
@ -120,13 +120,4 @@ class Upload extends Base
}
}
/**
* 同步到OOS服务器存储
* @param string $src
*/
private function syncToOos(string $src)
{
}
}

View File

@ -2,16 +2,33 @@
namespace app\model;
use think\model\relation\HasOne;
class Business extends Base
{
const state_reviewing = 0;
const state_on = 1;
const state_off = 2;
/**
* @remarks 代理商、平台代理商、渠道商等词组均描述的是平台商,因此文案统一为【平台商】
*/
public function category()
{
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");

View File

@ -48,7 +48,7 @@ class Category extends Base
/**
* 获取全部列表
*
* @return Disease[]|array|Collection
* @return Collection
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
@ -64,7 +64,7 @@ class Category extends Base
* @param int $pid
* @param array $selected
* @param array $disabled
* @return array|Disease[]|Collection
* @return array|Collection
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException

View File

@ -154,6 +154,33 @@ class BusinessRepository extends Repository
return $Flow;
}
/**
* 格式化前端输出商户信息
* @param array $data
* @param array $formats
* @return array
*/
public function formatFrontBusinessInfo(array $data, array $formats=[]): array
{
$fields = ['id', 'code', 'business_name', 'business_subtitle', 'business_license',
'lat', 'lng', 'business_address', 'contact_name', 'contact_phone',
'create_time', 'type', 'type_name', 'characteristic', 'intro',
'business_circle', 'business_circle_id', 'background', 'score',
];
if (in_array(1, $formats)) {
// 返回审批相关字段
$fields = array_merge($fields, ['state', 'reason']);
}
if (in_array(2, $formats)) {
// 返回关联的平台商相关字段
$fields = array_merge($fields, [ 'is_agency', 'agency_code']);
}
return arrayKeysFilter($data, $fields);
}
/**
* 查看指定商圈下的商家
* @param $businessCircleId

View File

@ -53,6 +53,24 @@ class DictionaryRepository extends Repository
}
}
/**
* 获取商圈详情
*
* @param int $id
* @param array $fields
* @param callable|null $call
* @return array|\think\Model|null
*/
public function findBusinessCircleById(int $id, array $fields = [], callable $call = null)
{
try {
return BusinessCircle::findById($id, $fields, $call);
} catch (\Exception $e) {
return null;
}
}
/**
* 获取商家分类数据
*/
@ -66,4 +84,20 @@ class DictionaryRepository extends Repository
}
}
/**
* 获取商家分类详情
* @param int $id
* @param array $fields
* @param callable|null $call
* @return array|\think\Model|null
*/
public function findBusinessTypeById(int $id, array $fields = [], callable $call = null)
{
try {
return Category::findById($id, $fields, $call);
} catch (\Exception $e) {
return null;
}
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace app\validate;
use think\Validate;
class BusinessValidate extends Validate
{
protected $rule = [
'type' => 'require|gt:0',
'business_name|商家名称' => 'require|max:150',
'business_subtitle|商家简称' => 'max:50',
'business_license|营业执照' => 'require|max:250',
'contact_name|联系人' => 'require|max:20',
'contact_phone|联系电话' => 'require|max:20',
'lat' => 'require|between:-90,90',
'lng' => 'require|between:-180,180',
'province|所属省份' => 'max:100',
'city|所属城市' => 'max:100',
'county|所属区县' => 'max:100',
'business_address|商家地址' => 'require|max:250',
'characteristic|商家特色' => 'max:250',
'background|商家背景图' => 'max:250',
'business_circle_id' => 'egt:0',
'agency_code' => 'require|length:32',
];
protected $message = [
'type.require' => '请选择商家分类!',
'type.gt' => '请选择商家分类!',
'lat.require' => '地址定位信息错误,请重新定位!',
'lat.between' => '地址定位信息错误,请重新定位!',
'lng.require' => '地址定位信息错误,请重新定位!',
'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',
'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'],
];
}