当前位置:网站首页>Digital currency exchange -- digital currency exchange system development source code sharing
Digital currency exchange -- digital currency exchange system development source code sharing
2022-06-25 12:28:00 【Procedure 15528175269】
Development source code sharing of digital currency exchange :
<?php
/**
* Created by PhpStorm.
* User: swl
* Date: 2018/7/3
* Time: 10:23
*/
namespace App;
use Illuminate\Database\Eloquent\Model;
class Transaction extends Model
{
protected $table = 'transaction';
public $timestamps = false;
const CREATED_AT = 'time';
protected $appends = [
'from_address',
'to_address',
'from_account',
'to_account',
'total',
'currency_name'
];
public static function createData($data)
{
if (empty($data)) {
return false;
}
if (empty($data["from_user_id"]) || empty($data["to_user_id"]) || empty($data["number"])) {
return false;
}
$transaction = new self();
$transaction->from_user_id = $data["from_user_id"];
$transaction->to_user_id = $data["to_user_id"];
$transaction->type = empty($data["type"]) ? 1 : $data["type"];
$transaction->number = $data["number"];
$transaction->remarks = $data["remarks"];
$transaction->time = time();
$transaction->status = 1;
if ($transaction->save()) {
return true;
} else {
return false;
}
}
public static function pushNews($currency_id, $legal_id)
{
$in = TransactionIn::with(['legalcoin', 'currencycoin'])
->where("number", ">", 0)
->where("currency", $currency_id)
->where("legal", $legal_id)
->groupBy('currency', 'legal', 'price')
->orderBy('price', 'desc')
->select([
'currency',
'legal',
'price',
])->selectRaw('sum(`number`) as `number`')
->limit(5)
->get()
->toArray();
$out = TransactionOut::with(['legalcoin', 'currencycoin'])
->where("number", ">", 0)
->where("currency", $currency_id)
->where("legal", $legal_id)
->groupBy('currency', 'legal', 'price')
->orderBy('price', 'asc')
->select([
'currency',
'legal',
'price',
])->selectRaw('sum(`number`) as `number`')
->limit(5)
->get()
->toArray();
krsort($out);
$out_data = array();
foreach ($out as $o) {
array_push($out_data, $o);
}
$last_price = 0;
$last = TransactionComplete::orderBy('id', 'desc')->where("currency", $currency_id)->where("legal", $legal_id)->first();
if (!empty($last)) {
$last_price = $last->price;
}
$send = array(
"type" => "transaction",
"in" => json_encode($in),
"out" => json_encode($out_data),
"last_price" => $last_price,
"currency_id" => $currency_id,
"legal_id" => $legal_id
);
return UserChat::sendChat($send);
}
public function getFromAddressAttribute()
{
return $this->hasOne('App\UsersWallet', 'user_id', 'from_user_id')->value('address');
}
public function getToAddressAttribute()
{
return $this->hasOne('App\UsersWallet', 'user_id', 'to_user_id')->value('address');
}
public function getFromAccountAttribute()
{
return $this->hasOne('App\Users', 'id', 'from_user_id')->value('account_number');
}
public function getToAccountAttribute()
{
return $this->hasOne('App\Users', 'id', 'to_user_id')->value('account_number');
}
public function getTimeAttribute()
{
$value = $this->attributes['time'];
return $value ? date('Y-m-d H:i:s', $value) : '';
}
public function getCurrencyNameAttribute()
{
return $this->hasOne('App\Currency', 'id', 'currency')->value('name');
}
// Get total transaction amount
public function getTotalAttribute()
{
$number = $this->attributes['number'];
$price = $this->attributes['price'];
$tol = $number * $price;
return $tol;
}
}边栏推荐
- What are redis avalanche, penetration and breakdown?
- ECSHOP upload video_ ECSHOP video list, video classification, video related product guide
- Arm V7 continuous load / store
- [oceanbase] Introduction to oceanbase and its comparison with MySQL
- The dist function of R language calculates the distance between two samples in dataframe data, returns the distance matrix between samples, and specifies the distance calculation method through the me
- [data midrange] what is the oneid of the data midrange? Isn't the master data fragrant?
- PD1.4转HDMI2.0转接线拆解。
- The latest IT learning route in 2020
- Uncover gaussdb (for redis): comprehensive comparison of CODIS
- sudo: ulimit: command not found
猜你喜欢

ECSHOP commodity page multi-attribute batch purchase plug-ins ECSHOP wholesale plug-ins multi-attribute order placing, multi-attribute batch purchase of commodities

Découvrir gaussdb (pour redis): une comparaison complète avec Codis

揭秘GaussDB(for Redis):全面對比Codis

A commonly used statistical modeling method -- difference analysis

Dark horse shopping mall ---1 Project introduction - environment construction

The first techo day Tencent technology open day in 2022 will be held online on June 28

Installation and removal of MySQL under Windows

黑馬暢購商城---3.商品管理

Upgrade opsenssh to 8.8p1

Black Horse Chang Shopping Mall - - - 3. Gestion des produits de base
随机推荐
Execution order of MySQL query statements join, on and where
R language uses ordinal or. The display function obtains the summary statistical information of the ordered logistic regression model (the odds ratio and its confidence interval corresponding to the v
The source code of the hottest online disk money making system in 2022 imitates Lanzou online disk / Chengtong online disk / sharing money making cloud disk system / online disk VIP Download System
R语言使用构建有序多分类逻辑回归模型、epiDisplay包的ordinal.or.display函数获取有序logistic回归模型的汇总统计信息(变量对应的优势比及其置信区间、以及假设检验的p值)
ARM V7 协处理器
Repair the error that ECSHOP background orders prompt insufficient inventory when adding goods. Please reselect
The R language cartools package divides data, the scale function scales data, and the NaiveBayes function of e1071 package constructs a naive Bayesian model
Explain factor analysis in simple terms, with case teaching (full)
Rank sum ratio comprehensive evaluation method for common models in mathematical modeling
devsecops与devops的理解与建设
How can we differ LEFT OUTER JOIN vs Left Join [duplicate]
How to open an account for trading futures Shanghai nickel products online
plt.gca()画框及打标签
ECSHOP video list_ ECSHOP uploading video, video classification, video list playing video function
What are redis avalanche, penetration and breakdown?
Image tagging to obtain the coordinates of the image in the ImageView
Gradle知识点
sklearnex 让你的 sklearn 机器学习模型训练快得飞起?
Effective reading of literature
20、wpf之MVVM命令绑定