|
@@ -13,6 +13,7 @@ use App\Model\Product;
|
|
use App\Model\ProductCategory;
|
|
use App\Model\ProductCategory;
|
|
use App\Model\ProductPriceDetail;
|
|
use App\Model\ProductPriceDetail;
|
|
use App\Model\SalesOrder;
|
|
use App\Model\SalesOrder;
|
|
|
|
+use App\Model\SalesOrderInfo;
|
|
use App\Model\SalesOrderProductInfo;
|
|
use App\Model\SalesOrderProductInfo;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
@@ -591,26 +592,67 @@ class ImportService extends Service
|
|
if(empty($array)) return [false, '导入数据不能为空'];
|
|
if(empty($array)) return [false, '导入数据不能为空'];
|
|
|
|
|
|
$model = BasicType::TopClear($user,[]);
|
|
$model = BasicType::TopClear($user,[]);
|
|
- $basic_type = $model->where('del_time',0)
|
|
|
|
- ->where('type',24)
|
|
|
|
- ->pluck('id','title')
|
|
|
|
|
|
+ $basic = $model->where('del_time',0)
|
|
|
|
+ ->whereIn('type',[18,23,24,29])
|
|
|
|
+ ->select('id','title','type')
|
|
|
|
+ ->get()
|
|
->toArray();
|
|
->toArray();
|
|
|
|
+ $basic_list = [];
|
|
|
|
+ foreach ($basic as $value){
|
|
|
|
+ if($value['type'] == 18){
|
|
|
|
+ $basic_list[10][$value['title']] = $value['id'];
|
|
|
|
+ }elseif ($value['type'] == 23){
|
|
|
|
+ $basic_list[11][$value['title']] = $value['id'];
|
|
|
|
+ }elseif ($value['type'] == 24){
|
|
|
|
+ $basic_list[3][$value['title']] = $value['id'];
|
|
|
|
+ }elseif ($value['type'] == 29){
|
|
|
|
+ $basic_list[2][$value['title']] = $value['id'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
$search = "";
|
|
$search = "";
|
|
|
|
+ $customer = [];
|
|
foreach ($array as $key => $value){
|
|
foreach ($array as $key => $value){
|
|
$rowData = array_filter($value);
|
|
$rowData = array_filter($value);
|
|
if (empty($rowData)) {
|
|
if (empty($rowData)) {
|
|
unset($array[$key]);
|
|
unset($array[$key]);
|
|
- } elseif(empty($value[0]) || empty($value[1]) || empty($value[2]) || empty($value[3]) || empty($value[4]) || empty($value[5]) || empty($value[6])) {
|
|
|
|
|
|
+ } elseif(empty($value[0]) || empty($value[1]) || empty($value[2]) || empty($value[3]) || empty($value[4]) || empty($value[5]) || empty($value[6]) || empty($value[7])) {
|
|
return [false, '带*号的字段项必填'];
|
|
return [false, '带*号的字段项必填'];
|
|
}else{
|
|
}else{
|
|
foreach ($value as $k => $v){
|
|
foreach ($value as $k => $v){
|
|
$value[$k] = trim($v);
|
|
$value[$k] = trim($v);
|
|
}
|
|
}
|
|
- if(! isset($basic_type[$value[1]])) return [false, '店铺(平台类型):' . $value[1] .'不存在'];
|
|
|
|
- $value[1] = $basic_type[$value[1]];
|
|
|
|
- if(! isset(SalesOrder::$order_type[$value[6]])) return [false, '产品类型填写错误'];
|
|
|
|
|
|
+ if(! isset($basic_list[2][$value[2]])) return [false, '客户简称:' . $value[2] .'不存在'];
|
|
|
|
+ if(! isset($basic_list[3][$value[3]])) return [false, '店铺(平台类型):' . $value[3] .'不存在'];
|
|
|
|
+ $value[3] = $basic_list[3][$value[3]];
|
|
|
|
+ if(! empty($value[10])){
|
|
|
|
+ if(! isset($basic_list[10][$value[10]])) return [false, '安装方式:' . $value[3] .'不存在'];
|
|
|
|
+ $value[10] = $basic_list[10][$value[10]];
|
|
|
|
+ }
|
|
|
|
+ if(! empty($value[11])){
|
|
|
|
+ if(! isset($basic_list[11][$value[11]])) return [false, '安装地点:' . $value[3] .'不存在'];
|
|
|
|
+ $value[11] = $basic_list[11][$value[11]];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(! isset(SalesOrder::$order_type_name[$value[1]])) return [false, '产品类型填写错误'];
|
|
|
|
+ $value[1] = SalesOrder::$order_type_name[$value[1]];
|
|
|
|
+
|
|
|
|
+ if(! empty($value[12])) {
|
|
|
|
+ list($status,$msg) = $this->changeAndReturnDate($value[12]);
|
|
|
|
+ if(! $status) return [false,"施工日期请填写正确的日期格式,例如2023-05-01"];
|
|
|
|
+ $value[12] = $msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(! empty($value[13])) {
|
|
|
|
+ list($status,$msg) = $this->changeAndReturnDate($value[13]);
|
|
|
|
+ if(! $status) return [false,"交车日期请填写正确的日期格式,例如2023-05-01"];
|
|
|
|
+ $value[13] = $msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
$array[$key] = $value;
|
|
$array[$key] = $value;
|
|
- $search .= "(code = '".$value[2]."' and title ='".$value[3]."') or";
|
|
|
|
|
|
+ $search .= "(code = '".$value[4]."' and title ='".$value[5]."') or";
|
|
|
|
+
|
|
|
|
+ if(! empty($value[8]) && ! in_array($value[8], $customer)) $customer[] = $value[8];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(empty($array)) return [false, '导入数据不能为空'];
|
|
if(empty($array)) return [false, '导入数据不能为空'];
|
|
@@ -620,6 +662,8 @@ class ImportService extends Service
|
|
->where('del_time',0)
|
|
->where('del_time',0)
|
|
->select('title','id','code','cost','retail_price')
|
|
->select('title','id','code','cost','retail_price')
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
|
|
+// $pro = (new ProductService())->productList(['product_id' => array_column($product,'id'), 'type' => 2],$user);
|
|
|
|
+
|
|
$product_map = [];
|
|
$product_map = [];
|
|
foreach ($product as $value){
|
|
foreach ($product as $value){
|
|
$product_map[$value['code'] . $value['title']] = [
|
|
$product_map[$value['code'] . $value['title']] = [
|
|
@@ -630,15 +674,43 @@ class ImportService extends Service
|
|
}
|
|
}
|
|
|
|
|
|
$time = time();
|
|
$time = time();
|
|
|
|
+
|
|
|
|
+ $model = Customer::Clear($user,[]);
|
|
|
|
+ $customer_map = $model->where('del_time',0)
|
|
|
|
+ ->whereIn('title',$customer)
|
|
|
|
+ ->pluck('id','title')
|
|
|
|
+ ->toArray();
|
|
|
|
+
|
|
|
|
+ $customer_info = CustomerInfo::where('del_time',0)
|
|
|
|
+ ->whereIn('customer_id',array_values($customer_map))
|
|
|
|
+ ->whereIn('type',[CustomerInfo::type_one,CustomerInfo::type_two])
|
|
|
|
+ ->select('customer_id','type','contact_info','data_id')
|
|
|
|
+ ->orderBy('id','asc')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ $customer_contact = $customer_man = [];
|
|
|
|
+ foreach ($customer_info as $value){
|
|
|
|
+ if($value['type'] == CustomerInfo::type_one && ! isset($customer_contact[$value['customer_id']])){
|
|
|
|
+ $customer_contact[$value['customer_id']] = $value['contact_info'];
|
|
|
|
+ }elseif ($value['type'] == CustomerInfo::type_two){
|
|
|
|
+ $customer_man[$value['customer_id']][] = [
|
|
|
|
+ 'type' => SalesOrderInfo::type_two,
|
|
|
|
+ 'data_id' => $value['data_id'],
|
|
|
|
+ 'crt_time' => $time,
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
$tmp = [
|
|
$tmp = [
|
|
'model_type' => SalesOrder::Model_type_four,
|
|
'model_type' => SalesOrder::Model_type_four,
|
|
'sales_order_type' => 0,
|
|
'sales_order_type' => 0,
|
|
'order_number' => '',
|
|
'order_number' => '',
|
|
|
|
+ 'customer_short_name' => '',
|
|
'plat_type' => '',
|
|
'plat_type' => '',
|
|
'plat_order' => '',
|
|
'plat_order' => '',
|
|
'sign_time' => $time,
|
|
'sign_time' => $time,
|
|
'product_total' => 0,
|
|
'product_total' => 0,
|
|
'contract_fee' => 0,
|
|
'contract_fee' => 0,
|
|
|
|
+ 'discount_fee' => 0,
|
|
'rate' => 100,
|
|
'rate' => 100,
|
|
'depart_id' => $head,
|
|
'depart_id' => $head,
|
|
'top_depart_id' => $head,
|
|
'top_depart_id' => $head,
|
|
@@ -651,53 +723,76 @@ class ImportService extends Service
|
|
'product_id' => 0,
|
|
'product_id' => 0,
|
|
'cost' => 0,
|
|
'cost' => 0,
|
|
'retail_price' => 0,
|
|
'retail_price' => 0,
|
|
|
|
+ 'basic_type_id' => 0,
|
|
'price' => 0,
|
|
'price' => 0,
|
|
'final_amount' => 0,
|
|
'final_amount' => 0,
|
|
'number' => '',
|
|
'number' => '',
|
|
'crt_time' => $time,
|
|
'crt_time' => $time,
|
|
];
|
|
];
|
|
- $insert = $insert_detail = [];
|
|
|
|
|
|
+ $insert = $insert_detail = $insert_detail_man = [];
|
|
$prefix = SalesOrder::$prefix[salesOrder::Model_type_four];
|
|
$prefix = SalesOrder::$prefix[salesOrder::Model_type_four];
|
|
foreach ($array as $value){
|
|
foreach ($array as $value){
|
|
- $product_str = $value[2] . $value[3];
|
|
|
|
- if(! isset($product_map[$product_str])) return [false, '产品:' . '[' . $value[2]. ']' . '[' . $value[3]. ']' . '不存在'];
|
|
|
|
|
|
+ $product_str = $value[4] . $value[5];
|
|
|
|
+ if(! isset($product_map[$product_str])) return [false, '产品:' . '[' . $value[4]. ']' . '[' . $value[5]. ']' . '不存在'];
|
|
$product_tmp = $product_map[$product_str] ?? [];
|
|
$product_tmp = $product_map[$product_str] ?? [];
|
|
|
|
|
|
|
|
+ $customer_tmp = 0;
|
|
|
|
+ $customer_contact_tmp = "";
|
|
|
|
+ $customer_man_tmp = [];
|
|
|
|
+ if(! empty($value[8])){
|
|
|
|
+ $customer_tmp = $customer_map[$value[8]] ?? 0;
|
|
|
|
+ $customer_contact_tmp = $customer_contact[$customer_tmp] ?? "";
|
|
|
|
+ $customer_man_tmp = $customer_man[$customer_tmp] ?? [];
|
|
|
|
+ }
|
|
|
|
+ $customer_man_tmp[] = [
|
|
|
|
+ 'type' => SalesOrderInfo::type_one,
|
|
|
|
+ 'data_id' => $user['id'],
|
|
|
|
+ 'crt_time' => $time,
|
|
|
|
+ ];
|
|
|
|
+
|
|
$tmp['product_total'] = $tmp['contract_fee'] = 0;
|
|
$tmp['product_total'] = $tmp['contract_fee'] = 0;
|
|
- $keys = $value[0] . $value[6];
|
|
|
|
|
|
+ $keys = $value[0] . $value[1];
|
|
|
|
+ $insert_detail_man[$keys] = $customer_man_tmp;
|
|
if(! isset($insert[$keys])){
|
|
if(! isset($insert[$keys])){
|
|
$tmp['order_number'] = OrderNoService::createSalesOrderNumber($prefix);
|
|
$tmp['order_number'] = OrderNoService::createSalesOrderNumber($prefix);
|
|
- $tmp['sales_order_type'] = $value[6];
|
|
|
|
- $tmp['plat_type'] = $value[1];
|
|
|
|
|
|
+ $tmp['sales_order_type'] = $value[1];
|
|
|
|
+ $tmp['customer_short_name'] = $value[2];
|
|
|
|
+ $tmp['customer_id'] = $customer_tmp;
|
|
|
|
+ $tmp['customer_contact'] = $customer_contact_tmp;
|
|
|
|
+ $tmp['plat_type'] = $value[3];
|
|
$tmp['plat_order'] = $value[0];
|
|
$tmp['plat_order'] = $value[0];
|
|
- $tmp['product_total'] += $value[4] * $value[5];
|
|
|
|
- $tmp['contract_fee'] += $value[4] * $value[5];
|
|
|
|
|
|
+ $tmp['discount_fee'] = $value[9];
|
|
|
|
+ $tmp['product_total'] += $value[7];
|
|
|
|
+ $tmp['contract_fee'] += $value[7] - ($value[9]);
|
|
|
|
+ $tmp['construction_time'] = $value[12] ?? 0;
|
|
|
|
+ $tmp['handover_time'] = $value[13] ?? 0;
|
|
$insert[$keys] = $tmp;
|
|
$insert[$keys] = $tmp;
|
|
}else{
|
|
}else{
|
|
- $insert[$keys]['product_total'] += $value[4] * $value[5];
|
|
|
|
- $insert[$keys]['contract_fee'] += $value[4] * $value[5];
|
|
|
|
|
|
+ $insert[$keys]['product_total'] += $value[7];
|
|
|
|
+ $insert[$keys]['contract_fee'] += $value[7];
|
|
}
|
|
}
|
|
|
|
|
|
$tmp_detail['product_id'] = $product_tmp['id'];
|
|
$tmp_detail['product_id'] = $product_tmp['id'];
|
|
$tmp_detail['cost'] = $product_tmp['cost'];
|
|
$tmp_detail['cost'] = $product_tmp['cost'];
|
|
$tmp_detail['retail_price'] = $product_tmp['retail_price'];
|
|
$tmp_detail['retail_price'] = $product_tmp['retail_price'];
|
|
- $tmp_detail['price'] = $value[5];
|
|
|
|
- $tmp_detail['final_amount'] = $value[4] * $value[5];
|
|
|
|
- $tmp_detail['number'] = $value[4];
|
|
|
|
|
|
+ $tmp_detail['price'] = $product_tmp['retail_price'];
|
|
|
|
+ $tmp_detail['final_amount'] = $value[7];
|
|
|
|
+ $tmp_detail['number'] = $value[6];
|
|
|
|
|
|
$insert_detail[$keys][] = $tmp_detail;
|
|
$insert_detail[$keys][] = $tmp_detail;
|
|
}
|
|
}
|
|
|
|
|
|
$insert_detail = array_values($insert_detail);
|
|
$insert_detail = array_values($insert_detail);
|
|
|
|
+ $insert_detail_man = array_values($insert_detail_man);
|
|
try{
|
|
try{
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
if(! empty($insert)) SalesOrder::insert($insert);
|
|
if(! empty($insert)) SalesOrder::insert($insert);
|
|
|
|
+ $last_insert_id = SalesOrder::where('crt_time',$time)
|
|
|
|
+ ->select('id')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ $last_insert_id = array_column($last_insert_id,'id');
|
|
if(! empty($insert_detail)){
|
|
if(! empty($insert_detail)){
|
|
$insert2 = [];
|
|
$insert2 = [];
|
|
- $last_insert_id = SalesOrder::where('crt_time',$time)
|
|
|
|
- ->select('id')
|
|
|
|
- ->get()->toArray();
|
|
|
|
- $last_insert_id = array_column($last_insert_id,'id');
|
|
|
|
foreach ($last_insert_id as $key => $value){
|
|
foreach ($last_insert_id as $key => $value){
|
|
if(isset($insert_detail[$key])) {
|
|
if(isset($insert_detail[$key])) {
|
|
foreach ($insert_detail[$key] as $val){
|
|
foreach ($insert_detail[$key] as $val){
|
|
@@ -708,6 +803,18 @@ class ImportService extends Service
|
|
}
|
|
}
|
|
SalesOrderProductInfo::insert($insert2);
|
|
SalesOrderProductInfo::insert($insert2);
|
|
}
|
|
}
|
|
|
|
+ if(! empty($insert_detail_man)){
|
|
|
|
+ $insert3 = [];
|
|
|
|
+ foreach ($last_insert_id as $key => $value){
|
|
|
|
+ if(isset($insert_detail_man[$key])) {
|
|
|
|
+ foreach ($insert_detail_man[$key] as $val){
|
|
|
|
+ $val['sales_order_id'] = $value;
|
|
|
|
+ $insert3[] = $val;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ SalesOrderInfo::insert($insert3);
|
|
|
|
+ }
|
|
DB::commit();
|
|
DB::commit();
|
|
}catch (\Exception $e){
|
|
}catch (\Exception $e){
|
|
DB::rollBack();
|
|
DB::rollBack();
|