Commit 59ee5b6f authored by 朱招明's avatar 朱招明

update

parent 5593ebc6
...@@ -39,7 +39,7 @@ class AdminMenuTransformer extends BaseTransformer ...@@ -39,7 +39,7 @@ class AdminMenuTransformer extends BaseTransformer
public function transform(AdminMenu $menu) public function transform(AdminMenu $menu)
{ {
$return = ['id','parent_id','order','title','key','icon','is_menu','created_at']; $return = ['id','parent_id','order','title','key','icon','api','is_menu','created_at'];
return Helper::mapAttr($menu,$return); return Helper::mapAttr($menu,$return);
} }
......
...@@ -17,7 +17,9 @@ class BaseModel extends Model ...@@ -17,7 +17,9 @@ class BaseModel extends Model
public function scopeParamsSearch($query,$params) public function scopeParamsSearch($query,$params)
{ {
foreach ($params as $key => $value){ foreach ($params as $key => $value){
$value= (string)$value; if($value === '' || $value === NULL){
continue;
}
if(!in_array($key,$this->search)){ if(!in_array($key,$this->search)){
continue; continue;
} }
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
namespace Modules\Customers\Entities; namespace Modules\Customers\Entities;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Customer extends BaseModel class Customer extends BaseModel
{ {
protected $fillable = [ protected $fillable = [
...@@ -80,4 +82,7 @@ class Customer extends BaseModel ...@@ -80,4 +82,7 @@ class Customer extends BaseModel
$query->where('owner', 0); $query->where('owner', 0);
} }
public function follow():HasMany{
return $this->hasMany(CustomerFollow::class)->orderByDesc('follow_time');
}
} }
\ No newline at end of file
...@@ -29,4 +29,13 @@ class CustomerFollow extends BaseModel ...@@ -29,4 +29,13 @@ class CustomerFollow extends BaseModel
6 => '未成交', 6 => '未成交',
]; ];
public function getStatusTextAttribute()
{
return static::$status_maps[$this->status] ?? '';
}
public function getTypeTextAttribute()
{
return static::$type_maps[$this->type] ?? '';
}
} }
\ No newline at end of file
...@@ -25,8 +25,11 @@ class BusinessOpportunityController extends BaseController ...@@ -25,8 +25,11 @@ class BusinessOpportunityController extends BaseController
* @modify * @modify
*/ */
public function list(BusinessOpportunityRequest $request){ public function list(BusinessOpportunityRequest $request){
$params = $request->input('search',[]); $params = $request->only(
[
'expect_date', 'customer_name', 'customer_phone','title', 'id',
]
);
$list = BusinessOpportunity::paramsSearch($params)->paginate(request('per_page')); $list = BusinessOpportunity::paramsSearch($params)->paginate(request('per_page'));
return $this->response->paginator($list, new BusinessOpportunityTransformer()); return $this->response->paginator($list, new BusinessOpportunityTransformer());
......
...@@ -9,6 +9,7 @@ use Modules\Customers\Entities\Customer; ...@@ -9,6 +9,7 @@ use Modules\Customers\Entities\Customer;
use Modules\Customers\Entities\CustomerFollow; use Modules\Customers\Entities\CustomerFollow;
use Modules\Customers\Http\Requests\CustomerRequest; use Modules\Customers\Http\Requests\CustomerRequest;
use Modules\Customers\Http\Service\CustomerService; use Modules\Customers\Http\Service\CustomerService;
use Modules\Customers\Http\Transformer\CustomerFollowTransformer;
use Modules\Customers\Http\Transformer\CustomerTransformer; use Modules\Customers\Http\Transformer\CustomerTransformer;
class CustomersController extends BaseController class CustomersController extends BaseController
...@@ -24,9 +25,11 @@ class CustomersController extends BaseController ...@@ -24,9 +25,11 @@ class CustomersController extends BaseController
*/ */
public function list(CustomerRequest $request) public function list(CustomerRequest $request)
{ {
$params = $request->input('search',[]); $params = $request->only([
'name', 'tel_phone', 'mobile_phone','wechat', 'follow_status', 'from', 'type', 'created_at',
]);
$list = Customer::{$this->type}()->paramsSearch($params)->paginate(request('per_page')); $list = Customer::{$this->type}()->paramsSearch($params)->orderBy('id','desc')->paginate(request('per_page'));
return $this->response->paginator($list, new CustomerTransformer()); return $this->response->paginator($list, new CustomerTransformer());
...@@ -45,7 +48,7 @@ class CustomersController extends BaseController ...@@ -45,7 +48,7 @@ class CustomersController extends BaseController
[ [
'name', 'company', 'industry', 'department', 'duties', 'tel_phone', 'mobile_phone', 'name', 'company', 'industry', 'department', 'duties', 'tel_phone', 'mobile_phone',
'wechat', 'dy', 'email', 'province', 'city', 'area', 'address', 'follow_status', 'wechat', 'dy', 'email', 'province', 'city', 'area', 'address', 'follow_status',
'from', 'type','business_license', 'identity', 'bank_account', 'from', 'type',
] ]
); );
...@@ -115,7 +118,7 @@ class CustomersController extends BaseController ...@@ -115,7 +118,7 @@ class CustomersController extends BaseController
[ [
'name', 'company', 'industry', 'department', 'duties', 'tel_phone', 'mobile_phone', 'name', 'company', 'industry', 'department', 'duties', 'tel_phone', 'mobile_phone',
'wechat', 'dy', 'email', 'province', 'city', 'area', 'address', 'follow_status', 'wechat', 'dy', 'email', 'province', 'city', 'area', 'address', 'follow_status',
'from', 'type', 'founder', 'owner', 'from', 'type',
] ]
); );
$customer = Customer::where('id', $id)->{$this->type}()->first(); $customer = Customer::where('id', $id)->{$this->type}()->first();
...@@ -224,4 +227,14 @@ class CustomersController extends BaseController ...@@ -224,4 +227,14 @@ class CustomersController extends BaseController
]; ];
return $this->response->array(['data'=>$data]); return $this->response->array(['data'=>$data]);
} }
public function followList(CustomerRequest $request, $id){
$customer = Customer::where('id', $id)->{$this->type}()->first();
if (!$customer)
{
abort(500, '客户不存在');
}
return $this->response->collection($customer->follow,new CustomerFollowTransformer());
}
} }
...@@ -17,7 +17,7 @@ class BusinessOpportunityRequest extends BaseRequest ...@@ -17,7 +17,7 @@ class BusinessOpportunityRequest extends BaseRequest
'customer_id' => 'bail|required|exists:customers,id', 'customer_id' => 'bail|required|exists:customers,id',
'product_type' => ['bail','required',Rule::in(array_keys(BusinessOpportunity::$product_type_maps))], 'product_type' => ['bail','required',Rule::in(array_keys(BusinessOpportunity::$product_type_maps))],
'title' => 'bail|required', 'title' => 'bail|required',
'demand_doc' => 'bail|required', //'demand_doc' => 'bail|required',
'customer_desire_time' => ['bail','required','date_format:Y-m-d H:i:s','after:now'], 'customer_desire_time' => ['bail','required','date_format:Y-m-d H:i:s','after:now'],
'customer_expect_money' => 'bail|required', 'customer_expect_money' => 'bail|required',
]; ];
...@@ -29,7 +29,7 @@ class BusinessOpportunityRequest extends BaseRequest ...@@ -29,7 +29,7 @@ class BusinessOpportunityRequest extends BaseRequest
'customer_id' => 'bail|required|exists:customers,id', 'customer_id' => 'bail|required|exists:customers,id',
'product_type' => ['bail','required',Rule::in(array_keys(BusinessOpportunity::$product_type_maps))], 'product_type' => ['bail','required',Rule::in(array_keys(BusinessOpportunity::$product_type_maps))],
'title' => 'bail|required', 'title' => 'bail|required',
'demand_doc' => 'bail|required', //'demand_doc' => 'bail|required',
'customer_desire_time' => ['bail','required','date_format:Y-m-d H:i:s','after:now'], 'customer_desire_time' => ['bail','required','date_format:Y-m-d H:i:s','after:now'],
'customer_expect_money' => 'bail|required', 'customer_expect_money' => 'bail|required',
]; ];
......
...@@ -86,7 +86,7 @@ class CustomerService ...@@ -86,7 +86,7 @@ class CustomerService
'wechat' => '', 'wechat' => '',
'dy' => '', 'dy' => '',
'email' => '', 'email' => '',
'address' => '0', 'address' => '',
'follow_status' => '0', 'follow_status' => '0',
'from' => '0', 'from' => '0',
'type' => '0', 'type' => '0',
...@@ -119,21 +119,21 @@ class CustomerService ...@@ -119,21 +119,21 @@ class CustomerService
} }
#跟进状态 #跟进状态
if ($field == 'follow_status') if ($field == 'follow_status' && empty(CustomerFollow::$status_maps[$value]))
{ {
$value = array_search($value, CustomerFollow::$status_maps) ?: 0; $value = 0;
} }
#客户来源 #客户来源
if ($field == 'from') if ($field == 'from' && empty(Customer::$from_maps[$value]))
{ {
$value = array_search($value, Customer::$from_maps) ?: 0; $value = 0;
} }
#客户类型 #客户类型
if ($field == 'type') if ($field == 'type' && empty(Customer::$type_maps[$value]))
{ {
$value = array_search($value, Customer::$type_maps) ?: 0; $value = 0;
} }
$insert_item[ $field ] = $value; $insert_item[ $field ] = $value;
......
...@@ -13,6 +13,7 @@ use Modules\Customers\Entities\Customer; ...@@ -13,6 +13,7 @@ use Modules\Customers\Entities\Customer;
class BusinessOpportunityTransformer extends BaseTransformer class BusinessOpportunityTransformer extends BaseTransformer
{ {
protected array $availableIncludes = ['customer'];
public function __construct() public function __construct()
{ {
...@@ -49,4 +50,9 @@ class BusinessOpportunityTransformer extends BaseTransformer ...@@ -49,4 +50,9 @@ class BusinessOpportunityTransformer extends BaseTransformer
$return = Helper::mapAttr($business_opportunity,$return); $return = Helper::mapAttr($business_opportunity,$return);
return $return; return $return;
} }
public function includeCustomer($business_opportunity)
{
return $business_opportunity->customer?$this->item($business_opportunity->customer, new CustomerTransformer()):null;
}
} }
...@@ -12,6 +12,7 @@ use Modules\Customers\Entities\Customer; ...@@ -12,6 +12,7 @@ use Modules\Customers\Entities\Customer;
class CustomerTransformer extends BaseTransformer class CustomerTransformer extends BaseTransformer
{ {
protected array $availableIncludes = ['follow'];
public function __construct() public function __construct()
{ {
...@@ -60,4 +61,9 @@ class CustomerTransformer extends BaseTransformer ...@@ -60,4 +61,9 @@ class CustomerTransformer extends BaseTransformer
$return = Helper::mapAttr($customer,$return); $return = Helper::mapAttr($customer,$return);
return $return; return $return;
} }
public function includeFollow($customer)
{
return $customer->follow?$this->collection($customer->follow, new CustomerFollowTransformer()):null;
}
} }
...@@ -34,6 +34,8 @@ $api->version('v1', [ ...@@ -34,6 +34,8 @@ $api->version('v1', [
$api->get('private/{id}/show', 'PrivateCustomersController@show')->name('customer.private.show'); $api->get('private/{id}/show', 'PrivateCustomersController@show')->name('customer.private.show');
#写跟进 #写跟进
$api->put('private/{id}/follow', 'PrivateCustomersController@updateFollowStatus')->name('customer.private.follow'); $api->put('private/{id}/follow', 'PrivateCustomersController@updateFollowStatus')->name('customer.private.follow');
#跟进列表
$api->get('private/{id}/follow_list', 'PrivateCustomersController@followList')->name('customer.private.follow_list');
#退回公海 #退回公海
$api->put('private/back_public', 'PrivateCustomersController@backPublic')->name('customer.private.back_public'); $api->put('private/back_public', 'PrivateCustomersController@backPublic')->name('customer.private.back_public');
#数据字段 #数据字段
...@@ -54,6 +56,8 @@ $api->version('v1', [ ...@@ -54,6 +56,8 @@ $api->version('v1', [
$api->get('public/{id}/show', 'PublicCustomersController@show')->name('customer.public.show'); $api->get('public/{id}/show', 'PublicCustomersController@show')->name('customer.public.show');
#写跟进 #写跟进
$api->put('public/{id}/follow', 'PublicCustomersController@updateFollowStatus')->name('customer.public.follow'); $api->put('public/{id}/follow', 'PublicCustomersController@updateFollowStatus')->name('customer.public.follow');
#跟进列表
$api->get('public/{id}/follow_list', 'PublicCustomersController@followList')->name('customer.public.follow_list');
#退回公海 #退回公海
$api->put('public/receive_private', 'PublicCustomersController@receivePrivate')->name('customer.public.receive_private'); $api->put('public/receive_private', 'PublicCustomersController@receivePrivate')->name('customer.public.receive_private');
#数据字段 #数据字段
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment