173 lines
6.3 KiB
PHP
173 lines
6.3 KiB
PHP
<?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;
|
||
|
||
class SystemSupplierApplyServices extends BaseServices{
|
||
|
||
public function __construct(SystemSupplierApplyDao $dao){
|
||
$this->dao = $dao;
|
||
}
|
||
/**
|
||
* Common: 查询模型
|
||
* Author: wu-hui
|
||
* Time: 2024/01/30 14:46
|
||
* @param $where
|
||
* @return \crmeb\basic\BaseModel
|
||
*/
|
||
public function searchModel($where){
|
||
return $this->dao->searchModel($where);
|
||
}
|
||
|
||
|
||
/**
|
||
* Common: 获取列表信息
|
||
* Author: wu-hui
|
||
* Time: 2024/01/30 15:13
|
||
* @param $search
|
||
* @param $page
|
||
* @param $limit
|
||
* @param string $field
|
||
* @return array
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
*/
|
||
public function getList($search, $page, $limit, $field = '*'){
|
||
$query = $this->dao->searchModel($search);
|
||
$list = $query
|
||
->field($field)
|
||
->order('create_time desc,id desc')
|
||
->page($page, $limit)
|
||
->select();
|
||
$count = $query->count();
|
||
|
||
return compact('count', 'list');
|
||
}
|
||
/**
|
||
* Common: 获取单条信息
|
||
* Author: wu-hui
|
||
* Time: 2024/01/30 17:34
|
||
* @param $search
|
||
* @return array
|
||
*/
|
||
public function getSingleInfo($search){
|
||
return $this->dao->searchModel($search)->findOrEmpty()->toArray();
|
||
}
|
||
/**
|
||
* Common: 添加申请信息
|
||
* Author: wu-hui
|
||
* Time: 2024/01/30 14:28
|
||
* @param array $data
|
||
* @return mixed
|
||
*/
|
||
public function createApplyInfo(array $data){
|
||
return $this->transaction(function() use ($data){
|
||
// 添加供应商申请信息
|
||
$relation_id = $this->dao->save($data['applyInfo'])->id;
|
||
if(!$relation_id) throw new AdminException('申请失败');
|
||
|
||
return $relation_id;
|
||
});
|
||
}
|
||
/**
|
||
* Common: 修改编辑信息
|
||
* Author: wu-hui
|
||
* Time: 2024/01/30 18:07
|
||
* @param array $data
|
||
* @return mixed
|
||
*/
|
||
public function editApplyInfo(array $data){
|
||
return $this->transaction(function() use ($data){
|
||
// 修改供应商申请信息
|
||
$data['applyInfo']['status'] = 0;
|
||
$data['applyInfo']['reason'] = '';
|
||
$res = $this->dao->update($data['supplierApplyId'],$data['applyInfo']);
|
||
if(!$res) throw new AdminException('申请信息修改失败');
|
||
|
||
return true;
|
||
});
|
||
}
|
||
/**
|
||
* Common: 审核通过的操作
|
||
* Author: wu-hui
|
||
* Time: 2024/01/30 16:54
|
||
* @param $params
|
||
* @return mixed
|
||
*/
|
||
public function toExaminePass($params){
|
||
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' => [
|
||
'supplier_name' => $applyInfo['winery_name'],
|
||
'detailed_address' => '',
|
||
'name' => $applyInfo['contacts_name'],
|
||
'phone' => $applyInfo['contacts_phone'],
|
||
'is_show' => 1,
|
||
'invite_agent_id' => $applyInfo['agent']['id'] ?? 0,
|
||
'invite_uid' => $applyInfo['agent']['uid'] ?? 0,
|
||
],
|
||
'accountPassword' => [
|
||
'supplier_account' => $applyInfo['contacts_phone'],
|
||
'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);
|
||
});
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|