now() public méthode

Method returns generated interval function as an insert/update function
public now ( string $diff = null, string $func = "NOW()" ) : array
$diff string interval in the formats: "1", "-1d" or "- 1 day" -- For interval - 1 day Supported intervals [s]econd, [m]inute, [h]hour, [d]day, [M]onth, [Y]ear Default null;
$func string Initial date
Résultat array
function order_paid()
{
    require_once './submodules/php-mysqli-database-class/MysqliDb.php';
    require './includes/config.php';
    $db = new MysqliDb($db_host, $db_user, $db_pass, $db_name);
    $payid = $_GET['out_trade_no'];
    $aPayId = explode('_', $payid);
    $mtrid = $aPayId[1];
    $params = json_encode($_GET);
    //验证是否已经支付过
    $db->where("mtr_id = '{$mtrid}'")->get('mark_trafficpolice_reward');
    if ($db->count == 0) {
        $aNew = array('mtr_id' => $mtrid, 'pay_id' => $payid, 'pay_success' => 1, 'pay_money' => $_GET['total_fee'], 'pay_date' => $_GET['gmt_payment'], 'pay_params' => $params, 'created_date' => $db->now());
        $id = $db->insert('mark_trafficpolice_reward', $aNew);
        //给用户增加余额
        $sql = "SELECT mt.user_id,u.user_money FROM `mark_trafficpolice` mt\n            LEFT JOIN mark_trafficpolice_received mtr ON mt.id=mtr.mt_id\n            LEFT JOIN users u ON u.user_id=mt.user_id\n            WHERE mtr.id= '{$mtrid}'";
        $aUser = $db->rawQuery($sql);
        if ($db->count) {
            $aUpdate = array('user_money' => $aUser[0]['user_money'] + $_GET['total_fee'], 'updated_date' => $db->now());
            $db->where('user_id', $aUser[0]['user_id']);
            $db->update('users', $aUpdate);
        }
    } else {
        echo "already rewarded";
    }
}
echo '		<title>Sign Up</title>' . "\n";
echo '		<link rel="stylesheet" type="text/css" href="css/login_form.css">' . "\n";
echo '	</head>' . "\n";
echo '	<body>' . "\n";
if (isset($_POST['submitted']) && $_POST['pass'] === $_POST['repass']) {
    $submited = $_POST['submitted'];
    $name = explode(" ", $_POST['name']);
    $fName = $name[0];
    $lName = $name[1];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $intro = $_POST['intro'];
    $pass = $_POST['pass'];
    $options = ['cost' => 17];
    $pass = password_hash($pass, PASSWORD_BCRYPT, $options) . "\n";
    $data = array('password' => $pass, 'active' => true, 'fName' => $fName, 'lName' => $lName, 'email' => $email, 'phone' => $phone, 'intro' => $intro, 'createdAt' => $db->now(), 'expires' => $db->now('+1Y'));
    $id = $db->insert('Users', $data);
    if ($id) {
        echo 'user was created. Id=' . $id;
    } else {
        echo 'insert failed: ' . $db->getLastError();
    }
} else {
    echo '		<form name="signup" action="" method="post" autocomplete="on">' . "\n";
    echo '		<ul>' . "\n";
    echo '			<li>' . "\n";
    echo '				<h2>Contact Us</h2>' . "\n";
    echo '				<span class="required_notification">* Denotes Required Field</span>' . "\n";
    echo '			</li>' . "\n";
    echo '			<li>' . "\n";
    echo '				<label for="name"><font color="black">Name:</font></label>' . "\n";
/**
 * @description Modifica un pedido
 * @param $product
 */
function updatePedido($pedido)
{
    $db = new MysqliDb();
    $db->startTransaction();
    $item_decoded = checkPedido(json_decode($pedido));
    $db->where('pedido_id', $item_decoded->pedido_id);
    $data = array('proveedor_id' => $item_decoded->proveedor_id, 'usuario_id' => $item_decoded->usuario_id, 'fecha_entrega' => $item_decoded->fecha_entrega != '0000-00-00 00:00:00' ? $db->now() : $item_decoded->fecha_entrega, 'total' => $item_decoded->total, 'iva' => $item_decoded->iva, 'sucursal_id' => $item_decoded->sucursal_id);
    $result = $db->update('pedidos', $data);
    if ($result) {
        $db->where('pedido_id', $item_decoded->pedido_id);
        $db->delete('pedidos_detalles');
        foreach ($item_decoded->pedidos_detalles as $pedido_detalle) {
            $subitem_decoded = checkPedidodetalle($pedido_detalle);
            $data = array('pedido_id' => $item_decoded->pedido_id, 'producto_id' => $subitem_decoded->producto_id, 'cantidad' => $subitem_decoded->cantidad, 'precio_unidad' => $subitem_decoded->precio_unidad, 'precio_total' => $subitem_decoded->precio_total);
            $result = $db->insert('pedidos_detalles', $data);
            if ($result > -1) {
            } else {
                $db->rollback();
                echo json_encode(-1);
                return;
            }
        }
        $db->commit();
        echo json_encode($result);
    } else {
        $db->rollback();
        echo json_encode(-1);
    }
}
Exemple #4
0
 public function login($email, $password)
 {
     $db = new MysqliDb(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
     $db->where("email", $email);
     $user = $db->getOne("users");
     //Salt and hash password for checking
     $password = $user['user_salt'] . $password;
     $password = $this->hashData($password);
     //Check email and password hash match database row
     //Convert to boolean
     $is_active = (bool) $user['is_active'];
     $verified = (bool) $user['is_verified'];
     if ($password == $user['password']) {
         if ($is_active == true) {
             if ($verified == true) {
                 //Email/Password combination exists, set sessions
                 //First, generate a random string.
                 $random = $this->randomString();
                 //Build the token
                 $token = $_SERVER['HTTP_USER_AGENT'] . $random;
                 $token = $this->hashData($token);
                 //Setup sessions vars
                 $_SESSION['token'] = $token;
                 $_SESSION['user_id'] = $user['id'];
                 $_SESSION['data'] = json_decode($user['data'], true);
                 $_SESSION['fname'] = $user['fname'];
                 $_SESSION['lname'] = $user['lname'];
                 $_SESSION['email'] = $user['email'];
                 $_SESSION['is_admin'] = $user['is_admin'];
                 $_SESSION['is_super'] = $user['is_super'];
                 $_SESSION['is_provider'] = $user['is_provider'];
                 $db->where('user_id', $user['id']);
                 $db->delete('logged_in_member');
                 //Insert new logged_in_member record for user
                 $data = array('user_id' => $user['id'], 'session_id' => session_id(), 'token' => $token, 'is_provider' => $user['is_provider'], 'is_admin' => $user['is_admin'], 'is_super' => $user['is_super'], 'createdAt' => $db->now());
                 $id = $db->insert('logged_in_member', $data);
                 if ($id) {
                     return 10;
                 } else {
                     return 5;
                 }
             } else {
                 //Not verified
                 //Email/Password combination exists, set sessions
                 //First, generate a random string.
                 $random = $this->randomString();
                 //Build the token
                 $token = $_SERVER['HTTP_USER_AGENT'] . $random;
                 $token = $this->hashData($token);
                 //Setup sessions vars
                 session_start();
                 $_SESSION['token'] = $token;
                 $_SESSION['user_id'] = $user['id'];
                 $_SESSION['data'] = json_decode($user['data'], true);
                 $_SESSION['fname'] = $user['fname'];
                 $_SESSION['lname'] = $user['lname'];
                 $_SESSION['email'] = $user['email'];
                 $_SESSION['is_admin'] = $user['is_admin'];
                 $_SESSION['is_super'] = $user['is_super'];
                 $_SESSION['is_provider'] = $user['is_provider'];
                 //Delete old logged_in_member records for user
                 //Insert new logged_in_member record for user
                 $db->where('user_id', $user['id']);
                 $db->delete('logged_in_member');
                 //Insert new logged_in_member record for user
                 $data = array('user_id' => $user['id'], 'session_id' => session_id(), 'token' => $token, 'is_provider' => $user['is_provider'], 'is_admin' => $user['is_admin'], 'is_super' => $user['is_super'], 'createdAt' => $db->now());
                 $id = $db->insert('logged_in_member', $data);
                 if ($id) {
                     return 1;
                 } else {
                     return 5;
                 }
             }
         } else {
             //Not active
             return 2;
         }
     }
     //No match, reject
     return 4;
 }