3171 changed files with 736515 additions and 0 deletions
@ -0,0 +1,15 @@ |
|||||
|
root = true |
||||
|
|
||||
|
[*] |
||||
|
charset = utf-8 |
||||
|
end_of_line = lf |
||||
|
insert_final_newline = true |
||||
|
indent_style = space |
||||
|
indent_size = 4 |
||||
|
trim_trailing_whitespace = true |
||||
|
|
||||
|
[*.md] |
||||
|
trim_trailing_whitespace = false |
||||
|
|
||||
|
[*.yml] |
||||
|
indent_size = 2 |
||||
@ -0,0 +1,105 @@ |
|||||
|
APP_NAME=Laravel |
||||
|
APP_ENV=local |
||||
|
APP_KEY=base64:PIwHNrCP1exFsBTdDEgU6rWCDdsbAH++Y6i34eLs2Eo= |
||||
|
APP_DEBUG=false #开启dubug模式,debug模式将不载入缓存 |
||||
|
ADMIN_HTTPS=true #如果未配置HTTPS则需要将这个配置改成false(如果配置https证书后未开启配置会导致后台进不去) |
||||
|
|
||||
|
ADMIN_ROUTE_PREFIX=binvet #后台路径 |
||||
|
# 接口域名配置(用于拼接接口静态资源) |
||||
|
APP_URL=https://server.bitoc.pro |
||||
|
NOTIFY_URL=https://server.bitoc.pro |
||||
|
PC_URL=https://www.bitoc.pro |
||||
|
H5_URL=https://m.bitoc.pro |
||||
|
IMG_URL=https://server.bitoc.pro |
||||
|
COIN_URL=https://server.bitoc.pro |
||||
|
|
||||
|
LOG_CHANNEL=stack |
||||
|
|
||||
|
# 数据库配置 |
||||
|
DB_CONNECTION=mysql |
||||
|
DB_HOST=127.0.0.1 |
||||
|
DB_PORT=3306 |
||||
|
DB_DATABASE=server |
||||
|
DB_USERNAME=server |
||||
|
DB_PASSWORD=mTFkjKCmhB7PfTzk |
||||
|
|
||||
|
# reids配置(用于储存行情、消息队列信息) |
||||
|
REDIS_HOST=127.0.0.1 |
||||
|
REDIS_PASSWORD=null |
||||
|
REDIS_PORT=6379 |
||||
|
|
||||
|
# workerman SSL目录配置(绝对路径),用于开启wss,留空则为ws |
||||
|
SSL_CERT=/www/server/panel/vhost/cert/server.bitoc.pro/fullchain.pem |
||||
|
SSL_PK=/www/server/panel/vhost/cert/server.bitoc.pro/privkey.pem |
||||
|
|
||||
|
# 队列(用于处理币币、合约等交易、期权交易的处理) |
||||
|
BROADCAST_DRIVER=redis |
||||
|
CACHE_DRIVER=redis |
||||
|
QUEUE_CONNECTION=redis |
||||
|
SESSION_DRIVER=file |
||||
|
SESSION_LIFETIME=120 |
||||
|
|
||||
|
# 邮箱配置(用于用户注册发送邮件验证码) |
||||
|
MAIL_DRIVER=smtp |
||||
|
MAIL_HOST=smtp.gmail.com |
||||
|
MAIL_PORT=465 |
||||
|
MAIL_USERNAME=Bitocpro@gmail.com |
||||
|
MAIL_PASSWORD=ahvvlqagghzcimwz |
||||
|
MAIL_FROM_NAME=Bitocpro |
||||
|
MAIL_FROM_ADDRESS=Bitocpro@gmail.com |
||||
|
MAIL_ENCRYPTION=SSL |
||||
|
|
||||
|
#easysms短信配置 |
||||
|
MSG_UID= |
||||
|
MSG_PW= |
||||
|
MSG_ACCOUNT=bitoc |
||||
|
MSG_PASSWORD=qwer1234 |
||||
|
MSG_SIGN= |
||||
|
|
||||
|
AWS_ACCESS_KEY_ID= |
||||
|
AWS_SECRET_ACCESS_KEY= |
||||
|
AWS_DEFAULT_REGION=us-east-1 |
||||
|
AWS_BUCKET= |
||||
|
|
||||
|
PUSHER_APP_ID= |
||||
|
PUSHER_APP_KEY= |
||||
|
PUSHER_APP_SECRET= |
||||
|
PUSHER_APP_CLUSTER=mt1 |
||||
|
|
||||
|
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" |
||||
|
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" |
||||
|
|
||||
|
API_SUBTYPE=bourse |
||||
|
API_PREFIX=api |
||||
|
API_VERSION=v1 |
||||
|
API_NAME=bourse |
||||
|
API_CONDITIONAL_REQUEST=false |
||||
|
API_STRICT=false |
||||
|
API_STANDARDS_TREE=vnd |
||||
|
API_DEFAULT_FORMAT=json |
||||
|
API_DEBUG=true |
||||
|
|
||||
|
|
||||
|
JWT_SECRET=uO4Y9UTLapd5xzHlN3AlgnhkwGJ1ri9ijlzDhETDCoosqAVXlYOVGPo3XKtXUqLM |
||||
|
|
||||
|
HUOBI_ACCOUNT_ID=93562654 |
||||
|
HUOBI_ACCESS_KEY=82c973d7-0e25f2ca-4dedf56f-vfd5ghr532 |
||||
|
HUOBI_SECRET_KEY=3eb58129-0dcda92d-dc7c1f31-d9741 |
||||
|
|
||||
|
# 空气币配置 |
||||
|
COIN_SYMBOL=AETC |
||||
|
COIN2_SYMBOL=BT |
||||
|
COIN3_SYMBOL=TKB |
||||
|
|
||||
|
#GETH_HOST=http://127.0.0.1:8545 |
||||
|
#GETH_PWD= |
||||
|
#BITCORE_HOST=127.0.0.1 |
||||
|
#BITCORE_PORT=8888 |
||||
|
#BITCORE_PASSWORD= |
||||
|
#BITCORE_USERNAME=omnicorerpc |
||||
|
#BITCORE_UPASSWORD= |
||||
|
#OMNICORE_HOST=127.0.0.1 |
||||
|
#OMNICORE_PORT=8888 |
||||
|
#OMNICORE_PASSWORD= |
||||
|
#OMNICORE_USERNAME=omnicorerpc |
||||
|
#OMNICORE_UPASSWORD= |
||||
@ -0,0 +1,5 @@ |
|||||
|
* text=auto |
||||
|
*.css linguist-vendored |
||||
|
*.scss linguist-vendored |
||||
|
*.js linguist-vendored |
||||
|
CHANGELOG.md export-ignore |
||||
@ -0,0 +1,21 @@ |
|||||
|
/node_modules |
||||
|
/public/hot |
||||
|
/public/storage |
||||
|
/storage/*.key |
||||
|
/storage/app/public/upload/* |
||||
|
/storage/app/public/poster/* |
||||
|
/vendor |
||||
|
/storage/framework/cache/* |
||||
|
/storage/framework/sessions/* |
||||
|
/storage/framework/testing/* |
||||
|
/storage/framework/views/* |
||||
|
/storage/framework/workerman/* |
||||
|
/config |
||||
|
.env |
||||
|
.env.backup |
||||
|
.phpunit.result.cache |
||||
|
Homestead.json |
||||
|
Homestead.yaml |
||||
|
npm-debug.log |
||||
|
yarn-error.log |
||||
|
.idea |
||||
@ -0,0 +1 @@ |
|||||
|
|
||||
@ -0,0 +1,13 @@ |
|||||
|
php: |
||||
|
preset: laravel |
||||
|
disabled: |
||||
|
- unused_use |
||||
|
finder: |
||||
|
not-name: |
||||
|
- index.php |
||||
|
- server.php |
||||
|
js: |
||||
|
finder: |
||||
|
not-name: |
||||
|
- webpack.mix.js |
||||
|
css: true |
||||
@ -0,0 +1 @@ |
|||||
|
open_basedir=/www/wwwroot/btc_btcoinmt_com/:/tmp/ |
||||
@ -0,0 +1,7 @@ |
|||||
|
<html> |
||||
|
<head><title>404 Not Found</title></head> |
||||
|
<body> |
||||
|
<center><h1>404 Not Found</h1></center> |
||||
|
<hr><center>nginx</center> |
||||
|
</body> |
||||
|
</html> |
||||
@ -0,0 +1,134 @@ |
|||||
|
<!-- |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-03 23:56:30 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-07 00:15:13 |
||||
|
--> |
||||
|
## 交易所服务端 |
||||
|
pc端api接口,h5端api接口,后台管理,websocket信息推送系统 |
||||
|
|
||||
|
后台管理地址 |
||||
|
域名/admin |
||||
|
账号:admin |
||||
|
密码:admin |
||||
|
## 软件架构 |
||||
|
`Laravel6` + `Mysql`。 |
||||
|
|
||||
|
## 环境要求 |
||||
|
* `git` 用户版本管理,部署和升级必要工具 |
||||
|
* `PHP 7.3 +` |
||||
|
* `Mysql 5.7+` ,数据库 |
||||
|
* `Redis` redis需要开启过期键监听功能 |
||||
|
> 在配置文件中的配置 `notify-keyspace-events Ex` 重启 |
||||
|
* `composer` 用于安装依赖 |
||||
|
* PHP扩展 |
||||
|
- `gmp PHP`扩展,注意和 PHP 版本相同。 |
||||
|
- `mongodb PHP`扩展,注意和 PHP 版本相同。 |
||||
|
- `ext-zip` 扩展,注意和 PHP 版本相同。 |
||||
|
- `ext-json` 扩展,注意和 PHP 版本相同。 |
||||
|
- `ext-fileinfo` 扩展,注意和 PHP 版本相同。 |
||||
|
* PHP函数(需要进入php配置文件取消禁用) |
||||
|
- `putenv` 获取env配置信息 |
||||
|
- `proc_open` (函数说明:执行一个命令,并且打开用来输入/输出的文件指针) composer 安装时需要 |
||||
|
- `pcntl_signal` (函数说明:安装一个信号处理器) 启用workman需要 |
||||
|
- `pcntl_fork` (函数说明:在当前金正当前未知产生分支) 启动workerman需要 |
||||
|
- `pcntl_wait` (等待或返回fork的子进程状态) 启动workerman需要 |
||||
|
- `pcntl_signal_dispath` (调用等待信号的处理器) 启动workerman需要 |
||||
|
- `pcntl_alarm()` 启动workerman需要 |
||||
|
- `symlink` 创建静态资源软连接需要 |
||||
|
- `exec` tinker需要 |
||||
|
## 部署 |
||||
|
### Git部署 |
||||
|
> 注意:使用过程中,必须避免直接修改数据库数据,Laravel 拥有强大的 Eloquent ORM 模型层,程序中的所有逻辑交互都由模型关联完成,直接修改数据库数据将会导致未知的错误。应用脱离数据库直接交互是现在最流行的做法。 |
||||
|
|
||||
|
生产环境下为遵守安全策略,非常建议在服务器本地进行部署,暂时不提供相关线上初始化安装的功能。因此,虽然前期部署的步骤较多,但已经自动化处理了很大部分的流程,只需要跟着下面的命令一步步执行,一般是不会有部署问题的。 |
||||
|
|
||||
|
1. 创建一个数据库,命名随意,但记得之后填写配置时需要对应正确,并且数据库字符集为 `utf8-general-ci`。 |
||||
|
2. 打开linux服务器终端执行 `ssh-keygen -t rsa` 将在 ~/.ssh/id_rsa.pub 生成公钥,将公钥添加到git仓库部署公钥中 获得拉去代码的权限 |
||||
|
3. 在你想要项目运行目录中,执行 `git clone --depth 1 -b server git@gitee.com:guapiya233/binvet.git ./server` 将代码下载到本地 |
||||
|
> -b 意为选择分支 ./server 意为将代码克隆到 server 目录 |
||||
|
4. 进入server项目目录执行 `composer install` 进行依赖的安装 |
||||
|
> 如果未满足上述环境要求可能会出现安装报错 |
||||
|
5. 在项目根目录中,复制 `.env.example` 为一份新的,并重命名为`.env` |
||||
|
> 该文件储存了系统的配置信息 |
||||
|
6. 在`.env` 中配置Mysql数据库信息以及redis信息 |
||||
|
>mysql与redis是必须配置的信息,其余的workerman、接口域名配置、邮件配置、短信配置可滞后配置 |
||||
|
7. 进入项目根目录后执行`php artisan exchange:install` 进行安装 |
||||
|
>该命令将会自动创建导入数据库、创建资源目录软连接、重置管理员密码 |
||||
|
8. 你可能使用的web服务器为 `nginx` 以及 `apache`,无论怎样,应用的起始路径在 `/public` 目录,请确保指向正确,同时程序的根目录权限应该调整为:拥有者和你的 Web |
||||
|
服务器运行用户一致,且根目录权限为 `755`。 |
||||
|
8. 修改web服务器的伪静态规则为: |
||||
|
``` |
||||
|
location / { |
||||
|
try_files $uri $uri/ /index.php?$args; |
||||
|
} |
||||
|
``` |
||||
|
9. 此时可以通过访问 `http://your_domain` 来使用 交易所管理后台。管理员账号密码为:`admin / admin`。 |
||||
|
### 启动websocket行情服务 |
||||
|
1. 启动主程序 |
||||
|
- `php artisan workerman option start --d` |
||||
|
- `php artisan workerman swap start --d` |
||||
|
2. 启动websocket行情采集工具 |
||||
|
- 行情采集 |
||||
|
``` |
||||
|
cd public/exchange |
||||
|
sh wss_start.sh & |
||||
|
``` |
||||
|
- swap采集 |
||||
|
``` |
||||
|
cd public/swap |
||||
|
sh swap_start.sh & |
||||
|
``` |
||||
|
|
||||
|
3. 配置nginx 设置协议升级(如果是ws则需要将https改为http) |
||||
|
在站点nginx配置文件增加以下配置 |
||||
|
``` |
||||
|
#在nginx内添加该段内容 |
||||
|
location /ws1 { |
||||
|
proxy_pass https://127.0.0.1:2346; |
||||
|
proxy_http_version 1.1; |
||||
|
proxy_set_header Upgrade $http_upgrade; |
||||
|
proxy_set_header Connection "upgrade"; |
||||
|
} |
||||
|
location /ws2 { |
||||
|
proxy_pass https://127.0.0.1:2348; |
||||
|
proxy_http_version 1.1; |
||||
|
proxy_set_header Upgrade $http_upgrade; |
||||
|
proxy_set_header Connection "upgrade"; |
||||
|
} |
||||
|
``` |
||||
|
4. 常见问题 |
||||
|
- `killall -9 php` 解决无法workerman关闭的问题 |
||||
|
### 开启守护进程 (使用supervisor管理器) |
||||
|
1. `php artisan queue:work redis --queue=triggerStrategy` |
||||
|
>合约平仓? triggerStrategy |
||||
|
2. `php artisan queue:work redis --queue=HandleFlatPosition` |
||||
|
>HandleFlatPosition |
||||
|
3. `php artisan queue:work redis --queue=handleContractEntrust` |
||||
|
>handleContractEntrust |
||||
|
4. `php artisan queue:work redis --queue=handleEntrust` |
||||
|
>合约队列 handleEntrust |
||||
|
5. `php artisan queue:work redis --queue=UdunDeposit` |
||||
|
>U盾队列 UdunDeposit |
||||
|
6. `php artisan option:delivery 期权交割 option_delivery` |
||||
|
|
||||
|
7. `php artisan flatPosition` |
||||
|
>平仓机器人 flatPosition |
||||
|
8. `php artisan contractDealRobot` |
||||
|
>合约交易成交机器人 contractDealRobot |
||||
|
9. `php artisan BdealRobot BdealRobot` |
||||
|
>币币交易买单处理机器人 |
||||
|
10. `php artisan SdealRobot SdealRobot` |
||||
|
>币币交易卖单处理机器人 |
||||
|
### 添加corntab任务(用于执行定时任务) |
||||
|
> corntab任务是laravel的任务调度(定时任务)对系统的依赖,如果未开启这项配置将会导致,期权场景不能创建、异常期权任务不能取消、USD-CNY汇率不能更新、申购活动无法进行 |
||||
|
在命令行终端执行 |
||||
|
`crontab -e -u www` |
||||
|
增加这一行配置 (命令中的目录需要根据自己的环境进行修改) |
||||
|
`* * * * * /www/server/php/73/bin/php /www/wwwroot/exchange/server/artisan schedule:run >> /dev/null 2>&1` |
||||
|
>这行命令是起 每分钟调度一次 php artisan schedule:run 命令 但使用的是绝对路径 |
||||
|
## 常见问题 |
||||
|
1. 安装完成访问网址提示权限问题。 chown -R www:www ./ 将文件夹权限设置给www用户即可 |
||||
|
2. 期权订单无法交割。 打开redis的过期键监听功能 notify-keyspace-events "Ex" |
||||
@ -0,0 +1,99 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Agent; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class ChangeStatus extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '审核'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = "ChangeStatus-{$this->getKey()}"; |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">{$this->title}</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new \App\Admin\Forms\Agent\ChangeStatus($this->getKey()); |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">{$this->title}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,75 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: 合约返佣手动结算 |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-08-04 09:58:30 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-04 10:58:57 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Actions\Agent; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use App\Models\Contract\ContractRebate; |
||||
|
|
||||
|
class ContractSettle extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '结算'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
$rebate_log = ContractRebate::find($this->getKey()); |
||||
|
if ($rebate_log->settle()) { |
||||
|
return $this->response() |
||||
|
->success('结算成功: ' . $this->getKey()) |
||||
|
->refresh(); |
||||
|
} else { |
||||
|
return $this->response() |
||||
|
->error('结算失败: ' . $this->getKey()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定结算?', '每日12:00系统会自动结算,您可手动提前结算。']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
// 获取当前订单是否已结算 |
||||
|
return ContractRebate::find($this->getKey())->value('status') ? false : true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,109 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-08-05 11:35:45 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-12 16:15:23 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Actions\Agent; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use App\Models\User; |
||||
|
use App\Models\AgentUser; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class DeleteAgent extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '删除代理商'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
try { |
||||
|
DB::beginTransaction(); |
||||
|
$user_id = $this->getKey(); |
||||
|
$user = User::find($user_id); |
||||
|
// 1、更新用户渠道商状态 |
||||
|
$user->update(['is_agency' => 0]); |
||||
|
// 2、删除用户登录渠道商后台权限 |
||||
|
DB::table('agent_admin_role_users') |
||||
|
->where(['user_id' => $user_id, 'role_id' => 2]) |
||||
|
->delete(); |
||||
|
// 3、查询用户是否是代理商、如果不是 删除userAgent表中的代理信息 |
||||
|
if ($user->is_place == 0) { |
||||
|
AgentUser::query() |
||||
|
->where('id', $user_id) |
||||
|
->delete(); |
||||
|
} |
||||
|
// 4、将下级代理的referrer改为0(如果代理商是当前用户的情况下) |
||||
|
User::query() |
||||
|
->where('pid', $user_id) |
||||
|
->where('referrer', $user_id) |
||||
|
->update(['referrer' => 0]); |
||||
|
DB::commit(); |
||||
|
return $this->response() |
||||
|
->success('删除成功: ' . $this->getKey()) |
||||
|
->refresh(); |
||||
|
} catch (\Exception $e) { |
||||
|
info($e); |
||||
|
return $this->response() |
||||
|
->error('删除失败'); |
||||
|
} |
||||
|
|
||||
|
return $this->response() |
||||
|
->success('删除成功: ' . $this->getKey()) |
||||
|
->refresh(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定删除该用户渠道商权限?', '删除之后,若用户为渠道商仍可登录渠道商后台,但无法享受代理商返佣']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
// 判断该用户是否是渠道商 |
||||
|
|
||||
|
return (User::find($this->getKey())->is_agency == 1) ? true : false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
public function html() |
||||
|
{ |
||||
|
|
||||
|
$this->appendHtmlAttribute('class', 'btn btn-outline-primary btn-sm btn-mini submit'); |
||||
|
return parent::html(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,96 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-08-05 13:44:29 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-06 17:43:00 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Actions\Agent; |
||||
|
|
||||
|
use App\Models\User; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class ToBePlace extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '升为渠道商'; |
||||
|
|
||||
|
|
||||
|
public function canClick(bool $boolean) |
||||
|
{ |
||||
|
$this->canClick = $boolean; |
||||
|
return $this; |
||||
|
} |
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
try { |
||||
|
$user_id = $this->getKey(); |
||||
|
DB::beginTransaction(); |
||||
|
// 1、更新用户渠道商身份 |
||||
|
User::find($user_id)->update(['is_place' => 1]); |
||||
|
// 2、绑定用户渠道商角色 |
||||
|
DB::table('agent_admin_role_users')->insertOrIgnore(['role_id' => 3, 'user_id' => $user_id]); |
||||
|
DB::commit(); |
||||
|
return $this->response() |
||||
|
->success('升级成功') |
||||
|
->refresh(); |
||||
|
} catch (\Exception $e) { |
||||
|
dd($e); |
||||
|
info($e); |
||||
|
return $this->response() |
||||
|
->error('升级失败'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['升级渠道商?', '升级后该代理可在代理商后台查看用户盈亏数据']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
public function html() |
||||
|
{ |
||||
|
|
||||
|
|
||||
|
$this->appendHtmlAttribute('class', 'btn btn-outline-primary btn-sm btn-mini submit'); |
||||
|
if (!$this->canClick) $this->appendHtmlAttribute('class', 'disabled'); |
||||
|
return parent::html(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,106 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/** |
||||
|
* Created by PhpStorm. |
||||
|
* User: Administrator |
||||
|
* Date: 2020/7/23 |
||||
|
* Time: 15:42 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Actions\Application; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class ApplicationCheck extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '上币申请'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = "withdraw-{$this->getKey()}"; |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">审核</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new \App\Admin\Forms\Withdraw\ApplicationCheck($this->getKey()); |
||||
|
$username = $this->row->username; |
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">上币审核{$username}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,100 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\ContractAccount; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class Recharge extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '合约资产增减'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = "contract-recharge-{$this->getKey()}"; |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">{$this->title}</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$user_id = $this->row->user_id; |
||||
|
$form = new \App\Admin\Forms\ContractAccount\Recharge($user_id); |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">{$this->title}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,153 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\ContractEntrust; |
||||
|
|
||||
|
use App\Exceptions\ApiException; |
||||
|
use App\Models\ContractEntrust; |
||||
|
use App\Models\ContractPosition; |
||||
|
use App\Models\SustainableAccount; |
||||
|
use App\Models\User; |
||||
|
use App\Models\UserWallet; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\BatchAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class BatchCancel extends BatchAction |
||||
|
{ |
||||
|
protected $style = 'btn btn-sm btn-default'; |
||||
|
|
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '批量撤单'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$keys = $this->getKey(); |
||||
|
|
||||
|
$entrusts = ContractEntrust::query()->find($keys); |
||||
|
|
||||
|
try { |
||||
|
DB::beginTransaction(); |
||||
|
|
||||
|
foreach ($entrusts as $entrust) { |
||||
|
if (!$entrust->can_cancel()) continue; |
||||
|
$this->cancel($entrust); |
||||
|
} |
||||
|
|
||||
|
DB::commit(); |
||||
|
|
||||
|
return $this->response()->success('Processed successfully.')->refresh(); |
||||
|
} catch (\Exception $e) { |
||||
|
DB::rollBack(); |
||||
|
return $this->response()->error('Processed fail.'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private function cancel($entrust) |
||||
|
{ |
||||
|
DB::beginTransaction(); |
||||
|
try { |
||||
|
//更新委托 |
||||
|
$res = $entrust->update([ |
||||
|
'status' => 0, |
||||
|
'cancel_time' => time(), |
||||
|
]); |
||||
|
|
||||
|
$user = User::query()->findOrFail($entrust['user_id']); |
||||
|
if ($entrust['order_type'] == 1) { |
||||
|
// 开仓方向 |
||||
|
// 合约保证金账户 |
||||
|
$wallet = SustainableAccount::query()->where(['user_id' => $entrust['user_id']])->first(); |
||||
|
if (blank($wallet)) throw new ApiException('账户类型错误'); |
||||
|
$log_type = 'cancel_open_position'; // 撤销合约委托 |
||||
|
$log_type2 = 'cancel_open_position_fee'; // 撤销合约委托 |
||||
|
//退还用户可用资产 冻结保证金 |
||||
|
$user->update_wallet_and_log($wallet['coin_id'], 'usable_balance', $entrust['margin'], UserWallet::sustainable_account, $log_type, '', $entrust['contract_id']); |
||||
|
$user->update_wallet_and_log($wallet['coin_id'], 'freeze_balance', -$entrust['margin'], UserWallet::sustainable_account, $log_type, '', $entrust['contract_id']); |
||||
|
$user->update_wallet_and_log($wallet['coin_id'], 'usable_balance', $entrust['fee'], UserWallet::sustainable_account, $log_type2, '', $entrust['contract_id']); |
||||
|
$user->update_wallet_and_log($wallet['coin_id'], 'freeze_balance', -$entrust['fee'], UserWallet::sustainable_account, $log_type2, '', $entrust['contract_id']); |
||||
|
} else { |
||||
|
// 平仓方向 |
||||
|
$position_side = $entrust['side'] == 1 ? 2 : 1; |
||||
|
// 持仓信息 |
||||
|
$position = ContractPosition::getPosition(['user_id' => $user['user_id'], 'contract_id' => $entrust['contract_id'], 'side' => $position_side]); |
||||
|
if (blank($position)) throw new ApiException(); |
||||
|
// 回退持仓数量 |
||||
|
$position->update([ |
||||
|
'avail_position' => $position->avail_position + $entrust['amount'], |
||||
|
'freeze_position' => $position->freeze_position - $entrust['amount'], |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
DB::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
DB::rollBack(); |
||||
|
throw new ApiException($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定' . $this->title . '?']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
public function actionScript() |
||||
|
{ |
||||
|
$warning = "请选择撤销的委托!"; |
||||
|
|
||||
|
return <<<JS |
||||
|
function (data, target, action) { |
||||
|
console.log('发起请求之前', {data, target, action}); |
||||
|
var key = {$this->getSelectedKeysScript()} |
||||
|
|
||||
|
if (key.length === 0) { |
||||
|
Dcat.warning('{$warning}'); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
// 设置主键为复选框选中的行ID数组 |
||||
|
action.options.key = key; |
||||
|
} |
||||
|
JS; |
||||
|
} |
||||
|
protected function html() |
||||
|
{ |
||||
|
return <<<HTML |
||||
|
<a {$this->formatHtmlAttributes()}><button class="btn btn-primary btn-mini">{$this->title()}</button></a> |
||||
|
HTML; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,116 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\ContractEntrust; |
||||
|
|
||||
|
use App\Exceptions\ApiException; |
||||
|
use App\Models\ContractEntrust; |
||||
|
use App\Models\ContractPosition; |
||||
|
use App\Models\SustainableAccount; |
||||
|
use App\Models\User; |
||||
|
use App\Models\UserWallet; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use Illuminate\Support\Facades\Log; |
||||
|
|
||||
|
class cancel extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '撤单'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
if (blank($id)) { |
||||
|
return $this->response()->error('Processed fail.'); |
||||
|
} |
||||
|
|
||||
|
$entrust = ContractEntrust::query()->where('id', $id)->first(); |
||||
|
if (blank($entrust)) { |
||||
|
return $this->response()->error('委托不存在'); |
||||
|
} |
||||
|
if (!$entrust->can_cancel()) return $this->response()->error('当前委托不可撤销'); |
||||
|
Log::info($entrust); |
||||
|
DB::beginTransaction(); |
||||
|
try { |
||||
|
//更新委托 |
||||
|
$res = $entrust->update([ |
||||
|
'status' => 0, |
||||
|
'cancel_time' => time(), |
||||
|
]); |
||||
|
|
||||
|
$user = User::query()->findOrFail($entrust['user_id']); |
||||
|
if ($entrust['order_type'] == 1) { |
||||
|
// 开仓方向 |
||||
|
// 合约保证金账户 |
||||
|
$wallet = SustainableAccount::query()->where(['user_id' => $entrust['user_id']])->first(); |
||||
|
if (blank($wallet)) throw new ApiException('账户类型错误'); |
||||
|
$log_type = 'cancel_open_position'; // 撤销合约委托 |
||||
|
$log_type2 = 'cancel_open_position_fee'; // 撤销合约委托 |
||||
|
//退还用户可用资产 冻结保证金 |
||||
|
$user->update_wallet_and_log($wallet['coin_id'], 'usable_balance', $entrust['margin'], UserWallet::sustainable_account, $log_type, '', $entrust['contract_id']); |
||||
|
$user->update_wallet_and_log($wallet['coin_id'], 'freeze_balance', -$entrust['margin'], UserWallet::sustainable_account, $log_type, '', $entrust['contract_id']); |
||||
|
$user->update_wallet_and_log($wallet['coin_id'], 'usable_balance', $entrust['fee'], UserWallet::sustainable_account, $log_type2, '', $entrust['contract_id']); |
||||
|
$user->update_wallet_and_log($wallet['coin_id'], 'freeze_balance', -$entrust['fee'], UserWallet::sustainable_account, $log_type2, '', $entrust['contract_id']); |
||||
|
} else { |
||||
|
// 平仓方向 |
||||
|
$position_side = $entrust['side'] == 1 ? 2 : 1; |
||||
|
// 持仓信息 |
||||
|
$position = ContractPosition::getPosition(['user_id' => $user['user_id'], 'contract_id' => $entrust['contract_id'], 'side' => $position_side]); |
||||
|
if (blank($position)) throw new ApiException(); |
||||
|
// 回退持仓数量 |
||||
|
$position->update([ |
||||
|
'avail_position' => $position->avail_position + $entrust['amount'], |
||||
|
'freeze_position' => $position->freeze_position - $entrust['amount'], |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
DB::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
DB::rollBack(); |
||||
|
throw new ApiException($e->getMessage()); |
||||
|
} |
||||
|
|
||||
|
return $this->response()->success('Processed successfully.')->refresh(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确认' . $this->title . '?']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,388 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\ContractPosition; |
||||
|
|
||||
|
use App\Exceptions\ApiException; |
||||
|
use App\Handlers\ContractTool; |
||||
|
use App\Jobs\HandleContractEntrust; |
||||
|
use App\Jobs\HandleFlatPosition; |
||||
|
use App\Models\ContractEntrust; |
||||
|
use App\Models\ContractOrder; |
||||
|
use App\Models\ContractPair; |
||||
|
use App\Models\ContractPosition; |
||||
|
use App\Models\ContractWearPositionRecord; |
||||
|
use App\Models\SustainableAccount; |
||||
|
use App\Models\User; |
||||
|
use App\Models\UserWallet; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Facades\Cache; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use Illuminate\Support\Facades\Log; |
||||
|
|
||||
|
class Flat extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '平仓'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
if (blank($id)) { |
||||
|
return $this->response()->error('Processed fail..'); |
||||
|
} |
||||
|
|
||||
|
$position = ContractPosition::query()->where('id', $id)->first(); |
||||
|
if (blank($position)) { |
||||
|
return $this->response()->error('Processed fail.'); |
||||
|
} |
||||
|
Log::info("后台平仓3"); |
||||
|
if ($position['avail_position'] == 0) return $this->response()->error('当前仓位张数为0'); |
||||
|
|
||||
|
DB::beginTransaction(); |
||||
|
try { |
||||
|
|
||||
|
if ($position['side'] == 1) { |
||||
|
// 先平仓 |
||||
|
$entrust = $this->dealManyPosition($position); |
||||
|
} else { |
||||
|
$entrust = $this->dealEmptyPosition($position); |
||||
|
} |
||||
|
if ($entrust['side'] == 1) { |
||||
|
$this->dealProfit($entrust, 'buy'); |
||||
|
} else { |
||||
|
$this->dealProfit($entrust, 'sell'); |
||||
|
} |
||||
|
|
||||
|
DB::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
DB::rollBack(); |
||||
|
return $this->response()->error('Processed fail...'); |
||||
|
} |
||||
|
|
||||
|
return $this->response()->success('Processed successfully.')->refresh(); |
||||
|
} |
||||
|
|
||||
|
private function dealProfit($entrust, $side, $system = 1) |
||||
|
{ |
||||
|
$user = User::query()->find($entrust['user_id']); |
||||
|
if ($side == 'sell') { |
||||
|
$log_type = $system == 1 ? 'system_close_long_position' : 'close_long_position'; |
||||
|
} else { |
||||
|
$log_type = $system == 1 ? 'system_close_short_position' : 'close_short_position'; |
||||
|
} |
||||
|
|
||||
|
$balance = SustainableAccount::query()->where('user_id', $entrust['user_id'])->value('usable_balance'); |
||||
|
$settle_profit = $entrust['profit']; |
||||
|
if ($settle_profit < 0 && $balance < abs($settle_profit)) { |
||||
|
$settle_profit = -$balance; |
||||
|
|
||||
|
$position_side = $side == 'sell' ? 1 : 2; |
||||
|
$open_position_price = ContractPosition::query()->where(['user_id' => $entrust['user_id'], 'contract_id' => $entrust['contract_id'], 'side' => $position_side])->value('avg_price'); |
||||
|
|
||||
|
ContractWearPositionRecord::query()->create([ |
||||
|
'user_id' => $entrust['user_id'], |
||||
|
'contract_id' => $entrust['contract_id'], |
||||
|
'symbol' => $entrust['symbol'], |
||||
|
'position_side' => $position_side, |
||||
|
'open_position_price' => $open_position_price, |
||||
|
'close_position_price' => $entrust['avg_price'], |
||||
|
'profit' => $entrust['profit'], |
||||
|
'settle_profit' => $settle_profit, |
||||
|
'loss' => $settle_profit - $entrust['profit'], |
||||
|
'ts' => time(), |
||||
|
]); |
||||
|
|
||||
|
// 更新委托 记录穿仓 |
||||
|
$entrust->update(['settle_profit' => $settle_profit, 'is_wear' => 1]); |
||||
|
} |
||||
|
|
||||
|
$user->update_wallet_and_log($entrust['margin_coin_id'], 'usable_balance', $settle_profit, UserWallet::sustainable_account, $log_type, '', $entrust['contract_id']); |
||||
|
} |
||||
|
|
||||
|
private function dealManyPosition($position, $system = 1) |
||||
|
{ |
||||
|
$pair = ContractPair::query()->find($position['contract_id']); |
||||
|
if (blank($pair)) return; |
||||
|
// 记录仓位保证金(平仓时直接抵消掉) |
||||
|
$unit_amount = $position['unit_amount']; // 单张合约面值 |
||||
|
$margin = ($position['position_margin'] / $position['hold_position']) * $position['avail_position']; |
||||
|
$unit_fee = PriceCalculate($unit_amount, '*', $pair['maker_fee_rate'], 5); // 单张合约手续费 |
||||
|
$fee = PriceCalculate($position['avail_position'], '*', $unit_fee, 5); |
||||
|
Log::info("2022-06-27 01:29:28"); |
||||
|
//用户创建平仓订单 多仓 卖出平多 |
||||
|
$order_data = [ |
||||
|
'user_id' => $position['user_id'], |
||||
|
'order_no' => get_order_sn('PCB'), |
||||
|
'contract_id' => $position['contract_id'], |
||||
|
'contract_coin_id' => $position['contract_coin_id'], |
||||
|
'margin_coin_id' => $position['margin_coin_id'], |
||||
|
'symbol' => $position['symbol'], |
||||
|
'unit_amount' => $unit_amount, |
||||
|
'order_type' => 2, |
||||
|
'side' => 2, |
||||
|
'type' => 2, // 市价 |
||||
|
'entrust_price' => null, |
||||
|
'amount' => $position['avail_position'], |
||||
|
'lever_rate' => $position['lever_rate'], |
||||
|
'margin' => $margin, |
||||
|
'fee' => $fee, |
||||
|
'hang_status' => 1, |
||||
|
'trigger_price' => null, |
||||
|
'ts' => time(), |
||||
|
'system' => 1, |
||||
|
]; |
||||
|
$sell = ContractEntrust::query()->create($order_data); |
||||
|
Log::info("2022-06-27 01:29:29"); |
||||
|
$surplus_amount = $sell['amount']; |
||||
|
$cacheKey = 'swap:trade_detail_' . $position['symbol']; |
||||
|
$cacheData = Cache::store('redis')->get($cacheKey); |
||||
|
if (blank($cacheData)) return; |
||||
|
$entrust_price = $cacheData['price']; |
||||
|
$many_position_profit = ContractTool::unRealProfit($position, $pair, $entrust_price, $position['avail_position']); |
||||
|
Log::info("2022-06-27 01:29:30"); |
||||
|
if ($surplus_amount <= 0) return; |
||||
|
$user = User::getOneSystemUser(); // 获取随机一个系统账户 |
||||
|
if (blank($user)) return; |
||||
|
|
||||
|
//创建系统用户订单 对手单 |
||||
|
$order_data2 = [ |
||||
|
'user_id' => $user['user_id'], |
||||
|
'order_no' => get_order_sn('PCB'), |
||||
|
'contract_id' => $sell['contract_id'], |
||||
|
'contract_coin_id' => $sell['contract_coin_id'], |
||||
|
'margin_coin_id' => $sell['margin_coin_id'], |
||||
|
'symbol' => $sell['symbol'], |
||||
|
'unit_amount' => $sell['unit_amount'], |
||||
|
'order_type' => 2, |
||||
|
'side' => 1, |
||||
|
'type' => 1, |
||||
|
'entrust_price' => $entrust_price, |
||||
|
'amount' => $surplus_amount, |
||||
|
'lever_rate' => $sell['lever_rate'], |
||||
|
'margin' => $margin, |
||||
|
'fee' => $fee, |
||||
|
'ts' => time(), |
||||
|
'system' => 1, |
||||
|
]; |
||||
|
$buy = ContractEntrust::query()->create($order_data2); |
||||
|
|
||||
|
$exchange_amount = $buy['amount']; |
||||
|
$unit_price = $buy['entrust_price']; |
||||
|
Log::info("2022-06-27 01:29:52"); |
||||
|
$buy_traded_amount = $buy['traded_amount'] + $exchange_amount; |
||||
|
$sell_traded_amount = $sell['traded_amount'] + $exchange_amount; |
||||
|
$buy_margin = PriceCalculate(($exchange_amount * $unit_amount), '/', $buy['lever_rate'], 5); |
||||
|
$sell_margin = PriceCalculate(($exchange_amount * $unit_amount), '/', $sell['lever_rate'], 5); |
||||
|
$buy_fee = PriceCalculate($exchange_amount, '*', $unit_fee, 5); |
||||
|
$sell_fee = PriceCalculate($exchange_amount, '*', $unit_fee, 5); |
||||
|
//增加委托成交匹配记录 |
||||
|
ContractOrder::query()->create([ |
||||
|
'contract_id' => $buy['contract_id'], |
||||
|
'symbol' => $buy['symbol'], |
||||
|
'unit_amount' => $buy['unit_amount'], |
||||
|
'order_type' => $buy['order_type'], |
||||
|
'lever_rate' => $buy['lever_rate'], |
||||
|
'buy_id' => $buy['id'], |
||||
|
'sell_id' => $sell['id'], |
||||
|
'buy_user_id' => $buy['user_id'], |
||||
|
'sell_user_id' => $sell['user_id'], |
||||
|
'unit_price' => $unit_price, |
||||
|
'trade_amount' => $exchange_amount, |
||||
|
'trade_buy_fee' => $buy_fee, |
||||
|
'trade_sell_fee' => $sell_fee, |
||||
|
'ts' => time(), |
||||
|
]); |
||||
|
|
||||
|
// 解冻合约账户保证金 & 扣除平仓手续费 |
||||
|
$log_type = $system == 1 ? 'system_close_position' : 'close_position'; |
||||
|
$log_type2 = $system == 1 ? 'system_close_position_fee' : 'close_position_fee'; |
||||
|
Log::info("2022-06-27 01:30:04"); |
||||
|
// 卖出平多 |
||||
|
$sell_user = User::query()->find($sell['user_id']); |
||||
|
if (!blank($sell_user)) { |
||||
|
// 多仓 |
||||
|
$many_position = $position; |
||||
|
Log::info($many_position['hold_position'] ."----" .$exchange_amount); |
||||
|
Log::info($many_position['avail_position'] ."----" .$exchange_amount); |
||||
|
Log::info($many_position['position_margin'] ."----" .$sell_margin); |
||||
|
$many_position->update([ |
||||
|
'hold_position' => $many_position['hold_position'] - $exchange_amount, |
||||
|
'avail_position' => $many_position['avail_position'] - $exchange_amount, |
||||
|
'position_margin' => $many_position['position_margin'] - $sell_margin, |
||||
|
]); |
||||
|
$sell_user->update_wallet_and_log($sell['margin_coin_id'], 'usable_balance', $sell_margin, UserWallet::sustainable_account, $log_type, '', $sell['contract_id']); |
||||
|
Log::info("99999"); |
||||
|
// $sell_user->update_wallet_and_log($sell['margin_coin_id'], 'used_balance', -$sell_margin, UserWallet::sustainable_account, $log_type, '', $sell['contract_id']); |
||||
|
Log::info("99999"); |
||||
|
$sell_user->update_wallet_and_log($sell['margin_coin_id'], 'usable_balance', -$sell_fee, UserWallet::sustainable_account, $log_type2, '', $sell['contract_id']); |
||||
|
Log::info("99999"); |
||||
|
} |
||||
|
//更新买卖委托 |
||||
|
$buy->update(['traded_amount' => $buy_traded_amount, 'status' => ContractEntrust::status_completed]); |
||||
|
$sell->update(['traded_amount' => $sell_traded_amount, 'avg_price' => $entrust_price, 'profit' => $many_position_profit, 'status' => ContractEntrust::status_completed]); |
||||
|
|
||||
|
return $sell; |
||||
|
} |
||||
|
|
||||
|
private function dealEmptyPosition($position, $system = 1) |
||||
|
{ |
||||
|
$pair = ContractPair::query()->find($position['contract_id']); |
||||
|
if (blank($pair)) return; |
||||
|
// 记录仓位保证金(平仓时直接抵消掉) |
||||
|
$unit_amount = $position['unit_amount']; // 单张合约面值 |
||||
|
$margin = ($position['position_margin'] / $position['hold_position']) * $position['avail_position']; |
||||
|
$unit_fee = PriceCalculate($unit_amount, '*', $pair['maker_fee_rate'], 5); // 单张合约手续费 |
||||
|
$fee = PriceCalculate($position['avail_position'], '*', $unit_fee, 5); |
||||
|
//用户创建平仓订单 空仓 买入平空 |
||||
|
$order_data = [ |
||||
|
'user_id' => $position['user_id'], |
||||
|
'order_no' => get_order_sn('PCB'), |
||||
|
'contract_id' => $position['contract_id'], |
||||
|
'contract_coin_id' => $position['contract_coin_id'], |
||||
|
'margin_coin_id' => $position['margin_coin_id'], |
||||
|
'symbol' => $position['symbol'], |
||||
|
'unit_amount' => $unit_amount, |
||||
|
'order_type' => 2, |
||||
|
'side' => 1, |
||||
|
'type' => 2, // 市价 |
||||
|
'entrust_price' => null, |
||||
|
'amount' => $position['avail_position'], |
||||
|
'lever_rate' => $position['lever_rate'], |
||||
|
'margin' => $margin, |
||||
|
'fee' => $fee, |
||||
|
'hang_status' => 1, |
||||
|
'trigger_price' => null, |
||||
|
'ts' => time(), |
||||
|
'system' => 1, |
||||
|
]; |
||||
|
$buy = ContractEntrust::query()->create($order_data); |
||||
|
$surplus_amount = $buy['amount']; |
||||
|
$cacheKey = 'swap:trade_detail_' . $buy['symbol']; |
||||
|
$cacheData = Cache::store('redis')->get($cacheKey); |
||||
|
if (blank($cacheData)) return; |
||||
|
$entrust_price = $cacheData['price']; |
||||
|
$empty_position_profit = ContractTool::unRealProfit($position, $pair, $entrust_price, $position['avail_position']); |
||||
|
|
||||
|
if ($surplus_amount <= 0) return; |
||||
|
$user = User::getOneSystemUser(); // 获取随机一个系统账户 |
||||
|
if (blank($user)) return; |
||||
|
//创建对手委托 |
||||
|
$order_data2 = [ |
||||
|
'user_id' => $user['user_id'], |
||||
|
'order_no' => get_order_sn('PCB'), |
||||
|
'contract_id' => $buy['contract_id'], |
||||
|
'contract_coin_id' => $buy['contract_coin_id'], |
||||
|
'margin_coin_id' => $buy['margin_coin_id'], |
||||
|
'symbol' => $buy['symbol'], |
||||
|
'unit_amount' => $buy['unit_amount'], |
||||
|
'order_type' => 2, |
||||
|
'side' => 2, |
||||
|
'type' => 1, |
||||
|
'entrust_price' => $entrust_price, |
||||
|
'amount' => $surplus_amount, |
||||
|
'lever_rate' => $buy['lever_rate'], |
||||
|
'ts' => time(), |
||||
|
'system' => 1, |
||||
|
]; |
||||
|
$sell = ContractEntrust::query()->create($order_data2); |
||||
|
|
||||
|
$exchange_amount = $sell['amount']; |
||||
|
$unit_price = $sell['entrust_price']; |
||||
|
|
||||
|
$buy_traded_amount = $buy['traded_amount'] + $exchange_amount; |
||||
|
$sell_traded_amount = $sell['traded_amount'] + $exchange_amount; |
||||
|
$buy_margin = PriceCalculate(($exchange_amount * $unit_amount), '/', $buy['lever_rate'], 5); |
||||
|
$sell_margin = PriceCalculate(($exchange_amount * $unit_amount), '/', $sell['lever_rate'], 5); |
||||
|
$buy_fee = PriceCalculate($exchange_amount, '*', $unit_fee, 5); |
||||
|
$sell_fee = PriceCalculate($exchange_amount, '*', $unit_fee, 5); |
||||
|
//增加委托成交匹配记录 |
||||
|
ContractOrder::query()->create([ |
||||
|
'contract_id' => $buy['contract_id'], |
||||
|
'symbol' => $buy['symbol'], |
||||
|
'unit_amount' => $buy['unit_amount'], |
||||
|
'order_type' => $buy['order_type'], |
||||
|
'lever_rate' => $buy['lever_rate'], |
||||
|
'buy_id' => $buy['id'], |
||||
|
'sell_id' => $sell['id'], |
||||
|
'buy_user_id' => $buy['user_id'], |
||||
|
'sell_user_id' => $sell['user_id'], |
||||
|
'unit_price' => $unit_price, |
||||
|
'trade_amount' => $exchange_amount, |
||||
|
'trade_buy_fee' => $buy_fee, |
||||
|
'trade_sell_fee' => $sell_fee, |
||||
|
'ts' => time(), |
||||
|
]); |
||||
|
// 解冻合约账户保证金 & 扣除平仓手续费 |
||||
|
$log_type = $system == 1 ? 'system_close_position' : 'close_position'; |
||||
|
$log_type2 = $system == 1 ? 'system_close_position_fee' : 'close_position_fee'; |
||||
|
// 买入平空 |
||||
|
$buy_user = User::query()->find($buy['user_id']); |
||||
|
if (!blank($buy_user)) { |
||||
|
// 空仓 |
||||
|
$empty_position = $position; |
||||
|
// if($sell['id'] == 240){ |
||||
|
// $buy_margin= $buy_margin - 0.00001; |
||||
|
// } |
||||
|
Log::info("平仓开始"); |
||||
|
Log::info($empty_position['hold_position'] ."----" .$exchange_amount); |
||||
|
Log::info($empty_position['avail_position'] ."----" .$exchange_amount); |
||||
|
Log::info($empty_position['position_margin'] ."----" .$buy_margin); |
||||
|
$empty_position->update([ |
||||
|
'hold_position' => $empty_position['hold_position'] - $exchange_amount, |
||||
|
'avail_position' => $empty_position['avail_position'] - $exchange_amount, |
||||
|
'position_margin' => $empty_position['position_margin'] - $buy_margin, |
||||
|
]); |
||||
|
$buy_user->update_wallet_and_log($buy['margin_coin_id'], 'usable_balance', $buy_margin, UserWallet::sustainable_account, $log_type, '', $buy['contract_id']); |
||||
|
$buy_user->update_wallet_and_log($buy['margin_coin_id'], 'used_balance', -$buy_margin, UserWallet::sustainable_account, $log_type, '', $buy['contract_id']); |
||||
|
$buy_user->update_wallet_and_log($buy['margin_coin_id'], 'usable_balance', -$buy_fee, UserWallet::sustainable_account, $log_type2, '', $buy['contract_id']); |
||||
|
} |
||||
|
|
||||
|
//更新买卖委托 |
||||
|
$buy->update(['traded_amount' => $buy_traded_amount, 'avg_price' => $entrust_price, 'profit' => $empty_position_profit, 'status' => ContractEntrust::status_completed]); |
||||
|
$sell->update(['traded_amount' => $sell_traded_amount, 'status' => ContractEntrust::status_completed]); |
||||
|
|
||||
|
return $buy; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确认' . $this->title . '?']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,103 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\ContractPosition; |
||||
|
|
||||
|
use App\Jobs\HandleFlatPosition; |
||||
|
use App\Models\ContractEntrust; |
||||
|
use App\Models\ContractPosition; |
||||
|
use App\Models\User; |
||||
|
use App\Services\ContractService; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class OnekeyFlatPosition extends Action |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '一键平仓'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$items = ContractPosition::query()->where('hold_position', '>', 0)->get()->groupBy('user_id'); |
||||
|
// dd($items->toArray()); |
||||
|
|
||||
|
if (!blank($items)) { |
||||
|
DB::beginTransaction(); |
||||
|
try { |
||||
|
|
||||
|
foreach ($items as $user_id => $positions) { |
||||
|
$user = User::query()->find($user_id); |
||||
|
if (blank($user)) continue; |
||||
|
// 撤销未完成的委托 |
||||
|
$entrusts = ContractEntrust::query() |
||||
|
->where('user_id', $user['user_id']) |
||||
|
->whereIn('status', [ContractEntrust::status_wait, ContractEntrust::status_trading]) |
||||
|
->get(); |
||||
|
if (!blank($entrusts)) { |
||||
|
foreach ($entrusts as $entrust) { |
||||
|
$params2 = ['entrust_id' => $entrust['id'], 'symbol' => $entrust['symbol']]; |
||||
|
(new ContractService())->cancelEntrust($user, $params2); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 平仓 |
||||
|
HandleFlatPosition::dispatch($positions)->onQueue('HandleFlatPosition'); |
||||
|
} |
||||
|
|
||||
|
DB::commit(); |
||||
|
|
||||
|
return $this->response()->success('Processed successfully.')->refresh(); |
||||
|
} catch (\Exception $e) { |
||||
|
DB::rollBack(); |
||||
|
return $this->response()->error($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定执行' . $this->title . '?', '该操作会撤销所有用户的未完成委托,然后全部平仓']; |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
protected function html() |
||||
|
{ |
||||
|
return <<<HTML |
||||
|
<a {$this->formatHtmlAttributes()}><button class="btn btn-danger btn-mini">{$this->title()}</button></a> |
||||
|
HTML; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,90 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid; |
||||
|
|
||||
|
use App\Models\UserWallet; |
||||
|
use App\Models\WalletCollection; |
||||
|
use App\Services\CoinService\BitCoinService; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class BTCCollect extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '归集'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
if (blank($id)) { |
||||
|
return $this->response()->error('Processed fail.'); |
||||
|
} |
||||
|
$wallet_address = UserWallet::query()->where('wallet_id', $id)->value('wallet_address'); |
||||
|
if (blank($wallet_address)) return $this->response()->error('地址为空'); |
||||
|
|
||||
|
$min_amount = config('coin.collect_min_amount.btc'); |
||||
|
$to = \App\Models\CenterWallet::query()->where('center_wallet_account', 'btc_collection_account')->value('center_wallet_address'); |
||||
|
$balance = (new BitCoinService())->getBalance($wallet_address); |
||||
|
// if($balance < $min_amount) return $this->response()->error('余额小于最小额度'); |
||||
|
|
||||
|
$res = (new BitCoinService())->collection($wallet_address, $to, $balance); |
||||
|
if ($res) { |
||||
|
$txid = $res; |
||||
|
$status = 1; |
||||
|
WalletCollection::query()->create([ |
||||
|
'symbol' => 'BTC', |
||||
|
'from' => $wallet_address, |
||||
|
'to' => $to, |
||||
|
'amount' => $balance, |
||||
|
'txid' => $txid, |
||||
|
'datetime' => time(), |
||||
|
'note' => '', |
||||
|
'status' => $status, |
||||
|
]); |
||||
|
return $this->response() |
||||
|
->success('Processed successfully: ' . $this->getKey()) |
||||
|
->refresh(); |
||||
|
} else { |
||||
|
return $this->response()->error('归集失败'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,110 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-29 10:40:49 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-09 17:45:52 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid; |
||||
|
|
||||
|
use App\Models\UserWallet; |
||||
|
use App\Models\WalletCollection; |
||||
|
use App\Services\CoinService\GethService; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class ETHCollect extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '归集'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
if (blank($id)) { |
||||
|
return $this->response()->error('Processed fail.'); |
||||
|
} |
||||
|
$wallet_address = UserWallet::query()->where('wallet_id', $id)->value('wallet_address'); |
||||
|
if (blank($wallet_address)) return $this->response()->error('地址为空'); |
||||
|
|
||||
|
$min_amount = config('coin.collect_min_amount.eth'); |
||||
|
$to = \App\Models\CenterWallet::query()->where('center_wallet_account', 'eth_collection_account')->value('center_wallet_address'); |
||||
|
$balance = (new GethService())->getBalance($wallet_address); |
||||
|
// if($balance < $min_amount) return $this->response()->error('余额小于最小额度'); |
||||
|
|
||||
|
$res = (new GethService())->collection($wallet_address, $to, $balance); |
||||
|
if ($res) { |
||||
|
$txid = $res; |
||||
|
$status = 1; |
||||
|
WalletCollection::query()->create([ |
||||
|
'symbol' => 'ETH', |
||||
|
'from' => $wallet_address, |
||||
|
'to' => $to, |
||||
|
'amount' => $balance, |
||||
|
'txid' => $txid, |
||||
|
'datetime' => time(), |
||||
|
'note' => '', |
||||
|
'status' => $status, |
||||
|
]); |
||||
|
return $this->response() |
||||
|
->success('归集成功,等待区块网络确认') |
||||
|
->refresh(); |
||||
|
} else { |
||||
|
$txid = ''; |
||||
|
$status = 0; |
||||
|
WalletCollection::query()->create([ |
||||
|
'symbol' => 'ETH', |
||||
|
'from' => $wallet_address, |
||||
|
'to' => $to, |
||||
|
'amount' => $balance, |
||||
|
'txid' => $txid, |
||||
|
'datetime' => time(), |
||||
|
'note' => '', |
||||
|
'status' => $status, |
||||
|
]); |
||||
|
return $this->response()->error('归集失败,已加入待归集任务列表'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,135 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid; |
||||
|
|
||||
|
use App\Jobs\CoinCollection; |
||||
|
use App\Models\UserWallet; |
||||
|
use App\Models\WalletCollection; |
||||
|
use App\Services\CoinService\GethService; |
||||
|
use App\Services\CoinService\GethTokenService; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use phpseclib\Math\BigInteger as BigNumber; |
||||
|
use Web3\Utils; |
||||
|
|
||||
|
class ETHUSDTCollect extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '归集'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
if (blank($id)) { |
||||
|
return $this->response()->error('Processed fail.'); |
||||
|
} |
||||
|
$wallet_address = UserWallet::query()->where('wallet_id', $id)->value('wallet_address'); |
||||
|
if (blank($wallet_address)) return $this->response()->error('地址为空'); |
||||
|
|
||||
|
$min_amount = config('coin.collect_min_amount.usdt'); |
||||
|
$to = \App\Models\CenterWallet::query()->where('center_wallet_account', 'eth_collection_account')->value('center_wallet_address'); |
||||
|
$contractAddress = config('coin.erc20_usdt.contractAddress'); |
||||
|
$abi = config('coin.erc20_usdt.abi'); |
||||
|
$balance = (new GethTokenService($contractAddress, $abi))->getBalance($wallet_address); |
||||
|
// if($balance < $min_amount) return $this->response()->error('余额小于最小额度'); |
||||
|
|
||||
|
// 判断用户地址有没有可用的ETH手续费 |
||||
|
$gasPrice = Utils::toHex(Utils::toWei((new GethService())->getEthGasPrice('fast'), 'Gwei'), true); |
||||
|
$gas = (new GethService())->getGasUse(); |
||||
|
$collect_fee = new BigNumber((hexdec($gasPrice) * hexdec($gas))); |
||||
|
$min_fee = (new GethService())->weiToEther($collect_fee); |
||||
|
$ether = (new GethService())->getBalance($wallet_address); |
||||
|
if ($ether < $min_fee) { |
||||
|
$fee_res = (new GethService())->sendFee($wallet_address); |
||||
|
if ($fee_res) { |
||||
|
$txid = $fee_res; |
||||
|
$status = 0; |
||||
|
WalletCollection::query()->create([ |
||||
|
'symbol' => 'ETH_USDT', |
||||
|
'from' => $wallet_address, |
||||
|
'to' => $to, |
||||
|
'amount' => $balance, |
||||
|
'txid' => $txid, |
||||
|
'datetime' => time(), |
||||
|
'note' => '', |
||||
|
'status' => $status, |
||||
|
]); |
||||
|
return $this->response()->warning('已发送归集手续费,等待归集中'); |
||||
|
} else { |
||||
|
return $this->response()->warning('发送手续费失败,手续费账户余额不足'); |
||||
|
} |
||||
|
} else { |
||||
|
$res = (new GethTokenService($contractAddress, $abi))->collection($wallet_address, $to, $balance); |
||||
|
if ($res) { |
||||
|
$txid = $res; |
||||
|
$status = 1; |
||||
|
WalletCollection::query()->create([ |
||||
|
'symbol' => 'ETH_USDT', |
||||
|
'from' => $wallet_address, |
||||
|
'to' => $to, |
||||
|
'amount' => $balance, |
||||
|
'txid' => $txid, |
||||
|
'datetime' => time(), |
||||
|
'note' => '', |
||||
|
'status' => $status, |
||||
|
]); |
||||
|
return $this->response() |
||||
|
->success('归集成功,等待区块网络确认') |
||||
|
->refresh(); |
||||
|
} else { |
||||
|
$txid = ''; |
||||
|
$status = 0; |
||||
|
WalletCollection::query()->create([ |
||||
|
'symbol' => 'ETH_USDT', |
||||
|
'from' => $wallet_address, |
||||
|
'to' => $to, |
||||
|
'amount' => $balance, |
||||
|
'txid' => $txid, |
||||
|
'datetime' => time(), |
||||
|
'note' => '', |
||||
|
'status' => $status, |
||||
|
]); |
||||
|
return $this->response()->error('归集失败,已加入待归集任务列表'); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['Confirm?', '确认?']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,138 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid; |
||||
|
|
||||
|
use App\Models\UserWallet; |
||||
|
use App\Models\WalletCollection; |
||||
|
use App\Services\CoinService\OmnicoreService; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class OmniusdtCollection extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '归集'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
if (blank($id)) { |
||||
|
return $this->response()->error('Processed fail.'); |
||||
|
} |
||||
|
$wallet_address = UserWallet::query()->where('wallet_id', $id)->value('omni_wallet_address'); |
||||
|
if (blank($wallet_address)) return $this->response()->error('地址为空'); |
||||
|
|
||||
|
$min_amount = config('coin.collect_min_amount.usdt'); |
||||
|
$to = \App\Models\CenterWallet::query()->where('center_wallet_account', 'btc_collection_account')->value('center_wallet_address'); |
||||
|
$balance = (new OmnicoreService())->getBalance($wallet_address); |
||||
|
// if($balance < $min_amount) return $this->response()->error('余额小于最小额度'); |
||||
|
|
||||
|
$res = (new OmnicoreService())->collection($wallet_address, $to, $balance); |
||||
|
if ($res === false) { |
||||
|
$fee_res = (new OmnicoreService())->sendFee($wallet_address); |
||||
|
if ($fee_res) { |
||||
|
$txid = $fee_res; |
||||
|
$status = 0; |
||||
|
WalletCollection::query()->create([ |
||||
|
'symbol' => 'BTC_USDT', |
||||
|
'from' => $wallet_address, |
||||
|
'to' => $to, |
||||
|
'amount' => $balance, |
||||
|
'txid' => $txid, |
||||
|
'datetime' => time(), |
||||
|
'note' => '', |
||||
|
'status' => $status, |
||||
|
]); |
||||
|
return $this->response()->warning('已发送归集手续费,等待归集中'); |
||||
|
} else { |
||||
|
return $this->response()->warning('发送手续费失败,手续费账户余额不足'); |
||||
|
} |
||||
|
} else { |
||||
|
$txid = $res; |
||||
|
$status = 1; |
||||
|
WalletCollection::query()->create([ |
||||
|
'symbol' => 'BTC_USDT', |
||||
|
'from' => $wallet_address, |
||||
|
'to' => $to, |
||||
|
'amount' => $balance, |
||||
|
'txid' => $txid, |
||||
|
'datetime' => time(), |
||||
|
'note' => '', |
||||
|
'status' => $status, |
||||
|
]); |
||||
|
return $this->response() |
||||
|
->success('归集成功,等待区块网络确认') |
||||
|
->refresh(); |
||||
|
} |
||||
|
// if($res){ |
||||
|
// $txid = $res; |
||||
|
// $status = 1; |
||||
|
// WalletCollection::query()->create([ |
||||
|
// 'symbol' => 'BTC_USDT', |
||||
|
// 'from' => $wallet_address, |
||||
|
// 'to' => $to, |
||||
|
// 'amount' => $balance, |
||||
|
// 'txid' => $txid, |
||||
|
// 'datetime' => time(), |
||||
|
// 'note' => '', |
||||
|
// 'status' => $status, |
||||
|
// ]); |
||||
|
// return $this->response() |
||||
|
// ->success('归集成功,等待区块网络确认') |
||||
|
// ->refresh(); |
||||
|
// }else{ |
||||
|
// $txid = ''; |
||||
|
// $status = 0; |
||||
|
// WalletCollection::query()->create([ |
||||
|
// 'symbol' => 'BTC_USDT', |
||||
|
// 'from' => $wallet_address, |
||||
|
// 'to' => $to, |
||||
|
// 'amount' => $balance, |
||||
|
// 'txid' => $txid, |
||||
|
// 'datetime' => time(), |
||||
|
// 'note' => '', |
||||
|
// 'status' => $status, |
||||
|
// ]); |
||||
|
// return $this->response()->error('归集失败,已加入待归集任务列表'); |
||||
|
// } |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,101 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid; |
||||
|
|
||||
|
use App\Models\UserWallet; |
||||
|
use App\Models\WalletCollection; |
||||
|
use App\Services\CoinService\TronService; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class TRXCollect extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '归集'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
if (blank($id)) { |
||||
|
return $this->response()->error('Processed fail.'); |
||||
|
} |
||||
|
$wallet_address = UserWallet::query()->where('wallet_id', $id)->value('wallet_address'); |
||||
|
if (blank($wallet_address)) return $this->response()->error('地址为空'); |
||||
|
|
||||
|
$min_amount = config('coin.collect_min_amount.trx'); |
||||
|
$to = \App\Models\CenterWallet::query()->where('center_wallet_account', 'trx_collection_account')->value('center_wallet_address'); |
||||
|
$balance = (new TronService())->getBalance($wallet_address); |
||||
|
|
||||
|
$res = (new TronService())->collection($wallet_address, $to, $balance); |
||||
|
if ($res) { |
||||
|
$txid = $res; |
||||
|
$status = 1; |
||||
|
WalletCollection::query()->create([ |
||||
|
'symbol' => 'TRX', |
||||
|
'from' => $wallet_address, |
||||
|
'to' => $to, |
||||
|
'amount' => $balance, |
||||
|
'txid' => $txid, |
||||
|
'datetime' => time(), |
||||
|
'note' => '', |
||||
|
'status' => $status, |
||||
|
]); |
||||
|
return $this->response() |
||||
|
->success('归集成功,等待区块网络确认') |
||||
|
->refresh(); |
||||
|
} else { |
||||
|
$txid = ''; |
||||
|
$status = 0; |
||||
|
WalletCollection::query()->create([ |
||||
|
'symbol' => 'TRX', |
||||
|
'from' => $wallet_address, |
||||
|
'to' => $to, |
||||
|
'amount' => $balance, |
||||
|
'txid' => $txid, |
||||
|
'datetime' => time(), |
||||
|
'note' => '', |
||||
|
'status' => $status, |
||||
|
]); |
||||
|
return $this->response()->error('归集失败,已加入待归集任务列表'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,76 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid; |
||||
|
|
||||
|
use App\Jobs\CoinCollection; |
||||
|
use App\Models\UserWallet; |
||||
|
use App\Models\WalletCollection; |
||||
|
use App\Services\CoinService\GethService; |
||||
|
use App\Services\CoinService\GethTokenService; |
||||
|
use App\Services\CoinService\TronService; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use phpseclib\Math\BigInteger as BigNumber; |
||||
|
use Web3\Utils; |
||||
|
|
||||
|
class TRXUSDTCollect extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '归集'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
if (blank($id)) { |
||||
|
return $this->response()->error('Processed fail.'); |
||||
|
} |
||||
|
$wallet_address = UserWallet::query()->where('wallet_id', $id)->value('wallet_address'); |
||||
|
if (blank($wallet_address)) return $this->response()->error('地址为空'); |
||||
|
|
||||
|
$min_amount = config('coin.collect_min_amount.usdt'); |
||||
|
$to = \App\Models\CenterWallet::query()->where('center_wallet_account', 'trx_collection_account')->value('center_wallet_address'); |
||||
|
$balance = (new TronService())->getTokenBalance(1, $wallet_address); |
||||
|
|
||||
|
// TODO 判断用户地址有没有可用的手续费 |
||||
|
return $this->response()->warning('......'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['Confirm?', '确认?']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\InsideTradePair; |
||||
|
|
||||
|
use App\Models\InsideTradePair; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class Close extends Action |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '交易关闭'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
DB::beginTransaction(); |
||||
|
try { |
||||
|
|
||||
|
$res = InsideTradePair::query()->where('status', 1)->update(['trade_status' => 0]); |
||||
|
|
||||
|
DB::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
DB::rollBack(); |
||||
|
throw $e; |
||||
|
} |
||||
|
|
||||
|
return $this->response()->success('Processed successfully.')->refresh(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定全部' . $this->title . '?']; |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
protected function html() |
||||
|
{ |
||||
|
return <<<HTML |
||||
|
<a {$this->formatHtmlAttributes()}><button class="btn btn-primary btn-mini">{$this->title()}</button></a> |
||||
|
HTML; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,86 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-29 10:40:49 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-09 17:45:58 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Actions\InsideTradePair; |
||||
|
|
||||
|
use App\Models\InsideTradePair; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\BatchAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class Open extends Action |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '交易开启'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
DB::beginTransaction(); |
||||
|
try { |
||||
|
|
||||
|
$res = InsideTradePair::query()->where('status', 1)->update(['trade_status' => 1]); |
||||
|
|
||||
|
DB::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
DB::rollBack(); |
||||
|
throw $e; |
||||
|
} |
||||
|
|
||||
|
return $this->response()->success('Processed successfully.')->refresh(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定全部' . $this->title . '?']; |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
protected function html() |
||||
|
{ |
||||
|
return <<<HTML |
||||
|
<a {$this->formatHtmlAttributes()}><button class="btn btn-primary btn-mini">{$this->title()}</button></a> |
||||
|
HTML; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\OptionPair; |
||||
|
|
||||
|
use App\Models\OptionPair; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class Close extends Action |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '交易关闭'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
DB::beginTransaction(); |
||||
|
try { |
||||
|
|
||||
|
$res = OptionPair::query()->where('status', 1)->update(['trade_status' => 0]); |
||||
|
|
||||
|
DB::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
DB::rollBack(); |
||||
|
throw $e; |
||||
|
} |
||||
|
|
||||
|
return $this->response()->success('Processed successfully.')->refresh(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定全部' . $this->title . '?']; |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
protected function html() |
||||
|
{ |
||||
|
return <<<HTML |
||||
|
<a {$this->formatHtmlAttributes()}><button class="btn btn-primary btn-mini">{$this->title()}</button></a> |
||||
|
HTML; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,85 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-29 10:40:49 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-09 17:46:01 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Actions\OptionPair; |
||||
|
|
||||
|
use App\Models\OptionPair; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class Open extends Action |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '交易开启'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
DB::beginTransaction(); |
||||
|
try { |
||||
|
|
||||
|
$res = OptionPair::query()->where('status', 1)->update(['trade_status' => 1]); |
||||
|
|
||||
|
DB::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
DB::rollBack(); |
||||
|
throw $e; |
||||
|
} |
||||
|
|
||||
|
return $this->response()->success('Processed successfully.')->refresh(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定全部' . $this->title . '?']; |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
protected function html() |
||||
|
{ |
||||
|
return <<<HTML |
||||
|
<a {$this->formatHtmlAttributes()}><button class="btn btn-primary btn-mini">{$this->title()}</button></a> |
||||
|
HTML; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,105 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\OptionSceneOrder; |
||||
|
|
||||
|
use App\Models\OptionSceneOrder; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\BatchAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class Handle extends BatchAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '结算异常订单'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$keys = $this->getKey(); |
||||
|
|
||||
|
$orders = OptionSceneOrder::query()->find($keys); |
||||
|
|
||||
|
try { |
||||
|
DB::beginTransaction(); |
||||
|
|
||||
|
foreach ($orders as $order) { |
||||
|
if ($order->status != OptionSceneOrder::status_delivered) { |
||||
|
return $this->response()->error('Processed fail.')->refresh(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
DB::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
DB::rollBack(); |
||||
|
throw $e; |
||||
|
} |
||||
|
|
||||
|
return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
return ['确定' . $this->title . '?']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
public function actionScript() |
||||
|
{ |
||||
|
$warning = "请选择内容!"; |
||||
|
|
||||
|
return <<<JS |
||||
|
function (data, target, action) { |
||||
|
console.log('发起请求之前', {data, target, action}); |
||||
|
var key = {$this->getSelectedKeysScript()} |
||||
|
|
||||
|
if (key.length === 0) { |
||||
|
Dcat.warning('{$warning}'); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
// 设置主键为复选框选中的行ID数组 |
||||
|
action.options.key = key; |
||||
|
} |
||||
|
JS; |
||||
|
} |
||||
|
protected function html() |
||||
|
{ |
||||
|
return <<<HTML |
||||
|
<a {$this->formatHtmlAttributes()}><button class="btn btn-primary btn-mini">{$this->title()}</button></a> |
||||
|
HTML; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,99 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Performance; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class ChangeStatus extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '审核'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = "ChangeStatus-{$this->getKey()}"; |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">{$this->title}</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new \App\Admin\Forms\Performance\ChangeStatus($this->getKey()); |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">{$this->title}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,102 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class Pertain extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '归属'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = "user-pertain-{$this->getKey()}"; |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">归属</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new \App\Admin\Forms\pertain($this->getKey()); |
||||
|
|
||||
|
// 在弹窗标题处显示当前行的用户名 |
||||
|
$username = $this->row->username ?? ''; |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">归属 - {$username}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,110 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-08-04 22:36:15 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-09 17:46:04 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
namespace App\Admin\Actions\Place; |
||||
|
|
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Support\Str; |
||||
|
|
||||
|
class AddPlace extends Action |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '添加渠道商'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = get_order_sn('su'); |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">{$this->title}</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new \App\Admin\Forms\Place\AddPlace(); |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">{$this->title}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,104 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-08-05 11:35:45 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-07 00:58:42 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Actions\Place; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use App\Models\User; |
||||
|
use App\Models\AgentUser; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class DeletePlace extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '删除渠道商'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
try { |
||||
|
DB::beginTransaction(); |
||||
|
$user_id = $this->getKey(); |
||||
|
$user = User::find($user_id); |
||||
|
// 1、更新用户渠道商状态 |
||||
|
$user->update(['is_place' => 0]); |
||||
|
// 2、删除用户登录渠道商后台权限 |
||||
|
DB::table('agent_admin_role_users') |
||||
|
->where(['user_id' => $user_id, 'role_id' => 3]) |
||||
|
->delete(); |
||||
|
// 3、查询用户是否是代理商、如果不是 删除userAgent表中的代理信息 |
||||
|
if ($user->is_agency == 0) { |
||||
|
AgentUser::query() |
||||
|
->where('id', $user_id) |
||||
|
->delete(); |
||||
|
} |
||||
|
DB::commit(); |
||||
|
return $this->response() |
||||
|
->success('删除成功: ' . $this->getKey()) |
||||
|
->refresh(); |
||||
|
} catch (\Exception $e) { |
||||
|
info($e); |
||||
|
return $this->response() |
||||
|
->error('删除失败'); |
||||
|
} |
||||
|
|
||||
|
return $this->response() |
||||
|
->success('删除成功: ' . $this->getKey()) |
||||
|
->refresh(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定删除该用户渠道商权限?', '删除之后,若用户为代理商仍可登录代理商后台,但无法查看渠道商菜单']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
// 判断该用户是否是渠道商 |
||||
|
|
||||
|
return (User::find($this->getKey())->is_place == 1) ? true : false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
public function html() |
||||
|
{ |
||||
|
|
||||
|
$this->appendHtmlAttribute('class', 'btn btn-outline-primary btn-sm btn-mini submit'); |
||||
|
return parent::html(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-08-05 10:46:43 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-05 11:32:23 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
namespace App\Admin\Actions\Place; |
||||
|
|
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use App\Admin\Forms\Place\ToBeAgent as ToBeAgentForm; |
||||
|
use App\Admin\Extensions\Widgets\Modal; |
||||
|
|
||||
|
class ToBeAgent extends RowAction |
||||
|
{ |
||||
|
protected $title = "升为代理商"; |
||||
|
|
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$form = ToBeAgentForm::make()->payload(['id' => $this->getKey()]); |
||||
|
|
||||
|
return Modal::make() |
||||
|
->lg() |
||||
|
->title($this->title) |
||||
|
->body($form) |
||||
|
->canClick(($this->row->is_agency == 1) ? false : true) |
||||
|
->button($this->title); |
||||
|
} |
||||
|
|
||||
|
public function html() |
||||
|
{ |
||||
|
|
||||
|
$this->setHtmlAttribute(['class' => 'btn btn-primary btn-sm btn-mini submit']); |
||||
|
return parent::html(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,141 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Author: your name |
||||
|
* @Date: 2021-06-02 15:08:59 |
||||
|
* @LastEditTime: 2021-06-04 22:19:29 |
||||
|
* @LastEditors: Please set LastEditors |
||||
|
* @Description: In User Settings Edit |
||||
|
* @FilePath: \Dcat\app\Admin\Actions\User\Recharge.php |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Actions\Recharge; |
||||
|
|
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Widgets\Table; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use App\Models\RechargeManual; |
||||
|
|
||||
|
class Agree extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* 按钮标题 |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '充值'; |
||||
|
|
||||
|
/** |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $modalId = 'show-current-user'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* 处理当前动作的请求接口,如果不需要请直接删除 |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
|
||||
|
$this->model = new RechargeManual; |
||||
|
if (!$this->model->agree($id)) { |
||||
|
return $this->response() |
||||
|
->error('充值失败'); |
||||
|
} |
||||
|
return $this->response() |
||||
|
->success('充值成功') |
||||
|
->refresh(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理响应的HTML字符串,附加到弹窗节点中 |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected function handleHtmlResponse() |
||||
|
{ |
||||
|
return <<<'JS' |
||||
|
function (target, html, data) { |
||||
|
var $modal = $(target.data('target')); |
||||
|
|
||||
|
$modal.find('.modal-body').html(html) |
||||
|
$modal.modal('show') |
||||
|
} |
||||
|
JS; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置HTML标签的属性 |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
protected function setUpHtmlAttributes() |
||||
|
{ |
||||
|
// 添加class |
||||
|
$this->addHtmlClass('btn btn-sm btn-outline-primary nowrap'); |
||||
|
|
||||
|
// 保留弹窗的ID |
||||
|
// $this->setHtmlAttribute('data-target', '#' . $this->modalId); |
||||
|
// 设置style样式 |
||||
|
$this->setHtmlAttribute('style', 'white-space:nowrap'); |
||||
|
if ($this->row->status !== 0) { |
||||
|
$this->addHtmlClass('disabled'); |
||||
|
} |
||||
|
|
||||
|
parent::setUpHtmlAttributes(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 设置按钮的HTML,这里我们需要附加上弹窗的HTML |
||||
|
* |
||||
|
* @return string|void |
||||
|
*/ |
||||
|
public function html() |
||||
|
{ |
||||
|
// 按钮的html |
||||
|
$html = parent::html(); |
||||
|
|
||||
|
return <<<HTML |
||||
|
{$html} |
||||
|
<div class="modal fade" id="{$this->modalId}" tabindex="-1" role="dialog"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
<h4 class="modal-title">{$this->title()}</h4> |
||||
|
</div> |
||||
|
<div class="modal-body"></div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定充值?', '确定给该用户充值吗?']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 动作权限判断,返回false则标识无权限,如果不需要可以删除此方法 |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,137 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Recharge; |
||||
|
|
||||
|
use App\Admin\Forms\Recharge\Check; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\BatchAction; |
||||
|
use Dcat\Admin\Grid\GridAction; |
||||
|
use Dcat\Admin\Form\AbstractTool; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class Pass extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '充币审核'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = "recharge-{$this->getKey()}"; |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">审核</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new Check($this->getKey()); |
||||
|
|
||||
|
// 在弹窗标题处显示当前行的用户名 |
||||
|
$username = $this->row->username; |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">充币审核 - {$username}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
// /** |
||||
|
// * 添加JS |
||||
|
// * |
||||
|
// * @return string |
||||
|
// */ |
||||
|
// protected function script() |
||||
|
// { |
||||
|
// return <<<JS |
||||
|
//$('.grid-check-row').on('click', function () { |
||||
|
// |
||||
|
// // Your code. |
||||
|
// console.log($(this).data('id')); |
||||
|
// |
||||
|
//}); |
||||
|
//JS; |
||||
|
// } |
||||
|
// |
||||
|
// public function html() |
||||
|
// { |
||||
|
// // 获取当前行数据ID |
||||
|
// $id = $this->getKey(); |
||||
|
// |
||||
|
// // 获取当前行数据的用户名 |
||||
|
// $username = $this->row->username; |
||||
|
// |
||||
|
// // 这里需要添加一个class, 和上面script方法对应 |
||||
|
// $this->setHtmlAttribute(['data-id' => $id, 'email' => $username, 'class' => 'grid-check-row']); |
||||
|
// |
||||
|
// return parent::html(); |
||||
|
// } |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,157 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Author: your name |
||||
|
* @Date: 2021-06-02 15:08:59 |
||||
|
* @LastEditTime: 2021-06-04 22:19:53 |
||||
|
* @LastEditors: Please set LastEditors |
||||
|
* @Description: In User Settings Edit |
||||
|
* @FilePath: \Dcat\app\Admin\Actions\User\Recharge.php |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Actions\Recharge; |
||||
|
|
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Widgets\Table; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use App\Models\RechargeManual; |
||||
|
|
||||
|
class Reject extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* 按钮标题 |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '驳回'; |
||||
|
|
||||
|
/** |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $modalId = 'show-current-user'; |
||||
|
|
||||
|
// public function __construct($id) |
||||
|
// { |
||||
|
// $this->id = $id; |
||||
|
// } |
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* 处理当前动作的请求接口,如果不需要请直接删除 |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
|
||||
|
$this->model = new RechargeManual; |
||||
|
if (!$this->model->reject($id)) { |
||||
|
return $this->response() |
||||
|
->error('驳回失败'); |
||||
|
} |
||||
|
return $this->response() |
||||
|
->success('驳回成功') |
||||
|
->refresh(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理响应的HTML字符串,附加到弹窗节点中 |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected function handleHtmlResponse() |
||||
|
{ |
||||
|
return <<<'JS' |
||||
|
function (target, html, data) { |
||||
|
var $modal = $(target.data('target')); |
||||
|
|
||||
|
$modal.find('.modal-body').html(html) |
||||
|
$modal.modal('show') |
||||
|
} |
||||
|
JS; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置HTML标签的属性 |
||||
|
* |
||||
|
* @return void |
||||
|
*/ |
||||
|
protected function setUpHtmlAttributes() |
||||
|
{ |
||||
|
// 添加class |
||||
|
$this->addHtmlClass('btn btn-sm btn-outline-primary nowrap'); |
||||
|
|
||||
|
// 保留弹窗的ID |
||||
|
// $this->setHtmlAttribute('data-target', '#' . $this->modalId); |
||||
|
// 设置style样式 |
||||
|
$this->setHtmlAttribute('style', 'white-space:nowrap'); |
||||
|
if ($this->row->status !== 0) { |
||||
|
$this->addHtmlClass('disabled'); |
||||
|
} |
||||
|
parent::setUpHtmlAttributes(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 设置按钮的HTML,这里我们需要附加上弹窗的HTML |
||||
|
* |
||||
|
* @return string|void |
||||
|
*/ |
||||
|
public function html() |
||||
|
{ |
||||
|
// 按钮的html |
||||
|
$html = parent::html(); |
||||
|
|
||||
|
return <<<HTML |
||||
|
{$html} |
||||
|
<div class="modal fade" id="{$this->modalId}" tabindex="-1" role="dialog"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
<h4 class="modal-title">{$this->title()}</h4> |
||||
|
</div> |
||||
|
<div class="modal-body"></div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定驳回?', '确定驳回该充值申请吗?']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 动作权限判断,返回false则标识无权限,如果不需要可以删除此方法 |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 通过这个方法可以设置动作发起请求时需要附带的参数,如果不需要可以删除此方法 |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return [ |
||||
|
// 'id' => $this->getKey() |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
// 发起请求之前执行的js代码 actionScript |
||||
|
} |
||||
@ -0,0 +1,102 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace App\Admin\Actions\User; |
||||
|
|
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Support\Str; |
||||
|
|
||||
|
class AddContractControl extends Action |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '新增K线风控'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = get_order_sn('su'); |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">{$this->title}</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new \App\Admin\Forms\ContractRisknew(); |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">{$this->title}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,102 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace App\Admin\Actions\User; |
||||
|
|
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Support\Str; |
||||
|
|
||||
|
class AddPromotionUser extends Action |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '批量新增推广用户'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = get_order_sn('su'); |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">{$this->title}</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new \App\Admin\Forms\User\AddPromotionUser(); |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">{$this->title}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,102 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace App\Admin\Actions\User; |
||||
|
|
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Support\Str; |
||||
|
|
||||
|
class AddSystemUser extends Action |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '新增系统账户'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = get_order_sn('su'); |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">{$this->title}</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new \App\Admin\Forms\User\AddSystemUser(); |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">{$this->title}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,102 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace App\Admin\Actions\User; |
||||
|
|
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Support\Str; |
||||
|
|
||||
|
class AddUser extends Action |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '添加用户'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = get_order_sn('su'); |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">{$this->title}</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new \App\Admin\Forms\User\AddUser(); |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">{$this->title}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,102 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\User; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class CheckAuth extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '审核'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = "withdraw-{$this->getKey()}"; |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">审核</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new \App\Admin\Forms\CheckAuth($this->getKey()); |
||||
|
|
||||
|
// 在弹窗标题处显示当前行的用户名 |
||||
|
$realname = $this->row->realname ?? ''; |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">认证审核 - {$realname}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,102 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\User; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class MarkSystemUser extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '系统账户'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = "user-MarkSystemUser-{$this->getKey()}"; |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">{$this->title}</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new \App\Admin\Forms\User\MarkSystemUser($this->getKey()); |
||||
|
|
||||
|
// 在弹窗标题处显示当前行的用户名 |
||||
|
$username = $this->row->username ?? ''; |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">{$this->title} - {$username}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,102 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\User; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class ModifyPassword extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '修改密码'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = "user-ModifyPassword-{$this->getKey()}"; |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">{$this->title}</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new \App\Admin\Forms\User\ModifyPassword($this->getKey()); |
||||
|
|
||||
|
// 在弹窗标题处显示当前行的用户名 |
||||
|
$username = $this->row->username ?? ''; |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">{{$this->title}} - {$username}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,119 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\User; |
||||
|
|
||||
|
use App\Models\User; |
||||
|
use App\Models\UserAuth; |
||||
|
use Carbon\Carbon; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\BatchAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class PassUserAuth extends BatchAction |
||||
|
{ |
||||
|
protected $style = 'btn btn-sm btn-default'; |
||||
|
|
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '审核通过'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$keys = $this->getKey(); |
||||
|
$status = 1; |
||||
|
|
||||
|
$auths = UserAuth::query()->find($keys); |
||||
|
|
||||
|
try { |
||||
|
DB::beginTransaction(); |
||||
|
|
||||
|
foreach ($auths as $auth) { |
||||
|
if ($auth->status != UserAuth::STATUS_WAIT) { |
||||
|
return $this->response()->error('Processed fail.')->refresh(); |
||||
|
} |
||||
|
|
||||
|
$auth->status = $status == 1 ? UserAuth::STATUS_AUTH : UserAuth::STATUS_REJECT; |
||||
|
$auth->check_time = Carbon::now()->toDateTimeString(); |
||||
|
$auth->save(); |
||||
|
|
||||
|
if ($status == 1) { |
||||
|
$user = $auth->user; |
||||
|
$user->update(['user_auth_level' => User::user_auth_level_top]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
DB::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
DB::rollBack(); |
||||
|
throw $e; |
||||
|
} |
||||
|
|
||||
|
return $this->response()->success('Processed successfully.')->refresh(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
return ['确定认证' . $this->title . '?']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
public function actionScript() |
||||
|
{ |
||||
|
$warning = "请选择审核的内容!"; |
||||
|
|
||||
|
return <<<JS |
||||
|
function (data, target, action) { |
||||
|
console.log('发起请求之前', {data, target, action}); |
||||
|
var key = {$this->getSelectedKeysScript()} |
||||
|
|
||||
|
if (key.length === 0) { |
||||
|
Dcat.warning('{$warning}'); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
// 设置主键为复选框选中的行ID数组 |
||||
|
action.options.key = key; |
||||
|
} |
||||
|
JS; |
||||
|
} |
||||
|
protected function html() |
||||
|
{ |
||||
|
return <<<HTML |
||||
|
<a {$this->formatHtmlAttributes()}><button class="btn btn-primary btn-mini">{$this->title()}</button></a> |
||||
|
HTML; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,101 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\User; |
||||
|
|
||||
|
use App\Models\UserAuth; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\BatchAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class RejectUserAuth extends BatchAction |
||||
|
{ |
||||
|
protected $style = 'btn btn-sm btn-default'; |
||||
|
|
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '审核驳回'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$keys = $this->getKey(); |
||||
|
$status = 0; |
||||
|
|
||||
|
$auths = UserAuth::query()->find($keys); |
||||
|
|
||||
|
foreach ($auths as $auth) { |
||||
|
if ($auth->status != UserAuth::STATUS_WAIT) { |
||||
|
return $this->response()->error('Processed fail.')->refresh(); |
||||
|
} |
||||
|
|
||||
|
$auth->status = $status == 1 ? UserAuth::STATUS_AUTH : UserAuth::STATUS_REJECT; |
||||
|
$auth->save(); |
||||
|
} |
||||
|
|
||||
|
return $this->response()->success('Processed successfully.')->refresh(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
return ['确定认证' . $this->title . '?']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
public function actionScript() |
||||
|
{ |
||||
|
$warning = "请选择审核的内容!"; |
||||
|
|
||||
|
return <<<JS |
||||
|
function (data, target, action) { |
||||
|
console.log('发起请求之前', {data, target, action}); |
||||
|
var key = {$this->getSelectedKeysScript()} |
||||
|
|
||||
|
if (key.length === 0) { |
||||
|
Dcat.warning('{$warning}'); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
// 设置主键为复选框选中的行ID数组 |
||||
|
action.options.key = key; |
||||
|
} |
||||
|
JS; |
||||
|
} |
||||
|
protected function html() |
||||
|
{ |
||||
|
return <<<HTML |
||||
|
<a {$this->formatHtmlAttributes()}><button class="btn btn-primary btn-mini">{$this->title()}</button></a> |
||||
|
HTML; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,74 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\User; |
||||
|
|
||||
|
use App\Models\AdminModifyPasswordLogs; |
||||
|
use App\Models\User; |
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class RestorePassword extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
// protected $title = '恢复密码'; |
||||
|
|
||||
|
public function title() |
||||
|
{ |
||||
|
return '<button class="btn btn-sm btn-outline-primary">恢复密码</button>'; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$user_id = $this->getKey(); |
||||
|
$user = User::query()->find($user_id); |
||||
|
if (!$user) return $this->response()->error('记录不存在'); |
||||
|
|
||||
|
$modifyPasswordLog = AdminModifyPasswordLogs::query()->latest()->first(); |
||||
|
if (blank($modifyPasswordLog)) return $this->response()->error('没有修改过密码'); |
||||
|
|
||||
|
$user->update(['password' => $modifyPasswordLog['user_password_hash']]); |
||||
|
|
||||
|
return $this->response()->success('Processed successfully.')->refresh(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定执行该操作?']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-31 18:31:44 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-05 10:26:20 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Actions\User; |
||||
|
|
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use App\Admin\Forms\User\UpdateToAgent as UpdateToAgentForm; |
||||
|
use App\Admin\Extensions\Widgets\Modal; |
||||
|
|
||||
|
class UpdateToAgent extends RowAction |
||||
|
{ |
||||
|
protected $title = "升为代理"; |
||||
|
|
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$form = UpdateToAgentForm::make()->payload(['id' => $this->getKey()]); |
||||
|
|
||||
|
return Modal::make() |
||||
|
->lg() |
||||
|
->title($this->title) |
||||
|
->body($form) |
||||
|
->canClick(($this->row->is_place == 1) || ($this->row->is_agency == 1) ? false : true) |
||||
|
->button($this->title); |
||||
|
} |
||||
|
|
||||
|
public function html() |
||||
|
{ |
||||
|
|
||||
|
$this->setHtmlAttribute(['class' => 'btn btn-primary btn-sm btn-mini submit']); |
||||
|
return parent::html(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-31 18:31:44 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-05 10:26:01 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Actions\User; |
||||
|
|
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use App\Admin\Forms\User\UpdateToPlace as UpdateToPlaceForm; |
||||
|
use App\Admin\Extensions\Widgets\Modal; |
||||
|
|
||||
|
class UpdateToPlace extends RowAction |
||||
|
{ |
||||
|
protected $title = "升为渠道商"; |
||||
|
|
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$form = UpdateToPlaceForm::make()->payload(['id' => $this->getKey()]); |
||||
|
|
||||
|
return Modal::make() |
||||
|
->lg() |
||||
|
->title($this->title) |
||||
|
->body($form) |
||||
|
->canClick(($this->row->is_place == 1) || ($this->row->is_agency == 1) ? false : true) |
||||
|
->button($this->title); |
||||
|
} |
||||
|
|
||||
|
public function html() |
||||
|
{ |
||||
|
|
||||
|
$this->setHtmlAttribute(['class' => 'btn btn-primary btn-sm btn-mini submit']); |
||||
|
return parent::html(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,102 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\User; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class recharge extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '充值'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = "user-recharge-{$this->getKey()}"; |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">充值</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new \App\Admin\Forms\User\recharge($this->getKey()); |
||||
|
|
||||
|
// 在弹窗标题处显示当前行的用户名 |
||||
|
$username = $this->row->username ?? ''; |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">充值 - {$username}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,102 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Withdraw; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Action; |
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class Check extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '提币审核'; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = "withdraw-{$this->getKey()}"; |
||||
|
|
||||
|
// 模态窗 |
||||
|
$this->modal($id); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
|
<a class="btn btn-sm btn-outline-primary" href="javascript:void(0)">审核</a> |
||||
|
</span> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
protected function modal($id) |
||||
|
{ |
||||
|
// 工具表单 |
||||
|
$form = new \App\Admin\Forms\Withdraw\Check($this->getKey()); |
||||
|
|
||||
|
// 在弹窗标题处显示当前行的用户名 |
||||
|
$username = $this->row->username; |
||||
|
|
||||
|
// 通过 Admin::html 方法设置模态窗HTML |
||||
|
Admin::html( |
||||
|
<<<HTML |
||||
|
<div class="modal fade" id="{$id}"> |
||||
|
<div class="modal-dialog modal-lg" role="document"> |
||||
|
<div class="modal-content"> |
||||
|
<div class="modal-header"> |
||||
|
<h4 class="modal-title">提币审核 - {$username}</h4> |
||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
|
</div> |
||||
|
<div class="modal-body"> |
||||
|
{$form->render()} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// dump($this->getKey()); |
||||
|
|
||||
|
// return $this->response()->success('Processed successfully.')->redirect('/'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
// return ['Confirm?', 'contents']; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return array |
||||
|
*/ |
||||
|
protected function parameters() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Repositories\AdminSetting; |
||||
|
use App\Models\Admin\AdminSetting as Setting; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Layout\Content; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Card; |
||||
|
|
||||
|
class AdminSettingController extends AdminController |
||||
|
{ |
||||
|
public function index(Content $content) |
||||
|
{ |
||||
|
return $content |
||||
|
->title('网站设置') |
||||
|
->body(new Card(new \App\Admin\Forms\Setting())); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,106 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\Advice; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use function foo\func; |
||||
|
|
||||
|
class AdviceController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new Advice(), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc("created_at"); |
||||
|
$grid->id->sortable(); |
||||
|
$grid->column("user_id", "用户id"); |
||||
|
$grid->column("phone", "手机号"); |
||||
|
$grid->column("email", "邮箱"); |
||||
|
$grid->column("realname", "真实姓名"); |
||||
|
$grid->column("contents", "内容"); |
||||
|
|
||||
|
$grid->column("is_process", "处理结果")->display(function () { |
||||
|
if ($this->is_process == 0) { |
||||
|
return "<label style='color: red'>未处理</label>"; |
||||
|
} |
||||
|
return "<label style='color:dodgerblue'>已处理</label>"; |
||||
|
}); |
||||
|
$grid->process_note; |
||||
|
$grid->process_time; |
||||
|
$grid->created_at; |
||||
|
$grid->updated_at->sortable(); |
||||
|
|
||||
|
$grid->disableCreateButton(); |
||||
|
//$grid->disableDeleteButton(); |
||||
|
//$grid->disableEditButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('id'); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new Advice(), function (Show $show) { |
||||
|
$show->id; |
||||
|
$show->user_id; |
||||
|
$show->phone; |
||||
|
|
||||
|
$show->realname; |
||||
|
$show->contents; |
||||
|
|
||||
|
$show->is_process->using(Advice::$statusMap); |
||||
|
$show->process_note; |
||||
|
$show->process_time; |
||||
|
$show->created_at; |
||||
|
// $show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new Advice(), function (Form $form) { |
||||
|
$form->text('id')->display(false); |
||||
|
/* $form->text('user_id',"用户id")->readOnly(); |
||||
|
$form->text('phone',"手机号"); |
||||
|
$form->text('email',"邮箱"); |
||||
|
$form->text('realname',"真实姓名");*/ |
||||
|
$form->text('contents', "内容")->readOnly(); |
||||
|
|
||||
|
$form->select('is_process', "处理结果")->options([ |
||||
|
"0" => "未处理", |
||||
|
"1" => "已处理" |
||||
|
]); |
||||
|
$form->textarea('process_note'); |
||||
|
|
||||
|
//$form->display('created_at'); |
||||
|
$form->text('updated_at')->display(false); |
||||
|
|
||||
|
$form->saved(function (Form $form) { |
||||
|
if ($form->isEditing()) { |
||||
|
$form->process_time = date("Y-m-d H:i:s"); |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Repositories\AdvicesCategory; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class AdvicesCategoryController extends AdminController |
||||
|
{ |
||||
|
protected $title = "咨询项目"; |
||||
|
|
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new AdvicesCategory(), function (Grid $grid) { |
||||
|
$grid->model()->orderBy("order"); |
||||
|
//$grid->id; |
||||
|
$grid->name; |
||||
|
$grid->column('status', "状态")->switch(); |
||||
|
$grid->column("order", "排序"); |
||||
|
// $grid->model()->orderByDesc('created_at'); |
||||
|
$grid->actions(function (Grid\Displayers\Actions $actions) { |
||||
|
|
||||
|
|
||||
|
$actions->disableView(); |
||||
|
}); |
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->panel(); |
||||
|
$filter->like('name', "问题类型")->width(2)->placeholder("请输入问题类型"); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new AdvicesCategory(), function (Show $show) { |
||||
|
$show->id; |
||||
|
$show->name; |
||||
|
$show->order; |
||||
|
$show->status; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new AdvicesCategory(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->switch('status', "状态")->default(1); |
||||
|
$form->number('order', "排序"); |
||||
|
$form->hasMany('translations', '语言', function (Form\NestedForm $form) { |
||||
|
$form->select('locale')->options(['en' => '英', 'zh-CN' => '中', "zh-TW" => "繁体"])->default('zh-CN')->label(); |
||||
|
$form->text('name', "名称")->required(); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,176 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-29 10:40:49 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-17 14:56:13 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Actions\Agent\ChangeStatus; |
||||
|
use App\Handlers\ContractTool; |
||||
|
use App\Models\Agent; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Models\User; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use App\Models\AgentUser; |
||||
|
|
||||
|
use App\Admin\Actions\Agent\DeleteAgent; |
||||
|
use App\Admin\Actions\Agent\ToBePlace; |
||||
|
use App\Admin\Renderable\TradeStatistics; |
||||
|
|
||||
|
class AgentController extends \Dcat\Admin\Controllers\AdminController |
||||
|
{ |
||||
|
protected $title = "代理商列表"; |
||||
|
public function grid() |
||||
|
{ |
||||
|
|
||||
|
return Grid::make(Agent::with('agent_user'), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('user_id'); |
||||
|
$grid->actions(function (Grid\Displayers\Actions $actions) { |
||||
|
$actions->disableDelete(); |
||||
|
$actions->disableQuickEdit(); |
||||
|
$actions->disableView(); |
||||
|
if ($actions->row->status == 0) { |
||||
|
$actions->append(new ChangeStatus()); |
||||
|
}; |
||||
|
$actions->append(new DeleteAgent()); |
||||
|
$actions->append(ToBePlace::make()->canClick($this->is_place == 0)); |
||||
|
}); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->column('user_id', '代理商UID')->sortable()->link(function ($v) { |
||||
|
return admin_url('/users/', [$v]); |
||||
|
}, ''); |
||||
|
$grid->column('agent_user.username', '用户名')->help('用于登录渠道商/代理商后台的用户名'); |
||||
|
$grid->column('agent_user.name', '姓名')->help('代理商/渠道商姓名'); |
||||
|
$grid->column("pid", "邀请人UID"); |
||||
|
$grid->column("referrer", "上级代理UID"); |
||||
|
$grid->column('agname','代理邮箱')->display(function (){ |
||||
|
$var = ContractTool::GetProxyEmail($this->user_id); |
||||
|
//dd($var['username']); |
||||
|
return $var['username']; |
||||
|
}); |
||||
|
$grid->column('invite_code', '邀请码')->copyable(); |
||||
|
$grid->column("团队人数")->display(function () { |
||||
|
|
||||
|
$data = []; |
||||
|
return collect(User::recursion($this->user_id,$data))->count(); |
||||
|
// return 1; |
||||
|
|
||||
|
}); |
||||
|
$grid->column('content', '统计')->display('统计')->expand(TradeStatistics::make()); |
||||
|
// $grid->column('agent_user.rebate_rate', '默认返佣比率')->append('%'); |
||||
|
// $grid->column('agent_user.rebate_rate_exchange', '币币返佣比率')->append('%'); |
||||
|
// $grid->column('agent_user.rebate_rate_subscribe', '申购返佣比率')->append('%'); |
||||
|
// $grid->column('agent_user.rebate_rate_contract', '合约返佣比率')->append('%'); |
||||
|
// $grid->column('agent_user.rebate_rate_option', '期权返佣比率')->append('%'); |
||||
|
$grid->column('agent_user.is_show_auth','是否查看实名')->switch(); |
||||
|
$grid->column('identity', '身份')->display(function () { |
||||
|
if ($this->is_agency == 1) $iden[] = '代理商'; |
||||
|
if ($this->is_place == 1) $iden[] = '渠道商'; |
||||
|
return $iden ?? []; |
||||
|
})->label(); |
||||
|
|
||||
|
$grid->column('agent_user.status', '状态')->using(AgentUser::$userStatusMap)->dot([0 => 'danger', 1 => 'success']); |
||||
|
$grid->column('agent_user.created_at', '创建时间'); |
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->panel(); |
||||
|
$filter->between('agent_user.created_at', '创建时间')->date(); |
||||
|
$filter->equal('user_id', '代理商UID')->width(4); |
||||
|
$filter->like("agent_user.username", "代理商名称")->width(5); |
||||
|
}); |
||||
|
|
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new Agent(), function (Show $show) { |
||||
|
$show->user_id; |
||||
|
$show->account; |
||||
|
$show->account_type; |
||||
|
$show->username; |
||||
|
$show->pid; |
||||
|
|
||||
|
$show->path; |
||||
|
$show->country_code; |
||||
|
$show->phone; |
||||
|
|
||||
|
$show->password; |
||||
|
$show->payword; |
||||
|
$show->invite_code; |
||||
|
$show->user_grade; |
||||
|
$show->user_identity; |
||||
|
$show->user_auth_level; |
||||
|
$show->login_code; |
||||
|
$show->status; |
||||
|
$show->reg_ip; |
||||
|
$show->last_login_time; |
||||
|
$show->last_login_ip; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(Agent::with('agent_user'), function (Form $form) { |
||||
|
$form->hidden('user_id')->readOnly(); |
||||
|
$form->text('agent_user.username', '登录账户')->required()->help('用户登录代理后台的账户'); |
||||
|
$form->text('agent_user.name', '姓名')->required()->help('登记代理姓名'); |
||||
|
$form->text('invite_code', '邀请码')->rules('required'); |
||||
|
$form->text('pid', '邀请人UID'); |
||||
|
$form->text('referrer', '上级代理商UID'); |
||||
|
$form->switch('agent_user.is_show_auth','是否查看实名'); |
||||
|
$form->rate('agent_user.rebate_rate', '默认返佣比率')->required(); |
||||
|
$form->radio('agent_user.rebate_rate_exchange', '详细设置') |
||||
|
->when(1, function (Form $form) { |
||||
|
$form->rate('agent_user.rebate_rate_exchange', '币币返佣比率'); |
||||
|
$form->rate('agent_user.rebate_rate_subscribe', '申购返佣比率'); |
||||
|
$form->rate('agent_user.rebate_rate_contract', '合约返佣比率'); |
||||
|
$form->rate('agent_user.rebate_rate_option', '期权返佣比率'); |
||||
|
})->options([0 => '隐藏', 1 => '显示'])->default(0); |
||||
|
$form->image("agent_user.avatar", "头像")->rules('required:users,avatar')->autoUpload(); |
||||
|
$form->password('agent_user.password', "密码")->placeholder('留空则不修改'); |
||||
|
$form->saving(function (Form $form) { |
||||
|
// if (blank($form->agent_user['password'])) { //如果密码为空 |
||||
|
// $form->deleteInput('agent_user.password'); |
||||
|
// } |
||||
|
// $form->is_agency = 1; # 1:标记为代理商 |
||||
|
// if (User::isInviteCodeExist($form->code, $form->user_id)) { |
||||
|
// return $form->error('邀请码已存在'); |
||||
|
// } |
||||
|
// if (AgentUser::isUsernameExist($form->agent_user['username'], $form->user_id)) { |
||||
|
// return $form->error('用户名已存在'); |
||||
|
// } |
||||
|
}); |
||||
|
|
||||
|
// $form->saved(function (Form $form) { |
||||
|
// if ($form->isCreating()) { |
||||
|
// $id = $form->getKey(); |
||||
|
// User::find($id)->update(['is_agency' => 1]); |
||||
|
// DB::table("agent_admin_role_users")->insert(["role_id" => 2, "user_id" => $id]); |
||||
|
// } |
||||
|
// }); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,66 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\AgentGrade; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class AgentGradeController extends AdminController |
||||
|
{ |
||||
|
protected $title = "代理级别"; |
||||
|
|
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new AgentGrade(), function (Grid $grid) { |
||||
|
$grid->id->sortable(); |
||||
|
// $grid->key; |
||||
|
$grid->column('value', '名称')->editable(true)->help('点击编辑'); |
||||
|
|
||||
|
$grid->disableActions(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableBatchDelete(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('id'); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new AgentGrade(), function (Show $show) { |
||||
|
$show->id; |
||||
|
$show->key; |
||||
|
$show->value; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new AgentGrade(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->text('key'); |
||||
|
$form->text('value', '名称'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,82 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\AppVersion; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class AppVersionController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new AppVersion(), function (Grid $grid) { |
||||
|
|
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
$grid->disableCreateButton(); |
||||
|
|
||||
|
$grid->column('id')->sortable(); |
||||
|
$grid->column('client_type')->using([1 => 'Android', 2 => 'IOS'])->badge([1 => 'info', 2 => 'success']); |
||||
|
$grid->column('version'); |
||||
|
$grid->column('is_must')->using([0 => '否', 1 => '是'])->label([0 => 'default', 1 => 'success']); |
||||
|
$grid->column('url'); |
||||
|
$grid->column('update_log'); |
||||
|
$grid->column('created_at'); |
||||
|
// $grid->column('updated_at')->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
// $filter->equal('id'); |
||||
|
|
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new AppVersion(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('client_type'); |
||||
|
$show->field('version'); |
||||
|
$show->field('is_must'); |
||||
|
$show->field('url'); |
||||
|
$show->field('update_log'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new AppVersion(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->hidden('client_type'); |
||||
|
$form->text('version'); |
||||
|
$form->switch('is_must'); |
||||
|
$form->text('url'); |
||||
|
$form->editor('update_log'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,104 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\ArticleCategory; |
||||
|
use App\Models\Banner; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Layout\Content; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Layout\Row; |
||||
|
use Dcat\Admin\Tree; |
||||
|
|
||||
|
class ArticleCategoryController extends AdminController |
||||
|
{ |
||||
|
public function index(Content $content) |
||||
|
{ |
||||
|
return $content->header('文章分类') |
||||
|
->body(function (Row $row) { |
||||
|
$tree = new Tree(new ArticleCategory); |
||||
|
|
||||
|
$row->column(12, $tree); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new ArticleCategory(), function (Grid $grid) { |
||||
|
$grid->id->sortable(); |
||||
|
$grid->pid; |
||||
|
// $grid->names; |
||||
|
$grid->order; |
||||
|
$grid->created_at; |
||||
|
$grid->updated_at->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('id'); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new ArticleCategory(), function (Show $show) { |
||||
|
$show->id; |
||||
|
// $show->names; |
||||
|
$show->pid; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
$builder = ArticleCategory::with('translations'); |
||||
|
return Form::make($builder, function (Form $form) { |
||||
|
// $form->tab('基本信息', function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->select('pid')->options(ArticleCategory::selectOptions())->default(0); |
||||
|
// $form->text('names'); |
||||
|
$form->text('order'); |
||||
|
$form->text("url"); |
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
|
||||
|
$form->hasMany('translations', '语言', function (Form\NestedForm $form) { |
||||
|
$form->select('locale')->options(['en' => '英', 'zh-CN' => '中', "zh-TW" => "繁体",'kor' => '韩文', |
||||
|
'jp' => '日文', |
||||
|
'de' => '德文', |
||||
|
'it' => '意大利文', |
||||
|
'nl' => '荷兰文', |
||||
|
'pl' => '波兰文', |
||||
|
'pt' => '葡萄牙文', |
||||
|
'spa' => '西班牙文', |
||||
|
'swe' => '瑞典文', |
||||
|
'tr' => '土耳其文', |
||||
|
'uk' => '乌克兰文',])->default('zh-CN')->label(); |
||||
|
$form->text('name'); |
||||
|
}); |
||||
|
|
||||
|
/* })->tab('内容编辑', function (Form $form) { |
||||
|
|
||||
|
});*/ |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,159 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\Article; |
||||
|
use App\Models\ArticleCategory; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Card; |
||||
|
use Illuminate\Support\Facades\App; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class ArticleController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new Article(), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('id'); |
||||
|
$grid->id->sortable(); |
||||
|
$grid->column("admin_user_id", "文章作者(id)")->display(function () { |
||||
|
$res = DB::table("admin_users")->where("id", $this->admin_user_id)->select("name", "id")->first(); |
||||
|
$name = $res->name; |
||||
|
$id = $res->id; |
||||
|
return $name . "(" . $id . ")"; |
||||
|
}); |
||||
|
|
||||
|
$grid->title; |
||||
|
$grid->cover->image('', 50, 50); |
||||
|
$grid->body->display('详情') // 设置按钮名称 |
||||
|
->expand(function () { |
||||
|
// 返回显示的详情 |
||||
|
// 这里返回 content 字段内容,并用 Card 包裹起来 |
||||
|
$card = new Card(null, $this->body); |
||||
|
|
||||
|
return "<div style='padding:10px 10px 0'>$card</div>"; |
||||
|
}); |
||||
|
$grid->category_id->display(function ($id) { |
||||
|
return blank($cat = ArticleCategory::query()->where('id', $id)->first()) ? '' : $cat->name; |
||||
|
}); |
||||
|
$grid->view_count; |
||||
|
$grid->is_recommend; |
||||
|
|
||||
|
$grid->status->using([0 => '不显示', 1 => '显示'])->label([0 => 'default', 1 => 'success']); |
||||
|
$grid->order; |
||||
|
$grid->created_at; |
||||
|
// $grid->updated_at->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->panel(); |
||||
|
// $filter->equal('id')->width(2)->placeholder("请输入ID"); |
||||
|
// $filter->in('category_id')->select(ArticleCategory::selectOptions()); |
||||
|
|
||||
|
$filter->where('category_id', function ($query) { |
||||
|
|
||||
|
$subIds = ArticleCategory::getSubChildren($this->input); |
||||
|
|
||||
|
if (blank($subIds)) { |
||||
|
$query->where('category_id', $this->input); |
||||
|
} else { |
||||
|
$subIds[] = $this->input; |
||||
|
$query->whereIn('category_id', $subIds); |
||||
|
} |
||||
|
}, '分类')->select(ArticleCategory::selectOptions()); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new Article(), function (Show $show) { |
||||
|
$show->id; |
||||
|
$show->admin_user_id; |
||||
|
$show->body; |
||||
|
$show->title; |
||||
|
$show->category_id; |
||||
|
$show->view_count; |
||||
|
$show->cover; |
||||
|
$show->is_recommend; |
||||
|
$show->status; |
||||
|
$show->order; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
$builder = Article::with('translations'); |
||||
|
|
||||
|
return Form::make($builder, function (Form $form) { |
||||
|
|
||||
|
$form->tab('基本信息', function (Form $form) { |
||||
|
|
||||
|
$form->display('id'); |
||||
|
$form->select('category_id')->options(ArticleCategory::selectOptions()); |
||||
|
$form->file('cover')->accept('jpg,png,gif,jpeg,mp4')->maxSize("20480")->autoUpload(); |
||||
|
$form->switch('status')->default(1); |
||||
|
$form->number('order')->default(1); |
||||
|
$form->select("is_recommend", '是否推荐')->options([0 => "不推荐", 1 => "推荐"])->default(0); |
||||
|
// $form->number('view_count'); |
||||
|
if ($form->isCreating()) { |
||||
|
$form->display('created_at'); |
||||
|
} else { |
||||
|
$form->datetime('created_at'); |
||||
|
} |
||||
|
// $form->display('updated_at'); |
||||
|
|
||||
|
})->tab('内容编辑', function (Form $form) { |
||||
|
$form->hasMany('translations', '内容编辑', function (Form\NestedForm $form) { |
||||
|
|
||||
|
$lang = [ |
||||
|
'en' => '英', |
||||
|
'zh-CN' => '中', |
||||
|
"zh-TW" => "繁体", |
||||
|
'kor' => '韩文', |
||||
|
'jp' => '日文', |
||||
|
'de' => '德文', |
||||
|
'it' => '意大利文', |
||||
|
'nl' => '荷兰文', |
||||
|
'pl' => '波兰文', |
||||
|
'pt' => '葡萄牙文', |
||||
|
'spa' => '西班牙文', |
||||
|
'swe' => '瑞典文', |
||||
|
'tr' => '土耳其文', |
||||
|
'uk' => '乌克兰文', |
||||
|
'vie' => '越南语', |
||||
|
'fra' => '法文', |
||||
|
]; |
||||
|
|
||||
|
|
||||
|
$form->select('locale')->options($lang)->default('zh-CN'); |
||||
|
|
||||
|
$form->text('title'); |
||||
|
$form->textarea('excerpt'); |
||||
|
$form->editor('body'); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,120 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/** |
||||
|
* Created by PhpStorm. |
||||
|
* User: Administrator |
||||
|
* Date: 2020/7/29 |
||||
|
* Time: 19:36 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Handlers\ContractTool; |
||||
|
use App\Models\Agent; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Models\TransferRecord; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class AssetDetailsController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(TransferRecord::with(['user']), function (Grid $grid) { |
||||
|
// xlsx |
||||
|
$titles = ['id' => 'ID', 'user_id' => 'UID', 'username' => '用户名', 'coin_name' => '币名', 'direction' => '方向', 'amount' => '金额', 'datetime' => '时间', 'status' => '状态']; |
||||
|
$grid->export()->titles($titles)->rows(function (array $rows) use ($titles) { |
||||
|
foreach ($rows as $index => &$row) { |
||||
|
$row['username'] = $row['user']['username']; |
||||
|
$row['datetime'] = date('Y-m-d H:i:s', $row['datetime']); |
||||
|
$row['direction'] = (TransferRecord::$accountMap[$row['draw_out_direction']] ?? '--') . ' -> ' . (TransferRecord::$accountMap[$row['into_direction']] ?? '--'); |
||||
|
$row['status'] = TransferRecord::$statusMap[$row['status']]; |
||||
|
} |
||||
|
return $rows; |
||||
|
})->xlsx(); |
||||
|
|
||||
|
$grid->model()->orderByDesc('id'); |
||||
|
// 这里的字段会自动使用翻译文件 |
||||
|
$grid->id; |
||||
|
$grid->user_id; |
||||
|
$grid->column('user.username', '用户名'); |
||||
|
$grid->column('agname','代理邮箱')->display(function (){ |
||||
|
|
||||
|
$var = ContractTool::GetProxyEmail($this->user_id); |
||||
|
//dd($var['username']); |
||||
|
return $var['username']; |
||||
|
}); |
||||
|
$grid->coin_name; |
||||
|
$grid->column('direction', '方向')->display(function () { |
||||
|
return (TransferRecord::$accountMap[$this->draw_out_direction] ?? '--') . ' -> ' . (TransferRecord::$accountMap[$this->into_direction] ?? '--'); |
||||
|
}); |
||||
|
$grid->amount; |
||||
|
$grid->column('datetime', '时间')->display(function ($datetime) { |
||||
|
return date('Y-m-d H:i:s', $datetime); |
||||
|
}); |
||||
|
$grid->status->using(TransferRecord::$statusMap)->dot([1 => 'success', 2 => 'error']); |
||||
|
|
||||
|
$grid->disableActions(); |
||||
|
$grid->disableCreateButton(); |
||||
|
// $grid->disableRowSelector(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->whereBetween('datetime', function ($q) { |
||||
|
$start = $this->input['start'] ? strtotime($this->input['start']) : null; |
||||
|
$end = $this->input['end'] ? strtotime($this->input['end']) : null; |
||||
|
$q->whereBetween('datetime', [$start, $end]); |
||||
|
})->datetime()->width(4); |
||||
|
$filter->equal('user_id', '会员ID')->width(3); |
||||
|
$filter->like('coin_name', '币种名字')->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new TransferRecord(), function (Show $show) { |
||||
|
// 这里的字段会自动使用翻译文件 |
||||
|
$show->id; |
||||
|
$show->coin_name; |
||||
|
$show->draw_out_direction; |
||||
|
$show->into_direction; |
||||
|
$show->amount; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new TransferRecord(), function (Form $form) { |
||||
|
// 这里的字段会自动使用翻译文件 |
||||
|
$form->display('id'); |
||||
|
$form->text('coin_name'); |
||||
|
$form->text('draw_out_direction'); |
||||
|
$form->text('into_direction'); |
||||
|
$form->text('amount'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use Dcat\Admin\Controllers\AuthController as BaseAuthController; |
||||
|
|
||||
|
class AuthController extends BaseAuthController |
||||
|
{ |
||||
|
protected $view = 'admin.login.login'; |
||||
|
} |
||||
@ -0,0 +1,86 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/** |
||||
|
* Created by PhpStorm. |
||||
|
* User: Administrator |
||||
|
* Date: 2020/7/29 |
||||
|
* Time: 15:12 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\UserRechargeEth; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class AutomaticRechargeController extends AdminController |
||||
|
{ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new UserRechargeEth(), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('id'); |
||||
|
// 这里的字段会自动使用翻译文件 |
||||
|
$grid->id->sortable(); |
||||
|
$grid->user_id; |
||||
|
$grid->coin_name; |
||||
|
$grid->address; |
||||
|
$grid->txid; |
||||
|
$grid->amount; |
||||
|
$grid->amount_u; |
||||
|
$grid->status->using([1 => '充值失败', 2 => '充值成功'])->dot([1 => 'error', 2 => 'success']); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->filter(function ($filter) { |
||||
|
$filter->equal('user_id', '会员ID'); |
||||
|
$filter->like('status', '审核状态'); |
||||
|
$filter->like('coin_name', '币种名字'); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new UserRechargeEth(), function (Show $show) { |
||||
|
// 这里的字段会自动使用翻译文件 |
||||
|
$show->id; |
||||
|
$show->user_id; |
||||
|
$show->coin_name; |
||||
|
$show->address; |
||||
|
$show->txid; |
||||
|
$show->amount; |
||||
|
$show->amount_u; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new UserRechargeEth(), function (Form $form) { |
||||
|
// 这里的字段会自动使用翻译文件 |
||||
|
$form->display('id'); |
||||
|
$form->text('user_id'); |
||||
|
$form->text('coin_name'); |
||||
|
$form->text('address'); |
||||
|
$form->text('txid'); |
||||
|
$form->text('amount'); |
||||
|
$form->text('amount_u'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,87 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-29 10:40:49 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-09 17:42:45 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Actions\Grid\BTCCollect; |
||||
|
use App\Models\User; |
||||
|
use App\Models\UserWallet; |
||||
|
use App\Services\CoinService\BitCoinService; |
||||
|
use App\Services\CoinService\GethService; |
||||
|
use App\Services\CoinService\GethTokenService; |
||||
|
use App\Services\CoinService\OmnicoreService; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Layout\Content; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Alert; |
||||
|
use Dcat\Admin\Widgets\Card; |
||||
|
use Dcat\Admin\Widgets\Table; |
||||
|
use Web3\Providers\HttpProvider; |
||||
|
use Web3\RequestManagers\HttpRequestManager; |
||||
|
use Web3\Web3; |
||||
|
|
||||
|
class BTCAccountsController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
$builder = UserWallet::with(['user'])->where('coin_id', 2)->where(function ($q) { |
||||
|
$q->whereNotNull('wallet_address')->where('wallet_address', '<>', ''); |
||||
|
}); |
||||
|
return Grid::make($builder, function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('user_id'); |
||||
|
|
||||
|
#统计 |
||||
|
$grid->header(function ($query) { |
||||
|
$amount = (new BitCoinService())->getBalance(); |
||||
|
$con = '<code>BTC:' . $amount . '</code>'; |
||||
|
return Alert::make($con, '总余额')->info(); |
||||
|
}); |
||||
|
|
||||
|
$grid->actions(function (Grid\Displayers\Actions $actions) { |
||||
|
$actions->disableDelete(); |
||||
|
$actions->disableQuickEdit(); |
||||
|
$actions->disableEdit(); |
||||
|
$actions->disableView(); |
||||
|
|
||||
|
$actions->append(new BTCCollect()); |
||||
|
}); |
||||
|
|
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
|
||||
|
// 这里的字段会自动使用翻译文件 |
||||
|
$grid->column('user_id', 'UID'); |
||||
|
$grid->column('user.username', '用户名'); |
||||
|
$grid->column('coin_name', '币种'); |
||||
|
$grid->column('wallet_address', '地址'); |
||||
|
|
||||
|
$grid->column('balance', '余额')->display(function () { |
||||
|
return (new BitCoinService())->getBalance($this->wallet_address); |
||||
|
}); |
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('user_id', '会员ID')->width(2); |
||||
|
$filter->where('username', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$q->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
}, "用户名/手机/邮箱")->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,107 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\Banner; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class BannerController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* 轮播图和图标管理 |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new Banner(), function (Grid $grid) { |
||||
|
// $grid->model()->where("location_type",1); |
||||
|
$grid->id->sortable(); |
||||
|
$grid->imgurl->image('', 50, 50); |
||||
|
$grid->location_type->using(Banner::$locationTypeMap)->label(); |
||||
|
$grid->tourl; |
||||
|
$grid->tourl_type->using(Banner::$tourlTypeMap)->label(); |
||||
|
$grid->status->switch(); |
||||
|
$grid->order; |
||||
|
$grid->created_at->sortable(); |
||||
|
// $grid->updated_at->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('id'); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new Banner(), function (Show $show) { |
||||
|
$show->id; |
||||
|
$show->imgurl; |
||||
|
$show->location_type; |
||||
|
$show->tourl; |
||||
|
$show->tourl_type; |
||||
|
$show->status; |
||||
|
$show->order; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new Banner(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->select('location_type')->options(Banner::$locationTypeMap)->default(1); |
||||
|
$form->select('tourl_type')->options(Banner::$tourlTypeMap)->default(0); |
||||
|
$form->switch('status')->default(1); |
||||
|
$form->number('order')->default(1); |
||||
|
$form->text('tourl')->default('#'); |
||||
|
$form->hasMany('translations', '图片', function (Form\NestedForm $form) { |
||||
|
|
||||
|
$lang = [ |
||||
|
'en' => '英', |
||||
|
'zh-CN' => '中', |
||||
|
"zh-TW" => "繁体", |
||||
|
'kor' => '韩文', |
||||
|
'jp' => '日文', |
||||
|
'de' => '德文', |
||||
|
'it' => '意大利文', |
||||
|
'nl' => '荷兰文', |
||||
|
'pl' => '波兰文', |
||||
|
'pt' => '葡萄牙文', |
||||
|
'spa' => '西班牙文', |
||||
|
'swe' => '瑞典文', |
||||
|
'tr' => '土耳其文', |
||||
|
'uk' => '乌克兰文', |
||||
|
'vie' => '越南语', |
||||
|
'fra' => '法文', |
||||
|
|
||||
|
]; |
||||
|
|
||||
|
$form->select('locale')->options($lang)->default('zh-CN')->label(); |
||||
|
$form->image('imgurl')->uniqueName()->autoUpload(); |
||||
|
}); |
||||
|
|
||||
|
// $form->saving(function(Form $form){ |
||||
|
// if( blank($form->location_type)) return $form->error("请选择显示的位置"); |
||||
|
// }); |
||||
|
|
||||
|
|
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,197 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\Agent; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Models\BonusLog; |
||||
|
use App\Models\UserWallet; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Alert; |
||||
|
|
||||
|
class BonusLogController extends AdminController |
||||
|
{ |
||||
|
|
||||
|
public function statistics() |
||||
|
{ |
||||
|
$grades = AgentGrade::getCachedGradeOption(); |
||||
|
$builder1 = BonusLog::query(); |
||||
|
$params = request()->only(array_merge($grades, ['user_id', 'username', 'order_id', 'created_at'])); |
||||
|
|
||||
|
if (!empty($params)) { |
||||
|
if (!empty($params['user_id'])) { |
||||
|
$builder1->where('user_id', $params['user_id']); |
||||
|
} |
||||
|
if (!empty($params['username'])) { |
||||
|
$username = $params['username']; |
||||
|
$builder1->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
} |
||||
|
if (!empty($params['order_id'])) { |
||||
|
$builder1->where('bonusable_id', $params['order_id']); |
||||
|
} |
||||
|
if (!empty($params['created_at']) && !empty($params['created_at']['start'])) { |
||||
|
$start = $params['created_at']['start']; |
||||
|
$end = $params['created_at']['end']; |
||||
|
$builder1->whereDate('created_at', '>=', $start)->whereDate('created_at', '<=', $end); |
||||
|
} |
||||
|
|
||||
|
$lk = last(array_keys($grades)); |
||||
|
foreach ($grades as $k => $v) { |
||||
|
$key = 'A' . ($k + 1); |
||||
|
if ($k == $lk && !empty($params[$key])) { |
||||
|
$id = $params[$key]; |
||||
|
$builder1->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
} elseif (!empty($params[$key])) { |
||||
|
$ids = Agent::getBaseAgentIds($params[$key]); |
||||
|
$builder1->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$total_amount = $builder1->where('status', BonusLog::status_hand)->sum('amount'); |
||||
|
|
||||
|
$con = '<code>' . '总金额:' . (float)$total_amount . 'USDT</code> '; |
||||
|
return Alert::make($con, '统计')->info(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(BonusLog::with(['user']), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('id'); |
||||
|
|
||||
|
#统计 |
||||
|
$grid->header(function ($query) { |
||||
|
return $this->statistics(); |
||||
|
}); |
||||
|
|
||||
|
$grid->disableBatchDelete(); |
||||
|
$grid->disableActions(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
|
||||
|
$grid->column('id')->sortable(); |
||||
|
$grid->column('user_id'); |
||||
|
$grid->column('user.username', '用户名'); |
||||
|
// $grid->column('coin_id'); |
||||
|
$grid->column('coin_name'); |
||||
|
$grid->column('account_type')->display(function ($v) { |
||||
|
$account = array_first(UserWallet::$accountMap, function ($value, $key) use ($v) { |
||||
|
return $value['id'] == $v; |
||||
|
}); |
||||
|
return $account['name'] ?? '--'; |
||||
|
}); |
||||
|
// $grid->column('rich_type'); |
||||
|
$grid->column('amount'); |
||||
|
// $grid->column('log_type'); |
||||
|
$grid->column('status')->using(BonusLog::$statusMap)->dot([-1 => 'default', 1 => 'primary', 2 => 'success']); |
||||
|
$grid->column('hand_time'); |
||||
|
// $grid->column('created_at'); |
||||
|
// $grid->column('updated_at')->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$grades = AgentGrade::getCachedGradeOption(); |
||||
|
$lk = last(array_keys($grades)); |
||||
|
foreach ($grades as $k => $v) { |
||||
|
$key = 'A' . ($k + 1); |
||||
|
$next_key = 'A' . ($k + 2); |
||||
|
if ($k == 0) { |
||||
|
$options1 = Agent::query()->where(['deep' => 0, 'is_agency' => 1])->pluck('username', 'id'); |
||||
|
$filter->where($key, function ($q) { |
||||
|
$ids = Agent::getBaseAgentIds($this->input); |
||||
|
$q->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
}, $v)->select($options1)->load($next_key, 'api/agents')->placeholder('请选择')->width(2); |
||||
|
} elseif ($k == $lk) { |
||||
|
$filter->where($key, function ($q) { |
||||
|
$id = $this->input; |
||||
|
$q->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
}, $v)->select()->placeholder('请选择')->width(2); |
||||
|
} else { |
||||
|
$filter->where($key, function ($q) { |
||||
|
$ids = Agent::getBaseAgentIds($this->input); |
||||
|
$q->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
}, $v)->select()->load($next_key, 'api/agents')->placeholder('请选择')->width(2); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$filter->equal('user_id', '用户id')->width(2); |
||||
|
$filter->where('username', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$q->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
}, "用户名/手机/邮箱")->width(4); |
||||
|
$filter->equal('order_id', '订单ID')->width(2); |
||||
|
$filter->between('created_at', "时间")->datetime()->width(4); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new BonusLog(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('user_id'); |
||||
|
$show->field('coin_id'); |
||||
|
$show->field('coin_name'); |
||||
|
$show->field('account_type'); |
||||
|
$show->field('rich_type'); |
||||
|
$show->field('amount'); |
||||
|
$show->field('log_type'); |
||||
|
$show->field('status'); |
||||
|
$show->field('hand_time'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new BonusLog(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->text('user_id'); |
||||
|
$form->text('coin_id'); |
||||
|
$form->text('coin_name'); |
||||
|
$form->text('account_type'); |
||||
|
$form->text('rich_type'); |
||||
|
$form->text('amount'); |
||||
|
$form->text('log_type'); |
||||
|
$form->text('status'); |
||||
|
$form->text('hand_time'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,86 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\Agent; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Admin\Repositories\BonusLog as BonusLogRepository; |
||||
|
use App\Models\User; |
||||
|
use App\Models\UserWallet; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Alert; |
||||
|
|
||||
|
class BonusLogStatisticsController extends AdminController |
||||
|
{ |
||||
|
|
||||
|
protected $title = '期权佣金统计'; |
||||
|
|
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new BonusLogRepository(), function (Grid $grid) { |
||||
|
|
||||
|
$grid->disableBatchDelete(); |
||||
|
$grid->disableActions(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
|
||||
|
$grid->column('user_id', 'UID'); |
||||
|
$grid->column('user.username', '用户名'); |
||||
|
$grid->column('user.user_grade_name', '等级'); |
||||
|
$grid->column('user.referrer', '代理')->display(function ($v) { |
||||
|
return User::query()->where("id", $v)->value("name") ?? '--'; |
||||
|
}); |
||||
|
// $grid->column('coin_name'); |
||||
|
$grid->column('amount_sum', '佣金统计'); |
||||
|
// |
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$grades = AgentGrade::getCachedGradeOption(); |
||||
|
$lk = last(array_keys($grades)); |
||||
|
foreach ($grades as $k => $v) { |
||||
|
$key = 'A' . ($k + 1); |
||||
|
$next_key = 'A' . ($k + 2); |
||||
|
if ($k == 0) { |
||||
|
$options1 = Agent::query()->where(['deep' => 0, 'is_agency' => 1])->pluck('username', 'id'); |
||||
|
$filter->where($key, function ($q) { |
||||
|
$ids = Agent::getBaseAgentIds($this->input); |
||||
|
$q->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
}, $v)->select($options1)->load($next_key, 'api/agents')->placeholder('请选择')->width(2); |
||||
|
} elseif ($k == $lk) { |
||||
|
$filter->where($key, function ($q) { |
||||
|
$id = $this->input; |
||||
|
$q->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
}, $v)->select()->placeholder('请选择')->width(2); |
||||
|
} else { |
||||
|
$filter->where($key, function ($q) { |
||||
|
$ids = Agent::getBaseAgentIds($this->input); |
||||
|
$q->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
}, $v)->select()->load($next_key, 'api/agents')->placeholder('请选择')->width(2); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$filter->equal('user_id', '用户id')->width(2); |
||||
|
$filter->where('username', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$q->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
}, "用户名/手机/邮箱")->width(4); |
||||
|
$filter->between('created_at', "时间")->date()->width(4); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,104 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-29 10:40:49 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-09 17:42:48 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\CenterWallet; |
||||
|
use App\Services\CoinService\BitCoinService; |
||||
|
use App\Services\CoinService\GethService; |
||||
|
use App\Services\CoinService\GethTokenService; |
||||
|
use App\Services\CoinService\OmnicoreService; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class CenterWalletController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new CenterWallet(), function (Grid $grid) { |
||||
|
$grid->disableActions(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
|
||||
|
$grid->column('center_wallet_id')->sortable(); |
||||
|
$grid->column('center_wallet_name'); |
||||
|
$grid->column('center_wallet_account'); |
||||
|
$grid->column('center_wallet_address'); |
||||
|
|
||||
|
$grid->column('balance', '余额')->display(function () { |
||||
|
if ($this->coin_id == 2) { |
||||
|
return (new BitCoinService())->getBTCBalance($this->center_wallet_address) . '(BTC)'; |
||||
|
} elseif ($this->coin_id == 3) { |
||||
|
return (new GethService())->getBalance($this->center_wallet_address) . '(ETH)'; |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
$grid->column('token_balance', '代币余额')->display(function () { |
||||
|
if ($this->coin_id == 2) { |
||||
|
return (new OmnicoreService())->getBalance($this->center_wallet_address) . '(USDT)'; |
||||
|
} elseif ($this->coin_id == 3) { |
||||
|
$contractAddress = config('coin.erc20_usdt.contractAddress'); |
||||
|
$abi = config('coin.erc20_usdt.abi'); |
||||
|
return (new GethTokenService($contractAddress, $abi))->getBalance($this->center_wallet_address) . '(USDT)'; |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new CenterWallet(), function (Show $show) { |
||||
|
$show->field('center_wallet_id'); |
||||
|
$show->field('center_wallet_name'); |
||||
|
$show->field('center_wallet_account'); |
||||
|
$show->field('center_wallet_address'); |
||||
|
$show->field('center_wallet_balance'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new CenterWallet(), function (Form $form) { |
||||
|
$form->display('center_wallet_id'); |
||||
|
$form->text('center_wallet_name'); |
||||
|
$form->text('center_wallet_account'); |
||||
|
$form->text('center_wallet_address'); |
||||
|
$form->text('center_wallet_balance'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,116 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\Coins; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Card; |
||||
|
|
||||
|
class CoinController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new Coins(), function (Grid $grid) { |
||||
|
$grid->model()->orderByRaw("FIELD(status," . implode(",", [1, 0]) . ")")->orderByDesc('coin_id'); |
||||
|
|
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
// $grid->disableCreateButton(); |
||||
|
$grid->disableViewButton(); |
||||
|
|
||||
|
$grid->coin_id->sortable(); |
||||
|
$grid->coin_name; |
||||
|
// $grid->full_name; |
||||
|
// $grid->qty_decimals; |
||||
|
// $grid->price_decimals; |
||||
|
$grid->withdrawal_fee->sortable(); |
||||
|
$grid->withdrawal_min->sortable(); |
||||
|
$grid->withdrawal_max->sortable(); |
||||
|
// $grid->coin_withdraw_message; |
||||
|
// $grid->coin_recharge_message; |
||||
|
// $grid->coin_transfer_message; |
||||
|
$grid->coin_content->display('详情') // 设置按钮名称 |
||||
|
->expand(function () { |
||||
|
// 返回显示的详情 |
||||
|
// 这里返回 content 字段内容,并用 Card 包裹起来 |
||||
|
$card = new Card(null, $this->coin_content); |
||||
|
|
||||
|
return "<div style='padding:10px 10px 0'>$card</div>"; |
||||
|
}); |
||||
|
$grid->coin_icon->image('', 50, 50); |
||||
|
$grid->status->using([0 => '禁用', 1 => '启用'])->dot([0 => 'danger', 1 => 'success'])->switch(); |
||||
|
$grid->created_at->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('coin_id')->width(3); |
||||
|
$filter->like('coin_name', '币种名称')->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new Coins(), function (Show $show) { |
||||
|
$show->coin_id; |
||||
|
$show->coin_name; |
||||
|
$show->qty_decimals; |
||||
|
$show->price_decimals; |
||||
|
$show->full_name; |
||||
|
$show->withdrawal_fee; |
||||
|
$show->coin_withdraw_message; |
||||
|
$show->coin_recharge_message; |
||||
|
$show->coin_transfer_message; |
||||
|
$show->coin_content; |
||||
|
$show->coin_icon; |
||||
|
$show->status; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new Coins(), function (Form $form) { |
||||
|
$form->display('coin_id'); |
||||
|
$form->text('coin_name'); |
||||
|
$form->text('full_name'); |
||||
|
$form->number('qty_decimals')->default(2); |
||||
|
$form->number('price_decimals')->default(2); |
||||
|
$form->text('withdrawal_fee'); |
||||
|
$form->text('withdrawal_min'); |
||||
|
$form->text('withdrawal_max'); |
||||
|
$form->text('coin_withdraw_message'); |
||||
|
$form->text('coin_recharge_message'); |
||||
|
$form->text('coin_transfer_message'); |
||||
|
$form->text('official_website_link','官网链接'); |
||||
|
$form->text('white_paper_link','白皮书地址'); |
||||
|
$form->editor('coin_content'); |
||||
|
$form->image('coin_icon'); |
||||
|
$form->switch('status')->default(1); |
||||
|
$form->switch('can_recharge','可充值?')->default(0); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,67 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\ContactInfo; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class ContactInfoController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected $title = '联系我们信息'; |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new ContactInfo(), function (Grid $grid) { |
||||
|
$grid->id->sortable(); |
||||
|
$grid->name; |
||||
|
$grid->url; |
||||
|
|
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->disableViewButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
|
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('id'); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new ContactInfo(), function (Show $show) { |
||||
|
$show->id; |
||||
|
$show->name; |
||||
|
$show->url; //show 方法隐藏按钮 |
||||
|
|
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new ContactInfo(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->text('name'); |
||||
|
$form->text('url'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,98 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-08-04 09:34:17 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-06 18:51:21 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers\Contract; |
||||
|
|
||||
|
use App\Models\Contract\ContractRebate; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use App\Admin\Actions\Agent\ContractSettle; |
||||
|
|
||||
|
class ContractRebateController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new ContractRebate(), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('order_time', 'id'); //倒序排序 |
||||
|
// $grid->disableActions(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->actions(function (Grid\Displayers\Actions $actions) { |
||||
|
$actions->disableDelete(); |
||||
|
$actions->disableEdit(); |
||||
|
$actions->disableView(); |
||||
|
if ($this->status) { |
||||
|
$actions->append(ContractSettle::make()->addHtmlClass('btn btn-sm btn-outline-primary disabled')); |
||||
|
} else { |
||||
|
$actions->append(ContractSettle::make()->addHtmlClass('btn btn-sm btn-outline-primary')); |
||||
|
} |
||||
|
}); |
||||
|
$grid->column('id', '返佣ID')->sortable(); |
||||
|
$grid->column('order_no'); |
||||
|
$grid->column('aid', '受益人UID')->help('当前订单受益人ID'); |
||||
|
$grid->column('user_id')->help('当前订单的下单用户'); |
||||
|
$grid->column('deep', '返佣层级')->help('代理商层级(1为直推2为间推3为间推的间推以此类推)'); |
||||
|
$grid->column('rebate_type')->using(ContractRebate::$rebateTypeMap)->label(); |
||||
|
$grid->column('contract_pair'); |
||||
|
$grid->column('side')->using(ContractRebate::$sideMap); |
||||
|
$grid->column('margin', '保证金'); |
||||
|
$grid->column('fee'); |
||||
|
$grid->column('rebate_rate')->percentage(); |
||||
|
$grid->column('rebate', '佣金')->help('本单代理商可拿奖金'); |
||||
|
$grid->column('status')->using(ContractRebate::$statusMap)->dot([0 => 'grey', 1 => 'green'])->help('用户成功持仓合约后会产生返佣订单,每日12:00会自动结算历史佣金'); |
||||
|
$grid->column('order_time', '订单时间')->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->between('order_time', '订单时间')->date(); |
||||
|
$filter->equal('id')->width(3); |
||||
|
$filter->equal('user_referrer')->width(3); |
||||
|
$filter->equal('order_no')->width(3); |
||||
|
$filter->equal('aid', '受益人UID')->width(3); |
||||
|
$filter->equal('status')->select(ContractRebate::$statusMap)->width(4); |
||||
|
$filter->in('contract_pair')->multipleSelect(ContractRebate::$contractPairMap)->width(4); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new ContractRebate(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->text('order_no'); |
||||
|
$form->text('user_id'); |
||||
|
$form->text('user_referrer'); |
||||
|
$form->text('deep'); |
||||
|
$form->text('rebate_type'); |
||||
|
$form->text('contract_pair'); |
||||
|
$form->text('side'); |
||||
|
$form->text('amount'); |
||||
|
$form->text('fee'); |
||||
|
$form->text('rebate_rate'); |
||||
|
$form->text('status'); |
||||
|
$form->text('order_time'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,152 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-29 10:40:49 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-09 17:42:51 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Actions\ContractAccount\Recharge; |
||||
|
use App\Handlers\ContractTool; |
||||
|
use App\Models\Agent; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Models\SustainableAccount; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Alert; |
||||
|
|
||||
|
class ContractAccountController extends AdminController |
||||
|
{ |
||||
|
public function statistics() |
||||
|
{ |
||||
|
$builder = SustainableAccount::query(); |
||||
|
$params = request()->only(['user_id', 'username']); |
||||
|
|
||||
|
if (!empty($params)) { |
||||
|
if (!empty($params['user_id'])) { |
||||
|
$builder->where('user_id', $params['user_id']); |
||||
|
} |
||||
|
if (!empty($params['username'])) { |
||||
|
$username = $params['username']; |
||||
|
$builder->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$records = $builder->groupBy('coin_name')->selectRaw('sum(usable_balance) as total_usable_balance, coin_name')->get(); |
||||
|
$records = $records->sortByDesc('total_usable_balance'); |
||||
|
$con = ''; |
||||
|
foreach ($records as $record) { |
||||
|
$con .= '<code>' . $record['coin_name'] . '金额:' . $record['total_usable_balance'] . '</code> '; |
||||
|
} |
||||
|
return Alert::make($con, '统计')->info(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new SustainableAccount(), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('user_id'); |
||||
|
$grid->column('id')->sortable(); |
||||
|
|
||||
|
#统计 |
||||
|
$grid->header(function ($query) { |
||||
|
return $this->statistics(); |
||||
|
}); |
||||
|
|
||||
|
$grid->actions(function (Grid\Displayers\Actions $actions) { |
||||
|
$actions->disableDelete(); |
||||
|
$actions->disableQuickEdit(); |
||||
|
$actions->disableEdit(); |
||||
|
$actions->disableView(); |
||||
|
|
||||
|
// if (Admin::user()->can('user-recharge')) { |
||||
|
// $actions->append(new Recharge()); |
||||
|
// } |
||||
|
}); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
|
||||
|
$grid->column('user_id'); |
||||
|
$grid->column('usermail', '邮箱')->display(function () { |
||||
|
//$realtime_price = Cache::store('redis')->get('swap:' . 'trade_detail_' . $this->symbol)['price'] ?? null; |
||||
|
//dd(ContractTool::getUserMail($this->user_id)); |
||||
|
return ContractTool::getUserMail($this->user_id); |
||||
|
}); |
||||
|
$grid->column('agname','代理邮箱')->display(function (){ |
||||
|
//dd($this->user_id); |
||||
|
$var = ContractTool::GetProxyEmail($this->user_id); |
||||
|
//dd($var); |
||||
|
return $var['username']; |
||||
|
}); |
||||
|
// $grid->column('coin_id'); |
||||
|
// $grid->column('coin_name'); |
||||
|
$grid->column('margin_name'); |
||||
|
$grid->column('usable_balance')->sortable(); |
||||
|
$grid->column('used_balance'); |
||||
|
$grid->column('freeze_balance'); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('user_id', 'UID')->width(2); |
||||
|
$filter->where('username', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$q->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
}, "用户名/手机/邮箱")->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new SustainableAccount(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('user_id'); |
||||
|
$show->field('coin_id'); |
||||
|
$show->field('coin_name'); |
||||
|
$show->field('margin_name'); |
||||
|
$show->field('usable_balance'); |
||||
|
$show->field('used_balance'); |
||||
|
$show->field('freeze_balance'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new SustainableAccount(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->text('user_id'); |
||||
|
$form->text('coin_id'); |
||||
|
$form->text('coin_name'); |
||||
|
$form->text('margin_name'); |
||||
|
$form->text('usable_balance'); |
||||
|
$form->text('used_balance'); |
||||
|
$form->text('freeze_balance'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,357 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Repositories\ContractAnomaly; |
||||
|
use App\Models\Agent; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Models\ContractEntrust; |
||||
|
use App\Models\Recharge; |
||||
|
use App\Models\SustainableAccount; |
||||
|
use App\Models\UserWallet; |
||||
|
use App\Models\UserWalletLog; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Alert; |
||||
|
|
||||
|
class ContractAnomalyController extends AdminController |
||||
|
{ |
||||
|
protected $title = '异常检测'; |
||||
|
|
||||
|
public function statistics() |
||||
|
{ |
||||
|
$grades = AgentGrade::getCachedGradeOption(); |
||||
|
$builder0 = SustainableAccount::query()->whereHas('user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
}); |
||||
|
// 盈亏 |
||||
|
$builder1 = ContractEntrust::query()->whereHas('user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
}); |
||||
|
// 手续费 |
||||
|
$builder2 = UserWalletLog::query()->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->whereHas('user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
}) |
||||
|
->whereIn('log_type', ['open_position_fee', 'close_position_fee', 'system_close_position_fee', 'cancel_open_position_fee']); |
||||
|
// 资金费 |
||||
|
$builder3 = UserWalletLog::query()->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->whereHas('user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
}) |
||||
|
->where('log_type', 'position_capital_cost'); |
||||
|
// 转入 |
||||
|
$builder4 = UserWalletLog::query() |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->where('log_type', 'fund_transfer') |
||||
|
->whereHas('user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
}) |
||||
|
->where('amount', '>', 0); |
||||
|
// 转出 |
||||
|
$builder5 = UserWalletLog::query() |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->where('log_type', 'fund_transfer') |
||||
|
->whereHas('user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
}) |
||||
|
->where('amount', '<', 0); |
||||
|
// 合约扣款 |
||||
|
$builder6 = Recharge::query() |
||||
|
->where('type', 2) |
||||
|
->whereHas('user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
}) |
||||
|
->where('account_type', UserWallet::sustainable_account); |
||||
|
|
||||
|
$params = request()->only(array_merge($grades, ['user_id', 'is_anomaly', 'created_at'])); |
||||
|
|
||||
|
if (!empty($params)) { |
||||
|
if (!empty($params['user_id'])) { |
||||
|
$builder0->where('user_id', $params['user_id']); |
||||
|
$builder1->where('user_id', $params['user_id']); |
||||
|
$builder2->where('user_id', $params['user_id']); |
||||
|
$builder3->where('user_id', $params['user_id']); |
||||
|
$builder4->where('user_id', $params['user_id']); |
||||
|
$builder5->where('user_id', $params['user_id']); |
||||
|
$builder6->where('user_id', $params['user_id']); |
||||
|
} |
||||
|
if (!empty($params['created_at']) && !empty($params['created_at']['start'])) { |
||||
|
$builder1->whereDate('created_at', '>=', $params['created_at']['start'])->whereDate('created_at', '<=', $params['created_at']['end']); |
||||
|
$builder2->whereDate('created_at', '>=', $params['created_at']['start'])->whereDate('created_at', '<=', $params['created_at']['end']); |
||||
|
$builder3->whereDate('created_at', '>=', $params['created_at']['start'])->whereDate('created_at', '<=', $params['created_at']['end']); |
||||
|
$builder4->whereDate('created_at', '>=', $params['created_at']['start'])->whereDate('created_at', '<=', $params['created_at']['end']); |
||||
|
$builder5->whereDate('created_at', '>=', $params['created_at']['start'])->whereDate('created_at', '<=', $params['created_at']['end']); |
||||
|
$builder6->whereDate('created_at', '>=', $params['created_at']['start'])->whereDate('created_at', '<=', $params['created_at']['end']); |
||||
|
} |
||||
|
|
||||
|
$lk = last(array_keys($grades)); |
||||
|
foreach ($grades as $k => $v) { |
||||
|
$key = 'A' . ($k + 1); |
||||
|
if ($k == $lk && !empty($params[$key])) { |
||||
|
$id = $params[$key]; |
||||
|
$builder0->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
$builder1->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
$builder2->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
$builder3->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
$builder4->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
$builder5->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
$builder6->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
} elseif (!empty($params[$key])) { |
||||
|
$ids = Agent::getBaseAgentIds($params[$key]); |
||||
|
$builder0->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
$builder1->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
$builder2->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
$builder3->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
$builder4->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
$builder5->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
$builder6->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$total_profit = $builder1->where('status', ContractEntrust::status_completed)->sum('profit'); |
||||
|
$total_fee = $builder2->sum('amount'); |
||||
|
$total_cost = $builder3->sum('amount'); |
||||
|
$total_in = $builder4->sum('amount'); |
||||
|
$total_out = $builder5->sum('amount'); |
||||
|
$total_charge = $builder6->sum('amount'); |
||||
|
|
||||
|
$net_worth = $total_in + $total_out; |
||||
|
$total_used_balance = $builder0->sum('used_balance'); |
||||
|
$total_freeze_balance = $builder0->sum('freeze_balance'); |
||||
|
$total_usable_balance = $builder0->sum('usable_balance'); // 实际总余额 |
||||
|
$total_theory_balance = PriceCalculate(($net_worth - abs($total_fee) - abs($total_cost) + $total_profit - $total_used_balance - $total_freeze_balance), '+', $total_charge, 8); // 理论总余额 |
||||
|
$total_anomaly = PriceCalculate($total_theory_balance, '-', $total_usable_balance, 8); |
||||
|
|
||||
|
$con = '<code>总转入:' . (float)abs($total_in) . 'USDT</code> ' . '<code>总转出:' . (float)abs($total_out) . 'USDT</code> ' . '<code>总手续费:' . (float)abs($total_fee) . 'USDT</code> ' . '<code>总资金费:' . (float)abs($total_cost) . 'USDT</code> ' . '<code>总盈亏:' . (float)$total_profit . 'USDT</code> ' . '<code>总异常资金:' . (float)$total_anomaly . 'USDT</code> ' . '<code>总实际余额:' . (float)$total_usable_balance . 'USDT</code> ' . '<code>总理论余额:' . (float)$total_theory_balance . 'USDT</code> '; |
||||
|
return Alert::make($con, '统计')->info(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 异常检测 |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(SustainableAccount::with(['user']), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('user_id'); |
||||
|
|
||||
|
#统计 |
||||
|
$grid->header(function ($query) { |
||||
|
return $this->statistics(); |
||||
|
}); |
||||
|
|
||||
|
$grid->column('id')->sortable(); |
||||
|
|
||||
|
$grid->disableActions(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
|
||||
|
$grid->column('user.referrer', 'A5')->display(function ($referrer) { |
||||
|
$agent = Agent::query()->where('is_agency', 1)->where("id", $referrer)->first(); |
||||
|
if (blank($agent)) { |
||||
|
return '--'; |
||||
|
} else { |
||||
|
$parent = $agent->parent->parent->parent->parent; |
||||
|
return blank($parent) ? "--" : $parent['name']; |
||||
|
} |
||||
|
}); |
||||
|
$grid->column('user_id', 'UID'); |
||||
|
// $grid->column('margin_name'); |
||||
|
|
||||
|
$grid->column('contract_in', '转入')->display(function () { |
||||
|
return UserWalletLog::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->where('log_type', 'fund_transfer') |
||||
|
->where('amount', '>', 0) |
||||
|
->sum('amount'); |
||||
|
}); |
||||
|
$grid->column('contract_out', '转出')->display(function () { |
||||
|
return UserWalletLog::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->where('log_type', 'fund_transfer') |
||||
|
->where('amount', '<', 0) |
||||
|
->sum('amount'); |
||||
|
}); |
||||
|
$grid->column('contract_charge', '人工净充值')->display(function () { |
||||
|
return Recharge::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('type', 2) |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->sum('amount'); |
||||
|
}); |
||||
|
$grid->column('contract_fee', '手续费')->display(function () { |
||||
|
return UserWalletLog::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->whereIn('log_type', ['open_position_fee', 'close_position_fee', 'system_close_position_fee', 'cancel_open_position_fee']) |
||||
|
->sum('amount'); |
||||
|
}); |
||||
|
$grid->column('contract_cost', '资金费')->display(function () { |
||||
|
return UserWalletLog::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->where('log_type', 'position_capital_cost') |
||||
|
->sum('amount'); |
||||
|
}); |
||||
|
$grid->column('contract_profit', '盈亏')->display(function () { |
||||
|
return ContractEntrust::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('status', ContractEntrust::status_completed) |
||||
|
->sum('profit'); |
||||
|
}); |
||||
|
|
||||
|
$grid->column('used_balance', '持仓保证金'); |
||||
|
$grid->column('freeze_balance', '委托冻结'); |
||||
|
|
||||
|
$grid->column('theory_balance', '理论余额')->display(function () { |
||||
|
$net_worth = UserWalletLog::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->where('log_type', 'fund_transfer') |
||||
|
->sum('amount'); |
||||
|
$fee = UserWalletLog::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->whereIn('log_type', ['open_position_fee', 'close_position_fee', 'system_close_position_fee', 'cancel_open_position_fee']) |
||||
|
->sum('amount'); |
||||
|
$cost = UserWalletLog::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->where('log_type', 'position_capital_cost') |
||||
|
->sum('amount'); |
||||
|
$profit = ContractEntrust::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('status', ContractEntrust::status_completed) |
||||
|
->sum('profit'); |
||||
|
$charge = Recharge::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('type', 2) |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->sum('amount'); |
||||
|
return PriceCalculate(($net_worth - abs($fee) - abs($cost) + $profit - $this->used_balance - $this->freeze_balance), '+', $charge, 8); |
||||
|
}); |
||||
|
$grid->column('usable_balance', '实际余额')->sortable(); |
||||
|
|
||||
|
$grid->column('anomaly_balance', '异常资金')->display(function () { |
||||
|
$net_worth = UserWalletLog::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->where('log_type', 'fund_transfer') |
||||
|
->sum('amount'); |
||||
|
$fee = UserWalletLog::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->whereIn('log_type', ['open_position_fee', 'close_position_fee', 'system_close_position_fee', 'cancel_open_position_fee']) |
||||
|
->sum('amount'); |
||||
|
$cost = UserWalletLog::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->where('log_type', 'position_capital_cost') |
||||
|
->sum('amount'); |
||||
|
$profit = ContractEntrust::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('status', ContractEntrust::status_completed) |
||||
|
->sum('profit'); |
||||
|
$charge = Recharge::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('type', 2) |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->sum('amount'); |
||||
|
return PriceCalculate(PriceCalculate(($net_worth - abs($fee) - abs($cost) + $profit - $this->used_balance - $this->freeze_balance), '+', $charge, 8), '-', $this->usable_balance, 8); |
||||
|
}); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$grades = AgentGrade::getCachedGradeOption(); |
||||
|
$lk = last(array_keys($grades)); |
||||
|
foreach ($grades as $k => $v) { |
||||
|
$key = 'A' . ($k + 1); |
||||
|
$next_key = 'A' . ($k + 2); |
||||
|
if ($k == 0) { |
||||
|
$options1 = Agent::query()->where(['deep' => 0, 'is_agency' => 1])->pluck('username', 'id'); |
||||
|
$filter->where($key, function ($q) { |
||||
|
$ids = Agent::getBaseAgentIds($this->input); |
||||
|
$q->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
}, $v)->select($options1)->load($next_key, 'api/agents')->placeholder('请选择')->width(2); |
||||
|
} elseif ($k == $lk) { |
||||
|
$filter->where($key, function ($q) { |
||||
|
$id = $this->input; |
||||
|
$q->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
}, $v)->select()->placeholder('请选择')->width(2); |
||||
|
} else { |
||||
|
$filter->where($key, function ($q) { |
||||
|
$ids = Agent::getBaseAgentIds($this->input); |
||||
|
$q->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
}, $v)->select()->load($next_key, 'api/agents')->placeholder('请选择')->width(2); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$filter->equal('user_id', 'UID')->width(2); |
||||
|
$filter->whereBetween('created_at', function ($q) { |
||||
|
}, "时间")->date()->width(4); |
||||
|
$filter->where('contract_anomaly', function ($q) { |
||||
|
$is_anomaly = $this->input == 1 ? 1 : 0; |
||||
|
$q->whereHas('user', function ($q) use ($is_anomaly) { |
||||
|
$q->where('contract_anomaly', $is_anomaly); |
||||
|
}); |
||||
|
}, '异常')->select([0 => '正常', 1 => '异常'])->width(2); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,159 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\ContractDealRobot; |
||||
|
use App\Models\ContractPair; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Illuminate\Support\Facades\Cache; |
||||
|
|
||||
|
class ContractDealRobotController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new ContractDealRobot(), function (Grid $grid) { |
||||
|
$grid->column('id')->sortable(); |
||||
|
// $grid->column('contract_id'); |
||||
|
$grid->column('symbol'); |
||||
|
// $grid->column('bid_plus_unit'); |
||||
|
// $grid->column('bid_plus_count'); |
||||
|
// $grid->column('bid_minus_unit'); |
||||
|
// $grid->column('bid_minus_count'); |
||||
|
// $grid->column('ask_plus_unit'); |
||||
|
// $grid->column('ask_plus_count'); |
||||
|
// $grid->column('ask_minus_unit'); |
||||
|
// $grid->column('ask_minus_count'); |
||||
|
|
||||
|
$grid->column('bid_price_range', '买单成交价格区间')->display(function () { |
||||
|
$key = 'swap:trade_detail_' . $this->symbol; |
||||
|
$data = Cache::store('redis')->get($key); |
||||
|
if (blank($data)) { |
||||
|
return '--'; |
||||
|
} else { |
||||
|
$min = $data['price'] - ($this->bid_minus_unit * $this->bid_minus_count); |
||||
|
$max = $data['price'] + ($this->bid_plus_unit * $this->bid_plus_count); |
||||
|
return $min . ' ~ ' . $max; |
||||
|
} |
||||
|
})->label('success'); |
||||
|
$grid->column('ask_price_range', '卖单成交价格区间')->display(function () { |
||||
|
$key = 'swap:trade_detail_' . $this->symbol; |
||||
|
$data = Cache::store('redis')->get($key); |
||||
|
if (blank($data)) { |
||||
|
return '--'; |
||||
|
} else { |
||||
|
$min = $data['price'] - ($this->ask_minus_unit * $this->ask_minus_count); |
||||
|
$max = $data['price'] + ($this->ask_plus_unit * $this->ask_plus_count); |
||||
|
return $min . ' ~ ' . $max; |
||||
|
} |
||||
|
})->label('danger'); |
||||
|
|
||||
|
$grid->column('status')->switch(); |
||||
|
$grid->column('created_at'); |
||||
|
// $grid->column('updated_at')->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->like('symbol')->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new ContractDealRobot(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('contract_id'); |
||||
|
$show->field('symbol'); |
||||
|
$show->field('bid_plus_unit'); |
||||
|
$show->field('bid_plus_count'); |
||||
|
$show->field('bid_minus_unit'); |
||||
|
$show->field('bid_minus_count'); |
||||
|
$show->field('ask_plus_unit'); |
||||
|
$show->field('ask_plus_count'); |
||||
|
$show->field('ask_minus_unit'); |
||||
|
$show->field('ask_minus_count'); |
||||
|
$show->field('status'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new ContractDealRobot(), function (Form $form) { |
||||
|
$options = ContractPair::query()->where('status', 1)->pluck('symbol', 'id')->toArray(); |
||||
|
|
||||
|
if ($form->isCreating()) { |
||||
|
$form->row(function (Form\Row $form) use ($options) { |
||||
|
$form->hidden('id'); |
||||
|
$form->width(6)->select('contract_id', '合约')->options($options); |
||||
|
$form->hidden('symbol'); |
||||
|
}); |
||||
|
} else { |
||||
|
$form->row(function (Form\Row $form) use ($options) { |
||||
|
$form->hidden('id'); |
||||
|
$form->width(6)->select('contract_id', '合约')->options($options)->readOnly(); |
||||
|
$form->hidden('symbol'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
$form->row(function (Form\Row $form) { |
||||
|
$form->width(3)->text('bid_plus_unit'); |
||||
|
$form->width(3)->text('bid_plus_count'); |
||||
|
}); |
||||
|
|
||||
|
$form->row(function (Form\Row $form) { |
||||
|
$form->width(3)->text('bid_minus_unit'); |
||||
|
$form->width(3)->text('bid_minus_count'); |
||||
|
}); |
||||
|
|
||||
|
$form->row(function (Form\Row $form) { |
||||
|
$form->width(3)->text('ask_plus_unit'); |
||||
|
$form->width(3)->text('ask_plus_count'); |
||||
|
}); |
||||
|
|
||||
|
$form->row(function (Form\Row $form) { |
||||
|
$form->width(3)->text('ask_minus_unit'); |
||||
|
$form->width(3)->text('ask_minus_count'); |
||||
|
}); |
||||
|
|
||||
|
$form->row(function (Form\Row $form) { |
||||
|
$form->switch('status')->default(0); |
||||
|
|
||||
|
$form->hidden('created_at'); |
||||
|
$form->hidden('updated_at'); |
||||
|
}); |
||||
|
|
||||
|
$form->saving(function (Form $form) use ($options) { |
||||
|
if ($form->isCreating()) { |
||||
|
if (!blank($form->contract_id)) { |
||||
|
$symbol = $options[$form->contract_id]; |
||||
|
$is_exist = ContractDealRobot::query()->where('symbol', $symbol)->first(); |
||||
|
if ($is_exist) return $form->error('该合约已存在任务~'); |
||||
|
|
||||
|
$form->symbol = $symbol; |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,263 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Actions\ContractEntrust\BatchCancel; |
||||
|
use App\Admin\Actions\ContractEntrust\cancel; |
||||
|
use App\Handlers\ContractTool; |
||||
|
use App\Models\Agent; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Models\ContractEntrust; |
||||
|
use App\Models\User; |
||||
|
use App\Models\UserAuth; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Alert; |
||||
|
|
||||
|
class ContractEntrustController extends AdminController |
||||
|
{ |
||||
|
public function statistics() |
||||
|
{ |
||||
|
$builder1 = ContractEntrust::query()->whereHas('user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
}); |
||||
|
$params = request()->only(['user_id', 'username', 'symbol', 'type', 'ts']); |
||||
|
|
||||
|
if (!empty($params)) { |
||||
|
if (!empty($params['user_id'])) { |
||||
|
$builder1->where('user_id', $params['user_id']); |
||||
|
} |
||||
|
if (!empty($params['username'])) { |
||||
|
$username = $params['username']; |
||||
|
$builder1->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
} |
||||
|
if (!empty($params['symbol'])) { |
||||
|
$builder1->where('symbol', $params['symbol']); |
||||
|
} |
||||
|
if (!empty($params['type'])) { |
||||
|
if ($params['type'] == 1) { |
||||
|
$builder1->where('order_type', 1)->where('side', 1); |
||||
|
} elseif ($params['type'] == 2) { |
||||
|
$builder1->where('order_type', 1)->where('side', 2); |
||||
|
} elseif ($params['type'] == 3) { |
||||
|
$builder1->where('order_type', 2)->where('side', 2); |
||||
|
} else { |
||||
|
$builder1->where('order_type', 2)->where('side', 1); |
||||
|
} |
||||
|
} |
||||
|
if (!empty($params['ts']) && !empty($params['ts']['start'])) { |
||||
|
$start = $params['ts']['start'] ? strtotime($params['ts']['start']) : null; |
||||
|
$end = $params['ts']['end'] ? strtotime($params['ts']['end']) : null; |
||||
|
$builder1->whereBetween('ts', [$start, $end + 86399]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$res1 = $builder1->where('status', ContractEntrust::status_completed)->sum('profit'); |
||||
|
|
||||
|
$con = '<code>' . '总盈亏:' . $res1 . 'USDT</code> '; |
||||
|
return Alert::make($con, '统计')->info(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
$data = ContractEntrust::with('user') |
||||
|
->whereHas('user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
}); |
||||
|
return Grid::make($data, function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('id'); |
||||
|
|
||||
|
#统计 |
||||
|
$grid->header(function ($query) { |
||||
|
return $this->statistics(); |
||||
|
}); |
||||
|
|
||||
|
$grid->actions(function (Grid\Displayers\Actions $actions) { |
||||
|
$actions->disableDelete(); |
||||
|
$actions->disableQuickEdit(); |
||||
|
$actions->disableEdit(); |
||||
|
$actions->disableView(); |
||||
|
|
||||
|
if (in_array($actions->row->status, [ContractEntrust::status_wait, ContractEntrust::status_trading])) { |
||||
|
$actions->append(new cancel()); |
||||
|
} |
||||
|
}); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableBatchDelete(); |
||||
|
// $grid->disableRowSelector(); |
||||
|
|
||||
|
$grid->tools([new BatchCancel()]); |
||||
|
|
||||
|
//$grid->column('id')->sortable(); |
||||
|
$grid->column('order_no'); |
||||
|
$grid->column('user_id'); |
||||
|
$grid->column('usermail', '邮箱')->display(function () { |
||||
|
//$realtime_price = Cache::store('redis')->get('swap:' . 'trade_detail_' . $this->symbol)['price'] ?? null; |
||||
|
//dd(ContractTool::getUserMail($this->user_id)); |
||||
|
return ContractTool::getUserMail($this->user_id); |
||||
|
}); |
||||
|
$grid->column('agname','代理邮箱')->display(function (){ |
||||
|
$var = ContractTool::GetProxyEmail($this->user_id); |
||||
|
//dd($var['username']); |
||||
|
return $var['username']; |
||||
|
}); |
||||
|
$grid->column('order_type_side', '交易类型')->display(function () { |
||||
|
if ($this->order_type == 1 && $this->side == 1) { |
||||
|
return '买入开多'; |
||||
|
} elseif ($this->order_type == 1 && $this->side == 2) { |
||||
|
return '卖出开空'; |
||||
|
} elseif ($this->order_type == 2 && $this->side == 1) { |
||||
|
return '买入平空'; |
||||
|
} else { |
||||
|
return '卖出平多'; |
||||
|
} |
||||
|
})->label(); |
||||
|
// $grid->column('order_type'); |
||||
|
// $grid->column('side'); |
||||
|
// $grid->column('contract_id'); |
||||
|
// $grid->column('contract_coin_id'); |
||||
|
$grid->column('symbol'); |
||||
|
$grid->column('type')->using(ContractEntrust::$typeMap); |
||||
|
$grid->column('lever_rate'); |
||||
|
$grid->column('entrust_price'); |
||||
|
// $grid->column('trigger_price'); |
||||
|
$grid->column('amount'); |
||||
|
$grid->column('traded_amount'); |
||||
|
// $grid->column('margin'); |
||||
|
$grid->column('avg_price'); |
||||
|
$grid->column('fee'); |
||||
|
$grid->column('profit'); |
||||
|
$grid->column('settle_profit'); |
||||
|
$grid->column('status')->using(ContractEntrust::$statusMap)->dot([ |
||||
|
1 => 'primary', |
||||
|
2 => 'danger', |
||||
|
3 => 'success', |
||||
|
4 => 'info', |
||||
|
], 'primary')->filter( |
||||
|
Grid\Column\Filter\In::make(ContractEntrust::$statusMap) |
||||
|
); |
||||
|
// $grid->column('hang_status'); |
||||
|
// $grid->column('cancel_time'); |
||||
|
// $grid->column('ts'); |
||||
|
$grid->column('created_at')->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->whereBetween('ts', function ($q) { |
||||
|
$start = $this->input['start'] ? strtotime($this->input['start']) : null; |
||||
|
$end = $this->input['end'] ? strtotime($this->input['end']) : null; |
||||
|
$q->whereBetween('ts', [$start, $end + 86399]); |
||||
|
}, '时间')->date(); |
||||
|
$filter->equal('user_id', 'UID')->width(3); |
||||
|
$filter->where('username', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$q->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
}, "用户名/手机/邮箱")->width(3); |
||||
|
$filter->equal('symbol')->width(3); |
||||
|
$filter->where('type', function ($q) { |
||||
|
if ($this->input == 1) { |
||||
|
$q->where('order_type', 1)->where('side', 1); |
||||
|
} elseif ($this->input == 2) { |
||||
|
$q->where('order_type', 1)->where('side', 2); |
||||
|
} elseif ($this->input == 3) { |
||||
|
$q->where('order_type', 2)->where('side', 2); |
||||
|
} else { |
||||
|
$q->where('order_type', 2)->where('side', 1); |
||||
|
} |
||||
|
}, '交易类型')->select([1 => '开多', 2 => '开空', 3 => '平多', 4 => '平空'])->width(3); |
||||
|
$filter->equal('user.pid', '代理商UID')->width(3); |
||||
|
$filter->where('agent_id', function ($query) { |
||||
|
$base_ids = collect(User::getChilds($this->input))->pluck('user_id'); |
||||
|
$query->whereHas('user', function ($query) use ($base_ids) { |
||||
|
$query->whereIn('user_id', $base_ids); |
||||
|
}); |
||||
|
}, '链上查询')->placeholder('输入代理商UID查询该代理链上委托')->width(3); |
||||
|
$filter->where('acc', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$aa = $q->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('whethertopromote', $username); |
||||
|
}); |
||||
|
}, "账号类型")->select(UserAuth::$typeMap)->width(2); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new ContractEntrust(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('order_no'); |
||||
|
$show->field('order_type'); |
||||
|
$show->field('user_id'); |
||||
|
$show->field('side'); |
||||
|
$show->field('contract_id'); |
||||
|
$show->field('contract_coin_id'); |
||||
|
$show->field('symbol'); |
||||
|
$show->field('type'); |
||||
|
$show->field('entrust_price'); |
||||
|
$show->field('trigger_price'); |
||||
|
$show->field('amount'); |
||||
|
$show->field('traded_amount'); |
||||
|
$show->field('lever_rate'); |
||||
|
$show->field('margin'); |
||||
|
$show->field('fee'); |
||||
|
$show->field('status'); |
||||
|
$show->field('hang_status'); |
||||
|
$show->field('cancel_time'); |
||||
|
$show->field('ts'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new ContractEntrust(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->text('order_no'); |
||||
|
$form->text('order_type'); |
||||
|
$form->text('user_id'); |
||||
|
$form->text('side'); |
||||
|
$form->text('contract_id'); |
||||
|
$form->text('contract_coin_id'); |
||||
|
$form->text('symbol'); |
||||
|
$form->text('type'); |
||||
|
$form->text('entrust_price'); |
||||
|
$form->text('trigger_price'); |
||||
|
$form->text('amount'); |
||||
|
$form->text('traded_amount'); |
||||
|
$form->text('lever_rate'); |
||||
|
$form->text('margin'); |
||||
|
$form->text('fee'); |
||||
|
$form->text('status'); |
||||
|
$form->text('hang_status'); |
||||
|
$form->text('cancel_time'); |
||||
|
$form->text('ts'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,251 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Handlers\ContractTool; |
||||
|
use App\Models\Agent; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Models\ContractEntrust; |
||||
|
use App\Models\ContractOrder; |
||||
|
use App\Models\ContractPair; |
||||
|
use App\Models\User; |
||||
|
use App\Models\UserWallet; |
||||
|
use App\Models\UserWalletLog; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Alert; |
||||
|
use Illuminate\Support\Facades\Log; |
||||
|
|
||||
|
class ContractOrderController extends AdminController |
||||
|
{ |
||||
|
public function statistics($query) |
||||
|
{ |
||||
|
// $builder1 = $query;();$builder1 = $query; |
||||
|
// $builder3 = UserWalletLog::query()->where('rich_type', 'usable_balance') |
||||
|
// ->where('account_type', UserWallet::sustainable_account) |
||||
|
// ->where('log_type', 'position_capital_cost') |
||||
|
// ->whereHas('user', function ($q) { |
||||
|
// $q->where('is_system', 0); |
||||
|
// }); |
||||
|
// $params = request()->only(['user_id', 'username', 'symbol', 'ts', 'agent_id']); |
||||
|
// if (!empty($params)) { |
||||
|
// if (!empty($params['user_id'])) { //按照用户名 |
||||
|
// $builder3->where('user_id', $params['user_id']); |
||||
|
// } |
||||
|
// if (!empty($params['username'])) { //按照用户名 |
||||
|
// $username = $params['username']; |
||||
|
// $builder3->whereHas('user', function ($q) use ($username) { |
||||
|
// $q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
// }); |
||||
|
// } |
||||
|
// if (!empty($params['symbol'])) { //按照币种 |
||||
|
// $pair = ContractPair::query()->where('symbol', $params['symbol'])->select('id', 'symbol')->first(); |
||||
|
// if (!blank($pair)) { |
||||
|
// $builder3->where('sub_account', $pair['id']); |
||||
|
// } |
||||
|
// } |
||||
|
// if (!empty($params['ts']) && !empty($params['ts']['start'])) { //按照时间 |
||||
|
// $start = $params['ts']['start'] ? strtotime($params['ts']['start']) : null; |
||||
|
// $end = $params['ts']['end'] ? strtotime($params['ts']['end']) : null; |
||||
|
// $builder3->whereDate('created_at', '>=', $start)->whereDate('created_at', '<=', $end); |
||||
|
// } |
||||
|
// if (!empty($params['agent_id'])) { //按照代理商UID查询链上 |
||||
|
// $referrer = $params['agent_id']; |
||||
|
// $childs = collect(User::getChilds($referrer))->pluck('user_id')->toArray(); |
||||
|
// $builder3->where(function ($query) use ($childs) { |
||||
|
// $query->whereIn('user_id', $childs); |
||||
|
// }); |
||||
|
// } |
||||
|
// } |
||||
|
|
||||
|
// $total_buy_fee = (clone $builder1)->whereHas('buy_user', function ($q) { |
||||
|
// $q->where('is_system', 0); |
||||
|
// })->sum('trade_buy_fee'); |
||||
|
// $total_sell_fee = (clone $builder1)->whereHas('sell_user', function ($q) { |
||||
|
// $q->where('is_system', 0); |
||||
|
// })->sum('trade_sell_fee'); |
||||
|
// $total_fee = $total_buy_fee + $total_sell_fee; // 总手续费 |
||||
|
// $total_profit_1 = (clone $builder1) |
||||
|
// ->with('buy_entrust') |
||||
|
// ->whereHas('buy_entrust', function ($query) { |
||||
|
// $query->whereHas('user', function ($query) { |
||||
|
// $query->where('is_system', 0); |
||||
|
// }); |
||||
|
// }) |
||||
|
// ->get()->sum('buy_entrust.profit'); //买盈亏 |
||||
|
// $total_profit_2 = (clone $builder1) |
||||
|
// ->with('sell_entrust') |
||||
|
// ->whereHas('sell_entrust', function ($query) { |
||||
|
// $query->whereHas('user', function ($query) { |
||||
|
// $query->where('is_system', 0); |
||||
|
// }); |
||||
|
// }) |
||||
|
// ->get()->sum('sell_entrust.profit'); //卖盈亏 |
||||
|
// $total_profit = $total_profit_1 + $total_profit_2; |
||||
|
// $total_cost = $builder3->sum('amount'); //总资金费 |
||||
|
|
||||
|
// $con = '<code>总手续费:' . abs($total_fee) . 'USDT</code> ' . '<code>总资金费:' . (float)abs($total_cost) . 'USDT</code> ' . '<code>总盈亏:' . (float)$total_profit . 'USDT</code> '; |
||||
|
// return Alert::make($con, '统计')->info(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
$query = ContractOrder::query()->where(function ($q) { |
||||
|
$q->whereHas('buy_user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
})->orWhereHas('sell_user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
}); |
||||
|
}); |
||||
|
return Grid::make($query, function (Grid $grid) use ($query) { |
||||
|
// return Grid::make(new ContractOrder(), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('id'); |
||||
|
|
||||
|
#统计 |
||||
|
$grid->header(function () use ($grid, $query) { |
||||
|
$grid->model()->getQueries()->unique()->each(function ($v) use ($query) { |
||||
|
if (in_array($v['method'], ['get', 'paginate', 'orderBy', 'orderByDesc'])) return; |
||||
|
call_user_func_array([$query, $v['method']], $v['arguments'] ?? []); |
||||
|
}); |
||||
|
return $this->statistics($query); |
||||
|
}); |
||||
|
|
||||
|
$grid->disableActions(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
|
||||
|
$grid->column('id')->sortable(); |
||||
|
// $grid->column('contract_id'); |
||||
|
$grid->column('symbol'); |
||||
|
$grid->column('order_type')->using([1 => '开仓', 2 => '平仓'])->label(); |
||||
|
$grid->column('lever_rate'); |
||||
|
$grid->column('buy_id')->link(function ($value) { |
||||
|
return admin_url('contract-entrust', $value); |
||||
|
}); |
||||
|
$grid->column('usermail', '邮箱')->display(function () { |
||||
|
//dd($this->buy_user_id); |
||||
|
//$realtime_price = Cache::store('redis')->get('swap:' . 'trade_detail_' . $this->symbol)['price'] ?? null; |
||||
|
//dd(ContractTool::getUserMail($this->user_id)); |
||||
|
if ($this->buy_user_id != 0){ |
||||
|
return ContractTool::getUserMail($this->buy_user_id); |
||||
|
} |
||||
|
|
||||
|
}); |
||||
|
$grid->column('agname','代理邮箱')->display(function (){ |
||||
|
|
||||
|
if ($this->buy_user_id != 0){ |
||||
|
$var = ContractTool::GetProxyEmail($this->buy_user_id); |
||||
|
//dd($var['username']); |
||||
|
return $var['username']; |
||||
|
} |
||||
|
|
||||
|
}); |
||||
|
$grid->column('sell_id')->link(function ($value) { |
||||
|
return admin_url('contract-entrust', $value); |
||||
|
});; |
||||
|
$grid->column('buy_user_id'); |
||||
|
$grid->column('sell_user_id'); |
||||
|
$grid->column('unit_price'); |
||||
|
$grid->column('trade_amount'); |
||||
|
$grid->column('trade_buy_fee'); |
||||
|
$grid->column('trade_sell_fee'); |
||||
|
$grid->column('position_margin'); |
||||
|
$grid->column('ts', '时间')->display(function ($v) { |
||||
|
return date('Y-m-d H:i:s', $v); |
||||
|
}); |
||||
|
// $grid->column('created_at')->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->whereBetween('ts', function ($q) { |
||||
|
$start = $this->input['start'] ? strtotime($this->input['start']) : null; |
||||
|
$end = $this->input['end'] ? strtotime($this->input['end']) : null; |
||||
|
$q->whereBetween('ts', [$start, $end + 86399]); |
||||
|
}, '时间')->date(); |
||||
|
$filter->where('user_id', function ($q) { |
||||
|
$q->where('buy_user_id', $this->input)->orWhere('sell_user_id', $this->input); |
||||
|
}, 'UID')->width(2); |
||||
|
$filter->where('username', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$q->whereHas('buy_user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
})->orWhereHas('sell_user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
}, "用户名/手机/邮箱")->width(3); |
||||
|
$filter->equal('symbol')->width(3); |
||||
|
$filter->where('agent_id', function ($query) { |
||||
|
$referrer = $this->input; |
||||
|
$childs = collect(User::getChilds($referrer))->pluck('user_id')->toArray(); |
||||
|
$query->where(function ($query) use ($childs) { |
||||
|
$query->whereIn('buy_user_id', $childs) |
||||
|
->orWhereIn('sell_user_id', $childs); |
||||
|
}); |
||||
|
}, '链上查询')->placeholder('输入代理商UID查看链上用户订单')->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new ContractOrder(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('contract_id'); |
||||
|
$show->field('symbol'); |
||||
|
$show->field('lever_rate'); |
||||
|
$show->field('order_type'); |
||||
|
$show->field('buy_id'); |
||||
|
$show->field('sell_id'); |
||||
|
$show->field('buy_user_id'); |
||||
|
$show->field('sell_user_id'); |
||||
|
$show->field('unit_price'); |
||||
|
$show->field('trade_amount'); |
||||
|
$show->field('trade_buy_fee'); |
||||
|
$show->field('trade_sell_fee'); |
||||
|
$show->field('ts'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new ContractOrder(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->text('contract_id'); |
||||
|
$form->text('symbol'); |
||||
|
$form->text('lever_rate'); |
||||
|
$form->text('order_type'); |
||||
|
$form->text('buy_id'); |
||||
|
$form->text('sell_id'); |
||||
|
$form->text('buy_user_id'); |
||||
|
$form->text('sell_user_id'); |
||||
|
$form->text('unit_price'); |
||||
|
$form->text('trade_amount'); |
||||
|
$form->text('trade_buy_fee'); |
||||
|
$form->text('trade_sell_fee'); |
||||
|
$form->text('ts'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,130 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\Coins; |
||||
|
use App\Models\ContractPair; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class ContractPairController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new ContractPair(), function (Grid $grid) { |
||||
|
$grid->column('id')->sortable(); |
||||
|
$grid->column('symbol'); |
||||
|
// $grid->column('contract_coin_id'); |
||||
|
// $grid->column('contract_coin_name'); |
||||
|
$grid->column('type'); |
||||
|
$grid->column('unit_amount'); |
||||
|
$grid->column('maker_fee_rate'); |
||||
|
$grid->column('taker_fee_rate'); |
||||
|
$grid->column('lever_rage')->label(); |
||||
|
$grid->column('default_lever')->label('info'); |
||||
|
// $grid->column('min_qty'); |
||||
|
// $grid->column('max_qty'); |
||||
|
// $grid->column('total_max_qty'); |
||||
|
$grid->column('buy_spread'); |
||||
|
$grid->column('sell_spread'); |
||||
|
$grid->column('settle_spread'); |
||||
|
$grid->column('status')->switch(); |
||||
|
$grid->column('trade_status')->switch(); |
||||
|
$grid->column('created_at'); |
||||
|
// $grid->column('updated_at')->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('symbol')->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new ContractPair(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('symbol'); |
||||
|
$show->field('contract_coin_id'); |
||||
|
$show->field('contract_coin_name'); |
||||
|
$show->field('type'); |
||||
|
$show->field('unit_amount'); |
||||
|
$show->field('maker_fee_rate'); |
||||
|
$show->field('taker_fee_rate'); |
||||
|
$show->field('status'); |
||||
|
$show->field('trade_status'); |
||||
|
$show->field('lever_rage'); |
||||
|
$show->field('min_qty'); |
||||
|
$show->field('max_qty'); |
||||
|
$show->field('total_max_qty'); |
||||
|
$show->field('buy_spread'); |
||||
|
$show->field('sell_spread'); |
||||
|
$show->field('settle_spread'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new ContractPair(), function (Form $form) { |
||||
|
$form->disableDeleteButton(); |
||||
|
|
||||
|
$options = Coins::query()->where('status', 1)->orderByDesc('coin_id')->pluck('coin_name', 'coin_id')->toArray(); |
||||
|
|
||||
|
$form->display('id'); |
||||
|
$form->hidden('symbol'); |
||||
|
$form->select('contract_coin_id')->options($options); |
||||
|
$form->hidden('contract_coin_name'); |
||||
|
$form->text('type')->default('USDT')->readOnly(); |
||||
|
$form->text('unit_amount')->default(1); |
||||
|
$form->text('maker_fee_rate')->default(0.0005); |
||||
|
$form->text('taker_fee_rate')->default(0.0005); |
||||
|
$form->list('lever_rage')->min(1)->saving(function ($v) { |
||||
|
return json_decode($v); |
||||
|
}); |
||||
|
$form->text('default_lever'); |
||||
|
$form->text('min_qty')->required(); |
||||
|
$form->text('max_qty')->required(); |
||||
|
$form->text('total_max_qty')->required(); |
||||
|
$form->text('buy_spread'); |
||||
|
$form->text('sell_spread'); |
||||
|
$form->text('settle_spread'); |
||||
|
$form->switch('status')->default(1); |
||||
|
$form->switch('trade_status')->default(1); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
|
||||
|
$form->saving(function (Form $form) use ($options) { |
||||
|
if ($form->isCreating() || $form->isEditing()) { |
||||
|
if (!blank($form->contract_coin_id)) { |
||||
|
$contract_coin_id = $form->contract_coin_id; |
||||
|
$contract_coin_name = $options[$contract_coin_id]; |
||||
|
$form->contract_coin_id = $contract_coin_id; |
||||
|
$form->contract_coin_name = $contract_coin_name; |
||||
|
$form->symbol = $contract_coin_name; |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,194 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Actions\ContractPosition\Flat; |
||||
|
use App\Admin\Actions\ContractPosition\OnekeyFlatPosition; |
||||
|
use App\Handlers\ContractTool; |
||||
|
use App\Models\Agent; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Models\ContractPair; |
||||
|
use App\Models\ContractPosition; |
||||
|
use App\Models\ContractStrategy; |
||||
|
use App\Models\SustainableAccount; |
||||
|
use App\Models\UserAuth; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use GatewayWorker\Lib\Db; |
||||
|
use Illuminate\Support\Facades\Cache; |
||||
|
|
||||
|
class ContractPositionController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
$builder = ContractPosition::query()->where('hold_position', '>', 0); |
||||
|
return Grid::make($builder, function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('id'); |
||||
|
$grid->disableRowSelector(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->actions(function (Grid\Displayers\Actions $actions) { |
||||
|
$actions->disableDelete(); |
||||
|
$actions->disableQuickEdit(); |
||||
|
$actions->disableEdit(); |
||||
|
$actions->disableView(); |
||||
|
|
||||
|
$actions->append(new Flat()); |
||||
|
}); |
||||
|
|
||||
|
$grid->tools([new OnekeyFlatPosition()]); |
||||
|
|
||||
|
$grid->column('id')->sortable(); |
||||
|
$grid->column('user_id'); |
||||
|
$grid->column('usermail', '邮箱')->display(function () { |
||||
|
//$realtime_price = Cache::store('redis')->get('swap:' . 'trade_detail_' . $this->symbol)['price'] ?? null; |
||||
|
// dd(ContractTool::getUserMail($this->user_id)); |
||||
|
return ContractTool::getUserMail($this->user_id); |
||||
|
}); |
||||
|
$grid->column('agname', '代理邮箱')->display(function () { |
||||
|
$var = ContractTool::GetProxyEmail($this->user_id); |
||||
|
// dd($var['username'],$this->user_id); |
||||
|
return $var['username']; |
||||
|
}); |
||||
|
$grid->column('symbol'); |
||||
|
$grid->column('side')->using([1 => '多', 2 => '空'])->label([1 => 'info', 2 => 'danger']); |
||||
|
// $grid->column('contract_id'); |
||||
|
// $grid->column('unit_amount'); |
||||
|
$grid->column('lever_rate'); |
||||
|
$grid->column('hold_position'); |
||||
|
$grid->column('avail_position'); |
||||
|
$grid->column('freeze_position'); |
||||
|
$grid->column('position_margin'); |
||||
|
$grid->column('avg_price'); |
||||
|
|
||||
|
$grid->column('LatestPrice', '最新价格')->display(function () { |
||||
|
|
||||
|
return $realtime_price = Cache::store('redis')->get('swap:' . 'trade_detail_' . $this->symbol)['price'] ?? null; |
||||
|
//return ContractTool::unRealProfit($this, ['unit_amount' => $this->unit_amount], $realtime_price); |
||||
|
}); |
||||
|
$grid->column('unRealProfit', '未实现盈亏')->display(function () { |
||||
|
$realtime_price = Cache::store('redis')->get('swap:' . 'trade_detail_' . $this->symbol)['price'] ?? null; |
||||
|
return ContractTool::unRealProfit($this, ['unit_amount' => $this->unit_amount], $realtime_price); |
||||
|
}); |
||||
|
$grid->column('ProfitAndLossRatio', '盈亏比')->display(function () { |
||||
|
$realtime_price = Cache::store('redis')->get('swap:' . 'trade_detail_' . $this->symbol)['price'] ?? null; |
||||
|
if ($this->side == 1) { |
||||
|
$aa = ($realtime_price - $this->avg_price) / $this->avg_price * $this->lever_rate; |
||||
|
} else { |
||||
|
$aa = ($this->avg_price - $realtime_price) / $this->avg_price * $this->lever_rate; |
||||
|
} |
||||
|
|
||||
|
$aa = sprintf("%.2f", $aa); |
||||
|
return $aa * 100 . '%'; |
||||
|
}); |
||||
|
$grid->column('estimatedLiquidationValue', '预估强平值')->display(function () { |
||||
|
|
||||
|
$account = SustainableAccount::getContractAccount($this->user_id); |
||||
|
$contract = ContractPair::query()->find($this->contract_id); |
||||
|
//$realtime_price = Cache::store('redis')->get('swap:' . 'trade_detail_' . $this->symbol)['price'] ?? null; |
||||
|
//dd(ContractTool::getUserMail($this->user_id)); |
||||
|
//return ContractTool::getUserMail($this->user_id); |
||||
|
return ContractTool::getFlatPrice($account, $contract); |
||||
|
}); |
||||
|
$grid->column('zhiying','止盈/止损')->display(function(){ |
||||
|
$strategy = ContractStrategy::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('status', 1) |
||||
|
->where('contract_id', $this->contract_id) |
||||
|
->where('position_side', $this->side) |
||||
|
->first(); |
||||
|
// $abababa =$strategy['created_at']; |
||||
|
$abababa = $strategy['tp_trigger_price'] ?? '--' ; |
||||
|
$abababa .= "/"; |
||||
|
$abababa .=$strategy['sl_trigger_price'] ?? '--'; |
||||
|
|
||||
|
return $abababa; |
||||
|
}); |
||||
|
$grid->column('updated_at'); |
||||
|
$grid->column('forCurrencyBalances', '对于币种余额')->display(function () { |
||||
|
$conac = $account = SustainableAccount::getContractAccount($this->user_id); |
||||
|
return $conac['usable_balance']; |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
// $grid->column('created_at'); |
||||
|
// $grid->column('updated_at')->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('user_id')->width(3); |
||||
|
$filter->where('username', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$aa = $q->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
}, "用户名/手机/邮箱")->width(3); |
||||
|
$filter->equal('symbol')->width(3); |
||||
|
$filter->where('acc', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$aa = $q->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('whethertopromote', $username); |
||||
|
}); |
||||
|
}, "账号类型")->select(UserAuth::$typeMap)->width(2); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new ContractPosition(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('user_id'); |
||||
|
$show->field('side'); |
||||
|
$show->field('contract_id'); |
||||
|
$show->field('symbol'); |
||||
|
$show->field('unit_amount'); |
||||
|
$show->field('lever_rate'); |
||||
|
$show->field('hold_position'); |
||||
|
$show->field('avail_position'); |
||||
|
$show->field('freeze_position'); |
||||
|
$show->field('position_margin'); |
||||
|
$show->field('avg_price'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new ContractPosition(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->text('user_id'); |
||||
|
$form->text('side'); |
||||
|
$form->text('contract_id'); |
||||
|
$form->text('symbol'); |
||||
|
$form->text('unit_amount'); |
||||
|
$form->text('lever_rate'); |
||||
|
$form->text('hold_position'); |
||||
|
$form->text('avail_position'); |
||||
|
$form->text('freeze_position'); |
||||
|
$form->text('position_margin'); |
||||
|
$form->text('avg_price'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\ContractPair; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Layout\Content; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Card; |
||||
|
use Illuminate\Support\Facades\Cache; |
||||
|
|
||||
|
class ContractRiskController extends AdminController |
||||
|
{ |
||||
|
public function index(Content $content) |
||||
|
{ |
||||
|
return $content |
||||
|
->title('合约风控') |
||||
|
->body(new Card(new \App\Admin\Forms\ContractRisk())); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,95 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Actions\User\AddContractControl; |
||||
|
use App\Admin\Actions\User\AddPromotionUser; |
||||
|
use App\Admin\Actions\User\AddSystemUser; |
||||
|
use App\Admin\Actions\User\AddUser; |
||||
|
use App\Admin\Renderable\Parents; |
||||
|
use App\Admin\Renderable\UserTradeStatistics; |
||||
|
use App\Admin\Renderable\UserWalletExpand; |
||||
|
use App\Handlers\ContractTool; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Models\ContractPair; |
||||
|
use App\Models\ContractPosition; |
||||
|
use App\Models\PlatformContractControl; |
||||
|
use App\Models\SustainableAccount; |
||||
|
use App\Models\User; |
||||
|
use App\Models\UserAuth; |
||||
|
use App\Models\UserGrade; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Layout\Content; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Card; |
||||
|
use Illuminate\Support\Facades\Cache; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class ContractRisknewController extends AdminController |
||||
|
{ |
||||
|
// public function index(Content $content) |
||||
|
// { |
||||
|
// return $content |
||||
|
// ->title('新合约风控') |
||||
|
// ->body(new Card(new \App\Admin\Forms\ContractRisknew())); |
||||
|
// } |
||||
|
|
||||
|
protected function grid() |
||||
|
{ |
||||
|
$pcc = PlatformContractControl::query()->orderByDesc('id'); |
||||
|
return Grid::make($pcc, function (Grid $grid) { |
||||
|
// $aa = DB::select('select * from contract_position'); |
||||
|
|
||||
|
if (Admin::user()->can('addSystemUser')) { |
||||
|
$grid->tools([new AddContractControl()]); |
||||
|
} |
||||
|
|
||||
|
$grades = AgentGrade::getCachedGradeOption(); |
||||
|
|
||||
|
$grid->id; |
||||
|
|
||||
|
|
||||
|
$grid->column('symbol','币种名称'); |
||||
|
$grid->column('now_price','操作价格'); |
||||
|
$grid->column('blacktime','回调时间'); |
||||
|
$grid->column('time','操作时间')->display(function ($v) { |
||||
|
return date('Y-m-d H:i:s', $v); |
||||
|
});; |
||||
|
|
||||
|
|
||||
|
$grid->disableViewButton(); |
||||
|
$grid->disableCreateButton(); |
||||
|
//$grid->disableEditButton(); |
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->disableBatchDelete(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) use ($grades) { |
||||
|
$filter->between('created_at', "时间")->date()->width(4); |
||||
|
$filter->equal('whethertopromote', '币种名称')->select(function (){ |
||||
|
$symbols = config('coin.exchange_symbols'); |
||||
|
$PlatformCurrency = []; |
||||
|
foreach ($symbols as $key=>$val){ |
||||
|
$PlatformCurrency[]= $key; |
||||
|
// var_dump($key); |
||||
|
} |
||||
|
return $PlatformCurrency; |
||||
|
|
||||
|
})->width(2); |
||||
|
}); |
||||
|
}) |
||||
|
->title('新合约风控'); |
||||
|
} |
||||
|
|
||||
|
public function symbolDetal(Request $request){ |
||||
|
$cd = Cache::store('redis')->get('swap:' . $request['symbol'] . '_detail'); |
||||
|
if($cd){ |
||||
|
$cd['highest'] = $cd['price'] * 1.1; |
||||
|
$cd['minimum'] = $cd['price'] * 0.9; |
||||
|
} |
||||
|
|
||||
|
return $cd; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,216 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\Agent; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Models\ContractEntrust; |
||||
|
use App\Models\ContractOrder; |
||||
|
use App\Models\Recharge; |
||||
|
use App\Models\SustainableAccount; |
||||
|
use App\Models\UserWallet; |
||||
|
use App\Models\UserWalletLog; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Alert; |
||||
|
|
||||
|
class ContractSettlementController extends AdminController |
||||
|
{ |
||||
|
protected $title = '合约结算'; |
||||
|
|
||||
|
public function statistics() |
||||
|
{ |
||||
|
$grades = AgentGrade::getCachedGradeOption(); |
||||
|
// 盈亏 |
||||
|
$builder1 = ContractEntrust::query()->where('order_type', 2)->whereHas('user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
}); |
||||
|
// 手续费 |
||||
|
$builder2 = UserWalletLog::query()->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->whereHas('user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
}) |
||||
|
->whereIn('log_type', ['open_position_fee', 'close_position_fee', 'system_close_position_fee', 'cancel_open_position_fee']); |
||||
|
// 资金费 |
||||
|
$builder3 = UserWalletLog::query()->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->where('log_type', 'position_capital_cost') |
||||
|
->whereHas('user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
}); |
||||
|
|
||||
|
$params = request()->only(array_merge($grades, ['user_id', 'created_at'])); |
||||
|
|
||||
|
if (!empty($params)) { |
||||
|
if (!empty($params['user_id'])) { |
||||
|
$builder1->where('user_id', $params['user_id']); |
||||
|
$builder2->where('user_id', $params['user_id']); |
||||
|
$builder3->where('user_id', $params['user_id']); |
||||
|
} |
||||
|
if (!empty($params['created_at']) && !empty($params['created_at']['start'])) { |
||||
|
$builder1->whereDate('created_at', '>=', $params['created_at']['start'])->whereDate('created_at', '<=', $params['created_at']['end']); |
||||
|
$builder2->whereDate('created_at', '>=', $params['created_at']['start'])->whereDate('created_at', '<=', $params['created_at']['end']); |
||||
|
$builder3->whereDate('created_at', '>=', $params['created_at']['start'])->whereDate('created_at', '<=', $params['created_at']['end']); |
||||
|
} |
||||
|
|
||||
|
$lk = last(array_keys($grades)); |
||||
|
foreach ($grades as $k => $v) { |
||||
|
$key = 'A' . ($k + 1); |
||||
|
if ($k == $lk && !empty($params[$key])) { |
||||
|
$id = $params[$key]; |
||||
|
$builder1->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
$builder2->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
$builder3->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
} elseif (!empty($params[$key])) { |
||||
|
$ids = Agent::getBaseAgentIds($params[$key]); |
||||
|
$builder1->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
$builder2->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
$builder3->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$total_profit = $builder1->where('status', ContractEntrust::status_completed)->sum('profit'); |
||||
|
$total_fee = $builder2->sum('amount'); |
||||
|
$total_cost = $builder3->sum('amount'); |
||||
|
$total_amount = abs($total_fee) + abs($total_cost) - $total_profit; |
||||
|
|
||||
|
$con = '<code>总手续费:' . (float)abs($total_fee) . 'USDT</code> ' . '<code>总资金费:' . (float)abs($total_cost) . 'USDT</code> ' . '<code>总盈亏:' . (float)$total_profit . 'USDT</code> ' . '<code>总业绩:' . (float)$total_amount . 'USDT</code> '; |
||||
|
return Alert::make($con, '统计')->info(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 代理结算 |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(SustainableAccount::with(['user']), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('user_id'); |
||||
|
|
||||
|
#统计 |
||||
|
$grid->header(function ($query) { |
||||
|
return $this->statistics(); |
||||
|
}); |
||||
|
|
||||
|
// $grid->column('id')->sortable(); |
||||
|
|
||||
|
$grid->disableActions(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
|
||||
|
// $grid->column('user.referrer','A5')->display(function($referrer){ |
||||
|
// $agent = Agent::query()->where('is_agency',1)->where("id",$referrer)->first(); |
||||
|
// if(blank($agent)){ |
||||
|
// return '--'; |
||||
|
// }else{ |
||||
|
// $parent = $agent->parent->parent->parent->parent; |
||||
|
// return blank($parent) ? "--" : $parent['name']; |
||||
|
// } |
||||
|
// }); |
||||
|
$grid->column('user_id', 'UID'); |
||||
|
|
||||
|
$grid->column('user.referrer', '代理ID'); |
||||
|
|
||||
|
$grid->column('contract_fee', '手续费')->display(function () { |
||||
|
return abs(UserWalletLog::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->whereIn('log_type', ['open_position_fee', 'close_position_fee', 'system_close_position_fee', 'cancel_open_position_fee']) |
||||
|
->sum('amount')); |
||||
|
}); |
||||
|
$grid->column('contract_cost', '资金费')->display(function () { |
||||
|
return abs(UserWalletLog::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->where('log_type', 'position_capital_cost') |
||||
|
->sum('amount')); |
||||
|
}); |
||||
|
$grid->column('contract_profit', '盈亏')->display(function () { |
||||
|
return ContractEntrust::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('order_type', 2) |
||||
|
->where('status', ContractEntrust::status_completed) |
||||
|
->sum('profit'); |
||||
|
}); |
||||
|
|
||||
|
$grid->column('total_amount', '总业绩')->display(function () { |
||||
|
$fee = UserWalletLog::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->whereIn('log_type', ['open_position_fee', 'close_position_fee', 'system_close_position_fee', 'cancel_open_position_fee']) |
||||
|
->sum('amount'); |
||||
|
$cost = UserWalletLog::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('rich_type', 'usable_balance') |
||||
|
->where('account_type', UserWallet::sustainable_account) |
||||
|
->where('log_type', 'position_capital_cost') |
||||
|
->sum('amount'); |
||||
|
$profit = ContractEntrust::query() |
||||
|
->where('user_id', $this->user_id) |
||||
|
->where('order_type', 2) |
||||
|
->where('status', ContractEntrust::status_completed) |
||||
|
->sum('profit'); |
||||
|
|
||||
|
return abs($fee) + abs($cost) - $profit; |
||||
|
}); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$grades = AgentGrade::getCachedGradeOption(); |
||||
|
$lk = last(array_keys($grades)); |
||||
|
foreach ($grades as $k => $v) { |
||||
|
$key = 'A' . ($k + 1); |
||||
|
$next_key = 'A' . ($k + 2); |
||||
|
if ($k == 0) { |
||||
|
$options1 = Agent::query()->where(['deep' => 0, 'is_agency' => 1])->pluck('username', 'id'); |
||||
|
$filter->where($key, function ($q) { |
||||
|
$ids = Agent::getBaseAgentIds($this->input); |
||||
|
$q->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
}, $v)->select($options1)->load($next_key, 'api/agents')->placeholder('请选择')->width(2); |
||||
|
} elseif ($k == $lk) { |
||||
|
$filter->where($key, function ($q) { |
||||
|
$id = $this->input; |
||||
|
$q->whereHas('user', function ($q) use ($id) { |
||||
|
$q->where('referrer', $id); |
||||
|
}); |
||||
|
}, $v)->select()->placeholder('请选择')->width(2); |
||||
|
} else { |
||||
|
$filter->where($key, function ($q) { |
||||
|
$ids = Agent::getBaseAgentIds($this->input); |
||||
|
$q->whereHas('user', function ($q) use ($ids) { |
||||
|
$q->whereIn('referrer', $ids); |
||||
|
}); |
||||
|
}, $v)->select()->load($next_key, 'api/agents')->placeholder('请选择')->width(2); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$filter->equal('user_id', 'UID')->width(2); |
||||
|
$filter->whereBetween('created_at', function ($q) { |
||||
|
}, "时间")->date()->width(4); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,114 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-29 10:40:49 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-13 15:57:59 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\ContractShare; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class ContractShareController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new ContractShare(), function (Grid $grid) { |
||||
|
$grid->column('id')->sortable(); |
||||
|
|
||||
|
$grid->actions(function (Grid\Displayers\Actions $actions) { |
||||
|
$actions->disableDelete(); |
||||
|
$actions->disableQuickEdit(); |
||||
|
// $actions->disableEdit(); |
||||
|
$actions->disableView(); |
||||
|
}); |
||||
|
$grid->column('type', '涨跌')->radio(['1' => '涨', 2 => '跌']); |
||||
|
$grid->column('created_at')->display(function ($v) { |
||||
|
return date('Y-m-d H:i:s', $v); |
||||
|
}); |
||||
|
$grid->column('bg_img')->image(); |
||||
|
$grid->column('text_img')->image(); |
||||
|
$grid->column('peri_img')->image(); |
||||
|
$grid->column('status')->switch(); |
||||
|
|
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
// $filter->equal('id'); |
||||
|
|
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new ContractShare(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('data'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(ContractShare::with('translations'), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->radio('type', '涨跌')->options([ |
||||
|
1 => '涨', |
||||
|
2 => '跌' |
||||
|
]); |
||||
|
$form->hasMany('translations', '标题', function (Form\NestedForm $form) { |
||||
|
$form->select('locale', '语言')->options([ |
||||
|
'en' => '英文', |
||||
|
'zh-CN' => '中文', |
||||
|
"zh-TW" => "繁体", |
||||
|
'kor' => '韩文', |
||||
|
'jp' => '日文', |
||||
|
'de' => '德文', |
||||
|
'it' => '意大利文', |
||||
|
'nl' => '荷兰文', |
||||
|
'pl' => '波兰文', |
||||
|
'pt' => '葡萄牙文', |
||||
|
'spa' => '西班牙文', |
||||
|
'swe' => '瑞典文', |
||||
|
'tr' => '土耳其文', |
||||
|
'uk' => '乌克兰文', |
||||
|
])->default('zh-CN'); |
||||
|
$form->text('title', '标题'); |
||||
|
}); |
||||
|
|
||||
|
$form->image('bg_img', '背景图')->uniqueName()->autoUpload()->disableRemove(); |
||||
|
$form->image('text_img', '文字图')->uniqueName()->autoUpload()->disableRemove(); |
||||
|
$form->image('peri_img', '人物图')->uniqueName()->autoUpload()->disableRemove(); |
||||
|
|
||||
|
$form->switch('status')->default(1); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,153 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-29 10:40:49 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-09 17:43:03 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Handlers\ContractTool; |
||||
|
use App\Models\Agent; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Models\ContractWearPositionRecord; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Alert; |
||||
|
|
||||
|
class ContractWearPositionRecordController extends AdminController |
||||
|
{ |
||||
|
public function statistics() |
||||
|
{ |
||||
|
$builder = ContractWearPositionRecord::query()->whereHas('user', function ($q) { |
||||
|
$q->where('is_system', 0); |
||||
|
}); |
||||
|
$params = request()->only(['user_id', 'symbol']); |
||||
|
|
||||
|
if (!empty($params)) { |
||||
|
if (!empty($params['user_id'])) { |
||||
|
$builder->where('user_id', $params['user_id']); |
||||
|
} |
||||
|
if (!empty($params['symbol'])) { |
||||
|
$builder->where('symbol', $params['symbol']); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$total = $builder->count(); |
||||
|
$total_loss = $builder->sum('loss'); |
||||
|
|
||||
|
$con = '<code>总记录数:' . $total . '</code> ' . '<code>穿仓损失:' . $total_loss . ' USDT' . '</code> '; |
||||
|
return Alert::make($con, '统计')->info(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new ContractWearPositionRecord(), function (Grid $grid) { |
||||
|
|
||||
|
#统计 |
||||
|
$grid->header(function ($query) { |
||||
|
return $this->statistics(); |
||||
|
}); |
||||
|
|
||||
|
$grid->model()->orderByDesc('id'); |
||||
|
|
||||
|
$grid->disableRowSelector(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableActions(); |
||||
|
|
||||
|
//$grid->column('id')->sortable(); |
||||
|
$grid->column('user_id'); |
||||
|
$grid->column('usermail', '邮箱')->display(function () { |
||||
|
//$realtime_price = Cache::store('redis')->get('swap:' . 'trade_detail_' . $this->symbol)['price'] ?? null; |
||||
|
//dd(ContractTool::getUserMail($this->user_id)); |
||||
|
return ContractTool::getUserMail($this->user_id); |
||||
|
}); |
||||
|
$grid->column('agname','代理邮箱')->display(function (){ |
||||
|
//dd($this->user_id); |
||||
|
$var = ContractTool::GetProxyEmail($this->user_id); |
||||
|
//dd($var); |
||||
|
return $var['username']; |
||||
|
}); |
||||
|
// $grid->column('contract_id'); |
||||
|
$grid->column('symbol'); |
||||
|
$grid->column('position_side')->using([1 => '多', 2 => '空'])->label([1 => 'info', 2 => 'danger']); |
||||
|
$grid->column('open_position_price'); |
||||
|
$grid->column('close_position_price'); |
||||
|
$grid->column('profit'); |
||||
|
$grid->column('settle_profit'); |
||||
|
$grid->column('loss'); |
||||
|
$grid->column('ts')->display(function ($v) { |
||||
|
return date('Y-m-d H:i:s', $v); |
||||
|
}); |
||||
|
// $grid->column('created_at'); |
||||
|
// $grid->column('updated_at')->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('user_id')->width(3); |
||||
|
$filter->equal('symbol')->width(3); |
||||
|
$filter->whereBetween('ts', function ($q) { |
||||
|
$start = $this->input['start'] ? strtotime($this->input['start']) : null; |
||||
|
$end = $this->input['end'] ? strtotime($this->input['end']) : null; |
||||
|
$q->whereBetween('ts', [$start, $end + 86399]); |
||||
|
}, '时间')->date()->width(4); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new ContractWearPositionRecord(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('user_id'); |
||||
|
$show->field('contract_id'); |
||||
|
$show->field('symbol'); |
||||
|
$show->field('position_side'); |
||||
|
$show->field('open_position_price'); |
||||
|
$show->field('close_position_price'); |
||||
|
$show->field('profit'); |
||||
|
$show->field('settle_profit'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new ContractWearPositionRecord(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->text('user_id'); |
||||
|
$form->text('contract_id'); |
||||
|
$form->text('symbol'); |
||||
|
$form->text('position_side'); |
||||
|
$form->text('open_position_price'); |
||||
|
$form->text('close_position_price'); |
||||
|
$form->text('profit'); |
||||
|
$form->text('settle_profit'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,125 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/** |
||||
|
* Created by PhpStorm. |
||||
|
* User: Administrator |
||||
|
* Date: 2020/8/6 |
||||
|
* Time: 15:14 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\Coins; |
||||
|
use Dcat\Admin\Widgets\Card; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class CurrencyDetailsController extends AdminController |
||||
|
{ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new Coins(), function (Grid $grid) { |
||||
|
$grid->id->sortable(); |
||||
|
$grid->coin_name; |
||||
|
$grid->symbol; |
||||
|
$grid->full_name; |
||||
|
$grid->withdrawal_fee; |
||||
|
$grid->official_website_link->display('详情') // 设置按钮名称 |
||||
|
->expand(function () { |
||||
|
// 返回显示的详情// |
||||
|
// 这里返回 content 字段内容,并用 Card 包裹起来 |
||||
|
$card = new Card("官网地址", $this->official_website_link); |
||||
|
|
||||
|
return "<div style='padding:10px 10px 0'>$card</div>"; |
||||
|
}); |
||||
|
$grid->white_paper_link->display('详情') // 设置按钮名称 |
||||
|
->expand(function () { |
||||
|
// 返回显示的详情// |
||||
|
// 这里返回 content 字段内容,并用 Card 包裹起来 |
||||
|
$card = new Card("白皮书地址", $this->white_paper_link); |
||||
|
|
||||
|
return "<div style='padding:10px 10px 0'>$card</div>"; |
||||
|
}); |
||||
|
$grid->block_query_link->display('详情') // 设置按钮名称 |
||||
|
->expand(function () { |
||||
|
// 返回显示的详情// |
||||
|
// 这里返回 content 字段内容,并用 Card 包裹起来 |
||||
|
$card = new Card("区块查询地址", $this->block_query_link); |
||||
|
|
||||
|
return "<div style='padding:10px 10px 0'>$card</div>"; |
||||
|
}); |
||||
|
$grid->publish_time; |
||||
|
$grid->total_issuance; |
||||
|
$grid->total_circulation; |
||||
|
$grid->crowdfunding_price; |
||||
|
$grid->coin_content->display('详情') // 设置按钮名称 |
||||
|
->expand(function () { |
||||
|
// 返回显示的详情// |
||||
|
// 这里返回 content 字段内容,并用 Card 包裹起来 |
||||
|
$card = new Card("项目详情", $this->coin_content); |
||||
|
|
||||
|
return "<div style='padding:10px 10px 0'>$card</div>"; |
||||
|
});; |
||||
|
// $grid->coin_content; |
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->filter(function ($filter) { |
||||
|
$filter->equal('contact_phone', '联系人电话'); |
||||
|
$filter->like('status', '审核状态'); |
||||
|
$filter->like('coin_name', '币种名字'); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new Coins(), function (Show $show) { |
||||
|
// 这里的字段会自动使用翻译文件 |
||||
|
$show->full_name; |
||||
|
$show->withdrawal_fee; |
||||
|
$show->official_website_link; |
||||
|
$show->coin_content; |
||||
|
$show->white_paper_link; |
||||
|
$show->block_query_link; |
||||
|
$show->publish_time; |
||||
|
$show->total_issuance; |
||||
|
$show->total_circulation; |
||||
|
$show->crowdfunding_price; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new Coins(), function (Form $form) { |
||||
|
// 这里的字段会自动使用翻译文件 |
||||
|
$form->text('full_name'); |
||||
|
$form->text('coin_content'); |
||||
|
$form->text('withdrawal_fee'); |
||||
|
$form->text('official_website_link'); |
||||
|
$form->text('white_paper_link'); |
||||
|
$form->text('block_query_link'); |
||||
|
$form->text('publish_time'); |
||||
|
$form->text('total_issuance'); |
||||
|
$form->text('total_circulation'); |
||||
|
$form->text('crowdfunding_price'); |
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,71 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/** |
||||
|
* Created by PhpStorm. |
||||
|
* User: Administrator |
||||
|
* Date: 2020/8/4 |
||||
|
* Time: 16:31 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\UserDepositAddress; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class DepositAddressController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new UserDepositAddress(), function (Grid $grid) { |
||||
|
$grid->id; |
||||
|
$grid->coin_name; |
||||
|
$grid->wallet_address; |
||||
|
$grid->wallet_address_image->image('', 50, 50); |
||||
|
$grid->status->using([0 => '禁用', 1 => '启用'])->dot([0 => 'danger', 1 => 'success']); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new UserDepositAddress(), function (Show $show) { |
||||
|
$show->id; |
||||
|
$show->coin_name; |
||||
|
$show->wallet_address; |
||||
|
$show->wallet_address_image; |
||||
|
$show->status; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new UserDepositAddress(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->text('coin_name'); |
||||
|
$form->text('wallet_address'); |
||||
|
$form->image('wallet_address_image'); |
||||
|
$form->switch('status')->default(0); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,96 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Actions\Grid\ETHCollect; |
||||
|
use App\Models\User; |
||||
|
use App\Models\UserWallet; |
||||
|
use App\Services\CoinService\GethService; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Layout\Content; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Card; |
||||
|
use Dcat\Admin\Widgets\Table; |
||||
|
use Web3\Providers\HttpProvider; |
||||
|
use Web3\RequestManagers\HttpRequestManager; |
||||
|
use Web3\Web3; |
||||
|
|
||||
|
class ETHAccountsController extends AdminController |
||||
|
{ |
||||
|
// public function index(Content $content) |
||||
|
// { |
||||
|
// $web3 = new Web3(new HttpProvider(new HttpRequestManager(env('GETH_HOST'), 60))); |
||||
|
// $accounts = UserWallet::query()->where('coin_id',3)->where(function($q){ |
||||
|
// $q->whereNotNull('wallet_address')->where('wallet_address','<>',''); |
||||
|
// })->pluck('wallet_address','user_id')->toArray(); |
||||
|
// $data = []; |
||||
|
// $kk = 0; |
||||
|
// foreach ($accounts as $uid => $account){ |
||||
|
// $data[$kk]['user_id'] = $uid; |
||||
|
// $data[$kk]['wallet_address'] = $account; |
||||
|
// $web3->eth->getBalance($account, function ($err, $balance) use (&$result){ |
||||
|
// if ($err !== null) { |
||||
|
// echo 'Error: ' . $err->getMessage(); |
||||
|
// $result = 0; |
||||
|
// } |
||||
|
// $result = $balance; |
||||
|
// }); |
||||
|
// $data[$kk]['balance'] = $result; |
||||
|
// $kk++; |
||||
|
// } |
||||
|
// $table = Table::make(['UID','地址','余额'],$data); |
||||
|
// |
||||
|
// return $content |
||||
|
// ->title('网站设置') |
||||
|
// ->body($table); |
||||
|
// } |
||||
|
|
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
$builder = UserWallet::with(['user'])->where('coin_id', 3)->where(function ($q) { |
||||
|
$q->whereNotNull('wallet_address')->where('wallet_address', '<>', ''); |
||||
|
})->orderBy('user_id', 'asc'); |
||||
|
return Grid::make($builder, function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('user_id'); |
||||
|
|
||||
|
$grid->actions(function (Grid\Displayers\Actions $actions) { |
||||
|
$actions->disableDelete(); |
||||
|
$actions->disableQuickEdit(); |
||||
|
$actions->disableEdit(); |
||||
|
$actions->disableView(); |
||||
|
|
||||
|
$actions->append(new ETHCollect()); |
||||
|
}); |
||||
|
|
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
|
||||
|
// 这里的字段会自动使用翻译文件 |
||||
|
$grid->column('user_id', 'UID'); |
||||
|
$grid->column('user.username', '用户名'); |
||||
|
$grid->column('coin_name', '币种'); |
||||
|
$grid->column('wallet_address', '地址'); |
||||
|
|
||||
|
$grid->column('balance', '余额')->display(function () { |
||||
|
return (new GethService())->getBalance($this->wallet_address); |
||||
|
}); |
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('user_id', '会员ID')->width(2); |
||||
|
$filter->where('username', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$q->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
}, "用户名/手机/邮箱")->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,79 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-29 10:40:49 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-09 17:43:07 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Actions\Grid\ETHUSDTCollect; |
||||
|
use App\Models\User; |
||||
|
use App\Models\UserWallet; |
||||
|
use App\Services\CoinService\GethService; |
||||
|
use App\Services\CoinService\GethTokenService; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Layout\Content; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Card; |
||||
|
use Dcat\Admin\Widgets\Table; |
||||
|
use Web3\Providers\HttpProvider; |
||||
|
use Web3\RequestManagers\HttpRequestManager; |
||||
|
use Web3\Web3; |
||||
|
|
||||
|
class ETHUSDTAccountsController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
$builder = UserWallet::with(['user'])->where('coin_id', 1)->where(function ($q) { |
||||
|
$q->whereNotNull('wallet_address')->where('wallet_address', '<>', ''); |
||||
|
}); |
||||
|
return Grid::make($builder, function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('user_id'); |
||||
|
|
||||
|
$grid->actions(function (Grid\Displayers\Actions $actions) { |
||||
|
$actions->disableDelete(); |
||||
|
$actions->disableQuickEdit(); |
||||
|
$actions->disableEdit(); |
||||
|
$actions->disableView(); |
||||
|
|
||||
|
$actions->append(new ETHUSDTCollect()); |
||||
|
}); |
||||
|
|
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
|
||||
|
// 这里的字段会自动使用翻译文件 |
||||
|
$grid->column('user_id', 'UID'); |
||||
|
$grid->column('user.username', '用户名'); |
||||
|
$grid->column('coin_name', '币种'); |
||||
|
$grid->column('wallet_address', '地址'); |
||||
|
|
||||
|
$grid->column('balance', '余额')->display(function () { |
||||
|
$contractAddress = config('coin.erc20_usdt.contractAddress'); |
||||
|
$abi = config('coin.erc20_usdt.abi'); |
||||
|
return (new GethTokenService($contractAddress, $abi))->getBalance($this->wallet_address); |
||||
|
}); |
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('user_id', '会员ID')->width(2); |
||||
|
$filter->where('username', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$q->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
}, "用户名/手机/邮箱")->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Metrics\Examples; |
||||
|
use App\Admin\Metrics\Dashboard as Home; |
||||
|
use App\Http\Controllers\Controller; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Controllers\Dashboard; |
||||
|
use Dcat\Admin\Layout\Column; |
||||
|
use Dcat\Admin\Layout\Content; |
||||
|
use Dcat\Admin\Layout\Row; |
||||
|
|
||||
|
class HomeController extends Controller |
||||
|
{ |
||||
|
public static $css = [ |
||||
|
'/static/css/home.css', |
||||
|
]; |
||||
|
|
||||
|
public function index(Content $content) |
||||
|
{ |
||||
|
Admin::css(static::$css); |
||||
|
|
||||
|
return $content |
||||
|
->header('Dashboard') |
||||
|
->description('Description...') |
||||
|
->body(function (Row $row) { |
||||
|
$row->column(6, function (Column $column) { |
||||
|
$column->row(new Home\TotalUsers()); |
||||
|
$column->row(new Home\Tickets()); |
||||
|
}); |
||||
|
|
||||
|
$row->column(6, function (Column $column) { |
||||
|
$column->row(new Home\Option()); |
||||
|
$column->row(new Home\Exchange()); |
||||
|
$column->row(new Home\ProductOrders()); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,158 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\Agent; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Models\InsideTradeBuy; |
||||
|
use App\Models\InsideTradePair; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Card; |
||||
|
use Dcat\Admin\Widgets\Table; |
||||
|
|
||||
|
class InsideTradeBuyController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(InsideTradeBuy::with(['user', 'order_details']), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc("id"); |
||||
|
|
||||
|
$grid->disableActions(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableBatchDelete(); |
||||
|
$grid->disableDeleteButton(); |
||||
|
|
||||
|
$grid->id->sortable(); |
||||
|
$grid->order_no; |
||||
|
$grid->column('user.username', '用户'); |
||||
|
$grid->symbol; |
||||
|
$grid->type->using(InsideTradeBuy::$typeMap)->label(); |
||||
|
$grid->entrust_price->display(function ($v) { |
||||
|
return number_format($v, 8, '.', ''); |
||||
|
}); |
||||
|
$grid->trigger_price; |
||||
|
// $grid->quote_coin_id; |
||||
|
// $grid->base_coin_id; |
||||
|
$grid->amount; |
||||
|
$grid->traded_amount; |
||||
|
$grid->money; |
||||
|
$grid->traded_money; |
||||
|
$grid->status->using(InsideTradeBuy::$statusMap)->dot([ |
||||
|
1 => 'primary', |
||||
|
2 => 'danger', |
||||
|
3 => 'success', |
||||
|
4 => 'info', |
||||
|
], 'primary'); |
||||
|
$grid->column('order_details', '明细')->display('明细') // 设置按钮名称 |
||||
|
->expand(function () { |
||||
|
// 返回显示的详情 |
||||
|
// 这里返回 content 字段内容,并用 Card 包裹起来 |
||||
|
// dd($this->order_details); |
||||
|
$data = []; |
||||
|
foreach ($this->order_details as $k => $detail) { |
||||
|
// $data[] = array_only($detail,['symbol','unit_price','trade_amount','trade_money','trade_buy_fee','trade_sell_fee']); |
||||
|
$data[$k]['symbol'] = $detail['symbol']; |
||||
|
$data[$k]['buy_order_no'] = $detail['buy_order_no']; |
||||
|
$data[$k]['sell_order_no'] = $detail['sell_order_no']; |
||||
|
$data[$k]['unit_price'] = $detail['unit_price']; |
||||
|
$data[$k]['trade_amount'] = $detail['trade_amount']; |
||||
|
$data[$k]['trade_money'] = $detail['trade_money']; |
||||
|
$data[$k]['trade_buy_fee'] = $detail['trade_buy_fee']; |
||||
|
$data[$k]['trade_sell_fee'] = $detail['trade_sell_fee']; |
||||
|
} |
||||
|
return Table::make(['币对', '买单', '卖单', '成交价', '交易量', '交易额', '买手续费', '卖手续费'], $data); |
||||
|
}); |
||||
|
// $grid->cancel_time; |
||||
|
// $grid->hang_status; |
||||
|
$grid->created_at; |
||||
|
// $grid->updated_at->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('user_id', 'UID')->width(2); |
||||
|
$filter->where('username', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$q->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
}, "用户名/手机/邮箱")->width(3); |
||||
|
|
||||
|
$filter->between('created_at', "时间")->datetime()->width(4); |
||||
|
$filter->where('symbol', function ($q) { |
||||
|
$q->where('symbol', $this->input); |
||||
|
}, '币对')->select(InsideTradePair::query()->where(['status' => 1, 'trade_status' => 1])->pluck('pair_name', 'pair_name')->toArray())->width(3); |
||||
|
$filter->where('status', function ($q) { |
||||
|
$q->where('status', $this->input); |
||||
|
}, '状态')->select(InsideTradeBuy::$statusMap)->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new InsideTradeBuy(), function (Show $show) { |
||||
|
$show->id; |
||||
|
$show->order_no; |
||||
|
$show->user_id; |
||||
|
$show->symbol; |
||||
|
$show->type; |
||||
|
$show->entrust_price; |
||||
|
$show->trigger_price; |
||||
|
$show->quote_coin_id; |
||||
|
$show->base_coin_id; |
||||
|
$show->amount; |
||||
|
$show->traded_amount; |
||||
|
$show->money; |
||||
|
$show->traded_money; |
||||
|
$show->status; |
||||
|
$show->cancel_time; |
||||
|
$show->hang_status; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new InsideTradeBuy(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->text('order_no'); |
||||
|
$form->text('user_id'); |
||||
|
$form->text('symbol'); |
||||
|
$form->text('type'); |
||||
|
$form->text('entrust_price'); |
||||
|
$form->text('trigger_price'); |
||||
|
$form->text('quote_coin_id'); |
||||
|
$form->text('base_coin_id'); |
||||
|
$form->text('amount'); |
||||
|
$form->text('traded_amount'); |
||||
|
$form->text('money'); |
||||
|
$form->text('traded_money'); |
||||
|
$form->text('status'); |
||||
|
$form->text('cancel_time'); |
||||
|
$form->text('hang_status'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,162 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\InsideTradeDealRobot; |
||||
|
use App\Models\InsideTradePair; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Illuminate\Support\Facades\Cache; |
||||
|
|
||||
|
class InsideTradeDealRobotController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new InsideTradeDealRobot(), function (Grid $grid) { |
||||
|
|
||||
|
$grid->column('id')->sortable(); |
||||
|
// $grid->column('pair_id'); |
||||
|
$grid->column('symbol')->badge(); |
||||
|
|
||||
|
$grid->column('bid_price_range', '买单成交价格区间')->display(function () { |
||||
|
$key = 'market:' . strtolower(str_before($this->symbol, '/') . str_after($this->symbol, '/')) . '_newPrice'; |
||||
|
$data = Cache::store('redis')->get($key); |
||||
|
if (blank($data)) { |
||||
|
return '--'; |
||||
|
} else { |
||||
|
$min = $data['price'] - ($this->bid_minus_unit * $this->bid_minus_count); |
||||
|
$max = $data['price'] + ($this->bid_plus_unit * $this->bid_plus_count); |
||||
|
return $min . ' ~ ' . $max; |
||||
|
} |
||||
|
})->label('success'); |
||||
|
$grid->column('ask_price_range', '卖单成交价格区间')->display(function () { |
||||
|
$key = 'market:' . strtolower(str_before($this->symbol, '/') . str_after($this->symbol, '/')) . '_newPrice'; |
||||
|
$data = Cache::store('redis')->get($key); |
||||
|
if (blank($data)) { |
||||
|
return '--'; |
||||
|
} else { |
||||
|
$min = $data['price'] - ($this->ask_minus_unit * $this->ask_minus_count); |
||||
|
$max = $data['price'] + ($this->ask_plus_unit * $this->ask_plus_count); |
||||
|
return $min . ' ~ ' . $max; |
||||
|
} |
||||
|
})->label('danger'); |
||||
|
|
||||
|
// $grid->column('bid_plus_unit'); |
||||
|
// $grid->column('bid_plus_count'); |
||||
|
// $grid->column('bid_minus_unit'); |
||||
|
// $grid->column('bid_minus_count'); |
||||
|
// $grid->column('ask_plus_unit'); |
||||
|
// $grid->column('ask_plus_count'); |
||||
|
// $grid->column('ask_minus_unit'); |
||||
|
// $grid->column('ask_minus_count'); |
||||
|
|
||||
|
$grid->column('status')->switch(); |
||||
|
|
||||
|
$grid->column('created_at'); |
||||
|
// $grid->column('updated_at')->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->like('symbol')->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new InsideTradeDealRobot(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('pair_id'); |
||||
|
$show->field('symbol'); |
||||
|
$show->field('bid_plus_unit'); |
||||
|
$show->field('bid_plus_count'); |
||||
|
$show->field('bid_minus_unit'); |
||||
|
$show->field('bid_minus_count'); |
||||
|
$show->field('ask_plus_unit'); |
||||
|
$show->field('ask_plus_count'); |
||||
|
$show->field('ask_minus_unit'); |
||||
|
$show->field('ask_minus_count'); |
||||
|
$show->field('status'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new InsideTradeDealRobot(), function (Form $form) { |
||||
|
$options = InsideTradePair::query()->where('status', 1)->pluck('pair_name', 'pair_id')->toArray(); |
||||
|
|
||||
|
if ($form->isCreating()) { |
||||
|
$form->row(function (Form\Row $form) use ($options) { |
||||
|
$form->hidden('id'); |
||||
|
$form->width(6)->select('pair_id', '交易对')->options($options); |
||||
|
$form->hidden('symbol'); |
||||
|
}); |
||||
|
} else { |
||||
|
$form->row(function (Form\Row $form) use ($options) { |
||||
|
$form->hidden('id'); |
||||
|
$form->width(6)->select('pair_id', '交易对')->options($options)->readOnly(); |
||||
|
$form->hidden('symbol'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
$form->row(function (Form\Row $form) { |
||||
|
$form->width(3)->text('bid_plus_unit'); |
||||
|
$form->width(3)->text('bid_plus_count'); |
||||
|
}); |
||||
|
|
||||
|
$form->row(function (Form\Row $form) { |
||||
|
$form->width(3)->text('bid_minus_unit'); |
||||
|
$form->width(3)->text('bid_minus_count'); |
||||
|
}); |
||||
|
|
||||
|
$form->row(function (Form\Row $form) { |
||||
|
$form->width(3)->text('ask_plus_unit'); |
||||
|
$form->width(3)->text('ask_plus_count'); |
||||
|
}); |
||||
|
|
||||
|
$form->row(function (Form\Row $form) { |
||||
|
$form->width(3)->text('ask_minus_unit'); |
||||
|
$form->width(3)->text('ask_minus_count'); |
||||
|
}); |
||||
|
|
||||
|
$form->row(function (Form\Row $form) { |
||||
|
$form->switch('status')->default(0); |
||||
|
|
||||
|
$form->hidden('created_at'); |
||||
|
$form->hidden('updated_at'); |
||||
|
}); |
||||
|
|
||||
|
$form->saving(function (Form $form) use ($options) { |
||||
|
if ($form->isCreating()) { |
||||
|
if (!blank($form->pair_id)) { |
||||
|
$symbol = $options[$form->pair_id]; |
||||
|
$is_exist = InsideTradeDealRobot::query()->where('symbol', $symbol)->first(); |
||||
|
if ($is_exist) return $form->error('该交易对已存在任务~'); |
||||
|
|
||||
|
$form->symbol = $symbol; |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,192 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\Agent; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Models\Coins; |
||||
|
use App\Models\InsideTradeOrder; |
||||
|
use App\Models\User; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Alert; |
||||
|
|
||||
|
class InsideTradeOrderController extends AdminController |
||||
|
{ |
||||
|
|
||||
|
public function statistics() |
||||
|
{ |
||||
|
$builder1 = InsideTradeOrder::query(); |
||||
|
$params = request()->only(['user_id', 'username', 'created_at']); |
||||
|
|
||||
|
if (!empty($params)) { |
||||
|
if (!empty($params['user_id'])) { |
||||
|
$user_id = $params['user_id']; |
||||
|
$builder1->where(function ($q) use ($user_id) { |
||||
|
$q->where('buy_user_id', $user_id)->orWhere('sell_user_id', $user_id); |
||||
|
}); |
||||
|
} |
||||
|
if (!empty($params['username'])) { |
||||
|
$username = $params['username']; |
||||
|
$builder1->where(function ($q) use ($username) { |
||||
|
$q->whereHas('buy_user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
})->orWhereHas('sell_user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
if (!empty($params['created_at']) && !empty($params['created_at']['start'])) { |
||||
|
$start = $params['created_at']['start']; |
||||
|
$end = $params['created_at']['end']; |
||||
|
$builder1->whereDate('created_at', '>=', $start)->whereDate('created_at', '<=', $end); |
||||
|
} |
||||
|
} |
||||
|
$builder2 = $builder1; |
||||
|
|
||||
|
// \DB::enableQueryLog(); |
||||
|
$records1 = $builder1->groupBy('base_coin_id')->selectRaw('sum(trade_buy_fee) as total_fee, base_coin_id as coin_id')->get(); |
||||
|
$records2 = $builder2->groupBy('quote_coin_id')->selectRaw('sum(trade_sell_fee) as total_fee, quote_coin_id as coin_id')->get(); |
||||
|
$tmp = $records1->concat($records2); |
||||
|
// dd(\DB::getQueryLog()); |
||||
|
$records = []; |
||||
|
foreach ($tmp as $k => $v) { |
||||
|
if (!isset($records[$v['coin_id']])) { |
||||
|
$records[$v['coin_id']] = $v; |
||||
|
} else { |
||||
|
$records[$v['coin_id']]['total_fee'] += $v['total_fee']; |
||||
|
} |
||||
|
} |
||||
|
// dd($records); |
||||
|
$con = ''; |
||||
|
foreach ($records as $record) { |
||||
|
$coin_name = Coins::query()->where('coin_id', $record['coin_id'])->value('coin_name'); |
||||
|
$con .= '<code>' . $coin_name . '手续费:' . $record['total_fee'] . '</code> '; |
||||
|
} |
||||
|
return Alert::make($con, '统计')->info(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(InsideTradeOrder::with(['buy_user', 'sell_user']), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc("order_id"); |
||||
|
|
||||
|
#统计 |
||||
|
$grid->header(function ($query) { |
||||
|
return $this->statistics(); |
||||
|
}); |
||||
|
|
||||
|
$grid->disableActions(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableBatchDelete(); |
||||
|
$grid->disableDeleteButton(); |
||||
|
|
||||
|
$grid->order_id->sortable(); |
||||
|
$grid->buy_order_no; |
||||
|
$grid->sell_order_no; |
||||
|
$grid->column('buy_user.username', '买家'); |
||||
|
$grid->column('sell_user.username', '卖家'); |
||||
|
$grid->unit_price; |
||||
|
$grid->symbol; |
||||
|
$grid->trade_amount; |
||||
|
$grid->trade_money; |
||||
|
$grid->trade_buy_fee->display(function ($v) { |
||||
|
return $v . ' ' . str_before($this->symbol, '/'); |
||||
|
}); |
||||
|
$grid->trade_sell_fee->display(function ($v) { |
||||
|
return $v . ' ' . str_after($this->symbol, '/'); |
||||
|
}); |
||||
|
$grid->created_at; |
||||
|
// $grid->updated_at->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->between('created_at', "时间")->datetime(); |
||||
|
$filter->where('user_id', function ($q) { |
||||
|
$q->where('buy_user_id', $this->input)->orWhere('sell_user_id', $this->input); |
||||
|
}, 'UID')->width(2); |
||||
|
$filter->where('username', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$q->whereHas('buy_user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
})->orWhereHas('sell_user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
}, "用户名/手机/邮箱")->width(3); |
||||
|
$filter->where('pid', function ($query) { |
||||
|
$referrer = $this->input; |
||||
|
$query->whereHas('buy_user', function ($query) use ($referrer) { |
||||
|
$query->where('pid', $referrer); |
||||
|
})->whereHas('sell_user', function ($query) use ($referrer) { |
||||
|
$query->where('pid', $referrer); |
||||
|
}); |
||||
|
}, '代理商UID')->width(3); |
||||
|
$filter->where('agent_id', function ($query) { |
||||
|
$base_ids = collect(User::getChilds($this->input))->pluck('user_id'); |
||||
|
$query->whereHas('buy_user', function ($query) use ($base_ids) { |
||||
|
$query->whereIn('user_id', $base_ids); |
||||
|
})->whereHas('sell_user', function ($query) use ($base_ids) { |
||||
|
$query->whereIn('user_id', $base_ids); |
||||
|
}); |
||||
|
}, '链上查询')->placeholder('输入代理商UID查询该代理商链上成交记录')->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new InsideTradeOrder(), function (Show $show) { |
||||
|
$show->order_id; |
||||
|
$show->buy_order_no; |
||||
|
$show->sell_order_no; |
||||
|
$show->buy_user_id; |
||||
|
$show->sell_user_id; |
||||
|
$show->unit_price; |
||||
|
$show->symbol; |
||||
|
$show->trade_amount; |
||||
|
$show->trade_money; |
||||
|
$show->trade_buy_fee; |
||||
|
$show->trade_sell_fee; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new InsideTradeOrder(), function (Form $form) { |
||||
|
$form->display('order_id'); |
||||
|
$form->text('buy_order_no'); |
||||
|
$form->text('sell_order_no'); |
||||
|
$form->text('buy_user_id'); |
||||
|
$form->text('sell_user_id'); |
||||
|
$form->text('unit_price'); |
||||
|
$form->text('symbol'); |
||||
|
$form->text('trade_amount'); |
||||
|
$form->text('trade_money'); |
||||
|
$form->text('trade_buy_fee'); |
||||
|
$form->text('trade_sell_fee'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,192 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Actions\InsideTradePair\Close; |
||||
|
use App\Admin\Actions\InsideTradePair\Open; |
||||
|
use App\Models\Coins; |
||||
|
use App\Models\InsideTradePair; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Layout\Content; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Tab; |
||||
|
|
||||
|
class InsideTradePairController extends AdminController |
||||
|
{ |
||||
|
// public function index(Content $content) |
||||
|
// { |
||||
|
// $tab = Tab::make(); |
||||
|
// |
||||
|
// $quote_coins = array_unique(InsideTradePair::query()->pluck('quote_coin_name')->toArray()); |
||||
|
// |
||||
|
// $index = 1; |
||||
|
// foreach ($quote_coins as $k => $quote_coin){ |
||||
|
// $tab_html = Grid::make(InsideTradePair::query()->where('quote_coin_name',$quote_coin), function (Grid $grid) { |
||||
|
// $grid->model()->orderByDesc('pair_id'); |
||||
|
// |
||||
|
// $grid->disableBatchDelete(); |
||||
|
// |
||||
|
// $grid->tools([ |
||||
|
// new Open(), |
||||
|
// new Close(), |
||||
|
// ]); |
||||
|
// |
||||
|
// $grid->pair_id->sortable(); |
||||
|
// $grid->pair_name; |
||||
|
// $grid->symbol; |
||||
|
// $grid->quote_coin_id; |
||||
|
// $grid->quote_coin_name; |
||||
|
// $grid->base_coin_id; |
||||
|
// $grid->base_coin_name; |
||||
|
// $grid->qty_decimals; |
||||
|
// $grid->price_decimals; |
||||
|
// $grid->min_qty; |
||||
|
// $grid->min_total; |
||||
|
// $grid->status->switch(); |
||||
|
// $grid->trade_status->switch(); |
||||
|
// $grid->created_at->sortable(); |
||||
|
// |
||||
|
// $grid->filter(function (Grid\Filter $filter) { |
||||
|
// $filter->equal('pair_id'); |
||||
|
// }); |
||||
|
// })->render(); |
||||
|
// |
||||
|
// // 第一个参数是选项卡标题,第二个参数是内容,第三个参数是是否选中 |
||||
|
// if($index == 1){ |
||||
|
// $tab->add($quote_coin, $tab_html, true); |
||||
|
// }else{ |
||||
|
// $tab->add($quote_coin, $tab_html); |
||||
|
// } |
||||
|
// $index++; |
||||
|
// } |
||||
|
// |
||||
|
// return $content->body($tab->withCard()); |
||||
|
// } |
||||
|
|
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new InsideTradePair(), function (Grid $grid) { |
||||
|
$grid->model()->orderBy('sort', 'asc'); |
||||
|
|
||||
|
$grid->disableBatchDelete(); |
||||
|
// $grid->disableCreateButton(); |
||||
|
$grid->actions(function (Grid\Displayers\Actions $actions) { |
||||
|
$actions->disableDelete(); |
||||
|
// $actions->disableEdit(); |
||||
|
$actions->disableView(); |
||||
|
}); |
||||
|
|
||||
|
$grid->tools([ |
||||
|
new Open(), |
||||
|
new Close(), |
||||
|
]); |
||||
|
|
||||
|
$grid->pair_id->sortable(); |
||||
|
$grid->pair_name; |
||||
|
$grid->symbol; |
||||
|
// $grid->quote_coin_id; |
||||
|
$grid->quote_coin_name; |
||||
|
// $grid->base_coin_id; |
||||
|
$grid->base_coin_name; |
||||
|
$grid->qty_decimals; |
||||
|
$grid->price_decimals; |
||||
|
$grid->min_qty; |
||||
|
$grid->min_total; |
||||
|
$grid->status->switch(); |
||||
|
$grid->trade_status->switch(); |
||||
|
$grid->sort->editable(); |
||||
|
$grid->created_at->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('base_coin_name')->width(2); |
||||
|
$filter->equal('quote_coin_name')->width(2); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new InsideTradePair(), function (Show $show) { |
||||
|
$show->pair_id; |
||||
|
$show->pair_name; |
||||
|
$show->symbol; |
||||
|
$show->quote_coin_name; |
||||
|
$show->base_coin_name; |
||||
|
$show->qty_decimals; |
||||
|
$show->price_decimals; |
||||
|
$show->min_qty; |
||||
|
$show->min_total; |
||||
|
$show->status; |
||||
|
$show->sort; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new InsideTradePair(), function (Form $form) { |
||||
|
$form->disableDeleteButton(); |
||||
|
|
||||
|
$options = Coins::query()->where('status', 1)->orderByDesc('coin_id')->pluck('coin_name', 'coin_id')->toArray(); |
||||
|
|
||||
|
$form->display('pair_id'); |
||||
|
$form->select('quote_coin_id')->options($options)->default(1); |
||||
|
$form->select('base_coin_id')->options($options); |
||||
|
$form->hidden('quote_coin_name'); |
||||
|
$form->hidden('base_coin_name'); |
||||
|
$form->hidden('pair_name'); |
||||
|
$form->hidden('symbol'); |
||||
|
$form->number('qty_decimals')->default(2); |
||||
|
$form->number('price_decimals')->default(2); |
||||
|
$form->number('min_qty')->default(1); |
||||
|
$form->number('min_total')->default(1); |
||||
|
$form->switch('status')->default(1); |
||||
|
$form->switch('trade_status')->default(1); |
||||
|
$form->number('sort')->default(255); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
|
||||
|
$form->saving(function (Form $form) use ($options) { |
||||
|
if ($form->isCreating() || $form->isEditing()) { |
||||
|
if (!blank($form->quote_coin_id)) { |
||||
|
$quote_coin_id = $form->quote_coin_id; |
||||
|
// dd($quote_coin_id); |
||||
|
$quote_coin_name = $options[$quote_coin_id]; |
||||
|
$base_coin_id = $form->base_coin_id; |
||||
|
$base_coin_name = $options[$base_coin_id]; |
||||
|
if ($quote_coin_id == $base_coin_id) { |
||||
|
return $form->error('参数错误~'); |
||||
|
} |
||||
|
$form->quote_coin_id = $quote_coin_id; |
||||
|
$form->quote_coin_name = $quote_coin_name; |
||||
|
$form->base_coin_id = $base_coin_id; |
||||
|
$form->base_coin_name = $base_coin_name; |
||||
|
$form->pair_name = $base_coin_name . '/' . $quote_coin_name; |
||||
|
$form->symbol = strtolower($base_coin_name . $quote_coin_name); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,104 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\InsideTradePair; |
||||
|
use App\Models\InsideTradeRisk; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class InsideTradeRiskController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new InsideTradeRisk(), function (Grid $grid) { |
||||
|
$grid->column('id')->sortable(); |
||||
|
$grid->column('pair_id'); |
||||
|
// $grid->column('pair_name'); |
||||
|
$grid->column('symbol'); |
||||
|
$grid->column('up_or_down', '涨跌')->using([0 => '跌', 1 => '涨'])->dot([0 => 'danger', 1 => 'success']); |
||||
|
$grid->column('range', '幅度')->label(); |
||||
|
$grid->column('start_time'); |
||||
|
$grid->column('end_time'); |
||||
|
$grid->column('status')->switch(); |
||||
|
// $grid->column('created_at'); |
||||
|
// $grid->column('updated_at')->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->like('symbol')->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new InsideTradeRisk(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('pair_id'); |
||||
|
$show->field('pair_name'); |
||||
|
$show->field('symbol'); |
||||
|
$show->field('status'); |
||||
|
$show->field('start_time'); |
||||
|
$show->field('end_time'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new InsideTradeRisk(), function (Form $form) { |
||||
|
$options = InsideTradePair::query()->where('status', 1)->pluck('symbol', 'pair_id')->toArray(); |
||||
|
|
||||
|
$form->display('id'); |
||||
|
if ($form->isCreating()) { |
||||
|
$form->select('pair_id', '交易对')->options($options); |
||||
|
} else { |
||||
|
$form->select('pair_id', '交易对')->options($options)->readOnly(); |
||||
|
} |
||||
|
$form->hidden('symbol'); |
||||
|
|
||||
|
$form->radio('up_or_down')->options([0 => '跌', 1 => '涨'])->value(1); |
||||
|
$form->text('range'); |
||||
|
|
||||
|
$form->switch('status')->default(0); |
||||
|
|
||||
|
$form->datetime('start_time')->help('任务运行开始时间,开启状态时必填'); |
||||
|
$form->datetime('end_time')->help('任务运行结束时间,不填表示一直运行'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
|
||||
|
$form->saving(function (Form $form) use ($options) { |
||||
|
if ($form->isCreating()) { |
||||
|
if (!blank($form->pair_id)) { |
||||
|
$symbol = $options[$form->pair_id]; |
||||
|
$is_exist = InsideTradeRisk::query()->where('symbol', $symbol)->first(); |
||||
|
if ($is_exist) return $form->error('该交易对已存在任务~'); |
||||
|
|
||||
|
$form->symbol = $symbol; |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,159 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\Agent; |
||||
|
use App\Models\AgentGrade; |
||||
|
use App\Models\InsideTradeBuy; |
||||
|
use App\Models\InsideTradePair; |
||||
|
use App\Models\InsideTradeSell; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Card; |
||||
|
use Dcat\Admin\Widgets\Table; |
||||
|
|
||||
|
class InsideTradeSellController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(InsideTradeSell::with(['user', 'order_details']), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc("id"); |
||||
|
|
||||
|
$grid->disableActions(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableBatchDelete(); |
||||
|
$grid->disableDeleteButton(); |
||||
|
|
||||
|
$grid->id->sortable(); |
||||
|
$grid->order_no; |
||||
|
$grid->column('user.username', '用户'); |
||||
|
$grid->symbol; |
||||
|
$grid->type->using(InsideTradeSell::$typeMap)->label(); |
||||
|
$grid->entrust_price->display(function ($v) { |
||||
|
return number_format($v, 8, '.', ''); |
||||
|
}); |
||||
|
$grid->trigger_price; |
||||
|
// $grid->quote_coin_id; |
||||
|
// $grid->base_coin_id; |
||||
|
$grid->amount; |
||||
|
$grid->traded_amount; |
||||
|
$grid->money; |
||||
|
$grid->traded_money; |
||||
|
$grid->status->using(InsideTradeSell::$statusMap)->dot([ |
||||
|
1 => 'primary', |
||||
|
2 => 'danger', |
||||
|
3 => 'success', |
||||
|
4 => 'info', |
||||
|
], 'primary'); |
||||
|
$grid->column('order_details', '明细')->display('明细') // 设置按钮名称 |
||||
|
->expand(function () { |
||||
|
// 返回显示的详情 |
||||
|
// 这里返回 content 字段内容,并用 Card 包裹起来 |
||||
|
// dd($this->order_details); |
||||
|
$data = []; |
||||
|
foreach ($this->order_details as $k => $detail) { |
||||
|
// $data[] = array_only($detail,['symbol','unit_price','trade_amount','trade_money','trade_buy_fee','trade_sell_fee']); |
||||
|
$data[$k]['symbol'] = $detail['symbol']; |
||||
|
$data[$k]['buy_order_no'] = $detail['buy_order_no']; |
||||
|
$data[$k]['sell_order_no'] = $detail['sell_order_no']; |
||||
|
$data[$k]['unit_price'] = $detail['unit_price']; |
||||
|
$data[$k]['trade_amount'] = $detail['trade_amount']; |
||||
|
$data[$k]['trade_money'] = $detail['trade_money']; |
||||
|
$data[$k]['trade_buy_fee'] = $detail['trade_buy_fee']; |
||||
|
$data[$k]['trade_sell_fee'] = $detail['trade_sell_fee']; |
||||
|
} |
||||
|
return Table::make(['币对', '买单', '卖单', '成交价', '交易量', '交易额', '买手续费', '卖手续费'], $data); |
||||
|
}); |
||||
|
// $grid->hang_status; |
||||
|
// $grid->cancel_time; |
||||
|
$grid->created_at; |
||||
|
// $grid->updated_at->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('user_id', 'UID')->width(2); |
||||
|
$filter->where('username', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$q->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
}, "用户名/手机/邮箱")->width(3); |
||||
|
|
||||
|
$filter->between('created_at', "时间")->datetime()->width(4); |
||||
|
$filter->where('symbol', function ($q) { |
||||
|
$q->where('symbol', $this->input); |
||||
|
}, '币对')->select(InsideTradePair::query()->where(['status' => 1, 'trade_status' => 1])->pluck('pair_name', 'pair_name')->toArray())->width(3); |
||||
|
$filter->where('status', function ($q) { |
||||
|
$q->where('status', $this->input); |
||||
|
}, '状态')->select(InsideTradeSell::$statusMap)->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new InsideTradeSell(), function (Show $show) { |
||||
|
$show->id; |
||||
|
$show->order_no; |
||||
|
$show->user_id; |
||||
|
$show->symbol; |
||||
|
$show->type; |
||||
|
$show->entrust_price; |
||||
|
$show->trigger_price; |
||||
|
$show->quote_coin_id; |
||||
|
$show->base_coin_id; |
||||
|
$show->amount; |
||||
|
$show->traded_amount; |
||||
|
$show->money; |
||||
|
$show->traded_money; |
||||
|
$show->status; |
||||
|
$show->hang_status; |
||||
|
$show->cancel_time; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new InsideTradeSell(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->text('order_no'); |
||||
|
$form->text('user_id'); |
||||
|
$form->text('symbol'); |
||||
|
$form->text('type'); |
||||
|
$form->text('entrust_price'); |
||||
|
$form->text('trigger_price'); |
||||
|
$form->text('quote_coin_id'); |
||||
|
$form->text('base_coin_id'); |
||||
|
$form->text('amount'); |
||||
|
$form->text('traded_amount'); |
||||
|
$form->text('money'); |
||||
|
$form->text('traded_money'); |
||||
|
$form->text('status'); |
||||
|
$form->text('hang_status'); |
||||
|
$form->text('cancel_time'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,51 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-08-11 17:08:40 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-11 17:42:47 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\InvitePoster; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Form; |
||||
|
|
||||
|
class InvitePosterController extends AdminController |
||||
|
{ |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* @description: |
||||
|
* @param {*} |
||||
|
* @return {*} |
||||
|
*/ |
||||
|
public function grid() |
||||
|
{ |
||||
|
return Grid::make(new InvitePoster(), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('id'); |
||||
|
$grid->column('id')->sortable(); |
||||
|
$grid->column('image', '背景')->image(); |
||||
|
$grid->column('sort', '排序'); |
||||
|
$grid->column('status', '状态')->switch(); |
||||
|
$grid->column('is_default', '默认')->switch(); |
||||
|
}); |
||||
|
} |
||||
|
public function form() |
||||
|
{ |
||||
|
return Form::make(new InvitePoster(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->image('image', '背景')->uniqueName()->move('poster')->autoUpload(); |
||||
|
$form->number('sort', '排序'); |
||||
|
$form->switch('status', '状态')->default(1); |
||||
|
$form->switch('is_default', '默认'); |
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,581 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-29 10:40:49 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-09 17:44:06 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Handlers\Kline; |
||||
|
use App\Models\CoinConfig; |
||||
|
use App\Models\CoinData; |
||||
|
use App\Models\DataTobr; |
||||
|
|
||||
|
use Dcat\Admin\Layout\Content; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Carbon; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class KlineRobotController extends AdminController |
||||
|
{ |
||||
|
public function index(Content $content) |
||||
|
{ |
||||
|
return $content |
||||
|
->title('行情控制') |
||||
|
->body(view('admin.klineRobot')); |
||||
|
// return $content->full()->body(view('admin.klineRobot')); |
||||
|
// return view('admin.klineRobot'); |
||||
|
} |
||||
|
|
||||
|
public function kline() |
||||
|
{ |
||||
|
return view('admin.kline'); |
||||
|
} |
||||
|
|
||||
|
public function getKlineConfig(Request $request) |
||||
|
{ |
||||
|
$datetime = $request->input('datetime'); |
||||
|
$coin = $request->input('coin', 1); |
||||
|
$symbols = config('coin.exchange_symbols'); |
||||
|
$coins = []; |
||||
|
$kk = 1; |
||||
|
foreach ($symbols as $symbol => $model) { |
||||
|
$coins[$kk] = ['symbol' => $symbol, 'model' => $model]; |
||||
|
$kk++; |
||||
|
} |
||||
|
$model = $coins[$coin]['model']; |
||||
|
// dd($model); |
||||
|
$symbol = $coins[$coin]['symbol']; |
||||
|
|
||||
|
$period = $request->input('period', 30); |
||||
|
|
||||
|
if (empty($datetime)) return []; |
||||
|
// dd($datetime,Carbon::parse($datetime)->addDay()->toDateTimeString()); |
||||
|
$config = CoinConfig::query()->where('datetime', $datetime)->where('symbol', $symbol)->first(); |
||||
|
if (empty($config)) { |
||||
|
DB::connection()->enableQueryLog(); |
||||
|
$todaytime = strtotime(date("Y-m-d")); |
||||
|
if (strtotime($datetime) >= $todaytime) { |
||||
|
// 制作时间大于或者等于今天就查询日期最新的收盘 |
||||
|
|
||||
|
$all = $model::query()->orderBy('Date', 'desc')->first(); // 上一条K线 |
||||
|
$config['open'] = $all->attributes['Close']; |
||||
|
// dd($config,$all); |
||||
|
|
||||
|
} else { |
||||
|
// 制作时间大于或者等于今天就查询日期最老的开盘 |
||||
|
$all = $model::query()->orderBy('Date', 'asc')->first(); // 上一条K线 |
||||
|
$config['close'] = $all->attributes['Open']; |
||||
|
//dd($config,$all); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
if ($period == 1) { |
||||
|
$klineData = $model::query() |
||||
|
->where('datetime', '>=', $datetime) |
||||
|
->where('datetime', '<', Carbon::parse($datetime)->addDay()->toDateTimeString()) |
||||
|
->where('is_1min', 1) |
||||
|
->select(['Date as timestamp', 'datetime', 'Open as open', 'Close as close', 'High as high', 'Low as low', 'Volume as volume', 'Amount as amount']) |
||||
|
->get(); |
||||
|
} else { |
||||
|
$klineData = $model::query() |
||||
|
->where('datetime', '>=', $datetime) |
||||
|
->where('datetime', '<', Carbon::parse($datetime)->addDay()->toDateTimeString()) |
||||
|
->where('is_30min', 1) |
||||
|
->select(['Date as timestamp', 'datetime', 'Open as open', 'Close as close', 'High as high', 'Low as low', 'Volume as volume', 'Amount as amount']) |
||||
|
->get(); |
||||
|
} |
||||
|
// dd($klineData); |
||||
|
$response = [ |
||||
|
'config' => $config, |
||||
|
'lists' => [], |
||||
|
'max' => 0, |
||||
|
'min' => 1000000, |
||||
|
'dateKline' => [], |
||||
|
'klineData' => [], |
||||
|
'klineFormData' => $klineData, |
||||
|
]; |
||||
|
foreach ($klineData as $item) { |
||||
|
$response['lists'][] = [ |
||||
|
$item['timestamp'] * 1000, $item['close'], |
||||
|
]; |
||||
|
$response['dateKline'][] = substr($item['datetime'], 11, 5); |
||||
|
$response['klineData'][] = [ |
||||
|
$item['open'], $item['close'], $item['high'], $item['low'], |
||||
|
]; |
||||
|
if ($item['close'] > $response['max']) { |
||||
|
$response['max'] = $item['close']; |
||||
|
} |
||||
|
if ($item['close'] < $response['min']) { |
||||
|
$response['min'] = $item['close']; |
||||
|
} |
||||
|
} |
||||
|
// dd($response); |
||||
|
return $response; |
||||
|
} |
||||
|
|
||||
|
// 生成K线 |
||||
|
public function generateKline(Request $request) |
||||
|
{ |
||||
|
|
||||
|
// 这里控制,是否生产历史数据 |
||||
|
$history = 1; |
||||
|
|
||||
|
|
||||
|
if(!$request['open'] || !$request['close'] || !$request['high'] || !$request['low'] || !$request['min_amount'] || !$request['max_amount'] || !$request['datetime']){ |
||||
|
return $request; |
||||
|
} |
||||
|
|
||||
|
$ss_time = 0; |
||||
|
$all_time = 0; |
||||
|
|
||||
|
$config = $request->all(); |
||||
|
|
||||
|
if($history == 1){ |
||||
|
$coin = $request->input('currency_coin', 1); |
||||
|
$symbols = config('coin.exchange_symbols'); |
||||
|
$coins = []; |
||||
|
$kk = 1; |
||||
|
foreach ($symbols as $symbol => $model) { |
||||
|
$coins[$kk] = ['symbol' => $symbol, 'model' => $model]; |
||||
|
$kk++; |
||||
|
} |
||||
|
$model = $coins[$coin]['model']; |
||||
|
$symbol = $coins[$coin]['symbol']; |
||||
|
$all = $model::query()->orderBy('Date', 'asc')->where('is_1min',1)->first()->toArray(); // 上一条K线 |
||||
|
// $all_time = $all['Date'] - 60 * 60 * 24; |
||||
|
$all_time = $all['Date']; |
||||
|
$ss_time = strtotime($config['datetime']); |
||||
|
} |
||||
|
// $all = DataNka::query()->where('is_1min',1)->orderBniy('Date', 'asc')->first()->toArray(); // 上一条K线 |
||||
|
// $all_time = $all['Date'] - 60 * 60 * 24; |
||||
|
// $ss_time = strtotime($config['datetime']); |
||||
|
// return $all; |
||||
|
if (empty($config)) return []; |
||||
|
if (($ss_time < $all_time) && $history == 1) { |
||||
|
$klineData = (new Kline())->generateKline2($config, date("Y-m-d H:i:s", $all['Date'])); |
||||
|
} else { |
||||
|
$klineData = (new Kline())->generateKline2($config); |
||||
|
} |
||||
|
|
||||
|
// dd($klineData); |
||||
|
$response = [ |
||||
|
'lists' => [], |
||||
|
'max' => 0, |
||||
|
'min' => 1000000, |
||||
|
'dateKline' => [], |
||||
|
'klineData' => [], |
||||
|
'klineFormData' => $klineData, |
||||
|
]; |
||||
|
foreach ($klineData as $item) { |
||||
|
$response['lists'][] = [ |
||||
|
$item['timestamp'] * 1000, $item['close'], |
||||
|
]; |
||||
|
$response['dateKline'][] = substr($item['datetime'], 11, 5); |
||||
|
$response['klineData'][] = [ |
||||
|
$item['open'], $item['close'], $item['high'], $item['low'], |
||||
|
]; |
||||
|
if ($item['close'] > $response['max']) { |
||||
|
$response['max'] = $item['close']; |
||||
|
} |
||||
|
if ($item['close'] < $response['min']) { |
||||
|
$response['min'] = $item['close']; |
||||
|
} |
||||
|
} |
||||
|
return $response; |
||||
|
} |
||||
|
|
||||
|
// 保存K线 |
||||
|
public function kline_save(Request $request) |
||||
|
{ |
||||
|
$post = $request->all(); |
||||
|
|
||||
|
$coin = $request->input('coin', 1); |
||||
|
$symbols = config('coin.exchange_symbols'); |
||||
|
$coins = []; |
||||
|
$kk = 1; |
||||
|
foreach ($symbols as $symbol => $model) { |
||||
|
$coins[$kk] = ['symbol' => $symbol, 'model' => $model]; |
||||
|
$kk++; |
||||
|
} |
||||
|
|
||||
|
$model = $coins[$coin]['model']; |
||||
|
$symbol = $coins[$coin]['symbol']; |
||||
|
|
||||
|
|
||||
|
$config = array_only($post, ['datetime', 'open', 'close', 'high', 'low', 'min_amount', 'max_amount']); |
||||
|
if (empty($config['min_amount'])) $config['min_amount'] = 1000; |
||||
|
if (empty($config['max_amount'])) $config['max_amount'] = 10000; |
||||
|
|
||||
|
|
||||
|
$klineList = $post['klineFormData']; |
||||
|
$days = count($klineList); |
||||
|
$days = $days / 48; |
||||
|
// dd($days, $config, $post); |
||||
|
|
||||
|
DB::beginTransaction(); |
||||
|
try { |
||||
|
|
||||
|
|
||||
|
// 保存K线配置 |
||||
|
CoinConfig::query()->updateOrCreate(['datetime' => $config['datetime'], 'symbol' => $symbol], $config); |
||||
|
|
||||
|
// 保存K线 |
||||
|
foreach ($klineList as $kline) { |
||||
|
|
||||
|
//if ($kline['timestamp'] < time()) { |
||||
|
// continue; |
||||
|
//} |
||||
|
// $model::query()->updateOrCreate( |
||||
|
// ['is_30min' => 1,'Date' => $kline['timestamp']], |
||||
|
// [ |
||||
|
// 'Open' => $kline['open'], |
||||
|
// 'High' => $kline['high'], |
||||
|
// 'Low' => $kline['low'], |
||||
|
// 'Close' => $kline['close'], |
||||
|
// 'Volume' => $kline['volume'], |
||||
|
// 'Amount' => $kline['amount'], |
||||
|
// 'datetime' => $kline['datetime'], |
||||
|
// ] |
||||
|
// ); |
||||
|
|
||||
|
$datetime = $kline['datetime']; |
||||
|
//Y-m-d H:i:s 开始结束时间 |
||||
|
$seconds = 1800; |
||||
|
$start_date = Carbon::parse($datetime)->toDateTimeString(); |
||||
|
$end_date = Carbon::parse($datetime)->addSeconds($seconds)->toDateTimeString(); |
||||
|
$this->fake_1min_kline(array_merge($kline, ['min_amount' => $config['min_amount'], 'max_amount' => $config['max_amount']]), $start_date, $end_date, $model); |
||||
|
} |
||||
|
$time_now = $config['datetime']; |
||||
|
for ($i = 0; $i < $days; $i++) { |
||||
|
$config['datetime']= date("Y-m-d H:i:s", strtotime($time_now)+ $i * (60 * 60 * 24)); |
||||
|
// 更新一天的K线 |
||||
|
$day_start_date = Carbon::parse($config['datetime'])->toDateTimeString(); |
||||
|
$day_end_date = Carbon::parse($config['datetime'])->addSeconds(86400)->toDateTimeString(); |
||||
|
|
||||
|
$this->fake_period_kline('5min', $day_start_date, $day_end_date, $model); |
||||
|
$this->fake_period_kline('15min', $day_start_date, $day_end_date, $model); |
||||
|
$this->fake_period_kline('30min', $day_start_date, $day_end_date, $model); |
||||
|
$this->fake_period_kline('60min', $day_start_date, $day_end_date, $model); |
||||
|
$this->fake_period_kline('1day', $day_start_date, $day_end_date, $model); |
||||
|
// 更新周线和月线 |
||||
|
$this->update_kline('1week', $day_start_date, $model); |
||||
|
$this->update_kline('1mon', $day_start_date, $model); |
||||
|
} |
||||
|
DB::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
DB::rollBack(); |
||||
|
throw $e; |
||||
|
} |
||||
|
return "success"; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
// 生成1minK线 |
||||
|
private function fake_1min_kline($config, $start_date, $end_date, $model) |
||||
|
{ |
||||
|
$decimal = 100000; |
||||
|
$seconds = 60; |
||||
|
$flag = 'is_1min'; |
||||
|
|
||||
|
$open_price = $config['open']; |
||||
|
$close_price = ($config['close'] == $config['open']) ? ($config['close'] * 1.3) : $config['close']; |
||||
|
$high_price = $config['high']; |
||||
|
$low_price = $config['low']; |
||||
|
$min_amount = $config['min_amount']; |
||||
|
$max_amount = $config['max_amount']; |
||||
|
$start = strtotime($start_date); |
||||
|
$end = strtotime($end_date); |
||||
|
|
||||
|
$period_seconds = 60; |
||||
|
$periodCount = 1800 / $period_seconds; //30 |
||||
|
$unit = custom_number_format(bcMath(($high_price - $low_price), $periodCount - 1, '/', 8), 8); |
||||
|
|
||||
|
$points = linspace($open_price, $close_price, $periodCount); |
||||
|
//dd($open_price,$close_price,$points,$unit); |
||||
|
// 24小时 周期价格上涨下跌趋势随机 1涨2跌 |
||||
|
$period2_seconds = 60; |
||||
|
$periodCount2 = 1800 / $period2_seconds; |
||||
|
$periodsTrend = []; |
||||
|
for ($i = 0; $i < $periodCount2; $i++) { |
||||
|
if ($close_price > $open_price) { |
||||
|
$thresholdValue = 60; |
||||
|
} else { |
||||
|
$thresholdValue = 40; |
||||
|
} |
||||
|
$periodsTrend[$start + ($i * $period2_seconds)] = mt_rand(1, 100) <= $thresholdValue ? 1 : 2; |
||||
|
} |
||||
|
|
||||
|
$ups_downs_high = abs(floor($unit * $decimal * 10)); //高 |
||||
|
$ups_downs_value = abs(floor($unit * 2 * $decimal)); //值 |
||||
|
$ups_downs_low = floor(0); //低 |
||||
|
|
||||
|
// dd($open_price,$close_price,$unit,$points,$ups_downs_high,$ups_downs_value); |
||||
|
|
||||
|
$current = $start; |
||||
|
$kkk = 0; |
||||
|
while ($current < $end) { |
||||
|
// echo $current . '--' . $kkk . "\r\n"; |
||||
|
// 获取上一条 |
||||
|
$prev = $model::query()->where($flag, 1)->where('Date', $current - $seconds)->first(); // 上一条K线 |
||||
|
if (blank($prev)) { |
||||
|
$price = $open_price * $decimal; |
||||
|
} else { |
||||
|
$price = $prev['Close'] * $decimal; |
||||
|
} |
||||
|
if (!isset($points[$kkk])) dd($points, $open_price, $close_price, $periodCount, $config['close']); |
||||
|
$close_point = $points[$kkk] * $decimal; |
||||
|
|
||||
|
$amount = mt_rand($min_amount * $decimal, $max_amount * $decimal) / $decimal; |
||||
|
$volume = bcMath($amount, $price / $decimal, '/'); |
||||
|
$open = $price; |
||||
|
$up_or_down = mt_rand(1, 100); |
||||
|
|
||||
|
$first = array_first($periodsTrend, function ($v, $k) use ($current, $period2_seconds) { |
||||
|
return $current >= $k && $current < ($k + $period2_seconds); |
||||
|
}); |
||||
|
// dump($current . '--' . $first); |
||||
|
if ($first == 1) { |
||||
|
$value = 60; |
||||
|
} else { |
||||
|
$value = 40; |
||||
|
} |
||||
|
|
||||
|
// dump($ups_downs_low,$ups_downs_value,$ups_downs_high); |
||||
|
if ($up_or_down <= $value) { |
||||
|
// 涨 |
||||
|
$close = mt_rand($close_point, $close_point + mt_rand($ups_downs_low, $ups_downs_high)); |
||||
|
$high = mt_rand($close, $close + mt_rand($ups_downs_low, $ups_downs_value)); |
||||
|
$low = mt_rand($close - mt_rand($ups_downs_low, $ups_downs_value), $close); |
||||
|
} else { |
||||
|
// 跌 |
||||
|
$close = mt_rand($close_point - mt_rand($ups_downs_low, $ups_downs_high), $close_point); |
||||
|
$high = mt_rand($close, $close + mt_rand($ups_downs_value, $ups_downs_high)); |
||||
|
$low = mt_rand($close - mt_rand($ups_downs_low, $ups_downs_value), $close); |
||||
|
} |
||||
|
|
||||
|
if ($current == $start) { |
||||
|
$open = $open_price * $decimal; |
||||
|
} elseif ($current + $seconds == $end) { |
||||
|
$close = $close_price * $decimal; |
||||
|
} |
||||
|
|
||||
|
$high = max($open, $close, $high, $low); |
||||
|
$low = min($open, $close, $high, $low); |
||||
|
|
||||
|
// dd($open,$close,$high,$low,$close_point); |
||||
|
|
||||
|
$open = $open / $decimal; |
||||
|
$close = $close / $decimal; |
||||
|
$high = $high / $decimal; |
||||
|
$low = $low / $decimal; |
||||
|
|
||||
|
// dd($open,$close,$high,$low,$prev->toArray()); |
||||
|
$model::query()->updateOrCreate( |
||||
|
['Date' => $current, $flag => 1], |
||||
|
[ |
||||
|
'Date' => $current, |
||||
|
'datetime' => date('Y-m-d H:i:s', $current), |
||||
|
'Open' => $open, |
||||
|
'Close' => $close, |
||||
|
'High' => $high, |
||||
|
'Low' => $low, |
||||
|
'LastClose' => $close, |
||||
|
'Volume' => $volume, |
||||
|
'Amount' => $amount, |
||||
|
$flag => 1, |
||||
|
] |
||||
|
); |
||||
|
|
||||
|
$current += $seconds; |
||||
|
$kkk++; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// 根据1minK线生成其他周期K线 |
||||
|
public function fake_period_kline($period, $start_date, $end_date, $model) |
||||
|
{ |
||||
|
$periods = [ |
||||
|
'1min' => [60, 'is_1min'], |
||||
|
'5min' => [300, 'is_5min'], |
||||
|
'15min' => [900, 'is_15min'], |
||||
|
'30min' => [1800, 'is_30min'], |
||||
|
'60min' => [3600, 'is_1h'], |
||||
|
'1day' => [86400, 'is_day'], |
||||
|
'1week' => [604800, 'is_week'], |
||||
|
'1mon' => [2592000, 'is_month'], |
||||
|
]; |
||||
|
$seconds = $periods[$period][0] ?? 60; |
||||
|
$flag = $periods[$period][1] ?? 'is_1min'; |
||||
|
|
||||
|
$start = strtotime($start_date); |
||||
|
$end = strtotime($end_date); |
||||
|
$current = $start; |
||||
|
|
||||
|
$kkk = 1; |
||||
|
while ($current < $end) { |
||||
|
//echo $current . '--' . $kkk . "\r\n"; |
||||
|
$where_start = $current; |
||||
|
$where_end = $current + $seconds - 60; |
||||
|
|
||||
|
$open = $model::query()->where('is_1min', 1)->where('Date', $where_start)->value('Open'); |
||||
|
$close = $model::query()->where('is_1min', 1)->where('Date', $where_end)->value('Close'); |
||||
|
$high = $model::query()->where('is_1min', 1)->whereBetween('Date', [$where_start, $where_end])->max('High'); |
||||
|
$low = $model::query()->where('is_1min', 1)->whereBetween('Date', [$where_start, $where_end])->min('Low'); |
||||
|
$volume = $model::query()->where('is_1min', 1)->whereBetween('Date', [$where_start, $where_end])->sum('Volume'); |
||||
|
$amount = $model::query()->where('is_1min', 1)->whereBetween('Date', [$where_start, $where_end])->sum('Amount'); |
||||
|
|
||||
|
$model::query()->updateOrCreate( |
||||
|
['Date' => $current, $flag => 1], |
||||
|
[ |
||||
|
'datetime' => date('Y-m-d H:i:s', $current), |
||||
|
'Open' => $open, |
||||
|
'Close' => $close, |
||||
|
'High' => $high, |
||||
|
'Low' => $low, |
||||
|
'LastClose' => $close, |
||||
|
'Volume' => $volume, |
||||
|
'Amount' => $amount, |
||||
|
] |
||||
|
); |
||||
|
|
||||
|
$current += $seconds; |
||||
|
$kkk++; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 更新周线和月线 |
||||
|
public function update_kline($period, $start_date, $model) |
||||
|
{ |
||||
|
$periods = [ |
||||
|
'1min' => [60, 'is_1min'], |
||||
|
'5min' => [300, 'is_5min'], |
||||
|
'15min' => [900, 'is_15min'], |
||||
|
'30min' => [1800, 'is_30min'], |
||||
|
'60min' => [3600, 'is_1h'], |
||||
|
'1day' => [86400, 'is_day'], |
||||
|
'1week' => [604800, 'is_week'], |
||||
|
'1mon' => [2592000, 'is_month'], |
||||
|
]; |
||||
|
$seconds = $periods[$period][0] ?? 60; |
||||
|
$flag = $periods[$period][1] ?? 'is_1min'; |
||||
|
|
||||
|
if ($period == '1week') { |
||||
|
$where_start = Carbon::parse($start_date)->startOfWeek(Carbon::SUNDAY)->getTimestamp(); |
||||
|
$where_end = Carbon::parse($start_date)->endOfWeek(Carbon::SUNDAY)->getTimestamp(); |
||||
|
$open = $model::query()->where('is_1min', 1)->where('Date', '>=', $where_start)->orderBy('Date', 'asc')->first()['Open'] ?? null; |
||||
|
$close = $model::query()->where('is_1min', 1)->where('Date', '<=', $where_end)->orderBy('Date', 'desc')->first()['Close'] ?? null; |
||||
|
$high = $model::query()->where('is_1min', 1)->whereBetween('Date', [$where_start, $where_end])->max('High'); |
||||
|
$low = $model::query()->where('is_1min', 1)->whereBetween('Date', [$where_start, $where_end])->min('Low'); |
||||
|
$volume = $model::query()->where('is_1min', 1)->whereBetween('Date', [$where_start, $where_end])->sum('Volume'); |
||||
|
$amount = $model::query()->where('is_1min', 1)->whereBetween('Date', [$where_start, $where_end])->sum('Amount'); |
||||
|
|
||||
|
$model::query()->updateOrCreate( |
||||
|
[ |
||||
|
'Date' => $where_start, |
||||
|
$flag => 1, |
||||
|
], |
||||
|
[ |
||||
|
'datetime' => date('Y-m-d H:i:s', $where_start), |
||||
|
'Open' => $open, |
||||
|
'Close' => $close, |
||||
|
'High' => $high, |
||||
|
'Low' => $low, |
||||
|
'LastClose' => $close, |
||||
|
'Volume' => $volume, |
||||
|
'Amount' => $amount, |
||||
|
] |
||||
|
); |
||||
|
} elseif ($period == '1mon') { |
||||
|
$where_start = Carbon::parse($start_date)->startOfMonth()->getTimestamp(); |
||||
|
$where_end = Carbon::parse($start_date)->endOfMonth()->getTimestamp(); |
||||
|
$open = $model::query()->where('is_1min', 1)->where('Date', '>=', $where_start)->orderBy('Date', 'asc')->first()['Open'] ?? null; |
||||
|
$close = $model::query()->where('is_1min', 1)->where('Date', '<=', $where_end)->orderBy('Date', 'desc')->first()['Close'] ?? null; |
||||
|
$high = $model::query()->where('is_1min', 1)->whereBetween('Date', [$where_start, $where_end])->max('High'); |
||||
|
$low = $model::query()->where('is_1min', 1)->whereBetween('Date', [$where_start, $where_end])->min('Low'); |
||||
|
$volume = $model::query()->where('is_1min', 1)->whereBetween('Date', [$where_start, $where_end])->sum('Volume'); |
||||
|
$amount = $model::query()->where('is_1min', 1)->whereBetween('Date', [$where_start, $where_end])->sum('Amount'); |
||||
|
|
||||
|
$model::query()->updateOrCreate( |
||||
|
[ |
||||
|
'Date' => $where_start, |
||||
|
$flag => 1, |
||||
|
], |
||||
|
[ |
||||
|
'datetime' => date('Y-m-d H:i:s', $where_start), |
||||
|
'Open' => $open, |
||||
|
'Close' => $close, |
||||
|
'High' => $high, |
||||
|
'Low' => $low, |
||||
|
'LastClose' => $close, |
||||
|
'Volume' => $volume, |
||||
|
'Amount' => $amount, |
||||
|
] |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected function checkTimeInterval($datetime, $price) |
||||
|
{ |
||||
|
$min5 = CoinData::query()->where('datetime', '<=', $datetime)->where('is_5min', 1)->orderByDesc('datetime')->first(); |
||||
|
if ($min5) { |
||||
|
$this->updateTimeIntervalKline($min5, $price, $datetime, '5'); |
||||
|
} |
||||
|
|
||||
|
$min15 = CoinData::query()->where('datetime', '<=', $datetime)->where('is_15min', 1)->orderByDesc('datetime')->first(); |
||||
|
if ($min15) { |
||||
|
$this->updateTimeIntervalKline($min15, $price, $datetime, '15'); |
||||
|
} |
||||
|
|
||||
|
$min30 = CoinData::query()->where('datetime', '<=', $datetime)->where('is_30min', 1)->orderByDesc('datetime')->first(); |
||||
|
if ($min30) { |
||||
|
$this->updateTimeIntervalKline($min30, $price, $datetime, '30'); |
||||
|
} |
||||
|
|
||||
|
$min60 = CoinData::query()->where('datetime', '<=', $datetime)->where('is_1h', 1)->orderByDesc('datetime')->first(); |
||||
|
if ($min60) { |
||||
|
$this->updateTimeIntervalKline($min60, $price, $datetime, '60'); |
||||
|
} |
||||
|
|
||||
|
$day = CoinData::query()->where('datetime', '<', $datetime)->where('is_day', 1)->orderByDesc('datetime')->first(); |
||||
|
if ($day) { |
||||
|
$this->updateTimeIntervalKline($day, $price, $datetime, 'day'); |
||||
|
} |
||||
|
|
||||
|
$w = date('w', strtotime($datetime)); |
||||
|
$time = strtotime($datetime); |
||||
|
if ($w > 0) { |
||||
|
$time += (7 - $w) * 86400; |
||||
|
} |
||||
|
$date = date('Y-m-d 00:00:00', $time); |
||||
|
$week = CoinData::query()->where('datetime', $date)->where('is_week', 1)->orderByDesc('datetime')->first(); |
||||
|
if ($week) { |
||||
|
$this->updateTimeIntervalKline($week, $price, $datetime, 'week'); |
||||
|
} |
||||
|
|
||||
|
$month = CoinData::query()->where('datetime', '<', $datetime)->where('is_month', 1)->orderByDesc('datetime')->first(); |
||||
|
if ($month) { |
||||
|
$this->updateTimeIntervalKline($month, $price, $datetime, 'month'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected function updateTimeIntervalKline($dataStai, $price, $datetime, $timeInterval) |
||||
|
{ |
||||
|
if ($price > $dataStai->high) { |
||||
|
$dataStai->high = $price + (mt_rand(1, 10) / 10000); |
||||
|
} |
||||
|
if ($price < $dataStai->low) { |
||||
|
$dataStai->low = $price - (mt_rand(1, 10) / 10000); |
||||
|
} |
||||
|
$dataStai->save(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,110 @@ |
|||||
|
<?php |
||||
|
|
||||
|
/** |
||||
|
* Created by PhpStorm. |
||||
|
* ListingApplication: Administrator |
||||
|
* Date: 2020/7/23 |
||||
|
* Time: 11:12 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Actions\Application\ApplicationCheck; |
||||
|
use App\Models\ListingApplication; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class ListingApplicationController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new ListingApplication(), function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('id'); |
||||
|
|
||||
|
$grid->setActionClass(Grid\Displayers\Actions::class); |
||||
|
|
||||
|
$grid->actions(function (Grid\Displayers\Actions $actions) { |
||||
|
$actions->disableDelete(); |
||||
|
$actions->disableQuickEdit(); |
||||
|
$actions->disableEdit(); |
||||
|
$actions->disableView(); |
||||
|
|
||||
|
if ($actions->row->status == ListingApplication::status_wait) { |
||||
|
$actions->append(new ApplicationCheck()); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->disableEditButton(); |
||||
|
|
||||
|
// 这里的字段会自动使用翻译文件 |
||||
|
$grid->id->sortable(); |
||||
|
$grid->contact_phone; |
||||
|
$grid->contact_position; |
||||
|
$grid->coin_name; |
||||
|
$grid->listing_fee_budget; |
||||
|
$grid->referrer_mechanism_code; |
||||
|
$grid->status->using([0 => '等待审核', 1 => '审核成功', 2 => '审核失败'])->dot([0 => 'danger', 1 => 'success', 2 => 'error'])->filter( |
||||
|
Grid\Column\Filter\In::make(ListingApplication::$statusMap) |
||||
|
); |
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('id'); |
||||
|
}); |
||||
|
$grid->filter(function ($filter) { |
||||
|
$filter->equal('contact_phone', '联系人电话'); |
||||
|
$filter->like('status', '审核状态'); |
||||
|
$filter->like('coin_name', '币种名字'); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new ListingApplication(), function (Show $show) { |
||||
|
// 这里的字段会自动使用翻译文件 |
||||
|
$show->id; |
||||
|
$show->contact_phone; |
||||
|
$show->contact_position; |
||||
|
$show->coin_name; |
||||
|
$show->listing_fee_budget; |
||||
|
$show->referrer_mechanism_code; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new ListingApplication(), function (Form $form) { |
||||
|
// 这里的字段会自动使用翻译文件 |
||||
|
$form->display('id'); |
||||
|
$form->text('contact_phone'); |
||||
|
$form->text('contact_position'); |
||||
|
$form->text('coin_name'); |
||||
|
$form->text('listing_fee_budget'); |
||||
|
$form->text('referrer_mechanism_code'); |
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,89 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Models\Navigation; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class NavigationController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected $title = "导航配置"; |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new Navigation(), function (Grid $grid) { |
||||
|
$grid->id->sortable(); |
||||
|
$grid->column('type', "位置")->using(Navigation::$type); |
||||
|
$grid->name; |
||||
|
$grid->img; |
||||
|
$grid->link_type; |
||||
|
$grid->link_data; |
||||
|
$grid->desc; |
||||
|
$grid->order; |
||||
|
$grid->column("status", "是否首页显示")->using(Navigation::$status); |
||||
|
$grid->created_at; |
||||
|
$grid->updated_at->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('id'); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new Navigation(), function (Show $show) { |
||||
|
$show->id; |
||||
|
$show->type; |
||||
|
$show->name; |
||||
|
$show->img; |
||||
|
$show->link_type; |
||||
|
$show->link_data; |
||||
|
$show->desc; |
||||
|
$show->order; |
||||
|
$show->status; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new Navigation(), function (Form $form) { |
||||
|
$form->display('id'); |
||||
|
$form->select('type', "顶部|底部")->options(Navigation::$type)->default(1); |
||||
|
$form->image('img')->autoUpload(); |
||||
|
$form->text('link_type', "链接类型"); |
||||
|
$form->text('link_data', "链接数据"); |
||||
|
$form->text('desc', "描述"); |
||||
|
$form->text('order')->default(1); |
||||
|
$form->select('status', "是否首页展示")->options(Navigation::$status)->default(1); |
||||
|
$form->hasMany('translations', '语言', function (Form\NestedForm $form) { |
||||
|
$form->select('locale')->options(['en' => '英', 'zh-CN' => '中', "zh-TW" => "繁体"])->default('zh-CN')->label(); |
||||
|
|
||||
|
$form->text('name'); |
||||
|
// $form->text('imgurl'); |
||||
|
|
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,77 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Actions\Grid\OmniusdtCollection; |
||||
|
use App\Models\User; |
||||
|
use App\Models\UserWallet; |
||||
|
use App\Services\CoinService\GethService; |
||||
|
use App\Services\CoinService\GethTokenService; |
||||
|
use App\Services\CoinService\OmnicoreService; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Layout\Content; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use Dcat\Admin\Widgets\Alert; |
||||
|
use Dcat\Admin\Widgets\Card; |
||||
|
use Dcat\Admin\Widgets\Table; |
||||
|
use Web3\Providers\HttpProvider; |
||||
|
use Web3\RequestManagers\HttpRequestManager; |
||||
|
use Web3\Web3; |
||||
|
|
||||
|
class OMNIUSDTAccountsController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
$builder = UserWallet::with(['user'])->where('coin_id', 1)->where(function ($q) { |
||||
|
$q->whereNotNull('omni_wallet_address')->where('omni_wallet_address', '<>', ''); |
||||
|
}); |
||||
|
return Grid::make($builder, function (Grid $grid) { |
||||
|
$grid->model()->orderByDesc('user_id'); |
||||
|
|
||||
|
#统计 |
||||
|
$grid->header(function ($query) { |
||||
|
$usdt_amount = (new OmnicoreService())->getwalletbalances(); |
||||
|
$con = '<code>USDT:' . $usdt_amount . '</code>'; |
||||
|
return Alert::make($con, '统计')->info(); |
||||
|
}); |
||||
|
|
||||
|
$grid->actions(function (Grid\Displayers\Actions $actions) { |
||||
|
$actions->disableDelete(); |
||||
|
$actions->disableQuickEdit(); |
||||
|
$actions->disableEdit(); |
||||
|
$actions->disableView(); |
||||
|
|
||||
|
$actions->append(new OmniusdtCollection()); |
||||
|
}); |
||||
|
|
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->disableRowSelector(); |
||||
|
|
||||
|
$grid->column('user_id', 'UID'); |
||||
|
$grid->column('user.username', '用户名'); |
||||
|
$grid->column('coin_name', '币种'); |
||||
|
$grid->column('omni_wallet_address', '地址'); |
||||
|
|
||||
|
$grid->column('balance', '余额')->display(function () { |
||||
|
return (new OmnicoreService())->getBalance($this->omni_wallet_address); |
||||
|
}); |
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('user_id', '会员ID')->width(2); |
||||
|
$filter->where('username', function ($q) { |
||||
|
$username = $this->input; |
||||
|
$q->whereHas('user', function ($q) use ($username) { |
||||
|
$q->where('username', $username)->orWhere('phone', $username)->orWhere('email', $username); |
||||
|
}); |
||||
|
}, "用户名/手机/邮箱")->width(3); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,96 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
* @Descripttion: |
||||
|
* @version: |
||||
|
* @Author: GuaPi |
||||
|
* @Date: 2021-07-29 10:40:49 |
||||
|
* @LastEditors: GuaPi |
||||
|
* @LastEditTime: 2021-08-09 17:43:18 |
||||
|
*/ |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Actions\OptionPair\Close; |
||||
|
use App\Admin\Actions\OptionPair\Open; |
||||
|
use App\Models\OptionPair; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
|
||||
|
class OptionPairController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new OptionPair(), function (Grid $grid) { |
||||
|
|
||||
|
$grid->disableRowSelector(); |
||||
|
$grid->disableBatchDelete(); |
||||
|
|
||||
|
$grid->tools([ |
||||
|
new Open(), |
||||
|
new Close(), |
||||
|
]); |
||||
|
|
||||
|
$grid->pair_id->sortable(); |
||||
|
$grid->pair_name; |
||||
|
$grid->coin_name; |
||||
|
$grid->base_coin_name; |
||||
|
$grid->status->switch(); |
||||
|
$grid->trade_status->switch(); |
||||
|
$grid->created_at->sortable(); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('pair_id'); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new OptionPair(), function (Show $show) { |
||||
|
$show->pair_id; |
||||
|
$show->pair_name; |
||||
|
$show->base_coin_name; |
||||
|
$show->coin_name; |
||||
|
$show->status; |
||||
|
$show->created_at; |
||||
|
$show->updated_at; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new OptionPair(), function (Form $form) { |
||||
|
$form->display('pair_id'); |
||||
|
$form->text('pair_name'); |
||||
|
$form->text('quote_coin_id'); |
||||
|
$form->text('quote_coin_name'); |
||||
|
$form->text('base_coin_id'); |
||||
|
$form->text('base_coin_name'); |
||||
|
$form->switch('status')->default(1); |
||||
|
$form->switch('trade_status')->default(1); |
||||
|
|
||||
|
|
||||
|
$form->display('created_at'); |
||||
|
$form->display('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue