From 416050a387b4ffb76d0c55a06d93b3eab3ae6c4f Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Thu, 17 Jul 2025 09:36:46 +0800 Subject: [PATCH] crm --- app/crm/controller/CustomerController.php | 144 +++++++++++++--------- app/crm/controller/FollowController.php | 60 ++++----- app/crm/logic/CustomerLogic.php | 7 ++ app/crm/model/Channel.php | 4 +- app/crm/model/Country.php | 2 +- app/crm/model/Customer.php | 3 +- app/crm/service/CustomerService.php | 12 ++ app/crm/service/FollowService.php | 17 +-- config/route.php | 5 + 9 files changed, 156 insertions(+), 98 deletions(-) diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index 9c9cd05..5fc0750 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -2,11 +2,12 @@ namespace app\crm\controller; +use app\common\model\User; use app\crm\model\Channel; +use app\crm\model\Country; use app\crm\model\Customer; use app\crm\model\CustomerHis; use app\crm\model\Follow; -use app\crm\model\User; use app\crm\service\CustomerService; use app\crm\utils\Util; use config\constants\Constants; @@ -24,9 +25,9 @@ class CustomerController extends BaseController { $grade = []; $gradeConstants = Constants::GRADE_EN; - if($request->user['language'] == 'zh_CN'){ - $gradeConstants = Constants::GRADE; - }elseif ($request->user['language'] == 'ru'){ + if('zh_CN' == 'zh_CN'){ + $gradeConstants = Constants::GRADE_ZH; + }elseif ('zh_CN' == 'ru'){ $gradeConstants = Constants::GRADE_RU; } foreach ($gradeConstants as $key => $value) { @@ -35,7 +36,7 @@ class CustomerController extends BaseController 'name' => $value, ]; } - return Util::success($grade); + return $this->success($grade); } /** @@ -47,9 +48,9 @@ class CustomerController extends BaseController { $grade = []; $magnitudeConstants = Constants::MAGNITUDE_EN; - if($request->user['language'] == 'zh_CN'){ + if('zh_CN' == 'zh_CN'){ $magnitudeConstants = Constants::MAGNITUDE; - }elseif ($request->user['language'] == 'ru'){ + }elseif ('zh_CN' == 'ru'){ $magnitudeConstants = Constants::MAGNITUDE_RU; } foreach ($magnitudeConstants as $key => $value) { @@ -58,7 +59,7 @@ class CustomerController extends BaseController 'name' => $value, ]; } - return Util::success($grade); + return $this->success($grade); } /** @@ -70,17 +71,40 @@ class CustomerController extends BaseController { $list = Channel::getAll(); - if($request->user['language'] != 'zh_CN'){ + if('zh_CN' != 'zh_CN'){ foreach ($list as &$value) { $value['name'] = $value['name_en']; } - }elseif ($request->user['language'] == 'ru'){ + }elseif ('zh_CN' == 'ru'){ foreach ($list as &$value) { $value['name'] = $value['name_ru']; } } - return Util::success($list); + return $this->success($list); + + } + + /** + * 国家 + * @param Request $request + * @return \support\Response + */ + public function getCountry(Request $request) + { + $list = Country::getAll(); + + if('zh_CN' != 'zh_CN'){ + foreach ($list as &$value) { + $value['name'] = $value['name_en']; + } + }elseif ('zh_CN' == 'ru'){ + foreach ($list as &$value) { + $value['name'] = $value['name_ru']; + } + } + + return $this->success($list); } @@ -91,12 +115,13 @@ class CustomerController extends BaseController */ public function waitFollow(Request $request) { - $userId = $request->user['id']; + $userId = $request->user->uid; $filter = Util::getParam($request, 'filter'); $page = $request->input('page', 1); $perPage = $request->input('per_page', 10); $where = [ ['user_id', '=', $userId], + ['corp_abbr', '=', $request->basic_data['corp_abbr']], ['follow_next', '<>', 0], ]; @@ -116,7 +141,7 @@ class CustomerController extends BaseController $item['follow_remaining'] = $item->follow_next-time(); $item['follow_next'] = date('Y-m-d H:i:s',$item->follow_next); } - return Util::page($customer); + return $this->success($this->page($customer)); } /** @@ -129,6 +154,7 @@ class CustomerController extends BaseController try { $param = $request->all(); $param['user_id'] = $request->user->uid; + $param['corp_abbr'] = $request->basic_data['corp_abbr']; $result = (new CustomerService())->list($param); return $this->success($this->page($result)); @@ -146,18 +172,18 @@ class CustomerController extends BaseController { $id = Util::getParam($request,'id', ''); if (Util::isEmpty($id)) { - return Util::fail([], trans('id_empty')); + return $this->error(trans('id_empty')); } - $userId = $request->user['id']; + $userId = $request->user->uid; $where = [ 'id' => $id, 'user_id' => $userId, ]; $res = Customer::where($where)->restore(); if($res){ - return Util::success($res, trans('success')); + return $this->success($res, trans('success')); }else{ - return Util::fail([], trans('fail')); + return $this->error(trans('fail')); } } @@ -171,21 +197,22 @@ class CustomerController extends BaseController { $id = Util::getParam($request, 'id'); if (Util::isEmpty($id)) { - return Util::fail([], 'id' . trans('not_null')); + return $this->error('id' . trans('not_null')); } - $res = Customer::with('tags')->select('id', 'user_id', 'grade', 'channel_id', 'car_type_id', 'country_id', 'magnitude', 'email', 'phone', 'WhatsApp', 'contacts', 'describe', 'address', 'lat', 'lng', 'follow_next', 'follow_remark', 'sex') - ->where('id', $id) - ->first(); +// $res = Customer::with('tags')->select('id', 'user_id', 'grade', 'channel_id', 'car_type_id', 'country_id', 'magnitude', 'email', 'phone', 'WhatsApp', 'contacts', 'describe', 'address', 'lat', 'lng', 'follow_next', 'follow_remark', 'sex') +// ->where('id', $id) +// ->first(); + $res = (new CustomerService)->detail($request->all()); if ($res) { $res->toArray(); } else { - return Util::fail([], '记录不存在'); + return $this->error('记录不存在'); } $res = Customer::getCustomer($res, $request, true); - return Util::success($res); + return $this->success($res); } /** @@ -198,25 +225,26 @@ class CustomerController extends BaseController $id = Util::getParam($request, 'id'); $channel_id = Util::getParam($request, 'channel_id'); if (Util::isEmpty($channel_id)) { - return Util::fail([], trans('channel_not_null')); + return $this->error(trans('channel_not_null')); } $country_id = Util::getParam($request, 'country_id', 0); if (Util::isEmpty($country_id)) { -// return Util::fail([],'country_id'.trans('not_null')); +// return $this->error('country_id'.trans('not_null')); } $car_type_id = Util::getParam($request, 'car_type_id'); if (Util::isEmpty($car_type_id)) { - return Util::fail([], trans('car_type_not_null')); + return $this->error(trans('car_type_not_null')); } $contacts = Util::getParam($request, 'contacts'); $email = Util::getParam($request, 'email'); $phone = Util::getParam($request, 'phone'); if (Util::isEmpty($contacts) && Util::isEmpty($email) && Util::isEmpty($phone)) { - return Util::fail([], trans('contacts_not_null')); + return $this->error(trans('contacts_not_null')); } $data = [ - 'user_id' => $request->user['id'], + 'user_id' => $request->user->uid, + 'corp_abbr' => $request->basic_data['corp_abbr'], 'grade' => Util::getParam($request, 'grade', 0), 'channel_id' => $channel_id, 'country_id' => $country_id, @@ -244,9 +272,9 @@ class CustomerController extends BaseController } if ($res) { - return Util::success($res, trans('save_success')); + return $this->success($res, trans('save_success')); } else { - return Util::fail($res, trans('save_fail')); + return $this->error(trans('save_fail')); } } @@ -261,7 +289,7 @@ class CustomerController extends BaseController { $id = Util::getParam($request, 'id'); if (Util::isEmpty($id)) { - return Util::fail([], 'id' . trans('not_null')); + return $this->error('id' . trans('not_null')); } $data = [ 'follow_next' => Util::getParam($request, 'follow_next', 0), @@ -273,9 +301,9 @@ class CustomerController extends BaseController ->update($data); if ($res) { - return Util::success($res, trans('save_success')); + return $this->success($res, trans('save_success')); } else { - return Util::fail($res, trans('save_fail')); + return $this->error(trans('save_fail')); } } @@ -289,14 +317,14 @@ class CustomerController extends BaseController $id = Util::getParam($request, 'id'); $force = Util::getParam($request, 'force',''); - $userId = $request->user['id']; + $userId = $request->user->uid; $where = [ 'id' => $id, 'user_id' => $userId, ]; $customer = Customer::where($where)->withTrashed()->first(); if(empty($customer)){ - return Util::fail('', trans('fail')); + return $this->error( trans('fail')); } if($force == 'force'){ $res = $customer->forceDelete(); @@ -304,9 +332,9 @@ class CustomerController extends BaseController $res = $customer->delete(); } if ($res) { - return Util::success($res, trans('success')); + return $this->success($res, trans('success')); } else { - return Util::fail($res, trans('fail')); + return $this->error(trans('fail')); } } @@ -319,12 +347,14 @@ class CustomerController extends BaseController { $created = Util::getParam($request, 'created'); if (Util::isEmpty($created)) { - return Util::fail([], 'created' . trans('not_null')); + return $this->error('created' . trans('not_null')); } - $userId = $request->user['id']; - $created_at = $request->user['created_at']; + $userId = $request->user->uid; + //$created_at = $request->user['created_at']; + $created_at = User::find($userId)->created_at; $day = ceil((time() - $created_at + 1) / 60 / 60 / 24); $where[] = ['user_id', '=', $userId]; + $where[] = ['corp_abbr', '=', $request->basic_data['corp_abbr']]; $start = strtotime($created . '-01'); $year = date('Y', $start); $month = date('n', $start); //获取月份 @@ -366,9 +396,9 @@ class CustomerController extends BaseController 'customer_deal' => $customerDeal, //已成交 ]; if ($res) { - return Util::success($res, trans('success')); + return $this->success($res, trans('success')); } else { - return Util::fail($res, trans('fail')); + return $this->error(trans('fail')); } } @@ -380,17 +410,17 @@ class CustomerController extends BaseController public function claim(Request $request) { $customerId = Util::getParam($request, 'customer_id'); - $userId = $request->user['id']; + $userId = $request->user->uid; if (Util::isEmpty($customerId)) { - return Util::fail([], trans('customer_id').trans('not_null')); + return $this->error(trans('customer_id').trans('not_null')); } $data = [ - 'user_id' => $request->user['id'] + 'user_id' => $request->user->uid ]; $customer= Customer::withTrashed()->find($customerId); if(empty($customer) || $customer->user_id != 0){ - return Util::fail('', trans('claim_fail')); + return $this->error( trans('claim_fail')); } $customer->restore(); @@ -404,9 +434,9 @@ class CustomerController extends BaseController ]); if ($res) { - return Util::success($res, trans('success')); + return $this->success($res, trans('success')); } else { - return Util::fail($res, trans('fail')); + return $this->error(trans('fail')); } } @@ -421,14 +451,14 @@ class CustomerController extends BaseController { $customerId = Util::getParam($request, 'customer_id'); $user_sn = Util::getParam($request, 'user_sn'); - $userId = $request->user['id']; + $userId = $request->user->uid; if (Util::isEmpty($user_sn)) { - return Util::fail([], 'ID'.trans('not_null')); + return $this->error('ID'.trans('not_null')); } $user = User::where(['sn' => $user_sn])->first(); if (Util::isEmpty($user)) { - return Util::fail(null, trans('user_none')); + return $this->error( trans('user_none')); } if(Util::isEmpty($customerId)){ @@ -453,9 +483,9 @@ class CustomerController extends BaseController if ($res) { - return Util::success($res, trans('success')); + return $this->success($res, trans('success')); } else { - return Util::fail($res, trans('fail')); + return $this->error(trans('fail')); } } @@ -469,10 +499,10 @@ class CustomerController extends BaseController $id = Util::getParam($request, 'id'); $grade = Util::getParam($request, 'grade'); if (Util::isEmpty($id)) { - return Util::fail('', 'id' . trans('not_null')); + return $this->error( 'id' . trans('not_null')); } if (Util::isEmpty($id)) { - return Util::fail('', 'grade' . trans('not_null')); + return $this->error( 'grade' . trans('not_null')); } $data = [ 'grade' => $grade, @@ -481,9 +511,9 @@ class CustomerController extends BaseController ->update($data); if ($res) { - return Util::success($res, trans('save_success')); + return $this->success($res, trans('save_success')); } else { - return Util::fail($res, trans('save_fail')); + return $this->error(trans('save_fail')); } } } \ No newline at end of file diff --git a/app/crm/controller/FollowController.php b/app/crm/controller/FollowController.php index 7ee34a4..a23749c 100644 --- a/app/crm/controller/FollowController.php +++ b/app/crm/controller/FollowController.php @@ -40,7 +40,8 @@ class FollowController extends BaseController { try { $data = $this->validate(new FollowValidate(), $request->get(), 'list'); - $result = (new FollowService())->list($request->all(),$request->user->uid); + $request->setGet('corp_abbr', $request->basic_data['corp_abbr']); + $result = (new FollowService())->list($request->all(), $request->user->uid); return $this->success($result); } catch (\Throwable $e) { return $this->error($e->getMessage()); @@ -55,17 +56,17 @@ class FollowController extends BaseController public function detail(Request $request) { //跟进id - $id = Util::getParam($request,'id'); - if(Util::isEmpty($id)){ - return $this->error('id'.trans('not_null')); + $id = Util::getParam($request, 'id'); + if (Util::isEmpty($id)) { + return $this->error('id' . trans('not_null')); } - $res = Follow::select('id','user_id','customer_id','type','picture','remark','audio','audio_text','lat','lng','address') - ->where('id',$id) + $res = Follow::select('id', 'user_id', 'customer_id', 'type', 'picture', 'remark', 'audio', 'audio_text', 'lat', 'lng', 'address') + ->where('id', $id) ->first(); - if($res){ + if ($res) { $res->toArray(); - }else{ + } else { return $this->error('记录不存在'); } @@ -81,32 +82,33 @@ class FollowController extends BaseController */ public function save(Request $request) { - $customer_id = Util::getParam($request,'customer_id'); + $customer_id = Util::getParam($request, 'customer_id'); - if(Util::isEmpty($customer_id)){ - return $this->error('customer_id'.trans('not_null')); + if (Util::isEmpty($customer_id)) { + return $this->error('customer_id' . trans('not_null')); } - $type = Util::getParam($request,'type'); - if(Util::isEmpty($type)){ - return $this->error('type'.trans('not_null')); + $type = Util::getParam($request, 'type'); + if (Util::isEmpty($type)) { + return $this->error('type' . trans('not_null')); } - $picture = Util::getParam($request,'picture'); - if(Util::isEmpty($picture)){ + $picture = Util::getParam($request, 'picture'); + if (Util::isEmpty($picture)) { return $this->error(trans('picture_not_null')); } $data = [ - 'user_id'=>$request->user->uid, - 'customer_id'=>$customer_id, - 'type'=>$type, - 'picture'=>$picture, - 'remark'=>Util::getParam($request,'remark',''), - 'audio'=>Util::getParam($request,'audio',''), - 'audio_text'=>Util::getParam($request,'audio_text',''), - 'lat'=>Util::getParam($request,'lat',0), - 'lng'=>Util::getParam($request,'lng',0), - 'address'=>Util::getParam($request,'address'), - 'follow_time'=>strtotime(Util::getParam($request,'firstFollowtime',0)), + 'user_id' => $request->user->uid, + 'corp_abbr' => $request->basic_data['corp_abbr'], + 'customer_id' => $customer_id, + 'type' => $type, + 'picture' => $picture, + 'remark' => Util::getParam($request, 'remark', ''), + 'audio' => Util::getParam($request, 'audio', ''), + 'audio_text' => Util::getParam($request, 'audio_text', ''), + 'lat' => Util::getParam($request, 'lat', 0), + 'lng' => Util::getParam($request, 'lng', 0), + 'address' => Util::getParam($request, 'address'), + 'follow_time' => strtotime(Util::getParam($request, 'firstFollowtime', 0)), ]; $res = Follow::create($data); @@ -119,7 +121,7 @@ class FollowController extends BaseController $follow_next = Util::getParam($request, 'follow_next', 0); $follow_remark = Util::getParam($request, 'follow_remark', 0); - if($res && (!empty($follow_next))){ + if ($res && (!empty($follow_next))) { $data = [ 'follow_next' => $follow_next, 'follow_remark' => $follow_remark, @@ -130,7 +132,7 @@ class FollowController extends BaseController } if ($res) { - return $this->success($res,trans('save_success')); + return $this->success($res, trans('save_success')); } else { return $this->error(trans('save_fail')); } diff --git a/app/crm/logic/CustomerLogic.php b/app/crm/logic/CustomerLogic.php index 0e6b1a0..4e0619d 100644 --- a/app/crm/logic/CustomerLogic.php +++ b/app/crm/logic/CustomerLogic.php @@ -2,7 +2,14 @@ namespace app\crm\logic; +use app\crm\model\Customer; + class CustomerLogic { + public function find(int $id) + { + $customer = Customer::find($id); + return $customer; + } } \ No newline at end of file diff --git a/app/crm/model/Channel.php b/app/crm/model/Channel.php index 59f9237..ac02c71 100644 --- a/app/crm/model/Channel.php +++ b/app/crm/model/Channel.php @@ -11,7 +11,7 @@ class Channel extends Model * * @var string */ - protected $table = 'channel'; + protected $table = 'inquiry_channel'; /** * The primary key associated with the table. @@ -42,7 +42,7 @@ class Channel extends Model public static function getAll() { - $list = self::get()->select('id','name','name_en','status')->where('status',0)->toArray(); + $list = self::get()->select('id','name','name_en','status')->where('status',1)->toArray(); return $list; } } \ No newline at end of file diff --git a/app/crm/model/Country.php b/app/crm/model/Country.php index 29ba895..f1fffd1 100644 --- a/app/crm/model/Country.php +++ b/app/crm/model/Country.php @@ -35,7 +35,7 @@ class Country extends Model public static function getAll() { - $list = self::get()->select('id','cn_addr','en_addr')->get()->toArray(); + $list = self::select('id','cn_addr','en_addr')->get(); return $list; } } \ No newline at end of file diff --git a/app/crm/model/Customer.php b/app/crm/model/Customer.php index 6c17787..f28fb11 100644 --- a/app/crm/model/Customer.php +++ b/app/crm/model/Customer.php @@ -95,7 +95,8 @@ class Customer extends Model // $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 = $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); diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index 74baab2..f085f44 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -2,6 +2,7 @@ namespace app\crm\service; +use app\crm\logic\CustomerLogic; use app\crm\model\Customer; class CustomerService @@ -25,4 +26,15 @@ class CustomerService // } return $user; } + + + public function detail($params) + { + $id =$params['id']; + $customer = Customer::with('tags')->select('id', 'user_id', 'grade', 'channel_id', 'car_type_id', 'country_id', 'magnitude', 'email', 'phone', 'WhatsApp', 'contacts', 'describe', 'address', 'lat', 'lng', 'follow_next', 'follow_remark', 'sex') + ->where('id', $id) + ->first(); + + return $customer; + } } \ No newline at end of file diff --git a/app/crm/service/FollowService.php b/app/crm/service/FollowService.php index 89b7c2b..b97d5f1 100644 --- a/app/crm/service/FollowService.php +++ b/app/crm/service/FollowService.php @@ -18,16 +18,18 @@ class FollowService // $perPage = $request->input('per_page', 10); //客户id - $customer_id =$param['customer_id']; + $customer_id = $param['customer_id']; + $corp_abbr = $param['corp_abbr']; $where = []; $where['customer_id'] = $customer_id; + $where['corp_abbr'] = $corp_abbr; //用户角色 //跟进id - $id = $param['id']??null; - if(!Util::isEmpty($id)){ + $id = $param['id'] ?? null; + if (!Util::isEmpty($id)) { $where['id'] = $id; } @@ -39,7 +41,7 @@ class FollowService // $host = $request->host(); // $url = 'http:'.$request->url(); - foreach ($data as &$value){ + foreach ($data as &$value) { $value = self::getFollow($value); } @@ -47,15 +49,14 @@ class FollowService } - - public static function getFollow($follow,$domain = 'https://vehicle-album.oss-cn-beijing.aliyuncs.com') + public static function getFollow($follow) { $follow['type_txt'] = Constants::FOLLOW[$follow['type']]; $follow['firstFollowtime'] = $follow['follow_time']; $oss_picture = ''; - if(!empty($follow['picture'])){ + if (!empty($follow['picture'])) { $ossservice = new OssService(); - $oss_picture = $ossservice->generatePrivateUrl($follow['picture'],86400); + $oss_picture = $ossservice->generatePrivateUrl($follow['picture'], 86400); } $follow['oss_picture'] = $oss_picture; // $follow = Util::formatDate($follow); diff --git a/config/route.php b/config/route.php index 4c29ced..dd98cca 100644 --- a/config/route.php +++ b/config/route.php @@ -91,5 +91,10 @@ Route::group('/crm', function () { Route::any('/customer/list', [app\crm\controller\CustomerController::class, 'list']); Route::any('/customer/detail', [app\crm\controller\CustomerController::class, 'detail']); Route::any('/customer/add', [app\crm\controller\CustomerController::class, 'save']); + Route::any('/customer/claim', [app\crm\controller\CustomerController::class, 'claim']); + Route::any('/customer/restore', [app\crm\controller\CustomerController::class, 'restore']); + Route::any('/customer/delete', [app\crm\controller\CustomerController::class, 'delete']); + Route::any('/customer/waitFollow', [app\crm\controller\CustomerController::class, 'waitFollow']); + Route::any('/customer/getChannel', [app\crm\controller\CustomerController::class, 'getChannel']); });