From: marina Date: Tue, 22 Jul 2025 11:53:41 +0000 (+0300) Subject: ERP-438 Доработка эндпойнтов X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=a58c2ed687aeb50fa757825dd352fb0a9384921a;p=erp24_rep%2Fyii-erp24%2F.git ERP-438 Доработка эндпойнтов --- diff --git a/erp24/api2/controllers/ClientController.php b/erp24/api2/controllers/ClientController.php index d557ef69..84d76791 100644 --- a/erp24/api2/controllers/ClientController.php +++ b/erp24/api2/controllers/ClientController.php @@ -700,16 +700,20 @@ class ClientController extends BaseController Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $data = json_decode(Yii::$app->request->getRawBody(), true); - $clientId = $data['client_id'] ?? null; $orderId = $data['order_id'] ?? null; $phone = $data['phone'] ?? null; $pointsToUse = $data['points_to_use'] ?? null; $comment = $data['comment'] ?? null; - if (!$clientId || !$orderId || !$phone || !$pointsToUse) { + if (!$orderId || !$phone || !$pointsToUse) { return $this->asJson(['error' => ['code' => 400, 'message' => 'Недостаточно параметров']]); } + $clientId = Users::findOne(['phone' => $phone])->id ?? null; + if (!$clientId) { + return $this->asJson(['error' => ['code' => 404, 'message' => 'Пользователь не найден']]); + } + $totalBonus = (int)UsersBonus::find() ->select([new \yii\db\Expression("SUM(CASE WHEN tip = 'plus' THEN bonus ELSE 0 END) - SUM(CASE WHEN tip = 'minus' THEN bonus ELSE 0 END)")]) ->where(['phone' => $phone]) @@ -721,7 +725,7 @@ class ClientController extends BaseController $sale = Sales::find() ->andWhere(['number' => $orderId]) - ->andWhere(['phone' => $clientId]) + ->andWhere(['phone' => $phone]) ->andWhere(['operation' => 'Продажа']) ->one(); @@ -732,6 +736,7 @@ class ClientController extends BaseController if (UsersBonus::find() ->andFilterWhere(['phone' => $phone]) ->andFilterWhere(['user_id' => $clientId]) + ->andFilterWhere(['phone' => $phone]) ->andFilterWhere(['tip' => 'minus']) ->one()) { return $this->asJson([ @@ -747,6 +752,7 @@ class ClientController extends BaseController ->alias('ubl') ->leftJoin('bonus_levels bl', 'bl.alias = ubl.bonus_level') ->andFilterWhere(['user_id' => $clientId]) + ->andFilterWhere(['phone' => $phone]) ->andFilterWhere(['check_id' => $sale->id]) ->andFilterWhere(['ubl.active' => 1]) ->select('cashback_rate') @@ -806,19 +812,24 @@ class ClientController extends BaseController Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $data = json_decode(Yii::$app->request->getRawBody(), true); - $clientId = $data['client_id'] ?? null; $orderId = $data['order_id'] ?? null; $phone = $data['phone'] ?? null; $pointsToAdd = $data['points_to_add'] ?? null; $comment = $data['comment'] ?? null; - if (!$clientId || !$orderId || !$phone || !$pointsToAdd) { + if (!$orderId || !$phone || !$pointsToAdd) { return $this->asJson(['error' => ['code' => 400, 'message' => 'Недостаточно параметров']]); } + + $clientId = Users::findOne(['phone' => $phone])->id ?? null; + if (!$clientId) { + return $this->asJson(['error' => ['code' => 404, 'message' => 'Пользователь не найден']]); + } + $sale = Sales::find() ->andWhere(['number' => $orderId]) - ->andWhere(['phone' => $clientId]) + ->andWhere(['phone' => $phone]) ->andWhere(['operation' => 'Продажа']) ->one(); @@ -881,7 +892,7 @@ class ClientController extends BaseController 'code' => 200, 'status' => 'success', 'data' => [ - 'client_id' => $clientId, + 'phone' => $phone, 'order_id' => $orderId, 'addedPoints' => $pointsToAdd, 'totalPoints' => $totalBonus @@ -895,16 +906,15 @@ class ClientController extends BaseController Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $data = json_decode(Yii::$app->request->getRawBody(), true); - $clientId = $data['client_id'] ?? null; $phone = $data['phone'] ?? null; - if (!$clientId || !$phone) { + if (!$phone) { return $this->asJson(['error' => ['code' => 400, 'message' => 'Недостаточно параметров']]); } + $user = Users::find() ->andFilterWhere(['phone' => $phone]) - ->andFilterWhere(['id' => $clientId]) ->one(); if (!$user) { @@ -921,7 +931,7 @@ class ClientController extends BaseController ]) ->leftJoin('bonus_levels bl', 'bl.alias = ubl.bonus_level AND bl.active = 1') ->andFilterWhere(['ubl.phone' => $phone]) - ->andFilterWhere(['ubl.user_id' => $clientId]) + ->andFilterWhere(['ubl.user_id' => $user->id]) ->andFilterWhere(['ubl.active' => 1]) ->asArray() ->one(); @@ -938,7 +948,7 @@ class ClientController extends BaseController return $this->asJson([ 'response' => [ - 'client_id' => $clientId, + 'phone' => $phone, 'bonus_level' => $bonusLevel['bonus_level'], 'current_points' => $bonusLevel['current_points'], 'next_points' => $nextLevel['next_points'] ?? null,