cqp 4 ماه پیش
والد
کامیت
70435de7ba

+ 13 - 0
app/Http/Controllers/Api/SalesOrderController.php

@@ -59,6 +59,19 @@ class SalesOrderController extends BaseController
         }
     }
 
+    public function salesOrderClose(Request $request)
+    {
+        $service = new SalesOrderService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->salesOrderClose($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function salesOrderDetail(Request $request)
     {
         $service = new SalesOrderService();

+ 6 - 6
app/Service/CheckService.php

@@ -90,7 +90,7 @@ class CheckService extends Service
 
     //改为待审核状态 校验
     public static $opt_1case_check = [
-        self::five => 'checkConstruction',//施工单
+//        self::five => 'checkConstruction',//施工单
     ];
 
     //改为待审核状态
@@ -131,9 +131,9 @@ class CheckService extends Service
 
     //单据库存流水
     public static $record = [
-        self::two => 'recordInvoiceOrder',
+//        self::two => 'recordInvoiceOrder',
         self::three => 'recordPurchaseOrder',
-        self::five => 'recordConstruction',
+//        self::five => 'recordConstruction',
         self::six => 'recordReturnExchangeOrder',
         self::fourteen => 'recordInventory',
     ];
@@ -164,7 +164,7 @@ class CheckService extends Service
 
     //审核通过后 驳回 产生流水
     public static $reject_record = [
-        self::five => 'reject_record_construction', //施工单驳回
+//        self::five => 'reject_record_construction', //施工单驳回
         self::three => 'reject_record_purchase', //采购
         self::six => 'reject_record_return_exchange',//退换货
     ];
@@ -194,7 +194,7 @@ class CheckService extends Service
         self::thi => OrderOperation::thirty,//虚拟采购单
     ];
 
-    //校验
+    //校验 不需要了
     public function checkConstruction($data, $user){
         $order = Construction::where('del_time',0)
             ->where('order_number',$data['order_number'])
@@ -231,7 +231,7 @@ class CheckService extends Service
         if(! $status) return [false, $msg];
 
         //锁定库存
-        ProductInventoryService::changeLockNumber($user,$product_submit);
+//        ProductInventoryService::changeLockNumber($user,$product_submit);
 
         return [true, ''];
     }

+ 6 - 24
app/Service/ConstructionService.php

@@ -149,7 +149,7 @@ class ConstructionService extends Service
                 ConstructionProductInfo::insert($insert);
 
                 //锁定库存
-                if($data['model_type'] == Construction::Model_type_one) ProductInventoryService::changeLockNumber($user,$msg[0],$msg[1]);
+//                if($data['model_type'] == Construction::Model_type_one) ProductInventoryService::changeLockNumber($user,$msg[0],$msg[1]);
             }
 
             if(! empty($data['schedule_info_id'])) ScheduleInfo::where('id',$data['schedule_info_id'])->update(['is_use' => 1]);
@@ -289,7 +289,7 @@ class ConstructionService extends Service
                 ConstructionProductInfo::insert($insert);
 
                 //锁定库存
-                if($data['model_type'] == Construction::Model_type_one) ProductInventoryService::changeLockNumber($user,$msg[0],[]);
+//                if($data['model_type'] == Construction::Model_type_one) ProductInventoryService::changeLockNumber($user,$msg[0],[]);
             }
 
             if(! empty($data['schedule_info_id'])) ScheduleInfo::where('id',$data['schedule_info_id'])->update(['is_use' => 1]);
@@ -371,16 +371,7 @@ class ConstructionService extends Service
             (new RangeService())->RangeDelete($data['id'],SeeRange::type_two);
 
             //锁定库存释放
-            if($construction['model_type'] == Construction::Model_type_one) ProductInventoryService::changeLockNumber($user,[],$product_save);
-
-            //排班修改
-//            $schedule = ScheduleInfo::where('del_time',0)
-//                ->where('schedule_id',$construction['schedule_id'])
-//                ->where('start_time',$construction['day_start_stamp'])
-//                ->where('end_time',$construction['day_end_stamp'])
-//                ->where('is_use','>', ScheduleInfo::not_use)
-//                ->first();
-//            if(! empty($schedule)) ScheduleInfo::where('id',$schedule->id)->update(['is_use' => ScheduleInfo::not_use]);
+//            if($construction['model_type'] == Construction::Model_type_one) ProductInventoryService::changeLockNumber($user,[],$product_save);
 
             DB::commit();
         }catch (\Exception $exception){
@@ -695,7 +686,6 @@ class ConstructionService extends Service
     public function constructionRule(&$data, $user, $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($data['model_type'] == Construction::Model_type_one && empty($data['storehouse_id'])) return [false,'请选择仓库'];
         if(empty($data['menu_id'])) return [false, '菜单信息不能为空'];
         if(empty($data['sales_order_id'])) return [false,'请选择合同'];
@@ -708,7 +698,7 @@ class ConstructionService extends Service
             //总社的订单 需要派单 才能建施工
             if($sale['state'] < SalesOrder::State_four) return [false,'合同未门店派单,不允许新建施工单'];
         }
-        if(empty($data['customer_id'])) return [false, '订单合同暂无客户,请补充完信息再进行施工单操作'];
+//        if(empty($data['customer_id'])) return [false, '订单合同暂无客户,请补充完信息再进行施工单操作'];
 
         list($status,$msg) = $this->limitingSendRequestBackgExpire("construction" . $sale['order_number']);
         if(! $status) return [false, $msg];
@@ -728,14 +718,6 @@ class ConstructionService extends Service
         if(! empty($data['construction_time'])) $data['construction_time'] = $this->changeDateToDateMin($data['construction_time']);
         if(! empty($data['handover_time'])) $data['handover_time'] = $this->changeDateToDateMin($data['handover_time']);
 
-        if($data['model_type'] == Construction::Model_type_one){
-//            if(empty($data['install_method'])) return [false,'安装方式不能为空'];
-//            if(empty($data['install_position'])) return [false,'安装地点不能为空'];
-        }else{
-//            if(empty($data['construction_contact'])) return [false,'联系方式不能为空'];
-//            if(empty($data['address1']) || empty($data['address2'])) return [false,'地址不能为空'];
-        }
-
         //所属部门 以及  顶级部门
         if(empty($data['depart_id'])) {
             $data['depart_id'] = $this->getDepart($user);
@@ -780,8 +762,8 @@ class ConstructionService extends Service
         $data['is_check_stock'] = $user['is_check_stock'];
         if($data['model_type'] == Construction::Model_type_one){
             //到店安装 才校验库存
-            list($status,$msg) = (new ProductInventoryService())->compareStock($user,$product_id, $product_submit, $product_save);
-            if(! $status) return [false, $msg];
+//            list($status,$msg) = (new ProductInventoryService())->compareStock($user,$product_id, $product_submit, $product_save);
+//            if(! $status) return [false, $msg];
         }else{
             $data['is_check_stock'] = ProductInventorySet::type_two;
         }

+ 11 - 2
app/Service/CustomerService.php

@@ -524,6 +524,15 @@ class CustomerService extends Service
             ->select('title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','pond_state','top_depart_id','fp_time','fp_top_depart_id')
             ->orderby('id', 'desc');
 
+        if(! empty($data['title_t'])) {
+            // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
+            $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title_t']));
+            $id = (new RangeService())->crtContactSearch($data);
+            // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
+            $model->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%'])
+                ->orWhere('consulting_product', 'LIKE', '%'.$data['title_t'].'%')
+                ->orWhereIn('id', $id);
+        }
         if(! empty($data['id'])) $model->where('id', $data['id']);
         if(! empty($data['my_fz']) || ! empty($data['my_xt'])){
             $id = $this->getCustomerId($data,$user);
@@ -960,10 +969,10 @@ class CustomerService extends Service
             $fp_top_depart_title = $depart2_map[$value['id']] ?? "";
             if($value['fp_time'] > 0) {
                 //分配过所属门店是分配门店
-                $data['data'][$key]['fp_top_depart_title'] = $fp_top_depart_title;
+                $data['data'][$key]['belong_top_depart_title'] = $fp_top_depart_title;
             }else{
                 //没分配过所属门店是创建门店
-                $data['data'][$key]['fp_top_depart_title'] = $top_depart_title;
+                $data['data'][$key]['belong_top_depart_title'] = $top_depart_title;
             }
             $data['data'][$key]['is_dispatch_title'] = $value['fp_time'] ? "已分配或移交" : "未分配或移交";
 

+ 2 - 2
app/Service/EmployeeService.php

@@ -290,7 +290,7 @@ class EmployeeService extends Service
             $employee_id = array_column($employee_id,'employee_id');
             $model->whereIn("id", $employee_id);
         }else{
-            if(! $user['is_all_depart']){
+            if(! $user['is_all_depart'] && ! empty($data['is_top_qx'])){
                 $employee_id = $this->getEmployee($user);
                 $model->whereIn('id',$employee_id);
             }
@@ -844,7 +844,7 @@ class EmployeeService extends Service
             $depart_id = $this->getDepartIdListOfMySales($user);
             $model->whereIn('id', $depart_id);
         }else{
-            if(! $user['is_all_depart']){
+            if(! $user['is_all_depart'] && ! empty($data['is_top_qx'])){
                 $depart_id = $this->getDepartIdList($user);
                 $model->whereIn('id',$depart_id);
             }

+ 7 - 2
app/Service/ImportService.php

@@ -25,6 +25,7 @@ use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Log;
 use Maatwebsite\Excel\Facades\Excel;
 use PhpOffice\PhpSpreadsheet\IOFactory;
+use PhpOffice\PhpSpreadsheet\Shared\Date;
 
 class ImportService extends Service
 {
@@ -303,10 +304,14 @@ class ImportService extends Service
                 $array_clean[] = $value[1];
 
                 if(! empty($value[15])){
-                    if(! strtotime($value[15])){
+                    $dateTimeObject = Date::excelToDateTimeObject($value[15]);
+                    // 现在你可以格式化这个日期了
+                    $formattedDate = $dateTimeObject->format('Y-m-d');
+
+                    if(! strtotime($formattedDate)){
                         return [false, '录入日期请填写正确的日期'];
                     }else{
-                        $value[15] = strtotime($value[15]);
+                        $value[15] = strtotime($formattedDate);
                     }
                 } else{
                     $value[15] = $now;

+ 6 - 6
app/Service/InvoiceOrderService.php

@@ -63,7 +63,7 @@ class InvoiceOrderService extends Service
                 InvoiceOrderInfo::insert($sub);
 
                 //锁定库存
-                ProductInventoryService::changeLockNumber($user, $msg[0],$msg[1]);
+//                ProductInventoryService::changeLockNumber($user, $msg[0],$msg[1]);
             }
 
             DB::commit();
@@ -121,7 +121,7 @@ class InvoiceOrderService extends Service
                 InvoiceOrderInfo::insert($sub);
 
                 //锁定库存
-                ProductInventoryService::changeLockNumber($user,$msg[0],[]);
+//                ProductInventoryService::changeLockNumber($user,$msg[0],[]);
             }
 
             DB::commit();
@@ -197,7 +197,7 @@ class InvoiceOrderService extends Service
         $order = $order->toArray();
         if($order['state'] > InvoiceOrder::STATE_ZERO) return [false,'发货订单已确认,删除失败!'];
 
-        $product_save = $this->getSaveDetail($data['order_number']);
+//        $product_save = $this->getSaveDetail($data['order_number']);
         try{
             DB::beginTransaction();
             InvoiceOrder::where('order_number',$data['order_number'])->update([
@@ -208,7 +208,7 @@ class InvoiceOrderService extends Service
             ]);
             (new RangeService())->RangeDelete($order['id'],SeeRange::type_three);
             //锁定库存释放
-            ProductInventoryService::changeLockNumber($user,[],$product_save);
+//            ProductInventoryService::changeLockNumber($user,[],$product_save);
 
             DB::commit();
         }catch (\Throwable $e){
@@ -363,8 +363,8 @@ class InvoiceOrderService extends Service
         //是否校验库存
         ProductInventoryService::is_check($user,$data);
 
-        list($status,$msg) = (new ProductInventoryService())->compareStock($user,$product_id, $product_submit, $product_save);
-        if(! $status) return [false, $msg];
+//        list($status,$msg) = (new ProductInventoryService())->compareStock($user,$product_id, $product_submit, $product_save);
+//        if(! $status) return [false, $msg];
 
         if($is_check){
             $order_number = (new OrderNoService())->createOrderNumber(InvoiceOrder::prefix);

+ 15 - 42
app/Service/ProductService.php

@@ -521,8 +521,6 @@ class ProductService extends Service
         $title_map = BasicType::whereIn('id',array_unique(array_merge_recursive(array_column($detail,'basic_type_id'),array_column($basic,'id'))))
             ->pluck('title','id')
             ->toArray();
-        //是否总公司
-        $is_main = $user['is_all_depart'];
         $top_depart = $user['depart_top'][0] ?? [];
         $customer['is_edit'] = $customer['top_depart_id'] == $top_depart['depart_id'] ? 1 : 0;
         $customer['product_price'] = [];
@@ -530,10 +528,10 @@ class ProductService extends Service
         //特殊功能按钮
         $special_button = $user['special_button'] ?? [];
 
-        //成本隐藏
-        $price = "******";
-        if(in_array(RoleMenuButton::special_two,$special_button)) $price = $customer['cost'];
-        $customer['cost_show'] = $price;
+        //成本
+        $is_show_cost = 0;
+        if(in_array(RoleMenuButton::special_two,$special_button)) $is_show_cost = 1;
+        $customer['cost_show'] = $is_show_cost;
 
         //所有金额
         foreach ($basic as $value){
@@ -832,8 +830,8 @@ class ProductService extends Service
         }
 
         //分社价格
-        $product_title = $product_fs = [];
-        if(! empty($search['fs_price_get'])) list($product_title , $product_fs) = $this->getProductPriceDetail(['id' => $product_id], $user);
+        $product_fs = [];
+        if(! empty($search['fs_price_get'])) $product_fs = $this->getProductPriceDetail(['id' => $product_id], $user);
 
         foreach ($data['data'] as $key => $value){
             $tmp = [];
@@ -854,7 +852,10 @@ class ProductService extends Service
                 }
             }
             $data['data'][$key]['product_price'] = $tmp;
-            $data['data'][$key]['product_fs_price'] = array_values($product_fs[$value['id']] ?? []);
+            $price_tmp = $product_fs[$value['id']] ?? [];
+            foreach ($price_tmp as $t_k => $t){
+                $data['data'][$key][$t_k] = $t;
+            }
             $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
             $data['data'][$key]['is_use_title'] = Product::$is_use[$value['is_use']] ?? "";
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
@@ -869,15 +870,10 @@ class ProductService extends Service
             $data['data'][$key]['img'] = $img[$value['id']] ?? "";
             //库存
             $data['data'][$key]['stock'] = $stock_map[$value['id']] ?? [];
-
-            //成本隐藏
-            $price = "******";
-            if(in_array(RoleMenuButton::special_two,$special_button)) $price = $value['cost'];
-            $data['data'][$key]['cost_show'] = $price;
+            //成本
+            $data['data'][$key]['cost_show'] = $value['cost'];
         }
 
-        $data['product_title'] = $product_title;
-
         return $data;
     }
 
@@ -1103,34 +1099,11 @@ class ProductService extends Service
             ->whereIn('product_id',$data['id'])
             ->select('product_id','basic_type_id','price')
             ->get()->toArray();
-        $title_map = BasicType::whereIn('id',array_unique(array_merge_recursive(array_column($detail,'basic_type_id'),array_column($basic,'id'))))
-            ->pluck('title','id')
-            ->toArray();
-        $top_depart = $user['depart_top'][0] ?? [];
         $product_price = [];
 
-        //特殊功能按钮
-        $special_button = $user['special_button'] ?? [];
-
-        $return_title = [];
-
         //所有金额
         foreach ($basic as $value){
-            $show = 0;
-            if(in_array(RoleMenuButton::special_one,$special_button)){
-                $show = 1;
-            }else{
-                if($top_depart['basic_type_id'] == $value['id']) $show = 1;
-            }
-            $return_title[] = [
-                'basic_type_id' => $value['id'],
-                'basic_type_title' => $title_map[$value['id']] ?? '',
-                'is_show' => $show,
-            ];
-            $product_price[$value['id']] = [
-                'basic_type_id' => $value['id'],
-                'price' => 0,
-            ];
+            $product_price[$value['id']] = "0";
         }
 
         $return = [];
@@ -1140,9 +1113,9 @@ class ProductService extends Service
 
         //展示金额
         foreach ($detail as $value){
-            if(isset($return[$value['product_id']][$value['basic_type_id']])) $return[$value['product_id']][$value['basic_type_id']]['price'] = $value['price'];
+            if(isset($return[$value['product_id']][$value['basic_type_id']])) $return[$value['product_id']][$value['basic_type_id']] = $value['price'];
         }
 
-        return [$return_title,$return];
+        return $return;
     }
 }

+ 94 - 45
app/Service/RangeService.php

@@ -561,6 +561,14 @@ class RangeService extends Service
         return array_column($emp_id,'id');
     }
 
+    public function crtContactSearch($data){
+        $id = CustomerInfo::where('del_time',0)
+            ->where('type',CustomerInfo::type_one)
+            ->where('contact_info','LIKE', '%'.$data['title_t'].'%')
+            ->select('customer_id')->get()->toArray();
+        return array_column($id,'customer_id');
+    }
+
     //负责人
     public function customerSearch($data){
         $emp_id = Employee::where('del_time',0)
@@ -620,14 +628,20 @@ class RangeService extends Service
             list($status, $id) = self::getWaitForSportsCheck($user,$search);
 
             //待审核
+            $check = implode(",", SportsBag::$wait_check);
             $args = "(state IN (" . implode(",", SportsBag::$wait_check) ."))";
 
             if($status) {
+                $wait_for_me = $search['wait_for_me'] ?? 0;
                 $check_2 = implode(',', array_diff(SportsBag::$wait_check, [SportsBag::STATE_ONE]));
-                if(empty($id)) {
-                    $args = "(state IN (" . implode(",", SportsBag::$wait_check) .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                }else{
-                    $args = "(state IN (" . implode(",", SportsBag::$wait_check) .") and (id IN (" . implode(",", $id) .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                $id = implode(",", $id);
+
+                if($wait_for_me){
+                    if(empty($id)) {
+                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }else{
+                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }
                 }
             }
         }elseif($search['is_check'] == 2){
@@ -639,7 +653,7 @@ class RangeService extends Service
     }
 
     private static function getWaitForSportsCheck($user, $search){
-        if(empty($search['wait_for_me'])) return [false, []];
+        if(! isset($search['wait_for_me'])) return [false, []];
 
         //获取待审核
         $args = "(state = " . SportsBag::STATE_ONE . ")";
@@ -659,14 +673,19 @@ class RangeService extends Service
             list($status, $id) = self::getWaitForPaymentCheck($user,$search);
 
             //待审核
-            $args = "(state IN (" . implode(",", PaymentReceipt::$wait_check) ."))";
+            $check = implode(",", SportsBag::$wait_check);
+            $args = "(state IN (" . $check ."))";
 
             if($status) {
+                $wait_for_me = $search['wait_for_me'] ?? 0;
+                $id = implode(",", $id);
                 $check_2 = implode(',', array_diff(SportsBag::$wait_check, [PaymentReceipt::STATE_ONE]));
-                if(empty($id)) {
-                    $args = "(state IN (" . implode(",", PaymentReceipt::$wait_check) .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                }else{
-                    $args = "(state IN (" . implode(",", PaymentReceipt::$wait_check) .") and (id IN (" . implode(",", $id) .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                if($wait_for_me){
+                    if(empty($id)) {
+                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }else{
+                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }
                 }
             }
         }elseif($search['is_check'] == 2){
@@ -678,7 +697,7 @@ class RangeService extends Service
     }
 
     private static function getWaitForPaymentCheck($user, $search){
-        if(empty($search['wait_for_me'])) return [false, []];
+        if(! isset($search['wait_for_me'])) return [false, []];
 
         //获取待审核
         $args = "(state = " . PaymentReceipt::STATE_ONE . ")";
@@ -698,14 +717,20 @@ class RangeService extends Service
             list($status, $id) = self::getWaitForSalesCheck($user,$search);
 
             //待审核
-            $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . implode(",", SalesOrder::$wait_check) ."))";
+            $check = implode(",", SalesOrder::$wait_check);
+            $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . $check ."))";
 
             if($status) {
+                $wait_for_me = $search['wait_for_me'] ?? 0;
+
                 $check_2 = implode(',', array_diff(SalesOrder::$wait_check, [SalesOrder::State_one]));
-                if(empty($id)) {
-                    $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . implode(",", SalesOrder::$wait_check) .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                }else{
-                    $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . implode(",", SalesOrder::$wait_check) .") and (id IN (" . implode(",", $id) .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                $id = implode(",", $id);
+                if($wait_for_me){
+                    if(empty($id)) {
+                        $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }else{
+                        $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }
                 }
             }
         }elseif($search['is_check'] == 2){
@@ -717,7 +742,7 @@ class RangeService extends Service
     }
 
     private static function getWaitForSalesCheck($user, $search){
-        if(empty($search['wait_for_me'])) return [false, []];
+        if(! isset($search['wait_for_me'])) return [false, []];
 
         //获取待审核合同
         $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state = " . SalesOrder::State_one . ")";
@@ -737,14 +762,20 @@ class RangeService extends Service
             list($status, $id) = self::getWaitForInvoiceCheck($user,$search);
 
             //待审核
-            $args = "(state IN (" . implode(",", InvoiceOrder::$wait_check) ."))";
+            $check = implode(",", InvoiceOrder::$wait_check);
+            $args = "(state IN (" . $check ."))";
 
             if($status) {
-                $check_2 = implode(',', array_diff(SportsBag::$wait_check, [InvoiceOrder::STATE_ONE]));
-                if(empty($id)) {
-                    $args = "(state IN (" . implode(",", InvoiceOrder::$wait_check) .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                }else{
-                    $args = "(state IN (" . implode(",", InvoiceOrder::$wait_check) .") and (id IN (" . implode(",", $id) .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                $wait_for_me = $search['wait_for_me'] ?? 0;
+
+                $check_2 = implode(',', array_diff(InvoiceOrder::$wait_check, [InvoiceOrder::STATE_ONE]));
+                $id = implode(",", $id);
+                if($wait_for_me){
+                    if(empty($id)) {
+                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }else{
+                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }
                 }
             }
         }elseif($search['is_check'] == 2){
@@ -756,7 +787,7 @@ class RangeService extends Service
     }
 
     private static function getWaitForInvoiceCheck($user, $search){
-        if(empty($search['wait_for_me'])) return [false, []];
+        if(! isset($search['wait_for_me'])) return [false, []];
 
         //获取待审核数据
         $args = "(state = " . InvoiceOrder::STATE_ONE . ")";
@@ -776,14 +807,20 @@ class RangeService extends Service
             list($status, $id) = self::getWaitForReturnExchangeCheck($user,$search);
 
             //待审核
-            $args = "(state IN (" . implode(",", ReturnExchangeOrder::$wait_check) ."))";
+            $check = implode(",", ReturnExchangeOrder::$wait_check);
+            $args = "(state IN (" . $check ."))";
 
             if($status) {
-                $check_2 = implode(',', array_diff(SportsBag::$wait_check, [ReturnExchangeOrder::State_one]));
-                if(empty($id)) {
-                    $args = "(state IN (" . implode(",", ReturnExchangeOrder::$wait_check) .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                }else{
-                    $args = "(state IN (" . implode(",", ReturnExchangeOrder::$wait_check) .") and (id IN (" . implode(",", $id) .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                $wait_for_me = $search['wait_for_me'] ?? 0;
+
+                $check_2 = implode(',', array_diff(ReturnExchangeOrder::$wait_check, [ReturnExchangeOrder::State_one]));
+                $id = implode(",", $id);
+                if($wait_for_me){
+                    if(empty($id)) {
+                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }else{
+                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }
                 }
             }
         }elseif($search['is_check'] == 2){
@@ -795,7 +832,7 @@ class RangeService extends Service
     }
 
     private static function getWaitForReturnExchangeCheck($user, $search){
-        if(empty($search['wait_for_me'])) return [false, []];
+        if(! isset($search['wait_for_me'])) return [false, []];
 
         //获取待审核数据
         $args = "(state = " . ReturnExchangeOrder::State_one . ")";
@@ -815,14 +852,20 @@ class RangeService extends Service
             list($status, $id) = self::getWaitForConstructionCheck($user,$search);
 
             //待审核
-            $args = "(state IN (" . implode(",", Construction::$wait_check) ."))";
+            $check = implode(",", Construction::$wait_check);
+            $args = "(state IN (" . $check ."))";
 
             if($status) {
-                $check_2 = implode(',', array_diff(SportsBag::$wait_check, [Construction::STATE_ONE]));
-                if(empty($id)) {
-                    $args = "(state IN (" . implode(",", Construction::$wait_check) .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                }else{
-                    $args = "(state IN (" . implode(",", Construction::$wait_check) .") and (id IN (" . implode(",", $id) .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                $wait_for_me = $search['wait_for_me'] ?? 0;
+
+                $check_2 = implode(',', array_diff(Construction::$wait_check, [Construction::STATE_ONE]));
+                $id = implode(",", $id);
+                if($wait_for_me){
+                    if(empty($id)) {
+                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }else{
+                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }
                 }
             }
         }elseif($search['is_check'] == 2){
@@ -834,7 +877,7 @@ class RangeService extends Service
     }
 
     private static function getWaitForConstructionCheck($user, $search){
-        if(empty($search['wait_for_me'])) return [false, []];
+        if(! isset($search['wait_for_me'])) return [false, []];
 
         //获取待审核数据
         $args = "(state = " . Construction::STATE_ONE . ")";
@@ -854,14 +897,20 @@ class RangeService extends Service
             list($status, $id) = self::getWaitForPurchaseCheck($user,$search);
 
             //待审核
-            $args = "(state IN (" . implode(",", PurchaseOrder::$wait_check) ."))";
+            $check = implode(",", PurchaseOrder::$wait_check);
+            $args = "(state IN (" . $check ."))";
 
             if($status) {
-                $check_2 = implode(',', array_diff(SportsBag::$wait_check, [PurchaseOrder::STATE_ONE]));
-                if(empty($id)) {
-                    $args = "(state IN (" . implode(",", PurchaseOrder::$wait_check) .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                }else{
-                    $args = "(state IN (" . implode(",", PurchaseOrder::$wait_check) .") and (id IN (" . implode(",", $id) .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                $wait_for_me = $search['wait_for_me'] ?? 0;
+
+                $check_2 = implode(',', array_diff(PurchaseOrder::$wait_check, [PurchaseOrder::STATE_ONE]));
+                $id = implode(",", $id);
+                if($wait_for_me){
+                    if(empty($id)) {
+                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }else{
+                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
+                    }
                 }
             }
         }elseif($search['is_check'] == 2){
@@ -873,7 +922,7 @@ class RangeService extends Service
     }
 
     private static function getWaitForPurchaseCheck($user, $search){
-        if(empty($search['wait_for_me'])) return [false, []];
+        if(! isset($search['wait_for_me'])) return [false, []];
 
         //获取待审核数据
         $args = "(state = " . PurchaseOrder::STATE_ONE . ")";

+ 6 - 6
app/Service/ReturnExchangeOrderService.php

@@ -83,7 +83,7 @@ class ReturnExchangeOrderService extends Service
                 }
 
                 //锁定库存
-                ProductInventoryService::changeLockNumber($user, $msg[0],$msg[1]);
+//                ProductInventoryService::changeLockNumber($user, $msg[0],$msg[1]);
             }
 
             DB::commit();
@@ -171,7 +171,7 @@ class ReturnExchangeOrderService extends Service
                 }
 
                 //锁定库存
-                ProductInventoryService::changeLockNumber($user, $msg[0],[]);
+//                ProductInventoryService::changeLockNumber($user, $msg[0],[]);
             }
 
             DB::commit();
@@ -280,7 +280,7 @@ class ReturnExchangeOrderService extends Service
                 'del_time'=>time()
             ]);
             //锁定库存
-            ProductInventoryService::changeLockNumber($user, [], $product_save_minus);
+//            ProductInventoryService::changeLockNumber($user, [], $product_save_minus);
 
             (new RangeService())->RangeDelete($data['id'],SeeRange::type_six);
 
@@ -596,9 +596,9 @@ class ReturnExchangeOrderService extends Service
                 //是否校验库存
                 ProductInventoryService::is_check($user,$data);
 
-                $product_save_minus = $this->getSaveDetailMinus($id);
-                list($status,$msg) = (new ProductInventoryService())->compareStock($user,$product_id, $product_submit_minus, $product_save_minus);
-                if(! $status) return [false, $msg];
+//                $product_save_minus = $this->getSaveDetailMinus($id);
+//                list($status,$msg) = (new ProductInventoryService())->compareStock($user,$product_id, $product_submit_minus, $product_save_minus);
+//                if(! $status) return [false, $msg];
             }
         }
 

+ 115 - 2
app/Service/SalesOrderService.php

@@ -764,7 +764,7 @@ class SalesOrderService extends Service
     public function salesOrderCommon($data,$user){
         $model = SalesOrder::Clear($user,$data);
         $model = $model->where('del_time',0)
-            ->select('id','sales_order_type','model_type','order_number','selling_price','vin_no','car_type','order_type','customer_id','sign_time','crt_id','crt_time','mark','product_total','rate','construction_time','handover_time','other_fee','discount_fee','contract_fee','pay_way','car_type','year','mileage','color','original_set','processing','state','invoice_state','plat_type','plat_order','install_method','install_position','customer_contact','is_confirm','dispatch_time_second','contact_order_no','type');
+            ->select('id','sales_order_type','model_type','order_number','selling_price','vin_no','car_type','order_type','customer_id','sign_time','crt_id','crt_time','mark','product_total','rate','construction_time','handover_time','other_fee','discount_fee','contract_fee','pay_way','car_type','year','mileage','color','original_set','processing','state','invoice_state','plat_type','plat_order','install_method','install_position','customer_contact','is_confirm','dispatch_time_second','contact_order_no','type','top_depart_id');
 
         if(! empty($data['order_list'])){
             if($data['order_list'] == 1){
@@ -781,15 +781,30 @@ class SalesOrderService extends Service
         }else{
             $model = $model->orderby('id', 'desc');
         }
+        $is_dispatch = -1;
         if(isset($data['is_dispatch'])) {
             if($data['is_dispatch'] == 0){
                 //订单合同 安装件合同 状态未指派总社分社的 或者 快递件合同
                 $model->where('dispatch_time_second', 0);
+                $is_dispatch = 0;
             }else{
                 //派单合同 安装件合同 状态已指派总社分社的
                 $model->where('dispatch_time_second', '>', 0);
+                $is_dispatch = 1;
             }
         }
+        if(! empty($data['belong_top_depart_title'])){
+            list($id, $depart_id) = $this->searchSalesDepart($data['belong_top_depart_title']);
+            if($is_dispatch < 0){
+                $model->whereIn('id', $id)
+                    ->orWhereIn('top_depart_id', $depart_id);
+            }elseif ($is_dispatch > 0){
+                $model->whereIn('id', $id);
+            }else{
+                $model->where('top_depart_id', $depart_id);
+            }
+        }
+
         if(! empty($data['order_number'])) $model->where('order_number','LIKE', '%'.$data['order_number'].'%');
         if(! empty($data['sales_order_type'])) $model->where('sales_order_type',$data['sales_order_type']);
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
@@ -898,6 +913,29 @@ class SalesOrderService extends Service
         return $model;
     }
 
+    //门店搜索
+    public function searchSalesDepart($depart_title = ""){
+        $sales_id = [];
+        if(empty($depart_title)) return $sales_id;
+
+        $depart_id = Depart::where('del_time', 0)
+            ->where('parent_id', 0)
+            ->where('title', 'LIKE', '%'. $depart_title .'%')
+            ->select('id')->get()->toArray();
+        $depart_id = array_column($depart_id, 'id');
+        if(empty($depart_id)) return [$sales_id, $depart_id];
+
+        $sales_id = SeeRange::where('del_time',0)
+            ->whereIn('param_id', $depart_id)
+            ->where('data_type',SeeRange::type_seven)
+            ->where('type',SeeRange::data_three)
+            ->select('data_id as sale_id')
+            ->get()->toArray();
+        $sales_id = array_column($sales_id, 'sale_id');
+
+        return [$sales_id, $depart_id];
+    }
+
     /**
      * 订单列表
      * @param $data
@@ -953,6 +991,62 @@ class SalesOrderService extends Service
         }
     }
 
+    public function salesOrderClose($data,$user){
+        if(empty($data['id'])) return [false, '请选择合同'];
+        $sale_order = SalesOrder::where('id',$data['id'])
+            ->where('del_time',0)
+            ->first();
+        if(empty($sale_order)) return [false, '合同不存在或已被删除'];
+        $sale_order = $sale_order->toArray();
+        if($sale_order['model_type'] != SalesOrder::Model_type_four) return [false, '非线上订单'];
+
+        $bool = ReturnExchangeOrder::where('del_time',0)
+            ->where('data_id', $sale_order['id'])
+            ->where('type',ReturnExchangeOrder::Order_type)
+            ->exists();
+        if($bool) return [false, '合同已存在退换货单'];
+
+        $bool = PaymentReceipt::where('del_time',0)
+            ->where('data_order_no', $sale_order['order_number'])
+            ->where('data_type',PaymentReceipt::data_type_one)
+            ->exists();
+        if($bool) return [false, '合同已存在收付款单'];
+
+        $bool = PurchaseOrder::where('del_time',0)
+            ->where('sales_order_id', $sale_order['id'])
+            ->exists();
+        if($bool) return [false, '合同已存在采购订单'];
+
+        $bool = Construction::where('del_time',0)
+            ->where('sales_order_id', $sale_order['id'])
+            ->exists();
+        if($bool) return [false, '合同已存在施工单'];
+
+        try {
+            DB::beginTransaction();
+            $del_time = 1234;
+            SalesOrder::where('id', $data['id'])
+                ->update(['del_time' => $del_time]);
+
+            SalesOrderInfo::where('del_time',0)
+                ->where('sales_order_id',$data['id'])
+                ->update(['del_time' => $del_time]);
+            SalesOrderProductInfo::where('del_time',0)
+                ->where('sales_order_id',$data['id'])
+                ->update(['del_time' => $del_time]);
+            SalesOrderOtherFee::where('del_time',0)
+                ->where('sales_order_id',$data['id'])
+                ->update(['del_time' => $del_time]);
+            (new RangeService())->RangeDelete($data['id'],SeeRange::type_seven);
+            DB::commit();
+        }catch (\Throwable $exception){
+            DB::rollBack();
+            return [false, $exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
     /**
      * 订单参数规则
      * @param $data
@@ -1159,6 +1253,8 @@ class SalesOrderService extends Service
         $customer_id = array_column($data['data'],'customer_id');
         $customer_map = $this->getCustomer($customer_id);
 
+        $array2 = array_unique(array_column($data['data'],'top_depart_id'));
+        $depart = Depart::whereIn('id',$array2)->pluck('title','id')->toArray();
         foreach ($data['data'] as $key => $value){
             $data['data'][$key]['construction_model_type'] = SalesOrder::$build_for_con[$value['type']] ?? 1;
             $data['data'][$key]['type_title'] = SalesOrder::$build_state[$value['type']] ?? '';
@@ -1195,6 +1291,13 @@ class SalesOrderService extends Service
             $data['data'][$key]['invoice_arr'] = implode(',', $tmp);
             $dispatch_company = $dispatch[$value['id']] ?? '';
             $data['data'][$key]['dispatch_company'] = $dispatch_company;
+            if($value['dispatch_time_second'] > 0) {
+                //分配过所属门店是分配门店
+                $data['data'][$key]['belong_top_depart_title'] = $dispatch_company;
+            }else{
+                //没分配过所属门店是创建门店
+                $data['data'][$key]['belong_top_depart_title'] = $depart[$value['top_depart_id']] ?? "";
+            }
             $data['data'][$key]['u8_message'] = $u8[$value['id']] ?? '';
             $data['data'][$key]['construction_no'] = $construction_array[$value['id']] ?? '';
             if($value['is_confirm']){
@@ -1595,7 +1698,7 @@ class SalesOrderService extends Service
 
     public function salesOrderListsalesOrderWxList($data,$user){
         $model = SalesOrder::where('del_time',0)
-            ->select('id','sales_order_type','model_type','order_number','selling_price','vin_no','car_type','order_type','customer_id','sign_time','crt_id','crt_time','mark','product_total','rate','construction_time','handover_time','other_fee','discount_fee','contract_fee','pay_way','car_type','year','mileage','color','original_set','processing','state','invoice_state','plat_type','plat_order','install_method','install_position','customer_contact','is_confirm','dispatch_time_second','contact_order_no','type')
+            ->select('id','sales_order_type','model_type','order_number','selling_price','vin_no','car_type','order_type','customer_id','sign_time','crt_id','crt_time','mark','product_total','rate','construction_time','handover_time','other_fee','discount_fee','contract_fee','pay_way','car_type','year','mileage','color','original_set','processing','state','invoice_state','plat_type','plat_order','install_method','install_position','customer_contact','is_confirm','dispatch_time_second','contact_order_no','type','top_depart_id')
             ->orderby('id', 'desc')
             ->orderby('dispatch_time_second','desc');
 
@@ -2093,4 +2196,14 @@ class SalesOrderService extends Service
 
         return [true, array_values($return)];
     }
+
+    public function saveOutData($data, $user){
+        if(empty($data['id'])) return [false, '合同ID不能为空'];
+        if(empty($data['type'])) return [false, '出库类型不能为空'];
+
+        SalesOrder::where('del_time',0)
+            ->where('id',$data['id'])
+            ->first();
+
+    }
 }

+ 47 - 0
app/Service/TableHeadService.php

@@ -2,6 +2,9 @@
 
 namespace App\Service;
 
+use App\Model\BasicType;
+use App\Model\ProductPriceDetail;
+use App\Model\RoleMenuButton;
 use App\Model\TableSetting;
 use Illuminate\Support\Facades\DB;
 
@@ -63,6 +66,8 @@ class TableHeadService extends Service
         $header_map = array_column($header,null,'key');
 
         $header_default = config("header.{$data['menu_id']}") ?? [];
+        $this->fillHeader($data['menu_id'], $user, $header_default);
+
         foreach ($header_default as $key => $value){
             if(isset($header_map[$value['key']])) {
                 //存在保存好的设置的表头 以下信息沿用
@@ -96,6 +101,48 @@ class TableHeadService extends Service
         return [true, $header_default];
     }
 
+    private function fillHeader($menu_id = 0,$user, &$header_default){
+        if($menu_id == 17){
+            $data['top_depart_id'] = $user['head']['id'] ?? 0;
+            $model = BasicType::TopClear($user,$data);
+            $basic = $model->where('del_time',0)
+                ->where('type',22)
+                ->select('title','id','type')
+                ->orderby('id', 'asc')
+                ->get()->toArray();
+            $title_map = BasicType::whereIn('id',array_column($basic,'id'))
+                ->pluck('title','id')
+                ->toArray();
+            $top_depart = $user['depart_top'][0] ?? [];
+
+            //特殊功能按钮
+            $special_button = $user['special_button'] ?? [];
+
+            //所有金额
+            foreach ($basic as $value){
+                $show = 0;
+                if(in_array(RoleMenuButton::special_one,$special_button)){
+                    $show = 1;
+                }else{
+                    if($top_depart['basic_type_id'] == $value['id']) $show = 1;
+                }
+                if($show){
+                    $header_default[] = [
+                        'key' => $value['id'],
+                        'value' => $title_map[$value['id']] ?? '',
+                    ];
+                }
+            }
+
+            if(in_array(RoleMenuButton::special_two,$special_button)) {
+                $header_default[] = [
+                    'key' => 'cost_show',
+                    'value' => "成本",
+                ];
+            }
+        }
+    }
+
     public function filterAdd($data, $user){
         if(! isset($data['is_filter'])) return [false,'是否打开筛选不能为空'];
         if(empty($data['menu_id'])) return [false, 'menu_id不能为空'];

+ 1 - 1
config/excel/customerTable.php

@@ -62,7 +62,7 @@ return [
     ],
     [
         'key' =>'enter_time',
-        'value' => '录入时间',
+        'value' => '创建时间',
     ],
 //    [
 //        'key' =>'man_xt',

+ 8 - 0
config/header/16.php

@@ -70,4 +70,12 @@ return [
         'key' => 'crt_name',
         'value' => '创建人',
     ],
+    [
+        'key' => 'is_dispatch_title',
+        'value' => '分配情况',
+    ],
+    [
+        'key' => 'belong_top_depart_title',
+        'value' => '所属门店',
+    ],
 ];

+ 0 - 4
config/header/17.php

@@ -39,10 +39,6 @@ return [
         'value' => '单位',
     ],
     [
-        'key' => 'cost_show',
-        'value' => '成本',
-    ],
-    [
         'key' => 'retail_price',
         'value' => '零售价',
     ],

+ 8 - 0
config/header/37.php

@@ -110,6 +110,14 @@ return [
         'key' => 'construction_no',
         'value' => '施工单',
     ],
+    [
+        'key' => 'is_dispatch_title',
+        'value' => '是否派单',
+    ],
+    [
+        'key' => 'belong_top_depart_title',
+        'value' => '所属门店',
+    ],
 //    [
 //        'key' => 'pay_way_title',
 //        'value' => '付款方式',

+ 1 - 0
routes/api.php

@@ -206,6 +206,7 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('salesOrderDispatchCompany', 'Api\SalesOrderController@salesOrderDispatchCompany');
     $route->any('salesOrderBatchDispatchCompany', 'Api\SalesOrderController@salesOrderBatchDispatchCompany');
     $route->any('salesOrderGetBuildFee', 'Api\SalesOrderController@salesOrderGetBuildFee');
+    $route->any('salesOrderClose', 'Api\SalesOrderController@salesOrderClose');
 
     //施工单
     $route->any('constructionGet', 'Api\ConstructionController@constructionGet');