客户删除
This commit is contained in:
@@ -67,6 +67,7 @@ class CustomerController
|
|||||||
|
|
||||||
$page = $request->input('page', 1);
|
$page = $request->input('page', 1);
|
||||||
$perPage = $request->input('per_page', 10);
|
$perPage = $request->input('per_page', 10);
|
||||||
|
$follow = $request->input('follow'); //跟进状态
|
||||||
|
|
||||||
$where = [];
|
$where = [];
|
||||||
|
|
||||||
@@ -78,6 +79,14 @@ class CustomerController
|
|||||||
$where['user_id'] = $userId;
|
$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)
|
$data = Customer::where($where)
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
@@ -102,7 +111,7 @@ class CustomerController
|
|||||||
return Util::fail([], 'id' . trans('not_null'));
|
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)
|
->where('id', $id)
|
||||||
->first();
|
->first();
|
||||||
if ($res) {
|
if ($res) {
|
||||||
@@ -128,7 +137,7 @@ class CustomerController
|
|||||||
if (Util::isEmpty($channel_id)) {
|
if (Util::isEmpty($channel_id)) {
|
||||||
return Util::fail([], 'channel_id' . trans('not_null'));
|
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)) {
|
if (Util::isEmpty($country_id)) {
|
||||||
// return Util::fail([],'country_id'.trans('not_null'));
|
// return Util::fail([],'country_id'.trans('not_null'));
|
||||||
}
|
}
|
||||||
@@ -152,12 +161,12 @@ class CustomerController
|
|||||||
'magnitude' => Util::getParam($request, 'magnitude', 0),
|
'magnitude' => Util::getParam($request, 'magnitude', 0),
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
'phone' => $phone,
|
'phone' => $phone,
|
||||||
'WhatsApp' => Util::getParam($request, 'WhatsApp',''),
|
'WhatsApp' => Util::getParam($request, 'WhatsApp', ''),
|
||||||
'contacts' => $contacts,
|
'contacts' => $contacts,
|
||||||
'describe' => Util::getParam($request, 'describe'),
|
'describe' => Util::getParam($request, 'describe'),
|
||||||
'lat' => Util::getParam($request, 'lat',0),
|
'lat' => Util::getParam($request, 'lat', 0),
|
||||||
'lng' => Util::getParam($request, 'lng',0),
|
'lng' => Util::getParam($request, 'lng', 0),
|
||||||
'address' => Util::getParam($request, 'address',''),
|
'address' => Util::getParam($request, 'address', ''),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (Util::isEmpty($id)) {
|
if (Util::isEmpty($id)) {
|
||||||
@@ -166,13 +175,30 @@ class CustomerController
|
|||||||
$res = Customer::where('id', $id)
|
$res = Customer::where('id', $id)
|
||||||
->update($data);
|
->update($data);
|
||||||
// Log::info('update', ['res' => $res]);
|
// Log::info('update', ['res' => $res]);
|
||||||
(!$res)?: $res=Customer::find($id)->toArray();
|
(!$res) ?: $res = Customer::find($id)->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($res) {
|
if ($res) {
|
||||||
return Util::success($res,trans('save_success'));
|
return Util::success($res, trans('save_success'));
|
||||||
} else {
|
} 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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ class FollowController
|
|||||||
public function list(Request $request)
|
public function list(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$page = $request->input('page', 1);
|
// $page = $request->input('page', 1);
|
||||||
$perPage = $request->input('per_page', 10);
|
// $perPage = $request->input('per_page', 10);
|
||||||
|
|
||||||
//客户id
|
//客户id
|
||||||
$customer_id = Util::getParam($request,'customer_id');
|
$customer_id = Util::getParam($request,'customer_id');
|
||||||
@@ -67,17 +67,17 @@ class FollowController
|
|||||||
|
|
||||||
// 执行分页查询
|
// 执行分页查询
|
||||||
$data = Follow::where($where)
|
$data = Follow::where($where)
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')->get();
|
||||||
->paginate($perPage, ['*'], 'page', $page);
|
// ->paginate($perPage, ['*'], 'page', $page);
|
||||||
|
|
||||||
|
|
||||||
// $host = $request->host();
|
// $host = $request->host();
|
||||||
$url = 'http:'.$request->url();
|
$url = 'http:'.$request->url();
|
||||||
foreach ($data->items() as &$value){
|
foreach ($data as &$value){
|
||||||
$value = Follow::getFollow($value,$url);
|
$value = Follow::getFollow($value,$url);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Util::page($data);
|
return Util::success($data,trans('success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ class UserController
|
|||||||
(!$res)?: $res=User::find($id)->toArray();
|
(!$res)?: $res=User::find($id)->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($res['password']);
|
||||||
if ($res) {
|
if ($res) {
|
||||||
return Util::success($res);
|
return Util::success($res);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ class Customer extends Model
|
|||||||
*/
|
*/
|
||||||
public $timestamps = true;
|
public $timestamps = true;
|
||||||
|
|
||||||
|
use SoftDeletes;
|
||||||
|
protected $dates = ['deleted_at'];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
// 'updated_at' => 'datetime:Y-m-d H:i:s', // 指定序列化格式
|
// 'updated_at' => 'datetime:Y-m-d H:i:s', // 指定序列化格式
|
||||||
// 'created_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')
|
$begin_follow = Follow::select('id','created_at','updated_at')
|
||||||
->where($where)
|
->where($where)
|
||||||
->min('created_at');
|
->min('created_at');
|
||||||
$customer['begin_follow'] = $begin_follow;
|
$customer['begin_follow'] = Util::timeTotDate($begin_follow);
|
||||||
$customer['created_at'] = Util::timeTotDate($customer['created_at']);
|
$customer['created_at'] = Util::timeTotDate($customer['created_at']);
|
||||||
$customer['updated_at'] = Util::timeTotDate($customer['updated_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;
|
// $customer['last_follow'] = $last_follow;
|
||||||
|
|
||||||
return $customer;
|
return $customer;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace app\model;
|
namespace app\model;
|
||||||
|
|
||||||
|
|
||||||
|
use app\util\Util;
|
||||||
use config\constants\Constants;
|
use config\constants\Constants;
|
||||||
use support\Model;
|
use support\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
@@ -47,6 +48,7 @@ class Follow extends Model
|
|||||||
{
|
{
|
||||||
$follow['type_txt'] = Constants::FOLLOW[$follow['type']];
|
$follow['type_txt'] = Constants::FOLLOW[$follow['type']];
|
||||||
$follow['oss_picture'] = $domain.'/'.$follow['picture'];
|
$follow['oss_picture'] = $domain.'/'.$follow['picture'];
|
||||||
|
$follow = Util::formatDate($follow);
|
||||||
return $follow;
|
return $follow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+12
-1
@@ -83,7 +83,7 @@ class Util
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 成功日期
|
* 日期格式转化
|
||||||
*/
|
*/
|
||||||
public static function timeTotDate($time = 0, $format = 'Y-m-d H:i:s')
|
public static function timeTotDate($time = 0, $format = 'Y-m-d H:i:s')
|
||||||
{
|
{
|
||||||
@@ -93,4 +93,15 @@ class Util
|
|||||||
return date($format, $time);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user