2023-05-10 13:38:51 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | Author: CRMEB Team <admin@crmeb.com>
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
namespace app\controller\api\store\merchant;
|
|
|
|
|
|
2023-09-22 09:35:06 +08:00
|
|
|
|
use app\common\model\system\merchant\Merchant;
|
2023-05-10 13:38:51 +08:00
|
|
|
|
use app\common\repositories\system\merchant\MerchantAdminRepository;
|
|
|
|
|
use app\common\repositories\system\merchant\MerchantCategoryRepository;
|
|
|
|
|
use app\common\repositories\system\merchant\MerchantRepository;
|
|
|
|
|
use app\common\repositories\system\merchant\MerchantTypeRepository;
|
2023-09-22 09:24:51 +08:00
|
|
|
|
use app\common\repositories\system\CacheRepository;
|
2023-05-10 13:38:51 +08:00
|
|
|
|
use app\validate\api\MerchantIntentionValidate;
|
|
|
|
|
use crmeb\services\SmsService;
|
|
|
|
|
use crmeb\services\SwooleTaskService;
|
|
|
|
|
use crmeb\services\YunxinSmsService;
|
|
|
|
|
use think\App;
|
2023-08-22 10:35:22 +08:00
|
|
|
|
use think\facade\Db;
|
2023-09-13 14:47:52 +08:00
|
|
|
|
use think\facade\Log;
|
2023-05-10 13:38:51 +08:00
|
|
|
|
use crmeb\basic\BaseController;
|
|
|
|
|
use app\common\repositories\system\merchant\MerchantIntentionRepository as repository;
|
|
|
|
|
use think\exception\ValidateException;
|
|
|
|
|
|
|
|
|
|
class MerchantIntention extends BaseController
|
|
|
|
|
{
|
|
|
|
|
protected $repository;
|
|
|
|
|
protected $userInfo;
|
|
|
|
|
|
|
|
|
|
public function __construct(App $app, repository $repository)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($app);
|
|
|
|
|
$this->repository = $repository;
|
|
|
|
|
$this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function create()
|
|
|
|
|
{
|
|
|
|
|
$data = $this->checkParams();
|
|
|
|
|
if (!systemConfig('mer_intention_open')) {
|
|
|
|
|
return app('json')->fail('未开启商户入驻');
|
|
|
|
|
}
|
|
|
|
|
if ($this->userInfo) $data['uid'] = $this->userInfo->uid;
|
2023-09-14 17:33:56 +08:00
|
|
|
|
if (($this->userInfo->phone ?? false) && ($this->userInfo->phone != ($data['phone'] ?? ''))) {
|
|
|
|
|
throw new ValidateException('联系电话和注册手机不一致');
|
|
|
|
|
}
|
2023-11-04 19:39:53 +08:00
|
|
|
|
|
2023-09-14 17:33:56 +08:00
|
|
|
|
$intentionInfo = Db::name('merchant_intention')->where('social_credit_code', $data['social_credit_code'])->where('status', '<>', 2)->find();
|
|
|
|
|
if ($intentionInfo) {
|
|
|
|
|
throw new ValidateException('此统一社会信用代码已申请商户');
|
|
|
|
|
}
|
2023-11-25 11:48:13 +08:00
|
|
|
|
$merInfo = Db::name('merchant_intention')->where('uid', $this->userInfo->uid)->where('status', 'in',[0,1])->where('is_del',0)->find();
|
2023-09-13 14:39:41 +08:00
|
|
|
|
if ($merInfo) {
|
2023-11-25 11:48:13 +08:00
|
|
|
|
throw new ValidateException('该用户已申请商户,不可重复申请');
|
2023-08-22 11:35:07 +08:00
|
|
|
|
}
|
2023-05-10 13:38:51 +08:00
|
|
|
|
$make = app()->make(MerchantRepository::class);
|
|
|
|
|
if ($make->fieldExists('mer_name', $data['mer_name']))
|
|
|
|
|
throw new ValidateException('商户名称已存在,不可申请');
|
|
|
|
|
if ($make->fieldExists('mer_phone', $data['phone']))
|
|
|
|
|
throw new ValidateException('手机号已存在,不可申请');
|
|
|
|
|
$adminRepository = app()->make(MerchantAdminRepository::class);
|
|
|
|
|
if ($adminRepository->fieldExists('account', $data['phone']))
|
|
|
|
|
throw new ValidateException('手机号已是管理员,不可申请');
|
2023-12-02 17:02:32 +08:00
|
|
|
|
// 数据表的village_id为int型,前端传的是village_code,可能超过11位,int最大可存储11位,导致sql报错。 转换为主键id存储
|
|
|
|
|
$data['village_id'] = Db::name('geo_village')->where('village_code', $data['village_id'])->value('village_id');
|
2023-05-10 13:38:51 +08:00
|
|
|
|
$intention = $this->repository->create($data);
|
|
|
|
|
SwooleTaskService::admin('notice', [
|
|
|
|
|
'type' => 'new_intention',
|
|
|
|
|
'data' => [
|
|
|
|
|
'title' => '商户入驻申请',
|
|
|
|
|
'message' => '您有一个新的商户入驻申请',
|
|
|
|
|
'id' => $intention->mer_intention_id
|
|
|
|
|
]
|
|
|
|
|
]);
|
2023-09-13 19:52:24 +08:00
|
|
|
|
$areaInfo = Db::name('geo_area')->where('area_code', $data['area_id'] ?? '')->find();
|
|
|
|
|
$sendData = [
|
2023-09-19 10:06:21 +08:00
|
|
|
|
'type' => 1,
|
|
|
|
|
'type_name' => Db::name('merchant_type')->where('mer_type_id', $data['mer_type_id'])->value('type_name', ''),
|
|
|
|
|
'category_name' => Db::name('merchant_category')->where('merchant_category_id', $data['merchant_category_id'])->value('category_name', ''),
|
2023-09-19 13:27:19 +08:00
|
|
|
|
'mer_name' => $data['mer_name'] ?? '',
|
2023-09-14 17:33:56 +08:00
|
|
|
|
'company_name' => $data['company_name'] ?? '',
|
2023-09-13 19:52:24 +08:00
|
|
|
|
'organization_code' => $data['social_credit_code'] ?? '',
|
|
|
|
|
'master_name' => $data['name'],
|
|
|
|
|
'master_phone' => $data['phone'],
|
2023-11-04 19:39:53 +08:00
|
|
|
|
'images' => !empty($data['images']) ? json_encode($data['images']) : '',
|
2023-09-14 17:33:56 +08:00
|
|
|
|
'city' => $areaInfo['city_code'] ?? '',
|
|
|
|
|
'area' => $data['area_id'] ?? '',
|
|
|
|
|
'street' => $data['street_id'] ?? '',
|
2023-12-02 16:21:24 +08:00
|
|
|
|
'village' => $data['village_id'] ?? '',
|
2023-09-14 17:33:56 +08:00
|
|
|
|
'address' => $data['address'] ?? '',
|
2023-11-16 11:27:38 +08:00
|
|
|
|
'mer_intention_id' => $intention->mer_intention_id,
|
2023-11-16 11:52:31 +08:00
|
|
|
|
'type_id'=>$data['mer_type_id']??''
|
2023-09-13 19:52:24 +08:00
|
|
|
|
];
|
2023-09-19 10:06:21 +08:00
|
|
|
|
$postUrl = env('TASK_WORKER_HOST_URL') . '/adminapi/company/createShopMerchant';
|
|
|
|
|
$res = $this->sendMerIntentionApply($sendData, $postUrl);
|
2023-09-23 18:18:30 +08:00
|
|
|
|
if (!$res['ok']) {
|
2023-09-19 10:06:21 +08:00
|
|
|
|
Db::name('merchant_intention')->where('mer_intention_id', $intention->mer_intention_id)->delete();
|
2023-09-27 12:23:17 +08:00
|
|
|
|
throw new ValidateException('供销平台申请商户入驻失败,' . $res['msg']);
|
2023-09-19 10:06:21 +08:00
|
|
|
|
}
|
2023-05-10 13:38:51 +08:00
|
|
|
|
return app('json')->success('提交成功');
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-22 09:51:32 +08:00
|
|
|
|
public function settlementApply()
|
2023-09-22 09:24:51 +08:00
|
|
|
|
{
|
2023-09-22 09:51:32 +08:00
|
|
|
|
$status = $this->request->post('status', 0);
|
|
|
|
|
if ($this->userInfo) $data['uid'] = $this->userInfo->uid;
|
|
|
|
|
if ($status == 1) {
|
2023-11-04 19:39:53 +08:00
|
|
|
|
Db::name('merchant')->where('uid', $this->userInfo->uid)->update(['mer_settlement_agree_status' => 1]);
|
2023-09-22 09:24:51 +08:00
|
|
|
|
}
|
2023-09-22 09:51:32 +08:00
|
|
|
|
return app('json')->success('操作成功');
|
2023-09-22 09:24:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-18 15:48:09 +08:00
|
|
|
|
public function businessApply()
|
|
|
|
|
{
|
2023-09-22 17:35:13 +08:00
|
|
|
|
$data = $this->request->params([
|
2023-11-04 19:39:53 +08:00
|
|
|
|
'phone',
|
2023-09-22 17:35:13 +08:00
|
|
|
|
'mer_name',
|
|
|
|
|
'company_name',
|
2023-11-04 19:39:53 +08:00
|
|
|
|
'address',
|
|
|
|
|
'name',
|
|
|
|
|
'code',
|
|
|
|
|
'images',
|
|
|
|
|
'merchant_category_id',
|
2023-09-22 17:35:13 +08:00
|
|
|
|
'mer_type_id',
|
|
|
|
|
'social_credit_code',
|
|
|
|
|
'area_id',
|
|
|
|
|
'street_id',
|
|
|
|
|
'village_id',
|
|
|
|
|
'is_nmsc',
|
|
|
|
|
'bank_username',
|
|
|
|
|
'bank_opening',
|
|
|
|
|
'bank_front',
|
|
|
|
|
'bank_back',
|
|
|
|
|
'cardno_front',
|
|
|
|
|
'cardno_back',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if (empty($data['bank_username']) || empty($data['bank_opening']) || empty($data['bank_front']) || empty($data['bank_back']) || empty($data['cardno_front']) || empty($data['cardno_back'])) {
|
|
|
|
|
return app('json')->fail('请完善银行卡及身份信息');
|
|
|
|
|
}
|
2023-11-04 19:39:53 +08:00
|
|
|
|
|
2023-09-18 15:48:09 +08:00
|
|
|
|
if (!systemConfig('mer_intention_open')) {
|
|
|
|
|
return app('json')->fail('未开启商户入驻');
|
|
|
|
|
}
|
|
|
|
|
if ($this->userInfo) $data['uid'] = $this->userInfo->uid;
|
2023-09-19 14:20:08 +08:00
|
|
|
|
$merInfo = Db::name('merchant')->where('uid', $this->userInfo->uid)->where('status', 1)->find();
|
2023-09-27 13:23:25 +08:00
|
|
|
|
if (empty($merInfo)) {
|
|
|
|
|
return app('json')->fail('请申请商户入驻申请!');
|
|
|
|
|
}
|
2023-11-04 19:39:53 +08:00
|
|
|
|
if (!empty($merInfo['business_status']) && ($merInfo['business_status'] == 1)) {
|
2023-09-19 15:16:50 +08:00
|
|
|
|
return app('json')->fail('商户交易已申请,正在审核中!');
|
|
|
|
|
}
|
2023-11-04 19:39:53 +08:00
|
|
|
|
if (!empty($merInfo['business_status']) && ($merInfo['business_status'] == 2)) {
|
2023-09-19 10:29:15 +08:00
|
|
|
|
return app('json')->fail('商户交易申请已通过');
|
|
|
|
|
}
|
|
|
|
|
$intenInfo = Db::name('merchant_intention')->where('mer_intention_id', $merInfo['mer_intention_id'] ?? 0)->where('type', 1)->find();
|
2023-09-18 15:48:09 +08:00
|
|
|
|
if (empty($intenInfo)) {
|
2023-09-26 15:05:56 +08:00
|
|
|
|
// 兼容处理已开通商户
|
2023-09-26 14:25:58 +08:00
|
|
|
|
$intenInfo = [
|
2023-09-26 14:44:27 +08:00
|
|
|
|
'uid' => $merInfo['uid'],
|
|
|
|
|
'mer_id' => $merInfo['mer_id'],
|
|
|
|
|
'phone' => $merInfo['mer_phone'],
|
|
|
|
|
'mer_name' => $merInfo['mer_name'],
|
2023-09-27 15:46:41 +08:00
|
|
|
|
'name' => $merInfo['mer_name'],
|
2023-09-26 14:44:27 +08:00
|
|
|
|
'merchant_category_id' => $merInfo['category_id'],
|
|
|
|
|
'mer_type_id' => $merInfo['type_id'],
|
2023-09-26 14:25:58 +08:00
|
|
|
|
];
|
2023-09-18 15:48:09 +08:00
|
|
|
|
}
|
2023-09-22 17:35:13 +08:00
|
|
|
|
$intenInfo['bank_username'] = $data['bank_username'];
|
|
|
|
|
$intenInfo['bank_opening'] = $data['bank_opening'];
|
|
|
|
|
$intenInfo['bank_front'] = $data['bank_front'];
|
|
|
|
|
$intenInfo['bank_back'] = $data['bank_back'];
|
|
|
|
|
$intenInfo['cardno_front'] = $data['cardno_front'];
|
|
|
|
|
$intenInfo['cardno_back'] = $data['cardno_back'];
|
|
|
|
|
|
2023-09-19 14:20:08 +08:00
|
|
|
|
$intenInfo['type'] = 2;
|
2023-09-19 15:16:50 +08:00
|
|
|
|
$intenInfo['status'] = 0;
|
2023-09-20 14:37:27 +08:00
|
|
|
|
$intenInfo['create_time'] = date('Y-m-d H:i:s');
|
2023-12-02 17:02:32 +08:00
|
|
|
|
|
2023-09-19 14:22:44 +08:00
|
|
|
|
unset($intenInfo['mer_intention_id']);
|
2023-12-02 17:02:32 +08:00
|
|
|
|
|
2023-09-19 14:20:08 +08:00
|
|
|
|
$intentionId = Db::name('merchant_intention')->insertGetId($intenInfo);
|
2023-09-18 15:48:09 +08:00
|
|
|
|
$areaInfo = Db::name('geo_area')->where('area_code', $intenInfo['area_id'] ?? '')->find();
|
|
|
|
|
$sendData = [
|
2023-09-19 10:06:21 +08:00
|
|
|
|
'type' => 2,
|
2023-09-18 15:48:09 +08:00
|
|
|
|
'type_name' => Db::name('merchant_type')->where('mer_type_id', $merInfo['type_id'])->value('type_name', ''),
|
|
|
|
|
'category_name' => Db::name('merchant_category')->where('merchant_category_id', $merInfo['category_id'])->value('category_name', ''),
|
2023-09-19 11:19:28 +08:00
|
|
|
|
'mer_name' => $intenInfo['mer_name'] ?? '',
|
2023-09-18 15:48:09 +08:00
|
|
|
|
'company_name' => $intenInfo['company_name'] ?? '',
|
|
|
|
|
'organization_code' => $intenInfo['social_credit_code'] ?? '',
|
|
|
|
|
'master_name' => $intenInfo['name'],
|
|
|
|
|
'master_phone' => $intenInfo['phone'],
|
2023-11-04 19:39:53 +08:00
|
|
|
|
'images' => !empty($intenInfo['images']) ? json_encode(explode(',', $intenInfo['images'])) : '',
|
2023-09-18 15:48:09 +08:00
|
|
|
|
'city' => $areaInfo['city_code'] ?? '',
|
2023-09-27 15:46:41 +08:00
|
|
|
|
'area' => $merInfo['area_id'] ?? '',
|
|
|
|
|
'street' => $merInfo['street_id'] ?? '',
|
2023-12-02 16:21:24 +08:00
|
|
|
|
'village' => $data['village_id'] ?? '',
|
2023-10-27 19:26:10 +08:00
|
|
|
|
'address' => $intenInfo['address'] ?? '',
|
2023-09-22 17:35:13 +08:00
|
|
|
|
'bank_username' => $data['bank_username'] ?? '',
|
|
|
|
|
'bank_opening' => $data['bank_opening'] ?? '',
|
|
|
|
|
'bank_front' => $data['bank_front'] ?? '',
|
|
|
|
|
'bank_back' => $data['bank_back'] ?? '',
|
|
|
|
|
'cardno_front' => $data['cardno_front'] ?? '',
|
|
|
|
|
'cardno_back' => $data['cardno_back'] ?? '',
|
2023-11-17 13:51:45 +08:00
|
|
|
|
'mer_intention_id' => $intentionId,
|
2023-11-17 18:40:35 +08:00
|
|
|
|
'type_id'=>$merInfo['type_id']??''
|
2023-11-17 13:51:45 +08:00
|
|
|
|
|
2023-09-18 15:48:09 +08:00
|
|
|
|
];
|
2023-09-19 10:06:21 +08:00
|
|
|
|
$postUrl = env('TASK_WORKER_HOST_URL') . '/adminapi/company/createShopMerchant';
|
|
|
|
|
$res = $this->sendMerIntentionApply($sendData, $postUrl);
|
2023-09-23 18:18:30 +08:00
|
|
|
|
if (!$res['ok']) {
|
2023-09-25 13:26:55 +08:00
|
|
|
|
Db::name('merchant_intention')->where('mer_intention_id', $intentionId)->delete();
|
2023-09-27 12:23:17 +08:00
|
|
|
|
throw new ValidateException('供销平台商户交易申请失败,' . $res['msg']);
|
2023-09-18 15:48:09 +08:00
|
|
|
|
}
|
2023-11-04 19:39:53 +08:00
|
|
|
|
Db::name('merchant')->where('uid', $this->userInfo->uid)->where('status', 1)->update(['business_status' => 1]);
|
2023-09-18 15:48:09 +08:00
|
|
|
|
return app('json')->success('申请成功');
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-26 14:25:58 +08:00
|
|
|
|
//发送商户申请
|
2023-09-19 10:06:21 +08:00
|
|
|
|
public function sendMerIntentionApply($data, $postUrl)
|
2023-09-13 14:35:08 +08:00
|
|
|
|
{
|
2023-09-19 13:51:09 +08:00
|
|
|
|
Log::info("商户申请URL: {$postUrl}");
|
2023-09-19 10:06:21 +08:00
|
|
|
|
Log::info("发送商户申请信息: " . json_encode($data));
|
2023-09-13 14:35:08 +08:00
|
|
|
|
$ch = curl_init();
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $postUrl);
|
|
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
2023-09-13 14:50:33 +08:00
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
|
|
|
$resData = curl_exec($ch);
|
2023-09-13 14:35:08 +08:00
|
|
|
|
curl_close($ch);
|
2023-09-23 18:18:30 +08:00
|
|
|
|
$rtnData = [
|
|
|
|
|
'ok' => false,
|
|
|
|
|
'msg' => ''
|
|
|
|
|
];
|
2023-09-13 14:50:33 +08:00
|
|
|
|
if (!empty($resData) && is_string($resData)) {
|
2023-09-19 10:06:21 +08:00
|
|
|
|
Log::info("商户申请反馈信息" . $resData);
|
2023-09-13 20:06:19 +08:00
|
|
|
|
$resInfo = json_decode($resData, true);
|
2023-11-04 19:39:53 +08:00
|
|
|
|
if (!empty($resInfo['code']) && $resInfo['code'] == 1) {
|
2023-09-23 18:18:30 +08:00
|
|
|
|
$rtnData['ok'] = true;
|
|
|
|
|
} else {
|
|
|
|
|
$rtnData['msg'] = $resInfo['msg'];
|
2023-09-13 20:04:57 +08:00
|
|
|
|
}
|
2023-09-13 14:35:08 +08:00
|
|
|
|
}
|
2023-09-23 18:18:30 +08:00
|
|
|
|
return $rtnData;
|
2023-09-13 14:35:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 13:38:51 +08:00
|
|
|
|
public function update($id)
|
|
|
|
|
{
|
2023-09-14 17:33:56 +08:00
|
|
|
|
$merIntentionInfo = $this->repository->getWhere(['mer_intention_id' => (int)$id, 'uid' => $this->userInfo->uid, 'is_del' => 0]);
|
|
|
|
|
if (!$merIntentionInfo)
|
2023-05-10 13:38:51 +08:00
|
|
|
|
return app('json')->fail('数据不存在');
|
2023-09-19 17:10:05 +08:00
|
|
|
|
if ($merIntentionInfo['status'] == 1) {
|
|
|
|
|
return app('json')->fail('已通过审核数据不能修改');
|
2023-09-14 17:33:56 +08:00
|
|
|
|
}
|
2023-05-10 13:38:51 +08:00
|
|
|
|
$data = $this->checkParams();
|
|
|
|
|
if (!systemConfig('mer_intention_open')) {
|
|
|
|
|
return app('json')->fail('未开启商户入驻');
|
|
|
|
|
}
|
2023-09-14 17:33:56 +08:00
|
|
|
|
if (($this->userInfo->phone ?? false) && ($this->userInfo->phone != ($data['phone'] ?? ''))) {
|
|
|
|
|
throw new ValidateException('联系电话和注册手机不一致');
|
|
|
|
|
}
|
|
|
|
|
$intentionInfo = Db::name('merchant_intention')->where('social_credit_code', $data['social_credit_code'])->where('status', '<>', 2)->find();
|
|
|
|
|
if ($intentionInfo) {
|
|
|
|
|
throw new ValidateException('此统一社会信用代码已申请商户');
|
|
|
|
|
}
|
2023-08-22 11:35:07 +08:00
|
|
|
|
if (!empty($data['mer_phone'])) {
|
|
|
|
|
unset($data['mer_phone']);
|
|
|
|
|
}
|
2023-09-14 17:33:56 +08:00
|
|
|
|
$make = app()->make(MerchantRepository::class);
|
|
|
|
|
if ($make->fieldExists('mer_name', $data['mer_name']))
|
|
|
|
|
throw new ValidateException('商户名称已存在,不可申请');
|
|
|
|
|
$adminRepository = app()->make(MerchantAdminRepository::class);
|
|
|
|
|
if ($adminRepository->fieldExists('account', $data['phone']))
|
|
|
|
|
throw new ValidateException('手机号已是管理员,不可申请');
|
2023-05-10 13:38:51 +08:00
|
|
|
|
$data['create_time'] = date('Y-m-d H:i:s', time());
|
2023-11-22 15:45:46 +08:00
|
|
|
|
$updateIntention=$this->repository->updateIntention((int)$id, $data);
|
2023-05-10 13:38:51 +08:00
|
|
|
|
SwooleTaskService::admin('notice', [
|
|
|
|
|
'type' => 'new_intention',
|
|
|
|
|
'data' => [
|
|
|
|
|
'title' => '商户入驻申请',
|
|
|
|
|
'message' => '您有一个新的商户入驻申请',
|
|
|
|
|
'id' => $id
|
|
|
|
|
]
|
|
|
|
|
]);
|
2023-09-14 17:33:56 +08:00
|
|
|
|
$areaInfo = Db::name('geo_area')->where('area_code', $data['area_id'] ?? '')->find();
|
|
|
|
|
$sendData = [
|
2023-09-19 10:06:21 +08:00
|
|
|
|
'type' => 1,
|
|
|
|
|
'type_name' => Db::name('merchant_type')->where('mer_type_id', $data['mer_type_id'])->value('type_name', ''),
|
|
|
|
|
'category_name' => Db::name('merchant_category')->where('merchant_category_id', $data['merchant_category_id'])->value('category_name', ''),
|
2023-09-19 13:27:19 +08:00
|
|
|
|
'mer_name' => $data['mer_name'] ?? '',
|
2023-09-14 17:33:56 +08:00
|
|
|
|
'company_name' => $data['company_name'] ?? '',
|
|
|
|
|
'organization_code' => $data['social_credit_code'] ?? '',
|
|
|
|
|
'master_name' => $data['name'],
|
|
|
|
|
'master_phone' => $data['phone'],
|
2023-11-04 19:39:53 +08:00
|
|
|
|
'images' => !empty($data['images']) ? json_encode($data['images']) : '',
|
2023-09-14 17:33:56 +08:00
|
|
|
|
'city' => $areaInfo['city_code'] ?? '',
|
|
|
|
|
'area' => $data['area_id'] ?? '',
|
|
|
|
|
'street' => $data['street_id'] ?? '',
|
2023-12-02 16:21:24 +08:00
|
|
|
|
'village' => $data['village_id'] ?? '',
|
2023-09-14 17:33:56 +08:00
|
|
|
|
'address' => $data['address'] ?? '',
|
2023-11-17 13:51:45 +08:00
|
|
|
|
'mer_intention_id' => $id,
|
|
|
|
|
'type_id'=>$data['mer_type_id']??''
|
|
|
|
|
|
2023-09-14 17:33:56 +08:00
|
|
|
|
];
|
2023-09-19 10:06:21 +08:00
|
|
|
|
$postUrl = env('TASK_WORKER_HOST_URL') . '/adminapi/company/createShopMerchant';
|
|
|
|
|
$res = $this->sendMerIntentionApply($sendData, $postUrl);
|
2023-09-23 18:18:30 +08:00
|
|
|
|
if (!$res['ok']) {
|
2023-09-27 12:23:17 +08:00
|
|
|
|
throw new ValidateException('供销平台申请商户入驻失败,' . $res['msg']);
|
2023-09-19 10:06:21 +08:00
|
|
|
|
}
|
2023-11-22 15:45:46 +08:00
|
|
|
|
if($updateIntention){
|
|
|
|
|
return app('json')->success('修改成功');
|
|
|
|
|
}else{
|
|
|
|
|
return app('json')->success('修改失败');
|
|
|
|
|
}
|
2023-05-10 13:38:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function lst()
|
|
|
|
|
{
|
|
|
|
|
[$page, $limit] = $this->getPage();
|
2023-09-19 10:55:01 +08:00
|
|
|
|
$type = $this->request->get('type', 1);
|
2023-11-04 19:39:53 +08:00
|
|
|
|
$data = $this->repository->getList(['uid' => $this->userInfo->uid, 'type' => $type], $page, $limit);
|
2023-05-10 13:38:51 +08:00
|
|
|
|
return app('json')->success($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function detail($id)
|
|
|
|
|
{
|
|
|
|
|
$data = $this->repository->detail((int)$id, $this->userInfo->uid);
|
|
|
|
|
if (!$data) {
|
|
|
|
|
return app('json')->fail('数据不存在');
|
|
|
|
|
}
|
|
|
|
|
if ($data->status == 1) {
|
|
|
|
|
$data['login_url'] = rtrim(systemConfig('site_url'), '/') . '/' . config('admin.merchant_prefix');
|
|
|
|
|
}
|
|
|
|
|
return app('json')->success($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function checkParams()
|
|
|
|
|
{
|
|
|
|
|
$data = $this->request->params([
|
2023-11-04 19:39:53 +08:00
|
|
|
|
'phone',
|
2023-09-14 17:33:56 +08:00
|
|
|
|
'mer_name',
|
|
|
|
|
'company_name',
|
2023-11-04 19:39:53 +08:00
|
|
|
|
'address',
|
|
|
|
|
'name',
|
|
|
|
|
'code',
|
|
|
|
|
'images',
|
2023-05-10 13:38:51 +08:00
|
|
|
|
'mer_type_id',
|
2023-11-21 16:20:48 +08:00
|
|
|
|
'merchant_category_id',
|
2023-09-13 14:35:08 +08:00
|
|
|
|
'social_credit_code',
|
2023-05-10 13:38:51 +08:00
|
|
|
|
'area_id',
|
|
|
|
|
'street_id',
|
|
|
|
|
'village_id',
|
|
|
|
|
'is_nmsc'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
app()->make(MerchantIntentionValidate::class)->check($data);
|
|
|
|
|
$check = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['code'], 'intention');
|
|
|
|
|
$data['mer_type_id'] = (int)$data['mer_type_id'];
|
2023-06-07 13:38:58 +08:00
|
|
|
|
if (!env('APP_DEBUG')) {
|
|
|
|
|
if (!$check) throw new ValidateException('验证码不正确');
|
|
|
|
|
}
|
2023-11-04 20:01:00 +08:00
|
|
|
|
// if (!app()->make(MerchantCategoryRepository::class)->get($data['merchant_category_id'])) throw new ValidateException('商户分类不存在');
|
2023-11-04 19:39:53 +08:00
|
|
|
|
if ($data['mer_type_id'] && !app()->make(MerchantTypeRepository::class)->exists($data['mer_type_id'])) {
|
2023-05-10 13:38:51 +08:00
|
|
|
|
throw new ValidateException('店铺类型不存在');
|
2023-11-04 19:39:53 +08:00
|
|
|
|
}
|
2023-11-21 16:20:48 +08:00
|
|
|
|
// if ($data['merchant_category_name'] == '') {
|
|
|
|
|
// throw new ValidateException('商户分类,不能为空');
|
|
|
|
|
// }
|
|
|
|
|
// $merchant_category_id=Db::name('merchant_category')->where('category_name',$data['merchant_category_name'])->value('merchant_category_id');
|
|
|
|
|
// if(!$merchant_category_id){
|
|
|
|
|
// throw new ValidateException('没有对应的商户分类,请联系工作人员添加');
|
|
|
|
|
// }
|
|
|
|
|
// $data['merchant_category_id']=$merchant_category_id;
|
2023-05-10 13:38:51 +08:00
|
|
|
|
unset($data['code']);
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 商户分类
|
|
|
|
|
* @Author:Qinii
|
|
|
|
|
* @Date: 2020/9/15
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function cateLst()
|
|
|
|
|
{
|
|
|
|
|
$lst = app()->make(MerchantCategoryRepository::class)->getSelect();
|
|
|
|
|
return app('json')->success($lst);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-05 17:30:23 +08:00
|
|
|
|
/**
|
|
|
|
|
* v2商户分类
|
|
|
|
|
* @Author:Qinii
|
|
|
|
|
* @Date: 2020/9/15
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function v2CateLst()
|
|
|
|
|
{
|
|
|
|
|
$lst = app()->make(MerchantCategoryRepository::class)->getSelect(1);
|
|
|
|
|
return app('json')->success($lst);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 13:38:51 +08:00
|
|
|
|
public function typeLst()
|
|
|
|
|
{
|
2023-06-07 14:42:50 +08:00
|
|
|
|
/** @var MerchantTypeRepository $repo */
|
2023-08-25 15:18:19 +08:00
|
|
|
|
$siftStore = $this->request->param('sift_store', 0);
|
2023-06-07 14:42:50 +08:00
|
|
|
|
$repo = app()->make(MerchantTypeRepository::class);
|
|
|
|
|
$repo->userApply = true;
|
2023-08-25 15:18:19 +08:00
|
|
|
|
$lst = $repo->getSelect(false, $siftStore);
|
2023-05-10 13:38:51 +08:00
|
|
|
|
return app('json')->success($lst);
|
|
|
|
|
}
|
|
|
|
|
}
|