gorden 11 сар өмнө
parent
commit
e5d35cb827

+ 10 - 3
app/admin/controller/medical/DoctorController.php

@@ -74,9 +74,16 @@ class DoctorController extends Curd
         $data = $this->inputFilter($request->post());
         $data['doctor_avatar'] = str_replace(getenv("STORAGE_DOMAIN"), '', $data['doctor_avatar']);
         // 处理时间
-        $doctorVisitTimeStart = date('H:i', strtotime($data['doctor_visit_time'][0]));
-        dd($doctorVisitTimeStart);
-
+        if ($data['doctor_visit_time']) {
+            $doctorVisitTimeStart = date('H:i', strtotime(explode(',', $data['doctor_visit_time'])[0]));
+            $doctorVisitTimeEnd = date('H:i', strtotime(explode(',', $data['doctor_visit_time'])[1]));
+            $data['doctor_visit_time'] = $doctorVisitTimeStart . '~' . $doctorVisitTimeEnd;
+        }
+        if ($data['doctor_work']){
+            $doctorWorkStart = date('H:i', strtotime(explode(',', $data['doctor_work'])[0]));
+            $doctorWorkEnd = date('H:i', strtotime(explode(',', $data['doctor_work'])[1]));
+            $data['doctor_work'] = $doctorWorkStart . '~' . $doctorWorkEnd;
+        }
         return $data;
     }
 

+ 59 - 0
app/admin/controller/medical/ShopController.php

@@ -5,6 +5,7 @@ namespace app\admin\controller\medical;
 use app\admin\validate\medical\ShopValidate;
 use app\controller\Curd;
 use app\model\MedicalShop;
+use support\exception\BusinessException;
 use support\Request;
 use support\Response;
 
@@ -36,6 +37,64 @@ class ShopController extends Curd
         return $this->doFormat($query, $format, $limit);
     }
 
+
+    /**
+     * @Desc 插入数据处理
+     * @Author Gorden
+     * @Date 2024/3/19 13:37
+     *
+     * @param Request $request
+     * @return array
+     * @throws \support\exception\BusinessException
+     */
+    protected function insertInput(Request $request): array
+    {
+        $data = $this->inputFilter($request->post());
+
+        $data['shop_logo'] = str_replace(getenv("STORAGE_DOMAIN"), '', $data['shop_logo']);
+        if ($data['shop_business_hours']){
+            $shopBusinessHoursStart = date('H:i', strtotime(explode(',', $data['shop_business_hours'])[0]));
+            $shopBusinessHoursEnd = date('H:i', strtotime(explode(',', $data['shop_business_hours'])[1]));
+            $data['shop_business_hours'] = $shopBusinessHoursStart . '~' . $shopBusinessHoursEnd;
+        }
+        return $data;
+    }
+
+    protected function updateInput(Request $request): array
+    {
+        $primary_key = $this->model->getKeyName();
+        $id = $request->post($primary_key);
+        $data = $this->inputFilter($request->post());
+        $model = $this->model->find($id);
+        if (!$model) {
+            throw new BusinessException('记录不存在', 2);
+        }
+        unset($data[$primary_key]);
+        // 头像
+        $data['shop_logo'] = str_replace(getenv("STORAGE_DOMAIN"), '', $data['shop_logo']);
+        if ($data['shop_business_hours']){
+            $shopBusinessHoursStart = date('H:i', strtotime(explode(',', $data['shop_business_hours'])[0]));
+            $shopBusinessHoursEnd = date('H:i', strtotime(explode(',', $data['shop_business_hours'])[1]));
+            $data['shop_business_hours'] = $shopBusinessHoursStart . '~' . $shopBusinessHoursEnd;
+        }
+
+        return [$id, $data];
+    }
+
+    public function afterQuery($items)
+    {
+        foreach ($items as &$item) {
+            $item->shop_logo = getenv('STORAGE_DOMAIN').$item->shop_logo;
+            $shopBusinessHoursArr = explode('~', $item->shop_business_hours);
+            foreach ($shopBusinessHoursArr as $key => $v){
+                $shopBusinessHoursArr[$key] = date("Y-m-d\TH:i:s\Z",strtotime(date('Y-m-d ').$v)-8*3600);
+            }
+            $item->shop_business_hours = $shopBusinessHoursArr;
+            $item->shop_label = !empty($item->shop_label) ? explode(',',$item->shop_label) : [];
+        }
+        return $items;
+    }
+
     /**
      * @Desc 删除
      * @Author Gorden

+ 2 - 2
app/admin/validate/medical/ShopValidate.php

@@ -10,9 +10,9 @@ class ShopValidate extends Validate
         'shop_id' => 'require|integer',
         'shop_name' => 'require|chsDash',
         'shop_real_name' => 'require|chsDash',
-        'shop_logo' => 'regex:/^[0-9a-zA-Z\/\.]+$/',
+        'shop_logo' => 'url',
         'shop_img' => 'regex:/^[0-9a-zA-Z\.\/]+$/',
-        'shop_label' => '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9\_\-\,\s]+$/u',
+//        'shop_label' => '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9\_\-\,\s]+$/u',
         'shop_category_id' => 'require|integer',
         'shop_score' => 'require|float',
         'shop_type' => 'require|in:1,2,3,4,5',

+ 1 - 0
app/controller/Curd.php

@@ -102,6 +102,7 @@ class Curd
         } catch (BusinessException $customException) {
             return json_fail($customException->getMessage());
         } catch (\Exception $exception) {
+            dump($exception->getMessage());
             return json_fail('数据写入失败');
         }
         return json_success('success');