<?php



require_once '../init.php';

$action = Input::getStrVar('action');

if($action == 'goods_price_stock'){
    $goods_id = Input::postIntVar('goods_id');
    $sku_ids = Input::postIntArray('sku_ids');
    $sku_ids = implode('-', $sku_ids);
    $quantity = Input::postIntVar('quantity');
    $quantity = $quantity <= 0 ? 1 : $quantity;
    $quantity = (int)ceil($quantity);
    Api::local_init();
    $res = Api::getPriceStock([
        'goods_id' => $goods_id,
        'skus' => $sku_ids,
        'quantity' => $quantity,
    ]);
    Ret::success('', $res);
}

if($action == 'xiadan'){
    $goods_id = Input::postIntVar('goods_id');
    $sku_ids = Input::postIntArray('sku_ids');
    $sku_ids = implode('-', $sku_ids);
    $quantity = Input::postIntVar('quantity');
    $quantity = $quantity <= 0 ? 1 : $quantity;
    $quantity = (int)ceil($quantity);
    $payment_plugin = Input::postStrVar('payment_plugin');
    $payment_title = Input::postStrVar('payment_title');
    $attach = Input::postStrArray('attach');
    $required = Input::postStrArray('required');

    Api::local_init();
    $res = Api::xiadan([
        'goods_id' => $goods_id,
        'sku_ids' => $sku_ids,
        'quantity' => $quantity,
        'payment_plugin' => $payment_plugin,
        'payment_title' => $payment_title,
        'attach' => $attach,
        'required' => $required,
    ]);


    if($res['code'] == 200){
        Ret::success('ok', $res['data']);
    }else{
        Ret::error($res['msg']);
    }


}