|
|
<?php
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
use App\Exports\BaseExport;
|
|
|
use App\Exports\CommonExport;
|
|
|
use App\Helpers\ResponseCode;
|
|
|
use App\Helpers\StarterResponseCode;
|
|
|
use App\Models\Course;
|
|
|
use App\Models\CourseAppointmentTotal;
|
|
|
use App\Models\CourseSign;
|
|
|
use App\Models\CustomForm;
|
|
|
use App\Models\CustomFormField;
|
|
|
use App\Models\User;
|
|
|
use Illuminate\Support\Carbon;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
|
use Rap2hpoutre\FastExcel\FastExcel;
|
|
|
|
|
|
class UserController extends BaseController
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* 构造函数
|
|
|
*/
|
|
|
public function __construct()
|
|
|
{
|
|
|
parent::__construct(new User());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/admin/users/index",
|
|
|
* tags={"用户信息"},
|
|
|
* summary="所有用户列表",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="is_export", in="query", @OA\Schema(type="string"), required=false, description="是否导出0否1是"),
|
|
|
* @OA\Parameter(name="export_fields", in="query", @OA\Schema(type="string"), required=false, description="需要导出的字段数组"),
|
|
|
* @OA\Parameter(name="filter", in="query", @OA\Schema(type="string"), required=false, description="查询条件。数组"),
|
|
|
* @OA\Parameter(name="show_relation", in="query", @OA\Schema(type="string"), required=false, description="需要输出的关联关系数组,包括:courses,courseSigns,teacher,courseSettings,coursePeriods"),
|
|
|
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"),
|
|
|
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"),
|
|
|
* @OA\Parameter(name="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"),
|
|
|
* @OA\Parameter(name="has_course", in="query", @OA\Schema(type="string"), required=false, description="是否有课程0否1是"),
|
|
|
* @OA\Parameter(name="keyword", in="query", @OA\Schema(type="string"), required=true, description="关键词"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="暂无"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function index()
|
|
|
{
|
|
|
$all = request()->all();
|
|
|
$list = $this->model->with(underlineToHump($all['show_relation'] ?? []))
|
|
|
->with(['courseSigns' => function ($query) use ($all) {
|
|
|
$query->where('status', 1)->with('course.teacher', 'course.typeDetail');
|
|
|
}])->where(function ($query) use ($all) {
|
|
|
if (isset($all['keyword'])) {
|
|
|
$query->whereHas('courses', function ($q) use ($all) {
|
|
|
$q->where('name', 'like', '%' . $all['keyword'] . '%');
|
|
|
})->orWhere('name', 'like', '%' . $all['keyword'] . '%');
|
|
|
}
|
|
|
if (isset($all['has_course']) && $all['has_course'] == 1) {
|
|
|
$query->whereHas('courseSigns', function ($q) {
|
|
|
$q->where('status', 1);
|
|
|
});
|
|
|
}
|
|
|
if (isset($all['filter']) && !empty($all['filter'])) {
|
|
|
foreach ($all['filter'] as $condition) {
|
|
|
$key = $condition['key'] ?? null;
|
|
|
$op = $condition['op'] ?? null;
|
|
|
$value = $condition['value'] ?? null;
|
|
|
if (!isset($key) || !isset($op) || !isset($value)) {
|
|
|
continue;
|
|
|
}
|
|
|
// 等于
|
|
|
if ($op == 'eq') {
|
|
|
$query->where($key, $value);
|
|
|
}
|
|
|
// 不等于
|
|
|
if ($op == 'neq') {
|
|
|
$query->where($key, '!=', $value);
|
|
|
}
|
|
|
// 大于
|
|
|
if ($op == 'gt') {
|
|
|
$query->where($key, '>', $value);
|
|
|
}
|
|
|
// 大于等于
|
|
|
if ($op == 'egt') {
|
|
|
$query->where($key, '>=', $value);
|
|
|
}
|
|
|
// 小于
|
|
|
if ($op == 'lt') {
|
|
|
$query->where($key, '<', $value);
|
|
|
}
|
|
|
// 小于等于
|
|
|
if ($op == 'elt') {
|
|
|
$query->where($key, '<=', $value);
|
|
|
}
|
|
|
// 模糊搜索
|
|
|
if ($op == 'like') {
|
|
|
$query->where($key, 'like', '%' . $value . '%');
|
|
|
}
|
|
|
// 否定模糊搜索
|
|
|
if ($op == 'notlike') {
|
|
|
$query->where($key, 'not like', '%' . $value . '%');
|
|
|
}
|
|
|
// null搜索
|
|
|
if ($op == 'null') {
|
|
|
$query->whereNull($key);
|
|
|
}
|
|
|
// notnull搜索
|
|
|
if ($op == 'notnull') {
|
|
|
$query->whereNotNull($key);
|
|
|
}
|
|
|
// 范围搜索
|
|
|
if ($op == 'range') {
|
|
|
list($from, $to) = explode(',', $value);
|
|
|
if (empty($from) || empty($to)) {
|
|
|
continue;
|
|
|
}
|
|
|
$query->whereBetween($key, [$from, $to]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc');
|
|
|
if (isset($all['is_export']) && !empty($all['is_export'])) {
|
|
|
$list = $list->get()->toArray();
|
|
|
$export_fields = $all['export_fields'] ?? [];
|
|
|
// 导出文件名字
|
|
|
$tableName = $this->model->getTable();
|
|
|
$filename = (new CustomForm())->getTableComment($tableName);
|
|
|
return Excel::download(new BaseExport($export_fields, $list, $tableName), $filename . date('YmdHis') . '.xlsx');
|
|
|
} else {
|
|
|
// 输出
|
|
|
$list = $list->paginate($all['page_size'] ?? 20);
|
|
|
}
|
|
|
return $this->success($list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/admin/users/study",
|
|
|
* tags={"用户信息"},
|
|
|
* summary="学员管理(参与了课程的用户包含统计数据)",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="is_export", in="query", @OA\Schema(type="string"), required=false, description="是否导出0否1是"),
|
|
|
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"),
|
|
|
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"),
|
|
|
* @OA\Parameter(name="file_name", in="query", @OA\Schema(type="string"), required=false, description="导出文件名"),
|
|
|
* @OA\Parameter(name="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"),
|
|
|
* @OA\Parameter(name="sort_type", in="query", @OA\Schema(type="string"), required=false, description="排序类型"),
|
|
|
* @OA\Parameter(name="course_id", in="query", @OA\Schema(type="string"), required=false, description="课程id"),
|
|
|
* @OA\Parameter(name="course_name", in="query", @OA\Schema(type="string"), required=false, description="课程名称"),
|
|
|
* @OA\Parameter(name="name", in="query", @OA\Schema(type="string"), required=false, description="名字"),
|
|
|
* @OA\Parameter(name="company_name", in="query", @OA\Schema(type="string"), required=false, description="公司名字"),
|
|
|
* @OA\Parameter(name="company_position", in="query", @OA\Schema(type="string"), required=false, description="职务"),
|
|
|
* @OA\Parameter(name="company_area", in="query", @OA\Schema(type="string"), required=false, description="所属区域"),
|
|
|
* @OA\Parameter(name="company_type", in="query", @OA\Schema(type="string"), required=false, description="企业性质"),
|
|
|
* @OA\Parameter(name="company_industry", in="query", @OA\Schema(type="string"), required=false, description="所属行业"),
|
|
|
* @OA\Parameter(name="courses_start_date", in="query", @OA\Schema(type="string"), required=false, description="课程开始时间"),
|
|
|
* @OA\Parameter(name="courses_end_date", in="query", @OA\Schema(type="string"), required=false, description="课程结束时间"),
|
|
|
* @OA\Parameter(name="is_vip", in="query", @OA\Schema(type="string"), required=false, description="是否vip0否1是"),
|
|
|
* @OA\Parameter(name="courses_ing", in="query", @OA\Schema(type="string"), required=false, description="是否课程进行中0否1是"),
|
|
|
* @OA\Parameter(name="is_schoolmate", in="query", @OA\Schema(type="string"), required=false, description="is_schoolmate"),
|
|
|
* @OA\Parameter(name="mobile", in="query", @OA\Schema(type="string"), required=true, description="mobile"),
|
|
|
* @OA\Parameter(name="status", in="query", @OA\Schema(type="string"), required=true, description="审核状态"),
|
|
|
* @OA\Parameter(name="course_type", in="query", @OA\Schema(type="string"), required=true, description="course_type"),
|
|
|
* @OA\Parameter(name="company_has_share", in="query", @OA\Schema(type="string"), required=true, description="是否有股份"),
|
|
|
* @OA\Parameter(name="keyword", in="query", @OA\Schema(type="string"), required=true, description="关键词"),
|
|
|
* @OA\Parameter(name="start_company_date", in="query", @OA\Schema(type="string"), required=true, description="开始成立日期"),
|
|
|
* @OA\Parameter(name="end_company_date", in="query", @OA\Schema(type="string"), required=true, description="结束成立日期"),
|
|
|
* @OA\Parameter(name="start_birthday", in="query", @OA\Schema(type="string"), required=true, description="开始出生日期"),
|
|
|
* @OA\Parameter(name="end_birthday", in="query", @OA\Schema(type="string"), required=true, description="结束出生日期"),
|
|
|
* @OA\Parameter(name="company_need_fund", in="query", @OA\Schema(type="string"), required=true, description="是否需要融资"),
|
|
|
* @OA\Parameter(name="is_fee", in="query", @OA\Schema(type="string"), required=true, description="是否缴费0否1是"),
|
|
|
* @OA\Parameter(name="has_openid", in="query", @OA\Schema(type="string"), required=true, description="是否绑定小程序0否1是"),
|
|
|
* @OA\Parameter(name="year", in="query", @OA\Schema(type="string"), required=true, description="年份"),
|
|
|
* @OA\Parameter(name="is_black", in="query", @OA\Schema(type="string"), required=true, description="是否黑名单0否1是"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="暂无"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function study()
|
|
|
{
|
|
|
$all = request()->all();
|
|
|
$year = request('year', date('Y'));
|
|
|
$list = $this->model->with('appointments', 'companyIndustryDetail',
|
|
|
'companyPositionDetail', 'companyAreaDetail')
|
|
|
->with(['courseSigns' => function ($query) {
|
|
|
$query->with('course.typeDetail')->orderBy('fee_status', 'desc');
|
|
|
}])->withCount(['appointments' => function ($query) {
|
|
|
$query->whereIn('status', [0, 1]);
|
|
|
}]);
|
|
|
$list = $list->whereHas('courseSigns', function ($query) use ($all) {
|
|
|
if (isset($all['course_id'])) {
|
|
|
$query->where('course_id', $all['course_id']);
|
|
|
}
|
|
|
if (isset($all['status'])) {
|
|
|
$query->where('status', $all['status']);
|
|
|
}
|
|
|
$query->whereHas('course', function ($q) use ($all) {
|
|
|
if (isset($all['year'])) {
|
|
|
$q->where('year', $all['year']);
|
|
|
}
|
|
|
if (isset($all['is_fee'])) {
|
|
|
$q->where('is_fee', $all['is_fee']);
|
|
|
};
|
|
|
if (isset($all['course_type'])) {
|
|
|
$q->where('type', $all['course_type']);
|
|
|
};
|
|
|
if (isset($all['course_name'])) {
|
|
|
$q->where('name', 'like', '%' . $all['course_name'] . '%');
|
|
|
}
|
|
|
if (isset($all['courses_start_date'])) {
|
|
|
$q->where('start_date', '>=', $all['courses_start_date']);
|
|
|
}
|
|
|
if (isset($all['courses_end_date'])) {
|
|
|
$q->where('end_date', '<=', $all['courses_end_date']);
|
|
|
}
|
|
|
if (isset($all['courses_ing']) && $all['courses_ing'] == 1) {
|
|
|
$q->where(function ($query) use ($all) {
|
|
|
$query->where('start_date', '<=', date('Y-m-d'))->where('end_date', '>=', date('Y-m-d'));
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
// 不通过的需要全部不通过
|
|
|
if (isset($all['status']) && $all['status'] == 2) {
|
|
|
// 筛选不通过的
|
|
|
$list = $list->whereDoesntHave('courseSigns', function ($query) {
|
|
|
$query->where('status', 1);
|
|
|
});
|
|
|
}
|
|
|
$list = $list->where(function ($query) use ($all) {
|
|
|
if (isset($all['is_vip'])) {
|
|
|
$query->where('is_vip', $all['is_vip']);
|
|
|
}
|
|
|
if (isset($all['is_black'])) {
|
|
|
$query->where('is_black', $all['is_black']);
|
|
|
}
|
|
|
if (isset($all['type'])) {
|
|
|
$type = explode(',', $all['type']);
|
|
|
$query->where(function ($q) use ($type) {
|
|
|
foreach ($type as $v) {
|
|
|
$q->orWhereRaw('FIND_IN_SET(?, type)', [$v]);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
if (isset($all['has_openid'])) {
|
|
|
if ($all['has_openid'] == 1) {
|
|
|
$query->where(function ($q) {
|
|
|
$q->whereNotNull('openid')->where('openid', '!=', '');
|
|
|
});
|
|
|
} else {
|
|
|
$query->where(function ($q) {
|
|
|
$q->whereNull('openid')->orWhere('openid', '');
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
if (isset($all['name'])) {
|
|
|
$query->where('name', 'like', '%' . $all['name'] . '%');
|
|
|
}
|
|
|
if (isset($all['company_name'])) {
|
|
|
$query->where('company_name', 'like', '%' . $all['company_name'] . '%');
|
|
|
}
|
|
|
if (isset($all['company_position'])) {
|
|
|
$query->where('company_position', $all['company_position']);
|
|
|
}
|
|
|
if (isset($all['company_area'])) {
|
|
|
$company_area = explode(',', $all['company_area']);
|
|
|
$query->whereIn('company_area', $company_area);
|
|
|
}
|
|
|
if (isset($all['company_type'])) {
|
|
|
$company_type = explode(',', $all['company_type']);
|
|
|
$query->where(function ($q) use ($company_type) {
|
|
|
foreach ($company_type as $v) {
|
|
|
$q->orWhereRaw('FIND_IN_SET(?, company_type)', [$v]);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
if (isset($all['company_industry'])) {
|
|
|
$company_industry = explode(',', $all['company_industry']);
|
|
|
$query->where(function ($q) use ($company_industry) {
|
|
|
foreach ($company_industry as $v) {
|
|
|
$q->orWhereRaw('FIND_IN_SET(?, company_industry)', [$v]);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
if (isset($all['is_schoolmate'])) {
|
|
|
$query->where('is_schoolmate', $all['is_schoolmate']);
|
|
|
}
|
|
|
if (isset($all['company_need_fund'])) {
|
|
|
$query->where('company_need_fund', $all['company_need_fund']);
|
|
|
}
|
|
|
if (isset($all['mobile'])) {
|
|
|
$query->where('mobile', 'like', '%' . $all['mobile'] . '%');
|
|
|
}
|
|
|
if (isset($all['education'])) {
|
|
|
$education = explode(',', $all['education']);
|
|
|
$query->whereIn('education', $education);
|
|
|
}
|
|
|
if (isset($all['company_has_share'])) {
|
|
|
$query->where('company_has_share', $all['company_has_share']);
|
|
|
}
|
|
|
if (isset($all['school'])) {
|
|
|
$query->where('school', 'like', '%' . $all['school'] . '%');
|
|
|
}
|
|
|
if (isset($all['start_company_date']) && isset($all['end_company_date'])) {
|
|
|
$query->whereBetween('company_date', [$all['start_company_date'], $all['end_company_date']]);
|
|
|
}
|
|
|
if (isset($all['start_birthday']) && isset($all['end_birthday'])) {
|
|
|
$query->whereBetween('birthday', [$all['start_birthday'], $all['end_birthday']]);
|
|
|
}
|
|
|
if (isset($all['keyword'])) {
|
|
|
$query->where('school', 'like', '%' . $all['keyword'] . '%')
|
|
|
->orWhere('speciality', 'like', '%' . $all['keyword'] . '%')
|
|
|
->orWhere('introduce', 'like', '%' . $all['keyword'] . '%');
|
|
|
}
|
|
|
})->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc');
|
|
|
if (isset($all['is_export']) && !empty($all['is_export'])) {
|
|
|
$list = $list->limit(5000)->get()->toArray();
|
|
|
return Excel::download(new CommonExport($list, $all['export_fields'] ?? ''), $all['file_name'] ?? '' . date('YmdHis') . '.xlsx');
|
|
|
} else {
|
|
|
$total = $this->model->whereHas('courseSigns')->count();
|
|
|
$year_total = $this->model->whereHas('courseSigns', function ($query) use ($year) {
|
|
|
$query->whereHas('course', function ($q) use ($year) {
|
|
|
$q->where('year', $year);
|
|
|
});
|
|
|
})->count();
|
|
|
// 年度培养学员
|
|
|
$year_training_total = $this->model->whereHas('courseSigns', function ($query) use ($year) {
|
|
|
$query->where('status', 1)->whereHas('course', function ($q) use ($year) {
|
|
|
$q->where('year', $year);
|
|
|
});
|
|
|
})->count();
|
|
|
// 累计培养学员
|
|
|
$training_total = $this->model->whereHas('courseSigns', function ($query) use ($year) {
|
|
|
$query->where('status', 1);
|
|
|
})->count();
|
|
|
$list = $list->paginate($all['page_size'] ?? 20);
|
|
|
}
|
|
|
return $this->success(['list' => $list, 'year_total' => $year_total, 'total' => $total, 'year_training_total' => $year_training_total, 'training_total' => $training_total]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/admin/users/show",
|
|
|
* tags={"用户信息"},
|
|
|
* summary="详情",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=true, description="id"),
|
|
|
* @OA\Parameter(name="show_relation", in="query", @OA\Schema(type="string"), required=false, description="需要输出的关联关系数组,填写输出指定数据"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="暂无"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function show()
|
|
|
{
|
|
|
return parent::show();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Post(
|
|
|
* path="/api/admin/users/save",
|
|
|
* tags={"时间段设置"},
|
|
|
* summary="更新或新增",
|
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="integer"), required=true, description="课程ID(存在则更新,不存在则新增)"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="访问令牌"),
|
|
|
* @OA\Parameter(name="openid", in="query", @OA\Schema(type="string"), description="用户openid"),
|
|
|
* @OA\Parameter(name="sex", in="query", @OA\Schema(type="string"), description="性别男/女"),
|
|
|
* @OA\Parameter(name="nickname", in="query", @OA\Schema(type="string"), description="昵称"),
|
|
|
* @OA\Parameter(name="mobile", in="query", @OA\Schema(type="string"), description="手机号"),
|
|
|
* @OA\Parameter(name="country", in="query", @OA\Schema(type="string"), description="国家"),
|
|
|
* @OA\Parameter(name="province", in="query", @OA\Schema(type="string"), description="省份"),
|
|
|
* @OA\Parameter(name="city", in="query", @OA\Schema(type="string"), description="城市"),
|
|
|
* @OA\Parameter(name="headimgurl", in="query", @OA\Schema(type="string"), description="头像URL"),
|
|
|
* @OA\Parameter(name="username", in="query", @OA\Schema(type="string"), description="用户名"),
|
|
|
* @OA\Parameter(name="password", in="query", @OA\Schema(type="string"), description="密码"),
|
|
|
* @OA\Parameter(name="name", in="query", @OA\Schema(type="string"), description="名字"),
|
|
|
* @OA\Parameter(name="birthday", in="query", @OA\Schema(type="string"), description="生日"),
|
|
|
* @OA\Parameter(name="email", in="query", @OA\Schema(type="string"), description="邮箱"),
|
|
|
* @OA\Parameter(name="education", in="query", @OA\Schema(type="integer"), description="学历"),
|
|
|
* @OA\Parameter(name="school", in="query", @OA\Schema(type="string"), description="学校"),
|
|
|
* @OA\Parameter(name="speciality", in="query", @OA\Schema(type="string"), description="专业"),
|
|
|
* @OA\Parameter(name="honour", in="query", @OA\Schema(type="string"), description="荣誉"),
|
|
|
* @OA\Parameter(name="introduce", in="query", @OA\Schema(type="string"), description="介绍"),
|
|
|
* @OA\Parameter(name="company_name", in="query", @OA\Schema(type="string"), description="公司名称"),
|
|
|
* @OA\Parameter(name="company_position", in="query", @OA\Schema(type="string"), description="个人职务"),
|
|
|
* @OA\Parameter(name="company_has_share", in="query", @OA\Schema(type="string"), description="是否有股份0否1是"),
|
|
|
* @OA\Parameter(name="company_build_date", in="query", @OA\Schema(type="string"), description="公司成立日期"),
|
|
|
* @OA\Parameter(name="company_area", in="query", @OA\Schema(type="string"), description="公司区域-数据字典"),
|
|
|
* @OA\Parameter(name="company_type", in="query", @OA\Schema(type="string"), description="公司性质-数据字典"),
|
|
|
* @OA\Parameter(name="company_industry", in="query", @OA\Schema(type="string"), description="公司所属行业-数据字典"),
|
|
|
* @OA\Parameter(name="company_business", in="query", @OA\Schema(type="string"), description="公司主营业务"),
|
|
|
* @OA\Parameter(name="company_fund", in="query", @OA\Schema(type="string"), description="公司融资情况0否1是"),
|
|
|
* @OA\Parameter(name="company_need_fund", in="query", @OA\Schema(type="integer"), description="公司是否需要融资0否1是"),
|
|
|
* @OA\Parameter(name="sign_from", in="query", @OA\Schema(type="string"), description="报名信息来源"),
|
|
|
* @OA\Parameter(name="remark", in="query", @OA\Schema(type="string"), description="备注"),
|
|
|
* @OA\Parameter(name="is_black", in="query", @OA\Schema(type="string"), description="是否黑名单0否1是"),
|
|
|
* @OA\Parameter(name="has_appointment_total", in="query", @OA\Schema(type="string"), description="预约剩余次数"),
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function save()
|
|
|
{
|
|
|
return parent::save();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/admin/users/destroy",
|
|
|
* tags={"用户信息"},
|
|
|
* summary="删除",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=true, description="id"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="暂无"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function destroy()
|
|
|
{
|
|
|
return parent::destroy();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Post(
|
|
|
* path="/api/admin/users/excel-show",
|
|
|
* tags={"用户信息"},
|
|
|
* summary="导入预览",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="file", in="query", @OA\Schema(type="string"), required=true, description="文件"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="暂无"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function excelShow()
|
|
|
{
|
|
|
$file = \request()->file('file');
|
|
|
$data = \request('data', []);
|
|
|
//判断文件是否有效
|
|
|
if (!(\request()->hasFile('file') && $file->isValid())) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '文件不存在或无效']);
|
|
|
}
|
|
|
//获取文件大小
|
|
|
$img_size = floor($file->getSize() / 1024);
|
|
|
if ($img_size >= 50 * 1024) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '文件必须小于50M']);
|
|
|
}
|
|
|
//过滤文件后缀
|
|
|
$ext = $file->getClientOriginalExtension();
|
|
|
if (!in_array($ext, ['xls', 'xlsx', 'csv'])) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '仅支持xls/xlsx/csv格式']);
|
|
|
}
|
|
|
$tempFile = $file->getRealPath();
|
|
|
$dataArray = (new FastExcel)->import($tempFile)->toArray();
|
|
|
// 数据过滤,只能导入数据表有的字段
|
|
|
$tableName = $this->model->getTable();
|
|
|
$rowTableFieldByComment = (new CustomFormField)->getRowTableFieldsByComment($tableName);
|
|
|
$list = [];
|
|
|
$statusList = CourseSign::$intToString['status'];
|
|
|
$statusList = array_flip($statusList);
|
|
|
foreach ($dataArray as $key => $value) {
|
|
|
// 获取课程id
|
|
|
$course = Course::where('name', $value['课程名称'])->first();
|
|
|
$list[$key]['course_id'] = $course->id ?? 0;
|
|
|
$list[$key]['course_name'] = $value['课程名称'] ?? '';
|
|
|
// 默认没有付费
|
|
|
$list[$key]['fee_status'] = 0;
|
|
|
$list[$key]['status'] = $list[$key]['status_name'] = null;
|
|
|
if (isset($value['审核状态'])) {
|
|
|
// 获取审核状态
|
|
|
$list[$key]['status'] = $statusList[$value['审核状态']];
|
|
|
$list[$key]['status_name'] = $value['审核状态'];
|
|
|
if ($list[$key]['status'] == 1) {
|
|
|
// 审核通过,则付费情况根据课程情况定
|
|
|
$list[$key]['fee_status'] = $course->is_fee ?? 0;
|
|
|
}
|
|
|
}
|
|
|
foreach ($rowTableFieldByComment as $k => $v) {
|
|
|
if (isset($value[$v])) {
|
|
|
// 日期格式
|
|
|
if ($value[$v] instanceof \DateTimeImmutable) {
|
|
|
$list[$key][$k] = Carbon::parse($value[$v])->toDateString();
|
|
|
} else {
|
|
|
if (in_array($k, ['company_type', 'type'])) {
|
|
|
$list[$key][$k] = str_replace('、', ',', $value[$v]);
|
|
|
$list[$key][$k] = str_replace(',', ',', $list[$key][$k]);;
|
|
|
} else {
|
|
|
$list[$key][$k] = $value[$v];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return $this->success($list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Post(
|
|
|
* path="/api/admin/users/import",
|
|
|
* tags={"用户信息"},
|
|
|
* summary="导入",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="data", in="query", @OA\Schema(type="string"), required=true, description="导入分析获取到的二维数组"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="暂无"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function import()
|
|
|
{
|
|
|
return parent::import();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Post(
|
|
|
* path="/api/admin/users/import-study",
|
|
|
* tags={"用户信息"},
|
|
|
* summary="导入学员信息(旧的校友库导入)",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="data", in="query", @OA\Schema(type="string"), required=true, description="导入分析获取到的二维数组"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="暂无"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function importStudy()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'data.required' => '数据必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'data' => 'required',
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$filteredRecords = $all['data'];
|
|
|
$suc = 0;
|
|
|
DB::beginTransaction();
|
|
|
try {
|
|
|
// 一个个新增,因为需要设置关联表的id
|
|
|
foreach ($filteredRecords as $record) {
|
|
|
if (empty($record['mobile'])) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, ($record['姓名'] ?? '') . '手机号不存在']);
|
|
|
}
|
|
|
$record['is_import'] = 1;
|
|
|
$record['username'] = $record['name'];
|
|
|
$record['is_vip'] = $record['fee_status'] == 1 ? 1 : 0;
|
|
|
$where = ['mobile' => $record['mobile']];
|
|
|
// 去除空值更新
|
|
|
$record = array_filter($record, function ($value) {
|
|
|
return $value != '';
|
|
|
});
|
|
|
// 所有数据通过追加的形式更新
|
|
|
$user = $this->model->where($where)->first();
|
|
|
if ($user) {
|
|
|
// 更新,所有$record里的数组通过追加在原来数据后面的形式更新
|
|
|
foreach ($record as $k => &$v) {
|
|
|
if (!in_array($k, User::$coverFields)) {
|
|
|
// 追加更新
|
|
|
$tempArray = explode(',', $user->$k . ',' . $v);
|
|
|
$tempArray = array_unique(array_filter($tempArray));
|
|
|
$v = implode(',', $tempArray);
|
|
|
}
|
|
|
}
|
|
|
$user->fill($record);
|
|
|
$user->save();
|
|
|
} else {
|
|
|
// 新增
|
|
|
$user = $this->model->create($record);
|
|
|
}
|
|
|
// 写入报名表
|
|
|
if (isset($record['course_id']) && !empty($record['course_id'])) {
|
|
|
$whereSign = ['course_id' => $record['course_id'], 'user_id' => $user->id];
|
|
|
$dataSign = [
|
|
|
'course_id' => $record['course_id'],
|
|
|
'user_id' => $user->id,
|
|
|
'is_import' => 1,
|
|
|
'status' => $record['status'] ?? 1,
|
|
|
'fee_status' => $record['fee_status']
|
|
|
];
|
|
|
$courseSign = CourseSign::updateOrCreate($whereSign, $dataSign);
|
|
|
// 加导入次数,加预约次数
|
|
|
if ($courseSign->status == 1) {
|
|
|
CourseAppointmentTotal::add($courseSign->user_id, $courseSign->id);
|
|
|
}
|
|
|
}
|
|
|
$suc++;
|
|
|
}
|
|
|
DB::commit();
|
|
|
return $this->success(['total' => count($filteredRecords), 'suc' => $suc]);
|
|
|
} catch (\Exception $exception) {
|
|
|
DB::rollBack();
|
|
|
return $this->fail([$exception->getCode(), $exception->getMessage()]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Post(
|
|
|
* path="/api/admin/users/batch-update-schoolmate",
|
|
|
* tags={"用户信息"},
|
|
|
* summary="设置取消校友库",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="ids", in="query", @OA\Schema(type="string"), required=true, description="英文逗号分隔的id数组"),
|
|
|
* @OA\Parameter(name="is_schoolmate", in="query", @OA\Schema(type="string"), required=true, description="是否校友库-0否1是"),
|
|
|
* @OA\Parameter(name="is_black", in="query", @OA\Schema(type="string"), required=true, description="是否黑名单-0否1是"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="暂无"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function batchUpdateSchoolmate()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'ids.required' => '编号必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'ids' => 'required',
|
|
|
], $messages);
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([StarterResponseCode::START_ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$idsArray = explode(',', $all['ids']);
|
|
|
$data = [];
|
|
|
if (isset($all['is_schoolmate'])) {
|
|
|
$data['is_schoolmate'] = $all['is_schoolmate'];
|
|
|
}
|
|
|
// if (isset($all['is_black'])) {
|
|
|
// $data['is_black'] = $all['is_black'];
|
|
|
// }
|
|
|
$this->model->whereIn('id', $idsArray)->update($data);
|
|
|
return $this->success('批量更新成功');
|
|
|
}
|
|
|
|
|
|
}
|