<?php
namespace app\admin\controller\travel;

use app\admin\controller\BaseController;
use app\admin\server\travel\OrderServer;
use app\admin\model\UserTravelers;

class Order extends BaseController
{

    /**
     * Notes:获取订单列表
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/21
     */
    public function getOrderList()
    {
        [$page, $limit] = $this->getPage();
        $keywords = $this->request->get('keywords');
        $user_id = $this->request->user_id;
        $result         = OrderServer::getOrderList($page, $limit,$keywords);
        return json_success($result, '成功');
    }
    /**
     * Notes:订单详情
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/21
     */
    public function getOrderInfo()
    {
        $order_id = $this->request->get('order_id');
        if(!$order_id){
            throw new \Exception('订单ID不能为空');
        }
        $result         = OrderServer::orderInfo($order_id);
        $ids =  explode(',',$result['order_travelers']);
        $result['order_travelers_list'] = UserTravelers::whereIn('travelers_id',$ids)->get();
        if ($result){
            return json_success($result, '获取成功');
        }else{
            throw new \Exception('获取失败！');
        }

    }

    /**
     * Notes:修改订单支付状态
     * @return \support\Response
     * User: YCP
     * Date: 2022/11/28
     */
    public function updatePayStatus()
    {
        $order_id = $this->request->post('order_id');
        $order_pay_status = $this->request->post('order_pay_status');
        if(!$order_id){
            throw new \Exception('订单ID不能为空');
        }
        $result       = OrderServer::updatePayStatus($order_id, $order_pay_status);
        return json_success($result, '修改成功');
    }

    /**
     * Notes:修改订单状态
     * @return \support\Response
     * User: YCP
     * Date: 2022/11/28
     */
    public function updateOrderStatus()
    {
        $order_id = $this->request->post('order_id');
        $order_status = $this->request->post('order_status');
        $order_reject_reason = $this->request->post('order_reject_reason','');
        if(!$order_id){
            throw new \Exception('订单ID不能为空');
        }
        $result       = OrderServer::updateOrderStatus($order_id, $order_status, $order_reject_reason);
        return json_success($result, '修改成功');
    }


}
