This commit is contained in:
2025-07-18 15:15:37 +08:00
parent deb6a2db97
commit c09bf049fb
5 changed files with 114 additions and 66 deletions
+2 -1
View File
@@ -29,7 +29,8 @@ class UserController extends BaseController
{ {
try { try {
$uid = $request->user->uid; $uid = $request->user->uid;
$result = (new UserService())->getUser($uid); $corp_abbr = $request->basic_data['corp_abbr'];
$result = (new UserService())->getUser($uid,$corp_abbr);
return $this->success($result, '获取用户信息'); return $this->success($result, '获取用户信息');
} catch (\Throwable $e) { } catch (\Throwable $e) {
return $this->error($e->getMessage()); return $this->error($e->getMessage());
+7 -1
View File
@@ -3,6 +3,7 @@
namespace app\common\service; namespace app\common\service;
use app\common\logic\UserLogic; use app\common\logic\UserLogic;
use app\common\model\Corp;
use app\crm\model\Country; use app\crm\model\Country;
class UserService class UserService
@@ -43,19 +44,24 @@ class UserService
/** /**
* 获取用户信息(包括菜单和权限) * 获取用户信息(包括菜单和权限)
*/ */
public function getUser(int $uid) public function getUser(int $uid, $corp_abbr)
{ {
$user = $this->logic->userInfo($uid); $user = $this->logic->userInfo($uid);
$corp_name = Corp::where('abbr', $corp_abbr)->value('name');
$ossservice = new OssService();
return [ return [
'id' => $user->id, 'id' => $user->id,
'name' => $user->name, 'name' => $user->name,
'position' => $user->position, 'position' => $user->position,
'socialize' => $user->socialize, 'socialize' => $user->socialize,
'socialize_pic' => $user->socialize_pic, 'socialize_pic' => $user->socialize_pic,
'socialize_pic_full' => (!empty($user->socialize_pic))?$ossservice->generatePrivateUrl($user->socialize_pic):'',
'country_id' => $user->country_id, 'country_id' => $user->country_id,
'country_txt' => Country::where('id',$user->country_id)->value('cn_addr'), 'country_txt' => Country::where('id',$user->country_id)->value('cn_addr'),
'avatar' => $user->avatar, 'avatar' => $user->avatar,
'avatar_full' => (!empty($user->avatar))?$ossservice->generatePrivateUrl($user->avatar):'',
'phone' => $user->phone, 'phone' => $user->phone,
'corp_name' => $corp_name,
'email' => $user->email, 'email' => $user->email,
'status' => $user->status, 'status' => $user->status,
'roles' => $user->roles->pluck('name') 'roles' => $user->roles->pluck('name')
+2 -2
View File
@@ -166,7 +166,7 @@ class CustomerController extends BaseController
return $this->success($this->page($result)); return $this->success($this->page($result));
} catch (\Throwable $e) { } catch (\Throwable $e) {
return $this->error($e->getMessage()); return $this->error($e->getMessage().$e->getFile().$e->getLine());
} }
} }
@@ -217,7 +217,7 @@ class CustomerController extends BaseController
return $this->error('记录不存在'); return $this->error('记录不存在');
} }
$res = Customer::getCustomer($res, $request, true); $res = CustomerService::getCustomer($res, 'zh_CN', true);
return $this->success($res); return $this->success($res);
} }
-55
View File
@@ -58,61 +58,6 @@ class Customer extends Model
return $date->format(Carbon::parse($date)->toDateTimeString()); return $date->format(Carbon::parse($date)->toDateTimeString());
} }
/**
* @param $customer
* @param $request
* @param $tag 是否返回客户标签
* @return mixed
*/
public static function getCustomer($customer, $request, $tag = false)
{
$language = 'zh_CN' ?: 'en';
$customer['grade_txt'] = Util::language($language, Constants::GRADE_EN[$customer['grade']], Constants::GRADE_ZH[$customer['grade']], Constants::GRADE_RU[$customer['grade']]);
$customer['magnitude_txt'] = Util::language($language, Constants::MAGNITUDE_EN[$customer['magnitude']], Constants::MAGNITUDE[$customer['magnitude']], Constants::MAGNITUDE_RU[$customer['magnitude']]);
$customer['sex_txt'] = Util::language($language, Constants::SEX_EN[$customer['sex']], Constants::SEX[$customer['sex']], Constants::SEX_RU[$customer['sex']]);
if ($customer['grade']<=2) {
$customer['follow'] = 0;
$customer['follow_txt'] = Util::language($language,'Following','跟进中','Продолжение');
}elseif ($customer['grade']<5) {
$customer['follow'] = 1;
$customer['follow_txt'] = Util::language($language,'transacted','已成交','Транзакция завершена');
}else{
$customer['follow'] = 2;
$customer['follow_txt'] = Util::language($language,'lost','已流失','Потерянный');
}
$where = [
'customer_id' => $customer['id']
];
$begin_follow = Follow::select('id','created_at','updated_at')
->where($where)
->min('created_at');
$customer['begin_follow'] = Util::timeTotDate($begin_follow);
// $customer['created_at'] = Util::timeTotDate($customer['created_at']);
// $customer['updated_at'] = Util::timeTotDate($customer['updated_at']);
$customer = Util::formatDate($customer,['follow_last']);
// $nameLang = $language=='en'?'name_en':($language=='ru'?'name_ru':'name');
$nameLang = 'name';
$countryLang = $language=='en'?'en_addr':'cn_addr';
$customer['car_type_name'] = empty($customer['car_type_id'])?'':CarType::where(['id'=>$customer['car_type_id']])->value($nameLang);
$customer['country_name'] = empty($customer['country_id'])?'':Country::where(['id'=>$customer['country_id']])->value($countryLang);
$customer['channel_name'] = empty($customer['channel_id'])?'':Channel::where(['id'=>$customer['channel_id']])->value($nameLang);
// $customer['last_follow'] = $last_follow;
if ($tag) {
foreach ($customer['tags'] as &$tag) {
$tag['names'] = unserialize($tag['names']);
$tag['name'] = $tag['names'][$language];
}
}
return $customer;
}
/** /**
* 客户的标签 * 客户的标签
*/ */
+103 -7
View File
@@ -3,7 +3,13 @@
namespace app\crm\service; namespace app\crm\service;
use app\crm\logic\CustomerLogic; use app\crm\logic\CustomerLogic;
use app\crm\model\CarType;
use app\crm\model\Channel;
use app\crm\model\Country;
use app\crm\model\Customer; use app\crm\model\Customer;
use app\crm\model\Follow;
use app\crm\utils\Util;
use config\constants\Constants;
class CustomerService class CustomerService
{ {
@@ -13,18 +19,108 @@ class CustomerService
// $perPage = $request->input('per_page', 10); // $perPage = $request->input('per_page', 10);
$perPage = $params['size'] ?? 10; $perPage = $params['size'] ?? 10;
$page = $params['current'] ?? 1; $page = $params['current'] ?? 1;
$keyword = $params['keyword'] ?? '';
$recycle = $params['recycle'] ?? '';
$grade = $params['grade'] ?? '';
$where = []; $where = [];
$user_id =$params['user_id']; $user_id =$params['user_id'];
if(empty($user_id) || $user_id == 0){ if(empty($user_id) || $user_id == 0){
$where[] = ['user_id', '=', $user_id]; $where[] = ['user_id', '=', $user_id];
} }
$user = Customer::where($where)->paginate($perPage, ['*'], 'page', $page);
// $user = Customer::with('user')->where($where)->paginate($perPage, ['*'], 'page', $page); $seas = $params['seas'] ?? '';
// $user = $user->toArray(); if($seas == 'seas'){
// foreach ($user['data'] as &$item) { $where[] = ['user_id', 0];
// unset($item['password']); }
// } if($recycle == 'recycle'){
return $user; $where[] = ['user_id', $user_id];
}
$query = Customer::where($where);
if(!empty($tagId)){
$query->whereHas('tags', function($query) use ($tagId){
$query->where('tag.id', $tagId);
});
}
if (!Util::isEmpty($keyword)) {
$query->where(function ($query) use ($keyword) {
$query->where('contacts', 'like', "%{$keyword}%")
->orWhere('phone', 'like', "%{$keyword}%");
});
}
if (!Util::isEmpty($grade)) {
$query->whereIn('grade', $grade);
}
if ($recycle == 'recycle' || $seas == 'seas') {
$query->onlyTrashed();
}
$customer = Customer::where($where)->paginate($perPage, ['*'], 'page', $page);
foreach ($customer as &$item) {
$item = $this->getCustomer($item);
if($seas == 'seas'){
$item['seas_time'] = time()-strtotime($item['deleted_at']);
}
}
unset($item);
return $customer;
}
/**
* @param $customer
* @param $request
* @param $tag 是否返回客户标签
* @return mixed
*/
public static function getCustomer($customer, $language = 'zh_CN', $tag = false)
{
$customer['grade_txt'] = Util::language($language, Constants::GRADE_EN[$customer['grade']], Constants::GRADE_ZH[$customer['grade']], Constants::GRADE_RU[$customer['grade']]);
$customer['magnitude_txt'] = Util::language($language, Constants::MAGNITUDE_EN[$customer['magnitude']], Constants::MAGNITUDE[$customer['magnitude']], Constants::MAGNITUDE_RU[$customer['magnitude']]);
$customer['sex_txt'] = Util::language($language, Constants::SEX_EN[$customer['sex']], Constants::SEX[$customer['sex']], Constants::SEX_RU[$customer['sex']]);
if ($customer['grade']<=2) {
$customer['follow'] = 0;
$customer['follow_txt'] = Util::language($language,'Following','跟进中','Продолжение');
}elseif ($customer['grade']<5) {
$customer['follow'] = 1;
$customer['follow_txt'] = Util::language($language,'transacted','已成交','Транзакция завершена');
}else{
$customer['follow'] = 2;
$customer['follow_txt'] = Util::language($language,'lost','已流失','Потерянный');
}
$where = [
'customer_id' => $customer['id']
];
$begin_follow = Follow::select('id','created_at','updated_at')
->where($where)
->min('created_at');
$customer['begin_follow'] = Util::timeTotDate($begin_follow);
// $customer['created_at'] = Util::timeTotDate($customer['created_at']);
// $customer['updated_at'] = Util::timeTotDate($customer['updated_at']);
$customer = Util::formatDate($customer,['follow_last']);
$nameLang = $language=='en'?'name_en':($language=='ru'?'name_ru':'name');
$countryLang = $language=='en'?'en_addr':'cn_addr';
// $customer['car_type_name'] = empty($customer['car_type_id'])?'':CarType::where(['id'=>$customer['car_type_id']])->value($nameLang);
$customer['country_name'] = empty($customer['country_id'])?'':Country::where(['id'=>$customer['country_id']])->value($countryLang);
$customer['channel_name'] = empty($customer['channel_id'])?'':Channel::where(['id'=>$customer['channel_id']])->value($nameLang);
// $customer['last_follow'] = $last_follow;
if ($tag) {
foreach ($customer['tags'] as &$tag) {
$tag['names'] = unserialize($tag['names']);
$tag['name'] = $tag['names'][$language];
}
}
return $customer;
} }