You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
177 lines
5.9 KiB
177 lines
5.9 KiB
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\api\model\dealer\User as DealerUserModel;
|
|
use app\api\model\Invite\InviteLog;
|
|
use app\api\model\wholesaler\Apply;
|
|
use app\api\service\User as UserService;
|
|
use app\common\enum\WholesalerEnum;
|
|
use app\common\model\invite\InviteConfig;
|
|
use cores\exception\BaseException;
|
|
use think\db\exception\DbException;
|
|
use think\response\Json;
|
|
use app\common\model\UploadFile;
|
|
use app\common\model\dealer\Setting;
|
|
use app\store\model\User;
|
|
use app\store\model\user\GradeLog;
|
|
|
|
class Invite extends Controller
|
|
{
|
|
/**
|
|
* @notes:基本信息
|
|
* @return Json
|
|
* @throws BaseException
|
|
* @author: wanghousheng
|
|
*/
|
|
public function index(): Json
|
|
{
|
|
$info = InviteConfig::detail([], ['coupon']);
|
|
$data = [];
|
|
if ($info) {
|
|
$data['one_order_rate'] = $info['one_order_rate'];
|
|
$data['integral'] = $info['integral'];
|
|
$data['coupon_name'] = $info['coupon']['name'];
|
|
$model = new InviteLog();
|
|
$data['money'] = $model->sumMoney();
|
|
$data['count_people'] = $model->countPeople();
|
|
}
|
|
return $this->renderSuccess($data);
|
|
}
|
|
|
|
/**
|
|
* @notes:邀请记录
|
|
* @throws BaseException
|
|
* @throws DbException
|
|
* @author: wanghousheng
|
|
*/
|
|
public function getList(): Json
|
|
{
|
|
$model = new InviteLog();
|
|
$list = $model->getList();
|
|
return $this->renderSuccess(compact('list'));
|
|
}
|
|
|
|
/**
|
|
* @notes:
|
|
* @return Json
|
|
* @throws BaseException
|
|
* @author: wanghousheng
|
|
*/
|
|
public function statistics(): Json
|
|
{
|
|
$refuse_num = 0;
|
|
$adoption_num = 0;
|
|
$money = 0;
|
|
$model = new InviteLog();
|
|
$user_ids = $model->inviteeUserIds();
|
|
if ($user_ids) {
|
|
$applyModel = new Apply();
|
|
//审核通过
|
|
$adoption_num = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::ADOPT])->count();
|
|
//审核拒绝
|
|
$refuse_num = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::REFUSE])->count();
|
|
}
|
|
// 当前用户ID
|
|
$userId = UserService::getCurrentLoginUserId();
|
|
// 分销商用户详情
|
|
$dealer = DealerUserModel::detail($userId, []);
|
|
if (!empty($dealer->freeze_money)) {
|
|
$money = $dealer->freeze_money;
|
|
}
|
|
$data = compact('refuse_num', 'adoption_num', 'money');
|
|
return $this->renderSuccess($data);
|
|
}
|
|
|
|
/**
|
|
* @notes:邀请采购商列表
|
|
* @return Json
|
|
* @throws BaseException
|
|
* @throws DbException
|
|
* @author: wanghousheng
|
|
*/
|
|
public function inviteWholesalerList(): Json
|
|
{
|
|
$data['list'] = [];
|
|
$data['total'] = 0;
|
|
$data['adoption_num'] = 0;
|
|
$data['refuse_num'] = 0;
|
|
$model = new InviteLog();
|
|
$user_ids = $model->inviteeUserIds();
|
|
$status = intval($this->request->post('status'));
|
|
if (!$status) {
|
|
$status = WholesalerEnum::ADOPT;
|
|
}
|
|
if ($user_ids) {
|
|
$applyModel = new Apply();
|
|
$list = $applyModel->whereIn('user_id', $user_ids)
|
|
->with(['avatarImg'])
|
|
->where(['status' => $status])
|
|
->order('id desc')
|
|
->paginate(15);
|
|
foreach ($list as &$item) {
|
|
$item['user_type'] = User::withoutGlobalScope()->where('user_id',$item['user_id'])->value('user_type');
|
|
$item['avatar_url'] = (UploadFile::withoutGlobalScope()->where('file_id',$item['avatar_id'])->find())['preview_url'];
|
|
$item['desensitization_mobile'] = hide_mobile($item['mobile']);
|
|
|
|
}
|
|
$data['list'] = $list->items();
|
|
$data['total'] = $list->total();
|
|
//审核通过
|
|
$data['adoption_num'] = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::ADOPT])->count();
|
|
//审核拒绝
|
|
$data['refuse_num'] = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::REFUSE])->count();
|
|
}
|
|
return $this->renderSuccess($data);
|
|
}
|
|
|
|
//立即升级服务商
|
|
public function upgradeWholesaler(): Json
|
|
{
|
|
$storeId = $this->storeId;
|
|
//1.查询需要的邀请人数是多少
|
|
$setting = Setting::where(['key'=>'condition'])->field('values')->find();
|
|
$setting = json_decode($setting,true);
|
|
$invite_num = $setting['values']['invite_num'] ?? 10;
|
|
//2.查询当前用户邀请的人数,判断比较
|
|
$model = new InviteLog();
|
|
$user_ids = $model->inviteeUserIds();
|
|
if (count($user_ids) < $invite_num) {
|
|
return $this->renderError('邀请人数不够');
|
|
}
|
|
|
|
// 获取当前日期时间
|
|
$now = time();
|
|
// 获取明年今天的日期时间
|
|
$nextYearToday = strtotime("+1 year", $now);
|
|
// 格式化日期时间为 Y-m-d H:i:s
|
|
$formattedDate = date("Y-m-d", $nextYearToday);
|
|
|
|
$applyModel = new Apply();
|
|
$list_count = $applyModel->whereIn('user_id', $user_ids)
|
|
->with(['avatarImg'])
|
|
->where(['status' => 20])
|
|
->count();
|
|
if($list_count >= $invite_num){
|
|
$data = [
|
|
'user_type' => 30,
|
|
'fx_effective_time' => $formattedDate,
|
|
'update_time'=>time()
|
|
];
|
|
|
|
User::where('user_id',$this->user['user_id'])->save($data);
|
|
|
|
$gradeLog = [
|
|
'user_id' => $this->user['user_id'],
|
|
'store_id' => $storeId,
|
|
'change_type' => 20,
|
|
'remark' => '邀请人数达到升级服务商',
|
|
'create_time' => time(),
|
|
];
|
|
GradeLog::create($gradeLog);
|
|
return $this->renderSuccess('升级成功');
|
|
}
|
|
|
|
return $this->renderError('升级失败,邀请人数不够');
|
|
}
|
|
} |