$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'];
$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]);
}
}