From a113544075dd1e9eaa29e48b51b42f4083fcc186 Mon Sep 17 00:00:00 2001 From: saparatayev Date: Fri, 2 Sep 2022 08:30:50 +0500 Subject: [PATCH] feat: gift after signup, artisan command gift to all users --- modules/system/lang/en/validation.php | 1 + modules/system/lang/ru/validation.php | 1 + modules/system/lang/tm/validation.php | 1 + .../rainlab/notify/models/Notification.php | 19 +++++ .../components/notifications/desktop.htm | 3 + .../components/notifications/mobile.htm | 3 + plugins/tps/birzha/Plugin.php | 9 ++- plugins/tps/birzha/actions/MakeGiftAction.php | 64 +++++++++++++++ .../birzha/actions/makegiftaction/fields.yaml | 9 +++ .../tps/birzha/console/MakeGiftToUsers.php | 77 +++++++++++++++++++ .../tps/birzha/events/PaymentGiftedEvent.php | 29 +++++++ plugins/tps/birzha/models/Payment.php | 35 ++++++++- plugins/vdomah/jwtauth/routes.php | 19 ++++- themes/birzha/assets/css/main.css | 14 ++++ 14 files changed, 278 insertions(+), 6 deletions(-) create mode 100644 plugins/tps/birzha/actions/MakeGiftAction.php create mode 100644 plugins/tps/birzha/actions/makegiftaction/fields.yaml create mode 100644 plugins/tps/birzha/console/MakeGiftToUsers.php create mode 100644 plugins/tps/birzha/events/PaymentGiftedEvent.php diff --git a/modules/system/lang/en/validation.php b/modules/system/lang/en/validation.php index 0e80ae2fb..38d9572c4 100644 --- a/modules/system/lang/en/validation.php +++ b/modules/system/lang/en/validation.php @@ -139,6 +139,7 @@ return [ 'thanks_for_posting' => 'Thank you for your request!', 'new_message' => 'New message', 'payment_reviewed' => 'Payment has been reviewed', + 'payment_gifted' => 'You have a gift payment', 'product_reviewed' => 'Post has been reviewed', 'api' => [ 'sign_up_excp' => 'Registration error', diff --git a/modules/system/lang/ru/validation.php b/modules/system/lang/ru/validation.php index 97f426434..41d8a2143 100644 --- a/modules/system/lang/ru/validation.php +++ b/modules/system/lang/ru/validation.php @@ -139,6 +139,7 @@ return [ 'thanks_for_posting' => 'Спасибо за оставленный вами запрос!', 'new_message' => 'Новое сообщение', 'payment_reviewed' => 'Платеж рассмотрен', + 'payment_gifted' => 'У вас подарочный платеж', 'product_reviewed' => 'Объявление рассмотрено', 'api' => [ 'sign_up_excp' => 'Ошибка при регистрации', diff --git a/modules/system/lang/tm/validation.php b/modules/system/lang/tm/validation.php index 85428dccf..64cfcda36 100644 --- a/modules/system/lang/tm/validation.php +++ b/modules/system/lang/tm/validation.php @@ -141,6 +141,7 @@ return [ 'thanks_for_posting' => 'Ugradan ýüzlenmäňiz üçin sag boluň!', 'new_message' => 'Täze hat', 'payment_reviewed' => 'Töleg gözden geçirildi', + 'payment_gifted' => 'Sowgat Töleg', 'product_reviewed' => 'Bildiriş gözden geçirildi', 'api' => [ 'sign_up_excp' => 'Hasaba alyş ýalňyşy', diff --git a/plugins/rainlab/notify/models/Notification.php b/plugins/rainlab/notify/models/Notification.php index 83ee841a0..57aa20c69 100644 --- a/plugins/rainlab/notify/models/Notification.php +++ b/plugins/rainlab/notify/models/Notification.php @@ -4,6 +4,7 @@ use Guzzle\Http\Url; use Model; use Markdown; use TPS\Birzha\Events\MessageReceivedEvent; +use TPS\Birzha\Events\PaymentGiftedEvent; use TPS\Birzha\Events\PaymentReviewedEvent; use TPS\Birzha\Events\ProductReviewedEvent; @@ -136,6 +137,9 @@ class Notification extends Model } elseif($e instanceof PaymentReviewedEvent) { return trans('validation.payment_reviewed'); + } elseif($e instanceof PaymentGiftedEvent) { + + return trans('validation.payment_gifted'); } return 'Unknown type notification'; @@ -173,6 +177,13 @@ class Notification extends Model 'en' => trans('validation.payment_reviewed', [], 'en'), 'tm' => trans('validation.payment_reviewed', [], 'tm'), ]; + } elseif($e instanceof PaymentGiftedEvent) { + + return [ + 'ru' => trans('validation.payment_gifted', [], 'ru'), + 'en' => trans('validation.payment_gifted', [], 'en'), + 'tm' => trans('validation.payment_gifted', [], 'tm'), + ]; } return 'Unknown type notification'; @@ -198,6 +209,11 @@ class Notification extends Model } elseif($e instanceof PaymentReviewedEvent) { return 'balance_history_screen'; + + } elseif($e instanceof PaymentGiftedEvent) { + + return 'balance_history_screen'; + } return 'main_screen'; @@ -222,6 +238,9 @@ class Notification extends Model } elseif($e instanceof PaymentReviewedEvent) { + return \Url::to('/balans-taryhy'); + } elseif($e instanceof PaymentGiftedEvent) { + return \Url::to('/balans-taryhy'); } diff --git a/plugins/rainlab/userplus/components/notifications/desktop.htm b/plugins/rainlab/userplus/components/notifications/desktop.htm index 504793da6..d4b4a4689 100644 --- a/plugins/rainlab/userplus/components/notifications/desktop.htm +++ b/plugins/rainlab/userplus/components/notifications/desktop.htm @@ -1,6 +1,9 @@
+ {% if hasNotifications %} +
+ {% endif %} bell

{{ 'auth.notifications'|_ }}

diff --git a/plugins/rainlab/userplus/components/notifications/mobile.htm b/plugins/rainlab/userplus/components/notifications/mobile.htm index b01979003..bb9a2c087 100644 --- a/plugins/rainlab/userplus/components/notifications/mobile.htm +++ b/plugins/rainlab/userplus/components/notifications/mobile.htm @@ -1,5 +1,8 @@
+ {% if hasNotifications %} +
+ {% endif %} bell

diff --git a/plugins/tps/birzha/Plugin.php b/plugins/tps/birzha/Plugin.php index 0e0e4c056..1cb487e20 100644 --- a/plugins/tps/birzha/Plugin.php +++ b/plugins/tps/birzha/Plugin.php @@ -15,6 +15,9 @@ use TPS\Birzha\Models\Offer; use Event; use Illuminate\Http\Resources\Json\Resource; use Session; +use TPS\Birzha\Actions\MakeGiftAction; +use Tps\Birzha\Console\MakeGiftToUsers; + /** * Birzha Plugin Information File */ @@ -43,6 +46,7 @@ class Plugin extends PluginBase public function register() { $this->registerConsoleCommand('birzha:databasebackup', DatabaseBackUp::class); + $this->registerConsoleCommand('birzha:gifttousers', MakeGiftToUsers::class); } public function registerListColumnTypes() { @@ -204,6 +208,7 @@ class Plugin extends PluginBase \RainLab\Notify\Classes\Notifier::bindEvents([ 'tps.payment.received' => \TPS\Birzha\Events\PaymentRecievedEvent::class, 'tps.payment.reviewed' => \TPS\Birzha\Events\PaymentReviewedEvent::class, + 'tps.payment.gifted' => \TPS\Birzha\Events\PaymentGiftedEvent::class, 'tps.product.received' => \TPS\Birzha\Events\ProductRecievedEvent::class, 'tps.product.reviewed' => \TPS\Birzha\Events\ProductReviewedEvent::class, 'tps.message.received' => \TPS\Birzha\Events\MessageReceivedEvent::class, @@ -273,6 +278,7 @@ class Plugin extends PluginBase 'events' => [ \TPS\Birzha\Events\PaymentRecievedEvent::class, \TPS\Birzha\Events\PaymentReviewedEvent::class, + \TPS\Birzha\Events\PaymentGiftedEvent::class, \TPS\Birzha\Events\ProductRecievedEvent::class, \TPS\Birzha\Events\ProductReviewedEvent::class, \TPS\Birzha\Events\MessageReceivedEvent::class, @@ -282,7 +288,8 @@ class Plugin extends PluginBase 'actions' => [ SendSMSAction::class, MailToAdminsAction::class, - VerifyAction::class + VerifyAction::class, + MakeGiftAction::class ], 'conditions' => [ \RainLab\User\NotifyRules\UserAttributeCondition::class diff --git a/plugins/tps/birzha/actions/MakeGiftAction.php b/plugins/tps/birzha/actions/MakeGiftAction.php new file mode 100644 index 000000000..bdb96e1d1 --- /dev/null +++ b/plugins/tps/birzha/actions/MakeGiftAction.php @@ -0,0 +1,64 @@ + 'Make gift', + 'description' => 'Make gift after user registered', + 'icon' => 'icon-gift' + ]; + } + /** + * Defines validation rules for the custom fields. + * @return array + */ + public function defineValidationRules() + { + return [ + 'amount' => 'required|numeric' + ]; + } + /** + * Field configuration for the action. + */ + public function defineFormFields() + { + return 'fields.yaml'; + } + + public function getTitle() + { + return 'Make gift'; + } + + public function getActionIcon() + { + return 'icon-gift'; + } + + /** + * Triggers this action. + * @param array $params + * @return void + */ + public function triggerAction($params) + { + $newPayment = new Payment; + $newPayment->user_id = $params['user']['id']; + $newPayment->amount = $this->host->amount; + $newPayment->payment_type = Payment::PAYMENT_TYPE_GIFT; + $newPayment->save(); + } +} diff --git a/plugins/tps/birzha/actions/makegiftaction/fields.yaml b/plugins/tps/birzha/actions/makegiftaction/fields.yaml new file mode 100644 index 000000000..a6bffc06c --- /dev/null +++ b/plugins/tps/birzha/actions/makegiftaction/fields.yaml @@ -0,0 +1,9 @@ +# =================================== +# Field Definitions +# =================================== + +fields: + + amount: + cssClass: radio-align + label: Amount diff --git a/plugins/tps/birzha/console/MakeGiftToUsers.php b/plugins/tps/birzha/console/MakeGiftToUsers.php new file mode 100644 index 000000000..b6f722898 --- /dev/null +++ b/plugins/tps/birzha/console/MakeGiftToUsers.php @@ -0,0 +1,77 @@ +argument('amount'); + + if(is_numeric($amount)) { + + $users = User::all(); + + try { + $users->each(function($user) use ($amount) { + $newPayment = new Payment; + $newPayment->user_id = $user->id; + $newPayment->amount = $amount; + $newPayment->payment_type = Payment::PAYMENT_TYPE_GIFT; + $newPayment->save(); + }); + } catch (\Throwable $th) { + Log::info('Artisan make gift to users: ' . $th->getMessage()); + $this->error($th->getMessage()); + } + } else { + $this->info('the argument should be a number'); + } + } + + /** + * Get the console command arguments. + * @return array + */ + protected function getArguments() + { + return [ + ['amount', InputArgument::REQUIRED, 'An amount of the gift payment.', 100] + ]; + } + + /** + * Get the console command options. + * @return array + */ + protected function getOptions() + { + return []; + } +} diff --git a/plugins/tps/birzha/events/PaymentGiftedEvent.php b/plugins/tps/birzha/events/PaymentGiftedEvent.php new file mode 100644 index 000000000..a535d88f9 --- /dev/null +++ b/plugins/tps/birzha/events/PaymentGiftedEvent.php @@ -0,0 +1,29 @@ + 'Payment gifted', + 'description' => 'Payment gifted by admin', + 'group' => 'payment' + ]; + } + + public static function makeParamsFromEvent(array $args, $eventName = null) + { + return [ + 'payment' => array_get($args, 0), + 'user' => array_get($args, 1), + ]; + } + +} diff --git a/plugins/tps/birzha/models/Payment.php b/plugins/tps/birzha/models/Payment.php index 637e2e939..4f4845a45 100644 --- a/plugins/tps/birzha/models/Payment.php +++ b/plugins/tps/birzha/models/Payment.php @@ -16,6 +16,26 @@ class Payment extends Model protected $dates = ['deleted_at']; + /** + * @const string The payment type `gift` + */ + public const PAYMENT_TYPE_GIFT = 'gift'; + /** + * @const string The payment type `bank` + */ + public const PAYMENT_TYPE_BANK = 'bank'; + /** + * @const string The payment type `online` + */ + public const PAYMENT_TYPE_ONLINE = 'online'; + /** + * @const string The payment status `approved` + */ + public const PAYMENT_STATUS_APPROVED = 'approved'; + /** + * @const string The payment status `new` + */ + public const PAYMENT_STATUS_NEW = 'new'; /** * @var string The database table used by the model. @@ -78,13 +98,20 @@ class Payment extends Model { parent::beforeCreate(); if(\App::runningInBackend()) { - $this->payment_type = 'gift'; + $this->payment_type = self::PAYMENT_TYPE_GIFT; + $this->status = self::PAYMENT_STATUS_APPROVED; $this->created_at = Carbon::now(); $this->updated_at = Carbon::now(); } else{ - $this->status = 'new'; + if($this->payment_type == self::PAYMENT_TYPE_GIFT) { // when newly registered user gets gift + + $this->status = self::PAYMENT_STATUS_APPROVED; + } else { + + $this->status = self::PAYMENT_STATUS_NEW; + } } } @@ -92,9 +119,9 @@ class Payment extends Model { parent::afterCreate(); - if($this->payment_type == 'gift'){ + if($this->payment_type == self::PAYMENT_TYPE_GIFT){ $this->createTransaction(); - Event::fire('tps.payment.reviewed',[$this,$this->user]); + Event::fire('tps.payment.gifted',[$this,$this->user]); } } diff --git a/plugins/vdomah/jwtauth/routes.php b/plugins/vdomah/jwtauth/routes.php index 945e4e8cf..09132cb9d 100644 --- a/plugins/vdomah/jwtauth/routes.php +++ b/plugins/vdomah/jwtauth/routes.php @@ -161,6 +161,7 @@ Route::group(['prefix' => 'api'], function() { 'email' => 'required|between:6,191|email|unique:users', 'username' => 'required|numeric|unique:users', 'dial_code' => 'required', + 'password' => 'required:create|between:8,255', ]; $messages = [ @@ -176,7 +177,21 @@ Route::group(['prefix' => 'api'], function() { ], ]; - // username should be concatenated with username in order to check - validate + /** + * initial validation - + * $credentials['dial_code'], $credentials['username'] can throw error if not set + */ + $validation = \Validator::make($credentials, $rules, $messages); + if ($validation->fails()) { + + $errorResponse = $validation->errors(); + + $errorResponse = reset($errorResponse); + + return Response::json(['error' => reset($errorResponse)[0]], 400); + } + + // dial_code should be concatenated with username in order to check - validate // if a user (with dial_code + username) already exists $credentialsToValidate = array_merge($credentials,[ 'username' => $credentials['dial_code'] . $credentials['username'] @@ -233,6 +248,8 @@ Route::group(['prefix' => 'api'], function() { } $token = JWTAuth::fromUser($userModel); + + Event::fire('rainlab.user.register', $userModel); return Response::json(compact('token', 'user')); }); diff --git a/themes/birzha/assets/css/main.css b/themes/birzha/assets/css/main.css index c78720616..c33801298 100644 --- a/themes/birzha/assets/css/main.css +++ b/themes/birzha/assets/css/main.css @@ -1386,6 +1386,19 @@ li { .natification_icon { width: 14px; height: 16px; + position: relative; +} + +.natification_icon .natification_red-dot, +.mobile_user-item-icon .natification_red-dot { + display: block; + width: 8px; + height: 8px; + background-color: red; + border-radius: 50%; + position: absolute; + right: -6px; + top: -6px; } .natification_icon img { @@ -6224,6 +6237,7 @@ input::-webkit-calendar-picker-indicator { width: 20px; height: 20px; margin-right: 15px; + position: relative; } .mobile_user-item-icon img {