227 lines
8.4 KiB
PHP
227 lines
8.4 KiB
PHP
<?php
|
|
|
|
|
|
|
|
namespace app\common\repositories\system\merchant;
|
|
|
|
use app\common\model\user\User;
|
|
use app\common\repositories\BaseRepository;
|
|
use app\common\repositories\store\service\StoreServiceRepository;
|
|
use crmeb\jobs\SendSmsJob;
|
|
use crmeb\services\SmsService;
|
|
use FormBuilder\Factory\Elm;
|
|
use app\common\dao\system\merchant\MerchantIntentionDao;
|
|
use think\exception\ValidateException;
|
|
use think\facade\Db;
|
|
use think\facade\Queue;
|
|
use think\facade\Route;
|
|
|
|
/**
|
|
* @mixin MerchantIntentionDao
|
|
*/
|
|
class MerchantIntentionRepository extends BaseRepository
|
|
{
|
|
|
|
public function __construct(MerchantIntentionDao $dao)
|
|
{
|
|
$this->dao = $dao;
|
|
}
|
|
|
|
public function getList(array $where, $page, $limit)
|
|
{
|
|
$query = $this->dao->search($where);
|
|
$count = $query->count();
|
|
$list = $query->page($page, $limit)->order('create_time DESC , status ASC')
|
|
->with([
|
|
'merchantCategory',
|
|
'merchantType',
|
|
'applicant' => function($query){
|
|
$query->field('uid,nickname,avatar,real_name,phone');
|
|
},
|
|
'manage' => function($query){
|
|
$query->field('uid,nickname,avatar,real_name,phone');
|
|
}
|
|
])
|
|
->select();
|
|
|
|
return compact('count', 'list');
|
|
}
|
|
|
|
public function detail($id, ?int $uid)
|
|
{
|
|
$where = ['mer_intention_id' => $id];
|
|
if (!is_null($uid)) {
|
|
$where['uid'] = $uid;
|
|
}
|
|
return $this->dao->search($where)->find();
|
|
}
|
|
|
|
public function updateIntention($id, array $data)
|
|
{
|
|
if ($this->dao->existsWhere(['mer_intention_id' => $id, 'status' => '1']))
|
|
throw new ValidateException('当前状态不能修改');
|
|
$data['images'] = implode(',', (array)$data['images']);
|
|
$data['status'] = 0;
|
|
$data['fail_msg'] = '';
|
|
return $this->dao->update($id, $data);
|
|
}
|
|
|
|
public function markForm($id)
|
|
{
|
|
$data = $this->dao->get($id);
|
|
$form = Elm::createForm(Route::buildUrl('systemMerchantIntentionMark', ['id' => $id])->build());
|
|
$form->setRule([
|
|
Elm::textarea('mark', '备注', $data['mark'])->required(),
|
|
]);
|
|
return $form->setTitle('修改备注');
|
|
}
|
|
|
|
public function statusForm($id)
|
|
{
|
|
$form = Elm::createForm(Route::buildUrl('systemMerchantIntentionStatus', ['id' => $id])->build());
|
|
$form->setRule([
|
|
Elm::select('status', '审核状态', 1)->options([
|
|
['value' => 1, 'label' => '同意'],
|
|
['value' => 2, 'label' => '拒绝'],
|
|
])->control([
|
|
[
|
|
'value' => 1,
|
|
'rule' => [
|
|
Elm::radio('create_mer', '自动创建商户', 1)->options([
|
|
['value' => 1, 'label' => '创建'],
|
|
['value' => 2, 'label' => '不创建'],
|
|
])
|
|
]
|
|
],
|
|
[
|
|
'value' => 2,
|
|
'rule' => [
|
|
Elm::textarea('fail_msg', '失败原因', '信息填写有误')
|
|
]
|
|
]
|
|
]),
|
|
]);
|
|
return $form->setTitle('修改审核状态');
|
|
}
|
|
|
|
public function updateStatus($id, $data)
|
|
{
|
|
$create = $data['create_mer'] == 1;
|
|
unset($data['create_mer']);
|
|
$intention = $this->search(['mer_intention_id' => $id])->find();
|
|
if (!$intention)
|
|
throw new ValidateException('信息不存在');
|
|
if ($intention->status)
|
|
throw new ValidateException('状态有误,修改失败');
|
|
$config = systemConfig(['broadcast_room_type', 'broadcast_goods_type']);
|
|
|
|
$margin = app()->make(MerchantTypeRepository::class)->get($intention['mer_type_id']);
|
|
$data['is_margin'] = $margin['is_margin'] ?? -1;
|
|
$data['margin'] = $margin['margin'] ?? 0;
|
|
$merData = [];
|
|
$smsData = [];
|
|
if($create == 1){
|
|
$password = substr($intention['phone'],-6);
|
|
$merData = [
|
|
'mer_name' => $intention['mer_name'],
|
|
'mer_phone' => $intention['phone'],
|
|
'mer_account' => $intention['phone'],
|
|
'category_id' => $intention['merchant_category_id'],
|
|
'type_id' => $intention['mer_type_id'],
|
|
'real_name' => $intention['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,
|
|
'agent_id' => $intention['merchant_type'] == 1 ? 0 : $intention['agent_id'] ?? 0,// 酒道馆是合伙人邀请加入 不能直接绑定
|
|
'merchant_type' => $intention['merchant_type'] ?? 0,
|
|
'invite_agent_id' => $intention['agent_id'] ?? 0,
|
|
];
|
|
$data['fail_msg'] = '';
|
|
$smsData = [
|
|
'date' => date('m月d日',strtotime($intention->create_time)),
|
|
'mer' => $intention['mer_name'],
|
|
'phone' => $intention['phone'],
|
|
'pwd' => $password ?? '',
|
|
'site_name' => systemConfig('site_name'),
|
|
];
|
|
}
|
|
if ($data['status'] == 2) {
|
|
$smsData = [
|
|
'phone' => $intention['phone'],
|
|
'date' => date('m月d日', strtotime($intention->create_time)),
|
|
'mer' => $intention['mer_name'],
|
|
'site' => systemConfig('site_name'),
|
|
];
|
|
}
|
|
|
|
Db::transaction(function () use ($config, $intention, $data, $create,$margin,$merData,$smsData) {
|
|
if ($data['status'] == 1) {
|
|
if ($create == 1) {
|
|
$merchant = app()->make(MerchantRepository::class)->createMerchant($merData);
|
|
$data['mer_id'] = $merchant->mer_id;
|
|
// 存在默认管理员信息 生成管理员
|
|
if($intention->manage_uid > 0){
|
|
$staffUserInfo = User::where('uid',$intention->manage_uid)->findOrEmpty()->toArray();
|
|
$staffData = [
|
|
'uid' => $intention->manage_uid,
|
|
'nickname' => $staffUserInfo['nickname'] ?? $staffUserInfo['real_name'],
|
|
'account' => $intention->phone,
|
|
'pwd' => substr($intention->phone,-6,6),
|
|
'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' => $intention->phone,
|
|
'sort' => 1,
|
|
'mer_id' => $merchant->mer_id,
|
|
'is_manage' => 1
|
|
];
|
|
app()->make(StoreServiceRepository::class)->createInfo($staffData);
|
|
}
|
|
|
|
Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_SUCCESS', 'id' => $smsData]);
|
|
}
|
|
} else {
|
|
Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_FAIL', 'id' => $smsData]);
|
|
}
|
|
|
|
$intention->save($data);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Common: 判断:指定用户是否存在审核中店铺的管理员信息
|
|
* Author: wu-hui
|
|
* Time: 2024/01/19 15:59
|
|
* @param int $uid
|
|
* @param int $id
|
|
* @return bool
|
|
*/
|
|
public function isManage(int $uid,int $id = 0):bool{
|
|
$count = $this->dao->getSearch([])
|
|
->where('manage_uid',$uid)
|
|
->where('status',0)
|
|
->where('is_del',0)
|
|
->when($id > 0,function($query) use ($id){
|
|
$query->where('mer_intention_id','<>',$id);
|
|
})->count();
|
|
|
|
return $count > 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|