feat: 项目基础框架+配置+Kernel
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
|
||||
use App\CurrencyMatch;
|
||||
use App\CurrencyQuotation;
|
||||
use App\Logic\CoinTradeLogic;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
||||
class CoinTradeHandel implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
protected $params;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$currency_quotation = CurrencyQuotation::where('match_id', 46)->first();
|
||||
if(!empty($currency_quotation)){
|
||||
|
||||
$currency_id = $currency_quotation->currency_id;
|
||||
$legal_id = $currency_quotation->legal_id;
|
||||
$now_price = $currency_quotation->now_price;
|
||||
CoinTradeLogic::matchBuyTrade($currency_id,$legal_id,$now_price);
|
||||
CoinTradeLogic::matchSellTrade($currency_id,$legal_id,$now_price);
|
||||
}
|
||||
|
||||
extract($this->params);
|
||||
|
||||
|
||||
$match = CurrencyMatch::where([
|
||||
'legal_id' => $legal_id,
|
||||
'currency_id' => $currency_id,
|
||||
'open_coin_trade' => 1,
|
||||
'coin_trade_success' => 1
|
||||
])->first();
|
||||
if(!$match){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (bc_comp($now_price, 0) > 0) {
|
||||
CoinTradeLogic::matchBuyTrade($currency_id,$legal_id,$now_price);
|
||||
CoinTradeLogic::matchSellTrade($currency_id,$legal_id,$now_price);
|
||||
// LeverTransaction::newPrice($legal_id, $currency_id, $now_price);
|
||||
// } else {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
||||
class EntrustCheck implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use App\MarketHour;
|
||||
|
||||
class EsearchMarket implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $marketData;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($market_data)
|
||||
{
|
||||
$this->marketData = $market_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
MarketHour::getAndSetEsearchMarket($this->marketData);
|
||||
} catch (\Exception $e) {
|
||||
var_dump($e->getFile());
|
||||
var_dump($e->getLine());
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\LeverTransaction;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
||||
/**
|
||||
* 处理跟随订单
|
||||
*/
|
||||
class FollowOrderHandel implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
//被跟随的订单id
|
||||
protected $to_lever_transaction_id;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($to_lever_transaction_id)
|
||||
{
|
||||
$this->to_lever_transaction_id = $to_lever_transaction_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$toLeverTransaction = LeverTransaction::query()->find($this->to_lever_transaction_id);
|
||||
if ($toLeverTransaction->status != LeverTransaction::CLOSED) {
|
||||
throw new \Exception('被跟随的订单状态错误');
|
||||
}
|
||||
LeverTransaction::query()
|
||||
->where('status', LeverTransaction::TRANSACTION)
|
||||
->where('follow_user_id', $toLeverTransaction->user_id)
|
||||
->where('follow_order_id', $toLeverTransaction->id)
|
||||
->where('order_type', 2)
|
||||
->chunkById(50, function ($items) {
|
||||
$items->each(function ($item) {
|
||||
try {
|
||||
$return = LeverTransaction::leverClose($item, true);
|
||||
if (!$return) {
|
||||
throw new \Exception("平仓失败");
|
||||
}
|
||||
} catch (\Throwable $ex) {
|
||||
//出现出错跳过,执行下一个
|
||||
$msg = "跟随者的订单id:{$item->id},被跟随者订单id:{$this->to_lever_transaction_id}," . $ex->getMessage();
|
||||
$this->writeLog($msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (\Throwable $ex) {
|
||||
$msg = "被跟随者订单id:{$this->to_lever_transaction_id}," . $ex->getMessage();
|
||||
$this->writeLog($msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 写日志
|
||||
* @param $msg
|
||||
*/
|
||||
protected function writeLog($msg)
|
||||
{
|
||||
$path = base_path() . '/storage/logs/follow/';
|
||||
$filename = 'FollowOrderHandel-' . date('Ymd') . '.log';
|
||||
file_exists($path) || @mkdir($path);
|
||||
error_log(date('Y-m-d H:i:s') . ' ' . $msg . PHP_EOL, 3, $path . $filename);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\Logic\MicroTradeLogic;
|
||||
|
||||
class HandleMicroTrade implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $klineData = [];
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($kline_data)
|
||||
{
|
||||
$this->klineData = $kline_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// echo Carbon::now()->toDateTimeString() . PHP_EOL;
|
||||
|
||||
|
||||
$match_id = $this->klineData['match_id'];
|
||||
$now_price = $this->klineData['close'];
|
||||
|
||||
echo '---处理期权获取真实价格' . $match_id . PHP_EOL;
|
||||
// MicroTradeLogic::newPrice($match_id, $now_price);
|
||||
MicroTradeLogic::close($match_id);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\AccountLog;
|
||||
use App\LeverTransaction;
|
||||
use App\UsersWallet;
|
||||
|
||||
class LeverClose implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $task_list;
|
||||
protected $deduct_balance;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($task_list, $deduct_balance = true)
|
||||
{
|
||||
$this->task_list = $task_list;
|
||||
$this->deduct_balance = $deduct_balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$lever_transactions = LeverTransaction::whereIn('id', $this->task_list)
|
||||
->where('status', LeverTransaction::CLOSING)
|
||||
->get();
|
||||
foreach ($lever_transactions as $key => $trade) {
|
||||
try {
|
||||
DB::transaction(function () use ($trade) {
|
||||
try {
|
||||
if ($this->deduct_balance) {
|
||||
if(!$this->deductBalance($trade)) {
|
||||
throw new \Exception('平仓扣除资金失败');
|
||||
}
|
||||
}
|
||||
//更新状态和计算最终盈利
|
||||
$trade->status = LeverTransaction::CLOSED;
|
||||
$trade->fact_profits = $trade->profits;
|
||||
$trade->complete_time = microtime(true);
|
||||
$result = $trade->save();
|
||||
|
||||
if (!$result) {
|
||||
throw new \Exception('平仓失败:更新平仓状态失败');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
echo 'File:' . $e->getFile() . PHP_EOL;
|
||||
echo 'Line:' . $e->getLine() . PHP_EOL;
|
||||
echo 'Message:' . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function deductBalance($trade)
|
||||
{
|
||||
try {
|
||||
DB::transaction(function () use ($trade) {
|
||||
$legal_wallet = UsersWallet::where('user_id', $trade->user_id)
|
||||
->where('currency', $trade->legal)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
//计算盈亏
|
||||
$change = bc_add($trade->caution_money, $trade->profits);
|
||||
//从钱包处理资金
|
||||
$pre_result = bc_add($legal_wallet->micro_balance, $change);
|
||||
$diff = 0;
|
||||
//是否余额不够扣除
|
||||
// if (bc_comp($pre_result, 0) < 0) {
|
||||
// $change = -$legal_wallet->lever_balance;
|
||||
// $diff = $pre_result;
|
||||
// }
|
||||
$extra_data = [
|
||||
'trade_id' => $trade->id,
|
||||
'caution_money' => $trade->caution_money,
|
||||
'profit' => $trade->profits,
|
||||
'diff' => $diff,
|
||||
];
|
||||
$result = change_wallet_balance(
|
||||
$legal_wallet,
|
||||
3,
|
||||
$change,
|
||||
AccountLog::LEVER_TRANSACTION_ADD,
|
||||
'平仓资金处理',
|
||||
false,
|
||||
0,
|
||||
$diff == 0 ? 0 : 1, //1代表有差额
|
||||
serialize($extra_data),
|
||||
true,//余额为0仍然要平仓
|
||||
true //允许资金扣为负数
|
||||
);
|
||||
if ($result !== true) {
|
||||
throw new \Exception($result);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
echo 'File:' . $e->getFile() . PHP_EOL;
|
||||
echo 'Line:' . $e->getLine() . PHP_EOL;
|
||||
echo 'Message:' . $e->getMessage() . PHP_EOL;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use App\LeverTransaction;
|
||||
|
||||
class LeverHandle implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $params;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
extract($this->params);
|
||||
//价格大于0才做更新处理
|
||||
if (bc_comp($now_price, '0') > 0) {
|
||||
LeverTransaction::tradeHandle($legal_id, $currency_id, $now_price, $now);
|
||||
} else {
|
||||
echo '法币id:' . $this->legal_id . ',交易币id:' .$this->currency_id . '当前行情价格异常' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use App\Http\Controllers\Api\LeverController;
|
||||
use App\UserChat;
|
||||
|
||||
class LeverPushPrice implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $params;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
extract($this->params);
|
||||
$lever = new LeverController();
|
||||
$lever_transaction = $lever->getLastLeverTransaction($legal_id, $currency_id);
|
||||
$push_data = array_merge([
|
||||
'type' => 'lever_data'
|
||||
], $this->params, [
|
||||
'in' => $lever_transaction['in']->toJson(),
|
||||
'out' => $lever_transaction['out']->toJson(),
|
||||
]);
|
||||
//SendMarket::dispatch($push_data)->onQueue('send.price');
|
||||
//$result = UserChat::sendText($push_data);
|
||||
} catch (\Exception $e) {
|
||||
echo '文件:' . $e->getFile() . PHP_EOL;
|
||||
echo '行号:' . $e->getLine() . PHP_EOL;
|
||||
echo '错误:' . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use App\LeverTransaction;
|
||||
use App\UsersWallet;
|
||||
use App\UserChat;
|
||||
|
||||
class LeverPushTrade implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $user_id;
|
||||
protected $legal_id;
|
||||
protected $currency_id;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($user_id, $legal_id, $currency_id)
|
||||
{
|
||||
$this->user_id = $user_id;
|
||||
$this->legal_id = $legal_id;
|
||||
$this->currency_id = $currency_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
// echo '法币id:' . $this->legal_id . ',交易币id:' .$this->currency_id . ',user_id:' . $this->user_id . PHP_EOL;
|
||||
// $start = microtime(true);
|
||||
//推送用户风险率和订单
|
||||
$user_wallet = UsersWallet::where('user_id', $this->user_id)
|
||||
->where('currency', $this->legal_id)
|
||||
->first();
|
||||
if (!$user_wallet) {
|
||||
throw new \Exception('钱包不存在');
|
||||
}
|
||||
//取盈亏总额
|
||||
list(
|
||||
'caution_money_total' => $caution_money_all,
|
||||
'origin_caution_money_total' => $origin_caution_money_all,
|
||||
'profits_total' => $profits_all
|
||||
) = LeverTransaction::getUserProfit($this->user_id, $this->legal_id);
|
||||
//取该交易对盈亏总额
|
||||
list(
|
||||
'caution_money_total' => $caution_money,
|
||||
'origin_caution_money_total' => $origin_caution_money,
|
||||
'profits_total' => $profits
|
||||
) = LeverTransaction::getUserProfit($this->user_id, $this->legal_id, $this->currency_id);
|
||||
//取风险率
|
||||
$hazard_rate = LeverTransaction::getWalletHazardRate($user_wallet);
|
||||
|
||||
//取用户所有持仓交易
|
||||
$lever_transaction_all = LeverTransaction::where('status', LeverTransaction::TRANSACTION)
|
||||
->where('legal', $this->legal_id)
|
||||
->where('user_id', $this->user_id)
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
//委托中交易
|
||||
$lever_transaction_entrust = LeverTransaction::where('status', LeverTransaction::ENTRUST)
|
||||
->where('legal', $this->legal_id)
|
||||
->where('user_id', $this->user_id)
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
//取交易对持仓交易
|
||||
$lever_transaction_cur = LeverTransaction::where('status', LeverTransaction::TRANSACTION)
|
||||
->where('legal', $this->legal_id)
|
||||
->where('currency', $this->currency_id)
|
||||
->where('user_id', $this->user_id)
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
$push_data = [
|
||||
'type' => 'lever_trade',
|
||||
'to' => $this->user_id,
|
||||
'hazard_rate' => $hazard_rate, //风险率
|
||||
'caution_money_all' => $caution_money_all, //总保证金
|
||||
'origin_caution_money_all' => $origin_caution_money_all, //原始总保证金
|
||||
'profits_all' => $profits_all, //总盈亏
|
||||
'caution_money' => $caution_money, //当前交易对的保证金
|
||||
'origin_caution_money' => $origin_caution_money, //当前交易对的原始保证金
|
||||
'profits' => $profits, //当前交易对的盈亏金额
|
||||
'trades_all' => $lever_transaction_all->toJson(), //所有交易
|
||||
'trades_entrust' => $lever_transaction_entrust->toJson(), //取所有委托交易
|
||||
'trades_cur' => $lever_transaction_cur->toJson(), //当前交易对的交易
|
||||
];
|
||||
SendMarket::dispatch($push_data)->onQueue('send.trade');
|
||||
// echo 123;exit;
|
||||
// $end = microtime(true);
|
||||
// echo '共计耗时:' . ($end - $start) . '秒'. PHP_EOL;
|
||||
//$result = UserChat::sendChat($push_data);
|
||||
} catch (\Exception $e) {
|
||||
echo '文件:' . $e->getFile() . PHP_EOL;
|
||||
echo '行号:' . $e->getLine() . PHP_EOL;
|
||||
echo '错误:' . $e->getMessage() . PHP_EOL;
|
||||
return ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use App\LeverTransaction;
|
||||
|
||||
class LeverUpdate implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $params;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
extract($this->params);
|
||||
//价格大于0才做更新处理
|
||||
if (bc_comp($now_price, 0) > 0) {
|
||||
LeverTransaction::newPrice($legal_id, $currency_id, $now_price, $now);
|
||||
} else {
|
||||
echo '法币id:' . $legal_id . ',交易币id:' .$currency_id . '当前行情价格异常' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use App\{Agent, LeverTransaction};
|
||||
|
||||
class NewDoJie implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $lever_ids;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($lever_ids) {
|
||||
|
||||
$this->lever_ids=$lever_ids;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle() {
|
||||
|
||||
LeverTransaction::where('status' , LeverTransaction::CLOSED)
|
||||
->where('settled' , 0)
|
||||
->whereIn('id',$this->lever_ids)
|
||||
->chunk(100, function($lever_transactions) {
|
||||
foreach ($lever_transactions as $key => $trade) {
|
||||
try {
|
||||
|
||||
$agent_path=$trade->agent_path;
|
||||
|
||||
$_p_arr =explode(',', $agent_path);
|
||||
|
||||
if (!empty($_p_arr)) {
|
||||
|
||||
$da=[];
|
||||
foreach($_p_arr as $k=>$v){
|
||||
$agent=Agent::getAgentById($v);
|
||||
|
||||
$da[$k]['agent_id']=$v;
|
||||
$da[$k]['pro_loss']=$agent->pro_loss;
|
||||
$da[$k]['pro_ser']=$agent->pro_ser;
|
||||
|
||||
}
|
||||
|
||||
//极差收益
|
||||
foreach ($da as $k=>$val){
|
||||
|
||||
if($k==0){
|
||||
$pro_loss=$val['pro_loss'];
|
||||
$pro_ser=$val['pro_ser'];
|
||||
}else{
|
||||
$n=$k-1;
|
||||
$pro_loss=bc_sub($val['pro_loss'],$da[$n]['pro_loss']);
|
||||
$pro_ser=bc_sub($val['pro_ser'],$da[$n]['pro_ser']);
|
||||
}
|
||||
|
||||
|
||||
if ($pro_loss > 0){
|
||||
|
||||
$_base_money =bc_mul($trade->fact_profits , -1);
|
||||
$change = bc_mul($_base_money , $pro_loss/100);
|
||||
|
||||
Agent::change_agent_money(
|
||||
$val['agent_id'] ,
|
||||
1 ,
|
||||
$change,
|
||||
$trade->id,
|
||||
'您的下级用户'.$trade->user_id.'的订单产生的头寸收益为'.$change.'。订单编号为'.$trade->id,
|
||||
$trade->user_id,
|
||||
$trade->legal
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if ($pro_ser >0){
|
||||
|
||||
$change = bc_mul($trade->trade_fee ,$pro_ser/100);
|
||||
|
||||
Agent::change_agent_money(
|
||||
$val['agent_id'],
|
||||
2 ,
|
||||
$change,
|
||||
$trade->id,
|
||||
'您的下级用户'.$trade->user_id.'的订单产生的手续费收益为'.$change.'。订单编号为'.$trade->id,
|
||||
$trade->user_id,
|
||||
$trade->legal
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
LeverTransaction::where('id' , $trade->id)->update(['settled' =>1]);
|
||||
});
|
||||
|
||||
} catch (\Exception $e) {
|
||||
echo 'File :' . $e->getFile() . PHP_EOL;
|
||||
echo 'Line :' . $e->getLine() . PHP_EOL;
|
||||
echo 'Msg :' . $e->getMessage(). PHP_EOL;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use App\MicroOrder;
|
||||
use App\UserChat;
|
||||
|
||||
class SendClosedMicroOrder implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $order;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MicroOrder $order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$send_data = [
|
||||
'type' => 'closed_microorder',
|
||||
'to' => $this->order->user_id,
|
||||
'data' => $this->order,
|
||||
];
|
||||
dump(UserChat::sendText($send_data));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use App\UserChat;
|
||||
|
||||
class SendMarket implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $marketData;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($market_data)
|
||||
{
|
||||
$this->marketData = $market_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
UserChat::sendText($this->marketData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use App\DAO\BlockChain;
|
||||
|
||||
class UpdateBalance implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $wallet;
|
||||
protected $noBalanceContinue = false;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($wallet, $no_balance_continue = false)
|
||||
{
|
||||
$this->wallet = $wallet;
|
||||
$this->noBalanceContinue = $no_balance_continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
BlockChain::updateWalletBalance($this->wallet, $this->noBalanceContinue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Currency;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
||||
class UpdateCurrencyPrice implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
private $kline_data;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($kline_data)
|
||||
{
|
||||
//
|
||||
$this->kline_data = $kline_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
if(empty($this->kline_data)){
|
||||
return 0;
|
||||
}
|
||||
$currency_id = $this->kline_data['currency_id'];
|
||||
$currency = Currency::find($currency_id);
|
||||
if($currency){
|
||||
$currency->price = $this->kline_data['close'];
|
||||
$currency->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use App\MarketHour;
|
||||
|
||||
class WriteMarket implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $params;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
extract($this->params);
|
||||
MarketHour::batchWriteKlineMarket($currency_id, $legal_id, $market_data, $sign, $time);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user