|
@@ -28,6 +28,7 @@ class ImportService extends Service
|
|
'product', //产品
|
|
'product', //产品
|
|
'customer', //客户
|
|
'customer', //客户
|
|
'salesOnline', //线上订单
|
|
'salesOnline', //线上订单
|
|
|
|
+ 'btOnline' //补贴订单
|
|
];
|
|
];
|
|
|
|
|
|
//写活的导入------------------- 暂时不好用
|
|
//写活的导入------------------- 暂时不好用
|
|
@@ -192,6 +193,17 @@ class ImportService extends Service
|
|
return [true, $config_array,$filename];
|
|
return [true, $config_array,$filename];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private function btOnline($data,$user){
|
|
|
|
+ //生成下载文件
|
|
|
|
+ $filename = "补贴订单模板_" . time() . '.' . 'xlsx';
|
|
|
|
+
|
|
|
|
+ //获取配置文件
|
|
|
|
+ $config = "excel.salesOnlineTable";
|
|
|
|
+ $config_array = config($config) ?? [];
|
|
|
|
+ if(empty($config_array)) return [false, '配置文件不存在',''];
|
|
|
|
+ return [true, $config_array,$filename];
|
|
|
|
+ }
|
|
|
|
+
|
|
//导入入口
|
|
//导入入口
|
|
public function importAll($data,$user){
|
|
public function importAll($data,$user){
|
|
// //不超时
|
|
// //不超时
|
|
@@ -917,5 +929,251 @@ class ImportService extends Service
|
|
|
|
|
|
return [true, ''];
|
|
return [true, ''];
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public function btOnlineImport($array, $user){
|
|
|
|
+ $head = $user['head']['id'] ?? 0;
|
|
|
|
+
|
|
|
|
+ // 去除表头
|
|
|
|
+ unset($array[0]);
|
|
|
|
+ if(empty($array)) return [false, '导入数据不能为空'];
|
|
|
|
+
|
|
|
|
+ $basic = (new BasicTypeService())->getMyBasicList($user, [18,23,24,29]);
|
|
|
|
+ $basic_list = [];
|
|
|
|
+ foreach ($basic as $value){
|
|
|
|
+ if($value['type'] == 18){
|
|
|
|
+ $basic_list[9][$value['title']] = $value['id'];
|
|
|
|
+ }elseif ($value['type'] == 23){
|
|
|
|
+ $basic_list[10][$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 = "";
|
|
|
|
+ $customer = [];
|
|
|
|
+ foreach ($array as $key => $value){
|
|
|
|
+ $rowData = array_filter($value);
|
|
|
|
+ if (empty($rowData)) {
|
|
|
|
+ unset($array[$key]);
|
|
|
|
+ } elseif(empty($value[0]) || empty($value[1]) || empty($value[2]) || empty($value[3]) || empty($value[4]) || empty($value[5]) || $value[6] === null) {
|
|
|
|
+ return [false, '带*号的字段项必填'];
|
|
|
|
+ }else{
|
|
|
|
+ foreach ($value as $k => $v){
|
|
|
|
+ $value[$k] = trim($v);
|
|
|
|
+ }
|
|
|
|
+ if(! isset($basic_list[2][$value[2]])) return [false, '客户简称:' . $value[2] .'不存在'];
|
|
|
|
+ $value[2] = $basic_list[2][$value[2]];
|
|
|
|
+ if(! isset($basic_list[3][$value[3]])) return [false, '店铺(平台类型):' . $value[3] .'不存在'];
|
|
|
|
+ $value[3] = $basic_list[3][$value[3]];
|
|
|
|
+
|
|
|
|
+ if(! is_numeric($value[5])) return [false, '货品数量请填写正确的数值'];
|
|
|
|
+ if(! is_numeric($value[6])) return [false, '产品合同金额请填写正确的数值'];
|
|
|
|
+ if(! empty($value[8]) && ! is_numeric($value[8])) return [false, '订单优惠金额请填写正确的数值'];
|
|
|
|
+ if(! empty($value[9])){
|
|
|
|
+ if(! isset($basic_list[9][$value[9]])) return [false, '安装方式:' . $value[9] .'不存在'];
|
|
|
|
+ $value[9] = $basic_list[9][$value[9]];
|
|
|
|
+ }
|
|
|
|
+ if(! empty($value[10])){
|
|
|
|
+ if(! isset($basic_list[10][$value[10]])) return [false, '安装地点:' . $value[10] .'不存在'];
|
|
|
|
+ $value[10] = $basic_list[10][$value[10]];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(! isset(SalesOrder::$order_type_name[$value[1]])) return [false, '产品类型填写错误'];
|
|
|
|
+ $value[1] = SalesOrder::$order_type_name[$value[1]];
|
|
|
|
+
|
|
|
|
+ if(! empty($value[11])) {
|
|
|
|
+ list($status,$msg) = $this->changeAndReturnDate($value[11]);
|
|
|
|
+ if(! $status) return [false,"施工日期请填写正确的日期格式,例如2023-05-01"];
|
|
|
|
+ $value[11] = $msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(! empty($value[12])) {
|
|
|
|
+ list($status,$msg) = $this->changeAndReturnDate($value[12]);
|
|
|
|
+ if(! $status) return [false,"交车日期请填写正确的日期格式,例如2023-05-01"];
|
|
|
|
+ $value[12] = $msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $array[$key] = $value;
|
|
|
|
+ $search .= "(code = '".$value[4]."') or";
|
|
|
|
+
|
|
|
|
+ if(! empty($value[7]) && ! in_array($value[7], $customer)) $customer[] = $value[7];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(empty($array)) return [false, '导入数据不能为空'];
|
|
|
|
+ $search = rtrim($search,' or');
|
|
|
|
+ $search = "($search)";
|
|
|
|
+ $model = Product::ProductClear($user,[]);
|
|
|
|
+ $product = $model->whereRaw($search)
|
|
|
|
+ ->where('del_time',0)
|
|
|
|
+ ->select('title','id','code','cost','retail_price')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ $product_map = [];
|
|
|
|
+ foreach ($product as $value){
|
|
|
|
+ $product_map[$value['code']] = [
|
|
|
|
+ 'id' => $value['id'],
|
|
|
|
+ 'cost' => $value['cost'],
|
|
|
|
+ 'retail_price' => $value['retail_price'],
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $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 = [
|
|
|
|
+ 'model_type' => SalesOrder::Model_type_seven,
|
|
|
|
+ 'sales_order_type' => 0,
|
|
|
|
+ 'order_number' => '',
|
|
|
|
+ 'customer_short_name' => '',
|
|
|
|
+ 'plat_type' => '',
|
|
|
|
+ 'plat_order' => '',
|
|
|
|
+ 'sign_time' => $time,
|
|
|
|
+ 'product_total' => 0,
|
|
|
|
+ 'contract_fee' => 0,
|
|
|
|
+ 'discount_fee' => 0,
|
|
|
|
+ 'cdefine29' => '',//分社施工
|
|
|
|
+ 'cdefine32' => '',//达人昵称
|
|
|
|
+ 'cdefine30' => '',//业务员
|
|
|
|
+ 'rate' => 100,
|
|
|
|
+ 'depart_id' => $head,
|
|
|
|
+ 'top_depart_id' => $head,
|
|
|
|
+ 'crt_id' => $user['id'],
|
|
|
|
+ 'crt_time' => $time,
|
|
|
|
+ 'upd_time' => $time,
|
|
|
|
+ ];
|
|
|
|
+ $tmp_detail = [
|
|
|
|
+ 'sales_order_id' => 0,
|
|
|
|
+ 'product_id' => 0,
|
|
|
|
+ 'cost' => 0,
|
|
|
|
+ 'retail_price' => 0,
|
|
|
|
+ 'basic_type_id' => 0,
|
|
|
|
+ 'price' => 0,
|
|
|
|
+ 'final_amount' => 0,
|
|
|
|
+ 'number' => '',
|
|
|
|
+ 'crt_time' => $time,
|
|
|
|
+ ];
|
|
|
|
+ $insert = $insert_detail = $insert_detail_man = [];
|
|
|
|
+ $prefix = SalesOrder::$prefix[salesOrder::Model_type_four];
|
|
|
|
+ foreach ($array as $value){
|
|
|
|
+ $product_str = $value[4];
|
|
|
|
+ if(! isset($product_map[$product_str])) return [false, '产品:' . '[' . $value[4]. ']' . '不存在'];
|
|
|
|
+ $product_tmp = $product_map[$product_str] ?? [];
|
|
|
|
+
|
|
|
|
+ $customer_tmp = 0;
|
|
|
|
+ $customer_contact_tmp = "";
|
|
|
|
+ $customer_man_tmp = [];
|
|
|
|
+ if(! empty($value[7])){
|
|
|
|
+ $customer_tmp = $customer_map[$value[7]] ?? 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;
|
|
|
|
+ $keys = $value[0] . $value[1];
|
|
|
|
+ $insert_detail_man[$keys] = $customer_man_tmp;
|
|
|
|
+ if(! isset($insert[$keys])){
|
|
|
|
+ $tmp['order_number'] = OrderNoService::createSalesOrderNumberImport($prefix);
|
|
|
|
+ $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['discount_fee'] = $value[8] ?: 0;
|
|
|
|
+ $tmp['cdefine29'] = $value[13] ?? "";//分社施工
|
|
|
|
+ $tmp['cdefine32'] = $value[14] ?? "";//达人昵称
|
|
|
|
+ $tmp['cdefine30'] = $value[15] ?? "";//业务员
|
|
|
|
+ $tmp['product_total'] += $value[6];
|
|
|
|
+ $tmp['contract_fee'] += $value[6] - $tmp['discount_fee'];
|
|
|
|
+ $tmp['construction_time'] = $value[11] ?? 0;
|
|
|
|
+ $tmp['handover_time'] = $value[12] ?? 0;
|
|
|
|
+ $insert[$keys] = $tmp;
|
|
|
|
+ }else{
|
|
|
|
+ $insert[$keys]['product_total'] += $value[6];
|
|
|
|
+ $insert[$keys]['contract_fee'] += $value[6];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $tmp_detail['product_id'] = $product_tmp['id'];
|
|
|
|
+ $tmp_detail['cost'] = $product_tmp['cost'];
|
|
|
|
+ $tmp_detail['retail_price'] = $product_tmp['retail_price'];
|
|
|
|
+ $tmp_detail['price'] = $product_tmp['retail_price'];
|
|
|
|
+ $tmp_detail['final_amount'] = $value[6];
|
|
|
|
+ $tmp_detail['number'] = $value[5];
|
|
|
|
+
|
|
|
|
+ $insert_detail[$keys][] = $tmp_detail;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $insert_detail = array_values($insert_detail);
|
|
|
|
+ $insert_detail_man = array_values($insert_detail_man);
|
|
|
|
+ try{
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+ 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)){
|
|
|
|
+ $insert2 = [];
|
|
|
|
+ foreach ($last_insert_id as $key => $value){
|
|
|
|
+ if(isset($insert_detail[$key])) {
|
|
|
|
+ foreach ($insert_detail[$key] as $val){
|
|
|
|
+ $val['sales_order_id'] = $value;
|
|
|
|
+ $insert2[] = $val;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ 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();
|
|
|
|
+ }catch (\Exception $e){
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ return [false, $e->getMessage() . $e->getLine() . $e->getCode()];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true, ''];
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|