337 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			337 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						||
 | 
						||
namespace app\api\controller\school\newactivity;
 | 
						||
 | 
						||
use app\api\controller\school\Base;
 | 
						||
use app\common\model\school\activity\order\Order as OrderModel;
 | 
						||
use app\common\model\school\activity\order\OrderCode;
 | 
						||
 | 
						||
/**
 | 
						||
 * 用户端:新活动订单接口
 | 
						||
 */
 | 
						||
class Order extends Base
 | 
						||
{
 | 
						||
 | 
						||
    protected $noNeedLogin = [];
 | 
						||
    protected $noNeedRight = '*';
 | 
						||
 | 
						||
    protected $model = null;
 | 
						||
 | 
						||
 | 
						||
    /**
 | 
						||
     * 初始化操作
 | 
						||
     * @access protected
 | 
						||
     */
 | 
						||
    protected function _initialize()
 | 
						||
    {
 | 
						||
        $this->transactionCheck();
 | 
						||
 | 
						||
        $this->model = new OrderModel;
 | 
						||
        parent::_initialize();
 | 
						||
 | 
						||
 | 
						||
        $this->setUrlLock();
 | 
						||
    }
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
    /**
 | 
						||
     * @ApiTitle( 我的活动订单详情)
 | 
						||
     * @ApiSummary(我的活动订单详情)
 | 
						||
     * @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(我的活动订单列表接口)
 | 
						||
     * @ApiMethod(GET)
 | 
						||
     * @ApiParams(name = "keywords", type = "string",required=false,description = "搜索关键字")
 | 
						||
     * @ApiParams(name = "page", type = "string",required=true,description = "页数")
 | 
						||
     * @ApiParams(name = "limit", type = "string",required=true,description = "条数")
 | 
						||
     * @ApiParams(name = "status", type = "string",required=false,description = "订单状态:-3=已取消,0=待支付,2=已报名,3=核销中,4=售后中,5=退款结算中,6=已退款,9=已完成")
 | 
						||
     * @ApiParams(name = "server_status", type = "string",required=false,description = "售后订单状态:0=正常,3=售后中,6=售后完成")
 | 
						||
     * @ApiParams(name = "auth_status", type = "string",required=false,description = "售后结果状态:0=待审核,1=同意退款,2=拒绝退款")
 | 
						||
     * @ApiParams(name = "invoice_status", type = "string",required=false,description = "发票申请状态:0=未申请,1=申请中,2=已开票")
 | 
						||
     * @ApiParams(name = "have_invoice", type = "int",required=false,description = "是否查可开票:1是")
 | 
						||
     * @ApiParams(name = "activity_id", type = "int",required=false,description = "活动id")
 | 
						||
     * @ApiReturn({
 | 
						||
     *
 | 
						||
     *})
 | 
						||
     */
 | 
						||
    public function order_list()
 | 
						||
    {
 | 
						||
        $user_id = 0;
 | 
						||
        $user = $this->auth->getUser();//登录用户
 | 
						||
        if($user)$user_id = $user['id'];
 | 
						||
        $page  =  $this->request->get('page/d', 0); //页数
 | 
						||
        $limit =  $this->request->get('limit/d', 0); //条数
 | 
						||
        $keywords =  $this->request->get('keywords/s', ''); //搜索关键字
 | 
						||
        $status =  $this->request->get('status/s', ''); //搜索关键字
 | 
						||
        $server_status =  $this->request->get('server_status/s', ''); //搜索关键字
 | 
						||
        $params = [];
 | 
						||
        $params["auth_status"] =  $this->request->get('auth_status/s', ''); //搜索关键字
 | 
						||
 | 
						||
 | 
						||
        $params["invoice_status"] =  $this->request->get('invoice_status/s', ''); //搜索关键字
 | 
						||
        $params["have_invoice"] =  $this->request->get('have_invoice/d', 0); //搜索关键字
 | 
						||
 | 
						||
        $activity_id =  $this->request->get('activity_id/s', ''); //搜索关键字
 | 
						||
 | 
						||
        $has_evaluate =  $this->request->get('has_evaluate/d', 0); //搜索关键字
 | 
						||
//        $type =  $this->request->get('type/s', ''); //筛选学员和教练单
 | 
						||
 | 
						||
        try{
 | 
						||
            //当前申请状态
 | 
						||
            $res = $this->model::allList($user_id,$page, $limit,$keywords,$status,$activity_id,$has_evaluate,$server_status,$params);
 | 
						||
//            if($user_id =='670153'){
 | 
						||
//               file_put_contents("ceshi66.txt",(new AppointmentOrder())->getLastSql());
 | 
						||
//            }
 | 
						||
            $res['activity_info'] = null;
 | 
						||
            if($activity_id){
 | 
						||
                $res['activity_info'] = (new \app\common\model\school\activity\Activity)->getActivityPeopleInfo($activity_id);
 | 
						||
            }
 | 
						||
        }catch (\Exception $e){
 | 
						||
 | 
						||
            $this->error($e->getMessage());
 | 
						||
        }
 | 
						||
        $this->success('查询成功', $res);
 | 
						||
    }
 | 
						||
 | 
						||
 | 
						||
    /**
 | 
						||
     * @ApiTitle( 我的活动订单数量接口)
 | 
						||
     * @ApiSummary(返回订单各个数量)
 | 
						||
     * @ApiMethod(GET)
 | 
						||
     * @ApiParams(name = "activity_id", type = "int",required=false,description = "活动id(非必填)")
 | 
						||
     * @ApiReturn({
 | 
						||
     *
 | 
						||
     *})
 | 
						||
     */
 | 
						||
    public function order_count(){
 | 
						||
        $user_id = 0;
 | 
						||
        $user = $this->auth->getUser();//登录用户
 | 
						||
        if($user)$user_id = $user['id'];
 | 
						||
 | 
						||
        $activity_id =  $this->request->get('activity_id/s', ''); //搜索关键字
 | 
						||
        try{
 | 
						||
            $res = $this->model::orderCount($user_id,$activity_id);
 | 
						||
        }catch (\Throwable $e){
 | 
						||
            $this->error($e->getMessage());
 | 
						||
        }
 | 
						||
        $this->success('查询成功', $res);
 | 
						||
    }
 | 
						||
 | 
						||
 | 
						||
 | 
						||
    /**
 | 
						||
     * @ApiTitle( 订单确认/订单计算接口)
 | 
						||
     * @ApiSummary(订单确认/订单计算接口【有过期时间】)
 | 
						||
     * @ApiMethod(POST)
 | 
						||
     * @ApiParams(name = "num", type = "int",required=true,description = "人数")
 | 
						||
     * @ApiParams(name = "activity_id", type = "int",required=true,description = "活动id")
 | 
						||
     * @ApiParams(name = "order_no", type = "string",required=false,description = "缓存key")
 | 
						||
     * @ApiParams(name = "people", type = "string",required=true,description = "(需url编码)参与人员信息json [{name:"小明",idnum:"410303199501220515"}]")
 | 
						||
     * @ApiParams(name = "is_compute", type = "int",required=false,description = "是否重新计算并更新缓存 默认传1")
 | 
						||
     * @ApiParams(name = "desc", type = "string",required=false,description = "下单备注")
 | 
						||
     * @ApiReturn({
 | 
						||
     *
 | 
						||
     *})
 | 
						||
     */
 | 
						||
    public function confirm(){
 | 
						||
 | 
						||
        //敏感词过滤
 | 
						||
        $this->checkSensitivewords(["desc"]);
 | 
						||
 | 
						||
        $user_id = 0;
 | 
						||
        $user = $this->auth->getUser();//登录用户
 | 
						||
        if($user)$user_id = $user['id'];
 | 
						||
        $activity_id =  $this->request->post('activity_id/d', 0); //课程id
 | 
						||
        $num =  $this->request->post('num/d', 0); //想同时约的课时id
 | 
						||
//        $num =  0; //想同时约的课时id
 | 
						||
 | 
						||
        $param  = [];
 | 
						||
 | 
						||
        $people  =  urldecode($this->request->post('people/s', "{}") ?: "{}"); //参数
 | 
						||
//        if($people){
 | 
						||
        $param["people"] = json_decode($people,true) ?: [];
 | 
						||
//        var_dump($param["people"]);die;
 | 
						||
//            $num = count($param["people"]);
 | 
						||
 | 
						||
//        }
 | 
						||
 | 
						||
        //参数
 | 
						||
        $order_no  =  $this->request->post('order_no/s', ''); //订单号
 | 
						||
        $is_compute =  $this->request->post('is_compute/d', 1); //是否重新计算并更新缓存
 | 
						||
 | 
						||
 | 
						||
        $param["desc"]  =  $this->request->post('desc/s', ''); //订单号
 | 
						||
 | 
						||
        try{
 | 
						||
            //当前申请状态
 | 
						||
            $res = $this->model->confirm($user_id, $activity_id,$num,$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(订单下单接口)
 | 
						||
     * @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', ''); //下单备注
 | 
						||
        $this->setUrlLock("only");
 | 
						||
//        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);
 | 
						||
    }
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
    /**
 | 
						||
     * @ApiTitle(免费单和未支付单取消接口)
 | 
						||
     * @ApiSummary(活动单取消接口(免费单和未支付单取消))
 | 
						||
     * @ApiMethod(POST)
 | 
						||
     * @ApiParams(name = "order_no", type = "string",required=true,description = "订单号")
 | 
						||
     * @ApiReturn({
 | 
						||
     *
 | 
						||
     *})
 | 
						||
     */
 | 
						||
    public function freecancel(){
 | 
						||
        $user_id = 0;
 | 
						||
        $user = $this->auth->getUser();//登录用户
 | 
						||
        if($user)$user_id = $user['id'];
 | 
						||
        $order_no =  $this->request->post('order_no/s', ''); //订单号
 | 
						||
        try{
 | 
						||
            //当前申请状态
 | 
						||
            $res = $this->model->freeCancel($order_no,$user_id,true,'user',$user_id,true);
 | 
						||
        }catch (\Throwable $e){
 | 
						||
            $this->error($e->getMessage());
 | 
						||
        }
 | 
						||
        $this->success('活动订单取消成功', $res);
 | 
						||
    }
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
    /**
 | 
						||
     * @ApiTitle(付费活动支付后取消接口)
 | 
						||
     * @ApiSummary(付费活动支付后取消接口(支付后,活动开始前))
 | 
						||
     * @ApiMethod(POST)
 | 
						||
     * @ApiParams(name = "order_no", type = "string",required=true,description = "订单号")
 | 
						||
     * @ApiReturn({
 | 
						||
     *
 | 
						||
     *})
 | 
						||
     */
 | 
						||
    public function paidcancel(){
 | 
						||
        $user_id = 0;
 | 
						||
        $user = $this->auth->getUser();//登录用户
 | 
						||
        if($user)$user_id = $user['id'];
 | 
						||
        $order_no =  $this->request->post('order_no/s', ''); //订单号
 | 
						||
        try{
 | 
						||
            //当前申请状态
 | 
						||
            $res = $this->model->paidCancel($order_no,$user_id,true,'user',$user_id,false,true);
 | 
						||
        }catch (\Throwable $e){
 | 
						||
            $this->error($e->getMessage());
 | 
						||
        }
 | 
						||
        $this->success('活动订单取消成功', $res);
 | 
						||
    }
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
    /**
 | 
						||
     * @ApiTitle( 订单申请售后接口 )
 | 
						||
     * @ApiSummary(订单申请售后)
 | 
						||
     * @ApiMethod(POST)
 | 
						||
     * @ApiParams(name = "order_no", type = "string",required=true,description = "需要售后的订单号")
 | 
						||
     * @ApiParams(name = "auth_reason", type = "string",required=true,description = "申请理由")
 | 
						||
     * @ApiParams(name = "num", type = "int",required=true,description = "退票数")
 | 
						||
     * @ApiReturn({
 | 
						||
     *
 | 
						||
     *})
 | 
						||
     */
 | 
						||
    public function after_sales(){
 | 
						||
        $user_id = 0;
 | 
						||
        $user = $this->auth->getUser();//登录用户
 | 
						||
        if($user)$user_id = $user['id'];
 | 
						||
        $classes_order =  $this->request->post('order_no/s', 0); //课程id
 | 
						||
        $auth_reason  =  $this->request->post('auth_reason/s', ''); //订单号
 | 
						||
        $num  =  $this->request->post('num/d', ''); //订单号
 | 
						||
        try{
 | 
						||
            //当前申请状态
 | 
						||
            $res = $this->model->afterSales($classes_order,$num,$auth_reason,$user_id ,true,'user',$user_id,true);
 | 
						||
 | 
						||
 | 
						||
        }catch (\Exception $e){
 | 
						||
//            Log::log($e->getMessage());
 | 
						||
            $this->error($e->getMessage(),['errcode'=>$e->getCode()]);
 | 
						||
        }
 | 
						||
        $this->success('申请售后成功', $res);
 | 
						||
    }
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
} |