Browse Source

chore: 大宗

master
liyang 3 weeks ago
parent
commit
7df5e53e14
  1. 4
      app/admin/controller/Order.php
  2. 5
      app/admin/route/app.php
  3. 351
      app/admin/service/OrderService.php
  4. 12
      app/admin/service/setting/IPOService.php
  5. 2
      app/admin/validate/OrderValidate.php

4
app/admin/controller/Order.php

@ -477,10 +477,10 @@ class Order extends AdminBaseController
return json($result);
}
public function block()
public function blockStockHold()
{
$service = new OrderService();
$result = $service->blockStock($this->request->param(), $this->getAdminId());
$result = $service->blockStockHold($this->request->param(), $this->getAdminId());
return json($result);
}
}

5
app/admin/route/app.php

@ -198,7 +198,10 @@ Route::group('/', function () {
Route::post('/order/fund_interest_list', 'Order/fundInterestList');
//大宗交易订单
Route::post('/order/block_order', 'Order/block');
Route::post('/order/block_stock_hold', 'Order/blockStockHold')->append(['market_type' => 22, 'status' => 1]);
Route::post('/order/block_stock_place', 'Order/blockStockHold')->append(['market_type' => 22, 'status' => 0]);
Route::post('/order/block_stock_back', 'Order/blockStockHold')->append(['market_type' => 22, 'status' => 2]);
Route::post('/order/block_stock_clear', 'Order/blockStockHold')->append(['market_type' => 22, 'status' => 3]);
// 代理管理
Route::post('/agent/index', 'Agent/index');

351
app/admin/service/OrderService.php

@ -104,7 +104,8 @@ class OrderService extends AdminBaseService
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extent' => ['totalMoney' => 0]]);
}
if (!empty($where['user_id']) && is_numeric($where['user_id']) && $where['user_id'] == 0) {
return $this->toData('1', 'SUCCESS', ['total' => 0, 'list' => [], 'extent' => ['totalMoney' => 0,
return $this->toData('1', 'SUCCESS', ['total' => 0, 'list' => [], 'extent' => [
'totalMoney' => 0,
]]);
}
@ -163,10 +164,13 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -174,7 +178,6 @@ class OrderService extends AdminBaseService
} catch (\Exception $exception) {
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
}
}
// 现货撤单
@ -260,10 +263,13 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -271,7 +277,6 @@ class OrderService extends AdminBaseService
} catch (\Exception $exception) {
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
}
}
// 现货订单
@ -357,10 +362,13 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -368,7 +376,6 @@ class OrderService extends AdminBaseService
} catch (\Exception $exception) {
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
}
}
@ -463,10 +470,14 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney, 'totalServiceCost' => $totalServiceCost,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
'totalServiceCost' => $totalServiceCost,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -559,10 +570,13 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -656,10 +670,13 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -771,12 +788,14 @@ class OrderService extends AdminBaseService
}
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalClosingCost' => $totalClosingCost,
'totalFloat' => $totalFloat['total'],
]]);
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -878,10 +897,14 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney, 'totalServiceCost' => $totalServiceCost,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
'totalServiceCost' => $totalServiceCost,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -974,10 +997,13 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -1071,10 +1097,13 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -1184,12 +1213,14 @@ class OrderService extends AdminBaseService
}
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalClosingCost' => $totalClosingCost,
'totalFloat' => $totalFloat['total'],
]]);
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -1291,10 +1322,14 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney, 'totalServiceCost' => $totalServiceCost,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
'totalServiceCost' => $totalServiceCost,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -1387,10 +1422,13 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -1484,10 +1522,13 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -1599,12 +1640,14 @@ class OrderService extends AdminBaseService
}
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalClosingCost' => $totalClosingCost,
'totalFloat' => $totalFloat['total'],
]]);
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -1720,11 +1763,14 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney, 'totalServiceCost' => $totalServiceCost,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
'totalServiceCost' => $totalServiceCost,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -1835,10 +1881,13 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -1948,10 +1997,13 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -2075,12 +2127,14 @@ class OrderService extends AdminBaseService
}
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalClosingCost' => $totalClosingCost,
'totalFloat' => $totalFloat['total'],
]]);
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -2171,9 +2225,7 @@ class OrderService extends AdminBaseService
'stock_type_list' => $stockTypeList,
'status_list' => $statusList
]]);
} catch
(ValidateException $validateException) {
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
return $this->toData('1', $message);
@ -2398,7 +2450,6 @@ class OrderService extends AdminBaseService
'stock_type_list' => PreFundStockModel::$stockTypeList,
'cycle_type_list' => PreFundStockModel::$cycleTypeList
]]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -2602,10 +2653,14 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney, 'totalServiceCost' => $totalServiceCost,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
'totalServiceCost' => $totalServiceCost,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -2706,9 +2761,11 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => ['totalMoney' => $totalMoney]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -2810,10 +2867,13 @@ class OrderService extends AdminBaseService
if ($totalModel['total']) {
$totalMoney = round($totalModel['total'], 4);
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
'extent' => ['totalMoney' => $totalMoney,
]]);
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -2925,12 +2985,14 @@ class OrderService extends AdminBaseService
}
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows,
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalClosingCost' => $totalClosingCost,
'totalFloat' => $totalFloat['total'],
]]);
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
@ -2941,12 +3003,11 @@ class OrderService extends AdminBaseService
}
################################################# 大宗交易
//大宗交易订单
public function blockStock($param, $adminId)
public function blockStockHold($param, $adminId)
{
try {
// 参数校验
validate(OrderValidate::class)->scene('fund_stock')->check($param);
validate(OrderValidate::class)->scene('block_stockHold')->check($param);
$where = [];
$userId = 0;
@ -2964,50 +3025,88 @@ class OrderService extends AdminBaseService
if (!is_array($whereU)) {
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extent' => ['totalMoney' => 0]]);
}
$market_type = intval($param['market_type']);
$table_obj = (new IPOService())->getStockModel($market_type);
if (empty($table_obj)) {
return $this->toData('1', '数据异常');
}
if (!empty($param['type']) && is_numeric($param['type'])) {
$where['type'] = $param['type'];
// 订单号
if (!empty($param['order_id'])) {
$where['order_id'] = $param['order_id'];
}
if (isset($param['status'])) {
$where['status'] = $param['status'];
}
// 交易对
if (!empty($param['stock_id'])) {
$where['stock_id'] = $param['contract_id'];
}
$list = UserStockBlockOrderModel::where($whereU)->where($where)->order('id', 'desc')->page($param['page'], $param['limit'])->select();
$total = UserStockBlockOrderModel::where($whereU)->where($where)->count();
if (!empty($param['start_time']) && !empty($param['end_time'])) {
$where['open_time'] = ['between time', [$param['start_time'], $param['end_time']]];
}
// 列表
$list = Db::table($table_obj['trade_table'])->where($whereU)->where($where)->order('trade_id', 'desc')->page($param['page'], $param['limit'])->select();
// 总数
$summary = Db::table($table_obj['trade_table'])
->where($whereU)
->where($where)
->field('COUNT(*) as total,sum(order_money) as total_money,sum(service_cost) as total_service_cost')
->find();
$rows = [];
if (!$list->isEmpty()) {
// 获取用户号
$userIdArr = [];
// stock
$preStockId = [];
foreach ($list as $idItem) {
$userIdArr[] = $idItem['user_id'];
// $preStockId[] = $idItem['pre_stock_id'];
}
$userNoArr = UserModel::where('user_id', 'in', $userIdArr)->column('user_no', 'user_id');
// $stockArr = PreFundStockModel::where('id', 'in', $preStockId)->column('*', 'id');
$rows = $list->toArray();
foreach ($rows as $key => $item) {
// $stock = $stockArr[$item['pre_stock_id']] ?? [];
// if (empty($stock)) continue;
$rows[$key]['user_no'] = $userNoArr[$item['user_id']] ?? '-'; // 用户号
$rows[$key]['stock_name'] = $item['stock_name'] ?? '-';
$rows[$key]['market_price'] = $item['market_price'] ?? '-';
$rows[$key]['deal_price'] = $item['deal_price'] ?? '-';
$rows[$key]['order_number'] = $item['order_number'] ?? '-';
$rows[$key]['market_money'] = $item['market_money'] ?? '-';
$rows[$key]['order_money'] = $item['order_money'] ?? '-';
$rows[$key]['status'] = UserStockBlockOrderModel::$statusList[$item['status']];
$rows[$key]['type'] = UserStockBlockOrderModel::$typeList[$item['type']];
$rows[$key]['create_time'] = $item['create_time'] ?? '-';
foreach ($list as $item) {
$orderNumber = number_format($item['order_number'], '18', '.', '');
$orderPrice = number_format($item['deal_price'], '18', '.', '');
$orderAmount = bcmul($orderNumber, $orderPrice, 18);
if (in_array($market_type, [21])) { // 一些市场类型字段不一样,比如黄金期货没有stock_id,而是用的contract_id
$stockIdOrContractId = $item['contract_id'];
} else {
$stockIdOrContractId = $item['stock_id'];
}
$rows[] = [
'trade_id' => $item['trade_id'], //
'user_no' => $userNoArr[$item['user_id']] ?? '-', // 用户号
'order_id' => $item['order_id'], // 用户号
'open_time' => $item['open_time'] ?? '-', // 挂单时间
'trade_type' => $item['trade_type'] == 1 ? '买涨' : '买跌',
'order_money' => $orderAmount, // 订单金额
'stock_id' => $stockIdOrContractId, // 股票代码
'order_number' => $item['order_number'], // 数量
'service_cost' => $item['service_cost'], // 服务费
'float' => '-', // 浮动盈亏
'deal_price' => $item['deal_price'], // 开仓价
'now_price' => '-', // 当前价
'stop_loss_price' => $item['stop_loss_price'], // 止损价
'stop_win_price' => $item['stop_win_price'], // 止盈价
'pry_num' => $item['pry_num'], // 杠杆
];
}
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows, 'extend' => [
'status_list' => UserStockBlockOrderModel::$statusList,
'type_list' => UserStockBlockOrderModel::$typeList
]]);
$totalMoney = $total = $totalServiceCost = 0;
if ($summary) {
$totalMoney = round($summary['total'] ?? 0, 4);
$totalServiceCost = round($summary['total_service_cost'] ?? 0, 4);
$total = $summary['total'] ?? 0;
}
return $this->toData('0', 'SUCCESS', [
'total' => $total,
'list' => $rows,
'extent' => [
'totalMoney' => $totalMoney,
'totalServiceCost' => $totalServiceCost,
]
]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();

12
app/admin/service/setting/IPOService.php

@ -1669,6 +1669,18 @@ class IPOService extends AdminBaseService
// 'check' => '',
];
break;
case 22:
$result = [
'user_table' => $prefix . 'user_gold_futures',
'log_table' => $prefix . 'user_gold_futures_log',
'list_table' => $prefix . 'stock_block_list',
'trade_table' => $prefix . 'stock_block_trade',
'redis_key' => 'GoldFutures:STOCK:LIST:',
'stock_id' => 'USD', // 黄金期货资产表中contract_id对应的值,即 bot_user_gold_futures.contract_id
// 'country' => '',
// 'check' => '',
];
break;
default:
$result = [];
break;

2
app/admin/validate/OrderValidate.php

@ -104,6 +104,6 @@ class OrderValidate extends AdminBaseValidate
'hk_stockClear' => ['page', 'limit', 'order_id', 'user_no', 'stock_id', 'start_time', 'end_time'],
// 大宗交易
'block_stock' => ['page', 'limit', 'user_no'],
'block_stockHold' => ['page', 'limit', 'order_id', 'user_no', 'stock_id', 'start_time', 'end_time', 'status'],
];
}
Loading…
Cancel
Save