/** * Обновление зарплаты исполнителя * * @param array &$ExecutorRepository объект репозитория исполнителя * @param array &$Executor объект исполнителя * @param int $money на сколько изменить зарплату */ function updateSalary(array &$ExecutorRepository, array &$Executor, $money) { $Mysql =& MysqlFactory\createShard(getMysqlFactory($ExecutorRepository), SHARD_CONFIG, getShardId(Executor\getId($Executor))); Mysql\query($Mysql, ' UPDATE ' . DATABASE_NAME . '.' . TABLE_NAME . ' SET SALARY = SALARY + ' . (int) $money . ' WHERE id = ' . (int) Executor\getId($Executor)); Executor\setSalary($Executor, Executor\getSalary($Executor) + (int) $money); }
/** * Выполнение заказа * * @param array &$Controller объект контроллера * * @return array */ function cmdExecute(array &$Controller) { $Request =& getRequest($Controller); $ServiceManager =& getServiceManager($Controller); $orderId = (int) Request\getPostParam($Request, 'orderId'); $token = Request\getPostParam($Request, 'token'); if ($orderId < 1 || is_null($token) || $token !== Session\getToken()) { return ['errorMsg' => 'Неверный id заказа']; } $OrderRepository = ServiceManager\get($ServiceManager, 'OrderRepository'); if (!OrderRepository\deleteFromMysql($OrderRepository, $orderId)) { return ['errorMsg' => 'Такого заказа (уже) нет', 'deleted' => 1]; } $price = OrderRepository\getPriceFromMemcachedAndDeleteIt($OrderRepository, $orderId); $ExecutorRepository = ServiceManager\get($ServiceManager, 'ExecutorRepository'); $ActiveUser = ServiceManager\get($ServiceManager, 'ActiveUser'); $Application = ServiceManager\get($ServiceManager, 'Application'); ExecutorRepository\updateSalary($ExecutorRepository, $ActiveUser, $price - Application\getCommission($Application)); return ['salary' => Executor\getSalary($ActiveUser)]; }