添加:供应商申请通过后自动生成供应商相关账号信息

This commit is contained in:
wuhui_zzw 2024-02-05 18:17:57 +08:00
parent be8e4a0eb9
commit 4fea2f6ea4
2 changed files with 50 additions and 9 deletions

View File

@ -214,17 +214,13 @@ class MerchantRepository extends BaseRepository
*/
public function createMerchant(array $data)
{
if ($this->fieldExists('mer_name', $data['mer_name']))
throw new ValidateException('商户名已存在');
if ($data['mer_phone'] && isPhone($data['mer_phone']))
throw new ValidateException('请输入正确的手机号');
if ($this->fieldExists('mer_name', $data['mer_name'])) throw new ValidateException('商户名已存在');
if ($data['mer_phone'] && isPhone($data['mer_phone'])) throw new ValidateException('请输入正确的手机号');
$merchantCategoryRepository = app()->make(MerchantCategoryRepository::class);
$adminRepository = app()->make(MerchantAdminRepository::class);
if (!$data['category_id'] || !$merchantCategoryRepository->exists($data['category_id']))
throw new ValidateException('商户分类不存在');
if ($adminRepository->fieldExists('account', $data['mer_account']))
throw new ValidateException('账号已存在');
// if (!$data['category_id'] || !$merchantCategoryRepository->exists($data['category_id'])) throw new ValidateException('商户分类不存在');
if ($adminRepository->fieldExists('account', $data['mer_account'])) throw new ValidateException('账号已存在');
/** @var MerchantAdminRepository $make */
$make = app()->make(MerchantAdminRepository::class);

View File

@ -1,6 +1,10 @@
<?php
namespace app\services\supplier;
use app\common\model\marketing\Agent;
use app\common\model\user\User;
use app\common\repositories\store\service\StoreServiceRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use app\dao\supplier\SystemSupplierApplyDao;
use app\services\BaseServices;
use crmeb\exceptions\AdminException;
@ -101,7 +105,7 @@ class SystemSupplierApplyServices extends BaseServices{
return $this->transaction(function() use ($params){
// 修改状态
$this->update($params['id'],['status'=>$params['status']]);
// 自动生成账号信息
// 自动生成账号信息 —— 供应链信息
$applyInfo = $this->searchModel(['id'=>$params['id']])->findOrEmpty()->toArray();
app()->make(SystemSupplierServices::class)->create([
'accountInfo' => [
@ -118,6 +122,47 @@ class SystemSupplierApplyServices extends BaseServices{
'supplier_password' => substr($applyInfo['contacts_phone'],-6),
],
]);
// 自动生成账号信息 —— 供应商信息
$password = substr($applyInfo['contacts_phone'],-6);
$config = systemConfig(['broadcast_room_type', 'broadcast_goods_type']);
$merchant = app()->make(MerchantRepository::class)->createMerchant([
'mer_name' => $applyInfo['winery_name'],
'mer_phone' => $applyInfo['contacts_phone'],
'mer_account' => $applyInfo['contacts_phone'],
'category_id' => 0,
'type_id' => 0,
'real_name' => $applyInfo['contacts_name'],
'status' => 1,
'is_audit' => 1,
'is_bro_room' => $config['broadcast_room_type'] == 1 ? 0 : 1,
'is_bro_goods' => $config['broadcast_goods_type'] == 1 ? 0 : 1,
'mer_password' => $password,
'is_margin' => $margin['is_margin'] ?? -1,
'margin' => $margin['margin'] ?? 0,
'merchant_type' => 2,// 商户类别0=普通商户1=酒道馆2=供应商
]);
// 存在默认管理员信息 生成管理员
$staffUserInfo = User::where('uid', $applyInfo['uid'])->findOrEmpty()->toArray();
$staffData = [
'uid' => $applyInfo['uid'],
'nickname' => $staffUserInfo['nickname'] ?? $staffUserInfo['real_name'],
'account' => $applyInfo['contacts_phone'],
'pwd' => $password,
'is_open' => 1,
'status' => 1,
'customer' => 1,
'is_verify' => 1,
'is_goods' => 1,
'is_user' => 1,
'staff_manage' => 1,
'notify' => 1,
'avatar' => $staffUserInfo['avatar'] ?? '',
'phone' => $applyInfo['contacts_phone'],
'sort' => 1,
'mer_id' => $merchant->mer_id,
'is_manage' => 1
];
app()->make(StoreServiceRepository::class)->createInfo($staffData);
});
}