Compare commits

...

2 Commits

Author SHA1 Message Date
liyang 8087e69b41 fix: ipo 修复 2 months ago
liyang e17d58850e fix: ipo后支付 2 months ago
  1. 2
      app/admin/route/app.php
  2. 32
      app/admin/service/OrderService.php
  3. 106
      app/admin/service/setting/IPOService.php
  4. 8
      app/home/service/IPOService.php

2
app/admin/route/app.php

@ -189,7 +189,7 @@ Route::group('/', function () {
// 申购订单
Route::post('/order/pre_stock_order', 'Order/preStock');
Route::post('/order/update_order_num', 'Order/updateGetNum')->middleware('admin_log'); // 修改中签数
Route::post('/order/update_order_num', 'Order/updateGetNum')->append(['market_type' => 18])->middleware('admin_log'); // 修改中签数
Route::post('/order/pre_refund', 'Order/preRefund')->middleware('admin_log'); // ipo订单退款
//基金订单

32
app/admin/service/OrderService.php

@ -2252,22 +2252,30 @@ class OrderService extends AdminBaseService
if (in_array($order['status'], [7, 8])) return $this->toData('1', '订单已退款,不可操作');
if ($param['get_num'] > $order['num']) {
return $this->toData('1', '修改中签数不能大于订单申购数');
}
$getTime = Db::table($tableObj['stock_table'])->where('id', $order['pre_stock_id'])->value('get_time');
if (env('USER_ARREARS.HAS_USER_ARREARS') == 1 && $order['pay_type'] == 2 && in_array($order['status'], [5, 6])) {
} else {
if (strtotime($getTime) < time()) return $this->toData('1', 'IPO已中签,无法修改');
}
$bool = Db::table($tableObj['order_table'])->where('id', $param['id'])->update([
// if ($param['get_num'] > $order['num']) {
// return $this->toData('1', '修改中签数不能大于订单申购数');
// }
// 1 2 5 状态才能修改数量
if (!in_array($order['status'], [1, 2, 5])) {
return $this->toData('1', 'IPO已上市,无法修改');
}
// $getTime = Db::table($tableObj['stock_table'])->where('id', $order['pre_stock_id'])->value('get_time');
// if (env('USER_ARREARS.HAS_USER_ARREARS') == 1 && $order['pay_type'] == 2 && in_array($order['status'], [5, 6])) {
// } else {
// if (strtotime($getTime) < time()) return $this->toData('1', 'IPO已中签,无法修改');
// }
$updateArr = [
'get_num' => $param['get_num'],
'get_amount' => $param['get_num'] * $order['price'],
'get_fee' => $order['get_amount'] * $order['fee_rate'],
'update_time' => date('Y-m-d H:i:s')
]);
];
if ($order['pay_type'] == 2) {
$updateArr['num'] = $param['get_num'];
$updateArr['amount'] = $param['get_num'] * $order['price'];
$updateArr['fee'] = $updateArr['amount'] * $order['fee_rate'];
}
$bool = Db::table($tableObj['order_table'])->where('id', $param['id'])->update($updateArr);
if (!$bool) return $this->toData('1', '修改失败');
return $this->toData('0', 'SUCCESS', []);

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

@ -36,6 +36,7 @@ use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Log;
use think\facade\Queue;
use think\facade\Cache;
class IPOService extends AdminBaseService
{
@ -647,7 +648,6 @@ class IPOService extends AdminBaseService
return $this->toData('1', '无法操作');
}
Db::startTrans();
// 修改股票状态
$num = Db::table($table_obj['stock_table'])->where('id', $preInStock['id'])->update([
@ -662,10 +662,6 @@ class IPOService extends AdminBaseService
$tape_list = $this->getStockTape($market_type);
if (Db::table($table_obj['list_table'])->where('stock_code', $preInStock['stock_code'])->find()) {
Db::rollback();
return $this->toData('1', '股票列表已存在该股票');
}
// 将新股加入股票
$inStock['stock_name'] = $preInStock['stock_name'];
$inStock['stock_code'] = $preInStock['stock_code'];
@ -676,13 +672,19 @@ class IPOService extends AdminBaseService
$inStock['forced_closure'] = 30;
$inStock['up_limit'] = 30;
$inStock['down_limit'] = 30;
$inStock['create_time'] = date('Y-m-d H:i:s');
$inStock['update_time'] = date('Y-m-d H:i:s');
if ($market_type == 5) $inStock['numeric_code'] = $preInStock['numeric_code'];
$bool = Db::table($table_obj['list_table'])->insert($inStock);
if (!$bool) {
Db::rollback();
return $this->toData('1', '股票转移失败');
if (Db::table($table_obj['list_table'])->where('stock_code', $preInStock['stock_code'])->find()) {
$bool = Db::table($table_obj['list_table'])->where('stock_code', $preInStock['stock_code'])->update($inStock);
} else {
$inStock['create_time'] = date('Y-m-d H:i:s');
$bool = Db::table($table_obj['list_table'])->insert($inStock);
if (!$bool) {
Db::rollback();
return $this->toData('1', '股票转移失败');
}
}
// 加入缓存
@ -785,46 +787,68 @@ class IPOService extends AdminBaseService
return $this->toData('1', '市场类型无效');
}
if (empty($param['id']) || !is_numeric($param['id'])) {
return $this->toData('1', '主键 无效');
return $this->toData('1', '主键无效');
}
if (empty($param['type'])) {
return $this->toData('1', '缺少参数');
}
$tape_list = $this->getStockTape($market_type);
$preInStock = Db::table($table_obj['stock_table'])->where('id', $param['id'])->where('open_status', 2)->where('is_delete', 1)->find();
if (empty($preInStock)) {
return $this->toData('1', '股票未上市');
}
if ($preInStock['hq_status'] == 2 && $param['type'] == 'hq') {
// 给行情发送数据
Queue::push('app\admin\job\SendGo', [
'type' => 'hq',
'stock_code' => $preInStock['stock_code'],
'stock_name' => $preInStock['stock_name'],
'tape' => $tape_list['tape'][$preInStock['tape']],
'price' => $preInStock['price'],
'isReal' => 1,
'company_info' => $preInStock['company_info'],
'country' => $table_obj['country'],
'id' => $preInStock['id'],
'source' => 0,
'market_type' => $market_type,
], 'sendGo');
// ✅【防重复点击】锁键
$lockKey = "repeatNoteGo_lock_{$market_type}_{$param['id']}_{$param['type']}";
if (!Cache::store('redis')->setnx($lockKey, 1)) {
return $this->toData('1', '请勿重复操作');
}
if ($preInStock['trade_status'] == 2 && $param['type'] == 'trade') {
Queue::push('app\admin\job\SendGo', [
'type' => 'trade',
'id' => $preInStock['id'],
'stock_code' => $preInStock['stock_code'],
'market_type' => $market_type,
'source' => 0,
], 'sendGo');
// 锁自动过期时间 60 秒(你可以根据需求改为 2-10 秒)
Cache::store('redis')->expire($lockKey, 60);
try {
$tape_list = $this->getStockTape($market_type);
$preInStock = Db::table($table_obj['stock_table'])
->where('id', $param['id'])
->where('open_status', 2)
->where('is_delete', 1)
->find();
if (empty($preInStock)) {
return $this->toData('1', '股票未上市');
}
if ($preInStock['hq_status'] == 2 && $param['type'] == 'hq') {
Queue::push('app\admin\job\SendGo', [
'type' => 'hq',
'stock_code' => $preInStock['stock_code'],
'stock_name' => $preInStock['stock_name'],
'tape' => $tape_list['tape'][$preInStock['tape']] ?? '',
'price' => $preInStock['price'],
'isReal' => 1,
'company_info' => $preInStock['company_info'],
'country' => $table_obj['country'],
'id' => $preInStock['id'],
'source' => 0,
'market_type' => $market_type,
], 'sendGo');
}
if ($preInStock['trade_status'] == 2 && $param['type'] == 'trade') {
Queue::push('app\admin\job\SendGo', [
'type' => 'trade',
'id' => $preInStock['id'],
'stock_code' => $preInStock['stock_code'],
'market_type' => $market_type,
'source' => 0,
], 'sendGo');
}
return $this->toData('0', 'SUCCESS');
} catch (\Throwable $e) {
return $this->toData('1', '系统错误:' . $e->getMessage());
} finally {
// ✅ 无论成功或异常都释放锁
Cache::store('redis')->del($lockKey);
}
return $this->toData('0', 'SUCCESS');
}
/**
* 处理股票IPO中签
*/

8
app/home/service/IPOService.php

@ -221,9 +221,9 @@ class IPOService extends BaseHomeService
if ($preStock['price'] <= 0) {
return $this->toData('1', lang('price_error'), []);
}
$param['pay_type'] = 2;
// 支付类型
if (empty($param['pay_type']) || !is_numeric($param['pay_type']) || !in_array($param['pay_type'], [1, 2])) {
if (empty($param['pay_type']) || !is_numeric($param['pay_type']) || !in_array($param['pay_type'], [2])) {
return $this->toData('1', lang('parameter_error'), []);
}
@ -619,7 +619,9 @@ class IPOService extends BaseHomeService
if (empty($hasOrder)) {
return $this->toData('1', lang('parameter_error'), []);
}
if ($hasOrder['get_num'] <= 0) {
return $this->toData('1', '割当評価と配分を待っています', []);
}
$orderNo = $hasOrder['order_no'];
Db::startTrans();

Loading…
Cancel
Save