gorden 8 luni în urmă
părinte
comite
065863749a

+ 6 - 0
app/admin/controller/goods/ServiceGoodsController.php

@@ -4,6 +4,7 @@ namespace app\admin\controller\goods;
 
 use app\admin\service\goods\GoodsService;
 use app\admin\validate\goods\GoodsValidate;
+use app\model\Goods;
 use support\Request;
 use support\Response;
 
@@ -27,6 +28,11 @@ class ServiceGoodsController
         return GoodsService::selectList($request, 'SERVICE');
     }
 
+    public function selectCascaderList(Request $request)
+    {
+        return GoodsService::selectCascaderList($request);
+    }
+
     public function selectPicking(Request $request)
     {
         return GoodsService::selectPicking($request);

+ 184 - 105
app/admin/service/goods/GoodsService.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\service\goods;
 
+use app\common\Tree;
 use app\model\Appointment;
 use app\model\Goods;
 use app\model\GoodsComponent;
@@ -42,7 +43,7 @@ class GoodsService
             ->when($goodsName != '', function ($query) use ($goodsName) {
                 $query->where('goods_name', 'like', "%" . $goodsName . '%');
             })
-            ->select('goods_id', 'goods_name','goods_classify')
+            ->select('goods_id', 'goods_name', 'goods_classify')
             ->get()
             ->toArray();
         foreach ($goods as &$item) {
@@ -82,7 +83,7 @@ class GoodsService
                 $item['category_super_path'] = $item['category_super_path'] . '#' . $item['category_id'] . '#';
             }
 
-            $categoryIds = SysCategory::where('category_super_path', 'like', '%' . $item['category_super_path'].'%')->pluck('category_id');
+            $categoryIds = SysCategory::where('category_super_path', 'like', '%' . $item['category_super_path'] . '%')->pluck('category_id');
             $categoryIds = $categoryIds ? $categoryIds->toArray() : [];
             $categorySuperIds = array_merge($categorySuperIds, $categoryIds);
         }
@@ -94,8 +95,8 @@ class GoodsService
             ->when(!empty($categoryIds), function ($query) use ($categoryIds) {
                 $query->whereIn('join_goods_category_id', $categoryIds);
             })->when(empty($categoryIds), function ($query) {
-                $query->where('goods_classify','<>', 'RECHARGE');
-            })->where('goods_status','ON')
+                $query->where('goods_classify', '<>', 'RECHARGE');
+            })->where('goods_status', 'ON')
             ->select('goods_id', 'goods_name', 'join_goods_category_id')
             ->get()
             ->toArray();
@@ -174,10 +175,10 @@ class GoodsService
             'supplier' => function ($query) {
                 $query->select('supplier_id', 'supplier_name');
             },
-            'user'=>function($query){
+            'user' => function ($query) {
                 $query->select('user_id', 'user_name');
             }
-        ])->select('goods_id', 'join_goods_category_id', 'join_goods_supplier_id','creator_user_id', 'goods_status', 'goods_sales_price', 'goods_category', 'goods_name', 'goods_title', 'goods_cover', 'goods_sort', 'goods_attribute_json', 'goods_addtimes','goods_updatetimes')
+        ])->select('goods_id', 'join_goods_category_id', 'join_goods_supplier_id', 'creator_user_id', 'goods_status', 'goods_sales_price', 'goods_category', 'goods_name', 'goods_title', 'goods_cover', 'goods_sort', 'goods_attribute_json', 'goods_addtimes', 'goods_updatetimes')
             ->when($goodsName != '', function ($query) use ($goodsName) {
                 $query->where(function ($q) use ($goodsName) {
                     $q->where('goods_name', 'like', '%' . $goodsName . '%')
@@ -188,10 +189,10 @@ class GoodsService
             })->when($goodsCategory != null, function ($query) use ($goodsCategory) {
                 $query->where('goods_category', $goodsCategory);
             })
-            ->when($classify != '', function ($query) use ($classify,$categoryId) {
+            ->when($classify != '', function ($query) use ($classify, $categoryId) {
                 if ($classify == 'GOODS' && empty($categoryId)) {
                     $query->whereIn('join_goods_category_id', ['6', '7', '8', '9', '10', '11', '12', '30']);
-                } else if($classify != 'GOODS' && empty($categoryId)) {
+                } else if ($classify != 'GOODS' && empty($categoryId)) {
                     $query->where('goods_classify', $classify);
                 }
             })
@@ -210,10 +211,10 @@ class GoodsService
             $query->whereIn('join_goods_category_id', $categoryId);
         })->when($goodsCategory != null, function ($query) use ($goodsCategory) {
             $query->where('goods_category', $goodsCategory);
-        })->when($classify != '', function ($query) use ($classify,$categoryId) {
+        })->when($classify != '', function ($query) use ($classify, $categoryId) {
             if ($classify == 'GOODS' && empty($categoryId)) {
                 $query->whereIn('join_goods_category_id', ['6', '7', '8', '9', '10', '11', '12', '30']);
-            } else if($classify != 'GOODS' && empty($categoryId)) {
+            } else if ($classify != 'GOODS' && empty($categoryId)) {
                 $query->where('goods_classify', $classify);
             }
         })
@@ -227,7 +228,7 @@ class GoodsService
             if (!empty($row['goods_attribute_json'])) {
                 $row['goods_attribute_json'] = json_decode($row['goods_attribute_json']);
             }
-            if (!empty($row['goods_category']) && $row['goods_category'] == 'INDEX'){
+            if (!empty($row['goods_category']) && $row['goods_category'] == 'INDEX') {
                 $row['goods_recommend_index'] = 'INDEX';
             }
         }
@@ -257,10 +258,10 @@ class GoodsService
             'supplier' => function ($query) {
                 $query->select('supplier_id', 'supplier_name');
             },
-            'user'=>function($query){
+            'user' => function ($query) {
                 $query->select('user_id', 'user_name');
             }
-        ])->select('goods_id', 'join_goods_category_id', 'join_goods_supplier_id','creator_user_id', 'goods_status', 'goods_sales_price', 'goods_category', 'goods_name', 'goods_title', 'goods_cover', 'goods_sort', 'goods_addtimes','goods_updatetimes')
+        ])->select('goods_id', 'join_goods_category_id', 'join_goods_supplier_id', 'creator_user_id', 'goods_status', 'goods_sales_price', 'goods_category', 'goods_name', 'goods_title', 'goods_cover', 'goods_sort', 'goods_addtimes', 'goods_updatetimes')
             ->when($goodsName != '', function ($query) use ($goodsName) {
                 $query->where(function ($q) use ($goodsName) {
                     $q->where('goods_name', 'like', '%' . $goodsName . '%')
@@ -321,10 +322,10 @@ class GoodsService
             'supplier' => function ($query) {
                 $query->select('supplier_id', 'supplier_name');
             },
-            'user'=>function($query){
+            'user' => function ($query) {
                 $query->select('user_id', 'user_name');
             }
-        ])->select('goods_id', 'join_goods_category_id', 'join_goods_supplier_id','creator_user_id', 'goods_status', 'goods_sales_price', 'goods_category', 'goods_name', 'goods_title', 'goods_cover', 'goods_sort', 'goods_addtimes','goods_updatetimes')
+        ])->select('goods_id', 'join_goods_category_id', 'join_goods_supplier_id', 'creator_user_id', 'goods_status', 'goods_sales_price', 'goods_category', 'goods_name', 'goods_title', 'goods_cover', 'goods_sort', 'goods_addtimes', 'goods_updatetimes')
             ->when($goodsName != '', function ($query) use ($goodsName) {
                 $query->where(function ($q) use ($goodsName) {
                     $q->where('goods_name', 'like', '%' . $goodsName . '%')
@@ -371,10 +372,10 @@ class GoodsService
             'supplier' => function ($query) {
                 $query->select('supplier_id', 'supplier_name');
             },
-            'user'=>function($query){
+            'user' => function ($query) {
                 $query->select('user_id', 'user_name');
             }
-        ])->select('goods_id', 'join_goods_category_id', 'join_goods_supplier_id','creator_user_id', 'goods_status', 'goods_sales_price', 'goods_category', 'goods_name', 'goods_title', 'goods_cover', 'goods_sort', 'goods_addtimes','goods_updatetimes')
+        ])->select('goods_id', 'join_goods_category_id', 'join_goods_supplier_id', 'creator_user_id', 'goods_status', 'goods_sales_price', 'goods_category', 'goods_name', 'goods_title', 'goods_cover', 'goods_sort', 'goods_addtimes', 'goods_updatetimes')
             ->when($goodsName != '', function ($query) use ($goodsName) {
                 $query->where(function ($q) use ($goodsName) {
                     $q->where('goods_name', 'like', '%' . $goodsName . '%')
@@ -448,14 +449,14 @@ class GoodsService
                 $query->where('goods_name', 'like', "%" . $keywords . "%");
             })
             ->when($goodsClassify != '', function ($query) use ($goodsClassify) {
-                if($goodsClassify == 'NOPACKAGE'){
-                    $query->where('goods_classify','<>', 'PACKAGE');
-                }else if($goodsClassify == 'SERVICE'){
-                    $query->whereIn('goods_classify', ['SERVICE','CHNMED','CHNNCD']);
-                }else{
+                if ($goodsClassify == 'NOPACKAGE') {
+                    $query->where('goods_classify', '<>', 'PACKAGE');
+                } else if ($goodsClassify == 'SERVICE') {
+                    $query->whereIn('goods_classify', ['SERVICE', 'CHNMED', 'CHNNCD']);
+                } else {
                     $query->where('goods_classify', $goodsClassify);
                 }
-                
+
             })
             ->when($isSupportAppointment != '', function ($query) use ($isSupportAppointment) {
                 $query->where('is_support_appointment', $isSupportAppointment);
@@ -502,6 +503,84 @@ class GoodsService
 
     }
 
+    public static function selectCascaderList(Request $request)
+    {
+        $categoryIds = $request->get('category_id','');
+        if (!$categoryIds){
+            return json_fail('参数异常');
+        }
+        $data = [];
+        $categorys = SysCategory::whereIn('category_id',$categoryIds)
+            ->where('category_status','ACTIVED')
+            ->select('category_id as id','category_name as name','category_super_id as pid','category_super_path')
+            ->orderBy('category_sort','DESC')
+            ->get()
+            ->toArray();
+        $data = array_merge($data,$categorys);
+
+        foreach ($categorys as $category){
+            if(empty($category['category_super_path'])){
+                $category['category_super_path'] = '#'.$category['id'].'#';
+            }
+            $subCategory = SysCategory::where('category_super_path','like','%'.$category['category_super_path'].'%')
+                ->where('category_status','ACTIVED')
+                ->select('category_id as id','category_name as name','category_super_id as pid','category_super_path')
+                ->orderBy('category_sort','DESC')
+                ->get()
+                ->toArray();
+            $data = array_merge($data,$subCategory);
+        }
+
+        $goodsCategoryIds = array_column($data,'id');
+        $goods = Goods::with('sku')
+            ->whereIn('join_goods_category_id',$goodsCategoryIds)
+            ->where('goods_status','ON')
+            ->select('goods_id','goods_id as id','goods_name as name','join_goods_category_id as pid','goods_attribute_json')
+            ->orderBy('goods_sort','DESC')
+            ->orderBy('goods_addtimes','DESC')
+            ->get()
+            ->toArray();
+        foreach ($goods as &$good) {
+            if (!empty($good['sku'])) {
+                foreach ($good['sku'] as $key => $sku) {
+                    if (!empty($sku['goods_sku_specs_json'])) {
+                        $good['sku'][$key]['goods_sku_specs_json'] = json_decode($sku['goods_sku_specs_json']);
+
+                        $skuName = '';
+                        foreach ($good['sku'][$key]['goods_sku_specs_json'] as $specsKey => $skuSpecs) {
+                            if (is_array($skuSpecs)) {
+                                $skuName = $skuName . ' ' . implode(' ', $skuSpecs) . ';';
+                            } else {
+                                $skuName = $skuName . ' ' . $skuSpecs . ';';
+                            }
+                        }
+                        $good['sku'][$key]['sku_name'] = $skuName;
+                    }
+                }
+            } else {
+                $good['sku'] = [];
+            }
+            $good['premisses'] = [];
+            if (!empty($good['goods_attribute_json'])) {
+                $attributeJson = json_decode($good['goods_attribute_json'], true);
+                if (isset($attributeJson['premisses'])) {
+                    $premisses = SysDept::when(!empty($attributeJson['premisses']), function ($query) use ($attributeJson) {
+                        $query->whereIn('dept_id', $attributeJson['premisses']);
+                    })->where('dept_category', '营业场所')
+                        ->select('dept_id', 'dept_name')
+                        ->get();
+                    $good['premisses'] = $premisses;
+                }
+            }
+        }
+
+        $data = array_merge($data,$goods);
+        
+        $tree = new Tree($data);
+
+        return json_success('success', $tree->getTree());
+    }
+
     /**
      * @Desc 商品详情
      * @Author Gorden
@@ -600,14 +679,14 @@ class GoodsService
             $data['goods_label'] = !empty($data['goods_label']) ? explode(',', $data['goods_label']) : [];
             $data['goods_json'] = $data['goods_json'] ? json_decode($data['goods_json'], true) : [];
             $data['goods_cover'] = getenv('STORAGE_DOMAIN') . $data['goods_cover'];
-            if(!empty($data['goods_category']) && $data['goods_category'] == 'INDEX'){
+            if (!empty($data['goods_category']) && $data['goods_category'] == 'INDEX') {
                 $data['goods_recommend_index'] = 'INDEX';
             }
 
             // 创建者
             $data['creator_username'] = '';
-            if (!empty($data['creator_user_id'])){
-                $data['creator_username'] = SysUser::where('user_id',$data['creator_user_id'])->value('user_name');
+            if (!empty($data['creator_user_id'])) {
+                $data['creator_username'] = SysUser::where('user_id', $data['creator_user_id'])->value('user_name');
             }
 
             if (!empty($data['goods_detail_slider_json'])) {
@@ -637,21 +716,21 @@ class GoodsService
                 if (isset($extendJson['icon'])) {
                     $data['goods_theme_icon'] = getenv('STORAGE_DOMAIN') . $extendJson['icon'];
                 }
-                if (isset($extendJson['service_premises_id'])){
+                if (isset($extendJson['service_premises_id'])) {
                     $data['goods_service_premises'] = $extendJson['service_premises_id'];
                 }
             }
 
             $data['express_json'] = [];
-            if(!empty($data['goods_express_json'])){
-                $goodsExpressJson = json_decode($data['goods_express_json'],true);
-                if(isset($goodsExpressJson['express']) && $goodsExpressJson['express'] ==  'Y'){
+            if (!empty($data['goods_express_json'])) {
+                $goodsExpressJson = json_decode($data['goods_express_json'], true);
+                if (isset($goodsExpressJson['express']) && $goodsExpressJson['express'] == 'Y') {
                     $data['express_json'][] = 'express';
                 }
-                if(isset($goodsExpressJson['self']) && $goodsExpressJson['self'] ==  'Y'){
+                if (isset($goodsExpressJson['self']) && $goodsExpressJson['self'] == 'Y') {
                     $data['express_json'][] = 'self';
                 }
-                if(isset($goodsExpressJson['arrival']) && $goodsExpressJson['arrival'] ==  'Y'){
+                if (isset($goodsExpressJson['arrival']) && $goodsExpressJson['arrival'] == 'Y') {
                     $data['express_json'][] = 'arrival';
                 }
             }
@@ -674,12 +753,12 @@ class GoodsService
 
                     $data['appointment_times'] = $times;
                 }
-                if (isset($extendJson['time'])){
-                    $extendJsonTime = explode('至',$extendJson['time']);
-                    if(isset($extendJsonTime[0]) && isset($extendJsonTime[1])){
+                if (isset($extendJson['time'])) {
+                    $extendJsonTime = explode('至', $extendJson['time']);
+                    if (isset($extendJsonTime[0]) && isset($extendJsonTime[1])) {
                         $data['work_time'] = [
-                            date('Y-m-d H:i:s',strtotime(date('Y-m-d ').$extendJsonTime[0])),
-                            date('Y-m-d H:i:s',strtotime(date('Y-m-d ').$extendJsonTime[1])),
+                            date('Y-m-d H:i:s', strtotime(date('Y-m-d ') . $extendJsonTime[0])),
+                            date('Y-m-d H:i:s', strtotime(date('Y-m-d ') . $extendJsonTime[1])),
                         ];
                     }
                 }
@@ -700,13 +779,13 @@ class GoodsService
                 }
 
             }
-            if (isset($extendJson['month']) && $data['is_support_appointment'] == 'Y'){
+            if (isset($extendJson['month']) && $data['is_support_appointment'] == 'Y') {
                 $times = [];
-                foreach ($extendJson['month'] as $monKey => $months){
-                    foreach ($months as $day =>  $person){
+                foreach ($extendJson['month'] as $monKey => $months) {
+                    foreach ($months as $day => $person) {
                         $times[] = [
-                            'days'=>date('Y-m-d',strtotime($monKey.$day)),
-                            'person'=>$person
+                            'days' => date('Y-m-d', strtotime($monKey . $day)),
+                            'person' => $person
                         ];
                     }
                 }
@@ -740,13 +819,13 @@ class GoodsService
                 }
                 $data['goods_json'] = $goodsJsonNew;
             }
-            if (isset($extendJson['teachers'])){
+            if (isset($extendJson['teachers'])) {
                 $data['teachers'] = $extendJson['teachers'];
             }
             if (isset($extendJson['address'])) {
                 $data['address'] = $extendJson['address'];
             }
-            if (isset($extendJson['min-count'])){
+            if (isset($extendJson['min-count'])) {
                 $data['min_count'] = $extendJson['min-count'];
             }
             if (isset($extendJson['position'])) {
@@ -756,14 +835,14 @@ class GoodsService
             $data['goods_on_addtimes'] = date('Y-m-d\TH:i:s.u\Z', $data['goods_on_addtimes'] - 60 * 60 * 8);
 
             // 详情表数据
-            if (!empty($data['goods_detail_specs_json'])){
-                $specsJson = json_decode($data['goods_detail_specs_json'],true);
-                foreach($specsJson as $itemSpecsJson){
-                    if (isset($itemSpecsJson['key']) && $itemSpecsJson['key'] == '课时'){
+            if (!empty($data['goods_detail_specs_json'])) {
+                $specsJson = json_decode($data['goods_detail_specs_json'], true);
+                foreach ($specsJson as $itemSpecsJson) {
+                    if (isset($itemSpecsJson['key']) && $itemSpecsJson['key'] == '课时') {
                         $data['curriculum']['period'] = $itemSpecsJson['val'];
-                    }elseif (isset($itemSpecsJson['key']) && $itemSpecsJson['key'] == '群体'){
+                    } elseif (isset($itemSpecsJson['key']) && $itemSpecsJson['key'] == '群体') {
                         $data['curriculum']['group'] = $itemSpecsJson['val'];
-                    }elseif (isset($itemSpecsJson['key']) && $itemSpecsJson['key'] == '课程'){
+                    } elseif (isset($itemSpecsJson['key']) && $itemSpecsJson['key'] == '课程') {
                         $data['curriculum']['course'] = $itemSpecsJson['val'];
                     }
                 }
@@ -1168,16 +1247,16 @@ class GoodsService
         }
 
         // 是否在套包里
-        if (GoodsComponent::whereIn('join_component_goods_id',$ids)->exists()){
+        if (GoodsComponent::whereIn('join_component_goods_id', $ids)->exists()) {
             return json_fail("当前商品存在于套包中,请先在套包中删除");
         }
         // 是否已被购买过
-        if (OrderSheet::whereIn('join_sheet_goods_id',$ids)->exists()){
+        if (OrderSheet::whereIn('join_sheet_goods_id', $ids)->exists()) {
             return json_fail("当前商品已有购买历史,如不在APP显示,请选择【下架】操作");
         }
         // 是否预约过
-        if (Appointment::whereIn('join_appointment_goods_id',$ids)->exists()){
-            
+        if (Appointment::whereIn('join_appointment_goods_id', $ids)->exists()) {
+
             return json_fail("当前商品已有预约历史,如不在APP显示,请选择【下架】操作");
         }
 
@@ -1257,20 +1336,20 @@ class GoodsService
             $model->goods_updatetimes = time();
             // {"express":"Y","self":"Y","arrival":"Y"}
             $expressJson = [];
-            if (!empty($params['express_json'])){
-                if(in_array('express',$params['express_json'])){
+            if (!empty($params['express_json'])) {
+                if (in_array('express', $params['express_json'])) {
                     $expressJson['express'] = 'Y';
-                }else{
+                } else {
                     $expressJson['express'] = 'N';
                 }
-                if (in_array('self',$params['express_json'])){
+                if (in_array('self', $params['express_json'])) {
                     $expressJson['self'] = 'Y';
-                }else{
+                } else {
                     $expressJson['self'] = 'N';
                 }
-                if (in_array('arrival',$params['express_json'])){
+                if (in_array('arrival', $params['express_json'])) {
                     $expressJson['arrival'] = 'Y';
-                }else{
+                } else {
                     $expressJson['arrival'] = 'N';
                 }
 
@@ -1309,7 +1388,7 @@ class GoodsService
                 } else if (self::$week[$lastDate] - self::$week[$currentDate] + 1 == count($newDates)) {
                     $attributeJsonDate = $currentDate . '至' . $lastDate;
                 }
-            
+
                 // if (isset($params['work_time'])){
                 //     $workTimeStart = date('H:i',strtotime($params['work_time'][0]));
                 //     $workTimeEnd = date('H:i',strtotime($params['work_time'][1]));
@@ -1450,7 +1529,7 @@ class GoodsService
                 $attributeJson['address'] = $params['address'];
                 $model->goods_attribute_json = json_encode($attributeJson);
             }
-            if (!empty($params['position'])){
+            if (!empty($params['position'])) {
                 if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
                     $attributeJson = json_decode($model->goods_attribute_json, true);
                 } elseif (empty($model->goods_attribute_json)) {
@@ -1459,7 +1538,7 @@ class GoodsService
                 $attributeJson['position'] = $params['position'];
                 $model->goods_attribute_json = json_encode($attributeJson);
             }
-            if (isset($params['goods_service_premises'])){
+            if (isset($params['goods_service_premises'])) {
                 if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
                     $attributeJson = json_decode($model->goods_attribute_json, true);
                 } elseif (empty($model->goods_attribute_json)) {
@@ -1468,7 +1547,7 @@ class GoodsService
                 $attributeJson['service_premises_id'] = $params['goods_service_premises'];
                 $model->goods_attribute_json = json_encode($attributeJson);
             }
-            if (isset($params['min_count'])){
+            if (isset($params['min_count'])) {
                 if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
                     $attributeJson = json_decode($model->goods_attribute_json, true);
                 } elseif (empty($model->goods_attribute_json)) {
@@ -1477,7 +1556,7 @@ class GoodsService
                 $attributeJson['min-count'] = $params['min_count'];
                 $model->goods_attribute_json = json_encode($attributeJson);
             }
-            if (isset($params['teachers'])){
+            if (isset($params['teachers'])) {
                 if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
                     $attributeJson = json_decode($model->goods_attribute_json, true);
                 } elseif (empty($model->goods_attribute_json)) {
@@ -1486,17 +1565,17 @@ class GoodsService
                 $attributeJson['teachers'] = $params['teachers'];
                 $model->goods_attribute_json = json_encode($attributeJson);
             }
-            if (isset($params['work_time'])){
+            if (isset($params['work_time'])) {
                 if (!empty($model->goods_attribute_json) && !is_array($model->goods_attribute_json)) {
                     $attributeJson = json_decode($model->goods_attribute_json, true);
                 } elseif (empty($model->goods_attribute_json)) {
                     $attributeJson = [];
                 }
 
-                $workTimeStart = date('H:i',strtotime($params['work_time'][0]));
-                $workTimeEnd = date('H:i',strtotime($params['work_time'][1]));
-                $attributeJsonTime = $workTimeStart.'至'.$workTimeEnd;
-                
+                $workTimeStart = date('H:i', strtotime($params['work_time'][0]));
+                $workTimeEnd = date('H:i', strtotime($params['work_time'][1]));
+                $attributeJsonTime = $workTimeStart . '至' . $workTimeEnd;
+
                 $attributeJson['time'] = $attributeJsonTime;
                 $model->goods_attribute_json = json_encode($attributeJson);
             }
@@ -1527,19 +1606,19 @@ class GoodsService
             $params['goods_detail_slider_json'] = json_encode(['slider' => $params['goods_detail_slider_json']]);
         }
 
-        if(isset($params['curriculum'])){
+        if (isset($params['curriculum'])) {
             $params['goods_detail_specs_json'] = json_encode([
                 [
-                    'key'=>'课时',
-                    'val'=>$params['curriculum']['period'] ?? '',
+                    'key' => '课时',
+                    'val' => $params['curriculum']['period'] ?? '',
                 ],
                 [
-                    'key'=>'群体',
-                    'val'=>$params['curriculum']['group'] ?? '',
+                    'key' => '群体',
+                    'val' => $params['curriculum']['group'] ?? '',
                 ],
                 [
-                    'key'=>'课程',
-                    'val'=>$params['curriculum']['course'] ?? '',
+                    'key' => '课程',
+                    'val' => $params['curriculum']['course'] ?? '',
                 ],
             ]);
         }
@@ -1568,14 +1647,14 @@ class GoodsService
             // 有先删除
             if ($type == 'update') {
                 GoodsComponent::where('join_component_master_goods_id', $params['goods_id'])->delete();
-                $goodsSku = GoodsSku::where('join_sku_goods_id',$params['goods_id'])->first();
-                if ($goodsSku){
+                $goodsSku = GoodsSku::where('join_sku_goods_id', $params['goods_id'])->first();
+                if ($goodsSku) {
                     $goodsSku->goods_sku_market_price = $params['goods_market_price'] ?? 0;
                     $goodsSku->goods_sku_sales_price = $params['goods_sales_price'] ?? 0;
                     $goodsSku->save();
                 }
             }
-            if ($type == 'insert' || !$goodsSku){
+            if ($type == 'insert' || !$goodsSku) {
                 Goods::where('goods_id', $params['goods_id'])->update(['goods_sku_json' => '{"规格": ["标准"]}']);
                 $skuData = [
                     'join_sku_goods_id' => $params['goods_id'],
@@ -1589,7 +1668,7 @@ class GoodsService
             }
             $data = [];
             foreach ($params['goods_content_list'] as $item) {
-                if(!in_array($item['goods_id'],$params['join_component_goods_id'])){
+                if (!in_array($item['goods_id'], $params['join_component_goods_id'])) {
                     continue;
                 }
                 $goods = Goods::where('goods_id', $params['goods_id'])->first();
@@ -1723,7 +1802,7 @@ class GoodsService
                 $data['goods_category'] = $category->category_classify ?? '';
                 $data['goods_prefix'] = $data['goods_prefix'] ?? ($category->category_name ? '【' . $category->category_name . '】' : '');
             }
-            if (!empty($params['goods_recommend_index'])){
+            if (!empty($params['goods_recommend_index'])) {
                 $data['goods_category'] = $params['goods_recommend_index'];
             }
             // 上架时间有变动
@@ -1739,20 +1818,20 @@ class GoodsService
             }
 
             $expressJson = [];
-            if (!empty($params['express_json'])){
-                if(in_array('express',$params['express_json'])){
+            if (!empty($params['express_json'])) {
+                if (in_array('express', $params['express_json'])) {
                     $expressJson['express'] = 'Y';
-                }else{
+                } else {
                     $expressJson['express'] = 'N';
                 }
-                if (in_array('self',$params['express_json'])){
+                if (in_array('self', $params['express_json'])) {
                     $expressJson['self'] = 'Y';
-                }else{
+                } else {
                     $expressJson['self'] = 'N';
                 }
-                if (in_array('arrival',$params['express_json'])){
+                if (in_array('arrival', $params['express_json'])) {
                     $expressJson['arrival'] = 'Y';
-                }else{
+                } else {
                     $expressJson['arrival'] = 'N';
                 }
 
@@ -1927,7 +2006,7 @@ class GoodsService
                 $data['goods_attribute_json']['address'] = $params['address'];
                 $data['goods_attribute_json'] = json_encode($data['goods_attribute_json']);
             }
-            if (!empty($params['position'])){
+            if (!empty($params['position'])) {
                 if (!empty($data['goods_attribute_json']) && !is_array($data['goods_attribute_json'])) {
                     if (is_json($data['goods_attribute_json'])) {
                         $data['goods_attribute_json'] = json_decode($data['goods_attribute_json'], true);
@@ -1940,7 +2019,7 @@ class GoodsService
                 $data['goods_attribute_json']['position'] = $params['position'];
                 $data['goods_attribute_json'] = json_encode($data['goods_attribute_json']);
             }
-            if (isset($params['goods_service_premises'])){
+            if (isset($params['goods_service_premises'])) {
                 if (!empty($data['goods_attribute_json']) && !is_array($data['goods_attribute_json'])) {
                     if (is_json($data['goods_attribute_json'])) {
                         $data['goods_attribute_json'] = json_decode($data['goods_attribute_json'], true);
@@ -1953,7 +2032,7 @@ class GoodsService
                 $data['goods_attribute_json']['service_premises_id'] = $params['goods_service_premises'];
                 $data['goods_attribute_json'] = json_encode($data['goods_attribute_json']);
             }
-            if (isset($params['work_time'])){
+            if (isset($params['work_time'])) {
                 if (!empty($data['goods_attribute_json']) && !is_array($data['goods_attribute_json'])) {
                     if (is_json($data['goods_attribute_json'])) {
                         $data['goods_attribute_json'] = json_decode($data['goods_attribute_json'], true);
@@ -1964,14 +2043,14 @@ class GoodsService
                     $data['goods_attribute_json'] = [];
                 }
 
-                $workTimeStart = date('H:i',strtotime($params['work_time'][0]));
-                $workTimeEnd = date('H:i',strtotime($params['work_time'][1]));
+                $workTimeStart = date('H:i', strtotime($params['work_time'][0]));
+                $workTimeEnd = date('H:i', strtotime($params['work_time'][1]));
 
-                $data['goods_attribute_json']['time'] = $workTimeStart.'至'.$workTimeEnd;
+                $data['goods_attribute_json']['time'] = $workTimeStart . '至' . $workTimeEnd;
                 $data['goods_attribute_json'] = json_encode($data['goods_attribute_json']);
 
             }
-            if (isset($params['min_count'])){
+            if (isset($params['min_count'])) {
                 if (!empty($data['goods_attribute_json']) && !is_array($data['goods_attribute_json'])) {
                     if (is_json($data['goods_attribute_json'])) {
                         $data['goods_attribute_json'] = json_decode($data['goods_attribute_json'], true);
@@ -1984,7 +2063,7 @@ class GoodsService
                 $data['goods_attribute_json']['min-count'] = $params['min_count'];
                 $data['goods_attribute_json'] = json_encode($data['goods_attribute_json']);
             }
-            if (isset($params['teachers'])){
+            if (isset($params['teachers'])) {
                 if (!empty($data['goods_attribute_json']) && !is_array($data['goods_attribute_json'])) {
                     if (is_json($data['goods_attribute_json'])) {
                         $data['goods_attribute_json'] = json_decode($data['goods_attribute_json'], true);
@@ -2028,19 +2107,19 @@ class GoodsService
                 $data['goods_detail_slider_json'] = str_replace(getenv('STORAGE_DOMAIN'), '', $data['goods_detail_slider_json']);
                 $data['goods_detail_slider_json'] = json_encode(['slider' => $data['goods_detail_slider_json']]);
             }
-            if(isset($params['curriculum'])){
+            if (isset($params['curriculum'])) {
                 $data['goods_detail_specs_json'] = json_encode([
                     [
-                        'key'=>'课时',
-                        'val'=>$params['curriculum']['period'] ?? '',
+                        'key' => '课时',
+                        'val' => $params['curriculum']['period'] ?? '',
                     ],
                     [
-                        'key'=>'群体',
-                        'val'=>$params['curriculum']['group'] ?? '',
+                        'key' => '群体',
+                        'val' => $params['curriculum']['group'] ?? '',
                     ],
                     [
-                        'key'=>'课程',
-                        'val'=>$params['curriculum']['course'] ?? '',
+                        'key' => '课程',
+                        'val' => $params['curriculum']['course'] ?? '',
                     ],
                 ]);
             }

+ 32 - 11
app/admin/service/order/AppointmentService.php

@@ -71,6 +71,8 @@ class AppointmentService
             $row->order_addtimes = date('Y-m-d H:i:s', $row->order_addtimes);
             $row->appointment_addtimes = date('Y-m-d H:i:s', $row->appointment_addtimes);
             $row->appointment_apply_json = !empty($row->appointment_apply_json) ? json_decode($row->appointment_apply_json,true) : [];
+            $row->appointment_doing_json = !empty($row->appointment_doing_json) ? json_decode($row->appointment_doing_json,true) : [];
+            $row->appointment_result_json = !empty($row->appointment_result_json) ? json_decode($row->appointment_result_json,true) : [];
             if ($row->appointment_category == 'NOFEE') {
                 $row->member_benefit_name = "后付费预约";
             }elseif ($row->appointment_category == 'GREENWAY'){
@@ -83,6 +85,7 @@ class AppointmentService
             }
 
             $skus = GoodsSku::where('join_sku_goods_id',$row->join_appointment_goods_id)
+                ->where('goods_sku_id',$row->join_appointment_goods_sku_id)
                 ->select('goods_sku_id','goods_sku_specs_json','goods_sku_sales_price')
                 ->get();
             $skuJson = [];
@@ -236,7 +239,8 @@ class AppointmentService
                     'name' => !empty($member['cert']['member_cert_name']) ? $member['cert']['member_cert_name'] : $member['member_mobile'],
                     'mobile' => $member['member_mobile'],
                     'person' => $params['person'],
-                    'remark' => $data['appointment_remark'],
+                    'remark' => '',
+                    'remark_employe' => $data['remark_apply_employe'] ?? '',
                     'premises' => $params['premises'],
                     'times' => $params['appointment_times']
                 ]);
@@ -393,7 +397,7 @@ class AppointmentService
                 'appointment_doing_datetime' => $params['appointment_doing_datetime'] ? date('Y-m-d H:i:s', strtotime($params['appointment_doing_datetime'])) : null,
                 'appointment_done_datetime' => $params['appointment_done_datetime'] ? date('Y-m-d H:i:s', strtotime($params['appointment_done_datetime'])) : null,
                 'appointment_cancel_datetime' => $params['appointment_cancel_datetime'] ? date('Y-m-d H:i:s', strtotime($params['appointment_cancel_datetime'])) : null,
-                'appointment_remark' => $params['appointment_remark'] ?? '',
+                // 'appointment_remark' => $params['appointment_remark'] ?? '',
                 'appointment_mode' => $params['appointment_mode'] ?? '',
                 'settlement_mode' => $params['settlement_mode'] ?? '',
             ];
@@ -415,14 +419,27 @@ class AppointmentService
                     throw new BusinessException("核销人员不存在");
                 }
                 $member = $member->toArray();
-                $data['appointment_apply_json'] = json_encode([
-                    'name' => !empty($member['cert']['member_cert_name']) ? $member['cert']['member_cert_name'] : $member['member_mobile'],
-                    'mobile' => $member['member_mobile'],
-                    'person' => $params['person'],
-                    'remark' => $data['appointment_remark'],
-                    'premises' => $params['premises'],
-                    'times' => $params['appointment_times']
-                ]);
+                $applyJson = [];
+                if (!empty($appointment->appointment_apply_json)){
+                    $applyJson = json_decode($appointment->appointment_apply_json,true);
+                }
+                $applyJson['name'] = !empty($member['cert']['member_cert_name']) ? $member['cert']['member_cert_name'] : $member['member_mobile'];
+                $applyJson['mobile'] = $member['member_mobile'];
+                $applyJson['person'] = $params['person'];
+                $applyJson['remark_apply_employe'] = $params['remark_apply_employe'] ?? '';
+                $applyJson['remark_done_employe'] = $params['remark_done_employe'] ?? '';
+                $applyJson['remark_cancel_employe'] = $params['remark_cancel_employe'] ?? '';
+                $applyJson['premises'] = $params['premises'];
+                $applyJson['times'] = $params['appointment_times'];
+                $data['appointment_apply_json'] = json_encode($applyJson);
+                // $data['appointment_apply_json'] = json_encode([
+                //     'name' => !empty($member['cert']['member_cert_name']) ? $member['cert']['member_cert_name'] : $member['member_mobile'],
+                //     'mobile' => $member['member_mobile'],
+                //     'person' => $params['person'],
+                //     'remark' => $data['appointment_remark'],
+                //     'premises' => $params['premises'],
+                //     'times' => $params['appointment_times']
+                // ]);
             }
 
             Appointment::where('appointment_id', $appointmentId)->update($data);
@@ -656,12 +673,16 @@ class AppointmentService
             $extendJson = json_decode($goods->goods_attribute_json, true);
             $times = $extendJson['times'];
             foreach ($times as $key => $time) {
-//                $timesStr = $time['appointmentTimeStart'] . '~' . $time['appointmentTimeEnd'];
+                if (strtotime($date) < strtotime(date('Y-m-d')) || ($date == date('Y-m-d') && strtotime($date . ' ' . $key) < time())) {
+                    unset($times[$key]);
+                    continue;
+                }
                 $times[$key]['timesStr'] = $time['duration'];
                 foreach ($appointments as $appointment) {
                     if (!empty($appointment['appointment_apply_json'])) {
                         $applyJson = json_decode($appointment['appointment_apply_json'], true);
                         $applyJsonTimes = $applyJson['times'] ?? '';
+                        
                         if ($time['duration'] == $applyJsonTimes) {
                             $times[$key]['person'] -= $applyJson['person'];
                             if ($times[$key]['person'] < 1) {

+ 1 - 0
route/admin.php

@@ -73,6 +73,7 @@ Route::group('/admin', function () {
         Route::group('/service', function () {
             Route::get('/list', [\app\admin\controller\goods\ServiceGoodsController::class, 'select']);
             Route::get('/selectList', [\app\admin\controller\goods\ServiceGoodsController::class, 'selectList']);
+            Route::get('/selectCascaderList', [\app\admin\controller\goods\ServiceGoodsController::class, 'selectCascaderList']);
             Route::get('/selectPicking', [\app\admin\controller\goods\ServiceGoodsController::class, 'selectPicking']);
             Route::get('/info', [\app\admin\controller\goods\ServiceGoodsController::class, 'info']);
             Route::post('/add', [\app\admin\controller\goods\ServiceGoodsController::class, 'insert']);