This commit is contained in:
2025-03-17 18:01:53 +08:00
parent e3e9d990bb
commit 43897af989
13 changed files with 210 additions and 59 deletions
+13 -7
View File
@@ -14,12 +14,11 @@ class AreaController
$parentId = Util::getParam($request,'parent_id'); $parentId = Util::getParam($request,'parent_id');
$level = Util::getParam($request,'level')?:1; $level = Util::getParam($request,'level')?:1;
$list = $this->getRegions($parentId, $level); $list = $this->getRegions($parentId, $level);
return json($list); return Util::success($list);
} }
//递归查询
function getRegions($parentId = null, $level = 1, $child = true) {
function getRegions($parentId = null, $level = 1) {
$regions = []; $regions = [];
$where= array(); $where= array();
@@ -30,13 +29,20 @@ class AreaController
$results = Area::where($where)->get(); $results = Area::where($where)->get();
foreach ($results as $row) { foreach ($results as $row) {
// $row['level'] = $level; // 添加层级信息 if($child){
// $regions = array_merge($regions, $this->getRegions($row['id'], $level + 1)); // 递归调用 $row['children'] = $this->getRegions($row['id'], $row['level'] + 1);
$row['children'] = $this->getRegions($row['id'], $row['level'] + 1); }
$regions[] = $row; $regions[] = $row;
} }
return $regions; return $regions;
} }
public function getCountry (Request $request)
{
$level = Util::getParam($request,'level')?:1;
$list = $this->getRegions(null, $level,false);
return Util::success($list);
}
} }
+2 -1
View File
@@ -4,6 +4,7 @@ namespace app\controller;
use app\model\CarType; use app\model\CarType;
use app\model\Customer; use app\model\Customer;
use app\util\Util;
use PDO; use PDO;
use support\Db; use support\Db;
use support\Redis; use support\Redis;
@@ -15,7 +16,7 @@ class CarTypeController
public function getAll(Request $request) public function getAll(Request $request)
{ {
$list = CarType::getAll(); $list = CarType::getAll();
return json($list); return Util::success($list);
} }
} }
+24 -12
View File
@@ -2,6 +2,7 @@
namespace app\controller; namespace app\controller;
use app\model\Channel;
use app\model\Customer; use app\model\Customer;
use app\util\Util; use app\util\Util;
use config\constants\Constants; use config\constants\Constants;
@@ -10,7 +11,6 @@ use support\Request;
class CustomerController class CustomerController
{ {
/** /**
* 客户分级 * 客户分级
* @param Request $request * @param Request $request
@@ -21,28 +21,40 @@ class CustomerController
$grade = []; $grade = [];
foreach (Constants::GRADE as $key => $value) { foreach (Constants::GRADE as $key => $value) {
$grade[] = [ $grade[] = [
'status' => $key, 'id' => $key,
'text' => $value, 'name' => $value,
]; ];
} }
return json($grade); return Util::success($grade);
} }
/** /**
* 客户偏好 * 商机
* @param Request $request * @param Request $request
* @return \support\Response * @return \support\Response
*/ */
public function getCarType(Request $request) public function getMagnitude(Request $request)
{ {
$grade = []; $grade = [];
foreach (Constants::GRADE as $key => $value) { foreach (Constants::MAGNITUDE as $key => $value) {
$grade[] = [ $grade[] = [
'status' => $key, 'id' => $key,
'text' => $value, 'name' => $value,
]; ];
} }
return json($grade); return Util::success($grade);
}
/**
* 客户渠道
* @param Request $request
* @return \support\Response
*/
public function getChannel(Request $request)
{
$list = Channel::getAll();
return Util::success($list);
} }
/** /**
@@ -158,9 +170,9 @@ class CustomerController
} }
if ($res) { if ($res) {
return Util::success($res); return Util::success($res,trans('save_success'));
} else { } else {
return Util::fail($res); return Util::fail($res,trans('save_fail'));
} }
} }
+12 -8
View File
@@ -70,8 +70,11 @@ class FollowController
->orderBy('id', 'desc') ->orderBy('id', 'desc')
->paginate($perPage, ['*'], 'page', $page); ->paginate($perPage, ['*'], 'page', $page);
// $host = $request->host();
$url = 'http:'.$request->url();
foreach ($data->items() as &$value){ foreach ($data->items() as &$value){
$value = Follow::getFollow($value); $value = Follow::getFollow($value,$url);
} }
return Util::page($data); return Util::page($data);
@@ -112,6 +115,7 @@ class FollowController
public function save(Request $request) public function save(Request $request)
{ {
$customer_id = Util::getParam($request,'customer_id'); $customer_id = Util::getParam($request,'customer_id');
if(Util::isEmpty($customer_id)){ if(Util::isEmpty($customer_id)){
return Util::fail([],'customer_id'.trans('not_null')); return Util::fail([],'customer_id'.trans('not_null'));
} }
@@ -132,9 +136,9 @@ class FollowController
'remark'=>Util::getParam($request,'remark',''), 'remark'=>Util::getParam($request,'remark',''),
'audio'=>Util::getParam($request,'audio',''), 'audio'=>Util::getParam($request,'audio',''),
'audio_text'=>Util::getParam($request,'audio',''), 'audio_text'=>Util::getParam($request,'audio',''),
'lat'=>Util::getParam($request,'lat'), 'lat'=>Util::getParam($request,'lat',0),
'lng'=>Util::getParam($request,'lng'), 'lng'=>Util::getParam($request,'lng',0),
'address'=>Util::getParam($request,'address'), 'address1'=>Util::getParam($request,'address'),
]; ];
$res = Follow::create($data); $res = Follow::create($data);
@@ -143,10 +147,10 @@ class FollowController
$customer->follow_last = $res->created_at; $customer->follow_last = $res->created_at;
$customer->save(); $customer->save();
if($res){ if ($res) {
return Util::success($res); return Util::success($res,trans('save_success'));
}else{ } else {
return Util::fail($res); return Util::fail($res,trans('save_fail'));
} }
} }
+1 -1
View File
@@ -78,7 +78,7 @@ class UploadController
'size' => $fileSize 'size' => $fileSize
]); ]);
$result[] = [ $result = [
'original_name' => $file->getUploadName(), 'original_name' => $file->getUploadName(),
'saved_name' => $filename, 'saved_name' => $filename,
'path' => 'uploads/' . date('Ym') . '/' . $filename, 'path' => 'uploads/' . date('Ym') . '/' . $filename,
+84 -24
View File
@@ -14,26 +14,24 @@ class UserController
/** /**
* 不需要登录的方法 * 不需要登录的方法
*/ */
protected $noNeedLogin = ['login','sendCode']; protected $noNeedLogin = ['login', 'sendCode', 'register'];
public function login(Request $request) public function login(Request $request)
{ {
// Util::isEmpty($request->post('email')); $email = Util::getParam($request, 'email');
$email = Util::getParam($request,'email'); if (Util::isEmpty($email)) {
if(Util::isEmpty($email)){ return Util::fail([], 'email' . trans('not_null'));
return Util::fail([],'email'.trans('not_null'));
} }
// Util::isEmpty($request->post('password')); $password = Util::getParam($request, 'password');
$password = Util::getParam($request,'password'); if (Util::isEmpty($password)) {
if(Util::isEmpty($password)){ return Util::fail([], 'password' . trans('not_null'));
return Util::fail([],'password'.trans('not_null'));
} }
$user = User::select(['id','name','sex','role','avatar','email','password']) $user = User::select(['id', 'name', 'sex', 'role', 'avatar', 'email', 'password'])
->where('status',0) ->where('status', 0)
->where('email',$request->post('email')) ->where('email', $request->post('email'))
->first(); ->first();
if(!$user){ if (!$user) {
return Util::fail(['user'=>$user],trans('user_none')); return Util::fail(['user' => $user], trans('user_none'));
} }
$user = $user->toArray(); $user = $user->toArray();
@@ -44,12 +42,12 @@ class UserController
//验证密码 //验证密码
if (!password_verify($userPassword, $hashedPassword)) { if (!password_verify($userPassword, $hashedPassword)) {
return Util::fail([],trans('password_error')); return Util::fail([], trans('password_error'));
} }
$userId = $user['id']; // 实际从数据库获取 $userId = $user['id']; // 实际从数据库获取
Redis::set('user_'.$userId, $user); Redis::set('user_' . $userId, $user);
//密码验证成功后加密生成 Token //密码验证成功后加密生成 Token
$token = JwtUtil::generateToken($userId); $token = JwtUtil::generateToken($userId);
@@ -57,7 +55,7 @@ class UserController
unset($result['password']); unset($result['password']);
$result['token'] = $token; $result['token'] = $token;
return Util::success($result,trans('login_success')); return Util::success($result, trans('login_success'));
} }
/** /**
@@ -68,10 +66,9 @@ class UserController
*/ */
public function sendCode(Request $request) public function sendCode(Request $request)
{ {
// $email = $request->input('email'); $email = Util::getParam($request,'email');
$email = '1696136552@qq.com';
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
return json(['code' => 400, 'msg' => '邮箱格式错误']); return Util::fail([], 'email' . trans('not_null'));
} }
// 生成验证码 // 生成验证码
@@ -82,13 +79,76 @@ class UserController
if ($mailService->sendVerificationCode($email, $code)) { if ($mailService->sendVerificationCode($email, $code)) {
// 存储验证码到 Redis // 存储验证码到 Redis
Redis::set("verification_code:{$email}", $code, 300); Redis::set("verification_code:{$email}", $code, 300);
return Util::success([],'验证码已发送'); return Util::success([], '验证码已发送');
} }
return Util::fail([],'邮件发送失败'); return Util::fail([], '邮件发送失败');
}
/**
* 注册
* @param Request $request
* @return \support\Response
* @throws \Random\RandomException
*/
public function register(Request $request)
{
$email = Util::getParam($request,'email','asdf');
$code = Util::getParam($request,'code');
$sex = Util::getParam($request,'sex',0);
$name = Util::getParam($request,'name',0);
$password = Util::getParam($request,'password');
$mobile = Util::getParam($request,'mobile');
$id = Util::getParam($request,'id');
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
return Util::fail([], 'email'.$email . trans('not_null'));
}
$res = User::select('id', 'email')
->where('email', $email)
->first();
// if (!Util::isEmpty($res)) {
// return Util::fail([], trans('email_repeat'));
// }
if (Util::isEmpty($name)) {
return Util::fail([], 'name' . trans('not_null'));
}
$verification_code = Redis::get("verification_code:{$email}");
if ($code != $verification_code) {
return Util::fail([], trans('code_error'));
}
//加密
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
$data = [
'mobile' => $mobile,
'email' => $email,
'name' => $name,
'sex' => $sex,
'role' => 1,
'password' => $hashedPassword,
];
if (Util::isEmpty($id)) {
$res = User::create($data);
} else {
$res = User::where('id', $id)
->update($data);
// Log::info('update', ['res' => $res]);
(!$res)?: $res=User::find($id)->toArray();
}
if ($res) {
return Util::success($res);
} else {
return Util::fail($res);
}
} }
} }
+1 -3
View File
@@ -5,8 +5,6 @@ namespace app\model;
use support\Model; use support\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class CarType extends Model class CarType extends Model
{ {
/** /**
@@ -32,7 +30,7 @@ class CarType extends Model
public static function getAll() public static function getAll()
{ {
$list = CarType::get()->select('id','name','status')->where('status',0)->toArray(); $list = self::get()->select('id','name','status')->where('status',0)->toArray();
return $list; return $list;
} }
} }
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace app\model;
use support\Model;
class Channel extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'channel';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
//设置黑名单
protected $guarded = ['id','created_at','updated_at'];
// 指定日期字段存储格式为时间戳
protected $dateFormat = 'U';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
protected $casts = [
// 'updated_at' => 'datetime:Y-m-d H:i:s', // 指定序列化格式
// 'created_at' => 'datetime:Y-m-d H:i:s', // 指定序列化格式
'updated_at' => 'timestamp', // 指定序列化格式
'created_at' => 'timestamp', // 指定序列化格式
];
public static function getAll()
{
$list = self::get()->select('id','name','status')->where('status',0)->toArray();
return $list;
}
}
+2 -1
View File
@@ -43,9 +43,10 @@ class Follow extends Model
'created_at' => 'timestamp', // 指定序列化格式 'created_at' => 'timestamp', // 指定序列化格式
]; ];
public static function getFollow($follow) public static function getFollow($follow,$domain)
{ {
$follow['type_txt'] = Constants::FOLLOW[$follow['type']]; $follow['type_txt'] = Constants::FOLLOW[$follow['type']];
$follow['oss_picture'] = $domain.'/'.$follow['picture'];
return $follow; return $follow;
} }
} }
+13
View File
@@ -30,6 +30,19 @@ class User extends Model
*/ */
public $timestamps = true; public $timestamps = true;
// 指定日期字段存储格式为时间戳
protected $dateFormat = 'U';
//设置黑名单
protected $guarded = ['id','created_at','updated_at'];
protected $casts = [
// 'updated_at' => 'datetime:Y-m-d H:i:s', // 指定序列化格式
// 'created_at' => 'datetime:Y-m-d H:i:s', // 指定序列化格式
'updated_at' => 'timestamp', // 指定序列化格式
'created_at' => 'timestamp', // 指定序列化格式
];
public static function getUser($userId) public static function getUser($userId)
{ {
$user = User::first()->select(['id','name','sex','role','avatar','email','password']) $user = User::first()->select(['id','name','sex','role','avatar','email','password'])
+1 -1
View File
@@ -39,7 +39,7 @@ class MailService
public function sendVerificationCode(string $toEmail, string $code): bool public function sendVerificationCode(string $toEmail, string $code): bool
{ {
try { try {
$this->mailer->setFrom('1696136552@qq.com', 'XinYouHe Code'); // 发件人 $this->mailer->setFrom('1696136552@qq.com', 'XinYouHe'); // 发件人
$this->mailer->addAddress($toEmail); $this->mailer->addAddress($toEmail);
// 邮件内容 // 邮件内容
+3
View File
@@ -30,6 +30,9 @@ class Util
public static function getParam(Request $request,$param,$default='') public static function getParam(Request $request,$param,$default='')
{ {
$param = $request->input($param,$default); $param = $request->input($param,$default);
if(empty($default)&&$default!==''){
$param = $default;
}
return $param; return $param;
} }
@@ -2,10 +2,15 @@
return [ return [
'success' => '成功', 'success' => '成功',
'fail' => '成功', 'fail' => '失败',
'login_success' => '登录成功', 'login_success' => '登录成功',
'password_error' => '密码错误', 'password_error' => '密码错误',
'user_none' => '用户不存在', 'user_none' => '用户不存在',
'not_null' => '不能为空', 'not_null' => '不能为空',
'code_error' => '验证码错误',
'format_error' => '格式错误',
'email_repeat' => '邮箱重复',
'save_success' => '添加成功',
'save_fail' => '添加失败',
]; ];