From e9fe1eb81d566feb2dbdadddb601644aa73f5e4b Mon Sep 17 00:00:00 2001 From: Aleksey Filippov Date: Wed, 14 May 2025 11:58:44 +0300 Subject: [PATCH] =?utf8?q?=D0=BE=D1=82=D0=BB=D0=B0=D0=B4=D0=BA=D0=B0=20?= =?utf8?q?=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4?= =?utf8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=BE=D1=82=20=D1=81=D0=B0?= =?utf8?q?=D0=B9=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/BonusController.php | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/erp24/api2/controllers/BonusController.php b/erp24/api2/controllers/BonusController.php index 78b797a2..6acd83a3 100644 --- a/erp24/api2/controllers/BonusController.php +++ b/erp24/api2/controllers/BonusController.php @@ -1658,49 +1658,61 @@ class BonusController extends BaseController $fl = date('_Y_m_d__H_i_s_'); file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '.json', PHP_EOL . implode(',', $requestTest)); + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', $requestTest)); try { $result = Json::decode($request); + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); } catch (\Exception $ex) { return $this->asJson(['error' => ['code' => 400, 'message' => 'Json body invalid']]); + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); } $__API_PARAMS = ['phone', 'description', 'tip_sale', 'bonus', 'date_end']; foreach ($__API_PARAMS as $paramName) { if (!isset($result[$paramName])) { + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); if ($paramName != 'phone') { + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); LogService::apiErrorLog(json_encode(["error_id" => 1, "error" => "$paramName is required"], JSON_UNESCAPED_UNICODE)); } + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); return $this->asJson(["error_id" => 1, "error" => "$paramName is required"]); } } - + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); // if (!in_array($result['tip_sale'], ['podarok', 'senat', 'nino802', 'sale', '14feb', '23feb', '8mar', 'quest001'])) { + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); return $this->asJson(["error_id" => 1.1, "error" => "tip_sale не разрешён (podarok, senat, nino802)"]); } $phone = ClientHelper::phoneClear($result['phone']); + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); if (!ClientHelper::phoneVerify($phone)) { + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); return $this->asJson(["error_id" => 1.2, "error" => "phone is required"]); } $result['phone'] = $phone; $stop = UsersStopList::find()->select(['phone'])->where(['phone' => $result['phone']])->one(); + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); if ($stop) { + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); return $this->asJson(["error_id" => 4, "error" => 'Номер телефона числится в стоп листе']); } $bonus = min((int)$result['bonus'], 1000); - + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); $found = UsersBonus::find()->where(['phone' => $phone])->andWhere(['>=', 'date_start', date('Y-m-d H:i:s', time() - self::$YEAR_PERIOD * 86400)]) ->andWhere(['tip_sale' => $result['tip_sale']])->andWhere(['tip' => 'plus'])->andWhere(['bonus' => $bonus])->one(); - + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); if ($found) { + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); return $this->asJson(["error_id" => 3, "error" => 'Бонусы уже начисляли']); } - + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); $userBonus = new UsersBonus; $userBonus->phone = $phone; $userBonus->name = $result['description']; @@ -1713,11 +1725,13 @@ class BonusController extends BaseController $userBonus->date_start = $result['date_start'] ?? $userBonus->date; $userBonus->date_end = $result['date_end']; $userBonus->save(); + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); if ($userBonus->getErrors()) { + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); LogService::apiErrorLog(json_encode(["error_id" => 2, "error" => $userBonus->getErrors()], JSON_UNESCAPED_UNICODE)); return $this->asJson(["error_id" => 2, "error" => $userBonus->getErrors()]); } - + file_put_contents(self::OUT_DIR . '/add_bonuses_' . $fl . '_log.json', PHP_EOL . implode(',', __LINE__)); return $this->asJson(['response' => true]); } } -- 2.39.5