diff --git a/app/admin/controller/SysDictController.php b/app/admin/controller/SysDictController.php index b8a8c13..b75f923 100644 --- a/app/admin/controller/SysDictController.php +++ b/app/admin/controller/SysDictController.php @@ -32,8 +32,11 @@ class SysDictController extends BaseController $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); - $data['category'] = SysDictItem::where('id',$data['category_id'])->value('item_label'); - + if (isset($data['category_id'])){ + $data['category'] = SysDictItem::where('id',$data['category_id'])->value('item_label'); + } else { + $data['category'] = ''; + } return $data; } diff --git a/app/common/model/SysDict.php b/app/common/model/SysDict.php index 7ef5a62..ad7cf5c 100644 --- a/app/common/model/SysDict.php +++ b/app/common/model/SysDict.php @@ -43,7 +43,7 @@ class SysDict extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'dict_name', 'dict_code', 'description', 'status', 'created_at', 'updated_at', 'deleted_at']; + protected $fillable = ['id', 'category_id', 'dict_name', 'dict_code', 'description', 'status', 'created_at', 'updated_at', 'deleted_at']; /** * 不允许自动填充模型字段 diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index 0860af8..b2e125e 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -205,6 +205,25 @@ class CustomerController extends BaseController } } + /** + * 客户下拉 + * @param Request $request + * @return \support\Response + */ + public function preset(Request $request) + { + try { + $param = $request->all(); + $param['user_id'] = $request->user->uid; + $param['corp_abbr'] = $request->basic_data['corp_abbr']; + $result = (new CustomerService())->preset($param); + + return $this->success($result); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + /** * 客户恢复 * @param Request $request diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index c20ceab..c08b21d 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -164,6 +164,39 @@ class CustomerService return $customer; } + public function preset($params) + { + $keyword = $params['keyword'] ?? ''; + $where = []; + $user_id =$params['user_id']; + + $where[] = ['status', 1]; + $where[] = ['user_id', $user_id]; + + if (!empty($countryId)){ + $where[] = ['country_id', $countryId]; + } + + $query = Customer::select('id','code','sn','corp_id','email','phone','WhatsApp','contacts','company')->where($where); + + if (!Util::isEmpty($keyword)) { + $query->where(function ($query) use ($keyword) { + $query->where('contacts', 'like', "%{$keyword}%") + ->orWhere('phone', 'like', "%{$keyword}%") + ->orWhere('email', 'like', "%{$keyword}%") + ->orWhere('WhatsApp', 'like', "%{$keyword}%") + ->orWhere('code', 'like', "%{$keyword}%"); + }); + } + $customer = $query->orderBy('follow_last','desc')->get(); + + foreach ($customer as &$item) { + } + unset($item); + + return $customer; + } + /** 分页列表 */ public function serviceList(Request $request) diff --git a/config/route.php b/config/route.php index 2de1e13..5bab335 100644 --- a/config/route.php +++ b/config/route.php @@ -340,6 +340,7 @@ Route::group('/crm', function () { Route::any('/customer/followNext', [app\crm\controller\CustomerController::class, 'followNext']); Route::any('/customer/report', [app\crm\controller\CustomerController::class, 'report']); Route::any('/customer/distinctNotice', [app\crm\controller\CustomerController::class, 'distinctNotice']); + Route::any('/customer/preset', [app\crm\controller\CustomerController::class, 'preset']); Route::any('/tagGroup/list', [app\crm\controller\TagGroupController::class, 'list']); Route::any('/tagGroup/updatePivot', [app\crm\controller\TagGroupController::class, 'updatePivot']);