var substringMatcher = function (strs) {
return function findMatches(q, cb) {
var matches, substrRegex;
substrRegex = new RegExp(q, 'i');
matches = strs.map(function (str) {
return {pos: str.search(substrRegex), str: str};
}).filter(function (a) {
return a.pos > 0;
}).sort(function (a, b) {
return a.pos > b.pos;
}).map(function (a) {
return a.str;
});
cb(matches);
};
};
$f = function ($f, $categories, $lft = 0, $rgt = null, $depth = 1) {
if (!$categories) {
return '';
}
$result = '';
foreach ($categories as $k => $category) {
$catId = $category->id;
$catLft = $category->lft;
$catRgt = $category->rgt;
$catDepth = $category->depth;
if ($catDepth != $depth || $catLft < $lft + 1 || ($rgt !== null && $catRgt > $rgt)) {
continue;
}
$result .= $f($f, $categories, $catLft, $catRgt, $catDepth + 1);
}
return $result;
};
UPDATE users u SET u.balance = u.balance + ((SELECT SUM(d.sum) FROM user_deposits d WHERE d.user_id=u.id)/100*5)
$(function() {
// code
});