|
@@ -2,7 +2,6 @@
|
|
|
|
|
|
namespace App\Service;
|
|
namespace App\Service;
|
|
|
|
|
|
-use App\Exports\MyExport;
|
|
|
|
use App\Exports\TableHeadExport;
|
|
use App\Exports\TableHeadExport;
|
|
use App\Import\Import;
|
|
use App\Import\Import;
|
|
use App\Import\ImportAll;
|
|
use App\Import\ImportAll;
|
|
@@ -12,8 +11,9 @@ use App\Model\Employee;
|
|
use App\Model\Product;
|
|
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\SalesOrderProductInfo;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
-use Illuminate\Support\Facades\Storage;
|
|
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
|
|
|
@@ -23,7 +23,7 @@ class ImportService extends Service
|
|
public static $type = [
|
|
public static $type = [
|
|
'product', //产品
|
|
'product', //产品
|
|
'customer', //客户
|
|
'customer', //客户
|
|
- 'sales', //线上订单
|
|
|
|
|
|
+ 'salesOnline', //线上订单
|
|
];
|
|
];
|
|
|
|
|
|
//写活的导入------------------- 暂时不好用
|
|
//写活的导入------------------- 暂时不好用
|
|
@@ -145,7 +145,7 @@ class ImportService extends Service
|
|
return [true, ['file' => $filename]];
|
|
return [true, ['file' => $filename]];
|
|
}
|
|
}
|
|
|
|
|
|
- private function customer(){
|
|
|
|
|
|
+ private function customer($data,$user){
|
|
//生成下载文件
|
|
//生成下载文件
|
|
$filename = "客户模板_" . time() . '.' . 'xlsx';
|
|
$filename = "客户模板_" . time() . '.' . 'xlsx';
|
|
|
|
|
|
@@ -179,12 +179,12 @@ class ImportService extends Service
|
|
return [true, $config_array,$filename];
|
|
return [true, $config_array,$filename];
|
|
}
|
|
}
|
|
|
|
|
|
- private function sales(){
|
|
|
|
|
|
+ private function salesOnline($data,$user){
|
|
//生成下载文件
|
|
//生成下载文件
|
|
$filename = "线上订单模板_" . time() . '.' . 'xlsx';
|
|
$filename = "线上订单模板_" . time() . '.' . 'xlsx';
|
|
|
|
|
|
//获取配置文件
|
|
//获取配置文件
|
|
- $config = "excel.salesTable";
|
|
|
|
|
|
+ $config = "excel.salesOnlineTable";
|
|
$config_array = config($config) ?? [];
|
|
$config_array = config($config) ?? [];
|
|
if(empty($config_array)) return [false, '配置文件不存在',''];
|
|
if(empty($config_array)) return [false, '配置文件不存在',''];
|
|
return [true, $config_array,$filename];
|
|
return [true, $config_array,$filename];
|
|
@@ -512,5 +512,139 @@ class ImportService extends Service
|
|
|
|
|
|
return [true, ''];
|
|
return [true, ''];
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public function salesOnlineImport($array, $user){
|
|
|
|
+ $head = $user['head']['id'] ?? 0;
|
|
|
|
+
|
|
|
|
+ // 去除表头
|
|
|
|
+ unset($array[0]);
|
|
|
|
+ if(empty($array)) return [false, '导入数据不能为空'];
|
|
|
|
+
|
|
|
|
+ $model = BasicType::TopClear($user,[]);
|
|
|
|
+ $basic_type = $model->where('del_time',0)
|
|
|
|
+ ->where('type',24)
|
|
|
|
+ ->pluck('id','title')
|
|
|
|
+ ->toArray();
|
|
|
|
+ $search = "";
|
|
|
|
+ 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]) || empty($value[6])) {
|
|
|
|
+ return [false, '带*号的字段项必填'];
|
|
|
|
+ }else{
|
|
|
|
+ foreach ($value as $k => $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, '产品类型填写错误'];
|
|
|
|
+ $array[$key] = $value;
|
|
|
|
+ $search .= "(code = '".$value[2]."' and title ='".$value[3]."') or";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(empty($array)) return [false, '导入数据不能为空'];
|
|
|
|
+ $search = rtrim($search,' or');
|
|
|
|
+ $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'] . $value['title']] = [
|
|
|
|
+ 'id' => $value['id'],
|
|
|
|
+ 'cost' => $value['cost'],
|
|
|
|
+ 'retail_price' => $value['retail_price'],
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $time = time();
|
|
|
|
+ $tmp = [
|
|
|
|
+ 'model_type' => SalesOrder::Model_type_four,
|
|
|
|
+ 'sales_order_type' => 0,
|
|
|
|
+ 'order_number' => '',
|
|
|
|
+ 'plat_type' => '',
|
|
|
|
+ 'plat_order' => '',
|
|
|
|
+ 'sign_time' => $time,
|
|
|
|
+ 'product_total' => 0,
|
|
|
|
+ 'contract_fee' => 0,
|
|
|
|
+ '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,
|
|
|
|
+ 'price' => 0,
|
|
|
|
+ 'final_amount' => 0,
|
|
|
|
+ 'number' => '',
|
|
|
|
+ 'crt_time' => $time,
|
|
|
|
+ ];
|
|
|
|
+ $insert = $insert_detail = [];
|
|
|
|
+ $prefix = SalesOrder::$prefix[salesOrder::Model_type_four];
|
|
|
|
+ foreach ($array as $value){
|
|
|
|
+ $product_str = $value[2] . $value[3];
|
|
|
|
+ if(! isset($product_map[$product_str])) return [false, '产品:' . '[' . $value[2]. ']' . '[' . $value[3]. ']' . '不存在'];
|
|
|
|
+ $product_tmp = $product_map[$product_str] ?? [];
|
|
|
|
+
|
|
|
|
+ $tmp['product_total'] = $tmp['contract_fee'] = 0;
|
|
|
|
+ $keys = $value[0] . $value[6];
|
|
|
|
+ if(! isset($insert[$keys])){
|
|
|
|
+ $tmp['order_number'] = OrderNoService::createSalesOrderNumber($prefix);
|
|
|
|
+ $tmp['sales_order_type'] = $value[6];
|
|
|
|
+ $tmp['plat_type'] = $value[1];
|
|
|
|
+ $tmp['plat_order'] = $value[0];
|
|
|
|
+ $tmp['product_total'] += $value[4] * $value[5];
|
|
|
|
+ $tmp['contract_fee'] += $value[4] * $value[5];
|
|
|
|
+ $insert[$keys] = $tmp;
|
|
|
|
+ }else{
|
|
|
|
+ $insert[$keys]['product_total'] += $value[4] * $value[5];
|
|
|
|
+ $insert[$keys]['contract_fee'] += $value[4] * $value[5];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $tmp_detail['product_id'] = $product_tmp['id'];
|
|
|
|
+ $tmp_detail['cost'] = $product_tmp['cost'];
|
|
|
|
+ $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];
|
|
|
|
+
|
|
|
|
+ $insert_detail[$keys][] = $tmp_detail;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $insert_detail = array_values($insert_detail);
|
|
|
|
+ try{
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+ if(! empty($insert)) SalesOrder::insert($insert);
|
|
|
|
+ if(! empty($insert_detail)){
|
|
|
|
+ $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){
|
|
|
|
+ if(isset($insert_detail[$key])) {
|
|
|
|
+ foreach ($insert_detail[$key] as $val){
|
|
|
|
+ $val['sales_order_id'] = $value;
|
|
|
|
+ $insert2[] = $val;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ SalesOrderProductInfo::insert($insert2);
|
|
|
|
+ }
|
|
|
|
+ DB::commit();
|
|
|
|
+ }catch (\Exception $e){
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ return [false, $e->getMessage() . $e->getLine() . $e->getCode()];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true, ''];
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|