1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php /** Created by Anton on 28.01.2020. */
- require '../yiiInit.php';
- use app\models\entity\Log;
- use app\models\entity\Tmc;
- use app\models\entity\TmcStatus;
- use app\models\entity\TmcType;
- use app\models\entity\UserDevice;
- use yii\helpers\Url;
- $userId = (int) $_POST['userId'];
- $deviceId = (int) $_POST['deviceId'];
- $log = new Log();
- $log->tmc = $deviceId;
- $log->employee = $userId;
- $log->receipt_date = (new DateTime())->format('Y-m-d H:i:s');
- $log->save();
- $tmc = Tmc::findOne($deviceId);
- $tmc->status = TmcStatus::TMC_STATUS_IN_STORAGE;
- $tmc->employee = 0;
- $tmc->save();
- $userDevice = UserDevice::findOne(['employee' => $userId]);
- switch ($tmc->tmc_type) {
- case TmcType::TMC_TYPE_CAMERA:
- $userDevice->camera = 0;
- break;
- case TmcType::TMC_TYPE_OIL_METER:
- $userDevice->oil_meter = 0;
- break;
- case TmcType::TMC_TYPE_PHONE:
- $userDevice->phone = 0;
- break;
- }
- if ($userDevice->camera || $userDevice->oil_meter || $userDevice->phone) {
- $userDevice->save();
- } else {
- $userDevice->delete();
- }
- Yii::$app->response->redirect(Url::to($_SERVER['HTTP_REFERER']))->send();
|