134 lines
4.5 KiB
PHP
134 lines
4.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace app\services\agent;
|
||
|
|
|
||
|
|
use app\dao\agent\PromoterApplyDao;
|
||
|
|
use app\services\BaseServices;
|
||
|
|
use app\services\other\AgreementServices;
|
||
|
|
use app\services\user\UserServices;
|
||
|
|
use crmeb\exceptions\ApiException;
|
||
|
|
use crmeb\services\FormBuilder as Form;
|
||
|
|
use think\annotation\Inject;
|
||
|
|
|
||
|
|
class PromoterApplyServices extends BaseServices
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* @var PromoterApplyDao
|
||
|
|
*/
|
||
|
|
#[Inject]
|
||
|
|
protected PromoterApplyDao $dao;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取推广员申请信息
|
||
|
|
* @param int $uid 用户ID
|
||
|
|
* @param array $user 用户信息
|
||
|
|
* @return array
|
||
|
|
*/
|
||
|
|
public function applyInfo($uid, $user)
|
||
|
|
{
|
||
|
|
$applyInfo = $this->dao->get(['uid' => $uid, 'is_del' => 0]);
|
||
|
|
$user = [
|
||
|
|
'id' => $applyInfo['id'] ?? 0,
|
||
|
|
'uid' => $uid,
|
||
|
|
'nickname' => $user['nickname'] ?? '',
|
||
|
|
'real_name' => $user['real_name'] ?? '',
|
||
|
|
'phone' => $user['phone'] ?? '',
|
||
|
|
'status' => $applyInfo ? $applyInfo['status'] : -1,
|
||
|
|
'refusal_reason' => $applyInfo ? $applyInfo['refusal_reason'] : '',
|
||
|
|
'add_time' => $applyInfo ? date('Y/m/d H:i', $applyInfo['add_time']) : '',
|
||
|
|
'status_time' => $applyInfo && $applyInfo['status_time'] ? date('Y/m/d H:i', $applyInfo['status_time']) : '',
|
||
|
|
];
|
||
|
|
$agreement = app()->make(AgreementServices::class)->getAgreementBytype(2);
|
||
|
|
return compact('user', 'agreement');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 申请成为推广员
|
||
|
|
* @param array $data 申请数据
|
||
|
|
* @param int $id 申请记录ID
|
||
|
|
* @param array $userInfo 用户信息
|
||
|
|
* @return int
|
||
|
|
* @throws ApiException
|
||
|
|
*/
|
||
|
|
public function applyPromoter($data, $id, $userInfo)
|
||
|
|
{
|
||
|
|
if (!sys_config('brokerage_func_status')) throw new ApiException('未开启推广功能');
|
||
|
|
if (sys_config('store_brokerage_statu') != 1) throw new ApiException('非指定分销模式无需申请推广员');
|
||
|
|
if ($userInfo['is_promoter']) throw new ApiException('您已经是推广员');
|
||
|
|
if ($data['phone'] != $userInfo['phone']) {
|
||
|
|
$phoneUsed = app()->make(UserServices::class)->count(['phone' => $data['phone']]);
|
||
|
|
if ($phoneUsed) throw new ApiException('该手机号已被使用');
|
||
|
|
}
|
||
|
|
if ($id) {
|
||
|
|
$data['status'] = 0;
|
||
|
|
$res = $this->dao->update(['id' => $id], $data);
|
||
|
|
} else {
|
||
|
|
$data['add_time'] = time();
|
||
|
|
$this->dao->update(['uid' => $data['uid']], ['is_del' => 1]);
|
||
|
|
$res = $this->dao->save($data);
|
||
|
|
$id = $res->id;
|
||
|
|
}
|
||
|
|
if (!$res) throw new ApiException('申请失败');
|
||
|
|
return $id;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取推广员申请列表
|
||
|
|
* @param array $where 查询条件
|
||
|
|
* @return array
|
||
|
|
*/
|
||
|
|
public function applyList($where)
|
||
|
|
{
|
||
|
|
[$page, $limit] = $this->getPageValue();
|
||
|
|
$list = $this->dao->applyList($where, $page, $limit);
|
||
|
|
foreach ($list as &$item) {
|
||
|
|
$item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
|
||
|
|
$item['status_time'] = date('Y-m-d H:i:s', $item['status_time']);
|
||
|
|
}
|
||
|
|
$count = $this->dao->applyCount($where);
|
||
|
|
return compact('list', 'count');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 删除推广员申请记录
|
||
|
|
* @param int $id 申请记录ID
|
||
|
|
* @return bool
|
||
|
|
*/
|
||
|
|
public function applyDelete($id)
|
||
|
|
{
|
||
|
|
$this->dao->update(['id' => $id], ['is_del' => 1]);
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取推广员审核表单
|
||
|
|
* @param int $id 申请记录ID
|
||
|
|
* @return array
|
||
|
|
*/
|
||
|
|
public function applyExamine($id)
|
||
|
|
{
|
||
|
|
$field = [];
|
||
|
|
$field[] = Form::radio('status', '状态:', 1)->options([['label' => '通过', 'value' => 1], ['label' => '拒绝', 'value' => 2]]);
|
||
|
|
$field[] = Form::textarea('refusal_reason', '备注:', '')->rows(5);
|
||
|
|
return create_form('分销员审核', $field, $this->url('/agent/promoter/apply/examine/' . $id), 'POST');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 保存推广员审核结果
|
||
|
|
* @param int $id 申请记录ID
|
||
|
|
* @param array $data 审核数据
|
||
|
|
* @return bool
|
||
|
|
* @throws ApiException
|
||
|
|
*/
|
||
|
|
public function applyExamineSave($id, $data)
|
||
|
|
{
|
||
|
|
$info = $this->dao->get($id);
|
||
|
|
if (!$info) throw new ApiException('申请不存在');
|
||
|
|
$this->dao->update(['id' => $id], ['status' => $data['status'], 'refusal_reason' => $data['refusal_reason'], 'status_time' => time()]);
|
||
|
|
if ($data['status'] == 1) {
|
||
|
|
app()->make(UserServices::class)->update(['uid' => $info['uid']], ['is_promoter' => 1]);
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|