|
@@ -6,8 +6,13 @@ class Info
|
|
|
public function dec_commit(){}
|
|
public function dec_commit(){}
|
|
|
public function dec($id, $cash)
|
|
public function dec($id, $cash)
|
|
|
{
|
|
{
|
|
|
- $sql = 'UPDATE {table} SET cash = cash - :amount, balance = COALESCE(balance, credit + cash) - :amount WHERE id = :id AND COALESCE(balance, credit + cash) >= :amount';
|
|
|
|
|
- $bind = [':amount' => $cash, ':id' => $id];
|
|
|
|
|
|
|
+ $sql = 'UPDATE {table} SET cash = cash - :cash_dec, balance = COALESCE(balance, credit + cash) - :balance_dec WHERE id = :id AND COALESCE(balance, credit + cash) >= :need_amount';
|
|
|
|
|
+ $bind = [
|
|
|
|
|
+ ':cash_dec' => $cash,
|
|
|
|
|
+ ':balance_dec' => $cash,
|
|
|
|
|
+ ':need_amount' => $cash,
|
|
|
|
|
+ ':id' => $id,
|
|
|
|
|
+ ];
|
|
|
$statement = Dever::db('seller/info')->query($sql, $bind, ['method' => 'update']);
|
|
$statement = Dever::db('seller/info')->query($sql, $bind, ['method' => 'update']);
|
|
|
return $statement->rowCount() > 0;
|
|
return $statement->rowCount() > 0;
|
|
|
}
|
|
}
|
|
@@ -16,8 +21,12 @@ class Info
|
|
|
public function inc_commit(){}
|
|
public function inc_commit(){}
|
|
|
public function inc($id, $cash)
|
|
public function inc($id, $cash)
|
|
|
{
|
|
{
|
|
|
- $sql = 'UPDATE {table} SET cash = cash + :amount, balance = COALESCE(balance, credit + cash) + :amount WHERE id = :id';
|
|
|
|
|
- $bind = [':amount' => $cash, ':id' => $id];
|
|
|
|
|
|
|
+ $sql = 'UPDATE {table} SET cash = cash + :cash_inc, balance = COALESCE(balance, credit + cash) + :balance_inc WHERE id = :id';
|
|
|
|
|
+ $bind = [
|
|
|
|
|
+ ':cash_inc' => $cash,
|
|
|
|
|
+ ':balance_inc' => $cash,
|
|
|
|
|
+ ':id' => $id,
|
|
|
|
|
+ ];
|
|
|
$statement = Dever::db('seller/info')->query($sql, $bind, ['method' => 'update']);
|
|
$statement = Dever::db('seller/info')->query($sql, $bind, ['method' => 'update']);
|
|
|
return $statement->rowCount() > 0;
|
|
return $statement->rowCount() > 0;
|
|
|
}
|
|
}
|