You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
4.7 KiB
137 lines
4.7 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\api\controller\apiController;
|
|
|
|
use app\Request;
|
|
use app\service\api\apiService\CampusService;
|
|
use app\service\api\apiService\ChatService;
|
|
use app\service\api\apiService\CommonService;
|
|
use app\service\api\apiService\CourseService;
|
|
use app\service\api\apiService\OrderTableService;
|
|
use core\base\BaseApiService;
|
|
|
|
/**
|
|
* 订单-控制器相关接口
|
|
* Class Personnel
|
|
* @package app\api\controller\apiController
|
|
*/
|
|
class OrderTable extends BaseApiService
|
|
{
|
|
|
|
//订单-列表
|
|
public function index(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())->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)
|
|
{
|
|
// 获取当前登录的员工ID
|
|
$staff_id = request()->personnel_id ?? 0;
|
|
|
|
$params = $request->params([
|
|
["payment_type", ""], // 付款类型必填验证
|
|
["course_id", ""], // 课程ID必填验证
|
|
["class_id", ""], // 班级ID必填验证
|
|
["staff_id", ""], // 员工ID(可选)
|
|
["resource_id", ""], // 客户资源表ID必填验证
|
|
]);
|
|
|
|
// 验证必要参数
|
|
if(empty($params['payment_type']) || empty($params['course_id']) ||
|
|
empty($params['class_id']) || empty($params['resource_id'])) {
|
|
return fail('缺少必要参数');
|
|
}
|
|
|
|
// 如果前端没提供员工ID,使用当前登录的员工ID
|
|
if(empty($params['staff_id'])) {
|
|
if(empty($staff_id)) {
|
|
return fail('无法获取员工信息');
|
|
}
|
|
$params['staff_id'] = $staff_id;
|
|
}
|
|
|
|
// 获取班级信息以查询campus_id
|
|
$class = \app\model\class_grade\ClassGrade::where('id', $params['class_id'])->find();
|
|
if (!$class) {
|
|
return fail('班级不存在');
|
|
}
|
|
$class = $class->toArray();
|
|
$campus_id = $class['campus_id'] ?? 0;
|
|
|
|
if(empty($campus_id)) {
|
|
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
|
|
'campus_id' => $campus_id,//校区ID
|
|
];
|
|
|
|
$res = (new OrderTableService())->addData($data);
|
|
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
|
|
return success([]);
|
|
}
|
|
}
|
|
|