Browse Source

init bourse

p1
chuan 2 months ago
parent
commit
b230edde21
  1. 1
      .example.env
  2. 5
      .gitignore
  3. 42
      .travis.yml
  4. 32
      LICENSE.txt
  5. 8
      app/.htaccess
  6. 10
      app/404.html
  7. 22
      app/AppService.php
  8. 94
      app/BaseController.php
  9. 58
      app/ExceptionHandle.php
  10. BIN
      app/GeoLite2-City.mmdb
  11. BIN
      app/GeoLite2-Country.mmdb
  12. 8
      app/Request.php
  13. 85
      app/admin/controller/Admin.php
  14. 15
      app/admin/controller/AdminBaseController.php
  15. 33
      app/admin/controller/Agent.php
  16. 58
      app/admin/controller/Config.php
  17. 41
      app/admin/controller/Country.php
  18. 93
      app/admin/controller/Flow.php
  19. 1046
      app/admin/controller/Index.php
  20. 15
      app/admin/controller/Login.php
  21. 480
      app/admin/controller/Order.php
  22. 29
      app/admin/controller/Recharge.php
  23. 13
      app/admin/controller/Test.php
  24. 39
      app/admin/controller/Upload.php
  25. 126
      app/admin/controller/User.php
  26. 37
      app/admin/controller/Vote.php
  27. 41
      app/admin/controller/Withdraw.php
  28. 48
      app/admin/controller/auth/AuthRole.php
  29. 48
      app/admin/controller/auth/AuthRule.php
  30. 44
      app/admin/controller/document/Announcement.php
  31. 44
      app/admin/controller/document/Banner.php
  32. 44
      app/admin/controller/document/Faq.php
  33. 45
      app/admin/controller/document/Index.php
  34. 38
      app/admin/controller/document/LandingPage.php
  35. 52
      app/admin/controller/setting/BlockStock.php
  36. 33
      app/admin/controller/setting/Brokerage.php
  37. 66
      app/admin/controller/setting/Contract.php
  38. 45
      app/admin/controller/setting/DMarket.php
  39. 40
      app/admin/controller/setting/Digital.php
  40. 28
      app/admin/controller/setting/Drawal.php
  41. 31
      app/admin/controller/setting/Fee.php
  42. 66
      app/admin/controller/setting/Forex.php
  43. 56
      app/admin/controller/setting/GiveStock.php
  44. 39
      app/admin/controller/setting/Hq.php
  45. 47
      app/admin/controller/setting/Language.php
  46. 46
      app/admin/controller/setting/Market.php
  47. 63
      app/admin/controller/setting/Option.php
  48. 46
      app/admin/controller/setting/Payment.php
  49. 91
      app/admin/controller/setting/PreFundStock.php
  50. 59
      app/admin/controller/setting/PreStock.php
  51. 39
      app/admin/controller/setting/Service.php
  52. 41
      app/admin/controller/setting/Stock.php
  53. 25
      app/admin/controller/setting/StockIndex.php
  54. 40
      app/admin/controller/setting/StockMarket.php
  55. 42
      app/admin/controller/setting/StockPrice.php
  56. 54
      app/admin/middleware/AdminLog.php
  57. 22
      app/admin/middleware/Check.php
  58. 616
      app/admin/route/app.php
  59. 762
      app/admin/service/AdminBaseService.php
  60. 362
      app/admin/service/AdminService.php
  61. 154
      app/admin/service/AgentService.php
  62. 1303
      app/admin/service/FlowService.php
  63. 100
      app/admin/service/LoginService.php
  64. 2897
      app/admin/service/OrderService.php
  65. 176
      app/admin/service/RechargeService.php
  66. 1003
      app/admin/service/UserService.php
  67. 139
      app/admin/service/VoteService.php
  68. 346
      app/admin/service/WithdrawService.php
  69. 148
      app/admin/service/auth/AuthRoleService.php
  70. 216
      app/admin/service/auth/AuthRuleService.php
  71. 200
      app/admin/service/document/AnnouncementService.php
  72. 196
      app/admin/service/document/BannerService.php
  73. 195
      app/admin/service/document/FaqService.php
  74. 211
      app/admin/service/document/IndexService.php
  75. 148
      app/admin/service/document/LandingPageService.php
  76. 372
      app/admin/service/setting/BlockStockService.php
  77. 138
      app/admin/service/setting/BrokerageService.php
  78. 348
      app/admin/service/setting/ContractService.php
  79. 161
      app/admin/service/setting/DMarketService.php
  80. 203
      app/admin/service/setting/DigitalService.php
  81. 68
      app/admin/service/setting/DrawalService.php
  82. 202
      app/admin/service/setting/FeeService.php
  83. 270
      app/admin/service/setting/ForexService.php
  84. 133
      app/admin/service/setting/GiveStockService.php
  85. 175
      app/admin/service/setting/HqService.php
  86. 1701
      app/admin/service/setting/IPOService.php
  87. 123
      app/admin/service/setting/LanguageService.php
  88. 161
      app/admin/service/setting/MarketService.php
  89. 327
      app/admin/service/setting/OptionInService.php
  90. 154
      app/admin/service/setting/PaymentService.php
  91. 690
      app/admin/service/setting/PreFundStockService.php
  92. 112
      app/admin/service/setting/ServiceService.php
  93. 65
      app/admin/service/setting/StockIndexService.php
  94. 518
      app/admin/service/setting/StockMarketService.php
  95. 227
      app/admin/service/setting/StockPriceSettingService.php
  96. 43
      app/admin/service/setting/StockService.php
  97. 93
      app/admin/validate/AdminBaseValidate.php
  98. 40
      app/admin/validate/AdminValidate.php
  99. 77
      app/admin/validate/FlowValidate.php
  100. 20
      app/admin/validate/LoginValidate.php

1
.example.env

@ -0,0 +1 @@
APP_DEBUG =true [APP] DEFAULT_TIMEZONE = Asia/Shanghai CROSS_ORIGIN = true [DATABASE] TYPE = mysql HOSTNAME = 35.185.183.202 DATABASE = root USERNAME = bourse PASSWORD = ID}#3CZ^D\SXOZ+ HOSTPORT = 3306 CHARSET = utf8 DEBUG = true prefix = bot_ [LANG] default_lang = zh-cn [REDIS] HOST = 10.87.38.3 PORT = 6379 SELECT = 0 PASSWORD = 7d00cb62-1d1c-4c86-b50a-ebf9f00cc9fd [EMAIL] # 多个以逗号隔开 DENY_EMAIL_TYPE = 163.com,qq.com,126.com,sina.com,sohu.com.aliyun.com,139.com,189.cn Host= smtpdm-ap-southeast-1.aliyun.com // sg-smtp.qcloudmail.com Username=service@reg.twinim.com Password=rE51XlFpjJeMhLoHooX6 From=service@reg.twinim.com [NATION] # 多个以逗号隔开 DENY_NATION = 86,886,852,853 [ENCRYPT] SALT = #$%^issoeasy%$#$^ ADMINSALT = #1%^issoeasy%$%$^ [SMS] # 短信秘钥对 可拼接多个 key@secret,key@secret CONFIG = LTAI5tMYUS9asodB6n2qSL9Y@TIMy9s5m7mHSPZN4uRahok4GRdWH1p [LOGIN] PER_IP_REGISTER_NUM_EVERY_DAY = 100 PER_IP_GET_CODE_NUM = 1000 PER_PHONE_GET_CODE_NUM = 5 [USER] DEFAULT_HEAD_IMG_PATH = /bs/image/default.jpeg [BACKEND] BASE_URL=http://testmg.coincosmic.net [AGENT] AGENT_GROUP_ID=6 [QUOTE] BASE_URL=10.148.0.13:88 DEAL_BASE_URL=http://10.148.0.12:8000 [FEATURE] HAS_TEAM = true HAS_DIGITAL = true HAS_CONTRACT = true HAS_STOCK_US = true [PAY] NOTIFY_URL= https://api.sysdev8.cc [WALLET] NAME=test WALLET_TYPE=TRC-20 HTTP_URL=https://wallet.orcoin.net [QEAE_PAY] #key KEY=399fd368dbd84b3fbee7012f20ca0b45 #代付 key DF_KEY=UQBCGZ3IWBVWUUDXYU8ZDXZ2QOQAC2DN #商户号 MERCHANT=400029056 [REG_USER] INVITE_CODE_REQUIRED = 1 [OPTION_REFRESH] OPTION_REFRESH_IN_URL=https://quotes.sysdev8.cc/option/php/list?country=India

5
.gitignore

@ -0,0 +1,5 @@
/.idea
/.vscode
/vendor
*.log
.env

42
.travis.yml

@ -0,0 +1,42 @@
sudo: false
language: php
branches:
only:
- stable
cache:
directories:
- $HOME/.composer/cache
before_install:
- composer self-update
install:
- composer install --no-dev --no-interaction --ignore-platform-reqs
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip .
- composer require --update-no-dev --no-interaction "topthink/think-image:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0"
- composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0"
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip .
script:
- php think unit
deploy:
provider: releases
api_key:
secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw=
file:
- ThinkPHP_Core.zip
- ThinkPHP_Full.zip
skip_cleanup: true
on:
tags: true

32
LICENSE.txt

@ -0,0 +1,32 @@
ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn)
All rights reserved。
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
Apache Licence是著名的非盈利开源组织Apache采用的协议。
该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
允许代码修改,再作为开源或商业软件发布。需要满足
的条件:
1. 需要给代码的用户一份Apache Licence ;
2. 如果你修改了代码,需要在被修改的文件中说明;
3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
带有原来代码中的协议,商标,专利声明和其他原来作者规
定需要包含的说明;
4. 如果再发布的产品中包含一个Notice文件,则在Notice文
件中需要带有本协议内容。你可以在Notice中增加自己的
许可,但不可以表现为对Apache Licence构成更改。
具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

8
app/.htaccess

@ -0,0 +1,8 @@
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

10
app/404.html

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>404</title>
</head>
<body>
宝藏不见了
</body>
</html>

22
app/AppService.php

@ -0,0 +1,22 @@
<?php
declare (strict_types = 1);
namespace app;
use think\Service;
/**
* 应用服务类
*/
class AppService extends Service
{
public function register()
{
// 服务注册
}
public function boot()
{
// 服务启动
}
}

94
app/BaseController.php

@ -0,0 +1,94 @@
<?php
declare (strict_types = 1);
namespace app;
use think\App;
use think\exception\ValidateException;
use think\Validate;
/**
* 控制器基础类
*/
abstract class BaseController
{
/**
* Request实例
* @var \think\Request
*/
protected $request;
/**
* 应用实例
* @var \think\App
*/
protected $app;
/**
* 是否批量验证
* @var bool
*/
protected $batchValidate = false;
/**
* 控制器中间件
* @var array
*/
protected $middleware = [];
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = $this->app->request;
// 控制器初始化
$this->initialize();
}
// 初始化
protected function initialize()
{}
/**
* 验证数据
* @access protected
* @param array $data 数据
* @param string|array $validate 验证器名或者验证规则数组
* @param array $message 提示信息
* @param bool $batch 是否批量验证
* @return array|string|true
* @throws ValidateException
*/
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
{
if (is_array($validate)) {
$v = new Validate();
$v->rule($validate);
} else {
if (strpos($validate, '.')) {
// 支持场景
[$validate, $scene] = explode('.', $validate);
}
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
$v = new $class();
if (!empty($scene)) {
$v->scene($scene);
}
}
$v->message($message);
// 是否批量验证
if ($batch || $this->batchValidate) {
$v->batch(true);
}
return $v->failException(true)->check($data);
}
}

58
app/ExceptionHandle.php

@ -0,0 +1,58 @@
<?php
namespace app;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\Handle;
use think\exception\HttpException;
use think\exception\HttpResponseException;
use think\exception\ValidateException;
use think\Response;
use Throwable;
/**
* 应用异常处理类
*/
class ExceptionHandle extends Handle
{
/**
* 不需要记录信息(日志)的异常类列表
* @var array
*/
protected $ignoreReport = [
HttpException::class,
HttpResponseException::class,
ModelNotFoundException::class,
DataNotFoundException::class,
ValidateException::class,
];
/**
* 记录异常信息(包括日志或者其它方式记录)
*
* @access public
* @param Throwable $exception
* @return void
*/
public function report(Throwable $exception): void
{
// 使用内置的方式记录异常日志
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @access public
* @param \think\Request $request
* @param Throwable $e
* @return Response
*/
public function render($request, Throwable $e): Response
{
// 添加自定义异常处理机制
// 其他错误交给系统处理
return parent::render($request, $e);
}
}

BIN
app/GeoLite2-City.mmdb

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 MiB

BIN
app/GeoLite2-Country.mmdb

Binary file not shown.

8
app/Request.php

@ -0,0 +1,8 @@
<?php
namespace app;
// 应用请求对象类
class Request extends \think\Request
{
}

85
app/admin/controller/Admin.php

@ -0,0 +1,85 @@
<?php
namespace app\admin\controller;
use app\admin\service\AdminService;
use think\Request;
// 用户管理
class Admin extends AdminBaseController
{
public function addUser()
{
$service = new AdminService();
$result = $service->addUser($this->request->param());
return json($result);
}
public function updateInfo()
{
$service = new AdminService();
$result = $service->updateInfo($this->request->user_id,$this->request->param());
return json($result);
}
public function getUserInfo()
{
$service = new AdminService();
$result = $service->getUserInfo($this->request->user_id);
return json($result);
}
public function updatePassword()
{
$service = new AdminService();
$result = $service->updatePassword($this->request->user_id,$this->request->param());
return json($result);
}
//账号列表
public function getUserList()
{
$returnData = (new AdminService())->getUserList($this->request->param());
return json($returnData);
}
//编辑账号
public function updateAccount(){
$returnData = (new AdminService())->updateAccount($this->request->param('id'),$this->request->param());
return json($returnData);
}
//更新账号状态
public function updateAccountStauts(){
$returnData = (new AdminService())->updateAccountStauts($this->request->param('id'),$this->request->param());
return json($returnData);
}
//删除指定用户
public function del(){
$returnData = (new AdminService())->del($this->request->param('id'));
return json($returnData);
}
//获取用户权限代码
public function getPermCode(){
$returnData = (new AdminService())->getPermCode($this->request->user_id);
return json($returnData);
}
//退出登陆
public function logout()
{
$returnData = (new AdminService())->logout($this->request->user_id);
return json($returnData);
}
//操作日志
public function log()
{
$returnData = (new AdminService())->logList($this->request->param());
return json($returnData);
}
public function inviteCode(){
$returnData = (new AdminService())->inviteCode();
return json($returnData);
}
}

15
app/admin/controller/AdminBaseController.php

@ -0,0 +1,15 @@
<?php
namespace app\admin\controller;
use app\BaseController;
class AdminBaseController extends BaseController
{
public function getAdminId()
{
return $this->request->user_id;
}
}

33
app/admin/controller/Agent.php

@ -0,0 +1,33 @@
<?php
namespace app\admin\controller;
use app\admin\service\AgentService;
class Agent extends AdminBaseController
{
// 代理列表
public function index()
{
$service = new AgentService();
$result = $service->index();
return json($result);
}
// 代理用户列表
public function user()
{
$service = new AgentService();
$result = $service->user($this->request->param());
return json($result);
}
// 管理用户
public function manager()
{
$service = new AgentService();
$result = $service->manager($this->request->param());
return json($result);
}
}

58
app/admin/controller/Config.php

@ -0,0 +1,58 @@
<?php
namespace app\admin\controller;
use think\facade\Filesystem;
use app\model\ConfigModel;
class Config extends AdminBaseController
{
public function setConfig()
{
try {
$param = $this->request->param();
if (empty($param['name'])) return json(['code' => '1', 'message' => '参数错误', 'data' => []]);
$name = $param['name'];
$type = $param['type'] ?? 'string';
$value = $param['value'] ?? '';
$tip = $param['tip'] ?? '';
$insertData = [
'name' => $name,
'group' => 'config',
'title' => $name,
'tip' => $tip,
'type' => $type,
'value' => $value,
];
$config = ConfigModel::where('name', $name)->find();
if (empty($config)) {
$bool = ConfigModel::insert($insertData);
if (!$bool) return json(['code' => '100500', 'message' => '设置失败', 'data' => []]);
} else {
$bool = ConfigModel::where('name', $name)->update($insertData);
if (!$bool) return json(['code' => '100500', 'message' => '设置失败', 'data' => []]);
}
return json(['code' => '0', 'message' => 'Request successful', 'data' => []]);
} catch (\Exception $exception) {
return json(['code' => '100500', 'message' => '系统繁忙', 'data' => [$exception->getMessage()]]);
}
}
public function getConfig()
{
try {
$param = $this->request->param();
if (empty($param['name'])) return json(['code' => '1', 'message' => '参数错误', 'data' => []]);
$name = $param['name'];
$value = ConfigModel::where('name', $name)->value('value');
return json(['code' => '0', 'message' => 'Request successful', 'data' => ['value' => $value]]);
} catch (\Exception $exception) {
return json(['code' => '100500', 'message' => '系统繁忙', 'data' => [$exception->getMessage()]]);
}
}
}

41
app/admin/controller/Country.php

@ -0,0 +1,41 @@
<?php
namespace app\admin\controller;
use app\model\CountryModel;
use think\response\Json;
class Country extends AdminBaseController
{
/**
* @desc 获取国家码和地区
* @return Json
*/
public function getAll(): Json
{
try {
$res = CountryModel::getAll();
$returnData = [];
if(!$res->isEmpty()){
$deny = explode(',', env('NATION.DENY_NATION'));
foreach ($res as $item) {
$active = 1;
if(in_array($item['code'],$deny )){
$active = 0;
}
$returnData[] = [
'id' => $item['id'],
'nameCn' => $item['name_cn'],
'nameEn' => $item['name_en'],
'nation' => $item['code'],
'active' => $active,
];
}
}
return json(['code' => '0', 'message' => '请求成功','data' => $returnData]);
}catch (\Exception $exception){
return json(['code' => '100500', 'message' => '系统繁忙','data' => []]);
}
}
}

93
app/admin/controller/Flow.php

@ -0,0 +1,93 @@
<?php
namespace app\admin\controller;
use app\admin\service\FlowService;
// 资金管理 流水
class Flow extends AdminBaseController
{
public function digital()
{
$service = new FlowService();
$result = $service->digital($this->request->param(),$this->getAdminId());
return json($result);
}
public function stock()
{
$service = new FlowService();
$result = $service->stock($this->request->param(),$this->getAdminId());
return json($result);
}
public function contract()
{
$service = new FlowService();
$result = $service->contract($this->request->param(),$this->getAdminId());
return json($result);
}
public function forex()
{
$service = new FlowService();
$result = $service->forex($this->request->param(),$this->getAdminId());
return json($result);
}
public function transfer()
{
$service = new FlowService();
$result = $service->transfer($this->request->param(),$this->getAdminId());
return json($result);
}
public function fee()
{
$service = new FlowService();
$result = $service->fee($this->request->param(),$this->getAdminId());
return json($result);
}
public function brokerage()
{
$service = new FlowService();
$result = $service->brokerage($this->request->param(),$this->getAdminId());
return json($result);
}
################################ 股票资产流水 #####################################
// 股票流水
public function StockLogs()
{
$service = new FlowService();
$result = $service->StockLogs($this->request->param(),$this->getAdminId());
return json($result);
}
// 基金流水
public function fundStock()
{
$service = new FlowService();
$result = $service->fundStock($this->request->param(),$this->getAdminId());
return json($result);
}
// 印度期权流水
public function inOptionStock()
{
$service = new FlowService();
$result = $service->inOptionStock($this->request->param(),$this->getAdminId());
return json($result);
}
// 印度期权流水
public function blockStock()
{
$service = new FlowService();
$result = $service->blockStock($this->request->param(),$this->getAdminId());
return json($result);
}
}

1046
app/admin/controller/Index.php

File diff suppressed because it is too large

15
app/admin/controller/Login.php

@ -0,0 +1,15 @@
<?php
namespace app\admin\controller;
use app\admin\service\LoginService;
use think\Request;
class Login extends AdminBaseController
{
public function login(Request $request)
{
$returnData = (new LoginService())->login($this->request->post());
return json($returnData);
}
}

480
app/admin/controller/Order.php

@ -0,0 +1,480 @@
<?php
namespace app\admin\controller;
use app\admin\service\OrderService;
class Order extends AdminBaseController
{
######################################## 现货交易 #######################################
// 现货挂单
public function digitalPlace()
{
$service = new OrderService();
$result = $service->digitalPlace($this->request->param(), $this->getAdminId());
return json($result);
}
// 现货撤单
public function digitalBack()
{
$service = new OrderService();
$result = $service->digitalBack($this->request->param(), $this->getAdminId());
return json($result);
}
// 现货完成
public function digitalDeal()
{
$service = new OrderService();
$result = $service->digitalDeal($this->request->param(), $this->getAdminId());
return json($result);
}
######################################## 外汇交易 #######################################
// 合约持仓
public function forexHold()
{
$service = new OrderService();
$result = $service->forexHold($this->request->param(), $this->getAdminId());
return json($result);
}
// 合约挂单
public function forexPlace()
{
$service = new OrderService();
$result = $service->forexPlace($this->request->param(), $this->getAdminId());
return json($result);
}
// 合约撤单
public function forexBack()
{
$service = new OrderService();
$result = $service->forexBack($this->request->param(), $this->getAdminId());
return json($result);
}
// 合约平仓
public function forexClear()
{
$service = new OrderService();
$result = $service->forexClear($this->request->param(), $this->getAdminId());
return json($result);
}
######################################## 合约交易 #######################################
// 合约持仓
public function contractHold()
{
$service = new OrderService();
$result = $service->contractHold($this->request->param(), $this->getAdminId());
return json($result);
}
// 合约挂单
public function contractPlace()
{
$service = new OrderService();
$result = $service->contractPlace($this->request->param(), $this->getAdminId());
return json($result);
}
// 合约撤单
public function contractBack()
{
$service = new OrderService();
$result = $service->contractBack($this->request->param(), $this->getAdminId());
return json($result);
}
// 合约平仓
public function contractClear()
{
$service = new OrderService();
$result = $service->contractClear($this->request->param(), $this->getAdminId());
return json($result);
}
######################################## 秒合约交易 #######################################
// 合约持仓
public function contractSecHold()
{
$service = new OrderService();
$result = $service->contractSecHold($this->request->param(), $this->getAdminId());
return json($result);
}
// 合约挂单
public function contractSecPlace()
{
$service = new OrderService();
$result = $service->contractSecPlace($this->request->param(), $this->getAdminId());
return json($result);
}
// 合约撤单
public function contractSecBack()
{
$service = new OrderService();
$result = $service->contractSecBack($this->request->param(), $this->getAdminId());
return json($result);
}
// 合约平仓
public function contractSecClear()
{
$service = new OrderService();
$result = $service->contractSecClear($this->request->param(), $this->getAdminId());
return json($result);
}
########################################## 股票交易-lod ###########################################
public function stockHold()
{
$service = new OrderService();
$result = $service->stockHold($this->request->param(), $this->getAdminId());
return json($result);
}
// 合约挂单
public function stockPlace()
{
$service = new OrderService();
$result = $service->stockPlace($this->request->param(), $this->getAdminId());
return json($result);
}
// 合约撤单
public function stockBack()
{
$service = new OrderService();
$result = $service->stockBack($this->request->param(), $this->getAdminId());
return json($result);
}
// 合约平仓
public function stockClear()
{
$service = new OrderService();
$result = $service->stockClear($this->request->param(), $this->getAdminId());
return json($result);
}
############################################################## 美股订单
// 美股持仓
public function usStockHold()
{
$service = new OrderService();
$result = $service->usStockHold($this->request->param(), $this->getAdminId());
return json($result);
}
// 美股挂单
public function usStockPlace()
{
$service = new OrderService();
$result = $service->usStockPlace($this->request->param(), $this->getAdminId());
return json($result);
}
// 美股撤单
public function usStockBack()
{
$service = new OrderService();
$result = $service->usStockBack($this->request->param(), $this->getAdminId());
return json($result);
}
// 美股平仓
public function usStockClear()
{
$service = new OrderService();
$result = $service->usStockClear($this->request->param(), $this->getAdminId());
return json($result);
}
############################################################## 印尼股票订单
public function idnStockHold()
{
$service = new OrderService();
$result = $service->idnStockHold($this->request->param(), $this->getAdminId());
return json($result);
}
public function idnStockPlace()
{
$service = new OrderService();
$result = $service->idnStockPlace($this->request->param(), $this->getAdminId());
return json($result);
}
public function idnStockBack()
{
$service = new OrderService();
$result = $service->idnStockBack($this->request->param(), $this->getAdminId());
return json($result);
}
public function idnStockClear()
{
$service = new OrderService();
$result = $service->idnStockClear($this->request->param(), $this->getAdminId());
return json($result);
}
############################################################## 马来西亚股票订单
public function mysStockHold()
{
$service = new OrderService();
$result = $service->mysStockHold($this->request->param(), $this->getAdminId());
return json($result);
}
public function mysStockPlace()
{
$service = new OrderService();
$result = $service->mysStockPlace($this->request->param(), $this->getAdminId());
return json($result);
}
public function mysStockBack()
{
$service = new OrderService();
$result = $service->mysStockBack($this->request->param(), $this->getAdminId());
return json($result);
}
public function mysStockClear()
{
$service = new OrderService();
$result = $service->mysStockClear($this->request->param(), $this->getAdminId());
return json($result);
}
############################################################## 泰国股票订单
public function thaStockHold()
{
$service = new OrderService();
$result = $service->thaStockHold($this->request->param(), $this->getAdminId());
return json($result);
}
public function thaStockPlace()
{
$service = new OrderService();
$result = $service->thaStockPlace($this->request->param(), $this->getAdminId());
return json($result);
}
public function thaStockBack()
{
$service = new OrderService();
$result = $service->thaStockBack($this->request->param(), $this->getAdminId());
return json($result);
}
public function thaStockClear()
{
$service = new OrderService();
$result = $service->thaStockClear($this->request->param(), $this->getAdminId());
return json($result);
}
############################################################## 印度股票订单
public function inStockHold()
{
$service = new OrderService();
$result = $service->inStockHold($this->request->param(), $this->getAdminId());
return json($result);
}
public function inStockPlace()
{
$service = new OrderService();
$result = $service->inStockPlace($this->request->param(), $this->getAdminId());
return json($result);
}
public function inStockBack()
{
$service = new OrderService();
$result = $service->inStockBack($this->request->param(), $this->getAdminId());
return json($result);
}
public function inStockClear()
{
$service = new OrderService();
$result = $service->inStockClear($this->request->param(), $this->getAdminId());
return json($result);
}
############################################################## 新加坡股票订单
public function sgdStockHold()
{
$service = new OrderService();
$result = $service->sgdStockHold($this->request->param(), $this->getAdminId());
return json($result);
}
public function sgdStockPlace()
{
$service = new OrderService();
$result = $service->sgdStockPlace($this->request->param(), $this->getAdminId());
return json($result);
}
public function sgdStockBack()
{
$service = new OrderService();
$result = $service->sgdStockBack($this->request->param(), $this->getAdminId());
return json($result);
}
public function sgdStockClear()
{
$service = new OrderService();
$result = $service->sgdStockClear($this->request->param(), $this->getAdminId());
return json($result);
}
################################################# 申购订单
public function preStock()
{
$service = new OrderService();
$market_type = intval($this->request->param('market_type'));
$result = $service->preStock($market_type,$this->request->param(), $this->getAdminId());
return json($result);
}
public function updateGetNum()
{
$service = new OrderService();
$market_type = intval($this->request->param('market_type'));
$result = $service->updateGetNum($market_type, $this->request->param());
return json($result);
}
public function preRefund()
{
$service = new OrderService();
$market_type = intval($this->request->param('market_type'));
$result = $service->preRefund($market_type, $this->request->param());
return json($result);
}
################################################# 基金
public function fund()
{
$service = new OrderService();
$result = $service->fundStock($this->request->param(), $this->getAdminId());
return json($result);
}
public function fundInfo()
{
$service = new OrderService();
$result = $service->fundStockInfo($this->request->param());
return json($result);
}
public function fundInterestList()
{
$service = new OrderService();
$result = $service->fundInterestList($this->request->param(), $this->getAdminId());
return json($result);
}
################################################# 港股
public function hkStockHold()
{
$service = new OrderService();
$result = $service->hkStockHold($this->request->param(), $this->getAdminId());
return json($result);
}
public function hkStockPlace()
{
$service = new OrderService();
$result = $service->hkStockPlace($this->request->param(), $this->getAdminId());
return json($result);
}
public function hkStockBack()
{
$service = new OrderService();
$result = $service->hkStockBack($this->request->param(), $this->getAdminId());
return json($result);
}
public function hkStockClear()
{
$service = new OrderService();
$result = $service->hkStockClear($this->request->param(), $this->getAdminId());
return json($result);
}
################################################# 印度期权
public function inOptionHold()
{
$service = new OrderService();
$result = $service->inOptionHold($this->request->param(), $this->getAdminId());
return json($result);
}
public function inOptionPlace()
{
$service = new OrderService();
$result = $service->inOptionPlace($this->request->param(), $this->getAdminId());
return json($result);
}
public function inOptionBack()
{
$service = new OrderService();
$result = $service->inOptionBack($this->request->param(), $this->getAdminId());
return json($result);
}
public function inOptionClear()
{
$service = new OrderService();
$result = $service->inOptionClear($this->request->param(), $this->getAdminId());
return json($result);
}
public function block()
{
$service = new OrderService();
$result = $service->blockStock($this->request->param(), $this->getAdminId());
return json($result);
}
}

29
app/admin/controller/Recharge.php

@ -0,0 +1,29 @@
<?php
namespace app\admin\controller;
// 充值订单
use app\admin\service\RechargeService;
class Recharge extends AdminBaseController
{
public function index()
{
$service = new RechargeService();
$result = $service->index($this->request->param(),$this->getAdminId());
return json($result);
}
public function info()
{
$service = new RechargeService();
$result = $service->info($this->request->param(),$this->getAdminId());
return json($result);
}
public function check()
{
$service = new RechargeService();
$result = $service->check($this->request->param(),$this->getAdminId());
return json($result);
}
}

13
app/admin/controller/Test.php

@ -0,0 +1,13 @@
<?php
namespace app\admin\controller;
class Test extends AdminBaseController
{
public function index()
{
return json(['code' => '0', 'msg' => 'SUCCESS', 'data' => []]);
}
}

39
app/admin/controller/Upload.php

@ -0,0 +1,39 @@
<?php
namespace app\admin\controller;
use app\model\FileModel;
use think\facade\Filesystem;
class Upload extends AdminBaseController
{
// 上传图片
public function upload()
{
try {
// 获取文件
$file = $this->request->file('file');
$param = $this->request->param();
$rootPath = $param['path'] ?? '';
$filename = $param['name'] ?? '';
// 将文件存储在本地
$name = Filesystem::disk('local')->putFile($rootPath, $file);
$path = '/bs/image/' . $name;
if (!empty($filename) && file_exists(app()->getRootPath() . 'public' . $path)) {
$newName = app()->getRootPath() . 'public/bs/' . $filename;
copy(app()->getRootPath() . 'public' . $path, $newName);
unlink(app()->getRootPath() . 'public' . $path);
$path = '/bs/' . $filename;
}
// 返回路径
return json(['code' => '0', 'message' => '上传成功', 'data' => ['path' => $path]]);
} catch (\Exception $exception) {
return json(['code' => '100500', 'message' => '系统繁忙', 'data' => [$exception->getMessage()]]);
}
}
}

126
app/admin/controller/User.php

@ -0,0 +1,126 @@
<?php
namespace app\admin\controller;
use app\admin\service\UserService;
// 用户管理
class User extends AdminBaseController
{
// 用户列表
public function index()
{
$service = new UserService();
$result = $service->index($this->request->param(),$this->getAdminId());
return json($result);
}
// 用户状态操作
public function status()
{
$service = new UserService();
$result = $service->status($this->request->param(),$this->getAdminId());
return json($result);
}
// 用户资金管理
public function change()
{
$service = new UserService();
$result = $service->change($this->request->param(),$this->getAdminId());
return json($result);
}
// 用户关系
public function relation()
{
$service = new UserService();
$result = $service->relation($this->request->param(),$this->getAdminId());
return json($result);
}
public function reg_phone()
{
$service = new UserService();
$result = $service->reg_phone($this->request->param(),$this->getAdminId());
return json($result);
}
public function reg_email()
{
$service = new UserService();
$result = $service->reg_email($this->request->param(),$this->getAdminId());
return json($result);
}
public function verifyDetail()
{
$service = new UserService();
$result = $service->verifyDetail($this->request->param());
return json($result);
}
public function verifyDo()
{
$service = new UserService();
$result = $service->verifyDo($this->request->param(),$this->getAdminId());
return json($result);
}
public function leverReview()
{
$service = new UserService();
$result = $service->leverReview($this->request->param());
return json($result);
}
##################### 查看验证码
public function getUserCode()
{
$service = new UserService();
$result = $service->getUserCode($this->request->param());
return json($result);
}
public function getRegCode()
{
$service = new UserService();
$result = $service->getRegCode($this->request->param());
return json($result);
}
public function bankDetail()
{
$service = new UserService();
$result = $service->bankDetail($this->request->param());
return json($result);
}
public function editBank(){
$service = new UserService();
$result = $service->editBank($this->request->param());
return json($result);
}
public function editPassword(){
$service = new UserService();
$result = $service->editPassword($this->request->param());
return json($result);
}
public function autoLogin(){
$service = new UserService();
$result = $service->setAutoLogin($this->request->param());
return json($result);
}
public function getLeverageNum(){
$service = new UserService();
$result = $service->getLeverageNum($this->request->param());
return json($result);
}
public function editLeverageNum(){
$service = new UserService();
$result = $service->editLeverageNum($this->request->param());
return json($result);
}
}

37
app/admin/controller/Vote.php

@ -0,0 +1,37 @@
<?php
namespace app\admin\controller;
use app\admin\controller\AdminBaseController;
use app\admin\service\VoteService;
class Vote extends AdminBaseController
{
public function index()
{
$service = new VoteService();
$result = $service->index($this->request->param());
return json($result);
}
public function add()
{
$service = new VoteService();
$result = $service->add($this->request->param());
return json($result);
}
public function edit()
{
$service = new VoteService();
$result = $service->edit($this->request->param());
return json($result);
}
public function del()
{
$service = new VoteService();
$result = $service->del($this->request->param());
return json($result);
}
}

41
app/admin/controller/Withdraw.php

@ -0,0 +1,41 @@
<?php
namespace app\admin\controller;
use app\admin\service\WithdrawService;
class Withdraw extends AdminBaseController
{
public function index()
{
$service = new WithdrawService();
$result = $service->index($this->request->param(),$this->getAdminId());
return json($result);
}
public function info()
{
$service = new WithdrawService();
$result = $service->info($this->request->param(),$this->getAdminId());
return json($result);
}
public function change_status()
{
$service = new WithdrawService();
$result = $service->change_status($this->request->param(),$this->getAdminId());
return json($result);
}
public function get_balance()
{
$service = new WithdrawService();
$result = $service->get_balance($this->request->param(),$this->getAdminId());
return json($result);
}
public function channel_list()
{
$service = new WithdrawService();
$result = $service->channel_list($this->request->param(),$this->getAdminId());
return json($result);
}
}

48
app/admin/controller/auth/AuthRole.php

@ -0,0 +1,48 @@
<?php
namespace app\admin\controller\auth;
use app\admin\service\auth\AuthRoleService;
use app\admin\controller\AdminBaseController;
use think\Request;
// 用户管理
class AuthRole extends AdminBaseController
{
//新增
public function add()
{
$service = new AuthRoleService();
$result = $service->add($this->request->param());
return json($result);
}
public function edit()
{
$service = new AuthRoleService();
$result = $service->edit($this->request->param('id'),$this->request->param());
return json($result);
}
public function list()
{
$service = new AuthRoleService();
$result = $service->list($this->request->param());
return json($result);
}
public function del()
{
$service = new AuthRoleService();
$result = $service->del($this->request->param('id'));
return json($result);
}
public function updateStatus()
{
$service = new AuthRoleService();
$result = $service->updateStatus($this->request->param('id'),$this->request->param());
return json($result);
}
public function allList(){
$service = new AuthRoleService();
$result = $service->allList($this->request->param());
return json($result);
}
}

48
app/admin/controller/auth/AuthRule.php

@ -0,0 +1,48 @@
<?php
namespace app\admin\controller\auth;
use app\admin\service\auth\AuthRuleService;
use app\admin\controller\AdminBaseController;
// 用户管理
class AuthRule extends AdminBaseController
{
public function add()
{
$service = new AuthRuleService();
$result = $service->add($this->request->param());
return json($result);
}
public function edit()
{
$service = new AuthRuleService();
$result = $service->edit($this->request->param('id'),$this->request->param());
return json($result);
}
public function list()
{
$service = new AuthRuleService();
$result = $service->list($this->request->user_id,$this->request->param());
return json($result);
}
public function allList()
{
$service = new AuthRuleService();
$result = $service->allList($this->request->user_id);
return json($result);
}
public function getSideMenu(){
$service = new AuthRuleService();
$result = $service->getSideMenu($this->request->user_id);
return json($result);
}
public function del()
{
$service = new AuthRuleService();
$result = $service->del($this->request->param('id'));
return json($result);
}
}

44
app/admin/controller/document/Announcement.php

@ -0,0 +1,44 @@
<?php
namespace app\admin\controller\document;
use app\admin\controller\AdminBaseController;
use app\admin\service\document\AnnouncementService;
class Announcement extends AdminBaseController
{
public function index()
{
$service = new AnnouncementService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new AnnouncementService();
$result = $service->add($this->request->param());
return json($result);
}
public function detail()
{
$service = new AnnouncementService();
$result = $service->detail($this->request->param());
return json($result);
}
public function edit()
{
$service = new AnnouncementService();
$result = $service->edit($this->request->param());
return json($result);
}
public function del()
{
$service = new AnnouncementService();
$result = $service->del($this->request->param());
return json($result);
}
}

44
app/admin/controller/document/Banner.php

@ -0,0 +1,44 @@
<?php
namespace app\admin\controller\document;
use app\admin\controller\AdminBaseController;
use app\admin\service\document\BannerService;
class Banner extends AdminBaseController
{
public function index()
{
$service = new BannerService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new BannerService();
$result = $service->add($this->request->param());
return json($result);
}
public function detail()
{
$service = new BannerService();
$result = $service->detail($this->request->param());
return json($result);
}
public function edit()
{
$service = new BannerService();
$result = $service->edit($this->request->param());
return json($result);
}
public function del()
{
$service = new BannerService();
$result = $service->del($this->request->param());
return json($result);
}
}

44
app/admin/controller/document/Faq.php

@ -0,0 +1,44 @@
<?php
namespace app\admin\controller\document;
use app\admin\controller\AdminBaseController;
use app\admin\service\document\FaqService;
class Faq extends AdminBaseController
{
public function index()
{
$service = new FaqService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new FaqService();
$result = $service->add($this->request->param());
return json($result);
}
public function detail()
{
$service = new FaqService();
$result = $service->detail($this->request->param());
return json($result);
}
public function edit()
{
$service = new FaqService();
$result = $service->edit($this->request->param());
return json($result);
}
public function del()
{
$service = new FaqService();
$result = $service->del($this->request->param());
return json($result);
}
}

45
app/admin/controller/document/Index.php

@ -0,0 +1,45 @@
<?php
namespace app\admin\controller\document;
use app\admin\controller\AdminBaseController;
use app\admin\service\document\IndexService;
class Index extends AdminBaseController
{
public function index()
{
$service = new IndexService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new IndexService();
$result = $service->add($this->request->param());
return json($result);
}
public function detail()
{
$service = new IndexService();
$result = $service->detail($this->request->param());
return json($result);
}
public function edit()
{
$service = new IndexService();
$result = $service->edit($this->request->param());
return json($result);
}
public function del()
{
$service = new IndexService();
$result = $service->del($this->request->param());
return json($result);
}
}

38
app/admin/controller/document/LandingPage.php

@ -0,0 +1,38 @@
<?php
namespace app\admin\controller\document;
use app\admin\controller\AdminBaseController;
use app\admin\service\document\LandingPageService;
class LandingPage extends AdminBaseController
{
public function index()
{
$service = new LandingPageService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new LandingPageService();
$result = $service->add($this->request->param());
return json($result);
}
public function edit()
{
$service = new LandingPageService();
$result = $service->edit($this->request->param());
return json($result);
}
public function del()
{
$service = new LandingPageService();
$result = $service->del($this->request->param());
return json($result);
}
}

52
app/admin/controller/setting/BlockStock.php

@ -0,0 +1,52 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\BlockStockService;
// 大宗交易
class BlockStock extends AdminBaseController
{
// 列表
public function index()
{
$service = new BlockStockService();
$result = $service->index($this->request->param());
return json($result);
}
// 新增
public function add()
{
$service = new BlockStockService();
$result = $service->add($this->request->param());
return json($result);
}
// 编辑
public function edit()
{
$service = new BlockStockService();
$result = $service->edit($this->request->param());
return json($result);
}
// 上市
// public function open()
// {
// $service = new BlockStockService();
// $result = $service->open($this->request->param());
// return json($result);
// }
// 删除
// public function del()
// {
// $service = new BlockStockService();
// $result = $service->del($this->request->param());
// return json($result);
// }
}

33
app/admin/controller/setting/Brokerage.php

@ -0,0 +1,33 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\BrokerageService;
class Brokerage extends AdminBaseController
{
public function index()
{
$service = new BrokerageService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new BrokerageService();
$result = $service->add($this->request->param());
return json($result);
}
public function edit()
{
$service = new BrokerageService();
$result = $service->edit($this->request->param());
return json($result);
}
}

66
app/admin/controller/setting/Contract.php

@ -0,0 +1,66 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\ContractService;
// 合约交易对
class Contract extends AdminBaseController
{
public function index()
{
$service = new ContractService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new ContractService();
$result = $service->add($this->request->param());
return json($result);
}
public function edit()
{
$service = new ContractService();
$result = $service->edit($this->request->param());
return json($result);
}
public function getTradeNameList()
{
$service = new ContractService();
$result = $service->getTradeNameList($this->request->param());
return json($result);
}
public function setting()
{
$service = new ContractService();
$result = $service->setting($this->request->param());
return json($result);
}
public function set_add()
{
$service = new ContractService();
$result = $service->set_add($this->request->param());
return json($result);
}
public function set_edit()
{
$service = new ContractService();
$result = $service->set_edit($this->request->param());
return json($result);
}
public function set_del()
{
$service = new ContractService();
$result = $service->set_del($this->request->param());
return json($result);
}
}

45
app/admin/controller/setting/DMarket.php

@ -0,0 +1,45 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\DMarketService;
class DMarket extends AdminBaseController
{
public function index()
{
$service = new DMarketService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new DMarketService();
$result = $service->add($this->request->param());
return json($result);
}
public function detail()
{
$service = new DMarketService();
$result = $service->detail($this->request->param());
return json($result);
}
public function edit()
{
$service = new DMarketService();
$result = $service->edit($this->request->param());
return json($result);
}
public function del()
{
$service = new DMarketService();
$result = $service->del($this->request->param());
return json($result);
}
}

40
app/admin/controller/setting/Digital.php

@ -0,0 +1,40 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\DigitalService;
// 现货交易对
class Digital extends AdminBaseController
{
public function index()
{
$service = new DigitalService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new DigitalService();
$result = $service->add($this->request->param());
return json($result);
}
public function edit()
{
$service = new DigitalService();
$result = $service->edit($this->request->param());
return json($result);
}
public function getTradeNameList()
{
$service = new DigitalService();
$result = $service->getTradeNameList($this->request->param());
return json($result);
}
}

28
app/admin/controller/setting/Drawal.php

@ -0,0 +1,28 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\DrawalService;
class Drawal extends AdminBaseController
{
// 提现手续费
public function index()
{
$service = new DrawalService();
$result = $service->index();
return json($result);
}
public function edit()
{
$service = new DrawalService();
$result = $service->edit($this->request->param());
return json($result);
}
}

31
app/admin/controller/setting/Fee.php

@ -0,0 +1,31 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\FeeService;
// 交易手续费
class Fee extends AdminBaseController
{
public function index()
{
$service = new FeeService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new FeeService();
$result = $service->add($this->request->param());
return json($result);
}
public function edit()
{
$service = new FeeService();
$result = $service->edit($this->request->param());
return json($result);
}
}

66
app/admin/controller/setting/Forex.php

@ -0,0 +1,66 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\ForexService;
// 合约交易对
class Forex extends AdminBaseController
{
public function index()
{
$service = new ForexService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new ForexService();
$result = $service->add($this->request->param());
return json($result);
}
public function edit()
{
$service = new ForexService();
$result = $service->edit($this->request->param());
return json($result);
}
public function getTradeNameList()
{
$service = new ForexService();
$result = $service->getTradeNameList($this->request->param());
return json($result);
}
public function setting()
{
$service = new ForexService();
$result = $service->setting($this->request->param());
return json($result);
}
public function set_add()
{
$service = new ForexService();
$result = $service->set_add($this->request->param());
return json($result);
}
public function set_edit()
{
$service = new ForexService();
$result = $service->set_edit($this->request->param());
return json($result);
}
public function set_del()
{
$service = new ForexService();
$result = $service->set_del($this->request->param());
return json($result);
}
}

56
app/admin/controller/setting/GiveStock.php

@ -0,0 +1,56 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\GiveHkdStockService;
use app\admin\service\setting\GiveIdnStockService;
use app\admin\service\setting\GiveInStockService;
use app\admin\service\setting\GiveMysStockService;
use app\admin\service\setting\GiveSgdStockService;
use app\admin\service\setting\GiveStockService;
use app\admin\service\setting\GiveThaStockService;
use app\admin\service\setting\GiveUsStockService;
use app\model\StockMarketModel;
// 送股
class GiveStock extends AdminBaseController
{
// 列表
public function index()
{
try {
$param = $this->request->param();
if (empty($param['market_type'])) {
$result = [
'code' => 0,
'message' => 'SUCCESS',
'data' => ['total' => 0, 'list' => [], 'extent' => StockMarketModel::STOCK_MARKET_TYPE]
];
return json($result);
}
$result = (new GiveStockService)->index($param['market_type'], $param, $this->getAdminId());
return json($result);
} catch (\Exception $exception) {
return $this->toData('0', 'The system is busy. Please try again later.', [$exception->getMessage()]);
}
}
// 新增
public function add()
{
try {
$param = $this->request->param();
if (empty($param['market_type'])) return json([]);
$result = (new GiveStockService)->add($param['market_type'], $param);
return json($result);
} catch (\Exception $exception) {
return $this->toData('0', 'The system is busy. Please try again later.', [$exception->getMessage()]);
}
}
}

39
app/admin/controller/setting/Hq.php

@ -0,0 +1,39 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\HqService;
// 合约插针行情
class Hq extends AdminBaseController
{
public function index()
{
$service = new HqService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new HqService();
$result = $service->add($this->request->param());
return json($result);
}
public function edit()
{
$service = new HqService();
$result = $service->edit($this->request->param());
return json($result);
}
public function del()
{
$service = new HqService();
$result = $service->del($this->request->param());
return json($result);
}
}

47
app/admin/controller/setting/Language.php

@ -0,0 +1,47 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\LanguageService;
// 多语言设置
class Language extends AdminBaseController
{
public function index()
{
$service = new LanguageService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new LanguageService();
$result = $service->add($this->request->param());
return json($result);
}
public function edit()
{
$service = new LanguageService();
$result = $service->edit($this->request->param());
return json($result);
}
public function del()
{
$service = new LanguageService();
$result = $service->del($this->request->param());
return json($result);
}
public function getNameList()
{
$service = new LanguageService();
$result = $service->getNameList();
return json($result);
}
}

46
app/admin/controller/setting/Market.php

@ -0,0 +1,46 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\MarketService;
class Market extends AdminBaseController
{
public function index()
{
$service = new MarketService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new MarketService();
$result = $service->add($this->request->param());
return json($result);
}
public function detail()
{
$service = new MarketService();
$result = $service->detail($this->request->param());
return json($result);
}
public function edit()
{
$service = new MarketService();
$result = $service->edit($this->request->param());
return json($result);
}
public function del()
{
$service = new MarketService();
$result = $service->del($this->request->param());
return json($result);
}
}

63
app/admin/controller/setting/Option.php

@ -0,0 +1,63 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\OptionInService;
// 期权
class Option extends AdminBaseController
{
/*********************************印度期权*********************************/
public function indexIn()
{
$service = new OptionInService();
$result = $service->index($this->request->param());
return json($result);
}
public function addIn()
{
$service = new OptionInService();
$result = $service->add($this->request->param());
return json($result);
}
public function editIn()
{
$service = new OptionInService();
$result = $service->edit($this->request->param());
return json($result);
}
public function getTradeNameListIn()
{
$service = new OptionInService();
$result = $service->getTradeNameList();
return json($result);
}
public function onOffIn()
{
$service = new OptionInService();
$result = $service->onOff($this->request->param());
return json($result);
}
public function batchEditIn()
{
$service = new OptionInService();
$result = $service->batchEdit($this->request->param());
return json($result);
}
/*********************************印度期权*********************************/
public function refresh()
{
$result = (new OptionInService())->refresh();
return json([]);
}
}

46
app/admin/controller/setting/Payment.php

@ -0,0 +1,46 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\PaymentService;
use think\App;
// 股票交易对
class Payment extends AdminBaseController
{
public function index()
{
$service = new PaymentService();
$result = $service->index($this->request->param());
return json($result);
}
public function add()
{
$service = new PaymentService();
$result = $service->add($this->request->param());
return json($result);
}
public function edit()
{
$service = new PaymentService();
$result = $service->edit($this->request->param());
return json($result);
}
public function info()
{
$service = new PaymentService();
$result = $service->info($this->request->param());
return json($result);
}
public function del()
{
$service = new PaymentService();
$result = $service->del($this->request->param());
return json($result);
}
}

91
app/admin/controller/setting/PreFundStock.php

@ -0,0 +1,91 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\PreFundStockService;
// 基金 新股设置
class PreFundStock extends AdminBaseController
{
// 列表
public function index()
{
$service = new PreFundStockService();
$result = $service->index($this->request->param());
return json($result);
}
// 获取历史走势
public function history()
{
$service = new PreFundStockService();
$result = $service->history($this->request->param());
return json($result);
}
// 新增
public function add()
{
$service = new PreFundStockService();
$result = $service->add($this->request->param());
return json($result);
}
// 编辑
public function edit()
{
$service = new PreFundStockService();
$result = $service->edit($this->request->param());
return json($result);
}
// 上市
public function open()
{
$service = new PreFundStockService();
$result = $service->open($this->request->param());
return json($result);
}
// 退市
public function close()
{
$service = new PreFundStockService();
$result = $service->close($this->request->param());
return json($result);
}
// 编辑
public function del()
{
$service = new PreFundStockService();
$result = $service->del($this->request->param());
return json($result);
}
// 返息-定时任务
public function interest()
{
$service = new PreFundStockService();
$service->interest();
}
public function referStockAdd(){
$service = new PreFundStockService();
$result = $service->referStockAdd($this->request->param());
return json($result);
}
public function referStockDel(){
$service = new PreFundStockService();
$result = $service->referStockDel($this->request->param());
return json($result);
}
}

59
app/admin/controller/setting/PreStock.php

@ -0,0 +1,59 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\IPOService;
// 美股 新股设置
class PreStock extends AdminBaseController
{
// 列表
public function index()
{
$market_type=intval($this->request->param('market_type'));
$result= (new IPOService())->stockIPOList($market_type,$this->request->param(),$this->getAdminId());
return json($result);
}
// 新增
public function add()
{
$market_type=intval($this->request->param('market_type'));
$result = (new IPOService())->addStockIPO($market_type,$this->request->param());
return json($result);
}
// 编辑
public function edit()
{
$market_type=intval($this->request->param('market_type'));
$result = (new IPOService())->editStockIPO($market_type,$this->request->param());
return json($result);
}
// 上市
public function open()
{
$market_type=intval($this->request->param('market_type'));
$result = (new IPOService())->stockIPO($market_type,$this->request->param());
return json($result);
}
public function note(){
$service = new IPOService();
$market_type=intval($this->request->param('market_type'));
$result = $service->repeatNoteGo($market_type,$this->request->param());
return json($result);
}
public function cancel(){
$market_type=intval($this->request->param('market_type'));
$result = (new IPOService())->cancelIPO($market_type,$this->request->param());
return json($result);
}
// 删除
public function del()
{
$market_type=intval($this->request->param('market_type'));
$result = (new IPOService())->delStockIPO($market_type,$this->request->param());
return json($result);
}
}

39
app/admin/controller/setting/Service.php

@ -0,0 +1,39 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\ServiceService;
// 客服配置
class Service extends AdminBaseController
{
public function index()
{
$service = new ServiceService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new ServiceService();
$result = $service->add($this->request->param());
return json($result);
}
public function edit()
{
$service = new ServiceService();
$result = $service->edit($this->request->param());
return json($result);
}
public function del()
{
$service = new ServiceService();
$result = $service->del($this->request->param());
return json($result);
}
}

41
app/admin/controller/setting/Stock.php

@ -0,0 +1,41 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\IPOService;
use app\admin\service\setting\StockService;
// 股票交易对
class Stock extends AdminBaseController
{
public function index()
{
$market_type=$this->request->param('market_type');
$result = (new IPOService())->stockList($market_type,$this->request->param());
return json($result);
}
public function add()
{
$market_type=$this->request->param('market_type');
$result = (new IPOService())->addStock($market_type,$this->request->param());
return json($result);
}
public function edit()
{
$market_type=$this->request->param('market_type');
$result = (new IPOService())->editStock($market_type,$this->request->param());
return json($result);
}
public function getTradeNameList()
{
$market_type=$this->request->param('market_type');
$result = (new IPOService())->getTradeNameList($market_type);
return json($result);
}
}

25
app/admin/controller/setting/StockIndex.php

@ -0,0 +1,25 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\StockIndexService;
/**
* 股票指数操作
*/
class StockIndex extends AdminBaseController
{
public function index()
{
$result = (new StockIndexService())->index();
return json($result);
}
public function update()
{
$result = (new StockIndexService())->update($this->request->param());
return json($result);
}
}

40
app/admin/controller/setting/StockMarket.php

@ -0,0 +1,40 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\StockMarketService;
// 股票市场
class StockMarket extends AdminBaseController
{
public function index()
{
$service = new StockMarketService();
$result = $service->index();
return json($result);
}
public function add()
{
$service = new StockMarketService();
$result = $service->add($this->request->param());
return json($result);
}
public function edit()
{
$service = new StockMarketService();
$result = $service->edit($this->request->param());
return json($result);
}
// 股票筛选 根据股票号 股票市场 模糊搜索股票数据
public function searchStock()
{
$service = new StockMarketService();
$result = $service->searchStock($this->request->param());
return json($result);
}
}

42
app/admin/controller/setting/StockPrice.php

@ -0,0 +1,42 @@
<?php
namespace app\admin\controller\setting;
// 股票盘前价格
use app\admin\controller\AdminBaseController;
use app\admin\service\setting\StockPriceSettingService;
class StockPrice extends AdminBaseController
{
// 列表
public function index()
{
$service = new StockPriceSettingService();
$result = $service->index($this->request->param());
return json($result);
}
// 新增
public function add()
{
$service = new StockPriceSettingService();
$result = $service->add($this->request->param());
return json($result);
}
// 编辑
public function edit()
{
$service = new StockPriceSettingService();
$result = $service->edit($this->request->param());
return json($result);
}
public function del()
{
$service = new StockPriceSettingService();
$result = $service->del($this->request->param());
return json($result);
}
}

54
app/admin/middleware/AdminLog.php

@ -0,0 +1,54 @@
<?php
namespace app\admin\middleware;
use app\utility\BusinessLog;
class AdminLog
{
/**
* 处理请求
*
* @param \think\Request $param
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next)
{
//得到要log的数据
$adminId = $request->user_id;
$pathInfo = $request->pathinfo();
$host = $request->server("HTTP_HOST");
$uri = $request->server("REQUEST_URI");
$ua = $request->server("HTTP_USER_AGENT");
$ip = $request->ip();
//request参数 url上参数
$requestData = $request->request();
//body请求参数
$param = $request->param();
//放入数组
$content = [
"admin_id" => $adminId,
"host" => $host,
"uri" => $uri,
"ua" => $ua,
"ip" => $ip,
"request_param" => json_encode($requestData),
"body_param" => json_encode($param),
"path_info" => '/' . $pathInfo,
"create_date" => date("Y-m-d"),
"create_time" => date("Y-m-d H:i:s")
];
//log
$log = new BusinessLog();
$log->log($content);
//返回
return $next($request);
}
}

22
app/admin/middleware/Check.php

@ -0,0 +1,22 @@
<?php
namespace app\admin\middleware;
use app\utility\Jwt;
class Check
{
public function handle($request, \Closure $next)
{
$token = $request->header('Authorization');
// print_r($token);
// die();
//jwt进行校验token
$res = (new Jwt())->chekToken($token);
if ($res['code'] != 1 ){
return json(['code' => 401, 'message' => $res['msg'],'data' => $res]);
}
$request->user_id = $res['data']->user_id;
return $next($request);
}
}

616
app/admin/route/app.php

@ -0,0 +1,616 @@
<?php
use think\facade\Route;
$header = [
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Max-Age' => 1800,
'Access-Control-Allow-Methods' => 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers' => 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With,Token,Language,X-token,IgnoreCancelToken',
];
// 需要登陆的接口 使用中间件校验 请求路径 XwkjlLbDcG/test
Route::get('/test', 'Test/index');
Route::group('/', function () {
// 上传图片
Route::post('/upload', 'Upload/upload');
// 国家和地区
Route::post('/country', 'Country/getAll');
// 配置
Route::post('/set_config', 'Config/setConfig');
Route::post('/get_config', 'Config/getConfig');
// 首页数据
Route::post('/index', 'Index/index');
// 现货订单
Route::post('/order/digital_place', 'Order/digitalPlace');
Route::post('/order/digital_back', 'Order/digitalBack');
Route::post('/order/digital_deal', 'Order/digitalDeal');
// 合约订单
Route::post('/order/contract_hold', 'Order/contractHold');
Route::post('/order/contract_place', 'Order/contractPlace');
Route::post('/order/contract_back', 'Order/contractBack');
Route::post('/order/contract_clear', 'Order/contractClear');
// 秒合约订单
Route::post('/order/contract_sec_hold', 'Order/contractSecHold');
Route::post('/order/contract_sec_place', 'Order/contractSecPlace');
Route::post('/order/contract_sec_back', 'Order/contractSecBack');
Route::post('/order/contract_sec_clear', 'Order/contractSecClear');
// 外汇订单
Route::post('/order/forex_hold', 'Order/forexHold');
Route::post('/order/forex_place', 'Order/forexPlace');
Route::post('/order/forex_back', 'Order/forexBack');
Route::post('/order/forex_clear', 'Order/forexClear');
// 股票-废弃
// Route::post('/order/stock_hold', 'Order/stockHold');
// Route::post('/order/stock_place', 'Order/stockPlace');
// Route::post('/order/stock_back', 'Order/stockBack');
// Route::post('/order/stock_clear', 'Order/stockClear');
// 美股
Route::post('/order/us_stock_hold', 'Order/StockHold')->append(['market_type' =>3]);
Route::post('/order/us_stock_place', 'Order/StockPlace')->append(['market_type' =>3]);
Route::post('/order/us_stock_back', 'Order/StockBack')->append(['market_type' =>3]);
Route::post('/order/us_stock_clear', 'Order/StockClear')->append(['market_type' =>3]);
// 印尼股票
Route::post('/order/idn_stock_hold', 'Order/StockHold')->append(['market_type' =>4]);
Route::post('/order/idn_stock_place', 'Order/StockPlace')->append(['market_type' =>4]);
Route::post('/order/idn_stock_back', 'Order/StockBack')->append(['market_type' =>4]);
Route::post('/order/idn_stock_clear', 'Order/StockClear')->append(['market_type' =>4]);
// 马来西亚股票
Route::post('/order/mys_stock_hold', 'Order/StockHold')->append(['market_type' =>5]);
Route::post('/order/mys_stock_place', 'Order/StockPlace')->append(['market_type' =>5]);
Route::post('/order/mys_stock_back', 'Order/StockBack')->append(['market_type' =>5]);
Route::post('/order/mys_stock_clear', 'Order/StockClear')->append(['market_type' =>5]);
// 泰国股票
Route::post('/order/tha_stock_hold', 'Order/StockHold')->append(['market_type' =>6]);
Route::post('/order/tha_stock_place', 'Order/StockPlace')->append(['market_type' =>6]);
Route::post('/order/tha_stock_back', 'Order/StockBack')->append(['market_type' =>6]);
Route::post('/order/tha_stock_clear', 'Order/StockClear')->append(['market_type' =>6]);
// 印度股票
Route::post('/order/in_stock_hold', 'Order/StockHold')->append(['market_type' =>7]);
Route::post('/order/in_stock_place', 'Order/stockPlace')->append(['market_type' =>7]);
Route::post('/order/in_stock_back', 'Order/stockBack')->append(['market_type' =>7]);
Route::post('/order/in_stock_clear', 'Order/stockClear')->append(['market_type' =>7]);
// 新加坡股票
Route::post('/order/sgd_stock_hold', 'Order/StockHold')->append(['market_type' =>9]);
Route::post('/order/sgd_stock_place', 'Order/stockPlace')->append(['market_type' =>9]);
Route::post('/order/sgd_stock_back', 'Order/stockBack')->append(['market_type' =>9]);
Route::post('/order/sgd_stock_clear', 'Order/stockClear')->append(['market_type' =>9]);
// 香港股票
Route::post('/order/hk_stock_hold', 'Order/StockHold')->append(['market_type' =>12]);
Route::post('/order/hk_stock_place', 'Order/stockPlace')->append(['market_type' =>12]);
Route::post('/order/hk_stock_back', 'Order/stockBack')->append(['market_type' =>12]);
Route::post('/order/hk_stock_clear', 'Order/stockClear')->append(['market_type' =>12]);
// 英国股票
Route::post('/order/uk_stock_hold', 'Order/StockHold')->append(['market_type' =>14]); // 股票持仓
Route::post('/order/uk_stock_place', 'Order/StockPlace')->append(['market_type' =>14]); // 股票挂单
Route::post('/order/uk_stock_back', 'Order/StockBack')->append(['market_type' =>14]); // 股票撤单
Route::post('/order/uk_stock_clear', 'Order/StockClear')->append(['market_type' =>14]); // 股票平仓
// 法国股票
Route::post('/order/fur_stock_hold', 'Order/StockHold')->append(['market_type' =>15]); // 股票持仓
Route::post('/order/fur_stock_place', 'Order/StockPlace')->append(['market_type' =>15]); // 股票挂单
Route::post('/order/fur_stock_back', 'Order/StockBack')->append(['market_type' =>15]); // 股票撤单
Route::post('/order/fur_stock_clear', 'Order/StockClear')->append(['market_type' =>15]); // 股票平仓
// 德国股票
Route::post('/order/eur_stock_hold', 'Order/StockHold')->append(['market_type' =>16]); // 股票持仓
Route::post('/order/eur_stock_place', 'Order/StockPlace')->append(['market_type' =>16]); // 股票挂单
Route::post('/order/eur_stock_back', 'Order/StockBack')->append(['market_type' =>16]); // 股票撤单
Route::post('/order/eur_stock_clear', 'Order/StockClear')->append(['market_type' =>16]); // 股票平仓
// 巴西股票
Route::post('/order/eur_stock_hold', 'Order/StockHold')->append(['market_type' =>17]); // 股票持仓
Route::post('/order/eur_stock_place', 'Order/StockPlace')->append(['market_type' =>17]); // 股票挂单
Route::post('/order/eur_stock_back', 'Order/StockBack')->append(['market_type' =>17]); // 股票撤单
Route::post('/order/eur_stock_clear', 'Order/StockClear')->append(['market_type' =>17]); // 股票平仓
// 巴西股票
Route::post('/order/jp_stock_hold', 'Order/StockHold')->append(['market_type' =>18]); // 股票持仓
Route::post('/order/jp_stock_place', 'Order/StockPlace')->append(['market_type' =>18]); // 股票挂单
Route::post('/order/jp_stock_back', 'Order/StockBack')->append(['market_type' =>18]); // 股票撤单
Route::post('/order/jp_stock_clear', 'Order/StockClear')->append(['market_type' =>18]); // 股票平仓
// 印度期权
Route::post('/order/in_option_hold', 'Order/inOptionHold'); // 股票持仓
Route::post('/order/in_option_place', 'Order/inOptionPlace'); // 股票挂单
Route::post('/order/in_option_back', 'Order/inOptionBack'); // 股票撤单
Route::post('/order/in_option_clear', 'Order/inOptionClear'); // 股票平仓
// 申购订单
Route::post('/order/pre_stock_order', 'Order/preStock');
Route::post('/order/update_order_num', 'Order/updateGetNum')->middleware('admin_log'); // 修改中签数
Route::post('/order/pre_refund', 'Order/preRefund')->middleware('admin_log'); // ipo订单退款
//基金订单
Route::post('/order/fund_order', 'Order/fund');
Route::post('/order/fund_order_info', 'Order/fundInfo');
Route::post('/order/fund_interest_list', 'Order/fundInterestList');
//大宗交易订单
Route::post('/order/block_order', 'Order/block');
// 代理管理
Route::post('/agent/index', 'Agent/index');
Route::post('/agent/user', 'Agent/user');
Route::post('/agent/manager', 'Agent/manager');
// 用户管理
Route::post('/user/index', 'User/index');
Route::post('/user/status', 'User/status');
Route::post('/user/change', 'User/change')->middleware('admin_log');
Route::post('/user/relation', 'User/relation');
Route::post('/user/reg_phone', 'User/reg_phone')->middleware('admin_log');
Route::post('/user/reg_email', 'User/reg_email')->middleware('admin_log');
Route::post('/user/bank', 'User/bankDetail');
Route::post('/user/edit_bank', 'User/editBank')->middleware('admin_log');
Route::post('/user/edit_password', 'User/editPassword')->middleware('admin_log');
//送股
Route::post('/user/give_stock', 'setting.GiveStock/add')->middleware('admin_log');
Route::post('/user/give_stock_list', 'setting.GiveStock/index');
// 配置管理
// 合约插针行情
Route::post('/setting/hq_index', 'setting.Hq/index');
Route::post('/setting/hq_add', 'setting.Hq/add');
Route::post('/setting/hq_edit', 'setting.Hq/edit');
Route::post('/setting/hq_del', 'setting.Hq/del');
// 合约自发行情
Route::post('/setting/market_index', 'setting.Market/index');
Route::post('/setting/market_add', 'setting.Market/add');
Route::post('/setting/market_detail', 'setting.Market/detail');
Route::post('/setting/market_edit', 'setting.Market/edit');
Route::post('/setting/market_del', 'setting.Market/del');
// 现货行情
Route::post('/setting/d_market_index', 'setting.DMarket/index');
Route::post('/setting/d_market_add', 'setting.DMarket/add');
Route::post('/setting/d_market_detail', 'setting.DMarket/detail');
Route::post('/setting/d_market_edit', 'setting.DMarket/edit');
Route::post('/setting/d_market_del', 'setting.DMarket/del');
// 返佣配置
Route::post('/setting/brokerage_index', 'setting.Brokerage/index');
Route::post('/setting/brokerage_add', 'setting.Brokerage/add')->middleware('admin_log');
Route::post('/setting/brokerage_edit', 'setting.Brokerage/edit')->middleware('admin_log');
// 交易手续费
Route::post('/setting/fee_index', 'setting.Fee/index');
Route::post('/setting/fee_add', 'setting.Fee/add')->middleware('admin_log');
Route::post('/setting/fee_edit', 'setting.Fee/edit')->middleware('admin_log');
// 提现手续费
Route::post('/setting/drawal_index', 'setting.Drawal/index');
Route::post('/setting/drawal_edit', 'setting.Drawal/edit')->middleware('admin_log');
// 多语言
Route::post('/setting/lang_index', 'setting.Language/index');
Route::post('/setting/lang_add', 'setting.Language/add');
Route::post('/setting/lang_edit', 'setting.Language/edit');
Route::post('/setting/lang_del', 'setting.Language/del');
Route::post('/setting/lang_select', 'setting.Language/getNameList');
// 客服
Route::post('/setting/service_index', 'setting.Service/index');
Route::post('/setting/service_add', 'setting.Service/add');
Route::post('/setting/service_edit', 'setting.Service/edit');
Route::post('/setting/service_del', 'setting.Service/del');
// 现货交易对
Route::post('/setting/digital_index', 'setting.Digital/index');
Route::post('/setting/digital_add', 'setting.Digital/add')->middleware('admin_log');
Route::post('/setting/digital_edit', 'setting.Digital/edit')->middleware('admin_log');
Route::post('/setting/digital_select', 'setting.Digital/getTradeNameList');
// 美股股票交易对
Route::post('/setting/us_stock_index', 'setting.Stock/index')->append(['market_type' =>3]);
Route::post('/setting/us_stock_add', 'setting.Stock/add')->append(['market_type' =>3])->middleware('admin_log');
Route::post('/setting/us_stock_edit', 'setting.Stock/edit')->append(['market_type' =>3])->middleware('admin_log');
Route::post('/setting/us_stock_select', 'setting.Stock/getTradeNameList')->append(['market_type' =>3]);
// 印尼股股票交易对
Route::post('/setting/idn_stock_index', 'setting.Stock/index')->append(['market_type' =>4]);
Route::post('/setting/idn_stock_add', 'setting.Stock/add')->append(['market_type' =>4])->middleware('admin_log');
Route::post('/setting/idn_stock_edit', 'setting.Stock/edit')->append(['market_type' =>4])->middleware('admin_log');
Route::post('/setting/idn_stock_select', 'setting.Stock/getTradeNameList')->append(['market_type' =>4]);
// 马股股票交易对
Route::post('/setting/mys_stock_index', 'setting.Stock/index')->append(['market_type' =>5]);
Route::post('/setting/mys_stock_add', 'setting.Stock/add')->append(['market_type' =>5])->middleware('admin_log');
Route::post('/setting/mys_stock_edit', 'setting.Stock/edit')->append(['market_type' =>5])->middleware('admin_log');
Route::post('/setting/mys_stock_select', 'setting.Stock/getTradeNameList')->append(['market_type' =>5]);
// 泰股股票交易对
Route::post('/setting/tha_stock_index', 'setting.Stock/index')->append(['market_type' =>6]);
Route::post('/setting/tha_stock_add', 'setting.Stock/add')->append(['market_type' =>6])->middleware('admin_log');
Route::post('/setting/tha_stock_edit', 'setting.Stock/edit')->append(['market_type' =>6])->middleware('admin_log');
Route::post('/setting/tha_stock_select', 'setting.Stock/getTradeNameList')->append(['market_type' =>6]);
// 印度股票交易对
Route::post('/setting/in_stock_index', 'setting.Stock/index')->append(['market_type' =>7]);
Route::post('/setting/in_stock_add', 'setting.Stock/add')->append(['market_type' =>7])->middleware('admin_log');
Route::post('/setting/in_stock_edit', 'setting.Stock/edit')->append(['market_type' =>7])->middleware('admin_log');
Route::post('/setting/in_stock_select', 'setting.Stock/getTradeNameList')->append(['market_type' =>7]);
// 新加坡股票交易对
Route::post('/setting/sgd_stock_index', 'setting.Stock/index')->append(['market_type' =>9]);
Route::post('/setting/sgd_stock_add', 'setting.Stock/add')->append(['market_type' =>9])->middleware('admin_log');
Route::post('/setting/sgd_stock_edit', 'setting.Stock/edit')->append(['market_type' =>9])->middleware('admin_log');
Route::post('/setting/sgd_stock_select', 'setting.Stock/getTradeNameList')->append(['market_type' =>9]);
// 香港股票交易对
Route::post('/setting/hk_stock_index', 'setting.Stock/index')->append(['market_type' =>12]);
Route::post('/setting/hk_stock_add', 'setting.Stock/add')->append(['market_type' =>12])->middleware('admin_log');
Route::post('/setting/hk_stock_edit', 'setting.Stock/edit')->append(['market_type' =>12])->middleware('admin_log');
Route::post('/setting/hk_stock_select', 'setting.Stock/getTradeNameList')->append(['market_type' =>12]);
// 英国股票交易对
Route::post('/setting/uk_stock_index', 'setting.Stock/index')->append(['market_type' =>14]);
Route::post('/setting/uk_stock_add', 'setting.Stock/add')->append(['market_type' =>14])->middleware('admin_log');
Route::post('/setting/uk_stock_edit', 'setting.Stock/edit')->append(['market_type' =>14])->middleware('admin_log');
Route::post('/setting/uk_stock_select', 'setting.Stock/getTradeNameList')->append(['market_type' =>14]);
Route::post('/setting/fur_stock_index', 'setting.Stock/index')->append(['market_type' =>15]);
Route::post('/setting/fur_stock_add', 'setting.Stock/add')->append(['market_type' =>15])->middleware('admin_log');
Route::post('/setting/fur_stock_edit', 'setting.Stock/edit')->append(['market_type' =>15])->middleware('admin_log');
Route::post('/setting/fur_stock_select', 'setting.Stock/getTradeNameList')->append(['market_type' =>15]);
Route::post('/setting/eur_stock_index', 'setting.Stock/index')->append(['market_type' =>16]);
Route::post('/setting/eur_stock_add', 'setting.Stock/add')->append(['market_type' =>16])->middleware('admin_log');
Route::post('/setting/eur_stock_edit', 'setting.Stock/edit')->append(['market_type' =>16])->middleware('admin_log');
Route::post('/setting/eur_stock_select', 'setting.Stock/getTradeNameList')->append(['market_type' =>16]);
Route::post('/setting/brl_stock_index', 'setting.Stock/index')->append(['market_type' =>17]);
Route::post('/setting/brl_stock_add', 'setting.Stock/add')->append(['market_type' =>17])->middleware('admin_log');
Route::post('/setting/brl_stock_edit', 'setting.Stock/edit')->append(['market_type' =>17])->middleware('admin_log');
Route::post('/setting/brl_stock_select', 'setting.Stock/getTradeNameList')->append(['market_type' =>17]);
Route::post('/setting/jp_stock_index', 'setting.Stock/index')->append(['market_type' =>18]);
Route::post('/setting/jp_stock_add', 'setting.Stock/add')->append(['market_type' =>18])->middleware('admin_log');
Route::post('/setting/jp_stock_edit', 'setting.Stock/edit')->append(['market_type' =>18])->middleware('admin_log');
Route::post('/setting/jp_stock_select', 'setting.Stock/getTradeNameList')->append(['market_type' =>18]);
//外汇
Route::post('/setting/forex_index', 'setting.Forex/index');
Route::post('/setting/forex_add', 'setting.Forex/add');
Route::post('/setting/forex_edit', 'setting.Forex/edit');
Route::post('/setting/forex_select', 'setting.Contract/getTradeNameList');
// 印度期权交易对
Route::post('/setting/in_option_index', 'setting.Option/indexIn');
Route::post('/setting/in_option_add', 'setting.Option/addIn');
Route::post('/setting/in_option_edit', 'setting.Option/editIn');
Route::post('/setting/in_option_select', 'setting.Option/getTradeNameListIn');
Route::post('/setting/in_option_on_off', 'setting.Option/onOffIn');
Route::post('/setting/in_batch_edit', 'setting.Option/batchEditIn');
// 股票市场
Route::post('/setting/stock_market_index', 'setting.StockMarket/index');
Route::post('/setting/stock_market_add', 'setting.StockMarket/add')->middleware('admin_log');
Route::post('/setting/stock_market_edit', 'setting.StockMarket/edit')->middleware('admin_log');
Route::post('/setting/market_stock_search', 'setting.StockMarket/searchStock');
// 合约交易对
Route::post('/setting/contract_index', 'setting.Contract/index');
Route::post('/setting/contract_add', 'setting.Contract/add');
Route::post('/setting/contract_edit', 'setting.Contract/edit');
Route::post('/setting/contract_select', 'setting.Contract/getTradeNameList');
// 合约交易对
Route::post('/setting/contract_setting', 'setting.Contract/setting');
Route::post('/setting/contract_set_add', 'setting.Contract/set_add');
Route::post('/setting/contract_set_edit', 'setting.Contract/set_edit');
Route::post('/setting/contract_set_del', 'setting.Contract/set_del');
// 合约时间收益
Route::post('/setting/contract_setting', 'setting.Contract/setting');
Route::post('/setting/contract_setting_add', 'setting.Contract/set_add');
Route::post('/setting/contract_setting_edit', 'setting.Contract/set_edit');
Route::post('/setting/contract_setting_del', 'setting.Contract/set_del');
// 股票价格设置
Route::post('/setting/stock_prices_index', 'setting.StockPrice/index');
Route::post('/setting/stock_prices_add', 'setting.StockPrice/add')->middleware('admin_log');
Route::post('/setting/stock_prices_edit', 'setting.StockPrice/edit')->middleware('admin_log');
Route::post('/setting/stock_prices_del', 'setting.StockPrice/del')->middleware('admin_log');
// 支付通道设置
Route::post('/setting/payment_list', 'setting.Payment/index');
Route::post('/setting/payment_add', 'setting.Payment/add')->middleware('admin_log');
Route::post('/setting/payment_edit', 'setting.Payment/edit')->middleware('admin_log');
Route::post('/setting/payment_del', 'setting.Payment/del')->middleware('admin_log');
Route::post('/setting/payment_info', 'setting.Payment/info');
// 美股新股设置
Route::post('/setting/pre_us_stock_index', 'setting.PreStock/index')->append(['market_type' =>3]);
Route::post('/setting/pre_us_stock_add', 'setting.PreStock/add')->append(['market_type' =>3])->middleware('admin_log');
Route::post('/setting/pre_us_stock_edit', 'setting.PreStock/edit')->append(['market_type' =>3])->middleware('admin_log');
Route::post('/setting/pre_us_stock_open', 'setting.PreStock/open')->append(['market_type' =>3])->middleware('admin_log');
Route::post('/setting/pre_us_stock_del', 'setting.PreStock/del')->append(['market_type' =>3])->middleware('admin_log');
Route::post('/setting/pre_us_stock_note', 'setting.PreStock/note')->append(['market_type' =>3])->middleware('admin_log');
Route::post('/setting/pre_us_stock_cancel', 'setting.PreStock/cancel')->append(['market_type' =>3])->middleware('admin_log');//取消IPO
// 印尼股新股设置
Route::post('/setting/pre_idn_stock_index', 'setting.PreStock/index')->append(['market_type' =>4]);
Route::post('/setting/pre_idn_stock_add', 'setting.PreStock/add')->append(['market_type' =>4])->middleware('admin_log');
Route::post('/setting/pre_idn_stock_edit', 'setting.PreStock/edit')->append(['market_type' =>4])->middleware('admin_log');
Route::post('/setting/pre_idn_stock_open', 'setting.PreStock/open')->append(['market_type' =>4])->middleware('admin_log');
Route::post('/setting/pre_idn_stock_del', 'setting.PreStock/del')->append(['market_type' =>4])->middleware('admin_log');
Route::post('/setting/pre_idn_stock_note', 'setting.PreStock/note')->append(['market_type' =>4])->middleware('admin_log');
Route::post('/setting/pre_idn_stock_cancel', 'setting.PreStock/cancel')->append(['market_type' =>4])->middleware('admin_log');
// 马来股新股设置
Route::post('/setting/pre_mys_stock_index', 'setting.PreStock/index')->append(['market_type' =>5]);
Route::post('/setting/pre_mys_stock_add', 'setting.PreStock/add')->append(['market_type' =>5])->middleware('admin_log');
Route::post('/setting/pre_mys_stock_edit', 'setting.PreStock/edit')->append(['market_type' =>5])->middleware('admin_log');
Route::post('/setting/pre_mys_stock_open', 'setting.PreStock/open')->append(['market_type' =>5])->middleware('admin_log');
Route::post('/setting/pre_mys_stock_del', 'setting.PreStock/del')->append(['market_type' =>5])->middleware('admin_log');
Route::post('/setting/pre_mys_stock_note', 'setting.PreStock/note')->append(['market_type' =>5])->middleware('admin_log');
Route::post('/setting/pre_mys_stock_cancel', 'setting.PreStock/cancel')->append(['market_type' =>5])->middleware('admin_log');
// 泰股新股设置
Route::post('/setting/pre_tha_stock_index', 'setting.PreStock/index')->append(['market_type' =>6]);
Route::post('/setting/pre_tha_stock_add', 'setting.PreStock/add')->append(['market_type' =>6])->middleware('admin_log');
Route::post('/setting/pre_tha_stock_edit', 'setting.PreStock/edit')->append(['market_type' =>6])->middleware('admin_log');
Route::post('/setting/pre_tha_stock_open', 'setting.PreStock/open')->append(['market_type' =>6])->middleware('admin_log');
Route::post('/setting/pre_tha_stock_del', 'setting.PreStock/del')->append(['market_type' =>6])->middleware('admin_log');
Route::post('/setting/pre_tha_stock_note', 'setting.PreStock/note')->append(['market_type' =>6])->middleware('admin_log');
Route::post('/setting/pre_tha_stock_cancel', 'setting.PreStock/cancel')->append(['market_type' =>6])->middleware('admin_log');
// 印度股新股设置
Route::post('/setting/pre_in_stock_index', 'setting.PreStock/index')->append(['market_type' =>7]);
Route::post('/setting/pre_in_stock_add', 'setting.PreStock/add')->append(['market_type' =>7])->middleware('admin_log');
Route::post('/setting/pre_in_stock_edit', 'setting.PreStock/edit')->append(['market_type' =>7])->middleware('admin_log');
Route::post('/setting/pre_in_stock_open', 'setting.PreStock/open')->append(['market_type' =>7])->middleware('admin_log');
Route::post('/setting/pre_in_stock_del', 'setting.PreStock/del')->append(['market_type' =>7])->middleware('admin_log');
Route::post('/setting/pre_in_stock_note', 'setting.PreStock/note')->append(['market_type' =>7])->middleware('admin_log');
Route::post('/setting/pre_in_stock_cancel', 'setting.PreStock/cancel')->append(['market_type' =>7])->middleware('admin_log');
// 新加坡股新股设置
Route::post('/setting/pre_sgd_stock_index', 'setting.PreStock/index')->append(['market_type' =>9]);
Route::post('/setting/pre_sgd_stock_add', 'setting.PreStock/add')->append(['market_type' =>9])->middleware('admin_log');
Route::post('/setting/pre_sgd_stock_edit', 'setting.PreStock/edit')->append(['market_type' =>9])->middleware('admin_log');
Route::post('/setting/pre_sgd_stock_open', 'setting.PreStock/open')->append(['market_type' =>9])->middleware('admin_log');
Route::post('/setting/pre_sgd_stock_del', 'setting.PreStock/del')->append(['market_type' =>9])->middleware('admin_log');
Route::post('/setting/pre_sgd_stock_note', 'setting.PreStock/note')->append(['market_type' =>9])->middleware('admin_log');
Route::post('/setting/pre_sgd_stock_cancel', 'setting.PreStock/cancel')->append(['market_type' =>9])->middleware('admin_log');
// 香港新股设置
Route::post('/setting/pre_hk_stock_index', 'setting.PreStock/index')->append(['market_type' =>12]);
Route::post('/setting/pre_hk_stock_add', 'setting.PreStock/add')->append(['market_type' =>12])->middleware('admin_log');
Route::post('/setting/pre_hk_stock_edit', 'setting.PreStock/edit')->append(['market_type' =>12])->middleware('admin_log');
Route::post('/setting/pre_hk_stock_open', 'setting.PreStock/open')->append(['market_type' =>12])->middleware('admin_log');
Route::post('/setting/pre_hk_stock_del', 'setting.PreStock/del')->append(['market_type' =>12])->middleware('admin_log');
Route::post('/setting/pre_hk_stock_note', 'setting.PreStock/note')->append(['market_type' =>12])->middleware('admin_log');
Route::post('/setting/pre_hk_stock_cancel', 'setting.PreStock/cancel')->append(['market_type' =>12])->middleware('admin_log');
// 英国新股设置
Route::post('/setting/pre_uk_stock_index', 'setting.PreStock/index')->append(['market_type' =>14]);
Route::post('/setting/pre_uk_stock_add', 'setting.PreStock/add')->append(['market_type' =>14])->middleware('admin_log');
Route::post('/setting/pre_uk_stock_edit', 'setting.PreStock/edit')->append(['market_type' =>14])->middleware('admin_log');
Route::post('/setting/pre_uk_stock_open', 'setting.PreStock/open')->append(['market_type' =>14])->middleware('admin_log');
Route::post('/setting/pre_uk_stock_del', 'setting.PreStock/del')->append(['market_type' =>14])->middleware('admin_log');
Route::post('/setting/pre_uk_stock_note', 'setting.PreStock/note')->append(['market_type' =>14])->middleware('admin_log');
Route::post('/setting/pre_uk_stock_cancel', 'setting.PreStock/cancel')->append(['market_type' =>14])->middleware('admin_log');
Route::post('/setting/pre_fur_stock_index', 'setting.PreStock/index')->append(['market_type' =>15]);
Route::post('/setting/pre_fur_stock_add', 'setting.PreStock/add')->append(['market_type' =>15])->middleware('admin_log');
Route::post('/setting/pre_fur_stock_edit', 'setting.PreStock/edit')->append(['market_type' =>15])->middleware('admin_log');
Route::post('/setting/pre_fur_stock_open', 'setting.PreStock/open')->append(['market_type' =>15])->middleware('admin_log');
Route::post('/setting/pre_fur_stock_del', 'setting.PreStock/del')->append(['market_type' =>15])->middleware('admin_log');
Route::post('/setting/pre_fur_stock_note', 'setting.PreStock/note')->append(['market_type' =>15])->middleware('admin_log');
Route::post('/setting/pre_fur_stock_cancel', 'setting.PreStock/cancel')->append(['market_type' =>15])->middleware('admin_log');
Route::post('/setting/pre_eur_stock_index', 'setting.PreStock/index')->append(['market_type' =>16]);
Route::post('/setting/pre_eur_stock_add', 'setting.PreStock/add')->append(['market_type' =>16])->middleware('admin_log');
Route::post('/setting/pre_eur_stock_edit', 'setting.PreStock/edit')->append(['market_type' =>16])->middleware('admin_log');
Route::post('/setting/pre_eur_stock_open', 'setting.PreStock/open')->append(['market_type' =>16])->middleware('admin_log');
Route::post('/setting/pre_eur_stock_del', 'setting.PreStock/del')->append(['market_type' =>16])->middleware('admin_log');
Route::post('/setting/pre_eur_stock_note', 'setting.PreStock/note')->append(['market_type' =>16])->middleware('admin_log');
Route::post('/setting/pre_eur_stock_cancel', 'setting.PreStock/cancel')->append(['market_type' =>16])->middleware('admin_log');
Route::post('/setting/pre_brl_stock_index', 'setting.PreStock/index')->append(['market_type' =>17]);
Route::post('/setting/pre_brl_stock_add', 'setting.PreStock/add')->append(['market_type' =>17])->middleware('admin_log');
Route::post('/setting/pre_brl_stock_edit', 'setting.PreStock/edit')->append(['market_type' =>17])->middleware('admin_log');
Route::post('/setting/pre_brl_stock_open', 'setting.PreStock/open')->append(['market_type' =>17])->middleware('admin_log');
Route::post('/setting/pre_brl_stock_del', 'setting.PreStock/del')->append(['market_type' =>17])->middleware('admin_log');
Route::post('/setting/pre_brl_stock_note', 'setting.PreStock/note')->append(['market_type' =>17])->middleware('admin_log');
Route::post('/setting/pre_jp_stock_index', 'setting.PreStock/index')->append(['market_type' =>18]);
Route::post('/setting/pre_jp_stock_add', 'setting.PreStock/add')->append(['market_type' =>18])->middleware('admin_log');
Route::post('/setting/pre_jp_stock_edit', 'setting.PreStock/edit')->append(['market_type' =>18])->middleware('admin_log');
Route::post('/setting/pre_jp_stock_open', 'setting.PreStock/open')->append(['market_type' =>18])->middleware('admin_log');
Route::post('/setting/pre_jp_stock_del', 'setting.PreStock/del')->append(['market_type' =>18])->middleware('admin_log');
Route::post('/setting/pre_jp_stock_note', 'setting.PreStock/note')->append(['market_type' =>18])->middleware('admin_log');
Route::post('/setting/pre_stock_cancel', 'setting.PreStock/cancel')->middleware('admin_log');
// 基金配置
Route::post('/setting/pre_fund_stock_index', 'setting.PreFundStock/index');
Route::post('/setting/pre_fund_stock_history', 'setting.PreFundStock/history');
Route::post('/setting/pre_fund_stock_add', 'setting.PreFundStock/add')->middleware('admin_log');
Route::post('/setting/pre_fund_stock_edit', 'setting.PreFundStock/edit')->middleware('admin_log');
Route::post('/setting/pre_fund_stock_open', 'setting.PreFundStock/open')->middleware('admin_log');
Route::post('/setting/pre_fund_stock_close', 'setting.PreFundStock/close')->middleware('admin_log');
Route::post('/setting/pre_fund_stock_del', 'setting.PreFundStock/del');
Route::post('/setting/refer_stock_add', 'setting.PreFundStock/referStockAdd');
Route::post('/setting/refer_stock_del', 'setting.PreFundStock/referStockDel');
//大宗交易配置
Route::post('/setting/block_stock_index', 'setting.BlockStock/index');
Route::post('/setting/block_stock_add', 'setting.BlockStock/add');
Route::post('/setting/block_stock_edit', 'setting.BlockStock/edit');
// 股票指数
Route::post('/setting/stock_index_list', 'setting.StockIndex/index');
Route::post('/setting/stock_index_update', 'setting.StockIndex/update');
// 资金管理
Route::post('/flow/digital', 'Flow/digital');
Route::post('/flow/stock', 'Flow/stock');
Route::post('/flow/contract', 'Flow/contract');
Route::post('/flow/transfer', 'Flow/transfer');
Route::post('/flow/fee', 'Flow/fee');
Route::post('/flow/brokerage', 'Flow/brokerage');
Route::post('/flow/us_stock', 'Flow/StockLogs')->append(['market_type' =>3]);
Route::post('/flow/idn_stock', 'Flow/StockLogs')->append(['market_type' =>4]);
Route::post('/flow/mys_stock', 'Flow/StockLogs')->append(['market_type' =>5]);
Route::post('/flow/tha_stock', 'Flow/StockLogs')->append(['market_type' =>6]);
Route::post('/flow/in_stock', 'Flow/StockLogs')->append(['market_type' =>7]);
Route::post('/flow/sgd_stock', 'Flow/StockLogs')->append(['market_type' =>9]);
Route::post('/flow/hk_stock', 'Flow/StockLogs')->append(['market_type' =>12]);
Route::post('/flow/uk_stock', 'Flow/StockLogs')->append(['market_type' =>14]);
Route::post('/flow/fur_stock', 'Flow/StockLogs')->append(['market_type' =>15]);
Route::post('/flow/eur_stock', 'Flow/StockLogs')->append(['market_type' =>16]);
Route::post('/flow/eur_stock', 'Flow/StockLogs')->append(['market_type' =>17]);
Route::post('/flow/jp_stock', 'Flow/StockLogs')->append(['market_type' =>18]);
Route::post('/flow/fund_stock', 'Flow/fundStock');
Route::post('/flow/in_option_stock', 'Flow/inOptionStock');
Route::post('/flow/block_stock', 'Flow/blockStock');
// 充值订单
Route::post('/recharge/index', 'Recharge/index'); // 充值订单
Route::post('/recharge/info', 'Recharge/info');
Route::post('/recharge/check', 'Recharge/check')->middleware('admin_log');
Route::post('/withdraw/index', 'Withdraw/index');
Route::post('/withdraw/info', 'Withdraw/info');
Route::post('/withdraw/change_status', 'Withdraw/change_status')->middleware('admin_log');
Route::post('/withdraw/get_balance', 'Withdraw/get_balance');
Route::post('/withdraw/channel_list', 'Withdraw/channel_list');
// 文档管理
// 首页文章
Route::post('/document/doc_index', 'document.Index/index');
Route::post('/document/doc_add', 'document.Index/add');
Route::post('/document/doc_detail', 'document.Index/detail');
Route::post('/document/doc_edit', 'document.Index/edit');
Route::post('/document/doc_del', 'document.Index/del');
// 公告管理
Route::post('/document/announcement_index', 'document.Announcement/index');
Route::post('/document/announcement_add', 'document.Announcement/add');
Route::post('/document/announcement_detail', 'document.Announcement/detail');
Route::post('/document/announcement_edit', 'document.Announcement/edit');
Route::post('/document/announcement_del', 'document.Announcement/del');
// FAQ
Route::post('/document/faq_index', 'document.Faq/index');
Route::post('/document/faq_add', 'document.Faq/add');
Route::post('/document/faq_detail', 'document.Faq/detail');
Route::post('/document/faq_edit', 'document.Faq/edit');
Route::post('/document/faq_del', 'document.Faq/del');
// banner
Route::post('/document/banner_index', 'document.Banner/index');
Route::post('/document/banner_add', 'document.Banner/add');
Route::post('/document/banner_detail', 'document.Banner/detail');
Route::post('/document/banner_edit', 'document.Banner/edit');
Route::post('/document/banner_del', 'document.Banner/del');
//用户中心
Route::post('/account/update_info', 'Admin/updateInfo');
Route::post('/account/add', 'Admin/addUser');
Route::get('/account/get_user_info', 'Admin/getUserInfo');
Route::post('/account/update_password', 'Admin/updatePassword');
Route::post('/account/update_status', 'Admin/updateAccountStauts');
Route::post('/account/list', 'Admin/getUserList');
Route::post('/account/del', 'Admin/del');
Route::get('/account/logout', 'Admin/logout');
Route::post('/account/update_account', 'Admin/updateAccount');
Route::get('/account/get_perm_code', 'Admin/getPermCode');
//权限菜单
Route::post('/auth/rule/add', 'auth.AuthRule/add');
Route::post('/auth/rule/edit', 'auth.AuthRule/edit');
Route::post('/auth/rule/list', 'auth.AuthRule/list');
Route::post('/auth/rule/all_list', 'auth.AuthRule/allList');
Route::post('/auth/rule/del', 'auth.AuthRule/del');
Route::get('/auth/rule/get_side_menu', 'auth.AuthRule/getSideMenu');
//权限角色
Route::post('/auth/role/add', 'auth.AuthRole/add');
Route::post('/auth/role/edit', 'auth.AuthRole/edit');
Route::post('/auth/role/list', 'auth.AuthRole/list');
Route::post('/auth/role/update_status', 'auth.AuthRole/updateStatus');
Route::post('/auth/role/all_list', 'auth.AuthRole/allList');
Route::post('/auth/role/del', 'auth.AuthRole/del');
// 实名认证操作
Route::post('/user/verify_detail', 'User/verifyDetail');
Route::post('/user/verify_do', 'User/verifyDo');
Route::post('/user/lever_review', 'User/leverReview');
Route::post('/user/reg_code', 'User/getRegCode');
Route::post('/user/auto_login', 'User/autoLogin');
//设置杠杆
Route::post('/user/get_leverage', 'User/getLeverageNum');
Route::post('/user/edit_leverage', 'User/editLeverageNum')->middleware('admin_log');
// 投票
Route::post('/vote/index', 'Vote/index');
Route::post('/vote/add', 'Vote/add');
Route::post('/vote/edit', 'Vote/edit');
Route::post('/vote/del', 'Vote/del');
// 用户验证码
Route::post('/user/get_user_code', 'User/getUserCode');
})->allowCrossDomain($header)
->middleware('admin_auth');
Route::post('/admin/log', 'Admin/log')->allowCrossDomain($header)->middleware('admin_auth');
//登陆
Route::post('/login/login', 'Login/login')->allowCrossDomain($header);
// 缓存股票数据
Route::get('/cacheIdnStock', 'Index/cacheIdnStock');
Route::get('/cacheUsStock', 'Index/cacheUsStock');
Route::get('/cacheMysStock', 'Index/cacheMysStock');
Route::get('/cacheThaStock', 'Index/cacheThaStock');
Route::get('/cacheInStock', 'Index/cacheInStock');
Route::get('/cacheSgdStock', 'Index/cacheSgdStock');
Route::get('/cacheHkStock', 'Index/cacheHkStock');
Route::get('/cacheGbxStock', 'Index/cacheGbxStock');
Route::get('/cacheFurStock', 'Index/cacheFurStock');
Route::get('/cacheEurStock', 'Index/cacheEurStock');
Route::get('/cacheBrlStock', 'Index/cacheBrlStock');
Route::get('/cacheJpStock', 'Index/cacheJpStock');
Route::get('/cacheForex', 'Index/cacheForex');
Route::get('/cacheInOption', 'Index/cacheInOption');
Route::get('/invite_code', 'Admin/inviteCode');
//Route::get('/cache_stock', 'Index/cacheStock');
Route::get('/cache_redis', 'Index/cacheRedis');
Route::get('/test_send', 'Index/sendToGo');
Route::get('/sign_stock', 'Index/signStock');
Route::post('/add_stock', 'Index/autoAddStock');
Route::get('/deal_stock', 'Index/dealStock');
// 定时任务 基金返息
Route::get('/setting/fund_interest', 'setting.PreFundStock/interest');
Route::get('/setting/in_option_refresh', 'setting.Option/refresh');
// 修改 印度股-source
Route::post('/update_source', 'Index/updateSource');

762
app/admin/service/AdminBaseService.php

@ -0,0 +1,762 @@
<?php
namespace app\admin\service;
use app\model\AdminModel;
use app\model\ContractMarketModel;
use app\model\ContractSettingModel;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use think\db\exception\PDOException;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Log;
class AdminBaseService
{
// 获取redis客户端
public function getRedis()
{
$config = \think\facade\Config::get('cache.stores.redis');
$redis = new \Redis();
try {
$redis->connect($config['host'], $config['port'], 10);
} catch (\Exception $exception) {
echo 'redis连接失败';
}
if (!empty($config['password'])) {
$redis->auth($config['password']);
}
$redis->select($config['select']);
return $redis;
}
/**
* @param string $code // 状态码
* @param string $msg // 提示信息
* @param array $result // 返回结果
* @return array
*/
public function toData(string $code = '', string $msg = '', array $result = []): array
{
return [
'code' => $code,
'message' => $msg,
'data' => $result
];
}
// 根据是否是代理 以及用户id 获取where条件
public function getWhereByIsAgentAndUserId($adminId, $where, $userId)
{
// 判断是否是代理
$isAgent = AdminModel::checkUserIsAgent($adminId);
// 不是代理
if (!$isAgent) {
if ($userId > 0) {
$where[] = ['user_id', '=', $userId];
}
return $where;
}
// 获取管理用户
$userIds = AdminModel::getUserIdsByAgentId($adminId);
if (empty($userIds)) {
return false;
}
// 如果用户搜索
if ($userId > 0) {
$where[] = ['user_id', 'in', $userIds];
$where[] = ['user_id', '=', $userId];
return $where;
}
// 没有用户搜索
$where[] = ['user_id', 'in', $userIds];
return $where;
}
// 校验admin_id 是否可以管理 userId
public function checkUserIdInAgent($adminId, $userId)
{
// 判断是否是代理
$isAgent = AdminModel::checkUserIsAgent($adminId);
// 不是代理
if (!$isAgent) {
return true;
}
$userIds = AdminModel::getUserIdsByAgentId($adminId);
if (in_array($userId, $userIds)) {
return true;
}
return false;
}
/**
* @param $user_id
* @param $account_type
* @param $change_usable_num
* @param $change_frozen_num
* @param $change_type 变动类型:1-充值,2-提现,3-买入,4-卖出,5-冻结,6-解冻,7-账户转出,8-账户转入 ,9-注册返佣,10-开仓返佣 ,11-平仓返佣,12-调账加钱 13-调账减钱 19-基金返息 20-IPO订单退款
*/
public function updateUserAsset($user_id, $account_type, $change_type, $change_usable_num, $change_frozen_num = 0, $order_no = "", $change_log_admin_id = 0, $rate = 0)
{
$prefix = env('database.prefix');
$where['user_id'] = $user_id;
switch ($account_type) {
case 1:
$where['digital_id'] = 'USDT';
$table = $prefix . 'user_digital';
$log_table = $prefix . 'user_digital_log';
$log_data['digital_id'] = 'USDT';
break;
case 2:
$where['contract_id'] = 'USDT';
$table = $prefix . 'user_contract';
$log_table = $prefix . 'user_contract_log';
$log_data['contract_id'] = 'USDT';
break;
case 3:
$where['stock_id'] = 'USD';
$table = $prefix . 'user_stock';
$log_table = $prefix . 'user_stock_log';
$log_data['stock_id'] = 'USD';
break;
case 4:
$where['stock_id'] = 'IDR';
$table = $prefix . 'user_stock_idn';
$log_table = $prefix . 'user_stock_idn_log';
$log_data['stock_id'] = 'IDR';
break;
case 5:
$where['stock_id'] = 'MYR';
$table = $prefix . 'user_stock_mys';
$log_table = $prefix . 'user_stock_mys_log';
$log_data['stock_id'] = 'MYR';
break;
case 6:
$where['stock_id'] = 'THB';
$table = $prefix . 'user_stock_tha';
$log_table = $prefix . 'user_stock_tha_log';
$log_data['stock_id'] = 'THB';
break;
case 7:
$where['stock_id'] = 'INR';
$table = $prefix . 'user_stock_in';
$log_table = $prefix . 'user_stock_in_log';
$log_data['stock_id'] = 'INR';
break;
case 8:
$where['contract_id'] = 'USDT';
$table = $prefix . 'user_contract_sec';
$log_table = $prefix . 'user_contract_sec_log';
$log_data['contract_id'] = 'USDT';
break;
case 9:
$where['stock_id'] = 'SGD';
$table = $prefix . 'user_stock_sgd';
$log_table = $prefix . 'user_stock_sgd_log';
$log_data['stock_id'] = 'SGD';
break;
case 10:
$where['stock_id'] = 'USD';
$table = $prefix . 'user_stock_fund';
$log_table = $prefix . 'user_stock_fund_log';
$log_data['stock_id'] = 'USD';
break;
case 11:
$where['stock_id'] = 'INR';
$table = $prefix . 'user_stock_option_inr';
$log_table = $prefix . 'user_stock_option_inr_log';
$log_data['stock_id'] = 'INR';
break;
case 12:
$where['stock_id'] = 'HKD';
$table = $prefix . 'user_stock_hkd';
$log_table = $prefix . 'user_stock_hkd_log';
$log_data['stock_id'] = 'HKD';
break;
case 14:
$where['stock_id'] = 'GBX';
$table = $prefix . 'user_stock_gbx';
$log_table = $prefix . 'user_stock_gbx_log';
$log_data['stock_id'] = 'GBX';
break;
case 15:
$where['stock_id'] = 'EUR';
$table = $prefix . 'user_stock_fur';
$log_table = $prefix . 'user_stock_fur_log';
$log_data['stock_id'] = 'EUR';
break;
case 16:
$where['stock_id'] = 'EUR';
$table = $prefix . 'user_stock_eur';
$log_table = $prefix . 'user_stock_eur_log';
$log_data['stock_id'] = 'EUR';
break;
case 17:
$where['stock_id'] = 'BRL';
$table = $prefix . 'user_stock_brl';
$log_table = $prefix . 'user_stock_brl_log';
$log_data['stock_id'] = 'BRL';
break;
case 18:
$where['stock_id'] = 'JPY';
$table = $prefix . 'user_stock_jp';
$log_table = $prefix . 'user_stock_jp_log';
$log_data['stock_id'] = 'JPY';
break;
case 19:
$where['contract_id'] = 'USD';
$table = $prefix . 'user_forex';
$log_table = $prefix . 'user_forex_log';
$log_data['contract_id'] = 'USD';
break;
default:
return [
'status' => 100,
'msg' => '账户类型错误'
];
break;
}
Db::startTrans();
try {
//user_stock USD
$account_info = Db::table($table)->where($where)->lock(true)->find();
if (empty($account_info)) {
$insert_data = [
'user_id' => $user_id,
'usable_num' => 0,
'frozen_num' => 0,
'create_time' => date('Y-m-d H:i:s'),
'update_time' => date('Y-m-d H:i:s')
];
if (in_array($account_type, [1, 2, 8])) {
$insert_data['contract_id'] = $where['contract_id'];
} else {
$insert_data['stock_id'] = $where['stock_id'];
}
// 不存在 则新增
Db::table($table)->insert($insert_data);
$account_info = Db::table($table)->where($where)->lock(true)->find();
if (empty($account_info)) {
Db::rollback();
return [
'status' => 300,
'msg' => '用户资金账号不存在'
];
}
}
$last_usable_num = bcadd($account_info['usable_num'], $change_usable_num, 18);
$last_frozen_num = bcadd($account_info['frozen_num'], $change_frozen_num, 18);
if ($last_usable_num < 0) {
Db::rollback();
return [
'status' => 400,
'msg' => '可用资金不能为负'
];
}
if ($change_type == 6) {
if ($last_frozen_num < 0 && abs($last_frozen_num) > 0.01) {
Db::rollback();
return [
'status' => 400,
'msg' => '冻结资金不能为负'
];
} elseif (abs($last_frozen_num) < 0.01) {
$last_frozen_num = 0;
}
} else {
if ($last_frozen_num < 0) {
Db::rollback();
return [
'status' => 400,
'msg' => '冻结资金不能为负'
];
}
}
if (in_array($change_type, [12, 13]) && $change_log_admin_id > 0 && $rate != 0) {
$balance_change_log["user_id"] = $user_id;
$balance_change_log["type"] = $account_type;
$balance_change_log['before_num'] = bcdiv($account_info['usable_num'], $rate, 18);
$balance_change_log["change_num"] = bcdiv($change_usable_num, $rate, 18);
$balance_change_log["currency_rate"] = $rate;
$balance_change_log["admin_id"] = $change_log_admin_id;
$balance_change_log["create_time"] = date('Y-m-d H:i:s');
$balance_log_bool = Db::table('bot_user_balance_change_log')->insert($balance_change_log);
if (!$balance_log_bool) {
Db::rollback();
return [
'status' => 100,
'msg' => '上分 - 账户流水插入失败'
];
}
}
Db::commit();
return [
'status' => 200,
'msg' => 'ok'
];
} catch (ValidateException|PDOException|\Exception $e) {
Db::rollback();
return [
'status' => 100,
'msg' => $e->getMessage()
];
}
}
// 合约插针缓存
public function initContractHqData()
{
$now = date('Y-m-d H:i:s');
$list = ContractMarketModel::where('type', 0)
->whereTime('begin_time', '>', $now)
->field('trade_name as selfContractCode,begin_time as BeginTime,step as Step ,end_time as EndTime,max_price as Price')
->order('id', 'desc')
->select();
$rows = [];
$redis = $this->getRedis();
if (!$list->isEmpty()) {
$rows = $list->toArray();
foreach ($rows as $key => $val) {
$keep_decimal = $redis->hget('CONTRACT:LIST:' . $val['selfContractCode'], 'keep_decimal');
$list[$key]['Digits'] = $keep_decimal;
}
}
$reds_key = "contract_hq_setting";
$redis->del($reds_key);
$redis->set($reds_key, json_encode($rows));
}
public function initContractSetting()
{
$list = ContractSettingModel::getSettingList();
$redis_key = "contract_time_setting";
$redis = $this->getRedis();
$redis->del($redis_key);
$redis->set($redis_key, json_encode($list, JSON_NUMERIC_CHECK));
}
// 合约自发行情缓存
public function initContractMarketData()
{
$now = date('Y-m-d H:i:s');
$list = ContractMarketModel::where('type', 1)
->whereTime('begin_time', '>', $now)
->field('trade_name as selfContractCode,end_time as endTime,max_price as maxPrice')
->order('id', 'desc')
->select();
$rows = [];
if (!$list->isEmpty()) {
$rows = $list->toArray();
}
$key = "contract_market_setting";
$this->redis->set($key, json_encode($rows));
}
public function getBrokerageKey($type)
{
switch ($type) {
case 1:
//平仓返佣
$brokerage_key = 'BROKERAGE:SALE:SETTING';
break;
case 2:
//开仓返佣
$brokerage_key = 'BROKERAGE:BUY:SETTING';
break;
default:
//注册返佣
$brokerage_key = 'BROKERAGE:REG:SETTING';
break;
}
return $brokerage_key;
}
public function getTradeFeeKey($market_type)
{
switch ($market_type) {
case 1:
$fee_key = 'TRADE:FEE:DIGITAL';
break;
case 2:
$fee_key = 'TRADE:FEE:CONTRACT';
break;
case 3:
$fee_key = 'TRADE:FEE:US_STOCK';
break;
case 4:
$fee_key = 'TRADE:FEE:IDN_STOCK';
break;
case 5:
$fee_key = 'TRADE:FEE:MYS_STOCK';
break;
case 6:
$fee_key = 'TRADE:FEE:THA_STOCK';
break;
case 7:
$fee_key = 'TRADE:FEE:IN_STOCK';
break;
case 8:
$fee_key = 'TRADE:FEE:CONTRACT_SEC';
break;
case 9:
$fee_key = 'TRADE:FEE:SGD_STOCK';
break;
case 12:
$fee_key = 'TRADE:FEE:HK_STOCK';
break;
case 14:
$fee_key = 'TRADE:FEE:UK_STOCK';
break;
case 15:
$fee_key = 'TRADE:FEE:FUR_STOCK';
break;
case 16:
$fee_key = 'TRADE:FEE:EUR_STOCK';
break;
case 17:
$fee_key = 'TRADE:FEE:BR_STOCK';
break;
case 18:
$fee_key = 'TRADE:FEE:JP_STOCK';
break;
case 19:
$fee_key = 'TRADE:FEE:FOREX';
break;
default:
$fee_key = '';
break;
}
return $fee_key;
}
/**
* @param $menus
* @param $pid
* @param $showParentName
* @return array|string
*/
function getTreeMenu($menus, $pid = 0, $showParentName = false)
{
$arr = [];
if (empty($menus)) {
return '';
}
if ($showParentName) {
for ($i = 0; $i < count($menus); $i++) {
$parentId = $menus[$i]['pid'];
if ($parentId == '0') {
$menus[$i]['parent_name'] = "";
} else {
$parent = array_filter($menus, function ($item) use ($parentId) {
return $item['id'] == $parentId;
});
if ($parent) {
$parent = array_values($parent);
if ($parent[0]['name']) {
$menus[$i]['parent_name'] = $parent[0]['name'];
} else if ($parent[0]['title']) {
$menus[$i]['parent_name'] = $parent[0]['title'];
}
}
}
}
}
foreach ($menus as $key => $value) {
if ($value['pid'] == $pid) {
$children = $this->getTreeMenu($menus, $value['id']);
if (!empty($children)) {
$value['children'] = $children;
}
//pid=0为顶级菜单,前端不显示
if ($pid == '0') {
unset($value['pid']);
}
$arr[] = $value;
}
}
return $arr;
}
function getSortTreeMenu($menus, $sort = 'order', $pid = 0)
{
$menuList = getTreeMenu($menus, $pid = 0);
foreach ($menuList as $key => $value) {
if (!empty($value['children'])) {
$sort = array_column($value['children'], $sort);
array_multisort($sort, SORT_DESC, $value['children']);
}
}
return $menuList;
}
// 给 go 行情 发送 新增的股票
public function sendNewStockToGo($country, $newStockCode, $oldStockCode, $stockName, $tape, $price = 0, $isReal = 1, $intro = '', $source = 0, $numericCode = 0)
{
try {
switch ($country) {
case 'India':
case 'Thailand':
case 'US':
case 'HongKong':
$price = bcadd($price, 0, 2);
break;
case 'Indonesia':
$price = bcadd($price, 0, 0);
break;
case 'Malaysia':
$price = bcadd($price, 0, 3);
break;
default:
$price = bcadd($price, 0, 2);
}
$responseArr = [
'new_ticker' => $newStockCode, //旧的股票代码 (新增的话 ,两个字段都是一样的值)
'locale' => $country, //国家
'yesterday_close' => $price, //价格
'name' => $stockName, //股票name
'primary_exchange' => $tape, //交易所
'is_real' => $isReal, //1正式股票 2测试股票
'intro' => $intro //股票简介
];
if ($source > 0) {
$responseArr['source'] = $source;
}
if ($country == 'Malaysia') {
$responseArr['numeric_code'] = $numericCode . '';
}
$client = new Client();
$url = env('QUOTE.BASE_URL') . '/spots/list/new/add';
$response = $client->request("POST", $url, [
'json' => $responseArr
]);
$body = $response->getBody()->getContents();
$res = json_decode($body, true);
$responseArr['url'] = $url;
trace('---给行情推送数据---' . json_encode([$res, $responseArr]), 'error');
if (isset($res['code']) && $res['code'] == 200) {
return true;
}
trace('---给行情推送数据异常---' . json_encode([$res, $responseArr]), 'error');
return false;
} catch (\Exception $exception) {
trace('---给行情推送数据异常1---' . $exception->getMessage(), 'error');
} catch (GuzzleException $e) {
trace('---给行情推送数据异常2---' . $e->getMessage(), 'error');
}
return false;
}
// 给 go 行情 发送股票小数位数
public function sendDecimalToGo($country, $stockCode, int $decimal)
{
try {
$client = new Client();
$url = env('QUOTE.BASE_URL') . '/spots/update/keep';
$response = $client->request("POST", $url, [
'json' => [
'currency' => $country,
'stockCode' => $stockCode,
'keepDecimal' => $decimal,
],
]);
$body = $response->getBody()->getContents();
$res = json_decode($body, true);
if (isset($res['code']) && $res['code'] == 200) {
return true;
}
Log::error('给行情推送数据异常 ' . json_encode([$res]));
return false;
} catch (\Exception $exception) {
Log::error('给行情推送数据异常1 ' . $exception->getMessage());
} catch (GuzzleException $e) {
Log::error('给行情推送数据异常2 ' . $e->getMessage());
}
return false;
}
// 给 go 交易 发送股票小数位数 // $preStockId $marketType $stockCode
public function sendStockToGo($preStockId, $stockCode, $marketType)
{
try {
$marketType = $marketType + 0; // 转成数字
$preStockId = $preStockId . '';
$client = new Client();
$url = env('QUOTE.DEAL_BASE_URL') . '/order_sharepre/share_pre_trade';
$response = $client->request("POST", $url, [
'json' => [
'code' => $stockCode,
'id' => $preStockId,
'stock' => $marketType,
],
]);
$body = $response->getBody()->getContents();
$res = json_decode($body, true);
trace('---给交易推送数据---' . json_encode([$res, [
'url' => $url,
'code' => $stockCode,
'id' => $preStockId,
'stock' => $marketType,]]), 'error');
if (isset($res['code']) && $res['code'] == 200) {
return true;
}
return false;
} catch (\Exception $exception) {
trace('---通知交易异常1---' . $exception->getMessage(), 'error');
} catch (GuzzleException $e) {
trace('---通知交易异常1---' . $e->getMessage(), 'error');
}
return false;
}
public function sendStockToTrade($order_no, $stockCode, $marketType)
{
try {
$marketType = $marketType + 0; // 转成数字
$order_no = $order_no . '';
$client = new Client();
$url = env('QUOTE.DEAL_BASE_URL') . '/order_sharepre/share_pre_trade_by_order_no';
$response = $client->request("POST", $url, [
'json' => [
'code' => $stockCode,
'id' => $order_no,
'stock' => $marketType,
],
]);
$body = $response->getBody()->getContents();
$res = json_decode($body, true);
trace('---单个订单给交易推送数据---' . json_encode([$res, [
'url' => $url,
'code' => $stockCode,
'id' => $order_no,
'stock' => $marketType,]]), 'error');
if (isset($res['code']) && $res['code'] == 200) {
return true;
}
return false;
} catch (\Exception $exception) {
trace('---通知交易异常1---' . $exception->getMessage(), 'error');
} catch (GuzzleException $e) {
trace('---通知交易异常1---' . $e->getMessage(), 'error');
}
return false;
}
public function sendUpdateCodeGo($newCode, $oldCode, $marketType)
{
try {
$marketType = $marketType + 0; // 转成数字
$client = new Client();
$url = env('QUOTE.DEAL_BASE_URL') . '/order_sharepre/update_stock_id';
$response = $client->request("POST", $url, [
'json' => [
'code' => $newCode,
'codeOld' => $oldCode,
'stock' => $marketType,
],
]);
$body = $response->getBody()->getContents();
$res = json_decode($body, true);
if (isset($res['code']) && $res['code'] == 200) {
return true;
}
return false;
} catch (\Exception $exception) {
Log::error('给行情推送数据异常1 ' . $exception->getMessage());
} catch (GuzzleException $e) {
Log::error('给行情推送数据异常2 ' . $e->getMessage());
}
return false;
}
/**
* 给go推送股票指数代码
* @param $code
* @param $country
* @param $sort
* @param $status
* @return bool
*/
public function sendStockIndexToGo($code, $country, $sort, $status)
{
try {
$client = new Client();
$url = env('QUOTE.BASE_URL') . '/spots/index/list/new/add';
$response = $client->request("POST", $url, [
'json' => [
'ticker' => $code,
'state' => $status,
'sort' => $sort,
],
]);
$body = $response->getBody()->getContents();
$res = json_decode($body, true);
Log::info('给交易推送数据 ' . json_encode([$res, [
'url' => $url,
'ticker' => $code,
'locale' => $country,
'state' => $status,
'sort' => $sort,
]]));
if (isset($res['code']) && $res['code'] == 200) {
return true;
}
return false;
} catch (\Exception $exception) {
Log::error('给行情推送股票指数数据异常1 ' . $exception->getMessage());
} catch (GuzzleException $e) {
Log::error('给行情推送股票指数数据异常2 ' . $e->getMessage());
}
return false;
}
}

362
app/admin/service/AdminService.php

@ -0,0 +1,362 @@
<?php
namespace app\admin\service;
use app\admin\validate\AdminValidate;
use app\home\service\BaseHomeService;
use app\model\AdminLogModel;
use app\model\AdminModel;
use app\model\AuthRoleModel;
use phpDocumentor\Reflection\Type;
use think\exception\ValidateException;
use app\utility\UnqId;
use function Sodium\compare;
use think\facade\Request;
class AdminService extends AdminBaseService
{
public function addUser($param): array
{
try {
// 参数校验
validate(AdminValidate::class)->scene('addUser')->check($param);
// 查找用户是否存在
$username = $param['user_name'];
$user = AdminModel::getByUserName($username);
if (!empty($user)) {
return $this->toData('200100', '该用户已存在', []);
}
$param['password'] = (new UnqId())->encryptPassword($param['password'], env('ENCRYPT.ADMINSALT'));
$param['invite_code'] = (new BaseHomeService())->getUniqInviteCode();
AdminModel::create($param);
return $this->toData('0', '添加成功.', []);
} catch (ValidateException $validateException) {
$message = $validateException->getError();
return $this->toData('100400', $message);
} catch (\Exception $exception) {
return $this->toData('100500', '系统繁忙.', [$exception->getMessage()]);
}
}
/**
* 获取用户列表
* @return array
*/
public function getUserList($param)
{
try {
$adminModel = new AdminModel();
//查询条件
if (isset($param['user_name']) && !empty($param['user_name'])) {
$adminModel = $adminModel->where('user_name', $param['user_name']);
}
if (isset($param['nick_name']) && !empty($param['nick_name'])) {
$adminModel = $adminModel->where('nick_name', $param['nick_name']);
}
// 总数
$total = $adminModel->count();
$list = $adminModel->withoutField('password,token')->order('id', 'asc')->page($param['page'], $param['limit'])->select()->toArray();
$roleIds = array_column($list, "role_id");
$roleList = AuthRoleModel::where('id', 'in', $roleIds)->field('id,name')->select()->toArray();
$host = Request::host();
$host = str_replace('api.', '', $host);
if (!empty($list)) {
for ($i = 0; $i < count($list); $i++) {
$index = array_search($list[$i]['role_id'], array_column($roleList, 'id'));
if ($index !== false) {
$list[$i]['role_name'] = $roleList[$index]['name'];
}
$list[$i]['url'] = $host . '/register/index?=agent_code='.$list[$i]['invite_code'];
}
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $list]);
} catch (\Exception $exception) {
return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
}
}
/**
* @desc 获取用户信息
* @param $userId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserInfo($userId)
{
try {
if (empty($userId) || $userId <= 0) {
return $this->toData('100403', 'Please log in first', []);
}
$info = AdminModel::find($userId);
if (empty($info)) {
return $this->toData('100400', 'The user does not exist.', []);
}
// 返回数据
return $this->toData('0', 'Modification successful.', $info->toArray());
} catch (\Exception $exception) {
return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
}
}
/**
* @desc 设置用户信息
* @param $userId
* @param $param
* @return array
*/
public function updateInfo($userId, $param): array
{
try {
// 主键
if (empty($userId) || $userId <= 0) {
return $this->toData('200403', 'Please log in first.', []);
}
// 参数校验
validate(AdminValidate::class)->scene('updateInfo')->check($param);
// 查找用户信息
$user = AdminModel::find($userId);
if (empty($user)) {
return $this->toData('200403', 'Please log in first.', []);
}
$user['nick_name'] = $param['nick_name'];
$user['email'] = $param['email'];
$user['mobile'] = isset($param['mobile']) ? $param['mobile'] : null;
$user['desc'] = isset($param['desc']) ? $param['mobile'] : null;
$user->save();
// 返回
return $this->toData('0', 'Modification successful.', []);
} catch (ValidateException $validateException) {
$message = $validateException->getError();
return $this->toData('200400', $message);
} catch (\Exception $exception) {
return $this->toData('200500', 'The system is busy.', [$exception->getMessage()]);
}
}
/**
* 编辑账号信息
* @param $accountId
* @param $param
* @return array
*/
public function updateAccount($accountId, $param): array
{
try {
// 主键
if (empty($accountId) || $accountId <= 0) {
return $this->toData('200404', 'accountId lose.', []);
}
// 参数校验
validate(AdminValidate::class)->scene('updateAccount')->check($param);
// 查找用户信息
$user = AdminModel::find($accountId);
if (empty($user)) {
return $this->toData('200403', '不存在该用户.', []);
}
if (isset($param['password'])) {
$user['password'] = (new UnqId())->encryptPassword($param['password'], env('ENCRYPT.ADMINSALT'));
}
$user['role_id'] = $param['role_id'];
$user['user_name'] = $param['user_name'];
$user['nick_name'] = $param['nick_name'];
$user['email'] = isset($param['email']) ? $param['email'] : null;
$user['remark'] = isset($param['remark']) ? $param['remark'] : null;
$user->save();
// 返回
return $this->toData('0', 'Modification successful.', []);
} catch (ValidateException $validateException) {
$message = $validateException->getError();
return $this->toData('200400', $message);
} catch (\Exception $exception) {
return $this->toData('200500', 'The system is busy.', [$exception->getMessage()]);
}
}
public function updateAccountStauts($accountId, $param): array
{
try {
// 主键
if (empty($accountId) || $accountId <= 0) {
return $this->toData('200404', 'accountId lose.', []);
}
// 参数校验
validate(AdminValidate::class)->scene('updateAccountStatus')->check($param);
// 查找用户信息
$user = AdminModel::find($accountId);
if (empty($user)) {
return $this->toData('200403', 'Please log in first.', []);
}
$user['status'] = $param['status'];
$user->save();
// 返回
return $this->toData('0', 'Modification successful.', []);
} catch (ValidateException $validateException) {
$message = $validateException->getError();
return $this->toData('200400', $message);
} catch (\Exception $exception) {
return $this->toData('200500', 'The system is busy.', [$exception->getMessage()]);
}
}
public function updatePassword($userId, $param): array
{
try {
// 主键
if (empty($userId) || $userId <= 0) {
return $this->toData('200403', 'Please log in first.', []);
}
// 参数校验
validate(AdminValidate::class)->scene('updatePassword')->check($param);
// 查找用户信息
$user = AdminModel::find($userId);
if (empty($user)) {
return $this->toData('200403', 'Please log in first.', []);
}
//检查原始密码
$flag = (new UnqId())->checkPassword($param['old_password'], $user['password'], env('ENCRYPT.ADMINSALT'));
if (!$flag) {
return $this->toData('200401', '原始密码错误', []);
}
//设置新密码
$newPassword = (new UnqId())->encryptPassword($param['new_password'], env('ENCRYPT.ADMINSALT'));
$user['password'] = $newPassword;
$user->save();
// 返回
return $this->toData('0', 'Modification successful.', []);
} catch (ValidateException $validateException) {
$message = $validateException->getError();
return $this->toData('200400', $message);
} catch (\Exception $exception) {
return $this->toData('200500', 'The system is busy.', [$exception->getMessage()]);
}
}
public function del($id): array
{
try {
$adminModel = AdminModel::find($id);
$adminModel->delete();
// 返回
return $this->toData('0', 'Modification successful.', []);
} catch (ValidateException $validateException) {
$message = $validateException->getError();
return $this->toData('200400', $message);
} catch (\Exception $exception) {
return $this->toData('200500', 'The system is busy.', [$exception->getMessage()]);
}
}
/**
* 查询用户权限代码
* @param $id
* @return array
*/
public function getPermCode($id): array
{
try {
$adminModel = AdminModel::find($id);
//根据角色查询权限代码
$roleModel = AuthRoleModel::find($adminModel->role_id);
$rules = $roleModel->rules;
if ($rules) {
$rules = explode(",", $rules);
//字符串转换为数字类型
// $rules=array_map(function ($value){
// return (int)$value;
// },$rules);
}
// 返回
return $this->toData('0', 'Modification successful.', $rules);
} catch (ValidateException $validateException) {
$message = $validateException->getError();
return $this->toData('200400', $message);
} catch (\Exception $exception) {
return $this->toData('200500', 'The system is busy.', [$exception->getMessage()]);
}
}
/**
* @desc 退出登陆
* @param $userId
* @return array
*/
public function logout($userId)
{
try {
// 获取用户
$user = AdminModel::find($userId);
if (empty($user)) {
return $this->toData('200300', '用户不存在', []);
}
$user->token = "";
$user->save();
return $this->toData('0', 'Modification successful.');
} catch (\Exception $exception) {
return $this->toData('200500', 'The system is busy.', [$exception->getMessage()]);
}
}
public function logList($param)
{
try {
$adminLogModel = new AdminLogModel();
//查询条件
if (!empty($param['create_date'])) {
$adminLogModel = $adminLogModel->where('create_date', $param['create_date']);
}
// 总数
$total = $adminLogModel->count();
$list = $adminLogModel->order('id', 'desc')->page($param['page'], $param['limit'])->select()->toArray();
$accountIds = array_column($list, "admin_id");
$accountList = AdminModel::where('id', 'in', $accountIds)->column('user_name', 'id');
// $menuList = AuthRuleModel::column('title', 'path');
if (!empty($list)) {
foreach ($list as &$v) {
$v['admin_name'] = $accountList[$v['admin_id']] ?? '-';
$v['path_text'] = '用户上分';
}
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $list]);
} catch (\Exception $exception) {
return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
}
}
public function inviteCode()
{
try {
$user = AdminModel::select();
foreach ($user as $v){
$inviteCode = (new BaseHomeService())->getUniqInviteCode();
AdminModel::where('id',$v->id)->update(['invite_code'=>$inviteCode]);
}
} catch (\Exception $exception) {
return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
}
}
}

154
app/admin/service/AgentService.php

@ -0,0 +1,154 @@
<?php
namespace app\admin\service;
use app\model\AdminModel;
use app\model\AuthGroupAccessModel;
use app\model\UserModel;
class AgentService extends AdminBaseService
{
// 代理列表
public function index()
{
try {
// $agentUserId = env('AGENT.AGENT_GROUP_ID');
// $agentAdminUserIds = AuthGroupAccessModel::where('group_id', $agentUserId)->column('uid');
$roleId = 10;
$agentAdminUser = AdminModel::where('role_id', 'in', $roleId)->field('id,user_name,nick_name,email,mobile,status,invite_code')->select();
$rows = [];
if (!$agentAdminUser->isEmpty()) {
foreach ($agentAdminUser as $item) {
$rows[] = [
'id' => $item['id'],
'username' => $item['user_name'],
'nickname' => $item['nick_name'],
'email' => $item['email'] ?? '-',
'mobile' => $item['mobile'] ?? '-',
'status' => $item['status'],
'invite_code' => $item['invite_code'],
];
}
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
} catch (\Exception $exception) {
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
}
}
// 代理用户
public function user($param)
{
try {
if (empty($param['agent_id'])) {
return $this->toData('0', 'SUCCESS', ['list' => []]);
}
$userList = UserModel::where('agent_id', 'in', [0, $param['agent_id']])->where('parent_id', 0)
->order('user_id', 'desc')
->select();
$rows = [];
if (!$userList->isEmpty()) {
foreach ($userList as $item) {
$rows[] = [
'id' => $item['user_id'],
'email' => $item['email'],
'user_no' => $item['user_no'],
'status' => $item['agent_id'] == $param['agent_id'],
'agent_id' => $param['agent_id'],
];
}
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
} catch (\Exception $exception) {
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
}
}
public function manager($param)
{
try {
if (empty($param['id']) || !is_numeric($param['id'])) {
return $this->toData('1', '参错错误', ['list' => []]);
}
if (empty($param['agent_id']) || !is_numeric($param['agent_id'])) {
return $this->toData('1', '参错错误', ['list' => []]);
}
$user = UserModel::where('user_id', $param['id'])->find();
if (empty($user)) {
return $this->toData('1', '用户不存在', ['list' => []]);
}
if ($user['parent_id'] != 0) {
return $this->toData('1', '只能绑定顶层用户', ['list' => []]);
}
// 判断代理是否有效
$admin = AdminModel::where('id', $param['agent_id'])->find();
$roleId = 10;
if (empty($admin) || $admin['role_id'] != $roleId) {
return $this->toData('1', '代理不存在', ['list' => []]);
}
// $agentUserId = env('AGENT.AGENT_GROUP_ID');
// $agentAdminUserIds = AuthGroupAccessModel::where('group_id', $agentUserId)->column('uid');
// if(!in_array($param['agent_id'], $agentAdminUserIds)){
// return $this->toData('1', '代理不存在', ['list' => []]);
// }
// 未绑定 直接绑定
if ($user->agent_id == 0) {
UserModel::update(['agent_id' => $param['agent_id']], ['user_id' => $param['id']]);
return $this->toData('0', 'SUCCESS', []);
}
// 取消绑定
if ($user->agent_id == $param['agent_id']) {
UserModel::update(['agent_id' => 0], ['user_id' => $param['id']]);
return $this->toData('0', 'SUCCESS', []);
}
return $this->toData('1', '该用户已被其他代理绑定, 请先取消绑定', []);
} catch (\Exception $exception) {
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
}
}
public function addUser($param)
{
try {
if (empty($param['agent_id']) || !is_numeric($param['agent_id'])) {
return $this->toData('1', '参错错误');
}
if (empty($param['user_id']) || !is_numeric($param['user_id'])) {
return $this->toData('1', '参错错误');
}
$user = UserModel::where('user_id', $param['user_id'])->find();
if (empty($user)) {
return $this->toData('1', '用户不存在');
}
if ($user['parent_id'] != 0) {
return $this->toData('1', '只能绑定顶层用户');
}
// 判断代理是否有效
$admin = AdminModel::where('id', $param['agent_id'])->find();
$roleId = 10;
if (empty($admin) || $admin['role_id'] != $roleId) {
return $this->toData('1', '代理不存在');
}
UserModel::update(['agent_id' => $param['agent_id']], ['user_id' => $param['user_id']]);
return $this->toData('0', 'SUCCESS', []);
} catch (\Exception $exception) {
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
}
}
}

1303
app/admin/service/FlowService.php

File diff suppressed because it is too large

100
app/admin/service/LoginService.php

@ -0,0 +1,100 @@
<?php
namespace app\admin\service;
use app\admin\validate\LoginValidate;
use app\model\AdminModel;
use app\model\AuthRoleModel;
use app\utility\Jwt;
use app\utility\UnqId;
use think\exception\ValidateException;
use think\facade\Cache;
use think\Log;
class LoginService extends AdminBaseService
{
/**
* @desc 账号密码登陆
* @param $param
* @return array
*/
public function login($param): array
{
try {
// 参数校验
validate(LoginValidate::class)->scene('login')->check($param);
// 获取用户
$info = AdminModel::getByUserName($param['user_name']);
if(empty($info)){
return $this->toData('200300', 'Incorrect account or password.1', []);
}
if($info->status!==1){
return $this->toData('200300', '该账户已被禁用', []);
}
//查看角色状态
$role=AuthRoleModel::find($info->role_id);
if(!$role||$role->status!==1){
return $this->toData('200300', '该账户所在的群组已被禁用', []);
}
// 校验密码
$checkPasswordBool = (new UnqId())->checkPassword($param['password'], $info->password,env('ENCRYPT.ADMINSALT'));
if(!$checkPasswordBool){
return $this->toData('200300', 'Incorrect account or password.3', []);
}
$token = (new Jwt())->generateToken($info->id);
if(empty($token)){
return $this->toData('200400', 'The system is busy. Please try again later.1', []);
}
//保存token
$info->token=$token;
$info->save();
// $key = 'TOKEN:USER:'.$token;
// $expired = 3600*24;
// Cache::store('redis')->set($key, 9999999999, $expired);
$info=$info->toArray();
$this->setUserTokenCache($token, $info['id']);
// 返回结果以及用户信息
return $this->toData('0', 'Request successful.', [
'id' => $info['id'],
'nickname' => $info['nick_name'],
'email' => $info['email'],
'token' => $token,
]);
}catch (ValidateException $validateException) {
// 参数校验失败 异常类
$message = $validateException->getError();
return $this->toData('100400', $message);
}catch (\Exception $exception){
return $this->toData('200500', 'The system is busy. Please try again later.', [$exception->getMessage(), $exception->getTrace()]);
}
}
public function setUserTokenCache($token, $userId)
{
// 清除之前的token 设置新的token
$userTokenKey = 'USER:TOKEN:'.$userId; // 根据用户id 查找token
$oldToken = Cache::store('redis')->get($userTokenKey);
if($oldToken){
$oldTokenKey = 'TOKEN:USER:'.$oldToken;
Cache::store('redis')->delete($oldTokenKey);
}
//trace('---设置用户登陆凭证--'.$userId.'----'.$token, 'error');
$tokenKey = 'TOKEN:USER:'.$token; // 根据token查找用户id
$expired = 30 * 24 * 60 * 60;
// 由中间件自动续期
Cache::store('redis')->set($tokenKey, $userId, $expired);
Cache::store('redis')->set($userTokenKey, $token, $expired);
}
}

2897
app/admin/service/OrderService.php

File diff suppressed because it is too large

176
app/admin/service/RechargeService.php

@ -0,0 +1,176 @@
<?php
namespace app\admin\service;
use app\admin\validate\RechargeValidate;
use app\model\AdminModel;
use app\model\FileModel;
use app\model\PaymentListModel;
use app\model\RechargeApplyModel;
use app\model\UserModel;
class RechargeService extends AdminBaseService
{
public function index($param, $adminId)
{
try {
// 参数校验
validate(RechargeValidate::class)->scene('index')->check($param);
$where = [];
$userId = 0;
// 用户号精确搜索
if (!empty($param['user_no'])) {
$user = UserModel::where('user_no', $param['user_no'])->find();
if (empty($user)) {
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], ]);
}
$userId = $user['user_id'];
}
$statusList = RechargeApplyModel::$statusList;
// 判断是否是代理 如果是代理 只能看他自己管理的用户
$whereU = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId);
if (!is_array($whereU)) {
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extend' => $statusList]);
}
// 订单号
if (!empty($param['order_id'])) {
$where['order_no'] = $param['order_id'];
}
if (isset($param['is_online'])) {
$where['is_online'] = $param['is_online'];
if ($param['is_online'] == 1) $statusList[0] = '用户取消';
}
if (isset($param['status'])) {
$where['status'] = $param['status'];
}
if (!empty($param['start_time']) && !empty($param['end_time'])) {
$where['update_time'] = ['between time', [$param['start_time'], $param['end_time']]];
}
// 列表
$list = RechargeApplyModel::where($where)->where($whereU)->order('id', 'desc')->page($param['page'], $param['limit'])->select();
// 总数
$total = RechargeApplyModel::where($where)->where($whereU)->count();
// 统计 充值成功
$sum = RechargeApplyModel::where($where)->where($whereU)->where('status', 1)->sum('recharge_num');
$rows = [];
if (!$list->isEmpty()) {
// 获取用户号
$userIdArr = [];
foreach ($list as $idItem) {
$userIdArr[] = $idItem['user_id'];
}
$userNoArr = UserModel::where('user_id', 'in', $userIdArr)->column('user_no', 'user_id');
$rows = $list->toArray();
foreach ($rows as $key => $item) {
$rows[$key]['status_text'] = $statusList[$item['status']];
$rows[$key]['user_no'] = $userNoArr[$item['user_id']] ?? '-'; // 用户号
$rows[$key]['order_id'] = $item['order_no'];
$rows[$key]['recharge_channel'] = PaymentListModel::where('id', $item['recharge_channel'])->value('channel');
}
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows, 'sum' => $sum . 'USD', 'extend' => $statusList]);
} catch (\Exception $exception) {
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
}
}
public function info($param, $adminId)
{
try {
// 参数校验
validate(RechargeValidate::class)->scene('info')->check($param);
$where = [
'id' => $param['id']
];
$userId = 0;
$where = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId);
if (!is_array($where)) {
return $this->toData('0', 'SUCCESS', []);
}
$info = RechargeApplyModel::getOrderInfo($where);
if ($info['file_id']) {
$info['file_url'] = FileModel::getFilePath($info['file_id']);
}
$payment_info = PaymentListModel::getPaymentInfo([
'id' => $info['recharge_channel']
]);
if ($payment_info) {
$info['recharge_channel'] = !isset($payment_info['channel']) ? $payment_info['channel'] : $info['recharge_channel'];
$info['bank_name'] = !isset($payment_info['bank_name']) ? $payment_info['bank_name'] : '';
$info['bank_branch'] = !isset($payment_info['bank_branch']) ? $payment_info['bank_branch'] : '';
$info['bank_user'] = !isset($payment_info['bank_user']) ? $payment_info['bank_user'] : '';
$info['bank_account'] = !isset($payment_info['bank_account']) ? $payment_info['bank_account'] : '';
$info['wallet_address'] = !isset($payment_info['wallet_address']) ? $payment_info['wallet_address'] : '';
}
return $this->toData('0', 'SUCCESS', $info);
} catch (\Exception $exception) {
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
}
}
public function check($param, $adminId)
{
try {
// 参数校验
validate(RechargeValidate::class)->scene('info')->check($param);
$isAgent = AdminModel::checkUserIsAgent($adminId);
if ($isAgent) {
return $this->toData('10040', '代理无权限操作');
}
$where = [
'id' => $param['id']
];
$userId = 0;
$where = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId);
if (!is_array($where)) {
return $this->toData('0', 'SUCCESS', []);
}
$info = RechargeApplyModel::getOrderInfo($where);
if ($info) {
if ($info['is_online'] == 1){
return $this->toData('10040', '在线充值 不可操作');
}
if ($info['is_check'] == 0) {
if ($param['check_status'] == 1) {
$result = $this->updateUserAsset($info['user_id'], $info['account_type'], 1, $info['market_amount'], 0, $info['order_no']);
if ($result['status'] == 200) {
RechargeApplyModel::where('id', $info['id'])->update([
'is_check' => 1,
'status' => 1,
'deal_time' => date('Y-m-d H:i:s')
]);
} else {
return $this->toData('1015', '系统异常 请稍后重试');
}
} else {
RechargeApplyModel::where('id', $info['id'])->update([
'is_check' => 2,
'status' => 2
]);
}
}
if ($info['file_id']) {
$info['file_url'] = FileModel::getFilePath($info['file_id']);
$file = dirname(dirname(dirname(__DIR__))) . "/public" . $info['file_url'];
@unlink($file);
}
return $this->toData('0', 'SUCCESS', []);
} else {
return $this->toData('1', '参数错误', []);
}
} catch (\Exception $exception) {
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
}
}
}

1003
app/admin/service/UserService.php

File diff suppressed because it is too large

139
app/admin/service/VoteService.php

@ -0,0 +1,139 @@
<?php
namespace app\admin\service;
use app\admin\service\AdminBaseService;
use app\model\VoteModel;
class VoteService extends AdminBaseService
{
public function index($param)
{
try {
$vote = VoteModel::where('is_delete', VoteModel::IS_DELETE_NO)
->order('id', 'desc');
$total = $vote->count();
$list = $vote->page($param['page'], $param['limit'])->select();
return $this->toData('0', 'SUCCESS', ['list' => $list, 'total' => $total]);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function add($param)
{
try {
if (empty($param['code'])) {
return $this->toData('1', 'code无效');
}
if (empty($param['title'])) {
return $this->toData('1', '标题无效');
}
if (empty($param['icon'])) {
return $this->toData('1', '图标无效');
}
if (empty($param['content'])) {
return $this->toData('1', '内容无效');
}
$vote = new VoteModel();
$vote->code = $param['code'];
$vote->title = $param['title'];
$vote->icon = $param['icon'];
$vote->content = $param['content'];
$vote->score_num = $param['score_num'] ?? 0;
$vote->sort = $param['sort'] ?? 0;
$vote->oneday_times = $param['oneday_times'] ?? 1;
$vote->create_time = date('Y-m-d H:i:s');
$vote->update_time = date('Y-m-d H:i:s');
$vote->save();
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function edit($param)
{
try {
if (empty($param['id']) || !is_numeric($param['id'])) {
return $this->toData('1', '目标不存在');
}
$vote = VoteModel::where('id', $param['id'])
->where('is_delete', VoteModel::IS_DELETE_NO)
->find();
if (empty($doc)) {
return $this->toData('1', '目标不存在');
}
if (empty($param['code'])) {
return $this->toData('1', 'code无效');
}
if (empty($param['title'])) {
return $this->toData('1', '标题无效');
}
if (empty($param['icon'])) {
return $this->toData('1', '图标无效');
}
if (empty($param['content'])) {
return $this->toData('1', '内容无效');
}
$isHas = VoteModel::where('is_delete', VoteModel::IS_DELETE_NO)
->where('id', '<>', $param['id'])
->where('title', $param['title'])->find();
if (!empty($isHas)) {
return $this->toData('1', '标题在相同内容');
}
$vote->code = $param['code'];
$vote->title = $param['title'];
$vote->icon = $param['icon'];
$vote->content = $param['content'];
$vote->score_num = $param['score_num'] ?? 0;
$vote->sort = $param['sort'] ?? 0;
$vote->oneday_times = $param['oneday_times'] ?? 1;
$vote->update_time = date('Y-m-d H:i:s');
$vote->save();
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function del($param)
{
try {
if (empty($param['id']) || !is_numeric($param['id'])) {
return $this->toData('1', '目标不存在');
}
$vote = VoteModel::where('id', $param['id'])
->where('is_delete', VoteModel::IS_DELETE_NO)
->find();
if (empty($vote)) {
return $this->toData('1', '目标不存在');
}
$vote->is_delete = VoteModel::IS_DELETE_YES;
$vote->save();
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
}

346
app/admin/service/WithdrawService.php

@ -0,0 +1,346 @@
<?php
namespace app\admin\service;
use app\admin\validate\WithdrawValidate;
use app\home\service\ClickPayService;
use app\home\service\HTPayService;
use app\home\service\IndPayService;
use app\home\service\MoPayService;
use app\home\service\NicePayService;
use app\home\service\PayService;
use app\home\service\QeaePayService;
use app\home\service\TrcPayService;
use app\home\service\XdPayService;
use app\model\AdminModel;
use app\model\PaymentListModel;
use app\model\UserBankModel;
use app\model\UserModel;
use app\model\UserWithdrawalModel;
use function AlibabaCloud\Client\backgroundRed;
class WithdrawService extends AdminBaseService
{
public function index($param, $adminId)
{
try {
// 参数校验
validate(WithdrawValidate::class)->scene('index')->check($param);
$where = [];
$userId = 0;
// 用户号精确搜索
if (!empty($param['user_no'])) {
$user = UserModel::where('user_no', $param['user_no'])->find();
if (empty($user)) {
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extend' => UserWithdrawalModel::$statusList]);
}
$userId = $user['user_id'];
}
// 判断是否是代理 如果是代理 只能看他自己管理的用户
$whereU = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId);
if (!is_array($whereU)) {
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extend' => UserWithdrawalModel::$statusList]);
}
// 订单号
if (!empty($param['order_id'])) {
$where['order_no'] = $param['order_id'];
}
if (isset($param['status'])) {
$where['status'] = $param['status'];
}
if (!empty($param['start_time']) && !empty($param['end_time'])) {
$where['update_time'] = ['between time', [$param['start_time'], $param['end_time']]];
}
// 列表
$list = UserWithdrawalModel::where($where)->where($whereU)->order('id', 'desc')->page($param['page'], $param['limit'])->select();
// 总数
$total = UserWithdrawalModel::where($where)->where($whereU)->count();
// 统计 提现成功
$sum = UserWithdrawalModel::where($where)->where($whereU)->where('status', 4)->sum('apply_num');
$rows = [];
if (!$list->isEmpty()) {
// 获取用户号
$userIdArr = [];
foreach ($list as $idItem) {
$userIdArr[] = $idItem['user_id'];
}
$userNoArr = UserModel::where('user_id', 'in', $userIdArr)->column('user_no', 'user_id');
$ifscArr = UserBankModel::where('user_id', 'in', $userIdArr)->column('ifsc', 'user_id');
$rows = $list->toArray();
foreach ($rows as $key => $item) {
$rows[$key]['user_no'] = $userNoArr[$item['user_id']] ?? '-'; // 用户号.
$rows[$key]['ifsc'] = $ifscArr[$item['user_id']] ?? '-'; // ifsc
$rows[$key]['order_id'] = $item['order_no'];
$rows[$key]['status_text'] = UserWithdrawalModel::$statusList[$item['status']];
//$rows[$key]['pay_info'] = json_decode($item['pay_info'],true);
}
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $rows, 'sum' => $sum . 'USD', 'extend' => UserWithdrawalModel::$statusList]);
} catch (\Exception $exception) {
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
}
}
public function info($param, $adminId)
{
try {
// 参数校验
validate(WithdrawValidate::class)->scene('info')->check($param);
$where = [
'id' => $param['id']
];
$userId = 0;
$where = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId);
if (!is_array($where)) {
return $this->toData('0', 'SUCCESS', []);
}
$order_info = [];
$info = UserWithdrawalModel::where($where)->find();
$ifsc = UserBankModel::where('user_id', $info->user_id)->value('ifsc');
if (!$info->isEmpty()) {
$order_info = $info->toArray();
$order_info['pay_info'] = json_decode($order_info['pay_info'], true);
$channel = PaymentListModel::getPaymentInfo([
'id' => intval($order_info['channel_id'])
]);
$order_info['channel_name'] = isset($channel['channel']) ? $channel['channel'] : '';
$order_info['ifsc'] = $ifsc ?? '-';
}
return $this->toData('0', 'SUCCESS', $order_info);
} catch (\Exception $exception) {
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
}
}
public function change_status($param, $adminId)
{
try {
// 参数校验
validate(WithdrawValidate::class)->scene('status')->check($param);
$isAgent = AdminModel::checkUserIsAgent($adminId);
if ($isAgent) {
return $this->toData('10040', '代理无权限操作');
}
$where = [
'id' => $param['id']
];
$userId = 0;
$where = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId);
if (!is_array($where)) {
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => []]);
}
$order_info = [];
$info = UserWithdrawalModel::where($where)->find();
if (empty($info)) {
return $this->toData('1004', '订单不存在');
}
$order_info = $info->toArray();
$change_flag = false;
if ($order_info['status'] == 0 && $param['status'] < 3) {
$change_flag = true;
}
if ($order_info['status'] = 1 && ($param['status'] == 3 || $param['status'] == 2)) {
$change_flag = true;
}
if ($order_info['status'] = 3 && $param['status'] == 4) {
$change_flag = true;
}
$pay_flag = false;
$msg = "";
$content = "";
if ($change_flag) {
$update_data['status'] = $param['status'];
$update_data['update_time'] = date('Y-m-d H:i:s');
//拒绝
if ($param['status'] == 2) {
$updateStatus = $this->updateUserAsset($order_info['user_id'], $order_info['account_type'], 6, $order_info['market_amount'], -$order_info['market_amount'], $order_info['order_no']);
}
//代付
if ($param['status'] == 3) {
//解冻资金 ,扣除提现
$updateOne = $this->updateUserAsset($order_info['user_id'], $order_info['account_type'], 6, $order_info['market_amount'], -$order_info['market_amount'], $order_info['order_no']);
if (!empty($updateOne) && $updateOne['status'] == 200) {
$updateStatus = $this->updateUserAsset($order_info['user_id'], $order_info['account_type'], 2, -$order_info['market_amount'], 0, $order_info['order_no']);
} else {
//提现事务回滚...
// $updateOne = $this->updateUserAsset($order_info['user_id'], $order_info['account_type'], 5, -$order_info['market_amount'], +$order_info['market_amount'], $order_info['order_no']);
trace("提现失败1 - change_status - order_no=" . $order_info['order_no'] . "---user_id= " . $order_info['user_id'] . "---account_type= " . $order_info['account_type'] . "---market_amount= " . $order_info['market_amount']);
return $this->toData($updateOne['status'] ?? '3251', $updateOne['msg'] ?? $msg, [$content]);
}
if (!empty($updateStatus) && $updateStatus['status'] == 200) {
$channel = PaymentListModel::getPaymentInfo([
'id' => $param['channel']
]);
if ($channel) {
$result = $this->payToUser($order_info, $channel);
if ($result['code'] == 200) {
$update_data['order_idx'] = $result['order_idx'];
$update_data['channel_id'] = $param['channel'];
} else {
$update_data['status'] = 1; //代付失败
$pay_flag = true;
$content = $result['content'];
$msg = $result['msg'];
}
}
//手动支付完成
if ($param['channel'] == 0) {
$update_data['status'] = 4;
$update_data['channel_id'] = $param['channel'];
}
}
}
$update_data['beizhu'] = $param['beizhu'] ?? "";
if ($param['status'] == 1 || (!empty($updateStatus) && $updateStatus['status'] == 200)) {
UserWithdrawalModel::where($where)->update($update_data);
} else {
trace("提现失败2 - change_status - order_no=" . $order_info['order_no'] . "---user_id= " . $order_info['user_id'] . "---account_type= " . $order_info['account_type'] . "---market_amount= " . $order_info['market_amount']);
return $this->toData($updateStatus['status'] ?? '3251', $updateStatus['msg'] ?? $msg, [$content]);
}
if ($pay_flag) {
return $this->toData('3250', $msg, [$content]);
} else {
return $this->toData('0', 'SUCCESS');
}
} else {
return $this->toData('10040', '操作流程不合法');
}
} catch (\Exception $exception) {
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
}
}
private function payToUser($order, $channel)
{
//货币单位换算
$order['total_amount'] = $order['apply_num'] * $channel['exchange_rate'];
$address_info = json_decode($order['pay_info'], true);
switch ($channel['type']) {
//印尼支付
case 2:
return (new IndPayService())->singleIndOrder($order);
break;
//TRC
case 3:
return (new MoPayService())->apply_pay($order['order_no'], $order['total_amount'], $address_info['bank_code'], $address_info['bank_card'], $address_info['true_name'], $address_info['bank_phone'], $address_info['ifsc']);
break;
//合泰
case 4:
return (new HTPayService())->arPay($order['order_no'], $order['total_amount'], $address_info['bank_code'], $address_info['bank_card'], $address_info['true_name']);
break;
//合泰
case 5:
return (new XdPayService())->apply_pay($order['order_no'], $order['total_amount'], $address_info['ifsc'], $address_info['bank_card'], $address_info['true_name']);
break;
//QEAE
case 6:
return (new QeaePayService())->apply_pay($order['order_no'], $order['total_amount'], $address_info['bank_card'], $address_info['true_name'], $address_info['ifsc'], $address_info['bank_code']);
break;
//合泰
case 7:
return (new NicePayService())->apply_pay($order['order_no'], $order['total_amount'], $address_info['bank_card'], $address_info['true_name'], $address_info['ifsc']);
break;
//ClickPay
case 8:
return (new ClickPayService())->apply_pay($order['order_no'], $order['total_amount'], $address_info['bank_card'], $address_info['true_name'], $address_info['ifsc'], $address_info['bank_code']);
break;
default:
break;
}
}
public function get_balance($param, $adminId)
{
$channel = PaymentListModel::getPaymentInfo([
'id' => intval($param['id'])
]);
if ($channel) {
switch ($channel['type']) {
case 1:
//$result=(new IndPayService())->getIndBalance();
$result = [
'amount' => 0
];
break;
case 2:
$result = (new TrcPayService())->getTrcBalance();
break;
case 4:
$result = (new HTPayService())->getHtBalance();
break;
case 5:
$result = (new XdPayService())->getBalance();
break;
case 6:
$result = (new QeaePayService())->getBalance();
break;
case 8:
$result = (new ClickPayService())->getBalance();
break;
default:
$result = [
'amount' => 0
];
break;
}
return $this->toData('0', '请求成功', $result);
} else {
return $this->toData('1', '参数错误,通道不存在', []);
}
}
public function channel_list($param, $adminId)
{
try {
// 参数校验
validate(WithdrawValidate::class)->scene('info')->check($param);
$where = [
'id' => $param['id']
];
$userId = 0;
$where = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId);
if (!is_array($where)) {
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => []]);
}
$order_info = UserWithdrawalModel::getUserDrawalInfo($where);
if ($order_info) {
$channel_list = PaymentListModel::getPaymentList([
'is_withdrawal' => 1,
'status' => 1,
'channel_type' => $order_info['apply_type']
]);
} else {
$channel_list = [];
}
return $this->toData('0', '请求成功', $channel_list);
} catch (\Exception $exception) {
return $this->toData('1', '系统异常 请稍后重试', [$exception->getMessage(), $exception->getTrace()]);
}
}
}

148
app/admin/service/auth/AuthRoleService.php

@ -0,0 +1,148 @@
<?php
namespace app\admin\service\auth;
use app\admin\validate\auth\AuthRoleValidate;
use app\admin\service\AdminBaseService;
use app\model\AuthRoleModel;
use think\exception\ValidateException;
class AuthRoleService extends AdminBaseService
{
public function add($param): array
{
try {
// 参数校验
validate(AuthRoleValidate::class)->scene('add')->check($param);
// 查找角色是否存在
$authRole=new AuthRoleModel();
$rule = $authRole->where('name',$param['name'])->find();
if(!empty($rule)){
return $this->toData('200100', '名称已存在', []);
}
$authRole->save($param);
return $this->toData('0', '添加成功.', []);
}catch (ValidateException $validateException){
$message = $validateException->getError();
return $this->toData('100400', $message);
}catch (\Exception $exception){
return $this->toData('100500', '系统繁忙.', [$exception->getMessage()]);
}
}
public function list($param){
try {
$authRole=new AuthRoleModel();
//查询条件
if(isset($param['name'])&&!empty($param['name'])){
$authRole=$authRole->where('name',$param['name']);
}
if(isset($param['satus'])&&!empty($param['status'])){
$authRole=$authRole->where('status',$param['status']);
}
// 总数
$total = $authRole->count();
$list=$authRole->order('sort', 'asc')->page($param['page'], $param['limit'])->select();
for($i=0;$i<count($list);$i++){
if($list[$i]['rules']){
$rules=explode(",", $list[$i]['rules']);
//字符串转换为数字类型
$list[$i]['rules']=array_map(function ($value){
return (int)$value;
},$rules);
}
}
return $this->toData('0', 'SUCCESS', ['total' => $total, 'list' => $list]);
} catch (\Exception $exception) {
return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
}
}
public function updateStatus($id, $param): array
{
try {
// 主键
if(empty($id) || $id <= 0){
return $this->toData('200403', 'id字段丢失', []);
}
// 参数校验
validate(AuthRoleValidate::class)->scene('updateStatus')->check($param);
// 查找用户信息
$authRole = AuthRoleModel::find($id);
if(empty($authRole)){
return $this->toData('200403', '该角色不存在.', []);
}
$authRole->status=$param['status'];
$authRole->save();
// 返回
return $this->toData('0', 'Modification successful.', []);
}catch (ValidateException $validateException){
$message = $validateException->getError();
return $this->toData('200400', $message);
}catch (\Exception $exception){
return $this->toData('200500', 'The system is busy.', [$exception->getMessage()]);
}
}
public function allList($param){
try {
$authRole=new AuthRoleModel();
//查询条件
if(isset($param['name'])&&!empty($param['name'])){
$authRole=$authRole->where('name',$param['name']);
}
if(isset($param['satus'])&&!empty($param['status'])){
$authRole=$authRole->where('status',$param['status']);
}
$list=$authRole->order('sort', 'asc')->column('name,id');
return $this->toData('0', 'SUCCESS', $list);
} catch (\Exception $exception) {
return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
}
}
public function edit($id, $param): array
{
try {
// 主键
if(empty($id) || $id <= 0){
return $this->toData('200403', 'id字段丢失', []);
}
// 参数校验
validate(AuthRoleValidate::class)->scene('edit')->check($param);
// 查找用户信息
$authRole = AuthRoleModel::find($id);
if(empty($authRole)){
return $this->toData('200403', '该规则不存在.', []);
}
$authRole->withoutField('id')->save($param);
// 返回
return $this->toData('0', 'Modification successful.', []);
}catch (ValidateException $validateException){
$message = $validateException->getError();
return $this->toData('200400', $message);
}catch (\Exception $exception){
return $this->toData('200500', 'The system is busy.', [$exception->getMessage()]);
}
}
public function del($id): array
{
try {
$authRole = AuthRoleModel::find($id);
$authRole->delete();
// 返回
return $this->toData('0', 'Modification successful.', []);
}catch (ValidateException $validateException){
$message = $validateException->getError();
return $this->toData('200400', $message);
}catch (\Exception $exception){
return $this->toData('200500', 'The system is busy.', [$exception->getMessage()]);
}
}
}

216
app/admin/service/auth/AuthRuleService.php

@ -0,0 +1,216 @@
<?php
namespace app\admin\service\auth;
use app\admin\validate\auth\AuthRuleValidate;
use app\admin\service\AdminBaseService;
use app\model\AuthRuleModel;
use app\model\AdminModel;
use app\model\AuthRoleModel;
use think\exception\ValidateException;
class AuthRuleService extends AdminBaseService
{
public function add($param): array
{
try {
// 参数校验
validate(AuthRuleValidate::class)->scene('add')->check($param);
$this->verifyRepeat($param);
$authRule=new AuthRuleModel();
$authRule->create($param);
return $this->toData('0', '添加成功.', []);
}catch (ValidateException $validateException){
$message = $validateException->getError();
return $this->toData('100400', $message);
}catch (\Exception $exception){
return $this->toData('100500', '系统繁忙.', [$exception->getMessage()]);
}
}
/**
* 查重验证
* @param $param
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function verifyRepeat($param){
$authRule=new AuthRuleModel();
if(isset($param['id'])){ //编辑
$authRule=$authRule->whereNotIn('id',[$param['id']]);
}
$rule = (clone $authRule)->where('name',$param['name'])->find();
if(!empty($rule)){
throw new ValidateException('权限标识已存在');
}
if($param['type']=='menu'){
$rule = (clone $authRule)->where('path', $param['path'])->find();
if(!empty($rule)){
throw new ValidateException('路由地址已存在');
}
$rule = (clone $authRule)->where('component',$param['component'])->find();
if(!empty($rule)){
throw new ValidateException('组件已存在');
}
}
if($param['type']=='catelog'){
$rule = (clone $authRule)->where('path',$param['path'])->find();
if(!empty($rule)){
throw new ValidateException('路由地址已存在');
}
}
}
public function list($user_id,$param){
try {
$authRule=new AuthRuleModel();
//查询条件
if(isset($param['name'])&&!empty($param['name'])){
$authRule=$authRule->where('name',$param['name']);
}
if(isset($param['satus'])&&!empty($param['status'])){
$authRule=$authRule->where('status',$param['status']);
}
//获取用户权限id
$user=AdminModel::find($user_id);
//查询拥有权限
if($user->role_id=='7'){
//超级管理员拥有全部权限
$list=$authRule::order('sort', 'asc')->select()->toArray();
}else{
$role=AuthRoleModel::find($user->role_id);
$list=$authRule::whereIn('id',$role->rules)->order('sort', 'asc')->select()->toArray();
}
// 总数
// $total = $authRule->count();
// $list=$authRule->order('sort', 'asc')->select()->toArray();
$list=$this->getTreeMenu($list,0,true);
return $this->toData('0', 'SUCCESS', $list);
} catch (\Exception $exception) {
return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
}
}
public function allList($user_id){
try {
//获取用户权限id
$user=AdminModel::find($user_id);
//查询拥有权限
if($user->role_id=='7'){
//超级管理员拥有全部权限
$list=AuthRuleModel::order('sort', 'asc')->select()->toArray();
}else{
$role=AuthRoleModel::find($user->role_id);
$list=AuthRuleModel::whereIn('id',$role->rules)->order('sort', 'asc')->select()->toArray();
}
// $list=$authRule->order('sort', 'asc')->select()->toArray();
$list=$this->getTreeMenu($list,0,true);
return $this->toData('0', 'SUCCESS',$list);
} catch (\Exception $exception) {
return $this->toData('100500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
}
}
public function edit($id, $param): array
{
try {
// 主键
if(empty($id) || $id <= 0){
return $this->toData('200403', 'id字段丢失', []);
}
// 参数校验
validate(AuthRuleValidate::class)->scene('edit')->check($param);
// 查找用户信息
$authRule = AuthRuleModel::find($id);
if(empty($authRule)){
return $this->toData('200403', 'Please log in first.', []);
}
$this->verifyRepeat($param);
$authRule->save($param);
// 返回
return $this->toData('0', 'Modification successful.', []);
}catch (ValidateException $validateException){
$message = $validateException->getError();
return $this->toData('200400', $message);
}catch (\Exception $exception){
return $this->toData('200500', 'The system is busy.', [$exception->getMessage()]);
}
}
public function getSideMenu($user_id){
try {
//获取用户权限id
$user=AdminModel::find($user_id);
$role=AuthRoleModel::find($user->role_id);
//查询拥有权限
if($user->role_id=='7'){
//超级管理员拥有全部权限
$authRule=AuthRuleModel::order('sort', 'asc')->select()->toArray();
}else{
$role=AuthRoleModel::find($user->role_id);
$authRule=AuthRuleModel::whereIn('id',$role->rules)->order('sort', 'asc')->select()->toArray();
}
// $authRule=AuthRuleModel::whereIn('id',$role->rules)->order('sort', 'asc')->select()->toArray();
// $authRule=AuthRuleModel::order('sort', 'asc')->select()->toArray();//显示全部
$menus=[];
for($i=0;$i<count($authRule);$i++){
$menuItem=[
'id'=>$authRule[$i]['id'],
'pid'=>$authRule[$i]['pid'],
'path'=>$authRule[$i]['path'],
'name'=>$authRule[$i]['name'],
'component'=>$authRule[$i]['component'],
'redirect'=>$authRule[$i]['redirect'],
'meta'=>[
'title'=>$authRule[$i]['title'],
'hideMenu'=>$authRule[$i]['show']===1?false:true,
'icon'=>$authRule[$i]['icon'],
'ignoreKeepAlive'=>true,
'isLink'=>false,
// 'currentActiveMenu'=>"",
]
];
array_push($menus,$menuItem);
}
$list=$this->getTreeMenu($menus,0,true);
return $this->toData('0', 'SUCCESS',$list);
}catch (ValidateException $validateException){
$message = $validateException->getError();
return $this->toData('200400', $message);
}catch (\Exception $exception){
return $this->toData('200500', 'The system is busy.', [$exception->getMessage()]);
}
}
/**
* @param $id
* @return array
*/
public function del($id): array
{
try {
$authRule = AuthRuleModel::find($id);
$authRule->delete();
// 返回
return $this->toData('0', 'Modification successful.', []);
}catch (ValidateException $validateException){
$message = $validateException->getError();
return $this->toData('200400', $message);
}catch (\Exception $exception){
return $this->toData('200500', 'The system is busy.', [$exception->getMessage()]);
}
}
}

200
app/admin/service/document/AnnouncementService.php

@ -0,0 +1,200 @@
<?php
namespace app\admin\service\document;
use app\admin\service\AdminBaseService;
use app\model\AnnouncementModel;
use app\model\LanguageSettingModel;
class AnnouncementService extends AdminBaseService
{
public function index()
{
try {
$rows = [];
$list = AnnouncementModel::where('is_delete', AnnouncementModel::IS_DELETE_NO)
->field('id,lang,name,title,status,weight')
->order('name', 'asc')
->order('weight', 'desc')->select();
if(!$list->isEmpty()){
$rows = $list->toArray();
$lang = LanguageSettingModel::where('id', '>', 0)->column('china_name', 'id');
foreach ($rows as $key=>$item){
$rows[$key]['lang'] = $lang[$item['lang']] ?? '-';
$rows[$key]['status'] = AnnouncementModel::STATUS_MAP[$item['status']] ?? '-';
}
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function add($param)
{
try {
$langIds = LanguageSettingModel::column('id');
if(empty($param['lang']) || !in_array($param['lang'], $langIds)){
return $this->toData('1', '语言类型无效');
}
if(empty($param['name']) || !is_string($param['name'])){
return $this->toData('1', '名称无效');
}
if(empty($param['title']) || !is_string($param['title'])){
return $this->toData('1', '标题无效');
}
if(empty($param['content']) || !is_string($param['content'])){
return $this->toData('1', '内容无效');
}
if(!isset($param['weight']) || !is_numeric($param['weight']) || ceil($param['weight']) != $param['weight'] || $param['weight'] < 0){
return $this->toData('1', '权重无效');
}
if(!isset($param['status']) || !in_array($param['status'], [1,2])){
return $this->toData('1', '状态无效');
}
//
// if(!isset($param['is_pop_ups']) || !in_array($param['is_pop_ups'], [1,2])){
// return $this->toData('1', 'h5弹窗状态无效');
// }
$docExists = AnnouncementModel::where('is_delete', AnnouncementModel::IS_DELETE_NO)
->where('name', $param['name'])
->where('lang', $param['lang'])->find();
if(!empty($docExists)){
return $this->toData('1', '已存在相同内容');
}
$doc = new AnnouncementModel;
$doc->lang = $param['lang'];
$doc->title = $param['title'];
$doc->content = $param['content'];
$doc->status = $param['status'];
$doc->weight = $param['weight'];
if (!empty($param['is_pop_ups'])) $doc->is_pop_ups = $param['is_pop_ups'];
$doc->create_time = date('Y-m-d H:i:s');
$doc->update_time = date('Y-m-d H:i:s');
$doc->name = $param['name'];
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function detail($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在');
}
$doc = AnnouncementModel::where('id', $param['id'])
->where('is_delete', AnnouncementModel::IS_DELETE_NO)
->find();
if(empty($doc)){
return $this->toData('1', '目标不存在');
}
$docArr = $doc->toArray();
return $this->toData('0', 'SUCCESS', ['row' => $docArr,]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function edit($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在');
}
$doc = AnnouncementModel::where('id', $param['id'])
->where('is_delete', AnnouncementModel::IS_DELETE_NO)
->find();
if(empty($doc)){
return $this->toData('1', '目标不存在');
}
$langIds = LanguageSettingModel::column('id');
if(empty($param['lang']) || !in_array($param['lang'], $langIds)){
return $this->toData('1', '语言类型无效');
}
if(empty($param['name']) || !is_string($param['name'])){
return $this->toData('1', '名称无效');
}
if(empty($param['title']) || !is_string($param['title'])){
return $this->toData('1', '标题无效');
}
if(empty($param['content']) || !is_string($param['content'])){
return $this->toData('1', '内容无效');
}
if(!isset($param['weight']) || !is_numeric($param['weight']) || ceil($param['weight']) != $param['weight'] || $param['weight'] < 0){
return $this->toData('1', '权重无效');
}
if(!isset($param['status']) || !in_array($param['status'], [1,2])){
return $this->toData('1', '状态无效');
}
// $docExists = AnnouncementModel::where('is_delete', AnnouncementModel::IS_DELETE_NO)
// ->where('id', '<>', $param['id'])
// ->where('name', $param['name'])
// ->where('lang', $param['lang'])->find();
// if(!empty($docExists)){
// return $this->toData('1', '已存在相同内容');
// }
$doc->lang = $param['lang'];
$doc->title = $param['title'];
$doc->content = $param['content'];
$doc->status = $param['status'];
$doc->weight = $param['weight'];
if (!empty($param['is_pop_ups'])) $doc->is_pop_ups = $param['is_pop_ups'];
$doc->update_time = date('Y-m-d H:i:s');
$doc->name = $param['name'];
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function del($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在');
}
$doc = AnnouncementModel::where('id', $param['id'])
->where('is_delete', AnnouncementModel::IS_DELETE_NO)
->find();
if(empty($doc)){
return $this->toData('1', '目标不存在');
}
$doc->is_delete = AnnouncementModel::IS_DELETE_YES;
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
}

196
app/admin/service/document/BannerService.php

@ -0,0 +1,196 @@
<?php
namespace app\admin\service\document;
use app\admin\service\AdminBaseService;
use app\model\BannerModel;
use app\model\LanguageSettingModel;
class BannerService extends AdminBaseService
{
public function index()
{
try {
$rows = [];
$list = BannerModel::where('is_delete', BannerModel::IS_DELETE_NO)
->field('id,lang,path,name,title,status')
->order('name', 'asc')
->select();
if(!$list->isEmpty()){
$rows = $list->toArray();
$lang = LanguageSettingModel::where('id', '>', 0)->column('china_name', 'id');
foreach ($rows as $key=>$item){
$rows[$key]['lang'] = $lang[$item['lang']] ?? '-';
$rows[$key]['status'] = BannerModel::STATUS_MAP[$item['status']] ?? '-';
}
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function add($param)
{
try {
$langIds = LanguageSettingModel::column('id');
if(empty($param['lang']) || !in_array($param['lang'], $langIds)){
return $this->toData('1', '语言类型无效');
}
if(empty($param['name']) || !is_string($param['name'])){
return $this->toData('1', '名称无效');
}
if(empty($param['title']) || !is_string($param['title'])){
return $this->toData('1', '标题无效');
}
if(empty($param['content']) || !is_string($param['content'])){
return $this->toData('1', '内容无效');
}
if(empty($param['path']) || !is_string($param['path'])){
return $this->toData('1', '图片路径无效');
}
if(!isset($param['status']) || !in_array($param['status'], [1,2])){
return $this->toData('1', '状态无效');
}
$docExists = BannerModel::where('is_delete', BannerModel::IS_DELETE_NO)
->where('name', $param['name'])
->where('lang', $param['lang'])->find();
if(!empty($docExists)){
return $this->toData('1', '已存在相同内容');
}
$doc = new BannerModel();
$doc->lang = $param['lang'];
$doc->path = $param['path'];
$doc->title = $param['title'];
$doc->content = $param['content'];
$doc->status = $param['status'];
$doc->create_time = date('Y-m-d H:i:s');
$doc->update_time = date('Y-m-d H:i:s');
$doc->name = $param['name'];
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function detail($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在');
}
$doc = BannerModel::where('id', $param['id'])
->where('is_delete', BannerModel::IS_DELETE_NO)
->find();
if(empty($doc)){
return $this->toData('1', '目标不存在');
}
$docArr = $doc->toArray();
return $this->toData('0', 'SUCCESS', ['row' => $docArr]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function edit($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在');
}
$doc = BannerModel::where('id', $param['id'])
->where('is_delete', BannerModel::IS_DELETE_NO)
->find();
if(empty($doc)){
return $this->toData('1', '目标不存在');
}
$langIds = LanguageSettingModel::column('id');
if(empty($param['lang']) || !in_array($param['lang'], $langIds)){
return $this->toData('1', '语言类型无效');
}
if(empty($param['name']) || !is_string($param['name'])){
return $this->toData('1', '名称无效');
}
if(empty($param['title']) || !is_string($param['title'])){
return $this->toData('1', '标题无效');
}
if(empty($param['content']) || !is_string($param['content'])){
return $this->toData('1', '内容无效');
}
if(empty($param['path']) || !is_string($param['path'])){
return $this->toData('1', '图片路径无效');
}
if(!isset($param['status']) || !in_array($param['status'], [1,2])){
return $this->toData('1', '状态无效');
}
$docExists = BannerModel::where('is_delete', BannerModel::IS_DELETE_NO)
->where('id', '<>', $param['id'])
->where('name', $param['name'])
->where('lang', $param['lang'])->find();
if(!empty($docExists)){
return $this->toData('1', '已存在相同内容');
}
$doc->lang = $param['lang'];
$doc->title = $param['title'];
$doc->content = $param['content'];
$doc->status = $param['status'];
$doc->path = $param['path'];
$doc->update_time = date('Y-m-d H:i:s');
$doc->name = $param['name'];
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function del($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在');
}
$doc = BannerModel::where('id', $param['id'])
->where('is_delete', BannerModel::IS_DELETE_NO)
->find();
if(empty($doc)){
return $this->toData('1', '目标不存在');
}
$doc->is_delete = BannerModel::IS_DELETE_YES;
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
}

195
app/admin/service/document/FaqService.php

@ -0,0 +1,195 @@
<?php
namespace app\admin\service\document;
use app\admin\service\AdminBaseService;
use app\model\FaqModel;
use app\model\LanguageSettingModel;
class FaqService extends AdminBaseService
{
public function index()
{
try {
$rows = [];
$list = FaqModel::where('is_delete', FaqModel::IS_DELETE_NO)
->field('id,lang,name,title,status,weight')
->order('name', 'asc')
->order('weight', 'desc')->select();
if(!$list->isEmpty()){
$rows = $list->toArray();
$lang = LanguageSettingModel::where('id', '>', 0)->column('china_name', 'id');
foreach ($rows as $key=>$item){
$rows[$key]['lang'] = $lang[$item['lang']] ?? '-';
$rows[$key]['status'] = FaqModel::STATUS_MAP[$item['status']] ?? '-';
}
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function add($param)
{
try {
$langIds = LanguageSettingModel::column('id');
if(empty($param['lang']) || !in_array($param['lang'], $langIds)){
return $this->toData('1', '语言类型无效');
}
if(empty($param['name']) || !is_string($param['name'])){
return $this->toData('1', '名称无效');
}
if(empty($param['title']) || !is_string($param['title'])){
return $this->toData('1', '标题无效');
}
if(empty($param['content']) || !is_string($param['content'])){
return $this->toData('1', '内容无效');
}
if(!isset($param['weight']) || !is_numeric($param['weight']) || ceil($param['weight']) != $param['weight'] || $param['weight'] < 0){
return $this->toData('1', '权重无效');
}
if(!isset($param['status']) || !in_array($param['status'], [1,2])){
return $this->toData('1', '状态无效');
}
$docExists = FaqModel::where('is_delete', FaqModel::IS_DELETE_NO)
->where('name', $param['name'])
->where('lang', $param['lang'])->find();
if(!empty($docExists)){
return $this->toData('1', '已存在相同内容');
}
$doc = new FaqModel;
$doc->lang = $param['lang'];
$doc->title = $param['title'];
$doc->content = $param['content'];
$doc->status = $param['status'];
$doc->weight = $param['weight'];
$doc->create_time = date('Y-m-d H:i:s');
$doc->update_time = date('Y-m-d H:i:s');
$doc->name = $param['name'];
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function detail($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在');
}
$doc = FaqModel::where('id', $param['id'])
->where('is_delete', FaqModel::IS_DELETE_NO)
->find();
if(empty($doc)){
return $this->toData('1', '目标不存在');
}
$docArr = $doc->toArray();
return $this->toData('0', 'SUCCESS', ['row' => $docArr,]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function edit($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在');
}
$doc = FaqModel::where('id', $param['id'])
->where('is_delete', FaqModel::IS_DELETE_NO)
->find();
if(empty($doc)){
return $this->toData('1', '目标不存在');
}
$langIds = LanguageSettingModel::column('id');
if(empty($param['lang']) || !in_array($param['lang'], $langIds)){
return $this->toData('1', '语言类型无效');
}
if(empty($param['name']) || !is_string($param['name'])){
return $this->toData('1', '名称无效');
}
if(empty($param['title']) || !is_string($param['title'])){
return $this->toData('1', '标题无效');
}
if(empty($param['content']) || !is_string($param['content'])){
return $this->toData('1', '内容无效');
}
if(!isset($param['weight']) || !is_numeric($param['weight']) || ceil($param['weight']) != $param['weight'] || $param['weight'] < 0){
return $this->toData('1', '权重无效');
}
if(!isset($param['status']) || !in_array($param['status'], [1,2])){
return $this->toData('1', '状态无效');
}
$docExists = FaqModel::where('is_delete', FaqModel::IS_DELETE_NO)
->where('id', '<>', $param['id'])
->where('name', $param['name'])
->where('lang', $param['lang'])->find();
if(!empty($docExists)){
return $this->toData('1', '已存在相同内容');
}
$doc->lang = $param['lang'];
$doc->title = $param['title'];
$doc->content = $param['content'];
$doc->status = $param['status'];
$doc->weight = $param['weight'];
$doc->update_time = date('Y-m-d H:i:s');
$doc->name = $param['name'];
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function del($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在');
}
$doc = FaqModel::where('id', $param['id'])
->where('is_delete', FaqModel::IS_DELETE_NO)
->find();
if(empty($doc)){
return $this->toData('1', '目标不存在');
}
$doc->is_delete = FaqModel::IS_DELETE_YES;
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
}

211
app/admin/service/document/IndexService.php

@ -0,0 +1,211 @@
<?php
namespace app\admin\service\document;
use app\admin\service\AdminBaseService;
use app\model\DocumentModel;
use app\model\LanguageSettingModel;
class IndexService extends AdminBaseService
{
public function index()
{
try {
$rows = [];
$list = DocumentModel::where('is_delete', DocumentModel::IS_DELETE_NO)
->field('id,lang,type,name,title,status,weight')
->order('type', 'asc')
->order('name', 'asc')
->order('weight', 'desc')->select();
if(!$list->isEmpty()){
$rows = $list->toArray();
$lang = LanguageSettingModel::where('id', '>', 0)->column('china_name', 'id');
foreach ($rows as $key=>$item){
$rows[$key]['type'] = DocumentModel::TYPE_MAP[$item['type']] ?? '-';
$rows[$key]['lang'] = $lang[$item['lang']] ?? '-';
$rows[$key]['status'] = DocumentModel::STATUS_MAP[$item['status']] ?? '-';
}
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows),'extend' => ['typeMap' => DocumentModel::TYPE_MAP]]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function add($param)
{
try {
$typeMapKeys = array_keys(DocumentModel::TYPE_MAP);
if(empty($param['type']) || !in_array($param['type'],$typeMapKeys)){
return $this->toData('1', '文章类型无效');
}
$langIds = LanguageSettingModel::column('id');
if(empty($param['lang']) || !in_array($param['lang'], $langIds)){
return $this->toData('1', '语言类型无效');
}
if(empty($param['name']) || !is_string($param['name'])){
return $this->toData('1', '名称无效');
}
if(empty($param['title']) || !is_string($param['title'])){
return $this->toData('1', '标题无效');
}
if(empty($param['content']) || !is_string($param['content'])){
return $this->toData('1', '内容无效');
}
if(!isset($param['weight']) || !is_numeric($param['weight']) || ceil($param['weight']) != $param['weight'] || $param['weight'] < 0){
return $this->toData('1', '权重无效');
}
if(!isset($param['status']) || !in_array($param['status'], [1,2])){
return $this->toData('1', '状态无效');
}
$docExists = DocumentModel::where('type', $param['type'])
->where('is_delete', DocumentModel::IS_DELETE_NO)
->where('name', $param['name'])
->where('lang', $param['lang'])->find();
if(!empty($docExists)){
return $this->toData('1', '已存在相同内容');
}
$doc = new DocumentModel;
$doc->lang = $param['lang'];
$doc->type = $param['type'];
$doc->title = $param['title'];
$doc->content = $param['content'];
$doc->status = $param['status'];
$doc->weight = $param['weight'];
$doc->create_time = date('Y-m-d H:i:s');
$doc->update_time = date('Y-m-d H:i:s');
$doc->name = $param['name'];
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function detail($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在');
}
$doc = DocumentModel::where('id', $param['id'])
->where('is_delete', DocumentModel::IS_DELETE_NO)
->find();
if(empty($doc)){
return $this->toData('1', '目标不存在');
}
$docArr = $doc->toArray();
return $this->toData('0', 'SUCCESS', ['row' => $docArr,
'extend' => ['typeMap' => DocumentModel::TYPE_MAP]]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function edit($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在');
}
$doc = DocumentModel::where('id', $param['id'])
->where('is_delete', DocumentModel::IS_DELETE_NO)
->find();
if(empty($doc)){
return $this->toData('1', '目标不存在');
}
$typeMapKeys = array_keys(DocumentModel::TYPE_MAP);
if(empty($param['type']) || !in_array($param['type'],$typeMapKeys)){
return $this->toData('1', '文章类型无效');
}
$langIds = LanguageSettingModel::column('id');
if(empty($param['lang']) || !in_array($param['lang'], $langIds)){
return $this->toData('1', '语言类型无效');
}
if(empty($param['name']) || !is_string($param['name'])){
return $this->toData('1', '名称无效');
}
if(empty($param['title']) || !is_string($param['title'])){
return $this->toData('1', '标题无效');
}
if(empty($param['content']) || !is_string($param['content'])){
return $this->toData('1', '内容无效');
}
if(!isset($param['weight']) || !is_numeric($param['weight']) || ceil($param['weight']) != $param['weight'] || $param['weight'] < 0){
return $this->toData('1', '权重无效');
}
if(!isset($param['status']) || !in_array($param['status'], [1,2])){
return $this->toData('1', '状态无效');
}
$docExists = DocumentModel::where('type', $param['type'])
->where('is_delete', DocumentModel::IS_DELETE_NO)
->where('id', '<>', $param['id'])
->where('name', $param['name'])
->where('lang', $param['lang'])->find();
if(!empty($docExists)){
return $this->toData('1', '已存在相同内容');
}
$doc->lang = $param['lang'];
$doc->type = $param['type'];
$doc->title = $param['title'];
$doc->content = $param['content'];
$doc->status = $param['status'];
$doc->weight = $param['weight'];
$doc->update_time = date('Y-m-d H:i:s');
$doc->name = $param['name'];
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function del($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在');
}
$doc = DocumentModel::where('id', $param['id'])
->where('is_delete', DocumentModel::IS_DELETE_NO)
->find();
if(empty($doc)){
return $this->toData('1', '目标不存在');
}
$doc->is_delete = DocumentModel::IS_DELETE_YES;
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
}

148
app/admin/service/document/LandingPageService.php

@ -0,0 +1,148 @@
<?php
namespace app\admin\service\document;
use app\home\service\BaseHomeService;
use app\model\LandingPageModel;
class LandingPageService extends BaseHomeService
{
public function index(): array
{
try {
$rows = [];
$list = LandingPageModel::where('is_delete', LandingPageModel::IS_DELETE_NO)
->order('id', 'desc')->select();
if(!$list->isEmpty()){
$rows = $list->toArray();
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function add($param): array
{
try {
// 名称
if(empty($param['name']) || !is_string($param['name'])){
return $this->toData('1', '名称无效');
}
// 内容
if(empty($param['content']) || !is_string($param['content'])){
return $this->toData('1', '内容无效');
}
// 跳转地址
if(empty($param['link_url']) || !is_string($param['link_url'])){
$param['link_url'] = '';
}
if(!isset($param['status']) || !in_array($param['status'], [LandingPageModel::STATUS_ON, LandingPageModel::STATUS_OFF])){
return $this->toData('1', '状态无效');
}
$docExists = LandingPageModel::where('is_delete', LandingPageModel::IS_DELETE_NO)
->where('name', $param['name'])
->find();
if(!empty($docExists)){
return $this->toData('1', '已存在相同内容');
}
$doc = new LandingPageModel;
$doc->name = $param['name'];
$doc->content = $param['content'];
$doc->click_num = 0;
$doc->link_url = 0;
$doc->is_delete = 0;
$doc->status = 0;
$doc->create_time = date('Y-m-d H:i:s');
$doc->update_time = date('Y-m-d H:i:s');
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function edit($param): array
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在');
}
$doc = LandingPageModel::where('id', $param['id'])
->where('is_delete', LandingPageModel::IS_DELETE_NO)
->find();
if(empty($doc)){
return $this->toData('1', '目标不存在');
}
// 名称
if(empty($param['name']) || !is_string($param['name'])){
return $this->toData('1', '名称无效');
}
// 内容
if(empty($param['content']) || !is_string($param['content'])){
return $this->toData('1', '内容无效');
}
// 跳转地址
if(empty($param['link_url']) || !is_string($param['link_url'])){
$param['link_url'] = '';
}
if(!isset($param['status']) || !in_array($param['status'], [LandingPageModel::STATUS_ON, LandingPageModel::STATUS_OFF])){
return $this->toData('1', '状态无效');
}
$docExists = LandingPageModel::where('is_delete', LandingPageModel::IS_DELETE_NO)
->where('id', '<>', $param['id'])
->where('name', $param['name'])->find();
if(!empty($docExists)){
return $this->toData('1', '已存在相同内容');
}
$doc->name = $param['name'];
$doc->content = $param['content'];
$doc->status = $param['status'];
$doc->link_url = $param['link_url'];
$doc->update_time = date('Y-m-d H:i:s');
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function del($param): array
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在');
}
$doc = LandingPageModel::where('id', $param['id'])
->where('is_delete', LandingPageModel::IS_DELETE_NO)
->find();
if(empty($doc)){
return $this->toData('1', '目标不存在');
}
$doc->is_delete = LandingPageModel::IS_DELETE_YES;
$doc->save();
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
}

372
app/admin/service/setting/BlockStockService.php

@ -0,0 +1,372 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\model\StockBlockListModel;
use app\model\StockHkdListModel;
use app\model\StockIdnListModel;
use app\model\StockInListModel;
use app\model\StockListModel;
use app\model\StockMysListModel;
use app\model\StockSgdListModel;
use app\model\StockThaListModel;
// 大宗交易
class BlockStockService extends AdminBaseService
{
// 列表
public function index($param)
{
try {
if (empty($param['page']) || !is_numeric($param['page']) || empty($param['limit']) || !is_numeric($param['limit'])) {
return $this->toData('1', '分页参数错误');
}
$where = [];
// 未删除
$where[] = [
'is_delete', '=', StockBlockListModel::IS_DELETE_NO
];
// 股票号
if (!empty($param['stock_code']) && is_string($param['stock_code'])) {
$where[] = [
'stock_code', '=', $param['stock_code']
];
}
// 状态
if (!empty($param['status']) && in_array($param['status'], [StockBlockListModel::STATUS_ON, StockBlockListModel::STATUS_OFF])) {
$where[] = [
'status', '=', $param['status']
];
}
$query = StockBlockListModel::where($where);
$totalQuery = StockBlockListModel::where($where);
$list = $query->order('id', 'desc')->page($param['page'], $param['limit'])->select();
$total = $totalQuery->order('id', 'desc')->count();
return $this->toData('0', 'SUCCESS', ['list' => $list, 'total' => $total, 'extend' => [
// 'tape_list' => StockBlockListModel::$tapeList,
'stock_type_list' => StockBlockListModel::$typeList,
]]);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 新增
public function add($param)
{
try {
// 股票代码
if (empty($param['stock_code']) || !is_string($param['stock_code'])) {
return $this->toData('1', '股票代码 无效');
}
// 股票类型
if (empty($param['type']) || !in_array($param['type'], array_keys(StockBlockListModel::$typeList))) {
return $this->toData('1', '股票市场 无效');
}
// 交易所类型
// if(empty($param['tape']) || !in_array($param['tape'], array_keys(StockBlockListModel::$tapeList))){
// return $this->toData('1', '交易所类型 无效');
// }
switch ($param['type']) {
case '3':
$stock = StockListModel::where('stock_code', $param['stock_code'])->find();
if (empty($stock)) return $this->toData('1', 'stock_code 无效');
break;
case '4':
$stock = StockIdnListModel::where('stock_code', $param['stock_code'])->find();
if (empty($stock)) return $this->toData('1', 'stock_code 无效');
break;
case '5':
$stock = StockMysListModel::where('stock_code', $param['stock_code'])->find();
if (empty($stock)) return $this->toData('1', 'stock_code 无效');
break;
case '6':
$stock = StockThaListModel::where('stock_code', $param['stock_code'])->find();
if (empty($stock)) return $this->toData('1', 'stock_code 无效');
break;
case '7':
$stock = StockInListModel::where('stock_code', $param['stock_code'])->find();
if (empty($stock)) return $this->toData('1', 'stock_code 无效');
break;
case '9':
$stock = StockSgdListModel::where('stock_code', $param['stock_code'])->find();
if (empty($stock)) return $this->toData('1', 'stock_code 无效');
break;
case '12':
$stock = StockHkdListModel::where('stock_code', $param['stock_code'])->find();
if (empty($stock)) return $this->toData('1', 'stock_code 无效');
break;
default:
return $this->toData('1', '股票市场或股票代码 无效');
}
// 发布状态
if (empty($param['status']) || !in_array($param['status'], [StockBlockListModel::STATUS_ON, StockBlockListModel::STATUS_OFF])) {
return $this->toData('1', '发布状态 无效');
}
// 单股价格
if (empty($param['price']) || !is_numeric($param['price']) || $param['price'] <= 0) {
return $this->toData('1', '单股价格 无效');
}
// 最小申购数量
if (empty($param['min']) || !is_numeric($param['min']) || $param['min'] <= 0 || ceil($param['min']) != $param['min']) {
return $this->toData('1', '最小购买股数无效');
}
// 开始认购时间
if (empty($param['start_time']) || !is_string($param['start_time'])) {
return $this->toData('1', '开始认购时间 无效');
}
// 认购结束时间
if (empty($param['end_time']) || !is_string($param['end_time']) || strtotime($param['end_time']) <= strtotime($param['start_time'])) {
return $this->toData('1', '认购结束时间 无效');
}
// 可出售时间时间
if (empty($param['today_add']) || !is_numeric($param['today_add'])) {
return $this->toData('1', 'T+n 无效');
}
// 新增数据
$blockStock = new StockBlockListModel();
$blockStock->stock_code = $param['stock_code'];
$blockStock->stock_name = $param['stock_name'];
$blockStock->type = $param['type'];
$blockStock->tape = $stock->tape;
$blockStock->status = $param['status'];
$blockStock->price = $param['price'];
$blockStock->min = $param['min'];
$blockStock->start_time = $param['start_time'];
$blockStock->end_time = $param['end_time'];
$blockStock->today_add = $param['today_add'];
$blockStock->keep_decimal = $stock->keep_decimal;
$blockStock->info = $param['info'] ?? '';
$blockStock->forced_closure = $stock->forced_closure;
$blockStock->up_limit = $stock->up_limit;;
$blockStock->down_limit = $stock->down_limit;
$blockStock->create_time = date('Y-m-d H:i:s');
$blockStock->update_time = date('Y-m-d H:i:s');
$blockStock->save();
// 加入缓存
$list_key = StockBlockListModel::$typeListEn[$param['type']] . ":BLOCK:LIST:" . $param['stock_code'];
$redis = $this->getRedis();
$redis->del($list_key);
$redis->hMset($list_key, [
'stock_name' => $blockStock->stock_name,
'stock_code' => $blockStock->stock_code,
'status' => $blockStock->status,
'keep_decimal' => $blockStock->keep_decimal,
'forced_closure' => $blockStock->forced_closure,
'up_limit' => $blockStock->up_limit,
'down_limit' => $blockStock->down_limit,
'info' => $blockStock->info,
'tape' => $blockStock->tape,
'price' => $blockStock->price,
'min' => $blockStock->min,
'start_time' => $blockStock->start_time,
'end_time' => $blockStock->end_time,
'today_add' => $blockStock->today_add
]);
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('0', '系统繁忙', [$exception->getMessage()]);
}
}
// 编辑
public function edit($param)
{
try {
if (empty($param['id']) || !is_numeric($param['id'])) {
return $this->toData('1', '主键 无效');
}
$blockStock = StockBlockListModel::where('id', $param['id'])->where('is_delete', StockBlockListModel::IS_DELETE_NO)->find();
if (empty($blockStock)) {
return $this->toData('1', '主键 无效');
}
// // 已中签或者已上市不支持修改
// if($blockStock->open_status == PreMysStockModel::OPEN_STATUS_HAD || strtotime($blockStock->get_time)<=time()){
// return $this->toData('1', '已中签或已上市 不支持修改');
// }
// 股票代码
if (empty($param['stock_code']) || !is_string($param['stock_code'])) {
return $this->toData('1', '股票代码 无效');
}
// 股票名称
if (empty($param['stock_name']) || !is_string($param['stock_name'])) {
return $this->toData('1', '股票代码 无效');
}
// 股票类型
if (empty($param['type']) || !in_array($param['type'], array_keys(StockBlockListModel::$typeList))) {
return $this->toData('1', '股票市场 无效');
}
switch ($param['type']) {
case '3':
$stock = StockListModel::where('stock_code', $param['stock_code'])->find();
if (empty($stock)) return $this->toData('1', 'stock_code 无效');
break;
case '4':
$stock = StockIdnListModel::where('stock_code', $param['stock_code'])->find();
if (empty($stock)) return $this->toData('1', 'stock_code 无效');
break;
case '5':
$stock = StockMysListModel::where('stock_code', $param['stock_code'])->find();
if (empty($stock)) return $this->toData('1', 'stock_code 无效');
break;
case '6':
$stock = StockThaListModel::where('stock_code', $param['stock_code'])->find();
if (empty($stock)) return $this->toData('1', 'stock_code 无效');
break;
case '7':
$stock = StockInListModel::where('stock_code', $param['stock_code'])->find();
if (empty($stock)) return $this->toData('1', 'stock_code 无效');
break;
case '9':
$stock = StockSgdListModel::where('stock_code', $param['stock_code'])->find();
if (empty($stock)) return $this->toData('1', 'stock_code 无效');
break;
case '12':
$stock = StockHkdListModel::where('stock_code', $param['stock_code'])->find();
if (empty($stock)) return $this->toData('1', 'stock_code 无效');
break;
default:
return $this->toData('1', '股票市场或股票代码 无效');
}
// 交易所类型
// if(empty($param['tape']) || !in_array($param['tape'], array_keys(StockBlockListModel::$tapeList))){
// return $this->toData('1', '交易所类型 无效');
// }
// 发布状态
if (empty($param['status']) || !in_array($param['status'], [StockBlockListModel::STATUS_ON, StockBlockListModel::STATUS_OFF])) {
return $this->toData('1', '发布状态 无效');
}
// 单股价格
if (empty($param['price']) || !is_numeric($param['price']) || $param['price'] <= 0) {
return $this->toData('1', '单股价格 无效');
}
// 最小申购数量
if (empty($param['min']) || !is_numeric($param['min']) || $param['min'] <= 0 || ceil($param['min']) != $param['min']) {
return $this->toData('1', '最小购买股数无效');
}
// 开始认购时间
if (empty($param['start_time']) || !is_string($param['start_time'])) {
return $this->toData('1', '开始认购时间 无效');
}
// 认购结束时间
if (empty($param['end_time']) || !is_string($param['end_time']) || strtotime($param['end_time']) <= strtotime($param['start_time'])) {
return $this->toData('1', '认购结束时间 无效');
}
// 可出售时间时间
if (empty($param['today_add']) || !is_numeric($param['today_add'])) {
return $this->toData('1', 'T+n 无效');
}
// 新增数据
$blockStock->stock_code = $param['stock_code'];
$blockStock->stock_name = $param['stock_name'];
$blockStock->type = $param['type'];
$blockStock->tape = $stock->tape;
$blockStock->status = $param['status'];
$blockStock->price = $param['price'];
$blockStock->min = $param['min'];
$blockStock->start_time = $param['start_time'];
$blockStock->end_time = $param['end_time'];
$blockStock->today_add = $param['today_add'];
$blockStock->keep_decimal = $stock->keep_decimal;
$blockStock->info = $param['info'] ?? '';
$blockStock->forced_closure = $stock->forced_closure;
$blockStock->up_limit = $stock->up_limit;;
$blockStock->down_limit = $stock->down_limit;
$blockStock->update_time = date('Y-m-d H:i:s');
$blockStock->save();
// 加入缓存
$list_key = StockBlockListModel::$typeListEn[$param['type']] . ":BLOCK:LIST:" . $param['stock_code'];
$redis = $this->getRedis();
$redis->del($list_key);
$redis->hMset($list_key, [
'stock_name' => $blockStock->stock_name,
'stock_code' => $blockStock->stock_code,
'status' => $blockStock->status,
'keep_decimal' => $blockStock->keep_decimal,
'forced_closure' => $blockStock->forced_closure,
'up_limit' => $blockStock->up_limit,
'down_limit' => $blockStock->down_limit,
'info' => $blockStock->info,
'tape' => $blockStock->tape,
'price' => $blockStock->price,
'min' => $blockStock->min,
'start_time' => $blockStock->start_time,
'end_time' => $blockStock->end_time,
'today_add' => $blockStock->today_add
]);
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('0', '系统繁忙', [$exception->getMessage()]);
}
}
// //删除
// public function del($param)
// {
// try {
// if (empty($param['id']) || !is_numeric($param['id'])) {
// return $this->toData('1', '主键 无效');
// }
//
// $preInStock = StockBlockListModel::where('id', $param['id'])->where('is_delete', StockBlockListModel::IS_DELETE_NO)->find();
// if (empty($preInStock)) {
// return $this->toData('1', '主键 无效');
// }
//
// $orderList = UserMysPreStockOrderModel::where('pre_stock_id', $preInStock->id)->select();
// if (!$orderList->isEmpty()) {
// return $this->toData('1', '已有申购订单不可删除');
// }
//
// // 删除
// $list_key = "MYS:STOCK:LIST:" . $preInStock->stock_code;
// $redis = $this->getRedis();
// $redis->del($list_key);
//
// //删除 修改状态
// $preInStock->is_delete = PreMysStockModel::IS_DELETE_YES;
// $preInStock->save();
// return $this->toData('0', 'SUCCESS');
// } catch (\Exception $exception) {
// return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
// }
// }
}

138
app/admin/service/setting/BrokerageService.php

@ -0,0 +1,138 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\model\BrokerageSettingModel;
// 配置 返佣配置
class BrokerageService extends AdminBaseService
{
// 列表
public function index()
{
try {
$list = BrokerageSettingModel::order('id', 'desc')->select();
$rows = [];
if(!$list->isEmpty()){
$rows = $list->toArray();
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙');
}
}
public function add($param)
{
try {
if(!isset($param['brok_type']) || !in_array($param['brok_type'], [0,1,2])){
return $this->toData('1', '返佣类型无效');
}
if(!isset($param['pay_type']) || !in_array($param['pay_type'], [0,1])){
return $this->toData('1', '结算方式无效');
}
if(!isset($param['parent_fee']) || !is_numeric($param['parent_fee']) || $param['parent_fee'] < 0){
return $this->toData('1', '返佣比例无效1');
}
if(!isset($param['grandpa_fee']) || !is_numeric($param['grandpa_fee']) || $param['grandpa_fee'] < 0){
return $this->toData('1', '返佣比例无效2');
}
if(!isset($param['top_fee']) || !is_numeric($param['top_fee']) || $param['top_fee'] < 0){
return $this->toData('1', '返佣比例无效3');
}
if(isset($param['remark']) && (!is_string($param['remark']) || strlen($param['remark']) >= 15) ){
return $this->toData('1', '备注无效');
}
$remark = $param['remark']?? '';
$brok = new BrokerageSettingModel;
$brok->brok_type = $param['brok_type'];
$brok->pay_type = $param['pay_type'];
$brok->parent_fee = $param['parent_fee'];
$brok->grandpa_fee = $param['grandpa_fee'];
$brok->top_fee = $param['top_fee'];
$brok->remark = $remark;
$brok->save();
$fee_key=$this->getBrokerageKey($param['brok_type']);
$redis = $this->getRedis();
$redis->del($fee_key);
$redis->hMSet($fee_key, $param);
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙');
}
}
public function edit($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '主键无效');
}
$brok = BrokerageSettingModel::where('id', $param['id'])->find();
if(empty($brok)){
return $this->toData('1', '主键无效');
}
if(!isset($param['brok_type']) || !in_array($param['brok_type'], [0,1,2])){
return $this->toData('1', '返佣类型无效');
}
if(!isset($param['pay_type']) || !in_array($param['pay_type'], [0,1])){
return $this->toData('1', '结算方式无效');
}
if(!isset($param['parent_fee']) || !is_numeric($param['parent_fee']) || $param['parent_fee'] < 0){
return $this->toData('1', '返佣比例无效');
}
if(!isset($param['grandpa_fee']) || !is_numeric($param['grandpa_fee']) || $param['grandpa_fee'] < 0){
return $this->toData('1', '返佣比例无效');
}
if(!isset($param['top_fee']) || !is_numeric($param['top_fee']) || $param['top_fee'] < 0){
return $this->toData('1', '返佣比例无效');
}
if(isset($param['remark']) && (!is_string($param['remark']) || strlen($param['remark']) >= 15) ){
return $this->toData('1', '备注无效');
}
$remark = $param['remark']?? '';
$brok->brok_type = $param['brok_type'];
$brok->pay_type = $param['pay_type'];
$brok->parent_fee = $param['parent_fee'];
$brok->grandpa_fee = $param['grandpa_fee'];
$brok->top_fee = $param['top_fee'];
$brok->remark = $remark;
$brok->save();
$fee_key=$this->getBrokerageKey($param['brok_type']);
$redis = $this->getRedis();
$redis->del($fee_key);
$redis->hMSet($fee_key, $param);
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙');
}
}
}

348
app/admin/service/setting/ContractService.php

@ -0,0 +1,348 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\home\service\BaseHomeService;
use app\model\ContractListMode;
use app\model\ContractSettingModel;
use app\model\ContractTradeModel;
use think\facade\Cache;
class ContractService extends AdminBaseService
{
public function index()
{
try {
$list = ContractListMode::order('id', 'desc')->select();
$rows = [];
if(!$list->isEmpty()){
$rows =$list->toArray();
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
// 新增
public function add($param)
{
try {
// 交易对名称
if(empty($param['trade_name']) || !is_string($param['trade_name']) || strlen($param['trade_name']) > 100){
return $this->toData('1', '交易对名称无效', []);
}
// 状态
if(!isset($param['status']) || !in_array($param['status'], ['0', '1'])){
return $this->toData('1', '状态无效', []);
}
// 是否自发
if(!isset($param['is_owner']) || !in_array($param['is_owner'], ['0', '1'])){
return $this->toData('1', '是否自发无效', []);
}
// 简介
$info = '';
if(isset($param['info']) && is_string($param['info'])){
$info = $param['info'];
}
// 面值
if(!isset($param['face_value']) || !is_numeric($param['face_value']) || $param['face_value'] != ceil($param['face_value']) || $param['face_value'] <= 0){
return $this->toData('1', '面值无效', []);
}
// 排序
if(!isset($param['sort']) || !is_numeric($param['sort']) || $param['sort'] != ceil($param['sort']) || $param['sort'] < 0){
return $this->toData('1', '排序值无效', []);
}
// 最小杠杆
if(empty($param['min_pry']) || !is_numeric($param['min_pry']) || $param['min_pry'] != ceil($param['min_pry']) || $param['min_pry'] <= 0){
return $this->toData('1', '最小杠杆值无效', []);
}
// 最大杠杆
if(empty($param['max_pry']) || !is_numeric($param['max_pry']) || $param['max_pry'] != ceil($param['max_pry']) || $param['max_pry'] <= 0){
return $this->toData('1', '最大杠杆值无效', []);
}
// 强制平仓比例值
if(empty($param['compel_num']) || !is_numeric($param['compel_num']) || $param['compel_num'] <= 0){
return $this->toData('1', '强制平仓比例值无效', []);
}
// 小数位数
if(!isset($param['keep_decimal']) || !is_numeric($param['keep_decimal']) || $param['keep_decimal'] != ceil($param['keep_decimal']) || $param['keep_decimal'] < 0){
return $this->toData('1', '小数位数值无效', []);
}
// 判断名称是否已被添加
$count = ContractListMode::where('trade_name', $param['trade_name'])->count();
if($count > 0){
return $this->toData('1', '合约交易对名称已存在', []);
}
$contract = new ContractListMode;
$contract->trade_name = $param['trade_name'];
$contract->status = $param['status'];
$contract->is_owner = $param['is_owner'];
$contract->info = $info;
$contract->logo_link = '';
$contract->face_value = $param['face_value'];
$contract->sort = $param['sort'];
$contract->min_pry = $param['min_pry'];
$contract->max_pry = $param['max_pry'];
$contract->compel_num = $param['compel_num'];
$contract->keep_decimal = $param['keep_decimal'];
$contract->create_time = date('Y-m-d H:i:s');
$contract->update_time = date('Y-m-d H:i:s');
$contract->save();
$list_key="CONTRACT:LIST:".strtoupper($param['trade_name']);
$redis = $this->getRedis();
$redis->del($list_key);
$redis->hMset($list_key, [
'name'=>strtoupper($param['trade_name']),
'code'=>strtoupper($param['trade_name']),
'sort'=>$param['sort'],
'face_value'=>$param['face_value'],
'min_pry'=>$param['min_pry'],
'max_pry'=>$param['max_pry'],
'compel_num'=>$param['compel_num'],
'keep_decimal'=>$param['keep_decimal'],
'is_owner'=>$param['is_owner'],
'status'=>$param['status']
]);
return $this->toData('0', '操作成功', []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function edit($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在', []);
}
$contract = ContractListMode::where('id', $param['id'])->find();
$beforeStatus = $contract['status'];
if(empty($contract)){
return $this->toData('1', '目标不存在', []);
}
// 交易对名称
if(empty($param['trade_name']) || !is_string($param['trade_name']) || strlen($param['trade_name']) > 100){
return $this->toData('1', '交易对名称无效', []);
}
// 状态
if(!isset($param['status']) || !in_array($param['status'], ['0', '1'])){
return $this->toData('1', '状态无效', []);
}
// 是否自发
if(!isset($param['is_owner']) || !in_array($param['is_owner'], ['0', '1'])){
return $this->toData('1', '是否自发无效', []);
}
// 简介
$info = '';
if(isset($param['info']) && is_string($param['info'])){
$info = $param['info'];
}
// 面值
if(!isset($param['face_value']) || !is_numeric($param['face_value']) || $param['face_value'] != ceil($param['face_value']) || $param['face_value'] <= 0){
return $this->toData('1', '面值无效', []);
}
// 排序
if(!isset($param['sort']) || !is_numeric($param['sort']) || $param['sort'] != ceil($param['sort']) || $param['sort'] < 0){
return $this->toData('1', '排序值无效', []);
}
// 最小杠杆
if(empty($param['min_pry']) || !is_numeric($param['min_pry']) || $param['min_pry'] != ceil($param['min_pry']) || $param['min_pry'] <= 0){
return $this->toData('1', '最小杠杆值无效', []);
}
// 最大杠杆
if(empty($param['max_pry']) || !is_numeric($param['max_pry']) || $param['max_pry'] != ceil($param['max_pry']) || $param['max_pry'] <= 0){
return $this->toData('1', '最大杠杆值无效', []);
}
// 强制平仓比例值
if(empty($param['compel_num']) || !is_numeric($param['compel_num']) || $param['compel_num'] <= 0){
return $this->toData('1', '强制平仓比例值无效', []);
}
// 小数位数
if(!isset($param['keep_decimal']) || !is_numeric($param['keep_decimal']) || $param['keep_decimal'] != ceil($param['keep_decimal']) || $param['keep_decimal'] < 0){
return $this->toData('1', '小数位数值无效', []);
}
// 判断名称是否已被添加
$count = ContractListMode::where('trade_name', $param['trade_name'])->where('id', '<>', $param['id'])->count();
if($count > 0){
return $this->toData('1', '合约交易对名称已存在', []);
}
// 如果状态设置成关闭 则判断是否有正在交易的合约
if($beforeStatus == 1 && $param['status'] == 0){
$num=(new ContractTradeModel())->where([
'contract_id'=>strtoupper($contract['trade_name']),
'status'=>1
])->count();
if ($num != 0) {
return $this->toData('1', '交易对还存在交易,不能关闭', []);
}
}
// 写入数据
$contract->trade_name = $param['trade_name'];
$contract->status = $param['status'];
$contract->is_owner = $param['is_owner'];
$contract->info = $info;
$contract->logo_link = '';
$contract->face_value = $param['face_value'];
$contract->sort = $param['sort'];
$contract->min_pry = $param['min_pry'];
$contract->max_pry = $param['max_pry'];
$contract->compel_num = $param['compel_num'];
$contract->keep_decimal = $param['keep_decimal'];
$contract->create_time = date('Y-m-d H:i:s');
$contract->update_time = date('Y-m-d H:i:s');
$contract->save();
$list_key="CONTRACT:LIST:".strtoupper($param['trade_name']);
$redis = $this->getRedis();
$redis->del($list_key);
$redis->hMset($list_key, [
'name'=>strtoupper($param['trade_name']),
'code'=>strtoupper($param['trade_name']),
'sort'=>$param['sort'],
'face_value'=>$param['face_value'],
'min_pry'=>$param['min_pry'],
'max_pry'=>$param['max_pry'],
'compel_num'=>$param['compel_num'],
'keep_decimal'=>$param['keep_decimal'],
'status'=>$param['status']
]);
return $this->toData('0', 'SUCCESS', []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
// 获取合约交易对
public function getTradeNameList($param)
{
try {
if(isset($param['is_owner']) && in_array($param['is_owner'], [0,1])){
$list = ContractListMode::where('status', 1)->order('id', 'desc')
->where('is_owner', $param['is_owner'])
->column('trade_name', 'id');
} else {
$list = ContractListMode::where('status', 1)->order('id', 'desc')
->column('trade_name', 'id');
}
return $this->toData('0', 'SUCCESS', ['list' => $list]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
public function setting($param)
{
try {
$list = ContractSettingModel::order('time_step', 'asc')->select();
$rows = [];
if(!$list->isEmpty()){
$rows =$list->toArray();
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
public function set_add($param)
{
// 状态
if(!isset($param['time_step'])){
return $this->toData('1', '时间无效', []);
}
// 是否自发
if(!isset($param['earnings_num'])){
return $this->toData('1', '收益无效', []);
}
$contract = ContractSettingModel::where('time_step', $param['time_step'])->find();
if(!empty($contract)){
return $this->toData('1', '时间已存在', []);
}
$contract = new ContractSettingModel;
// 写入数据
$contract->time_step = $param['time_step'];
$contract->earnings_num = $param['earnings_num'];
$contract->create_time = date('Y-m-d H:i:s');
$contract->update_time = date('Y-m-d H:i:s');
$contract->save();
$this->initContractSetting();
return $this->toData('0', 'SUCCESS', []);
}
public function set_edit($param)
{
// 状态
if(!isset($param['time_step'])){
return $this->toData('1', '时间无效', []);
}
// 是否自发
if(!isset($param['earnings_num'])){
return $this->toData('1', '收益无效', []);
}
// 是否自发
if(!isset($param['id'])){
return $this->toData('1', 'ID无效', []);
}
$contract = ContractSettingModel::where('id', $param['id'])->find();
if(empty($contract)){
return $this->toData('1', '目标不存在', []);
}
// 写入数据
$contract->time_step = $param['time_step'];
$contract->earnings_num = $param['earnings_num'];
$contract->create_time = date('Y-m-d H:i:s');
$contract->update_time = date('Y-m-d H:i:s');
$contract->save();
$this->initContractSetting();
return $this->toData('0', 'SUCCESS', []);
}
public function set_del($param)
{
if(!isset($param['id'])){
return $this->toData('1', 'ID无效', []);
}
$contract = ContractSettingModel::where('id', $param['id'])->find();
if(empty($contract)){
return $this->toData('1', '目标不存在', []);
}
$contract->where('id',$param['id'])->delete();
$this->initContractSetting();
return $this->toData('0', 'SUCCESS', []);
}
}

161
app/admin/service/setting/DMarketService.php

@ -0,0 +1,161 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\admin\validate\setting\MarketValidate;
use app\model\ContractMarketModel;
use think\exception\ValidateException;
class DMarketService extends AdminBaseService
{
public function index()
{
try {
$list = ContractMarketModel::where('type', ContractMarketModel::TYPE_DIGITAL_SELF)
->order('id', 'desc')
->select();
$rows = [];
if(!$list->isEmpty()){
foreach ($list as $item){
if(empty($rows[$item['trade_name']])){
$rows[$item['trade_name']] = [
'trade_name' => $item['trade_name'],
'begin_time' => $item['begin_time'],
'end_time' => $item['end_time'],
'max_price' => $item['max_price'],
'step' => $item['step'],
];
}
}
}
$rows = array_values($rows);
return $this->toData('0','SUCCSS',['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
// 详情
public function detail($param)
{
try {
if(empty($param['trade_name']) || !is_string($param['trade_name'])){
return $this->toData('1', '参数错误');
}
$list = ContractMarketModel::where('type', ContractMarketModel::TYPE_DIGITAL_SELF)
->where('trade_name', $param['trade_name'])
->order('id', 'desc')->select();
$rows = [];
if(!$list->isEmpty()){
foreach ($list as $item){
$rows[] = [
'id' => $item['id'],
'trade_name' => $item['trade_name'],
'begin_time' => $item['begin_time'],
'end_time' => $item['end_time'],
'max_price' => $item['max_price'],
'step' => $item['step'],
];
}
}
return $this->toData('0','SUCCESS',['list' => $rows]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 新增
public function add($param)
{
try {
// 参数校验
validate(MarketValidate::class)->scene('add')->check($param);
// 必须大于当前时间
if(strtotime($param['end_time']) - time() <= 0){
return $this->toData('1','结束时间无效1');
}
if((strtotime($param['begin_time']) - time()) <= 0 || (strtotime($param['end_time']) - strtotime($param['begin_time'])) <= 0){
return $this->toData('1','开始时间无效2');
}
$market = new ContractMarketModel;
$market->trade_name = $param['trade_name'];
$market->begin_time = $param['begin_time'];
$market->end_time = $param['end_time'];
$market->max_price = $param['max_price'];
$market->type = ContractMarketModel::TYPE_DIGITAL_SELF;
$market->save();
return $this->toData('0','SUCCESS');
}catch (ValidateException $validateException){
return $this->toData('1', $validateException->getMessage(), []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 编辑
public function edit($param)
{
try {
// 参数校验
validate(MarketValidate::class)->scene('edit')->check($param);
// 目标
$market = ContractMarketModel::where('id', $param['id'])->where('type', ContractMarketModel::TYPE_DIGITAL_SELF)->find();
if(empty($market)){
return $this->toData('1','目标不存在');
}
// 必须大于当前时间
if(strtotime($param['end_time']) - time() <= 0){
return $this->toData('1','时间无效');
}
if((strtotime($param['begin_time']) - time()) <= 0 || (strtotime($param['end_time']) - strtotime($param['begin_time'])) <= 0){
return $this->toData('1','开始时间无效');
}
$market->trade_name = $param['trade_name'];
$market->begin_time = $param['begin_time'];
$market->end_time = $param['end_time'];
$market->max_price = $param['max_price'];
$market->save();
return $this->toData('0','SUCCESS');
}catch (ValidateException $validateException){
return $this->toData('1', $validateException->getMessage(), []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
// 删除
public function del($param)
{
try {
// 参数校验
validate(MarketValidate::class)->scene('del')->check($param);
// 目标
$market = ContractMarketModel::where('id', $param['id'])->where('type',ContractMarketModel::TYPE_DIGITAL_SELF)->find();
if(empty($market)){
return $this->toData('1','目标不存在');
}
$market->delete();
return $this->toData('0','SUCCESS');
}catch (ValidateException $validateException){
return $this->toData('1', $validateException->getMessage(), []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
}

203
app/admin/service/setting/DigitalService.php

@ -0,0 +1,203 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\model\DigitalListModel;
// 现货交易对
class DigitalService extends AdminBaseService
{
public function index()
{
try {
$list = DigitalListModel::order('id', 'desc')->select();
$rows = [];
if(!$list->isEmpty()){
$rows = $list->toArray();
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
public function add($param)
{
try {
if(empty($param['trade_name']) || !is_string($param['trade_name'])){
return $this->toData('1', '数字货币名称无效');
}
if(empty($param['exchange_name']) || !is_string($param['exchange_name'])){
return $this->toData('1', '数字币兑换对名称无效');
}
// 简介
if(!empty($param['info']) && !is_string($param['info'])){
return $this->toData('1', '简介无效');
}
$info = $param['info']?? '';
// 状态
if(!isset($param['status']) || !in_array($param['status'], [0,1])){
return $this->toData('1', '启用状态无效');
}
// 排序
if(!isset($param['sort']) || !is_numeric($param['sort']) || ceil($param['sort']) != $param['sort']){
return $this->toData('1', '排序无效');
}
// 图片链接
if(empty($param['logo_link']) || !is_string($param['logo_link'])){
return $this->toData('1', 'logo链接无效');
}
// 小数位数
if(!isset($param['keep_decimal']) || !is_numeric($param['keep_decimal']) || $param['keep_decimal'] < 0 || ceil($param['keep_decimal']) != $param['keep_decimal']){
return $this->toData('1', '保留小数位无效');
}
// 判断股票代码是否已经存在
$count = DigitalListModel::where('trade_name', $param['trade_name'])->where('exchange_name', $param['exchange_name'])->count();
if($count > 0){
return $this->toData('1', '现货数字币交易对已经存在');
}
$digitalList = new DigitalListModel;
$digitalList->trade_name = $param['trade_name'];
$digitalList->exchange_name = $param['exchange_name'];
$digitalList->status = $param['status'];
$digitalList->logo_link = $param['logo_link'];
$digitalList->sort = $param['sort'];
$digitalList->keep_decimal = $param['keep_decimal'];
$digitalList->info = $info;
$digitalList->create_time = date('Y-m-d H:i:s');
$digitalList->update_time = date('Y-m-d H:i:s');
$digitalList->save();
// 设置缓存
$fee_key="DIGITAL:LIST:".strtoupper($param['trade_name']);
$redis = $this->getRedis();
$redis->del($fee_key);
$redis->hMSet($fee_key,[
'name'=>strtoupper($param['trade_name']),
'sort'=>$param['sort'],
'exchange_name'=>$param['exchange_name'],
'logo_link'=>$param['logo_link'],
'keep_decimal'=>$param['keep_decimal'],
'status'=>$param['status'],
]);
return $this->toData('0', '操作成功', []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
public function edit($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在', []);
}
$digitalList = DigitalListModel::where('id', $param['id'])->find();
if(empty($digitalList)){
return $this->toData('1', '目标不存在', []);
}
if(empty($param['trade_name']) || !is_string($param['trade_name'])){
return $this->toData('1', '数字货币名称无效');
}
if(empty($param['exchange_name']) || !is_string($param['exchange_name'])){
return $this->toData('1', '数字币兑换对名称无效');
}
// 简介
if(!empty($param['info']) && !is_string($param['info'])){
return $this->toData('1', '简介无效');
}
$info = $param['info']?? '';
// 状态
if(!isset($param['status']) || !in_array($param['status'], [0,1])){
return $this->toData('1', '启用状态无效');
}
// 排序
if(!isset($param['sort']) || !is_numeric($param['sort']) || ceil($param['sort']) != $param['sort']){
return $this->toData('1', '排序无效');
}
// 图片链接
if(empty($param['logo_link']) || !is_string($param['logo_link'])){
return $this->toData('1', 'logo链接无效');
}
// 小数位数
if(!isset($param['keep_decimal']) || !is_numeric($param['keep_decimal']) || $param['keep_decimal'] < 0 || ceil($param['keep_decimal']) != $param['keep_decimal']){
return $this->toData('1', '保留小数位无效');
}
// 判断股票代码是否已经存在
$count = DigitalListModel::where('trade_name', $param['trade_name'])->where('exchange_name', $param['exchange_name'])
->where('id','<>', $param['id'])
->count();
if($count > 0){
return $this->toData('1', '现货数字币交易对已经存在');
}
$digitalList->trade_name = $param['trade_name'];
$digitalList->exchange_name = $param['exchange_name'];
$digitalList->status = $param['status'];
$digitalList->logo_link = $param['logo_link'];
$digitalList->sort = $param['sort'];
$digitalList->keep_decimal = $param['keep_decimal'];
$digitalList->info = $info;
$digitalList->update_time = date('Y-m-d H:i:s');
$digitalList->save();
// 设置缓存
$fee_key="DIGITAL:LIST:".strtoupper($param['trade_name']);
$redis = $this->getRedis();
$redis->del($fee_key);
$redis->hMSet($fee_key,[
'name'=>strtoupper($param['trade_name']),
'sort'=>$param['sort'],
'logo_link'=>$param['logo_link'],
'keep_decimal'=>$param['keep_decimal'],
'status'=>$param['status'],
]);
return $this->toData('0', '操作成功', []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
public function getTradeNameList($param)
{
try {
if(isset($param['is_owner']) && in_array($param['is_owner'], [0,1])){
$list = DigitalListModel::where('status', 1)->order('id', 'desc')
->where('is_owner', $param['is_owner'])
->column('trade_name', 'id');
} else {
$list = DigitalListModel::where('status', 1)->order('id', 'desc')->column('trade_name', 'id');
}
return $this->toData('0', 'SUCCESS', ['list' => $list]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
}

68
app/admin/service/setting/DrawalService.php

@ -0,0 +1,68 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\model\DrawalSettingModel;
class DrawalService extends AdminBaseService
{
// 提现手续费
public function index()
{
try {
$list = DrawalSettingModel::select();
$rows = [];
if(!$list->isEmpty()){
$rows = $list->toArray();
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
public function edit($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在', []);
}
if(empty($param['bank_drawal_fee']) || !is_numeric($param['bank_drawal_fee']) || $param['bank_drawal_fee'] < 0){
return $this->toData('1', '银行提现手续费无效', []);
}
if(empty($param['digital_drawal_fee']) || !is_numeric($param['digital_drawal_fee']) || $param['digital_drawal_fee'] < 0){
return $this->toData('1', '数字币提现手续费无效', []);
}
if(empty($param['min_recharge']) || !is_numeric($param['min_recharge']) || $param['min_recharge'] < 0){
return $this->toData('1', '最小充值金额无效', []);
}
if(empty($param['min_drawal']) || !is_numeric($param['min_drawal']) || $param['min_drawal'] < 0){
return $this->toData('1', '最小提现金额无效', []);
}
$drawal = DrawalSettingModel::where('id', $param['id'])->find();
if(empty($drawal)){
return $this->toData('1', '目标不存在', []);
}
$drawal->bank_drawal_fee = $param['bank_drawal_fee'];
$drawal->digital_drawal_fee = $param['digital_drawal_fee'];
$drawal->min_recharge = $param['min_recharge'];
$drawal->min_drawal = $param['min_drawal'];
$drawal->save();
$fee_key="DRAWAL:FEE:SETTING";
$redis = $this->getRedis();
$redis->del($fee_key);
$redis->hMSet($fee_key,$param);
return $this->toData('0','SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
}

202
app/admin/service/setting/FeeService.php

@ -0,0 +1,202 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\model\FeeSettingModel;
use app\model\StockMarketModel;
class FeeService extends AdminBaseService
{
// 交易手续费
public function index()
{
try {
$list = FeeSettingModel::order('id', 'desc')->select();
$rows = [];
if (!$list->isEmpty()) {
$rows = $list->toArray();
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows), 'extent' => [
'market_type_list' => StockMarketModel::STOCK_MARKET_TYPE, 'pay_type' => FeeSettingModel::$payTypeList
]]);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
public function add($param)
{
try {
$marketTypeIds = array_keys(StockMarketModel::STOCK_MARKET_TYPE);
if (empty($param['market_type']) || !in_array($param['market_type'], $marketTypeIds)) {
return $this->toData('1', '市场类型无效', []);
}
if (!is_numeric($param['buy_fee']) || $param['buy_fee'] < 0) {
return $this->toData('1', '买入手续费无效', []);
}
// if(empty($param['purchase_fee']) || !is_numeric($param['purchase_fee']) || $param['purchase_fee'] < 0){
// return $this->toData('1', '盘前申购手续费无效', []);
// }
if (!is_numeric($param['sale_fee']) || $param['sale_fee'] < 0) {
return $this->toData('1', '卖出手续费无效', []);
}
if (in_array($param['market_type'], [3, 4, 5, 6, 7, 9, 12,14])) {
if (empty($param['purchase_fee']) || !is_numeric($param['purchase_fee']) || $param['purchase_fee'] < 0) {
return $this->toData('1', '申购手续费无效', []);
}
}
// 结算方式:0固定费用,1按比例结算
if (!isset($param['pay_type']) || !in_array($param['pay_type'], array_keys(FeeSettingModel::$payTypeList))) {
return $this->toData('1', '结算方式无效', []);
}
// 买入最小下单金额
if (empty($param['min_buy_num']) || !is_numeric($param['min_buy_num']) || ceil($param['min_buy_num']) != $param['min_buy_num']) {
return $this->toData('1', '买入最小下单金额无效', []);
}
//卖出最小下单金额
if (empty($param['min_sale_num']) || !is_numeric($param['min_sale_num']) || ceil($param['min_sale_num']) != $param['min_sale_num']) {
return $this->toData('1', '卖出最小下单金额无效', []);
}
// max_entrust_num
if (empty($param['max_entrust_num']) || !is_numeric($param['max_entrust_num']) || ceil($param['max_entrust_num']) != $param['max_entrust_num']) {
return $this->toData('1', '最大挂单数量无效', []);
}
// 最大持仓数量
if (empty($param['max_hold_num']) || !is_numeric($param['max_hold_num']) || ceil($param['max_hold_num']) != $param['max_hold_num']) {
return $this->toData('1', '最大持仓数量无效', []);
}
$count = FeeSettingModel::where('market_type', $param['market_type'])->count();
if ($count > 0) {
return $this->toData('1', '市场类型已经存在', []);
}
$feeSetting = new FeeSettingModel;
$feeSetting->market_type = $param['market_type'];
$feeSetting->buy_fee = $param['buy_fee'];
$feeSetting->sale_fee = $param['sale_fee'];
$feeSetting->pay_type = $param['pay_type'];
$feeSetting->purchase_fee = isset($param['purchase_fee']) ? $param['purchase_fee'] : 0;
$feeSetting->min_buy_num = $param['min_buy_num'];
$feeSetting->min_sale_num = $param['min_sale_num'];
$feeSetting->max_entrust_num = $param['max_entrust_num'];
$feeSetting->max_hold_num = $param['max_hold_num'];
$feeSetting->min_withdrawal_num = empty($param['min_withdrawal_num']) ? 0 :$param['min_withdrawal_num'];
$feeSetting->min_recharge_num = empty($param['min_recharge_num']) ? 0 :$param['min_recharge_num'];
$feeSetting->save();
// 设置缓存
$fee_key = $this->getTradeFeeKey($param['market_type']);
$redis = $this->getRedis();
$redis->del($fee_key);
$redis->hMSet($fee_key, $param);
return $this->toData('0', 'SUCCESS', []);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage(), $exception->getTrace()]);
}
}
public function edit($param)
{
try {
if (empty($param['id']) || !is_numeric($param['id'])) {
return $this->toData('1', '目标不存在', []);
}
$feeSetting = FeeSettingModel::where('id', $param['id'])->find();
if (empty($feeSetting)) {
return $this->toData('1', '目标不存在', []);
}
$marketTypeIds = array_keys(StockMarketModel::STOCK_MARKET_TYPE);
if (empty($param['market_type']) || !in_array($param['market_type'], $marketTypeIds)) {
return $this->toData('1', '市场类型无效', []);
}
if (!is_numeric($param['buy_fee']) || $param['buy_fee'] < 0) {
return $this->toData('1', '买入手续费无效', []);
}
if (in_array($param['market_type'], [3, 4, 5, 6, 7, 9, 12, 14])) {
if (empty($param['purchase_fee']) || !is_numeric($param['purchase_fee']) || $param['purchase_fee'] < 0) {
return $this->toData('1', '申购手续费无效', []);
}
}
if (!is_numeric($param['sale_fee']) || $param['sale_fee'] < 0) {
return $this->toData('1', '卖出手续费无效', []);
}
// if(empty($param['purchase_fee']) || !is_numeric($param['purchase_fee']) || $param['purchase_fee'] < 0){
// return $this->toData('1', '申购手续费无效', []);
// }
// 结算方式:0固定费用,1按比例结算
if (!isset($param['pay_type']) || !in_array($param['pay_type'], array_keys(FeeSettingModel::$payTypeList))) {
return $this->toData('1', '结算方式无效', []);
}
// 买入最小下单金额
if (empty($param['min_buy_num']) || !is_numeric($param['min_buy_num']) || ceil($param['min_buy_num']) != $param['min_buy_num']) {
return $this->toData('1', '买入最小下单金额无效', []);
}
//卖出最小下单金额
if (empty($param['min_sale_num']) || !is_numeric($param['min_sale_num']) || ceil($param['min_sale_num']) != $param['min_sale_num']) {
return $this->toData('1', '卖出最小下单金额无效', []);
}
// max_entrust_num
if (empty($param['max_entrust_num']) || !is_numeric($param['max_entrust_num']) || ceil($param['max_entrust_num']) != $param['max_entrust_num']) {
return $this->toData('1', '最大挂单数量无效', []);
}
// 最大持仓数量
if (empty($param['max_hold_num']) || !is_numeric($param['max_hold_num']) || ceil($param['max_hold_num']) != $param['max_hold_num']) {
return $this->toData('1', '最大持仓数量无效', []);
}
$count = FeeSettingModel::where('market_type', $param['market_type'])->where('id', '<>', $feeSetting->id)->count();
if ($count > 0) {
return $this->toData('1', '市场类型已经存在', []);
}
$feeSetting->market_type = $param['market_type'];
$feeSetting->buy_fee = $param['buy_fee'];
$feeSetting->sale_fee = $param['sale_fee'];
$feeSetting->pay_type = $param['pay_type'];
$feeSetting->min_buy_num = $param['min_buy_num'];
$feeSetting->purchase_fee = $param['purchase_fee'];
$feeSetting->min_sale_num = $param['min_sale_num'];
$feeSetting->max_entrust_num = $param['max_entrust_num'];
$feeSetting->max_hold_num = $param['max_hold_num'];
$feeSetting->min_withdrawal_num = empty($param['min_withdrawal_num']) ? 0 :$param['min_withdrawal_num'];
$feeSetting->min_recharge_num = empty($param['min_recharge_num']) ? 0 :$param['min_recharge_num'];
$feeSetting->save();
// 设置缓存
$fee_key = $this->getTradeFeeKey($param['market_type']);
$redis = $this->getRedis();
$redis->del($fee_key);
$redis->hMSet($fee_key, $param);
return $this->toData('0', 'SUCCESS', []);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
}

270
app/admin/service/setting/ForexService.php

@ -0,0 +1,270 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\home\service\BaseHomeService;
use app\model\ContractListMode;
use app\model\ContractSettingModel;
use app\model\ContractTradeModel;
use app\model\ForexListModel;
use think\facade\Cache;
class ForexService extends AdminBaseService
{
public function index()
{
try {
$list = ForexListModel::order('id', 'desc')->select();
$rows = [];
if(!$list->isEmpty()){
$rows =$list->toArray();
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
// 新增
public function add($param)
{
try {
// 交易对名称
if(empty($param['trade_name']) || !is_string($param['trade_name']) || strlen($param['trade_name']) > 100){
return $this->toData('1', '交易对名称无效', []);
}
// 状态
if(!isset($param['status']) || !in_array($param['status'], ['0', '1'])){
return $this->toData('1', '状态无效', []);
}
// 是否自发
if(!isset($param['is_owner']) || !in_array($param['is_owner'], ['0', '1'])){
return $this->toData('1', '是否自发无效', []);
}
// 简介
$info = '';
if(isset($param['info']) && is_string($param['info'])){
$info = $param['info'];
}
// 面值
if(!isset($param['face_value']) || !is_numeric($param['face_value']) || $param['face_value'] != ceil($param['face_value']) || $param['face_value'] <= 0){
return $this->toData('1', '面值无效', []);
}
// 排序
if(!isset($param['sort']) || !is_numeric($param['sort']) || $param['sort'] != ceil($param['sort']) || $param['sort'] < 0){
return $this->toData('1', '排序值无效', []);
}
// 最小杠杆
if(empty($param['min_pry']) || !is_numeric($param['min_pry']) || $param['min_pry'] != ceil($param['min_pry']) || $param['min_pry'] <= 0){
return $this->toData('1', '最小杠杆值无效', []);
}
// 最大杠杆
if(empty($param['max_pry']) || !is_numeric($param['max_pry']) || $param['max_pry'] != ceil($param['max_pry']) || $param['max_pry'] <= 0){
return $this->toData('1', '最大杠杆值无效', []);
}
// 强制平仓比例值
if(empty($param['compel_num']) || !is_numeric($param['compel_num']) || $param['compel_num'] <= 0){
return $this->toData('1', '强制平仓比例值无效', []);
}
// 小数位数
if(!isset($param['keep_decimal']) || !is_numeric($param['keep_decimal']) || $param['keep_decimal'] != ceil($param['keep_decimal']) || $param['keep_decimal'] < 0){
return $this->toData('1', '小数位数值无效', []);
}
// 判断名称是否已被添加
$count = ForexListModel::where('trade_name', $param['trade_name'])->count();
if($count > 0){
return $this->toData('1', '合约交易对名称已存在', []);
}
$contract = new ForexListModel;
$contract->trade_name = $param['trade_name'];
$contract->status = $param['status'];
$contract->is_owner = $param['is_owner'];
$contract->info = $info;
$contract->logo_link = '';
$contract->face_value = $param['face_value'];
$contract->sort = $param['sort'];
$contract->min_pry = $param['min_pry'];
$contract->max_pry = $param['max_pry'];
$contract->compel_num = $param['compel_num'];
$contract->keep_decimal = $param['keep_decimal'];
$contract->create_time = date('Y-m-d H:i:s');
$contract->update_time = date('Y-m-d H:i:s');
$contract->save();
$list_key="FOREX:LIST:".strtoupper($param['trade_name']);
$redis = $this->getRedis();
$redis->del($list_key);
$redis->hMset($list_key, [
'name'=>strtoupper($param['trade_name']),
'code'=>strtoupper($param['trade_name']),
'sort'=>$param['sort'],
'face_value'=>$param['face_value'],
'min_pry'=>$param['min_pry'],
'max_pry'=>$param['max_pry'],
'compel_num'=>$param['compel_num'],
'keep_decimal'=>$param['keep_decimal'],
'is_owner'=>$param['is_owner'],
'status'=>$param['status']
]);
return $this->toData('0', '操作成功', []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function edit($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '目标不存在', []);
}
$contract = ForexListModel::where('id', $param['id'])->find();
$beforeStatus = $contract['status'];
if(empty($contract)){
return $this->toData('1', '目标不存在', []);
}
// 交易对名称
if(empty($param['trade_name']) || !is_string($param['trade_name']) || strlen($param['trade_name']) > 100){
return $this->toData('1', '交易对名称无效', []);
}
// 状态
if(!isset($param['status']) || !in_array($param['status'], ['0', '1'])){
return $this->toData('1', '状态无效', []);
}
// 是否自发
if(!isset($param['is_owner']) || !in_array($param['is_owner'], ['0', '1'])){
return $this->toData('1', '是否自发无效', []);
}
// 简介
$info = '';
if(isset($param['info']) && is_string($param['info'])){
$info = $param['info'];
}
// 面值
if(!isset($param['face_value']) || !is_numeric($param['face_value']) || $param['face_value'] != ceil($param['face_value']) || $param['face_value'] <= 0){
return $this->toData('1', '面值无效', []);
}
// 排序
if(!isset($param['sort']) || !is_numeric($param['sort']) || $param['sort'] != ceil($param['sort']) || $param['sort'] < 0){
return $this->toData('1', '排序值无效', []);
}
// 最小杠杆
if(empty($param['min_pry']) || !is_numeric($param['min_pry']) || $param['min_pry'] != ceil($param['min_pry']) || $param['min_pry'] <= 0){
return $this->toData('1', '最小杠杆值无效', []);
}
// 最大杠杆
if(empty($param['max_pry']) || !is_numeric($param['max_pry']) || $param['max_pry'] != ceil($param['max_pry']) || $param['max_pry'] <= 0){
return $this->toData('1', '最大杠杆值无效', []);
}
// 强制平仓比例值
if(empty($param['compel_num']) || !is_numeric($param['compel_num']) || $param['compel_num'] <= 0){
return $this->toData('1', '强制平仓比例值无效', []);
}
// 小数位数
if(!isset($param['keep_decimal']) || !is_numeric($param['keep_decimal']) || $param['keep_decimal'] != ceil($param['keep_decimal']) || $param['keep_decimal'] < 0){
return $this->toData('1', '小数位数值无效', []);
}
// 判断名称是否已被添加
$count = ForexListModel::where('trade_name', $param['trade_name'])->where('id', '<>', $param['id'])->count();
if($count > 0){
return $this->toData('1', '合约交易对名称已存在', []);
}
// 如果状态设置成关闭 则判断是否有正在交易的合约
if($beforeStatus == 1 && $param['status'] == 0){
$num=(new ForexListModel())->where([
'contract_id'=>strtoupper($contract['trade_name']),
'status'=>1
])->count();
if ($num != 0) {
return $this->toData('1', '交易对还存在交易,不能关闭', []);
}
}
// 写入数据
$contract->trade_name = $param['trade_name'];
$contract->status = $param['status'];
$contract->is_owner = $param['is_owner'];
$contract->info = $info;
$contract->logo_link = '';
$contract->face_value = $param['face_value'];
$contract->sort = $param['sort'];
$contract->min_pry = $param['min_pry'];
$contract->max_pry = $param['max_pry'];
$contract->compel_num = $param['compel_num'];
$contract->keep_decimal = $param['keep_decimal'];
$contract->create_time = date('Y-m-d H:i:s');
$contract->update_time = date('Y-m-d H:i:s');
$contract->save();
$list_key="FOREX:LIST:".strtoupper($param['trade_name']);
$redis = $this->getRedis();
$redis->del($list_key);
$redis->hMset($list_key, [
'name'=>strtoupper($param['trade_name']),
'code'=>strtoupper($param['trade_name']),
'sort'=>$param['sort'],
'face_value'=>$param['face_value'],
'min_pry'=>$param['min_pry'],
'max_pry'=>$param['max_pry'],
'compel_num'=>$param['compel_num'],
'keep_decimal'=>$param['keep_decimal'],
'status'=>$param['status']
]);
return $this->toData('0', 'SUCCESS', []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
// 获取合约交易对
public function getTradeNameList($param)
{
try {
if(isset($param['is_owner']) && in_array($param['is_owner'], [0,1])){
$list = ForexListModel::where('status', 1)->order('id', 'desc')
->where('is_owner', $param['is_owner'])
->column('trade_name', 'id');
} else {
$list = ForexListModel::where('status', 1)->order('id', 'desc')
->column('trade_name', 'id');
}
return $this->toData('0', 'SUCCESS', ['list' => $list]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
}

133
app/admin/service/setting/GiveStockService.php

@ -0,0 +1,133 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\model\StockInListModel;
use app\model\StockMarketModel;
use app\model\UserInGiveStockOrderModel;
use app\model\UserModel;
use app\utility\ClientGo;
use app\utility\Tool;
use think\facade\Db;
// 送股
class GiveStockService extends AdminBaseService
{
// 列表
public function index($marketType, $param, $adminId)
{
try {
if (empty($param['page']) || !is_numeric($param['page']) || empty($param['limit']) || !is_numeric($param['limit'])) {
return $this->toData('1', '分页参数错误');
}
$where = [];
$userId = 0;
// 用户号精确搜索
if (!empty($param['user_no'])) {
$user = UserModel::where('user_no', $param['user_no'])->find();
if (empty($user)) {
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extent' => StockMarketModel::STOCK_MARKET_TYPE]);
}
$userId = $user['user_id'];
}
// 判断是否是代理 如果是代理 只能看他自己管理的用户
$whereU = $this->getWhereByIsAgentAndUserId($adminId, $where, $userId);
if (!is_array($whereU)) {
return $this->toData('0', 'SUCCESS', ['total' => 0, 'list' => [], 'extent' => StockMarketModel::STOCK_MARKET_TYPE]);
}
// 股票号
if (!empty($param['stock_code']) && is_string($param['stock_code'])) {
$where[] = [
'stock_code', 'like', '%' . $param['stock_code']
];
}
$tableObj = (new IPOService())->getStockModel($marketType);
$query = Db::table($tableObj['give_order_table'])->where($where)->where($whereU)->with(['user' => function ($query) {
$query->field('user_id,user_no,nick_name,email,phone_number');
}])->order('id', 'desc');
$totalQuery = Db::table($tableObj['give_order_table'])->where($where)->where($whereU)->order('id', 'desc');
$list = $query->page($param['page'], $param['limit'])->select()->toArray();
$total = $totalQuery->count();
$stockCodeArr = array_column($list, 'stock_code');
$stockNameArr = Db::table($tableObj['list_table'])->whereIn('stock_code', $stockCodeArr)->column('stock_name', 'stock_code');
foreach ($list as &$v) {
$v['stock_name'] = $stockNameArr[$v['stock_code']];
}
return $this->toData('0', 'SUCCESS', ['list' => $list, 'total' => $total, 'extent' => StockMarketModel::STOCK_MARKET_TYPE]);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 新增
public function add($marketType, $param)
{
try {
// 股票代码
if (empty($param['stock_code']) || !is_string($param['stock_code'])) {
return $this->toData('1', '股票代码 无效');
}
if (empty($param['tape']) || !is_numeric($param['tape'])) {
return $this->toData('1', '交易所 无效');
}
$tapeList = (new StockMarketModel)->getAllTape();
if (strpos($param['stock_code'], ':') !== false) {
$param['stock_code'] = explode(':', $param['stock_code'])[1];
}
$tape = $tapeList[$marketType][$param['tape']];
if ($marketType != 3) $param['stock_code'] = $tape . ':' . $param['stock_code'];
$tableObj = (new IPOService())->getStockModel($marketType);
$isHas = Db::table($tableObj['list_table'])->where('stock_code', $param['stock_code'])->value('id');
if (empty($isHas)) return $this->toData('1', '股票 无效');
// 股票代码
if (empty($param['user_id']) || !is_numeric($param['user_id'])) {
return $this->toData('1', '用户 无效');
}
if (empty($param['num']) || !is_numeric($param['num']) || $param['num'] <= 0) {
return $this->toData('1', '送股数量 无效');
}
$price=!empty($param['price']) ? floatval($param['price']) : 0;
$date = date('Y-m-d H:i:s');
$orderNo = (new Tool())->orderNo(20);
$insertArr = [
'user_id' => $param['user_id'],
'stock_code' => $param['stock_code'],
'order_no' => $orderNo,
'num' => $param['num'],
'price' => $price,
'amount' => $price*$param['num'],
'create_time' => $date,
'update_time' => $date
];
$insertBool = Db::table($tableObj['give_order_table'])->insert($insertArr);
if ($insertBool) {
// 通知交易
$bool = (new ClientGo())->giveawaysStock($param['stock_code'], $orderNo, $param['market_type']);
if (!$bool) {
return $this->toData('1', '给交易推送数据异常', []);
}
}
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('0', '系统繁忙', [$exception->getMessage()]);
}
}
}

175
app/admin/service/setting/HqService.php

@ -0,0 +1,175 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\admin\validate\setting\HqValidate;
use app\model\ContractMarketModel;
use think\exception\ValidateException;
class HqService extends AdminBaseService
{
public function index()
{
try {
$list = ContractMarketModel::where('type', 0)->order('id', 'desc')->select();
$rows = [];
if(!$list->isEmpty()){
$rows = $list->toArray();
}
return $this->toData('0','SUCCSS',['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 新增
public function add($param)
{
try {
// 参数校验
validate(HqValidate::class)->scene('add')->check($param);
// 已存在未执行的 不能再插入
$count = ContractMarketModel::where('trade_name', $param['trade_name'])
->where('is_get',1)
->where('type', 0)
->count();
if($count > 0){
return $this->toData('1','已存在未执行');
}
//判断
$diff = strtotime($param['end_time']) - strtotime($param['begin_time']);
if($diff > 600 || $diff <=0){
return $this->toData('1','时间无效-结束时间必须在开始时间十分钟以内');
}
// 不能有交叉时间
$map1 = [
['trade_name', '=',$param['trade_name']],
['begin_time','between', [$param['begin_time'], $param['end_time']]]
];
$map2 = [
['trade_name', '=',$param['trade_name']],
['end_time','between', [$param['begin_time'], $param['end_time']]]
];
$count = ContractMarketModel::whereOr([$map1,$map2])
->count();
if($count > 0){
return $this->toData('1','时间无效-时间不能有交叉');
}
$market = new ContractMarketModel;
$market->trade_name = $param['trade_name'];
$market->begin_time = $param['begin_time'];
$market->end_time = $param['end_time'];
$market->max_price = $param['max_price'];
$market->step = $param['step'];
$market->type = 0;
$market->save();
// 写入redis
$this->initContractHqData();
return $this->toData('0','SUCCESS');
}catch (ValidateException $validateException){
return $this->toData('1', $validateException->getMessage(), []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 编辑
public function edit($param)
{
try {
// 参数校验
validate(HqValidate::class)->scene('edit')->check($param);
// 已存在未执行的 不能再插入
$count = ContractMarketModel::where('trade_name', $param['trade_name'])
->where('id', '<>', $param['id'])
->where('is_get',1)
->where('type', 0)
->count();
if($count > 0){
return $this->toData('1','已存在未执行');
}
// 目标
$market = ContractMarketModel::where('id', $param['id'])->where('type', 0)->find();
if(empty($market)){
return $this->toData('1','目标不存在');
}
//判断
$diff = strtotime($param['end_time']) - strtotime($param['begin_time']);
if($diff > 600 || $diff <=0){
return $this->toData('1','时间无效');
}
// 不能有交叉时间
$map1 = [
['trade_name', '=',$param['trade_name']],
['id', '<>',$param['id']],
['begin_time','between', [$param['begin_time'], $param['end_time']]]
];
$map2 = [
['trade_name', '=',$param['trade_name']],
['id', '<>',$param['id']],
['end_time','between', [$param['begin_time'], $param['end_time']]]
];
$count = ContractMarketModel::whereOr([$map1,$map2])
->count();
if($count > 0){
return $this->toData('1','时间无效');
}
$market->trade_name = $param['trade_name'];
$market->begin_time = $param['begin_time'];
$market->end_time = $param['end_time'];
$market->max_price = $param['max_price'];
$market->step = $param['step'];
$market->save();
// redis
$this->initContractHqData();
return $this->toData('0','SUCCESS');
}catch (ValidateException $validateException){
return $this->toData('1', $validateException->getMessage(), []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage(),$exception->getTrace()]);
}
}
// 删除
public function del($param)
{
try {
// 参数校验
validate(HqValidate::class)->scene('del')->check($param);
// 目标
$market = ContractMarketModel::where('id', $param['id'])->find();
if(empty($market)){
return $this->toData('1','目标不存在');
}
$market->delete();
$this->initContractHqData();
return $this->toData('0','SUCCESS');
}catch (ValidateException $validateException){
return $this->toData('12', $validateException->getMessage(), []);
}catch (\Exception $exception){
return $this->toData('11', '系统繁忙', [$exception->getMessage()]);
}
}
}

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

File diff suppressed because it is too large

123
app/admin/service/setting/LanguageService.php

@ -0,0 +1,123 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\model\LanguageSettingModel;
class LanguageService extends AdminBaseService
{
public function index()
{
try {
$list = LanguageSettingModel::order('id', 'desc')->select();
$rows = [];
if(!$list->isEmpty()){
$rows = $list->toArray();
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
public function add($param)
{
try {
if(empty($param['language_name']) || !is_string($param['language_name']) || strlen($param['language_name']) > 20){
return $this->toData('1','参错错误');
}
if(empty($param['language_code']) || !is_string($param['language_code']) || strlen($param['language_code']) > 20){
return $this->toData('1','参错错误');
}
if(empty($param['china_name']) || !is_string($param['china_name']) || strlen($param['china_name']) > 20){
return $this->toData('1','参错错误');
}
$count = LanguageSettingModel::where('language_code', $param['language_code'])->count();
if($count > 0){
return $this->toData('1','语言代码已经存在');
}
$lang = new LanguageSettingModel;
$lang->language_name = $param['language_name'];
$lang->language_code = $param['language_code'];
$lang->china_name = $param['china_name'];
$lang->save();
return $this->toData('0', 'SUCCESS', []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function edit($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1','参错错误1');
}
$lang = LanguageSettingModel::where('id', $param['id'])->find();
if(empty($lang)){
return $this->toData('1','目标不存在');
}
if(empty($param['language_name']) || !is_string($param['language_name']) || strlen($param['language_name']) > 20){
return $this->toData('1','参错错误2');
}
if(empty($param['language_code']) || !is_string($param['language_code']) || strlen($param['language_code']) > 20){
return $this->toData('1','参错错误3');
}
if(empty($param['china_name']) || !is_string($param['china_name']) || strlen($param['china_name']) > 20){
return $this->toData('1','参错错误4');
}
$count = LanguageSettingModel::where('language_code', $param['language_code'])
->where('id', '<>', $param['id'])
->count();
if($count > 0){
return $this->toData('1','语言代码已经存在');
}
$lang->language_name = $param['language_name'];
$lang->language_code = $param['language_code'];
$lang->china_name = $param['china_name'];
$lang->save();
return $this->toData('0', 'SUCCESS', []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
public function del($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1','参错错误');
}
$lang = LanguageSettingModel::where('id', $param['id'])->find();
if(empty($lang)){
return $this->toData('1','目标不存在');
}
$lang->delete();
return $this->toData('0','SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
public function getNameList()
{
try {
$list = LanguageSettingModel::order('id', 'desc')->column('language_name', 'id');
return $this->toData('0', 'SUCCESS', ['list' => $list]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
}

161
app/admin/service/setting/MarketService.php

@ -0,0 +1,161 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\admin\validate\setting\MarketValidate;
use app\model\ContractMarketModel;
use think\exception\ValidateException;
class MarketService extends AdminBaseService
{
public function index()
{
try {
$list = ContractMarketModel::where('type', 1)
->order('id', 'desc')
->select();
$rows = [];
if(!$list->isEmpty()){
foreach ($list as $item){
if(empty($rows[$item['trade_name']])){
$rows[$item['trade_name']] = [
'trade_name' => $item['trade_name'],
'begin_time' => $item['begin_time'],
'end_time' => $item['end_time'],
'max_price' => $item['max_price'],
'step' => $item['step'],
];
}
}
}
$rows = array_values($rows);
return $this->toData('0','SUCCSS',['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
// 详情
public function detail($param)
{
try {
if(empty($param['trade_name']) || !is_string($param['trade_name'])){
return $this->toData('1', '参数错误');
}
$list = ContractMarketModel::where('type', 1)
->where('trade_name', $param['trade_name'])
->order('id', 'desc')->select();
$rows = [];
if(!$list->isEmpty()){
foreach ($list as $item){
$rows[] = [
'id' => $item['id'],
'trade_name' => $item['trade_name'],
'end_time' => $item['end_time'],
'begin_time' => $item['begin_time'],
'max_price' => $item['max_price'],
'step' => $item['step'],
];
}
}
return $this->toData('0','SUCCSS',['list' => $rows]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 新增
public function add($param)
{
try {
// 参数校验
validate(MarketValidate::class)->scene('add')->check($param);
// 必须大于当前时间
if(strtotime($param['end_time']) - time() <= 0){
return $this->toData('1','时间无效');
}
if((strtotime($param['begin_time']) - time()) <= 0 || (strtotime($param['end_time']) - strtotime($param['begin_time'])) <= 0){
return $this->toData('1','开始时间无效');
}
$market = new ContractMarketModel;
$market->trade_name = $param['trade_name'];
$market->begin_time = $param['begin_time'];
$market->end_time = $param['end_time'];
$market->max_price = $param['max_price'];
$market->type = 1;
$market->save();
return $this->toData('0','SUCCESS');
}catch (ValidateException $validateException){
return $this->toData('1', $validateException->getMessage(), []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 编辑
public function edit($param)
{
try {
// 参数校验
validate(MarketValidate::class)->scene('edit')->check($param);
// 目标
$market = ContractMarketModel::where('id', $param['id'])->where('type', 1)->find();
if(empty($market)){
return $this->toData('1','目标不存在');
}
// 必须大于当前时间
if(strtotime($param['end_time']) - time() <= 0){
return $this->toData('1','时间无效');
}
if((strtotime($param['begin_time']) - time()) <= 0 || (strtotime($param['end_time']) - strtotime($param['begin_time'])) <= 0){
return $this->toData('1','开始时间无效');
}
$market->trade_name = $param['trade_name'];
$market->begin_time = $param['begin_time'];
$market->end_time = $param['end_time'];
$market->max_price = $param['max_price'];
$market->save();
return $this->toData('0','SUCCESS');
}catch (ValidateException $validateException){
return $this->toData('1', $validateException->getMessage(), []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
// 删除
public function del($param)
{
try {
// 参数校验
validate(MarketValidate::class)->scene('del')->check($param);
// 目标
$market = ContractMarketModel::where('id', $param['id'])->where('type',1)->find();
if(empty($market)){
return $this->toData('1','目标不存在');
}
$market->delete();
return $this->toData('0','SUCCESS');
}catch (ValidateException $validateException){
return $this->toData('1', $validateException->getMessage(), []);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
}

327
app/admin/service/setting/OptionInService.php

@ -0,0 +1,327 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\admin\validate\setting\StockValidate;
use app\model\StockOptionInrListModel;
use think\exception\ValidateException;
use PHPMailer\PHPMailer\Exception;
// 印度期权
class OptionInService extends AdminBaseService
{
public function index($param)
{
try {
validate(StockValidate::class)->scene('in_option_index')->check($param);
$stockCode = $param['stock_code'] ?? '';
$where = [];
if ($stockCode) {
$where[] = ['stock_code', '=', $stockCode];
}
$list = StockOptionInrListModel::where($where)->page($param['page'], $param['limit'])->append(['tape_text', 'status_text'])->order('id', 'desc')->select();
$total = StockOptionInrListModel::order('id', 'desc')->where($where)->count();
$rows = [];
if (!$list->isEmpty()) {
$rows = $list->toArray();
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => $total, 'extend' => [
'tape_list' => StockOptionInrListModel::$tapeListText,
'status_list' => StockOptionInrListModel::$statusList
]]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
return $this->toData('1', $message);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
public function add($param)
{
try {
validate(StockValidate::class)->scene('in_option_add')->check($param);
$info = '';
if (isset($param['info']) && is_string($param['info'])) {
$info = $param['info'];
}
// 判断股票交易所
$tape = '0';
if (isset($param['tape']) && in_array($param['tape'], array_keys(StockOptionInrListModel::$tapeList))) {
$tape = $param['tape'];
}
// 判断股票代码是否已经存在
$count = StockOptionInrListModel::where('stock_code', $param['stock_code'])->count();
if ($count > 0) {
return $this->toData('1', '股票代码已经存在');
}
// 新增数据
$stockList = new StockOptionInrListModel;
$stockList->stock_name = $param['stock_name'];
$stockList->stock_code = $param['stock_code'];
$stockList->status = $param['status'];
$stockList->rate = $param['rate'] ?? 0;
$stockList->keep_decimal = $param['keep_decimal'] ?? 4;
$stockList->forced_closure = $param['forced_closure'] ?? 30;
$stockList->up_limit = $param['up_limit'] ?? 30;
$stockList->down_limit = $param['down_limit'] ?? 30;
$stockList->info = $info;
$stockList->tape = $tape;
$stockList->create_time = date('Y-m-d H:i:s');
$stockList->update_time = date('Y-m-d H:i:s');
$stockList->save();
// 新增缓存
$list_key = "IN:OPTION:LIST:" . $param['stock_code'];
$redis = $this->getRedis();
$redis->del($list_key);
$redis->hMset($list_key, [
'stock_name' => $param['stock_name'],
'stock_code' => $param['stock_code'],
'status' => $param['status'],
'keep_decimal' => $param['keep_decimal'] ?? 4,
'forced_closure' => $param['forced_closure'] ?? 30,
'up_limit' => $param['up_limit'] ?? 30,
'down_limit' => $param['down_limit'] ?? 30,
'rate' => $param['rate'] ?? 0,
'info' => $info,
'tape' => $tape,
]);
// 给行情推送
// $bool = $this->sendDecimalToGo('Indonesia', $stockList->stock_code, $stockList->keep_decimal);
// $bool = $this->sendNewStockToGo('India', $stockList->stock_code, $stockList->stock_name, StockOptionInrListModel::$tapeList[$tape]);
// if (!$bool) {
// return $this->toData('1', '数据设置成功 但给行情推送数据异常', []);
// }
return $this->toData('0', 'SUCCESS', []);
} catch (ValidateException $validateException) {
$message = $validateException->getError();
return $this->toData('1', $message);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
public function edit($param)
{
try {
validate(StockValidate::class)->scene('in_option_edit')->check($param);
$stockList = StockOptionInrListModel::where('id', $param['id'])->find();
if (empty($stockList)) {
return $this->toData('1', '目标不存在', []);
}
$info = '';
if (isset($param['info']) && is_string($param['info'])) {
$info = $param['info'];
}
// 判断股票交易所
$tape = '0';
if (isset($param['tape']) && in_array($param['tape'], array_keys(StockOptionInrListModel::$tapeList))) {
$tape = $param['tape'];
}
// 判断股票代码是否已经存在
$count = StockOptionInrListModel::where('stock_code', $param['stock_code'])->where('id', '<>', $param['id'])->count();
if ($count > 0) {
return $this->toData('1', '股票代码已经存在');
}
// 修改数据
$stockList->stock_name = $param['stock_name'];
$stockList->stock_code = $param['stock_code'];
$stockList->status = $param['status'];
$stockList->rate = $param['rate'] ?? 0;
$stockList->keep_decimal = $param['keep_decimal'] ?? 4;
$stockList->forced_closure = $param['forced_closure'] ?? 30;
$stockList->up_limit = $param['up_limit'] ?? 30;
$stockList->down_limit = $param['down_limit'] ?? 30;
$stockList->info = $info;
$stockList->tape = $tape;
$stockList->update_time = date('Y-m-d H:i:s');
$stockList->save();
// 新增缓存
$list_key = "IN:OPTION:LIST:" . $param['stock_code'];
$redis = $this->getRedis();
$redis->del($list_key);
$redis->hMset($list_key, [
'stock_name' => $param['stock_name'],
'stock_code' => $param['stock_code'],
'status' => $param['status'],
'keep_decimal' => $param['keep_decimal'] ?? 4,
'forced_closure' => $param['forced_closure'] ?? 30,
'up_limit' => $param['up_limit'] ?? 30,
'down_limit' => $param['down_limit'] ?? 30,
'rate' => $param['rate'] ?? 0,
'info' => $info,
'tape' => $tape,
]);
// 给行情推送
// $bool = $this->sendNewStockToGo('India', $stockList->stock_code, $stockList->stock_name, StockOptionInrListModel::$tapeList[$tape]);
//
// if (!$bool) {
// return $this->toData('1', '数据设置成功 但给行情推送数据异常', []);
// }
return $this->toData('0', 'SUCCESS', []);
} catch (ValidateException $validateException) {
$message = $validateException->getError();
return $this->toData('1', $message);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
// 列表
public function getTradeNameList()
{
try {
$list = StockOptionInrListModel::where('status', 1)->order('id', 'desc')->column('stock_name', 'id');
return $this->toData('0', 'SUCCESS', ['list' => $list]);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
public function refresh()
{
try {
$ch = curl_init();
$url = env('OPTION_REFRESH.OPTION_REFRESH_IN_URL');
curl_setopt($ch, CURLOPT_URL, $url); // Set the URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response as a string
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow any redirects
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // This should be set to true in production, disables SSL certificate verification (only for testing)
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
$data = json_decode($response, true);
if (empty($data) || empty($data['data']) || empty($data['code']) || (!empty($data['code']) && $data['code'] != 200)) {
return;
}
$now = date('Y-m-d H:i:s'); // 订单时间
$insertArr = [];
$responseCodeArr = array_column($data['data'], 'Code');
$dataCodeArr = StockOptionInrListModel::column('stock_code');
$result = array_diff($responseCodeArr, $dataCodeArr);
foreach ($data['data'] as $v) {
if (in_array($v['Code'], $result)) {
$insertArr[] = [
'stock_name' => $v['Code'],
'stock_code' => $v['Code'],
'status' => 1,
'tape' => StockOptionInrListModel::$tapeList[$v['Exchange']] ?? 1,
'keep_decimal' => 4,
'create_time' => $now,
'update_time' => $now,
'rate' => 30,
'forced_closure' => 30,
'up_limit' => 30,
'down_limit' => 30
];
}
}
$StockOptionInrListModel = new StockOptionInrListModel();
$StockOptionInrListModel::insertAll($insertArr);
$redis = $this->getRedis();
foreach ($insertArr as $cacheV) {
$list_key = "IN:OPTION:LIST:" . $cacheV['stock_code'];
$redis->del($list_key);
$redis->hMset($list_key, [
'stock_name' => $cacheV['stock_name'],
'stock_code' => $cacheV['stock_code'],
'status' => $cacheV['status'],
'keep_decimal' => $cacheV['keep_decimal'],
'forced_closure' => $cacheV['forced_closure'],
'up_limit' => $cacheV['up_limit'],
'down_limit' => $cacheV['down_limit'],
'rate' => $cacheV['rate'],
'info' => '',
'tape' => $cacheV['tape'],
]);
}
} catch (\Exception $exception) {
}
}
public function batchEdit($param)
{
try {
$rate = $param['rate'];
$keep_decimal = $param['keep_decimal'];
$forced_closure = $param['forced_closure'];
$status = $param['status'];
$updateArr = ['rate' => $rate, 'keep_decimal' => $keep_decimal, 'forced_closure' => $forced_closure, 'status' => $status, 'update_time' => date('Y-m-d H:i:s')];
StockOptionInrListModel::where(1, '=', 1)->update($updateArr);
$dataCodeArr = StockOptionInrListModel::select()->toArray();
$redis = $this->getRedis();
foreach ($dataCodeArr as $cacheV) {
$list_key = "IN:OPTION:LIST:" . $cacheV['stock_code'];
$redis->del($list_key);
$redis->hMset($list_key, [
'stock_name' => $cacheV['stock_name'],
'stock_code' => $cacheV['stock_code'],
'status' => $cacheV['status'],
'keep_decimal' => $cacheV['keep_decimal'],
'forced_closure' => $cacheV['forced_closure'],
'up_limit' => $cacheV['up_limit'],
'down_limit' => $cacheV['down_limit'],
'rate' => $cacheV['rate'],
'info' => $cacheV['info'],
'tape' => $cacheV['tape'],
]);
}
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
public function onOff($param)
{
try {
$id = $param['id'];
$stockList = StockOptionInrListModel::where('id', $param['id'])->find();
if (empty($stockList)) {
return $this->toData('1', '目标不存在', []);
}
$status = $stockList->status == 0 ? 1 : 0;
$updateArr = ['status' => $status, 'update_time' => date('Y-m-d H:i:s')];
StockOptionInrListModel::where('id', $id)->update($updateArr);
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
}

154
app/admin/service/setting/PaymentService.php

@ -0,0 +1,154 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\admin\validate\setting\PaymentValidate;
use app\admin\validate\setting\StockValidate;
use app\model\PaymentListModel;
use app\model\StockListModel;
use PHPMailer\PHPMailer\Exception;
use think\exception\ValidateException;
use think\facade\Validate;
class PaymentService extends AdminBaseService
{
public function index($param)
{
try {
validate(PaymentValidate::class)->scene('payment_index')->check($param);
$list = PaymentListModel::order('id', 'desc')->page($param['page'], $param['limit'])->select();
$total = PaymentListModel::order('id', 'desc')->count();
$rows = [];
if (!$list->isEmpty()) {
$rows = $list->toArray();
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => $total, 'extend' => ['type_list' => PaymentListModel::TPYE_LIST]]);
} catch (ValidateException $validateException) {
// 参数校验失败
$message = $validateException->getError();
return $this->toData('1', $message);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
public function add($param)
{
try {
validate(PaymentValidate::class)->scene('payment_add')->check($param);
// 新增数据
$payment = new PaymentListModel();
$payment->country = $param['country'];
$payment->channel = $param['channel'];
$payment->pay_type = $param['pay_type'];
$payment->service_rate = $param['service_rate'];
$payment->type = $param['type'] ?? 1;
$payment->status = $param['status'];
$payment->channel_type = $param['channel_type'];
// $payment->exchange_rate = $param['exchange_rate'];
$payment->is_recharge = $param['is_recharge'];
$payment->is_withdrawal = $param['is_withdrawal'];
$payment->is_online = $param['is_online'];
if (isset($param['bank_name'])) {
$payment->bank_name = $param['bank_name'];
}
if (isset($param['bank_branch'])) {
$payment->bank_branch = $param['bank_branch'];
}
if (isset($param['bank_user'])) {
$payment->bank_user = $param['bank_user'];
}
if (isset($param['bank_account'])) {
$payment->bank_account = $param['bank_account'];
}
if (isset($param['wallet_address'])) {
$payment->wallet_address = $param['wallet_address'];
}
if (isset($param['unit'])) {
$payment->unit = $param['unit'];
}
if (isset($param['account_type'])) {
$payment->account_type = $param['account_type'];
}
if (isset($param['ifsc'])) {
$payment->ifsc = $param['ifsc'];
}
if (isset($param['extra_name'])) {
$payment->extra_name = $param['extra_name'];
}
if (isset($param['extra_list'])) {
$payment->extra_list = $param['extra_list'];
}
$payment->save();
return $this->toData('0', 'SUCCESS', []);
} catch (ValidateException $validateException) {
$message = $validateException->getError();
return $this->toData('1', $message);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function edit($param)
{
try {
validate(PaymentValidate::class)->scene('payment_edit')->check($param);
$payment_info = PaymentListModel::where('id', $param['id'])->find();
if (empty($payment_info)) {
return $this->toData('1', '目标不存在', []);
}
$param['type'] = $param['type'] ?? 1;
PaymentListModel::where('id', $param['id'])->update($param);
return $this->toData('0', 'SUCCESS', []);
} catch (ValidateException $validateException) {
$message = $validateException->getError();
return $this->toData('1', $message);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function info($param)
{
try {
validate(PaymentValidate::class)->scene('payment_info')->check($param);
$payment_info = PaymentListModel::where('id', $param['id'])->find();
if (empty($payment_info)) {
return $this->toData('1', '目标不存在', []);
}
return $this->toData('0', 'SUCCESS', $payment_info->toArray());
} catch (ValidateException $validateException) {
$message = $validateException->getError();
return $this->toData('1', $message);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
public function del($param)
{
try {
validate(PaymentValidate::class)->scene('payment_info')->check($param);
$payment_info = PaymentListModel::where('id', $param['id'])->find();
if (empty($payment_info)) {
return $this->toData('1', '目标不存在', []);
}
PaymentListModel::where('id', $param['id'])->delete();
return $this->toData('0', 'SUCCESS', []);
} catch (ValidateException $validateException) {
$message = $validateException->getError();
return $this->toData('1', $message);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
}

690
app/admin/service/setting/PreFundStockService.php

@ -0,0 +1,690 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\model\PreFundStockModel;
use app\model\HistoryFundStockModel;
use app\model\PreFundStockReferModel;
use app\model\UserFundPreStockOrderModel;
use app\model\UserStockFundInterestReceiptModel;
use app\model\UserStockFundLogModel;
use app\model\UserStockFundModel;
use think\facade\Db;
use think\facade\Log;
use DatePeriod;
use DateTime;
use DateInterval;
class PreFundStockService extends AdminBaseService
{
// 列表
public function index($param)
{
try {
if (empty($param['page']) || !is_numeric($param['page']) || empty($param['limit']) || !is_numeric($param['limit'])) {
return $this->toData('1', '分页参数错误');
}
$where = [];
// 未删除
$where[] = [
'is_delete', '=', PreFundStockModel::IS_DELETE_NO
];
// 基金号
if (!empty($param['stock_code']) && is_string($param['stock_code'])) {
$where[] = [
'stock_code', '=', $param['stock_code']
];
}
$query = PreFundStockModel::where($where)->withJoin(['history' => ['stock_code', 'start_date', 'end_date', 'start_point', 'end_point']])->order('id', 'desc');
$totalQuery = PreFundStockModel::where($where)->order('id', 'desc');
if (!empty($param['open_status']) && in_array($param['open_status'], PreFundStockModel::$openStatusList)) {
$query = $query->where('open_status', $param['open_status']);
$totalQuery = $totalQuery->where('open_status', $param['open_status']);
}
$list = $query->append(['stock_type_text', 'open_status_text'])->order('id', 'desc')->page($param['page'], $param['limit'])->select();
$total = $totalQuery->order('id', 'desc')->count();
$rows = [];
if (!$list->isEmpty()) {
$rows = $list->toArray();
foreach ($rows as $key => $item) {
$rows[$key]['product_file'] = json_decode($item['product_file'], true);
$rows[$key]['current_manager'] = json_decode($item['current_manager'], true);
}
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => $total, 'extend' => [
'open_status_list' => PreFundStockModel::$openStatusList,
'stock_type_list' => PreFundStockModel::$stockTypeList,
'interest_type_list' => PreFundStockModel::$interestTypeList,
'cycle_type_list' => PreFundStockModel::$cycleTypeList,
'symbol' => 'USD'
]]);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 历史走势
public function history($param)
{
try {
if (empty($param['stock_code'])) {
return $this->toData('1', '基本代码 无效');
}
$history = HistoryFundStockModel::where('stock_code', $param['stock_code'])->value('history_info');
$history = json_decode($history, true);
return $this->toData('0', 'SUCCESS', ['history_info' => $history]);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 新增
public function add($param)
{
try {
// 基金代码
if (empty($param['stock_code']) || !is_string($param['stock_code'])) {
return $this->toData('1', '基金代码 无效');
}
// 基金名称
if (empty($param['stock_name']) || !is_string($param['stock_name'])) {
return $this->toData('1', '基金名称 无效');
}
// 基金类型
if (empty($param['stock_type']) || !in_array($param['stock_type'], array_keys(PreFundStockModel::$stockTypeList))) {
return $this->toData('1', '基金类型 无效');
}
// 返利类型
if (empty($param['interest_type']) || !in_array($param['interest_type'], array_keys(PreFundStockModel::$interestTypeList))) {
return $this->toData('1', '返利类型 无效');
}
// 周期单位
if (empty($param['cycle_type']) || !in_array($param['cycle_type'], array_keys(PreFundStockModel::$cycleTypeList))) {
return $this->toData('1', '返利类型 无效');
}
// 收益率 两位小数
if (empty($param['rate']) || !is_numeric($param['rate']) || $param['rate'] <= 0) {
return $this->toData('1', '基金收益率 无效');
}
// 基金周期
if (empty($param['cycle']) || !is_numeric($param['cycle']) || $param['cycle'] <= 0) {
return $this->toData('1', '基金周期 无效');
}
// 最低申购价格
if (empty($param['min_price']) || !is_numeric($param['min_price']) || $param['min_price'] <= 0) {
return $this->toData('1', '最低申购金额 无效');
}
// 开始认购时间
if (empty($param['start_time']) || !is_string($param['start_time'])) {
return $this->toData('1', '开始认购时间 无效');
}
// 认购结束时间
if (empty($param['end_time']) || !is_string($param['end_time'])) {
return $this->toData('1', '认购结束时间 无效');
}
// 基金logo
if (empty($param['logo']) || !is_string($param['logo'])) {
return $this->toData('1', '基金logo 无效');
}
// 基金标签
$tag = "";
if (!empty($param['tag']) && is_string($param['tag'])) {
$tag = $param['tag'];
}
// 认购结束时间要大于 认购开始时间
if (strtotime($param['end_time']) <= strtotime($param['start_time'])) {
return $this->toData('1', ' 认购结束时间 晚于 认购开始时间');
}
// 1.0 判断基金号是否已经存在
$preStock = PreFundStockModel::where('stock_code', $param['stock_code'])->find();
if (!empty($preStock)) {
return $this->toData('1', '基金号已经存在');
}
// 历史走势 起始日期
if (empty($param['start_date']) || !is_string($param['start_date'])) {
return $this->toData('1', '历史走势 起始日期 无效');
}
// 历史走势 结束日期
if (empty($param['end_date']) || !is_string($param['end_date'])) {
return $this->toData('1', '历史走势 结束日期 无效');
}
if (strtotime($param['end_date']) <= strtotime($param['start_date']) || strtotime($param['end_date']) - time() > 0) {
return $this->toData('1', '历史走势-开始日期 要大于 历史走势-结束日期 ; 历史走势-结束日期 要小于 当前时间');
}
// 历史走势 起始值
if (empty($param['start_point']) || !is_numeric($param['start_point'])) {
return $this->toData('1', '历史走势 起始值 无效');
}
// 历史走势 结束值
if (empty($param['end_point']) || !is_numeric($param['end_point'])) {
return $this->toData('1', '历史走势 结束值 无效');
}
Db::startTrans();
// 新增数据
$preFundStock = new PreFundStockModel();
$preFundStock->stock_code = $param['stock_code'];
$preFundStock->stock_name = $param['stock_name'];
$preFundStock->stock_type = $param['stock_type'];
$preFundStock->show_interest = $param['show_interest'] ?? 66;
$preFundStock->tape = $param['tape'] ?? 1;
$preFundStock->status = $param['status'] ?? 0;
$preFundStock->min_price = $param['min_price'];
$preFundStock->rate = $param['rate'];
$preFundStock->cycle = $param['cycle'];
$preFundStock->start_time = $param['start_time'];
$preFundStock->end_time = $param['end_time'];
$preFundStock->sort = $param['sort'] ?? 0;
$preFundStock->interest_type = $param['interest_type'];
$preFundStock->cycle_type = $param['cycle_type'];
$preFundStock->phase_count = $param['phase_count'] ?? 1;
$preFundStock->is_delete = PreFundStockModel::IS_DELETE_NO;
$preFundStock->open_status = PreFundStockModel::OPEN_STATUS_NO;
$preFundStock->create_time = date('Y-m-d H:i:s');
$preFundStock->update_time = date('Y-m-d H:i:s');
$preFundStock->stock_info = $param['stock_info'] ?? "";
$preFundStock->logo = $param['logo'];
$preFundStock->tag = $tag;
$preFundStock->remark = $param['remark'];
$preFundStock->product_file = json_encode($param['product_file']);
$preFundStock->current_manager = json_encode($param['current_manager']);
$preFundStockBool = $preFundStock->save();
if (!$preFundStockBool) {
Db::rollback();
return $this->toData('1', '新增基金失败');
}
// 基金历史走势
$HistoryStock = new HistoryFundStockModel();
$HistoryStock->stock_code = $param['stock_code'];
$HistoryStock->start_date = $param['start_date'];
$HistoryStock->end_date = $param['end_date'];
$HistoryStock->start_point = $param['start_point'];
$HistoryStock->end_point = $param['end_point'];
$HistoryStock->history_info = $this->autoHistory($param['start_date'], $param['end_date'], $param['start_point'], $param['end_point']);
$HistoryStockBool = $HistoryStock->save();
if (!$HistoryStockBool) {
Db::rollback();
return $this->toData('1', '新增基金走势失败');
}
Db::commit();
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
Db::rollback();
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 编辑
public function edit($param)
{
try {
if (empty($param['id']) || !is_numeric($param['id'])) {
return $this->toData('1', '主键 无效');
}
$preFundStock = PreFundStockModel::where('id', $param['id'])->where('is_delete', PreFundStockModel::IS_DELETE_NO)->find();
if (empty($preFundStock)) {
return $this->toData('1', '主键 无效');
}
// 已中签或者已上市不支持修改
// if ($preFundStock->open_status == PreFundStockModel::OPEN_STATUS_HAD) {
// return $this->toData('1', '已上市 不支持修改');
// }
// 基金类型
if (empty($param['stock_type']) || !in_array($param['stock_type'], array_keys(PreFundStockModel::$stockTypeList))) {
return $this->toData('1', '基金类型 无效');
}
if ($preFundStock->had_get_price == 0) {
// 基金代码
if (empty($param['stock_code']) || !is_string($param['stock_code'])) {
return $this->toData('1', '基金代码 无效');
}
// 基金名称
if (empty($param['stock_name']) || !is_string($param['stock_name'])) {
return $this->toData('1', '基金代码 无效');
}
// 单股价格
if (empty($param['min_price']) || !is_numeric($param['min_price']) || $param['min_price'] <= 0) {
return $this->toData('1', '最低申购金额 无效');
}
// 开始认购时间
if (empty($param['start_time']) || !is_string($param['start_time'])) {
return $this->toData('1', '开始认购时间 无效');
}
// 收益率 两位小数
if (empty($param['rate']) || !is_numeric($param['rate']) || $param['rate'] <= 0) {
return $this->toData('1', '基金收益率 无效');
}
// 基金周期
if (empty($param['cycle']) || !is_numeric($param['cycle']) || $param['cycle'] <= 0) {
return $this->toData('1', '基金周期 无效');
}
// 返利类型
if (empty($param['interest_type']) || !in_array($param['interest_type'], array_keys(PreFundStockModel::$interestTypeList))) {
return $this->toData('1', '返利类型 无效');
}
// 周期单位
if (empty($param['cycle_type']) || !in_array($param['cycle_type'], array_keys(PreFundStockModel::$cycleTypeList))) {
return $this->toData('1', '返利类型 无效');
}
}
// 认购结束时间
if (empty($param['end_time']) || !is_string($param['end_time'])) {
return $this->toData('1', '认购结束时间 无效');
}
// 基金logo
if (empty($param['logo']) || !is_string($param['logo'])) {
return $this->toData('1', '基金logo 无效');
}
// 基金标签
$tag = "";
if (!empty($param['tag']) && is_string($param['tag'])) {
$tag = $param['tag'];
}
// 历史走势 起始日期
if (empty($param['start_date']) || !is_string($param['start_date'])) {
return $this->toData('1', '历史走势 起始日期 无效');
}
// 历史走势 结束日期
if (empty($param['end_date']) || !is_string($param['end_date'])) {
return $this->toData('1', '历史走势 结束日期 无效');
}
// 历史走势 起始值
if (empty($param['start_point']) || !is_numeric($param['start_point'])) {
return $this->toData('1', '历史走势 起始值 无效');
}
// 历史走势 结束值
if (empty($param['end_point']) || !is_numeric($param['end_point'])) {
return $this->toData('1', '历史走势 结束值 无效');
}
// 上市时间 要大于 认购结束时间 认购结束时间要大于 认购开始时间
if (strtotime($param['end_time']) <= strtotime($param['start_time'])) {
return $this->toData('1', '认购结束时间 要晚于 认购开始时间');
}
// 1.0 判断基金号是否已经存在
$preStock = PreFundStockModel::where('stock_code', $param['stock_code'])
->where('id', '<>', $param['id'])
->where('is_delete', PreFundStockModel::IS_DELETE_NO)->find();
if (!empty($preStock)) {
return $this->toData('1', '基金号已经存在');
}
Db::startTrans();
// 编辑数据
if ($preFundStock->had_get_price == 0) {
$UpdatePreFundStockArr['stock_code'] = $param['stock_code'];
$UpdatePreFundStockArr['stock_name'] = $param['stock_name'];
$UpdatePreFundStockArr['status'] = $param['status'] ?? 0;
$UpdatePreFundStockArr['min_price'] = $param['min_price'];
$UpdatePreFundStockArr['start_time'] = $param['start_time'];
$UpdatePreFundStockArr['rate'] = $param['rate'];
$UpdatePreFundStockArr['cycle'] = $param['cycle'];
$UpdatePreFundStockArr['interest_type'] = $param['interest_type'];
$UpdatePreFundStockArr['cycle_type'] = $param['cycle_type'];
$UpdatePreFundStockArr['phase_count'] = $param['phase_count'] ?? 1;
$UpdatePreFundStockArr['tape'] = $param['tape'] ?? 1;
}
$UpdatePreFundStockArr['show_interest'] = $param['show_interest'] ?? 66;
$UpdatePreFundStockArr['end_time'] = $param['end_time'];
$UpdatePreFundStockArr['is_delete'] = PreFundStockModel::IS_DELETE_NO;
$UpdatePreFundStockArr['update_time'] = date('Y-m-d H:i:s');
$UpdatePreFundStockArr['sort'] = $param['sort'] ?? 0;
$UpdatePreFundStockArr['stock_info'] = $param['stock_info'] ?? "";
$UpdatePreFundStockArr['logo'] = $param['logo'];
$UpdatePreFundStockArr['tag'] = $tag;
$UpdatePreFundStockArr['remark'] = $param['remark'];
$UpdatePreFundStockArr['product_file'] = json_encode($param['product_file']);
$UpdatePreFundStockArr['current_manager'] = json_encode($param['current_manager']);
$UpdatePreFundStockBool = PreFundStockModel::where('id', $param['id'])->update($UpdatePreFundStockArr);
if (!$UpdatePreFundStockBool) {
Db::rollback();
return $this->toData('1', '编辑基金失败');
}
// 基金历史走势
$HistoryStockArr['stock_code'] = $param['stock_code'];
$HistoryStockArr['start_date'] = $param['start_date'];
$HistoryStockArr['end_date'] = $param['end_date'];
$HistoryStockArr['start_point'] = $param['start_point'];
$HistoryStockArr['end_point'] = $param['end_point'];
$HistoryStockArr['history_info'] = $this->autoHistory($param['start_date'], $param['end_date'], $param['start_point'], $param['end_point']);
$HistoryStock = HistoryFundStockModel::where('stock_code', $param['stock_code'])->find();
if (empty($HistoryStock)) {
HistoryFundStockModel::where('stock_code', $preFundStock->stock_code)->delete();
$HistoryStockBool = HistoryFundStockModel::create($HistoryStockArr);
} else {
$HistoryStockBool = HistoryFundStockModel::where('stock_code', $param['stock_code'])->update($HistoryStockArr);
}
if (!$HistoryStockBool) {
Db::rollback();
return $this->toData('1', '编辑基金走势失败');
}
Db::commit();
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
Db::rollback();
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 上市
public function open($param)
{
try {
if (empty($param['id']) || !is_numeric($param['id'])) {
return $this->toData('1', '主键 无效');
}
// $isReal = 1;
// if (isset($param['is_real']) && is_numeric($param['is_real']) && $param['is_real'] == '2') {
// $isReal = 2;
// }
$preFundStock = PreFundStockModel::where('id', $param['id'])->where('is_delete', PreFundStockModel::IS_DELETE_NO)->find();
if (empty($preFundStock)) {
return $this->toData('1', '主键 无效');
}
// 判断是否签名
// if ($preFundStock->sign_status != PreFundStockModel::SIGN_STATUS_DONE) {
// return $this->toData('1', '还未签名');
// }
// if ($preFundStock->open_status != PreFundStockModel::OPEN_STATUS_NO) {
// return $this->toData('1', '无法操作');
// }
// 修改基金状态
$num = PreFundStockModel::where('id', $preFundStock->id)->update(['open_status' => PreFundStockModel::OPEN_STATUS_HAD,
'open_time' => date('Y-m-d H:i:s'),
'update_time' => date('Y-m-d H:i:s')]);
if ($num <= 0) {
return $this->toData('1', '基金状态修改失败-上市');
}
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
Log::error("基金上市失败 " . $exception->getMessage());
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 退市
public function close($param)
{
try {
if (empty($param['id']) || !is_numeric($param['id'])) {
return $this->toData('1', '主键 无效');
}
$preFundStock = PreFundStockModel::where('id', $param['id'])->where('is_delete', PreFundStockModel::IS_DELETE_NO)->find();
if (empty($preFundStock)) {
return $this->toData('1', '主键 无效');
}
//
if ($preFundStock->open_status != PreFundStockModel::OPEN_STATUS_HAD) {
return $this->toData('1', '上市中 无法操作');
}
// 修改基金状态
$num = PreFundStockModel::where('id', $preFundStock->id)->update(['open_status' => PreFundStockModel::OPEN_STATUS_OUT,
'close_time' => date('Y-m-d H:i:s'),
'update_time' => date('Y-m-d H:i:s')]);
if ($num <= 0) {
return $this->toData('1', '基金状态修改失败-退市');
}
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
Log::error("基金退市失败 " . $exception->getMessage());
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 删除
public function del($param)
{
try {
if (empty($param['id']) || !is_numeric($param['id'])) {
return $this->toData('1', '主键 无效');
}
$preFundStock = PreFundStockModel::where('id', $param['id'])->where('is_delete', PreFundStockModel::IS_DELETE_NO)->find();
if (empty($preFundStock)) {
return $this->toData('1', '主键 无效');
}
//
if ($preFundStock->open_status != PreFundStockModel::OPEN_STATUS_HAD) {
return $this->toData('1', '上市中 无法操作');
}
// 修改删除状态
$num = PreFundStockModel::where('id', $preFundStock->id)->update([
'is_delete' => PreFundStockModel::IS_DELETE_YES,
'update_time' => date('Y-m-d H:i:s')]);
if ($num <= 0) {
return $this->toData('1', '基金删除失败');
}
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
Log::error("基金删除失败 " . $exception->getMessage());
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
private function autoHistory($startDate, $endDate, $startPoint, $endPoint)
{
$startDateOjb = new DateTime($startDate);
$endDateOjb = new DateTime($endDate);
$endDateOjb->modify('+1 day'); //DateTime 取两个日期中间日期,不含结束日期
$period = new DatePeriod($startDateOjb, new DateInterval('P1D'), $endDateOjb);
$interval = $startDateOjb->diff($endDateOjb);
$daysCount = $interval->format('%a');
$numberArr = $this->autoNumber($startPoint, $endPoint, $daysCount);
$start = 0;
foreach ($period as $k => $date) {
$dates[$date->format("Y-m-d")] = number_format($start += $numberArr[$k], 2, '.', '');
}
return json_encode($dates);
}
private function autoNumber($startPoint, $endPoint, $count)
{
$rand = round(($endPoint - $startPoint) / $count, 2);
$randomNumbers = array();
$randomNumbers[] = $startPoint;
for ($i = 0; $i < $count - 2; $i++) {
$temp = bcmul(rand(1, 10) > 4 ? 1 : -1, (rand(1, 10) > 5 ? rand(1, 5) : rand(4, 8)) / 100, 2);
// 生成随机的增减值
$randomChange = bcmul(rand(1, 10) > 4 ? 1 : -1, rand(1, 10) > 5 ? rand(1, 10) > 3 ? $rand * 2 : $rand * 4 : $rand * 3, 2);
$randomChange = bcadd($randomChange, $temp, 2);
// 将当前值添加到数组中
$randomNumbers[] = round($randomChange, 2);
}
$end = round($endPoint - array_sum($randomNumbers), 2);
if (abs($end) > 30) {
return $this->autoNumber($startPoint, $endPoint, $count);
} else {
$randomNumbers[] = $end;
return $randomNumbers;
}
}
public function interest()
{
try {
// $interestSwitch = env();
// if (!$interestSwitch)return;
$today = date("Y-m-d");
$interestList = UserStockFundInterestReceiptModel::where("return_date", $today)->where('status', UserStockFundInterestReceiptModel::STATUS_ONE)->select();
if (count($interestList) == 0) {
trace('fund_interest count=0 基金没有需要处理的返息单-完成', 'error');
return json(["SUCCESS"]);
}
foreach ($interestList as $interestV) {
try {
// 单个股票 开始事务
Db::startTrans();
$vId = $interestV->id;
//用户基金账户加钱
$beforeAmount = UserStockFundModel::where('stock_id', 'USD')->where('user_id', $interestV->user_id)->value('usable_num');
if (empty($beforeAmount)) {
Db::rollback();
trace("基金返息失败0 返息单ID=$vId", 'error');
return json(["基金返息失败0"]);
}
$addNum = bcadd($interestV->capital, $interestV->interest, 18);//本金+利息
$addBool = UserStockFundModel::where('user_id', $interestV->user_id)->where('stock_id', 'USD')->inc('usable_num', $addNum)->update(['update_time' => date('Y-m-d H:i:s')]);
if (!$addBool) {
Db::rollback();
trace("基金返息失败1 返息单ID=$vId", 'error');
return json(["基金返息失败1"]);
}
// 新增用户基金账户流水
// 生成流水
$userStockLog = new UserStockFundLogModel();
$userStockLog->user_id = $interestV->user_id;
$userStockLog->change_type = 19;
$userStockLog->stock_id = 'USD';
$userStockLog->before_num = $beforeAmount;
$userStockLog->change_num = $addNum;
$userStockLog->order_id = $interestV->order_no;
$userStockLog->create_time = date('Y-m-d H:i:s');
$userStockLog->update_time = date('Y-m-d H:i:s');
$updateNum2 = $userStockLog->save();
if ($updateNum2 <= 0) {
Db::rollback();
trace("基金返息失败2 返息单ID=$vId", 'error');
return json(["基金返息失败2"]);
}
//修改返息单状态
$interestReceiptUpdateBool = UserStockFundInterestReceiptModel::where('id', $interestV->id)->update(['status' => UserStockFundInterestReceiptModel::STATUS_TWO, 'update_time' => date('Y-m-d H:i:s')]);
if (!$interestReceiptUpdateBool) {
Db::rollback();
trace("基金返息失败3 返息单ID=$vId", 'error');
return json(["基金返息失败3"]);
}
//修改订单状态
$order = UserFundPreStockOrderModel::where('id', $interestV->order_id)->find();
if (empty($order)) {
Db::rollback();
trace("基金返息失败4 返息单ID=$vId", 'error');
return json(["基金返息失败4"]);
}
if ($order->phase_count == $interestV->phase_time) {
$orderStatus = UserFundPreStockOrderModel::STATUS_THREE;//已结束
} else {
$orderStatus = UserFundPreStockOrderModel::STATUS_TWO;//进行中
}
$order->status = $orderStatus;
$order->save();
// 提交事务
Db::commit();
} catch (\Exception $exception) {
Db::rollback();
trace("基金返息息失败5-exception " . $exception->getMessage(), 'error');
return json(["基金返息失败5-exception"]);
}
}
trace('基金返息-完成', 'error');
return json(["SUCCESS"]);
} catch (\Exception $exception) {
trace("基金返息失败6-exception " . $exception->getMessage(), 'error');
return json([$exception->getMessage()]);
}
}
public function referStockAdd($param)
{
try {
$bool = PreFundStockReferModel::insert(['name' => $param['name'], 'year' => $param['year'], 'rate' => $param['rate']]);
if (!$bool) {
return $this->toData('1', '基金状态修改失败-退市');
}
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
public function referStockDel($param)
{
try {
$bool = PreFundStockReferModel::where('id', $param['id'])->delete();
if (!$bool) {
return $this->toData('1', '基金状态修改失败-退市');
}
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
}

112
app/admin/service/setting/ServiceService.php

@ -0,0 +1,112 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\model\ServiceSettingModel;
class ServiceService extends AdminBaseService
{
public function index()
{
try {
$rows = [];
$list = ServiceSettingModel::order('id', 'desc')->select();
if (!$list->isEmpty()) {
$rows = $list->toArray();
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows), 'extend' => ['type_list' => ServiceSettingModel::$typeList]]);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
public function add($param)
{
try {
if (empty($param['type']) || !in_array($param['type'], array_keys(ServiceSettingModel::$typeList))) {
return $this->toData('1', '类型 无效', []);
}
if (empty($param['header_photo']) || !is_string($param['header_photo'])) {
return $this->toData('1', '头像图片地址无效', []);
}
if (empty($param['server_name']) || !is_string($param['server_name'])) {
return $this->toData('1', '客服名称无效', []);
}
if (!empty($param['server_link']) && !is_string($param['server_link'])) {
return $this->toData('1', '类型内容 无效', []);
}
$service = new ServiceSettingModel;
$service->header_photo = $param['header_photo'];
$service->type = $param['type'];
$service->server_link = $param['server_link'] ?? '';
$service->server_name = $param['server_name'];
$service->save();
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
public function edit($param)
{
try {
if (empty($param['id']) || !is_numeric($param['id'])) {
return $this->toData('1', '目标不存在', []);
}
$service = ServiceSettingModel::where('id', $param['id'])->find();
if (empty($service)) {
return $this->toData('1', '目标不存在', []);
}
if (empty($param['type']) || !in_array($param['type'], array_keys(ServiceSettingModel::$typeList))) {
return $this->toData('1', '类型 无效', []);
}
if (empty($param['header_photo']) || !is_string($param['header_photo'])) {
return $this->toData('1', '头像图片地址无效', []);
}
if (empty($param['server_name']) || !is_string($param['server_name'])) {
return $this->toData('1', '客服名称无效', []);
}
if (!empty($param['server_link']) && !is_string($param['server_link'])) {
return $this->toData('1', '类型内容 无效', []);
}
$service->type = $param['type'];
$service->header_photo = $param['header_photo'];
$service->server_link = $param['server_link'] ?? '';
$service->server_name = $param['server_name'];
$service->save();
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
public function del($param)
{
try {
if (empty($param['id']) || !is_numeric($param['id'])) {
return $this->toData('1', '参错错误');
}
$lang = ServiceSettingModel::where('id', $param['id'])->find();
if (empty($lang)) {
return $this->toData('1', '目标不存在');
}
$lang->delete();
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
}

65
app/admin/service/setting/StockIndexService.php

@ -0,0 +1,65 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\model\StockIndexModel;
class StockIndexService extends AdminBaseService
{
public function index()
{
try {
$list = StockIndexModel::order('sort', 'desc')->order('id', 'desc')->select();
$rows = [];
if(!$list->isEmpty()){
$rows = $list->toArray();
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => count($rows)]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', []);
}
}
public function update($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '参数错误1', []);
}
if(!isset($param['sort']) || !is_numeric($param['sort'])){
return $this->toData('1', '参数错误2', []);
}
if(empty($param['status']) || !in_array($param['status'], [1,2])){
return $this->toData('1', '参数错误3', []);
}
$stockIndex = StockIndexModel::where('id', $param['id'])->find();
if(empty($stockIndex)){
return $this->toData('1', '目标不存在', []);
}
$stockIndex->sort = ceil($param['sort']);
$stockIndex->status = ceil($param['status']);
$stockIndex->update_time = date('Y-m-d H:i:s');
$stockIndex->save();
// 通知go
$bool = $this->sendStockIndexToGo($stockIndex->code, $stockIndex->country, $stockIndex->sort, $stockIndex->status);
if(!$bool){
return $this->toData('1', '通知行情失败 请重新设置数据', []);
}
return $this->toData('0', 'SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
}

518
app/admin/service/setting/StockMarketService.php

@ -0,0 +1,518 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\model\StockEurListModel;
use app\model\StockFurListModel;
use app\model\StockGBXListModel;
use app\model\StockHkdListModel;
use app\model\StockIdnListModel;
use app\model\StockInListModel;
use app\model\StockListModel;
use app\model\StockMarketModel;
use app\model\StockMysListModel;
use app\model\StockThaListModel;
// 股票市场
class StockMarketService extends AdminBaseService
{
public function index()
{
try {
$list = StockMarketModel::order('stock_market_type', 'asc')->select();
$rows = [];
if(!$list->isEmpty()){
$rows = $list->toArray();
}
return $this->toData('0','SUCCESS', ['total' => count($rows), 'list' => $rows, 'extent' => [
'stock_market_type_list' => StockMarketModel::STOCK_MARKET_TYPE,
'trade_day_type' => StockMarketModel::TRADE_DAY_TYPE,
]]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 新增
public function add($param)
{
try {
$stockMarketTypeArr = StockMarketModel::STOCK_MARKET_TYPE;
$tradeDayTypeArr = StockMarketModel::TRADE_DAY_TYPE;
$stockMarketTypeKeys = array_keys($stockMarketTypeArr);
$tradeDayTypeKeys = array_keys($tradeDayTypeArr);
if(empty($param['stock_market_type']) || !in_array($param['stock_market_type'], $stockMarketTypeKeys)){
return $this->toData('1', '股票市场类型无效', []);
}
// 判断是否已经存在
$stockM = StockMarketModel::where('stock_market_type', $param['stock_market_type'])->find();
if($stockM){
return $this->toData('1', '股票市场类型已经存在', []);
}
$amOpenTime = '00:00';
$amCloseTime = '00:00';
$pmOpenTime = '00:00';
$pmCloseTime = '00:00';
$num = 0;
if(isset($param['am_open_time']) && is_string($param['am_open_time'])){
$amOpenTimestamp = strtotime($param['am_open_time']);
if($amOpenTimestamp !== false && date('H:i', $amOpenTimestamp) === $param['am_open_time']){
$amOpenTime = $param['am_open_time'];
$num++;
}
}
if(isset($param['am_close_time']) && is_string($param['am_close_time'])){
$amCloseTimestamp = strtotime($param['am_close_time']);
if($amCloseTimestamp !== false && date('H:i', $amCloseTimestamp) === $param['am_close_time']){
$amCloseTime = $param['am_close_time'];
$num++;
}
}
if(isset($param['pm_open_time']) && is_string($param['pm_open_time'])){
$pmOpenTimestamp = strtotime($param['pm_open_time']);
if($pmOpenTimestamp !== false && date('H:i', $pmOpenTimestamp) === $param['pm_open_time']){
$pmOpenTime = $param['pm_open_time'];
$num++;
}
}
if(isset($param['pm_close_time']) && is_string($param['pm_close_time'])){
$pmCloseTimestamp = strtotime($param['pm_close_time']);
if($pmCloseTimestamp !== false && date('H:i', $pmCloseTimestamp) === $param['pm_close_time']){
$pmCloseTime = $param['pm_close_time'];
$num++;
}
}
if(empty($param['status']) || !in_array($param['status'], [StockMarketModel::STATUS_NO, StockMarketModel::STATUS_OFF])){
return $this->toData('1', '状态类型无效', []);
}
// 如果是开启状态 必须设置开盘时间
if($param['status'] == StockMarketModel::STATUS_NO && $num < 4){
return $this->toData('1', '需要设置开盘时间', []);
}
// 货币单位
if(empty($param['unit']) || !is_string($param['unit']) || strlen($param['unit']) > 10){
return $this->toData('1', '货币单位无效', []);
}
// 货币符号
if(empty($param['symbol']) || !is_string($param['symbol']) || strlen($param['symbol']) > 10){
return $this->toData('1', '货币符号无效', []);
}
// 兑换汇率
if(empty($param['rate']) || !is_numeric($param['rate']) || strlen($param['rate']) > 200){
return $this->toData('1', '兑换汇率无效', []);
}
// 如果是开启状态必须设置 交易日限制 如果是关闭状态
if($param['status'] == StockMarketModel::STATUS_NO){
if(empty($param['trade_day_type']) || !in_array($param['trade_day_type'], $tradeDayTypeKeys)){
return $this->toData('1', '交易日限制无效', []);
}
$tradeDayType = $param['trade_day_type'];
}else{
if(empty($param['trade_day_type']) || !in_array($param['trade_day_type'], $tradeDayTypeKeys)){
$tradeDayType = 0;
} else{
$tradeDayType = $param['trade_day_type'];
}
}
// 设置股票杠杆
$leverStatus = StockMarketModel::LEVER_STATUS_OFF;
$stockMin = 0;
$leverMin = 1;
$leverMax = 1;
if(!empty($param['lever_status']) && is_numeric($param['lever_status']) && $param['lever_status'] == StockMarketModel::LEVER_STATUS_ON){
$leverStatus = $param['lever_status'];
if(empty($param['stock_min']) || !is_numeric($param['stock_min']) || $param['stock_min'] <=0){
return $this->toData('1', '杠杆最小使用股数无效', []);
}
if(empty($param['lever_min']) || !is_numeric($param['lever_min']) || $param['lever_min'] <=0){
return $this->toData('1', '最小杠杆无效', []);
}
if(empty($param['lever_max']) || !is_numeric($param['lever_max']) || $param['lever_max'] <=0 || $param['lever_max'] < $param['lever_min']){
return $this->toData('1', '最大杠杆无效', []);
}
$stockMin = ceil($param['stock_min']);
$leverMin = ceil($param['lever_min']);
$leverMax = ceil($param['lever_max']);
}
$stockMarket = new StockMarketModel;
$stockMarket->stock_market_type = $param['stock_market_type'];
$stockMarket->status = $param['status'];
$stockMarket->symbol = $param['symbol'];
$stockMarket->unit = $param['unit'];
$stockMarket->rate = $param['rate'];
// 开盘时间
$stockMarket->am_open_time = $amOpenTime;
$stockMarket->am_close_time = $amCloseTime;
$stockMarket->pm_open_time = $pmOpenTime;
$stockMarket->pm_close_time = $pmCloseTime;
$stockMarket->trade_day_type = $tradeDayType;
$stockMarket->create_time = date('Y-m-d H:i:s');
$stockMarket->update_time = date('Y-m-d H:i:s');
$stockMarket->stock_min = $stockMin;
$stockMarket->lever_min = $leverMin;
$stockMarket->lever_max = $leverMax;
$stockMarket->lever_status = $leverStatus;
$stockMarket->save();
// 缓存
$list_key="STOCK_MARKET:LIST:" .$stockMarket->stock_market_type;
$redis = $this->getRedis();
$redis->del($list_key);
$redis->hMset($list_key, [
'id'=>$stockMarket->id,
'stock_market_type'=>$stockMarket->stock_market_type,
'trade_day_type'=>$stockMarket->trade_day_type,
'unit'=>$stockMarket->unit,
'rate'=>$stockMarket->rate,
'symbol'=>$stockMarket->symbol,
'status'=>$stockMarket->status,
'am_open_time'=>$stockMarket->am_open_time,
'am_close_time'=>$stockMarket->am_close_time,
'pm_open_time'=>$stockMarket->pm_open_time,
'pm_close_time'=>$stockMarket->pm_close_time,
'lever_status' => $leverStatus,
'stock_min' => $stockMin,
'lever_min' => $leverMin,
'lever_max' => $leverMax,
]);
return $this->toData('0','SUCCESS');
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage(),$exception->getLine()]);
}
}
public function edit($param)
{
try {
if(empty($param['id']) || !is_numeric($param['id'])){
return $this->toData('1', '主键无效', []);
}
$stockMarket = StockMarketModel::where('id', $param['id'])->find();
if(empty($stockMarket)){
return $this->toData('1', '主键无效', []);
}
$tradeDayTypeArr = StockMarketModel::TRADE_DAY_TYPE;
$tradeDayTypeKeys = array_keys($tradeDayTypeArr);
// 状态
if(empty($param['status']) || !in_array($param['status'], [StockMarketModel::STATUS_NO, StockMarketModel::STATUS_OFF])){
return $this->toData('1', '状态类型无效', []);
}
$amOpenTime = '00:00';
$amCloseTime = '00:00';
$pmOpenTime = '00:00';
$pmCloseTime = '00:00';
$num = 0;
if(isset($param['am_open_time']) && is_string($param['am_open_time'])){
$amOpenTimestamp = strtotime($param['am_open_time']);
if($amOpenTimestamp !== false && date('H:i', $amOpenTimestamp) === $param['am_open_time']){
$amOpenTime = $param['am_open_time'];
$num++;
}
}
if(isset($param['am_close_time']) && is_string($param['am_close_time'])){
$amCloseTimestamp = strtotime($param['am_close_time']);
if($amCloseTimestamp !== false && date('H:i', $amCloseTimestamp) === $param['am_close_time']){
$amCloseTime = $param['am_close_time'];
$num++;
}
}
if(isset($param['pm_open_time']) && is_string($param['pm_open_time'])){
$pmOpenTimestamp = strtotime($param['pm_open_time']);
if($pmOpenTimestamp !== false && date('H:i', $pmOpenTimestamp) === $param['pm_open_time']){
$pmOpenTime = $param['pm_open_time'];
$num++;
}
}
if(isset($param['pm_close_time']) && is_string($param['pm_close_time'])){
$pmCloseTimestamp = strtotime($param['pm_close_time']);
if($pmCloseTimestamp !== false && date('H:i', $pmCloseTimestamp) === $param['pm_close_time']){
$pmCloseTime = $param['pm_close_time'];
$num++;
}
}
// 如果是开启状态 必须设置开盘时间
if($param['status'] == StockMarketModel::STATUS_NO && $num < 4){
return $this->toData('1', '需要设置开盘时间', []);
}
// 货币单位
if(empty($param['unit']) || !is_string($param['unit']) || strlen($param['unit']) > 10){
return $this->toData('1', '货币单位无效', []);
}
// 货币符号
if(empty($param['symbol']) || !is_string($param['symbol']) || strlen($param['symbol']) > 10){
return $this->toData('1', '货币符号无效', []);
}
// 兑换汇率
if(empty($param['rate']) || !is_numeric($param['rate']) || strlen($param['rate']) > 200){
return $this->toData('1', '兑换汇率无效', []);
}
$tradeDayType = $stockMarket->trade_day_type;
// 只有在没有设置过的情况下可以设置 设置之后不能修改
if($tradeDayType == 0){
if($param['status'] == StockMarketModel::STATUS_NO){
// 如果是开启状态 必须设置
if(empty($param['trade_day_type']) || !in_array($param['trade_day_type'], $tradeDayTypeKeys)){
return $this->toData('1', '交易日限制无效', []);
}
$tradeDayType = $param['trade_day_type'];
}else{
// 关闭状态 可以不设置
if(!empty($param['trade_day_type']) && in_array($param['trade_day_type'], $tradeDayTypeKeys)){
$tradeDayType = $param['trade_day_type'];
} else{
$tradeDayType = 0;
}
}
}
// 设置股票杠杆
$leverStatus = StockMarketModel::LEVER_STATUS_OFF;
$stockMin = 0;
$leverMin = 1;
$leverMax = 1;
if(!empty($param['lever_status']) && is_numeric($param['lever_status']) && $param['lever_status'] == StockMarketModel::LEVER_STATUS_ON){
$leverStatus = $param['lever_status'];
if(empty($param['stock_min']) || !is_numeric($param['stock_min']) || $param['stock_min'] <=0){
return $this->toData('1', '杠杆最小使用股数无效', []);
}
if(empty($param['lever_min']) || !is_numeric($param['lever_min']) || $param['lever_min'] <=0){
return $this->toData('1', '最小杠杆无效', []);
}
if(empty($param['lever_max']) || !is_numeric($param['lever_max']) || $param['lever_max'] <=0 || $param['lever_max'] < $param['lever_min']){
return $this->toData('1', '最大杠杆无效', []);
}
}
$stockMin = ceil($param['stock_min']);
$leverMin = ceil($param['lever_min']);
$leverMax = ceil($param['lever_max']);
$stockMarket->status = $param['status'];
$stockMarket->trade_day_type = $tradeDayType;
$stockMarket->symbol = $param['symbol'];
$stockMarket->unit = $param['unit'];
$stockMarket->rate = $param['rate'];
$stockMarket->am_open_time = $amOpenTime;
$stockMarket->am_close_time = $amCloseTime;
$stockMarket->pm_open_time = $pmOpenTime;
$stockMarket->pm_close_time = $pmCloseTime;
$stockMarket->trade_day_type = $tradeDayType;
$stockMarket->update_time = date('Y-m-d H:i:s');
$stockMarket->stock_min = $stockMin;
$stockMarket->lever_min = $leverMin;
$stockMarket->lever_max = $leverMax;
$stockMarket->lever_status = $leverStatus;
$stockMarket->save();
// 缓存
$list_key="STOCK_MARKET:LIST:" .$stockMarket->stock_market_type;
$redis = $this->getRedis();
$redis->del($list_key);
$redis->hMset($list_key, [
'id'=>$stockMarket->id,
'stock_market_type'=>$stockMarket->stock_market_type,
'trade_day_type'=>$stockMarket->trade_day_type,
'status'=>$stockMarket->status,
'symbol'=>$stockMarket->symbol,
'unit'=>$stockMarket->unit,
'rate'=>$stockMarket->rate,
'am_open_time'=>$stockMarket->am_open_time,
'am_close_time'=>$stockMarket->am_close_time,
'pm_open_time'=>$stockMarket->pm_open_time,
'pm_close_time'=>$stockMarket->pm_close_time,
'lever_status' => $leverStatus,
'stock_min' => $stockMin,
'lever_min' => $leverMin,
'lever_max' => $leverMax,
]);
$arr=$redis->hGetAll($list_key);
return $this->toData('0','SUCCESS',$arr);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 股票筛选 根据股票号 股票市场 模糊搜索股票数据
public function searchStock($param)
{
try {
$marketTypeList = StockMarketModel::STOCK_MARKET_TYPE;
if(empty($param['market_type']) || !in_array($param['market_type'], array_keys($marketTypeList))){
return $this->toData('1', '股票市场无效', []);
}
$where = [];
if(empty($param['page']) || !is_numeric($param['page']) || ceil($param['page']) != $param['page'] || $param['page'] <= 0){
return $this->toData('1', '分页参数无效', []);
}
if(empty($param['limit']) || !is_numeric($param['limit']) || ceil($param['limit']) != $param['limit'] || $param['limit'] <= 0){
return $this->toData('1', '分页参数无效', []);
}
if(!empty($param['stock_code']) && is_string($param['stock_code'])){
$where[] = ['stock_code', 'like', '%'.$param['stock_code']];
}
switch ($param['market_type'])
{
// 美股
case StockMarketModel::STOCK_MARKET_USA:
$stockList = StockListModel::where($where)->page($param['page'], $param['limit'])->select();
$total = StockListModel::where($where)->count();
break;
case StockMarketModel::STOCK_MARKET_YNG:
$stockList = StockIdnListModel::where($where)->page($param['page'], $param['limit'])->select();
$total = StockIdnListModel::where($where)->count();
break;
case StockMarketModel::STOCK_MARKET_MG:
$stockList = StockMysListModel::where($where)->page($param['page'], $param['limit'])->select();
$total = StockMysListModel::where($where)->count();
break;
case StockMarketModel::STOCK_MARKET_TG:
$stockList = StockThaListModel::where($where)->page($param['page'], $param['limit'])->select();
$total = StockThaListModel::where($where)->count();
break;
case StockMarketModel::STOCK_MARKET_IN:
$stockList = StockInListModel::where($where)->page($param['page'], $param['limit'])->select();
$total = StockInListModel::where($where)->count();
break;
case StockMarketModel::STOCK_MARKET_HK:
$stockList = StockHkdListModel::where($where)->page($param['page'], $param['limit'])->select();
$total = StockHkdListModel::where($where)->count();
break;
case StockMarketModel::STOCK_MARKET_UK:
$stockList = StockGBXListModel::where($where)->page($param['page'], $param['limit'])->select();
$total = StockGBXListModel::where($where)->count();
break;
case StockMarketModel::STOCK_MARKET_FUR:
$stockList = StockFurListModel::where($where)->page($param['page'], $param['limit'])->select();
$total = StockFurListModel::where($where)->count();
break;
case StockMarketModel::STOCK_MARKET_EUR:
$stockList = StockEurListModel::where($where)->page($param['page'], $param['limit'])->select();
$total = StockEurListModel::where($where)->count();
break;
default:
return $this->toData('1', '股票市场无效', []);
}
$rows = [];
if(!$stockList->isEmpty()){
$rows = $stockList->toArray();
}
return $this->toData('0','SUCCESS', ['total' => $total, 'list' => $rows, 'extent' => [
'stock_market_type_list' => StockMarketModel::STOCK_MARKET_TYPE,
'trade_day_type' => StockMarketModel::TRADE_DAY_TYPE,
]]);
}catch (\Exception $exception){
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 根据股票市场 股票主键 查询股票
public function searchStockById($param)
{
$marketTypeList = StockMarketModel::STOCK_MARKET_TYPE;
if(empty($param['market_type']) || !in_array($param['market_type'], array_keys($marketTypeList))){
return [];
}
if(empty($param['stock_id']) || !is_numeric($param['stock_id'])){
return [];
}
switch ($param['market_type'])
{
// 美股
case StockMarketModel::STOCK_MARKET_USA:
$stock = StockListModel::where('id', $param['stock_id'])->find();
break;
case StockMarketModel::STOCK_MARKET_YNG:
$stock = StockIdnListModel::where('id', $param['stock_id'])->find();
break;
case StockMarketModel::STOCK_MARKET_MG:
$stock = StockMysListModel::where('id', $param['stock_id'])->find();
break;
case StockMarketModel::STOCK_MARKET_TG:
$stock = StockThaListModel::where('id', $param['stock_id'])->find();
break;
case StockMarketModel::STOCK_MARKET_IN:
$stock = StockInListModel::where('id', $param['stock_id'])->find();
break;
case StockMarketModel::STOCK_MARKET_HK:
$stock = StockHkdListModel::where('id', $param['stock_id'])->find();
break;
case StockMarketModel::STOCK_MARKET_UK:
$stock = StockGBXListModel::where('id', $param['stock_id'])->find();
break;
case StockMarketModel::STOCK_MARKET_FUR:
$stock = StockFurListModel::where('id', $param['stock_id'])->find();
break;
case StockMarketModel::STOCK_MARKET_EUR:
$stock = StockEurListModel::where('id', $param['stock_id'])->find();
break;
default:
return [];
}
if(empty($stock)){
return [];
}
return $stock->toArray();
}
}

227
app/admin/service/setting/StockPriceSettingService.php

@ -0,0 +1,227 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\model\StockMarketModel;
use app\model\StockPricesSettingModel;
class StockPriceSettingService extends AdminBaseService
{
// 列表
public function index($param)
{
try {
if (empty($param['page']) || !is_numeric($param['page']) || ceil($param['page']) != $param['page'] || $param['page'] <= 0) {
return $this->toData('1', '分页参数无效', []);
}
if (empty($param['limit']) || !is_numeric($param['limit']) || ceil($param['limit']) != $param['limit'] || $param['limit'] <= 0) {
return $this->toData('1', '分页参数无效', []);
}
$list = StockPricesSettingModel::order('id', 'desc')->page($param['page'], $param['limit'])->select();
$total = StockPricesSettingModel::where('id', '>', 0)->count();
$rows = [];
// 股票市场货币符号
$marketSymbol = StockMarketModel::where('id', '>', 0)->column('symbol', 'stock_market_type');
if (!$list->isEmpty()) {
$rows = $list->toArray();
foreach ($list as $key => $item) {
$stock = (new StockMarketService)->searchStockById(['market_type' => $item->market_type, 'stock_id' => $item->stock_id]);
$rows[$key]['stock_code'] = $stock['stock_code'] ?? '-';
$rows[$key]['stock_name'] = $stock['stock_name'] ?? '-';
$rows[$key]['symbol'] = $marketSymbol[$item->market_type] ?? '-';
$rows[$key]['price'] = rtrim(rtrim($item['price'], '0'), '.');
}
}
return $this->toData('0', 'SUCCESS', ['list' => $rows, 'total' => $total, 'extent' => [
'market_type_list' => StockMarketModel::STOCK_MARKET_TYPE,
'market_symbol' => $marketSymbol
]]);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 新增
public function add($param)
{
try {
$marketTypeList = StockMarketModel::STOCK_MARKET_TYPE;
// 股票市场
if (empty($param['market_type']) || !in_array($param['market_type'], array_keys($marketTypeList))) {
return $this->toData('1', '市场类型无效', []);
}
// 股票主键
if (empty($param['stock_id']) || !is_numeric($param['stock_id'])) {
return $this->toData('1', '股票无效', []);
}
$stock = (new StockMarketService)->searchStockById(['market_type' => $param['market_type'], 'stock_id' => $param['stock_id']]);
if (empty($stock)) {
return $this->toData('1', '股票无效', []);
}
// 盘前状态
if (empty($param['status']) || !in_array($param['status'], [StockPricesSettingModel::STATUS_ON, StockPricesSettingModel::STATUS_OFF])) {
return $this->toData('1', '状态无效', []);
}
if (empty($param['price']) || !is_numeric($param['price'])) {
return $this->toData('1', '价格无效', []);
}
// 判断市场是否已经存在
$count = StockPricesSettingModel::where('market_type', $param['market_type'])->where('stock_id', $param['stock_id'])->count();
if ($count > 0) {
return $this->toData('1', '已存在相同配置', []);
}
// 添加缓存
$key = 'STOCK_PRICES:' . $param['market_type'] . ':' . $stock['stock_code'];
$redis = $this->getRedis();
$redis->del($key);
$bool = $redis->hMSet($key, [
'market_type' => $param['market_type'],
'stock_id' => $param['stock_id'],
'stock_code' => $stock['stock_code'],
'status' => $param['status'],
'price' => $param['price'],
]);
if ($bool) {
$stockPriceSetting = new StockPricesSettingModel;
$stockPriceSetting->market_type = $param['market_type'];
$stockPriceSetting->stock_id = $param['stock_id'];
$stockPriceSetting->status = $param['status'];
$stockPriceSetting->price = $param['price'];
$stockPriceSetting->create_time = date('Y-m-d H:i:s');
$stockPriceSetting->update_time = date('Y-m-d H:i:s');
$stockPriceSetting->save();
}
return $this->toData('0', 'SUCCESS', []);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 编辑
public function edit($param)
{
try {
$marketTypeList = StockMarketModel::STOCK_MARKET_TYPE;
// 目标
if (empty($param['id']) || !is_numeric($param['id'])) {
return $this->toData('1', '目标不存在', []);
}
$stockPriceSetting = StockPricesSettingModel::where('id', $param['id'])->find();
if (empty($stockPriceSetting)) {
return $this->toData('1', '目标不存在', []);
}
// 股票市场
if (empty($param['market_type']) || !in_array($param['market_type'], array_keys($marketTypeList))) {
return $this->toData('1', '市场类型无效', []);
}
// 股票主键
if (empty($param['stock_id']) || !is_numeric($param['stock_id'])) {
return $this->toData('1', '股票无效', []);
}
$stock = (new StockMarketService)->searchStockById(['market_type' => $param['market_type'], 'stock_id' => $param['stock_id']]);
if (empty($stock)) {
return $this->toData('1', '股票无效', []);
}
// 盘前状态
if (empty($param['status']) || !in_array($param['status'], [StockPricesSettingModel::STATUS_ON, StockPricesSettingModel::STATUS_OFF])) {
return $this->toData('1', '盘前状态无效', []);
}
if (empty($param['price']) || !is_numeric($param['price'])) {
return $this->toData('1', '价格无效', []);
}
// 判断市场是否已经存在
$count = StockPricesSettingModel::where('market_type', $param['market_type'])->where('stock_id', $param['stock_id'])
->where('id', '<>', $param['id'])
->count();
if ($count > 0) {
return $this->toData('1', '已存在相同配置', []);
}
// 添加缓存
$key = 'STOCK_PRICES:' . $param['market_type'] . ':' . $stock['stock_code'];
$redis = $this->getRedis();
$redis->del($key);
$bool = $redis->hMSet($key, [
'market_type' => $param['market_type'],
'stock_id' => $param['stock_id'],
'stock_code' => $stock['stock_code'],
'status' => $param['status'],
'price' => $param['price'],
]);
if ($bool) {
$stockPriceSetting->market_type = $param['market_type'];
$stockPriceSetting->stock_id = $param['stock_id'];
$stockPriceSetting->status = $param['status'];
$stockPriceSetting->price = $param['price'];
$stockPriceSetting->update_time = date('Y-m-d H:i:s');
$stockPriceSetting->save();
}
return $this->toData('0', 'SUCCESS', [$stockPriceSetting->price]);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
// 删除
public function del($param)
{
try {
// 目标
if (empty($param['id']) || !is_numeric($param['id'])) {
return $this->toData('1', '目标不存在', []);
}
$stockPriceSetting = StockPricesSettingModel::where('id', $param['id'])->find();
if (empty($stockPriceSetting)) {
return $this->toData('1', '目标不存在', []);
}
if ($stockPriceSetting->status == StockPricesSettingModel::STATUS_ON) {
return $this->toData('1', '配置开启中 不可删除', []);
}
$stock = (new StockMarketService)->searchStockById(['market_type' => $stockPriceSetting->market_type, 'stock_id' => $stockPriceSetting->stock_id]);
if (empty($stock)) {
return $this->toData('1', '股票无效', []);
}
$key = 'STOCK_PRICES:' . $stockPriceSetting->market_type . ':' . $stock['stock_code'];
$redis = $this->getRedis();
$num = $redis->del($key);
if ($num > 0) {
$stockPriceSetting->delete();
}
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', [$exception->getMessage()]);
}
}
}

43
app/admin/service/setting/StockService.php

@ -0,0 +1,43 @@
<?php
namespace app\admin\service\setting;
use app\admin\service\AdminBaseService;
use app\admin\validate\setting\StockValidate;
use app\model\StockListModel;
use app\model\StockMarketModel;
use app\model\StockPricesSettingModel;
use PHPMailer\PHPMailer\Exception;
use think\exception\ValidateException;
use think\facade\Validate;
class StockService extends AdminBaseService
{
public function index($param)
{
return (new IPOService())->stockList(3,$param);
}
public function add($param)
{
return (new IPOService())->addStock(3,$param);
}
public function edit($param)
{
return (new IPOService())->editStock(3,$param);
}
// 美股列表
public function getTradeNameList($param)
{
try {
$list = StockListModel::where('status', 1)->order('id', 'desc')->column('stock_name', 'id');
return $this->toData('0', 'SUCCESS', ['list' => $list]);
} catch (\Exception $exception) {
return $this->toData('1', '系统繁忙', []);
}
}
}

93
app/admin/validate/AdminBaseValidate.php

@ -0,0 +1,93 @@
<?php
namespace app\admin\validate;
use think\Validate;
class AdminBaseValidate extends Validate
{
// 校验是否是 整数 包含字符串 大于0
public function checkNumberIntBg($value, $rule, $data=[])
{
if(!is_numeric($value)){
return false;
}
if(ceil($value) != $value){
return false;
}
if($value <= 0){
return false;
}
return true;
}
// 校验是否是 整数 包含字符串 大于0
public function checkNumberIntAt($value, $rule, $data=[])
{
if(!is_numeric($value)){
return false;
}
if(ceil($value) != $value){
return false;
}
if($value < 0){
return false;
}
return true;
}
// 校验是否是 数字 包含 小数 字符串 大于 0
public function checkNumberFloatBg($value, $rule, $data=[])
{
if(!is_numeric($value)){
return false;
}
if($value <= 0){
return false;
}
return true;
}
// 必传 包含0的情况
public function checkStatusRequire($value, $rule, $data=[])
{
if(!isset($data['status'])){
return false;
}
if(!is_numeric($value)){
return false;
}
return true;
}
// 是否是字符串
public function checkIsString($value, $rule, $data=[])
{
return is_string($value);
}
public function checkInRequire($value, $rule, $data=[])
{
if(!isset($data['channel_type'])){
return false;
}
if(!in_array($value,$rule)){
return false;
}
return true;
}
}

40
app/admin/validate/AdminValidate.php

@ -0,0 +1,40 @@
<?php
namespace app\admin\validate;
class AdminValidate extends AdminBaseValidate
{
protected $rule = [
'user_name' => 'require|alphaNum',
'password' => 'require|length:5,40',
'new_password' => 'require|length:5,40',
'old_password' => 'require|length:5,40',
'nick_name' => 'require|alphaNum',
];
protected $message = [
'user_name.alphaNum' => '用户名必须包含字母和数字',
'nick_name.alphaNum' => '昵称必须包含字母和数字',
'password.require' => '请填写密码',
// 'password.isString' => '密码格式不正确.',
'password.length' => '密码必须大于5个字符.',
'new_password.require' => '请填写新密码',
// 'password.isString' => '密码格式不正确.',
'new_password.length' => '密码必须大于5个字符.',
'old_password.require' => '请填写原始密码',
// 'password.isString' => '密码格式不正确.',
'old_password.length' => '密码必须大于5个字符.',
];
protected $scene = [
'addUser' => ['user_name','password','nick_name'],
'updateInfo' => ['nick_name','email'],
'updateAccount' => ['user_name','nick_name'],
'updatePassword'=>['new_password','old_password'],
'updateAccountStatus'=>['id','status']
];
}

77
app/admin/validate/FlowValidate.php

@ -0,0 +1,77 @@
<?php
namespace app\admin\validate;
class FlowValidate extends AdminBaseValidate
{
protected $rule = [
'page' => 'require|integer',
'limit' => 'require|integer',
'order_id' => 'alphaNum',
'user_no' => 'alphaNum',
'chang_type' => 'in:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20',
'digital_id' => 'upper',
'contract_id' => 'alphaDash',
'stock_id' => 'alphaDash',
'start_time' => 'date|dateFormat:Y-m-d H:i:s',
'end_time' => 'date|dateFormat:Y-m-d H:i:s',
'from_account' => 'in:1,2,3',
'to_account' => 'in:1,2,3',
'account_type' => 'in:1,2,3',
'trade_type' => 'in:1,2',
'trade_no' => 'alphaNum',
'level_type' => 'in:1,2,3',
'back_type' => 'in:0,1,2,3',
];
protected $message = [
'page.require' => '分页参数无效',
'page.integer' => '分页参数无效',
'limit.require' => '分页参数无效',
'limit.integer' => '分页参数无效',
'chang_type.in' => '变动类型无效',
'order_id.alphaNum' => '订单号无效',
'user_no.alphaNum' => '用户号无效',
'digital_id.upper' => '交易对无效',
'contract_id.upper' => '合约代码无效',
'stock_id.upper' => '股票代码无效',
'start_time.date' => '搜索日期无效',
'start_time.dateFormat' => '搜索日期无效',
'end_time.date' => '搜索日期无效',
'end_time.dateFormat' => '搜索日期无效',
'from_account.in' => '转出资金账号无效',
'to_account.in' => '转入资金账号无效',
'account_type.in' => '账户类型无效',
'trade_type.in' => '交易类型无效',
'trade_no.in' => '交易单号无效',
'level_type.in' => '返佣级别无效',
'back_type.in' => '返佣类型无效',
];
protected $scene = [
'digital' => ['page','limit', 'user_no', 'digital_id', 'chang_type','start_time', 'end_time'],
'stock' => ['page','limit', 'user_no', 'stock_id', 'chang_type','start_time', 'end_time'],
'contract' => ['page','limit', 'user_no', 'contract_id', 'chang_type','start_time', 'end_time'],
'forex' => ['page','limit', 'user_no', 'contract_id', 'chang_type','start_time', 'end_time'],
'transfer' => ['page','limit', 'user_no', 'from_account', 'to_account','start_time', 'end_time'],
'fee' => ['page','limit', 'user_no', 'account_type', 'trade_type','trade_no','start_time', 'end_time'],
'brokerage' => ['page','limit', 'user_no', 'level_type', 'back_type','start_time', 'end_time'],
// 美股资产流水
'us_stock' => ['page','limit', 'user_no', 'stock_id', 'chang_type','start_time', 'end_time'],
// 印尼股票
'idn_stock' => ['page','limit', 'user_no', 'stock_id', 'chang_type','start_time', 'end_time'],
// 马来西亚资产流水
'mys_stock' => ['page','limit', 'user_no', 'stock_id', 'chang_type','start_time', 'end_time'],
// 泰国股票
'tha_stock' => ['page','limit', 'user_no', 'stock_id', 'chang_type','start_time', 'end_time'],
// 印度股票
'in_stock' => ['page','limit', 'user_no', 'stock_id', 'chang_type','start_time', 'end_time'],
'sgd_stock' => ['page','limit', 'user_no', 'stock_id', 'chang_type','start_time', 'end_time'],
'hk_stock' => ['page','limit', 'user_no', 'stock_id', 'chang_type','start_time', 'end_time'],
'fund_stock' => ['page','limit', 'user_no', 'stock_id', 'chang_type','start_time', 'end_time'],
'block_stock' => ['page','limit', 'user_no', 'stock_id', 'chang_type','start_time', 'end_time'],
];
}

20
app/admin/validate/LoginValidate.php

@ -0,0 +1,20 @@
<?php
namespace app\admin\validate;
class LoginValidate extends AdminBaseValidate
{
protected $rule = [
'user_name' => 'require|alphaNum',
'password' => 'require|length:5,40',
];
protected $message = [
'user_name.require' => '请填写用户名',
'user_name.alphaNum' => '用户名必须包含字母和数字',
'password.require' => '请填写密码',
'password.length' => '密码必须大于5个字符.',
];
protected $scene = [
'login' => ['user_name','password'],
];
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save