示例#1
0
$app->get('/tickets/update[/{id}/{status}]', function ($request, $response, $args) {
    $ticket = \models\Tickets::find($args['id']);
    $ticket->status = $args['status'];
    $rer = [];
    if ($ticket->update()) {
        $rer['data'] = $ticket;
        $rer['msg'] = "success";
    } else {
        $rer['data'] = null;
        $rer['msg'] = "failed";
    }
    $response->write(json_encode($rer));
    return $response;
});
$app->get('/tickets/data[/{id}]', function ($request, $response, $args) {
    $rer = \models\Tickets::find($args['id']);
    $response->write(json_encode($rer));
    return $response;
})->setArgument('id', '1');
/*$app->get('/buses/data[/{id}]',function($request,$response,$args){
    $rer  = \models\Bus::find($args['id']);
    $response->write(json_encode($rer));
    return $response;
})->setArgument('id', '1');*/
$app->get('/terminals/index', function ($request, $response, $args) {
    $rer = \models\Terminal::all();
    $response->write(json_encode($rer));
    return $response;
});
$app->get('/terminals/data[/{id}]', function ($request, $response, $args) {
    $rer = \models\Terminal::find($args['id']);
示例#2
0
});
/**
 * Create Ticketing
 */
$app->post("/ticketing/create/", function ($request, $response, $args) {
    try {
        $json = $request->getBody();
        $data = json_decode($json, true);
        $myTicketing = new \models\Ticketing();
        //$ticketing = json_decode($args['ticketing']);
        foreach ($data as $key => $val) {
            $myTicketing->{$key} = $val;
        }
        $myTicketing->created_at = date("Y-m-d H:i:s");
        if ($myTicketing->create()) {
            $ticket = \models\Tickets::find($myTicketing->ticket_id);
            $ticket->status = 1;
            $ticket->updated_at = date("Y-m-d H:i:s");
            $ticket->update();
            $acc = \models\Account::find_by_sql("SELECT * FROM accounts WHERE app_id ='" . $data['app_id'] . "'");
            $acc[0]->balance -= $data['amount'];
            $acc[0]->updated_at = date("Y-m-d H:i:s");
            $acc[0]->update();
            $result['success'] = true;
            $result['data'] = $myTicketing;
            $result['msg'] = "Data Updated";
            $result['code'] = "200";
        } else {
            $result['data'] = null;
            $result['msg'] = "failed";
            $result['success'] = false;