Bläddra i källkod

编辑服务商

moonsflyer 4 månader sedan
förälder
incheckning
d017f69f55

+ 44 - 0
app/adminapi/controller/agricultural_machinery/UserServiceController.php

@@ -123,6 +123,50 @@ class UserServiceController extends BaseAdminController
         return $this->data($result);
     }
 
+    /**
+     * @notes  编辑服务商信息
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/21 17:31
+     */
+    public function editUserService()
+    {
+        if($this->request->isPost()) {
+
+            $params = (new UserServiceValidate())->post()->goCheck('editUserService');
+//            $userId = $this->userId;
+//            $params['user_id'] = $userId;
+            switch ($params['type']){
+                case 1 :
+                    $type_name = '农机手';
+                    break;
+                case 2 :
+                    $type_name = '烘干服务';
+                    break ;
+                case 3 :
+                    $type_name = '飞防服务';
+                    break;
+                default :
+                    $type_name = '';
+                    break;
+            }
+            $result = UserServiceLogic::edit($params,$type_name);
+            if (1 === $result['code']) {
+                return $this->success($type_name.'入驻信息修改成功成功', $result, 1, 1);
+            }else{
+                return $this->fail(UserServiceLogic::getError());
+            }
+
+
+        }else{
+            return $this->fail('请求方式错误');
+        }
+//
+//
+//        $params = (new UserServiceValidate())->post()->goCheck('add');
+//        UserServiceLogic::add($params);
+//        return $this->success('添加成功', [], 1, 1);
+    }
 
     /**
      * @notes  更改服务商状态

+ 47 - 2
app/adminapi/logic/agricultural_machinery/UserServiceLogic.php

@@ -42,7 +42,7 @@ class UserServiceLogic extends BaseLogic
 
 
     /**
-     * @notes  添加农耕分类
+     * @notes  添加服务商
      * @param array $params
      * @author heshihu
      * @date 2022/2/18 10:17
@@ -132,10 +132,55 @@ class UserServiceLogic extends BaseLogic
             return ['code'=>0,'data'=>[]];
         }
     }
+    /**
+     * @notes  编辑服务商
+     * @param array $params
+     * @author heshihu
+     * @date 2022/2/18 10:17
+     */
+    public static function edit(array $params,$type_name)
+    {
+        Db::startTrans();
+        try {
 
+//            $where['user_id'] = $params['user_id'];
+//            $where['type'] = $params['type'];
+//            $userService = UserService::where($where)->findOrEmpty();
+//
+//            if(!$userService->isEmpty()){
+//                Db::rollback();
+//                self::setError('当前用户存在'.$type_name.'服务信息,无需添加');
+//                return ['code'=>0,'data'=>[]];
+//            }
+            $result = UserService::where(['id'=>$params['id']])->update([
+                'user_id' => $params['user_id'],
+                'type' => $params['type'] ?? 1,
+                'name' => $params['name'],
+                'mobile' => $params['mobile'],
+                'agricultural_machinery_model' =>$params['agricultural_machinery_model'],
+                'images' => $params['images'],
+                'agricultural_image'=>$params['agricultural_image'],
+                'driver_image'=>$params['driver_image'],
+                'driving_image'=>$params['driving_image'],
+                'cate_id' => ','.$params['cate_id'].',',
+                'area_id' => ','.$params['area_id'].',',
+                'mechanical_cate_id' => ','.$params['mechanical_cate_id'].',',
+                'money' => $params['money'],
+                'content'=>$params['content']?? '',
+            ]);
+
+
+            Db::commit();
+            return ['code'=>1,'data'=>$result];
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return ['code'=>0,'data'=>[]];
+        }
+    }
 
     /**
-     * @notes  删除农耕分类
+     * @notes  删除服务商
      * @param array $params
      * @author heshihu
      * @date 2022/2/21 17:52

+ 11 - 1
app/adminapi/validate/agricultural_machinery/UserServiceValidate.php

@@ -109,7 +109,17 @@ class UserServiceValidate extends BaseValidate
             ->remove('id', 'require|checkUserServiceInfo')
             ->remove('disclaimer', 'require');
     }
-
+    /**
+     * @notes  编辑场景
+     * @return ArticleCateValidate
+     * @author heshihu
+     * @date 2022/2/10 15:11
+     */
+    public function sceneEditUserService()
+    {
+        return $this->remove(['disclaimer'])
+            ->remove('disclaimer', 'require');
+    }
     /**
      * @notes  详情场景
      * @return ArticleCateValidate