<?php
namespace app\api\controller\h5;

use app\hander\HelpHander;
use app\common\model\ShopOrders;

class ShopOrder extends Base
{
    public function addOrder(){
        $addressid = input('address_id/d',0);
        $delivery_time = input('delivery_time','','trim');
        $type = input('type/d',0);
        $json = input('json','','trim');
        if($addressid <= 0){
            HelpHander::error('未选择收货地址');
        }
        if(!$delivery_time){
            HelpHander::error('未选择配送时间');
        }
        if($type <= 0){
            HelpHander::error('未选择类型');
        }
        if(!$json){
            HelpHander::error('商品信息不能为空');
        }
        $so = new ShopOrders();
        $ret = $so->addOrder_old($json,$addressid,$this->orgId,$this->userId,$delivery_time,$type);
        if(!$ret){
            HelpHander::error($so->getError());
        }
        HelpHander::success($ret);
    }

    public function orderList(){
        $page = input('page/d',1);
        $size = input('size/d',10);
        $so = new ShopOrders();
        $ret = $so->list($page,$size,$this->userId,$this->orgId);
        HelpHander::success($ret);
    }

    public function orderDetails(){
        $id = input('id/d',0);
        $so = new ShopOrders();
        $ret = $so->details($id);

        if(!$ret){
            HelpHander::error('数据不存在');
        }
        HelpHander::success($ret);
    }

    public function cancel(){
        $id = input('id/d',0);
        $so = new ShopOrders();
        $ret = $so->cancel($id,$this->userId);
        if(!$ret){
            HelpHander::error('操作失败');
        }
        HelpHander::success([],'操作成功');
    }

}