|
|
@@ -6,8 +6,8 @@ class Info
|
|
|
public function dec_commit(){}
|
|
|
public function dec($id, $cash)
|
|
|
{
|
|
|
- $sql = 'UPDATE {table} SET cash = cash - :amount WHERE id = :id AND (credit + cash) >= :need';
|
|
|
- $bind = [':amount' => $cash, ':id' => $id, ':need' => $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];
|
|
|
$statement = Dever::db('seller/info')->query($sql, $bind, ['method' => 'update']);
|
|
|
return $statement->rowCount() > 0;
|
|
|
}
|
|
|
@@ -16,8 +16,8 @@ class Info
|
|
|
public function inc_commit(){}
|
|
|
public function inc($id, $cash)
|
|
|
{
|
|
|
- $sql = 'UPDATE {table} SET cash = cash + :cash WHERE id = :id';
|
|
|
- $bind = [':cash' => $cash, ':id' => $id];
|
|
|
+ $sql = 'UPDATE {table} SET cash = cash + :amount, balance = COALESCE(balance, credit + cash) + :amount WHERE id = :id';
|
|
|
+ $bind = [':amount' => $cash, ':id' => $id];
|
|
|
$statement = Dever::db('seller/info')->query($sql, $bind, ['method' => 'update']);
|
|
|
return $statement->rowCount() > 0;
|
|
|
}
|