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])
$sale = Sales::find()
->andWhere(['number' => $orderId])
- ->andWhere(['phone' => $clientId])
+ ->andWhere(['phone' => $phone])
->andWhere(['operation' => 'Продажа'])
->one();
if (UsersBonus::find()
->andFilterWhere(['phone' => $phone])
->andFilterWhere(['user_id' => $clientId])
+ ->andFilterWhere(['phone' => $phone])
->andFilterWhere(['tip' => 'minus'])
->one()) {
return $this->asJson([
->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')
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();
'code' => 200,
'status' => 'success',
'data' => [
- 'client_id' => $clientId,
+ 'phone' => $phone,
'order_id' => $orderId,
'addedPoints' => $pointsToAdd,
'totalPoints' => $totalBonus
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) {
])
->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();
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,