This commit is contained in:
saparatayev 2021-11-22 21:15:10 +05:00
commit 8655daf30a
16 changed files with 228 additions and 20 deletions

View File

@ -50,7 +50,7 @@ class Plugin extends PluginBase
}
public function moneyColumn($value, $column, $record){
return '<span style="color: '.($value > 0 ? 'green':'red').'">'.$value.'tmt</span>';
return '<span style="color: '.($value > 0 ? 'green':'red').'">'.number_format($value,2).' tmt</span>';
}
public function userLinkListColumn($value, $column, $record){

View File

@ -83,6 +83,12 @@ class OfferForm extends ComponentBase
if(isset($data['productForEditing'])) {
$product = Product::find($data['productForEditing']);
//approved edilen produkty prodlenie uchin drafta tayinlamak, bagly transacsiasyny goparmak,
if($product && $product->status == 'approved' && $product->transaction)
{
$product->transaction()->update(['description'=>"Lot #{$product->id} {$product->name} harydyn onki publikasia tolegidir.(bu haryt prodlenia uchin taze transaksia doredilyar)"]);
$product->transaction = null;
}
} else {
$product = new Product;
}
@ -190,8 +196,9 @@ class OfferForm extends ComponentBase
// step3
public function onPublish() {
$user = \Auth::user();
if($user->balance - Settings::getValue('fee') < 0) {
$balance = \Auth::user()->getBalance();
if($balance - Settings::getValue('fee') < 0) {
// ... message about not enough money
throw new ValidationException(['money' => trans('validation.low_balance')]);
} else {

View File

@ -5,9 +5,10 @@ use BackendMenu;
class Transactions extends Controller
{
public $implement = [ 'Backend\Behaviors\ListController' ];
public $implement = ['Backend\Behaviors\ListController','Backend\Behaviors\FormController' ];
public $listConfig = 'config_list.yaml';
public $formConfig = 'config_form.yaml';
public function __construct()
{

View File

@ -0,0 +1,10 @@
scopes:
created_at:
label: Date
type: daterange
conditions: created_at >= ':after' AND created_at <= ':before'
user:
label: Seller
modelClass: RainLab\User\Models\User
nameFrom: name
conditions: user_id in (:filtered)

View File

@ -0,0 +1,10 @@
name: Payments
form: $/tps/birzha/models/transaction/fields.yaml
modelClass: TPS\Birzha\Models\Transaction
defaultRedirect: tps/birzha/transactions
create:
redirect: 'tps/birzha/transactions/update/:id'
redirectClose: tps/birzha/transactions
update:
redirect: tps/birzha/transactions
redirectClose: tps/birzha/transactions

View File

@ -9,3 +9,5 @@ toolbar:
buttons: list_toolbar
search:
prompt: 'backend::lang.list.search_prompt'
recordUrl: 'tps/birzha/transactions/update/:id'
filter: config_filter.yaml

View File

@ -0,0 +1,54 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('tps/birzha/transactions') ?>">Transactions</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<?php if (!$this->fatalError): ?>
<?= Form::open(['class' => 'layout']) ?>
<div class="layout-row">
<?= $this->formRender() ?>
</div>
<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-request-data="redirect:0"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-primary">
<?= e(trans('backend::lang.form.save')) ?>
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-default">
<?= e(trans('backend::lang.form.save_and_close')) ?>
</button>
<button
type="button"
class="oc-icon-trash-o btn-icon danger pull-right"
data-request="onDelete"
data-load-indicator="<?= e(trans('backend::lang.form.deleting')) ?>"
data-request-confirm="<?= e(trans('backend::lang.form.confirm_delete')) ?>">
</button>
<span class="btn-text">
<?= e(trans('backend::lang.form.or')) ?> <a href="<?= Backend::url('tps/birzha/transactions') ?>"><?= e(trans('backend::lang.form.cancel')) ?></a>
</span>
</div>
</div>
<?= Form::close() ?>
<?php else: ?>
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
<p><a href="<?= Backend::url('tps/birzha/transactions') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')) ?></a></p>
<?php endif ?>

View File

@ -43,7 +43,7 @@ class Payment extends Model
if($this->status == 'approved' || $this->payment_type == 'gift' ) {
if(!$transaction = $this->transaction)
{
$this->createTransaction();
$this->createTransaction($this->payment_type != 'gift'? $this->patment_type:'sowgat');
}
else{
$transaction->amount = $this->amount;
@ -86,10 +86,11 @@ class Payment extends Model
}
}
private function createTransaction(){
private function createTransaction($desc='sowgat'){
$transaction = new Transaction([
'user_id' => $this->user_id,
'amount' => $this->amount
'amount' => $this->amount,
'description' => "Balansyn doldurulmagy {$desc} {$this->amount} manat"
]);
$this->transaction()->save($transaction);
}

View File

@ -58,7 +58,7 @@ class Product extends Model
];
public $morphOne = [
'transaction' => [Transaction::class, 'name' => 'transactable','delete' => true]
'transaction' => [Transaction::class, 'name' => 'transactable']
];
public $attachMany = [
@ -113,7 +113,8 @@ class Product extends Model
private function createTransaction(){
$transaction = new Transaction([
'user_id' => $this->vendor_id,
'amount' => 0 - $this->payed_fee_for_publ
'amount' => 0 - $this->payed_fee_for_publ,
'description' => "Lot #{$this->id} {$this->name} haryt ucin tutym."
]);
$this->transaction()->save($transaction);
}
@ -132,12 +133,8 @@ class Product extends Model
// $createdAt = Carbon::parse($this->created_at);
$this->ends_at = \Carbon\Carbon::now()->addDays(Settings::getValue('duration'));
}
elseif($this->status == 'denied') {
// give fee back to the user, because his post has been denied
$user = $this->vendor;
//todo delete associated transaction
$user->balance = $user->balance + $this->payed_fee_for_publ;
$user->save();
elseif($this->status == 'denied' && $this->transaction) {
$this->transaction()->delete();
}
}

View File

@ -13,6 +13,10 @@ columns:
type: datetime
user_id:
label: User
type: text
type: user
relation: user
valueFrom: email
sortable: false
description:
label: Description
type: text

View File

@ -3,14 +3,22 @@ fields:
label: Number
span: auto
type: number
disabled: true
user:
label: User
nameFrom: email
descriptionFrom: name
span: auto
type: relation
disabled: true
created_at:
label: 'Created date'
mode: datetime
span: auto
type: datepicker
disabled: true
description:
label: Description
span: auto
type: text
disabled: true

View File

@ -0,0 +1,23 @@
<?php namespace TPS\Birzha\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateTpsBirzhaTransactions2 extends Migration
{
public function up()
{
Schema::table('tps_birzha_transactions', function($table)
{
$table->text('description')->nullable();
});
}
public function down()
{
Schema::table('tps_birzha_transactions', function($table)
{
$table->dropColumn('description');
});
}
}

View File

@ -0,0 +1,23 @@
<?php namespace TPS\Birzha\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateTpsBirzhaTransactions3 extends Migration
{
public function up()
{
Schema::table('tps_birzha_transactions', function($table)
{
$table->decimal('amount', 10, 2)->change();
});
}
public function down()
{
Schema::table('tps_birzha_transactions', function($table)
{
$table->decimal('amount', 10, 0)->change();
});
}
}

View File

@ -236,3 +236,9 @@
1.0.82:
- 'Updated table tps_birzha_transactions'
- builder_table_update_tps_birzha_transactions.php
1.0.83:
- 'Updated table tps_birzha_transactions'
- builder_table_update_tps_birzha_transactions_2.php
1.0.84:
- 'Updated decimal table tps_birzha_transactions'
- builder_table_update_tps_birzha_transactions_3.php

View File

@ -0,0 +1,62 @@
title = "Balans taryhy"
url = "/balans-taryhy"
layout = "default"
is_hidden = 0
==
<section class="post">
<div class="auto_container">
<div class="post_wrap">
<div class="contact_title">
История Balansa
</div>
<div class="history_table">
<table>
<thead>
<tr>
<th></th>
<th>Дата пополнения</th>
<th>Description</th>
<th>Сумма</th>
<th>Type</th>
</tr>
</thead>
<tbody>
{% for transaction in user.transactions%}
<tr>
<td>{{transaction.id}}</td>
<td>{{transaction.created_at|date('H:i - d.m.Y')}}</td>
<td>{{transaction.description}}</td>
<td>{{transaction.amount}} TMT</td>
<td>
{% if transaction.amount > 0%}
<p class="approved">{{'popolnenie'|_}}</p>
{% else %}
<p class="denied">{{'oplata'|_}} </p>
{% endif %}
</td>
</tr>
{% else %}
<tr><td colspan="5">{{'no_balance_history'|_}}</td></tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- <div class="cat_end">-->
<!-- <a href="#" class="cat_arrow left">-->
<!-- <img src="images/svg/arrow-right.svg" alt="">-->
<!-- </a>-->
<!-- <form action="#" class="cat_form">-->
<!-- <input type="text" placeholder="1">-->
<!-- </form>-->
<!-- <a href="#" class="cat_arrow ">-->
<!-- <img src="images/svg/arrow-right.svg" alt="">-->
<!-- </a>-->
<!-- <div class="cat_page">-->
<!-- 15 страниц-->
<!-- </div>-->
<!-- </div>-->
</div>
</div>
</section>

View File

@ -114,14 +114,14 @@ code = "main-top"
</div>
</a>
<div class="profile_info-group">
<a class="profile_info-group" href="{{ 'kabinet/transactions'|page }}">
<div class="profile_icon">
<img src="{{'assets/images/svg/coins.svg'|theme}}" alt="">
</div>
<div class="profile_text">
{{user.getBalance}} TMT
</div>
</div>
</a>
<div class="profile_bio">
<div class="profile_head">
<div class="profile_icon">