124 lines
3.8 KiB
PHP
124 lines
3.8 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller\school;
|
||
|
||
use app\common\model\school\classes\order\Order as OrderModel;
|
||
use app\common\model\school\classes\Teacher as Teachermodel;
|
||
|
||
/**
|
||
* 课时订单接口
|
||
*/
|
||
class HourOrder extends Base
|
||
{
|
||
protected $noNeedLogin = [];
|
||
protected $noNeedRight = '*';
|
||
|
||
protected $model = null;
|
||
|
||
/**
|
||
* 初始化操作
|
||
* @access protected
|
||
*/
|
||
protected function _initialize()
|
||
{
|
||
|
||
$this->model = new OrderModel;
|
||
parent::_initialize();
|
||
|
||
//判断登录用户是否是员工
|
||
}
|
||
|
||
|
||
/**
|
||
* @ApiTitle( 订单详情)
|
||
* @ApiSummary(订单详情)
|
||
* @ApiRoute(/api/school/order/detail)
|
||
* @ApiMethod(GET)
|
||
* @ApiParams(name = "id", type = "int",required=true,description = "订单id或订单号")
|
||
* @ApiReturn({
|
||
*
|
||
*})
|
||
*/
|
||
public function detail(){
|
||
$id = $this->request->get('id/d','');
|
||
|
||
if(empty($id)){
|
||
$this->error(__('缺少必要参数'));
|
||
}
|
||
|
||
try {
|
||
$res = OrderModel::getDetail($id);
|
||
} catch (\Exception $e){
|
||
// Log::log($e->getMessage());
|
||
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
|
||
}
|
||
$this->success('获取成功', ['detail' => $res]);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/**
|
||
* @ApiTitle( 订单确认/订单计算接口)
|
||
* @ApiSummary(订单确认/订单计算接口【有过期时间】)
|
||
* @ApiRoute(/api/school/order/confirm)
|
||
* @ApiMethod(POST)
|
||
* @ApiParams(name = "classes_lib_id", type = "int",required=true,description = "订单id或订单号")
|
||
* @ApiParams(name = "order_no", type = "string",required=false,description = "缓存key")
|
||
* @ApiParams(name = "is_compute", type = "int",required=false,description = "是否重新计算并更新缓存 默认传1")
|
||
* @ApiReturn({
|
||
*
|
||
*})
|
||
*/
|
||
public function confirm(){
|
||
$user_id = 0;
|
||
$user = $this->auth->getUser();//登录用户
|
||
if($user)$user_id = $user['id'];
|
||
$classes_lib_id = $this->request->post('classes_lib_id/d', 0); //课程id
|
||
// $param = urldecode($this->request->post('param/s', "{}")); //参数
|
||
$param = []; //参数
|
||
$order_no = $this->request->post('order_no/s', ''); //订单号
|
||
$is_compute = $this->request->post('is_compute/d', 1); //是否重新计算并更新缓存
|
||
try{
|
||
//当前申请状态
|
||
$res = $this->model->confirm($user_id, $classes_lib_id,$order_no,$param, $is_compute);
|
||
}catch (\Exception $e){
|
||
// Log::log($e->getMessage());
|
||
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
|
||
}
|
||
$this->success('执行成功,可用缓存key下单', $res);
|
||
}
|
||
|
||
|
||
/**
|
||
* @ApiTitle( 订单下单接口)
|
||
* @ApiSummary(订单下单接口)
|
||
* @ApiRoute(/api/school/order/create)
|
||
* @ApiMethod(POST)
|
||
* @ApiParams(name = "order_no", type = "string",required=true,description = "缓存key")
|
||
* @ApiReturn({
|
||
*
|
||
*})
|
||
*/
|
||
public function create(){
|
||
$user_id = 0;
|
||
$user = $this->auth->getUser();//登录用户
|
||
if($user)$user_id = $user['id'];
|
||
$order_no = $this->request->post('order_no/s', ''); //订单号
|
||
$remark = $this->request->post('remark/s', ''); //下单备注
|
||
// repeat_filter("appointment\order\create".$user_id, 2);
|
||
try{
|
||
//当前申请状态
|
||
$res = $this->model->cacheCreateOrder($order_no,$user_id,$remark,true);
|
||
}catch (\Throwable $e){
|
||
// file_put_contents("test.txt",$e->getMessage().$e->getFile().$e->getLine());//写入文件,一般做正式环境测试
|
||
// Log::log($e->getMessage());
|
||
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);;
|
||
}
|
||
$this->success('订单创建成功,缓存key被消耗', $res);
|
||
}
|
||
|
||
}
|
||
|