feat: gift after signup, artisan command gift to all users

This commit is contained in:
saparatayev 2022-09-02 08:30:50 +05:00
parent cdcef1822e
commit a113544075
14 changed files with 278 additions and 6 deletions

View File

@ -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',

View File

@ -139,6 +139,7 @@ return [
'thanks_for_posting' => 'Спасибо за оставленный вами запрос!',
'new_message' => 'Новое сообщение',
'payment_reviewed' => 'Платеж рассмотрен',
'payment_gifted' => 'У вас подарочный платеж',
'product_reviewed' => 'Объявление рассмотрено',
'api' => [
'sign_up_excp' => 'Ошибка при регистрации',

View File

@ -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',

View File

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

View File

@ -1,6 +1,9 @@
<div class="notification_box">
<div class="notification_header" onclick="toggleNotificationsPopover(this)">
<div class="natification_icon">
{% if hasNotifications %}
<div class="natification_red-dot"></div>
{% endif %}
<img src="{{'assets/images/svg/bell.svg'|theme}}" alt="bell">
</div>
<p>{{ 'auth.notifications'|_ }}</p>

View File

@ -1,5 +1,8 @@
<div class="mobile_user-item accord" onclick="toggleNotificationsPopover(this)">
<div class="mobile_user-item-icon">
{% if hasNotifications %}
<div class="natification_red-dot"></div>
{% endif %}
<img src="{{ 'assets/images/svg/bell-b.svg'|theme }}" alt="bell">
</div>
<p class="mobile_user-item-text">

View File

@ -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

View File

@ -0,0 +1,64 @@
<?php
namespace TPS\Birzha\Actions;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;
use RainLab\Notify\Classes\ActionBase;
use TPS\Birzha\Models\Payment;
class MakeGiftAction extends ActionBase
{
/**
* Returns information about this event, including name and description.
*/
public function actionDetails()
{
return [
'name' => '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();
}
}

View File

@ -0,0 +1,9 @@
# ===================================
# Field Definitions
# ===================================
fields:
amount:
cssClass: radio-align
label: Amount

View File

@ -0,0 +1,77 @@
<?php namespace Tps\Birzha\Console;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use RainLab\User\Models\User;
use Symfony\Component\Console\Input\InputArgument;
use TPS\Birzha\Models\Payment;
class MakeGiftToUsers extends Command
{
/**
* @var string The console command name.
*/
protected $name = 'birzha:gifttousers';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'birzha:gifttousers {amount}';
/**
* @var string The console command description.
*/
protected $description = 'Makes a gift to every registered user.';
/**
* Execute the console command.
* @return void
*/
public function handle()
{
$amount = $this->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 [];
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace TPS\Birzha\Events;
use RainLab\Notify\Classes\EventBase;
class PaymentGiftedEvent extends EventBase
{
/**
* Returns information about this event, including name and description.
*/
public function eventDetails()
{
return [
'name' => '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),
];
}
}

View File

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

View File

@ -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']
@ -234,6 +249,8 @@ Route::group(['prefix' => 'api'], function() {
$token = JWTAuth::fromUser($userModel);
Event::fire('rainlab.user.register', $userModel);
return Response::json(compact('token', 'user'));
});

View File

@ -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 {