From 03c3ab95a9809cd22894854dce5348296dfaeffb Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Fri, 13 Jun 2025 17:43:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(api):=20=E6=B7=BB=E5=8A=A0=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD=E5=92=8C=E5=85=AC?= =?UTF-8?q?=E5=85=B1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增订单管理相关接口和功能,包括订单列表、详情和创建 - 添加获取全部课程列表和班级列表的公共接口 - 在路由中注册新接口 - 实现订单管理的服务层逻辑 --- .../api/controller/apiController/Common.php | 18 +++ .../controller/apiController/OrderTable.php | 120 ++++++++++++++++ niucloud/app/api/route/route.php | 12 ++ niucloud/app/model/order_table/OrderTable.php | 5 +- .../service/api/apiService/CommonService.php | 26 ++++ .../api/apiService/OrderTableService.php | 128 ++++++++++++++++++ 6 files changed, 308 insertions(+), 1 deletion(-) create mode 100644 niucloud/app/api/controller/apiController/OrderTable.php create mode 100644 niucloud/app/service/api/apiService/OrderTableService.php diff --git a/niucloud/app/api/controller/apiController/Common.php b/niucloud/app/api/controller/apiController/Common.php index 7bccd8bd..9d2f4873 100644 --- a/niucloud/app/api/controller/apiController/Common.php +++ b/niucloud/app/api/controller/apiController/Common.php @@ -92,5 +92,23 @@ class Common extends BaseApiService return success($res['data']); } + //获取全部课程列表 + public function getCourseAll(Request $request) + { + $where = []; + $res = (new CommonService())->getCourseAllList($where); + return success($res); + } + + //获取全部班级列表 + public function getClassAll(Request $request) + { + $where = [ + 'status' => $request->param('status', '') + ]; + $res = (new CommonService())->getClassAllList($where); + return success($res); + } + } diff --git a/niucloud/app/api/controller/apiController/OrderTable.php b/niucloud/app/api/controller/apiController/OrderTable.php new file mode 100644 index 00000000..08b2065f --- /dev/null +++ b/niucloud/app/api/controller/apiController/OrderTable.php @@ -0,0 +1,120 @@ +param('resource_id', '');//客户资源表school_customer_resources表id(两个参数2选1) + $staff_id = $request->param('staff_id', '');//员工表school_personnel表id(两个参数2选1) + if (empty($resource_id) && empty($staff_id)) { + return fail('缺少参数'); + } + + $where = [ + 'resource_id' => $resource_id, + 'staff_id' => $staff_id, + ]; + + $res = (new OrderTableService())->getList($where); + + return success($res); + } + + //订单-详情 + public function info(Request $request) + { + $resource_id = $request->param('resource_id', '');//客户资源表school_customer_resources表id(两个参数2选1) + $staff_id = $request->param('staff_id', '');//员工表school_personnel表id(两个参数2选1) + if (empty($resource_id) && empty($staff_id)) { + return fail('缺少参数'); + } + + $where = [ + 'resource_id' => $resource_id, + 'staff_id' => $staff_id, + ]; + + $res = (new OrderTableService())->getInfo($where); + + if (!$res['code']) { + return fail($res['msg']); + } + + return success($res['data']); + } + + //订单-创建 + public function add(Request $request) + { + + $params = $request->params([ + ["payment_type", ""], // 付款类型必填验证 + ["course_id", ""], // 课程ID必填验证 + ["class_id", ""], // 班级ID必填验证 + ["staff_id", ""], // 员工ID必填验证 + ["resource_id", ""], // 客户资源表ID必填验证 + ]); + + foreach($params as $k=>$v){ + if(empty($v)){ + return fail('缺少参数'); + } + } + + + $course = \app\model\course\Course::where('id', $params['course_id'])->find(); + if (!$course) { + return fail('课程不存在'); + } + $course = $course->toArray(); + $order_amount = $course['price'];//课程的价格 + + + $data = [ + 'payment_type' => $params['payment_type'],//付款类型: cash-现金支付, scan_code-扫码支付, subscription-订阅支付 + 'order_amount' => $order_amount,//订单金额 + 'course_id' => $params['course_id'],//课程ID + 'class_id' => $params['class_id'],//班级ID + 'staff_id' => $params['staff_id'],//员工表ID + 'resource_id' => $params['resource_id'],//客户资源表id + ]; + + + + + + $res = (new OrderTableService())->addData($data); + + if (!$res['code']) { + return fail($res['msg']); + } + + return success([]); + } +} diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 8d542f04..b0d47cd4 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -183,6 +183,11 @@ Route::group(function () { //获取微信小程序openid Route::post('common/getMiniWxOpenId', 'apiController.Common/getMiniWxOpenId'); + //公共端-获取全部课程列表 + Route::get('common/getCourseAll', 'apiController.Common/getCourseAll'); + //公共端-获取全部班级列表 + Route::get('common/getClassAll', 'apiController.Common/getClassAll'); + @@ -267,6 +272,13 @@ Route::group(function () { //员工端-用户聊天-修改未读消息数量 Route::post('chat/editUnreadCount', 'apiController.Chat/editUnreadCount'); + //员工端-订单管理-列表 + Route::get('orderTable', 'apiController.OrderTable/index'); + //员工端-订单管理-详情 + Route::get('orderTable/info', 'apiController.OrderTable/info'); + //员工端-订单管理-创建 + Route::post('orderTable/add', 'apiController.OrderTable/add'); + diff --git a/niucloud/app/model/order_table/OrderTable.php b/niucloud/app/model/order_table/OrderTable.php index 04532570..2c2d28c3 100644 --- a/niucloud/app/model/order_table/OrderTable.php +++ b/niucloud/app/model/order_table/OrderTable.php @@ -78,19 +78,22 @@ class OrderTable extends BaseModel - + //客户资源表-客户姓名 public function customerResources(){ return $this->hasOne(CustomerResources::class, 'id', 'resource_id')->joinType('left')->withField('name,id')->bind(['resource_id_name'=>'name']); } + //课程表-课程名称 public function course(){ return $this->hasOne(Course::class, 'id', 'course_id')->joinType('left')->withField('course_name,id')->bind(['course_id_name'=>'course_name']); } + //班级表-班级名称 public function classGrade(){ return $this->hasOne(ClassGrade::class, 'id', 'class_id')->joinType('left')->withField('class_name,id')->bind(['class_id_name'=>'class_name']); } + //员工表-员工姓名 public function personnel(){ return $this->hasOne(Personnel::class, 'id', 'staff_id')->joinType('left')->withField('name,id')->bind(['staff_id_name'=>'name']); } diff --git a/niucloud/app/service/api/apiService/CommonService.php b/niucloud/app/service/api/apiService/CommonService.php index 1f0e82cf..2e31b14a 100644 --- a/niucloud/app/service/api/apiService/CommonService.php +++ b/niucloud/app/service/api/apiService/CommonService.php @@ -11,6 +11,8 @@ namespace app\service\api\apiService; +use app\model\class_grade\ClassGrade; +use app\model\course\Course; use app\model\dict\Dict; use app\model\member\Member; use app\model\sys\SysConfig; @@ -265,5 +267,29 @@ class CommonService extends BaseApiService ]; } + //获取全部课程列表 + public function getCourseAllList(array $where, string $field = '*') + { + $model = (new Course()); + $res = $model->field($field) + ->select() + ->toArray();//员工信息 + return $res; + } + + //获取全部班级列表 + public function getClassAllList(array $where, string $field = '*') + { + $model = (new ClassGrade()); + if(!empty($where['status'])){ + $model = $model->where('status',$where['status']); + } + $res = $model->field($field) + ->select() + ->toArray();//员工信息 + return $res; + } + + } diff --git a/niucloud/app/service/api/apiService/OrderTableService.php b/niucloud/app/service/api/apiService/OrderTableService.php new file mode 100644 index 00000000..09989091 --- /dev/null +++ b/niucloud/app/service/api/apiService/OrderTableService.php @@ -0,0 +1,128 @@ +getPageParam();//获取请求参数中的页码+分页数 + $page = $page_params['page']; + $limit = $page_params['limit']; + + $model = new OrderTable(); + //员工表id + if (!empty($where['staff_id'])) { + $model = $model->where('staff_id', $where['staff_id']); + } + + //客户资源表id + if (!empty($where['resource_id'])) { + $model = $model->where('resource_id', $where['resource_id']); + } + + $data = $model + ->append([ + 'customerResources', + 'course', + 'classGrade', + 'personnel' + ]) + ->order('id','desc') + ->paginate([ + 'list_rows' => $limit, + 'page' => $page, + ])->toArray(); + + return $data; + } + + //查询详情 + public function getInfo(array $where) + { + $model = new OrderTable(); + //判断用没有员工id + if (!empty($where['staff_id'])) { + $model = $model->where('staff_id', $where['staff_id']); + } + //判断用没有客户资源id + if (!empty($where['resource_id'])) { + $model = $model->where('resource_id', $where['resource_id']); + } + $data = $model + ->append([ + 'customerResources', + 'course', + 'classGrade', + 'personnel' + ]) + ->find(); + + + if ($data) { + $data = $data->toArray(); + $res = [ + 'code' => 1, + 'msg' => '操作成功', + 'data' => $data + ]; + return $res; + } else { + $res = [ + 'code' => 0, + 'msg' => '暂无数据', + 'data' => [] + ]; + return $res; + } + } + + //创建订单 + public function addData(array $data) + { + $success = OrderTable::create($data); + + $res = [ + 'code' => 1, + 'msg' => '操作成功', + 'data' => [] + ]; + if (!$success) { + $res = [ + 'code' => 0, + 'msg' => '操作失败', + 'data' => [] + ]; + } + return $res; + } +}