From 54c8e5186e96576abeac78ea5ba7e309a4fa99e8 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Tue, 18 Mar 2025 15:07:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/CustomerController.php | 44 +++++++++++++++++++++------ app/controller/FollowController.php | 12 ++++---- app/controller/UserController.php | 1 + app/model/Customer.php | 6 +++- app/model/Follow.php | 2 ++ app/util/Util.php | 13 +++++++- 6 files changed, 61 insertions(+), 17 deletions(-) diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index ba0066d..160eb25 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -67,6 +67,7 @@ class CustomerController $page = $request->input('page', 1); $perPage = $request->input('per_page', 10); + $follow = $request->input('follow'); //跟进状态 $where = []; @@ -78,6 +79,14 @@ class CustomerController $where['user_id'] = $userId; } + if (!Util::isEmpty($follow) && $follow == 0) { + $where['grade'] = ['<=', 2]; + } elseif (!Util::isEmpty($follow) && $follow == 1) { + $where['grade'] = ['in', [3, 4, 5]]; + } elseif (!Util::isEmpty($follow) && $follow == 2) { + $where['grade'] = ['>', 5]; + } + // 执行分页查询 $data = Customer::where($where) ->orderBy('id', 'desc') @@ -102,7 +111,7 @@ class CustomerController return Util::fail([], 'id' . trans('not_null')); } - $res = Customer::select('id', 'user_id', 'grade', 'channel_id','car_type_id', 'country_id', 'magnitude', 'email', 'phone', 'WhatsApp', 'contacts', 'describe') + $res = Customer::select('id', 'user_id', 'grade', 'channel_id', 'car_type_id', 'country_id', 'magnitude', 'email', 'phone', 'WhatsApp', 'contacts', 'describe', 'sex') ->where('id', $id) ->first(); if ($res) { @@ -128,7 +137,7 @@ class CustomerController if (Util::isEmpty($channel_id)) { return Util::fail([], 'channel_id' . trans('not_null')); } - $country_id = Util::getParam($request, 'country_id'); + $country_id = Util::getParam($request, 'country_id',0); if (Util::isEmpty($country_id)) { // return Util::fail([],'country_id'.trans('not_null')); } @@ -152,12 +161,12 @@ class CustomerController 'magnitude' => Util::getParam($request, 'magnitude', 0), 'email' => $email, 'phone' => $phone, - 'WhatsApp' => Util::getParam($request, 'WhatsApp',''), + 'WhatsApp' => Util::getParam($request, 'WhatsApp', ''), 'contacts' => $contacts, 'describe' => Util::getParam($request, 'describe'), - 'lat' => Util::getParam($request, 'lat',0), - 'lng' => Util::getParam($request, 'lng',0), - 'address' => Util::getParam($request, 'address',''), + 'lat' => Util::getParam($request, 'lat', 0), + 'lng' => Util::getParam($request, 'lng', 0), + 'address' => Util::getParam($request, 'address', ''), ]; if (Util::isEmpty($id)) { @@ -166,13 +175,30 @@ class CustomerController $res = Customer::where('id', $id) ->update($data); // Log::info('update', ['res' => $res]); - (!$res)?: $res=Customer::find($id)->toArray(); + (!$res) ?: $res = Customer::find($id)->toArray(); } if ($res) { - return Util::success($res,trans('save_success')); + return Util::success($res, trans('save_success')); } else { - return Util::fail($res,trans('save_fail')); + return Util::fail($res, trans('save_fail')); + } + } + + /** + * 删除客户 + * @param Request $request + * @return \support\Response + */ + public function delete(Request $request) + { + $id = Util::getParam($request, 'id'); + $customer = Customer::where('id', $id)->first(); + $res = $customer->delete(); + if ($res) { + return Util::success($res, trans('success')); + } else { + return Util::fail($res, trans('fail')); } } diff --git a/app/controller/FollowController.php b/app/controller/FollowController.php index 3e8223b..c8d7161 100644 --- a/app/controller/FollowController.php +++ b/app/controller/FollowController.php @@ -38,8 +38,8 @@ class FollowController public function list(Request $request) { - $page = $request->input('page', 1); - $perPage = $request->input('per_page', 10); +// $page = $request->input('page', 1); +// $perPage = $request->input('per_page', 10); //客户id $customer_id = Util::getParam($request,'customer_id'); @@ -67,17 +67,17 @@ class FollowController // 执行分页查询 $data = Follow::where($where) - ->orderBy('id', 'desc') - ->paginate($perPage, ['*'], 'page', $page); + ->orderBy('id', 'desc')->get(); +// ->paginate($perPage, ['*'], 'page', $page); // $host = $request->host(); $url = 'http:'.$request->url(); - foreach ($data->items() as &$value){ + foreach ($data as &$value){ $value = Follow::getFollow($value,$url); } - return Util::page($data); + return Util::success($data,trans('success')); } /** diff --git a/app/controller/UserController.php b/app/controller/UserController.php index fccc7d6..87bdccb 100644 --- a/app/controller/UserController.php +++ b/app/controller/UserController.php @@ -143,6 +143,7 @@ class UserController (!$res)?: $res=User::find($id)->toArray(); } + unset($res['password']); if ($res) { return Util::success($res); } else { diff --git a/app/model/Customer.php b/app/model/Customer.php index d8068c5..0fa9fb6 100644 --- a/app/model/Customer.php +++ b/app/model/Customer.php @@ -37,6 +37,9 @@ class Customer extends Model */ public $timestamps = true; + use SoftDeletes; + protected $dates = ['deleted_at']; + protected $casts = [ // 'updated_at' => 'datetime:Y-m-d H:i:s', // 指定序列化格式 // 'created_at' => 'datetime:Y-m-d H:i:s', // 指定序列化格式 @@ -67,9 +70,10 @@ class Customer extends Model $begin_follow = Follow::select('id','created_at','updated_at') ->where($where) ->min('created_at'); - $customer['begin_follow'] = $begin_follow; + $customer['begin_follow'] = Util::timeTotDate($begin_follow); $customer['created_at'] = Util::timeTotDate($customer['created_at']); $customer['updated_at'] = Util::timeTotDate($customer['updated_at']); + $customer['car_type_name'] = empty($customer['car_type_id'])?'':CarType::where(['id'=>$customer['car_type_id']])->value('name'); // $customer['last_follow'] = $last_follow; return $customer; diff --git a/app/model/Follow.php b/app/model/Follow.php index aed113d..e353994 100644 --- a/app/model/Follow.php +++ b/app/model/Follow.php @@ -3,6 +3,7 @@ namespace app\model; +use app\util\Util; use config\constants\Constants; use support\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -47,6 +48,7 @@ class Follow extends Model { $follow['type_txt'] = Constants::FOLLOW[$follow['type']]; $follow['oss_picture'] = $domain.'/'.$follow['picture']; + $follow = Util::formatDate($follow); return $follow; } } \ No newline at end of file diff --git a/app/util/Util.php b/app/util/Util.php index daa6a22..7997abe 100644 --- a/app/util/Util.php +++ b/app/util/Util.php @@ -83,7 +83,7 @@ class Util } /** - * 成功日期 + * 日期格式转化 */ public static function timeTotDate($time = 0, $format = 'Y-m-d H:i:s') { @@ -93,4 +93,15 @@ class Util return date($format, $time); } + /** + * 格式化创建时间 + */ + public static function formatDate($value,$key = ['created_at','updated_at']) + { + foreach ($key as $k){ + $value[$k]= self::timeTotDate($value[$k]); + } + return $value; + } + } \ No newline at end of file