|
@@ -4,6 +4,8 @@ namespace App\Service;
|
|
|
|
|
|
use App\Model\BasicType;
|
|
|
use App\Model\Construction;
|
|
|
+use App\Model\ConstructionInfo;
|
|
|
+use App\Model\ConstructionProductInfo;
|
|
|
use App\Model\Customer;
|
|
|
use App\Model\Employee;
|
|
|
use App\Model\SalesOrder;
|
|
@@ -24,86 +26,60 @@ class ConstructionService extends Service
|
|
|
$model->model_type = $data['model_type'];
|
|
|
$model->order_number = $data['order_number'];
|
|
|
$model->title = $data['title'] ?? '';
|
|
|
- $model->selling_price = $data['selling_price'] ?? 0;
|
|
|
- $model->vin_no = $data['vin_no'] ?? '';
|
|
|
- $model->order_type = $data['order_type'] ?? 0;
|
|
|
- $model->deal_type = $data['deal_type'] ?? 0;
|
|
|
$model->customer_id = $data['customer_id'] ?? 0;
|
|
|
- $model->sign_time = $data['sign_time'] ?? 0;
|
|
|
- $model->contract_state = $data['contract_state'] ?? 0;
|
|
|
- $model->product_total = $data['product_total'] ?? 0;
|
|
|
- $model->rate = $data['rate'] ?? 0;
|
|
|
- $model->mark = $data['mark'] ?? '';
|
|
|
+ $model->install_method = $data['install_method'] ?? 0;
|
|
|
+ $model->install_position = $data['install_position'] ?? '';
|
|
|
+ $model->sales_order_id = $data['sales_order_id'] ?? 0;
|
|
|
+ $model->construction_fee = $data['construction_fee'] ?? 0;
|
|
|
$model->construction_time = $data['construction_time'] ?? 0;
|
|
|
$model->handover_time = $data['handover_time'] ?? 0;
|
|
|
- $model->expire_time = $data['expire_time'] ?? 0;
|
|
|
- $model->other_fee = $data['other_fee'] ?? 0;
|
|
|
- $model->discount_fee = $data['discount_fee'] ?? 0;
|
|
|
- $model->contract_fee = $data['contract_fee'] ?? 0;
|
|
|
- $model->contract_type = $data['contract_type'] ?? 0;
|
|
|
- $model->pay_way = $data['pay_way'] ?? 0;
|
|
|
- $model->logistics_company = $data['logistics_company'] ?? 0;
|
|
|
- $model->logistics_number = $data['logistics_number'] ?? '';
|
|
|
- $model->car_type = $data['car_type'] ?? 0;
|
|
|
- $model->year = $data['year'] ?? '';
|
|
|
- $model->mileage = $data['mileage'] ?? '';
|
|
|
- $model->color = $data['color'] ?? '';
|
|
|
- $model->original_set = $data['original_set'] ?? '';
|
|
|
- $model->processing = $data['processing'] ?? '';
|
|
|
+ $model->urgency = $data['urgency'] ?? 0;
|
|
|
+ $model->mark = $data['mark'] ?? '';
|
|
|
+ $model->address1 = $data['address1'] ?? '';
|
|
|
+ $model->address2 = $data['address2'] ?? '';
|
|
|
+ $model->introduction = $data['introduction'] ?? '';
|
|
|
$model->save();
|
|
|
$time = time();
|
|
|
|
|
|
- SalesOrderInfo::where('del_time',0)
|
|
|
- ->where('sales_order_id',$data['id'])
|
|
|
+ ConstructionInfo::where('del_time',0)
|
|
|
+ ->where('construction_id',$data['id'])
|
|
|
->update(['del_time' => $time]);
|
|
|
- SalesOrderProductInfo::where('del_time',0)
|
|
|
- ->where('sales_order_id',$data['id'])
|
|
|
+ ConstructionProductInfo::where('del_time',0)
|
|
|
+ ->where('construction_id',$data['id'])
|
|
|
->update(['del_time' => $time]);
|
|
|
|
|
|
- if(! empty($data['employee_one'])){
|
|
|
- $insert = [];
|
|
|
- foreach ($data['employee_one'] as $value){
|
|
|
- $insert[] = [
|
|
|
- 'sales_order_id' => $model->id,
|
|
|
- 'employee_id' => $value,
|
|
|
- 'type' => SalesOrderInfo::type_one,
|
|
|
- 'crt_time' => $time,
|
|
|
- ];
|
|
|
- }
|
|
|
- SalesOrderInfo::insert($insert);
|
|
|
- }
|
|
|
-
|
|
|
- if(! empty($data['employee_two'])){
|
|
|
+ if(! empty($data['construction_contact'])){
|
|
|
$insert = [];
|
|
|
- foreach ($data['employee_two'] as $value){
|
|
|
+ foreach ($data['construction_contact'] as $value){
|
|
|
$insert[] = [
|
|
|
- 'sales_order_id' => $model->id,
|
|
|
- 'employee_id' => $value,
|
|
|
- 'type' => SalesOrderInfo::type_two,
|
|
|
+ 'construction_id' => $model->id,
|
|
|
+ 'contact_type' => $value['id'],
|
|
|
+ 'contact_info' => $value['info'],
|
|
|
+ 'type' => ConstructionInfo::type_one,
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
|
}
|
|
|
SalesOrderInfo::insert($insert);
|
|
|
}
|
|
|
|
|
|
- if(! empty($data['employee_three'])){
|
|
|
+ if(! empty($data['employee_one'])){
|
|
|
$insert = [];
|
|
|
- foreach ($data['employee_three'] as $value){
|
|
|
+ foreach ($data['employee_one'] as $value){
|
|
|
$insert[] = [
|
|
|
- 'sales_order_id' => $model->id,
|
|
|
+ 'construction_id' => $model->id,
|
|
|
'employee_id' => $value,
|
|
|
- 'type' => SalesOrderInfo::type_three,
|
|
|
+ 'type' => ConstructionInfo::type_two,
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
|
}
|
|
|
- SalesOrderInfo::insert($insert);
|
|
|
+ ConstructionInfo::insert($insert);
|
|
|
}
|
|
|
|
|
|
if(! empty($data['product'])){
|
|
|
$insert = [];
|
|
|
foreach ($data['product'] as $value){
|
|
|
$insert[] = [
|
|
|
- 'sales_order_id' => $model->id,
|
|
|
+ 'construction_id' => $model->id,
|
|
|
'product_id' => $value['product_id'],
|
|
|
'price' => $value['price'],
|
|
|
'number' => $value['number'],
|
|
@@ -111,7 +87,7 @@ class ConstructionService extends Service
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
|
}
|
|
|
- SalesOrderProductInfo::insert($insert);
|
|
|
+ ConstructionProductInfo::insert($insert);
|
|
|
}
|
|
|
|
|
|
DB::commit();
|
|
@@ -134,80 +110,54 @@ class ConstructionService extends Service
|
|
|
$model->model_type = $data['model_type'];
|
|
|
$model->order_number = $data['order_number'];
|
|
|
$model->title = $data['title'] ?? '';
|
|
|
- $model->selling_price = $data['selling_price'] ?? 0;
|
|
|
- $model->vin_no = $data['vin_no'] ?? '';
|
|
|
- $model->order_type = $data['order_type'] ?? 0;
|
|
|
- $model->deal_type = $data['deal_type'] ?? 0;
|
|
|
$model->customer_id = $data['customer_id'] ?? 0;
|
|
|
- $model->sign_time = $data['sign_time'] ?? 0;
|
|
|
- $model->contract_state = $data['contract_state'] ?? 0;
|
|
|
- $model->product_total = $data['product_total'] ?? 0;
|
|
|
- $model->rate = $data['rate'] ?? 0;
|
|
|
- $model->mark = $data['mark'] ?? '';
|
|
|
+ $model->install_method = $data['install_method'] ?? 0;
|
|
|
+ $model->install_position = $data['install_position'] ?? '';
|
|
|
+ $model->sales_order_id = $data['sales_order_id'] ?? 0;
|
|
|
+ $model->construction_fee = $data['construction_fee'] ?? 0;
|
|
|
$model->construction_time = $data['construction_time'] ?? 0;
|
|
|
$model->handover_time = $data['handover_time'] ?? 0;
|
|
|
- $model->expire_time = $data['expire_time'] ?? 0;
|
|
|
- $model->other_fee = $data['other_fee'] ?? 0;
|
|
|
- $model->discount_fee = $data['discount_fee'] ?? 0;
|
|
|
- $model->contract_fee = $data['contract_fee'] ?? 0;
|
|
|
- $model->contract_type = $data['contract_type'] ?? 0;
|
|
|
- $model->pay_way = $data['pay_way'] ?? 0;
|
|
|
- $model->logistics_company = $data['logistics_company'] ?? 0;
|
|
|
- $model->logistics_number = $data['logistics_number'] ?? '';
|
|
|
- $model->car_type = $data['car_type'] ?? 0;
|
|
|
- $model->year = $data['year'] ?? '';
|
|
|
- $model->mileage = $data['mileage'] ?? '';
|
|
|
- $model->color = $data['color'] ?? '';
|
|
|
- $model->original_set = $data['original_set'] ?? '';
|
|
|
- $model->processing = $data['processing'] ?? '';
|
|
|
+ $model->urgency = $data['urgency'] ?? 0;
|
|
|
+ $model->mark = $data['mark'] ?? '';
|
|
|
+ $model->address1 = $data['address1'] ?? '';
|
|
|
+ $model->address2 = $data['address2'] ?? '';
|
|
|
+ $model->introduction = $data['introduction'] ?? '';
|
|
|
$model->crt_id = $user['id'];
|
|
|
$model->save();
|
|
|
$time = time();
|
|
|
|
|
|
- if(! empty($data['employee_one'])){
|
|
|
- $insert = [];
|
|
|
- foreach ($data['employee_one'] as $value){
|
|
|
- $insert[] = [
|
|
|
- 'sales_order_id' => $model->id,
|
|
|
- 'employee_id' => $value,
|
|
|
- 'type' => SalesOrderInfo::type_one,
|
|
|
- 'crt_time' => $time,
|
|
|
- ];
|
|
|
- }
|
|
|
- SalesOrderInfo::insert($insert);
|
|
|
- }
|
|
|
-
|
|
|
- if(! empty($data['employee_two'])){
|
|
|
+ if(! empty($data['construction_contact'])){
|
|
|
$insert = [];
|
|
|
- foreach ($data['employee_two'] as $value){
|
|
|
+ foreach ($data['construction_contact'] as $value){
|
|
|
$insert[] = [
|
|
|
- 'sales_order_id' => $model->id,
|
|
|
- 'employee_id' => $value,
|
|
|
- 'type' => SalesOrderInfo::type_two,
|
|
|
+ 'construction_id' => $model->id,
|
|
|
+ 'contact_type' => $value['id'],
|
|
|
+ 'contact_info' => $value['info'],
|
|
|
+ 'type' => ConstructionInfo::type_one,
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
|
}
|
|
|
SalesOrderInfo::insert($insert);
|
|
|
}
|
|
|
|
|
|
- if(! empty($data['employee_three'])){
|
|
|
+ if(! empty($data['employee_one'])){
|
|
|
$insert = [];
|
|
|
- foreach ($data['employee_three'] as $value){
|
|
|
+ foreach ($data['employee_one'] as $value){
|
|
|
$insert[] = [
|
|
|
- 'sales_order_id' => $model->id,
|
|
|
+ 'construction_id' => $model->id,
|
|
|
'employee_id' => $value,
|
|
|
- 'type' => SalesOrderInfo::type_three,
|
|
|
+ 'type' => ConstructionInfo::type_two,
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
|
}
|
|
|
- SalesOrderInfo::insert($insert);
|
|
|
+ ConstructionInfo::insert($insert);
|
|
|
}
|
|
|
|
|
|
if(! empty($data['product'])){
|
|
|
$insert = [];
|
|
|
foreach ($data['product'] as $value){
|
|
|
$insert[] = [
|
|
|
- 'sales_order_id' => $model->id,
|
|
|
+ 'construction_id' => $model->id,
|
|
|
'product_id' => $value['product_id'],
|
|
|
'price' => $value['price'],
|
|
|
'number' => $value['number'],
|
|
@@ -215,7 +165,7 @@ class ConstructionService extends Service
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
|
}
|
|
|
- SalesOrderProductInfo::insert($insert);
|
|
|
+ ConstructionProductInfo::insert($insert);
|
|
|
}
|
|
|
|
|
|
DB::commit();
|
|
@@ -233,14 +183,14 @@ class ConstructionService extends Service
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
- SalesOrder::whereIn('id',$data['id'])->update([
|
|
|
+ Construction::whereIn('id',$data['id'])->update([
|
|
|
'del_time'=> time()
|
|
|
]);
|
|
|
- SalesOrderInfo::where('del_time',0)
|
|
|
- ->where('sales_order_id',$data['id'])
|
|
|
+ ConstructionInfo::where('del_time',0)
|
|
|
+ ->where('construction_id',$data['id'])
|
|
|
->update(['del_time' => time()]);
|
|
|
- SalesOrderProductInfo::where('del_time',0)
|
|
|
- ->where('sales_order_id',$data['id'])
|
|
|
+ ConstructionProductInfo::where('del_time',0)
|
|
|
+ ->where('construction_id',$data['id'])
|
|
|
->update(['del_time' => time()]);
|
|
|
|
|
|
DB::commit();
|
|
@@ -255,60 +205,47 @@ class ConstructionService extends Service
|
|
|
public function constructionDetail($data){
|
|
|
if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
|
|
|
|
|
|
- $sales = SalesOrderInfo::where('del_time',0)
|
|
|
+ $construction = Construction::where('del_time',0)
|
|
|
->where('id',$data['id'])
|
|
|
->first();
|
|
|
- if(empty($sales)) return [false,'销售订单不存在或已被删除'];
|
|
|
- $sales = $sales->toArray();
|
|
|
- $sales['employee_one'] = $sales['employee_two'] = $sales['employee_three'] = $sales['product'] = [];
|
|
|
+ if(empty($construction)) return [false,'施工订单不存在或已被删除'];
|
|
|
+ $construction = $construction->toArray();
|
|
|
+ $construction['employee_one'] = $construction['construction_contact'] = $construction['product'] = [];
|
|
|
$array = [
|
|
|
- $sales['order_type'],
|
|
|
- $sales['deal_type'],
|
|
|
- $sales['contract_state'],
|
|
|
- $sales['car_type'],
|
|
|
- $sales['pay_way'],
|
|
|
- $sales['logistics_company'],
|
|
|
- $sales['state_type'],
|
|
|
+ $construction['install_method'],
|
|
|
+ $construction['urgency'],
|
|
|
];
|
|
|
$basic_map = BasicType::whereIn('id',$array)
|
|
|
->pluck('title','id')
|
|
|
->toArray();
|
|
|
- foreach ($sales as $key => $value){
|
|
|
- $sales[$key]['order_type_title'] = $basic_map[$value['order_type']] ?? '';
|
|
|
- $sales[$key]['deal_type_title'] = $basic_map[$value['deal_type']] ?? '';
|
|
|
- $sales[$key]['contract_state_title'] = $basic_map[$value['contract_state']] ?? '';
|
|
|
- $sales[$key]['car_type_title'] = $basic_map[$value['car_type']] ?? '';
|
|
|
- $sales[$key]['pay_way_title'] = $basic_map[$value['pay_way']] ?? '';
|
|
|
- $sales[$key]['logistics_company_title'] = $basic_map[$value['logistics_company']] ?? '';
|
|
|
- $sales[$key]['state_type_title'] = $basic_map[$value['state_type']] ?? '';
|
|
|
+ foreach ($construction as $key => $value){
|
|
|
+ $construction[$key]['install_method_title'] = $basic_map[$value['install_method']] ?? '';
|
|
|
+ $construction[$key]['urgency_title'] = $basic_map[$value['urgency']] ?? '';
|
|
|
}
|
|
|
|
|
|
- $sales_info = SalesOrderInfo::where('del_time',0)
|
|
|
- ->where('sales_order_id',$sales['id'])
|
|
|
- ->select('id','sales_order_id','employee_id','type')
|
|
|
+ $construction_info = ConstructionInfo::where('del_time',0)
|
|
|
+ ->where('construction_id',$construction['id'])
|
|
|
+ ->select('id','construction_id','employee_id','type','contact_type','contact_info')
|
|
|
->get()->toArray();
|
|
|
- foreach ($sales_info as $value){
|
|
|
- if($value['type'] == SalesOrderInfo::type_one){
|
|
|
- $sales['employee_one'][] = [
|
|
|
- $value['employee_id']
|
|
|
+ foreach ($construction_info as $value){
|
|
|
+ if($value['type'] == ConstructionInfo::type_one){
|
|
|
+ $construction['construction_contact'][] = [
|
|
|
+ 'id' => $value['contact_type'],
|
|
|
+ 'info' => $value['contact_info']
|
|
|
];
|
|
|
- }elseif ($value['type'] == SalesOrderInfo::type_two){
|
|
|
- $sales['employee_two'][] = [
|
|
|
- $value['employee_id']
|
|
|
- ];
|
|
|
- }elseif ($value['type'] == SalesOrderInfo::type_three){
|
|
|
- $sales['employee_three'][] = [
|
|
|
+ }elseif ($value['type'] == ConstructionInfo::type_two){
|
|
|
+ $construction['employee_one'][] = [
|
|
|
$value['employee_id']
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $sales_p_info = SalesOrderProductInfo::where('del_time',0)
|
|
|
- ->where('sales_order_id',$sales['id'])
|
|
|
- ->select('id','sales_order_id','product_id','mark','price','number')
|
|
|
+ $p_info = ConstructionProductInfo::where('del_time',0)
|
|
|
+ ->where('construction_id',$construction['id'])
|
|
|
+ ->select('id','construction_id','product_id','mark','price','number')
|
|
|
->get()->toArray();
|
|
|
- foreach ($sales_p_info as $value){
|
|
|
- $sales['product'][] = [
|
|
|
+ foreach ($p_info as $value){
|
|
|
+ $construction['product'][] = [
|
|
|
'product_id' => $value['product_id'],
|
|
|
'mark' => $value['mark'],
|
|
|
'price' => $value['price'],
|
|
@@ -316,12 +253,12 @@ class ConstructionService extends Service
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- return [true, $sales];
|
|
|
+ return [true, $construction];
|
|
|
}
|
|
|
|
|
|
public function constructionList($data,$user){
|
|
|
- $model = SalesOrder::where('del_time',0)
|
|
|
- ->select('title','id','model_type','order_number','selling_price','vin_no','car_type','order_type','deal_type','customer_id','sign_time','contract_state','crt_id','crt_time','mark','product_total','rate','construction_time','handover_time','expire_time','other_fee','discount_fee','contract_fee','contract_type','pay_way','logistics_company','logistics_number','car_type','year','mileage','color','original_set','processing')
|
|
|
+ $model = Construction::where('del_time',0)
|
|
|
+ ->select('title','id','model_type','order_number','customer_id','install_method','install_position','sales_order_id','construction_fee','construction_time','handover_time','urgency','crt_id','crt_time','mark','state','address1','address2','introduction')
|
|
|
->orderby('id', 'desc')
|
|
|
->where('model_type',$data['model_type']);
|
|
|
|
|
@@ -336,7 +273,7 @@ class ConstructionService extends Service
|
|
|
public function constructionRule(&$data, $is_add = true){
|
|
|
if(empty($data['model_type'])) return [false,'工单模板类型不能为空'];
|
|
|
if(! in_array($data['model_type'],Construction::$model_type)) return [false,'工单模板类型错误'];
|
|
|
- if(empty($data['order_number'])) return [false,'合同编号不能为空'];
|
|
|
+ if(empty($data['order_number'])) return [false,'工单编号不能为空'];
|
|
|
if(empty($data['construction_time'])) return [false,'实施日期不能为空'];
|
|
|
$data['construction_time'] = $this->changeDateToDateMin($data['construction_time']);
|
|
|
if(empty($data['product'])) return [false,'请选择产品'];
|
|
@@ -364,24 +301,9 @@ class ConstructionService extends Service
|
|
|
if($is_add){
|
|
|
$bool = Construction::where('del_time',0)->where('order_number',$data['order_number'])->exists();
|
|
|
if($bool) return [false,'工单编号已存在,请重新获取'];
|
|
|
-
|
|
|
- if(! empty($data['title'])){
|
|
|
- $boolean = SalesOrder::where('del_time',0)
|
|
|
- ->where('title',$data['title'])
|
|
|
- ->where('model_type',$data['model_type'])
|
|
|
- ->exists();
|
|
|
- }
|
|
|
}else{
|
|
|
if(empty($data['id'])) return [false,'ID不能为空'];
|
|
|
- if(! empty($data['title'])){
|
|
|
- $boolean = SalesOrder::where('del_time',0)
|
|
|
- ->where('id','<>',$data['id'])
|
|
|
- ->where('title',$data['title'])
|
|
|
- ->where('model_type',$data['model_type'])
|
|
|
- ->exists();
|
|
|
- }
|
|
|
}
|
|
|
- if(isset($boolean) && $boolean) return [false,'工单名称不能重复'];
|
|
|
|
|
|
return [true, $data];
|
|
|
}
|
|
@@ -389,7 +311,7 @@ class ConstructionService extends Service
|
|
|
public function fillData($data){
|
|
|
if(empty($data['data'])) return $data;
|
|
|
|
|
|
- $array = array_unique(array_merge_recursive(array_column($data['data'],'order_type'),array_column($data['data'],'deal_type'),array_column($data['data'],'contract_state'),array_column($data['data'],'car_type'),array_column($data['data'],'pay_way'),array_column($data['data'],'logistics_company'),array_column($data['data'],'state_type')));
|
|
|
+ $array = array_unique(array_merge_recursive(array_column($data['data'],'install_method'),array_column($data['data'],'urgency')));
|
|
|
$basic_map = BasicType::whereIn('id',$array)
|
|
|
->pluck('title','id')
|
|
|
->toArray();
|
|
@@ -401,13 +323,8 @@ class ConstructionService extends Service
|
|
|
->toArray();
|
|
|
|
|
|
foreach ($data['data'] as $key => $value){
|
|
|
- $data['data'][$key]['order_type_title'] = $basic_map[$value['order_type']] ?? '';
|
|
|
- $data['data'][$key]['deal_type_title'] = $basic_map[$value['deal_type']] ?? '';
|
|
|
- $data['data'][$key]['contract_state_title'] = $basic_map[$value['contract_state']] ?? '';
|
|
|
- $data['data'][$key]['car_type_title'] = $basic_map[$value['car_type']] ?? '';
|
|
|
- $data['data'][$key]['pay_way_title'] = $basic_map[$value['pay_way']] ?? '';
|
|
|
- $data['data'][$key]['logistics_company_title'] = $basic_map[$value['logistics_company']] ?? '';
|
|
|
- $data['data'][$key]['state_type_title'] = $basic_map[$value['state_type']] ?? '';
|
|
|
+ $data['data'][$key]['install_method_title'] = $basic_map[$value['install_method']] ?? '';
|
|
|
+ $data['data'][$key]['urgency_title'] = $basic_map[$value['urgency']] ?? '';
|
|
|
$data['data'][$key]['customer_title'] = $customer[$value['customer_id']] ?? '';
|
|
|
$data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
|
|
|
$data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
|