FastMovieAI AI短剧创作平台 二开基线
- 源码: xhadmincn/FastMovieAI (Apache 2.0) - 二开: Docker部署, Swoole改Select, route.php修复, 补update/VERSION - vendor/示例资源已gitignore
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"title": "财务",
|
||||
"icon": "Wallet",
|
||||
"path": "/app/finance/admin",
|
||||
"sort":4999,
|
||||
"children":[
|
||||
{
|
||||
"title":"控制台",
|
||||
"icon":"ElementPlus",
|
||||
"path": "/app/finance/admin/Index/index",
|
||||
"component": "databoard"
|
||||
},
|
||||
{
|
||||
"title":"订单列表",
|
||||
"icon":"ShoppingCart",
|
||||
"path": "/app/finance/admin/Orders/index",
|
||||
"component": "table",
|
||||
"children":[
|
||||
{
|
||||
"title":"实收",
|
||||
"path": "/app/finance/admin/Orders/real_money",
|
||||
"component": "form",
|
||||
"show":false
|
||||
},
|
||||
{
|
||||
"title":"收付",
|
||||
"path": "/app/finance/admin/Orders/receipt_money",
|
||||
"component": "form",
|
||||
"show":false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title":"交易设置",
|
||||
"icon":"Setting",
|
||||
"path": "/app/finance/admin/Settings/basic",
|
||||
"component": "form"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\api;
|
||||
|
||||
use plugin\control\expose\api\Control as ApiControl;
|
||||
|
||||
class Control
|
||||
{
|
||||
use ApiControl;
|
||||
public function __construct()
|
||||
{
|
||||
$this->path = __DIR__;
|
||||
$this->plugin = 'finance';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\api;
|
||||
|
||||
use app\expose\api\Install as ApiInstall;
|
||||
|
||||
class Install
|
||||
{
|
||||
use ApiInstall;
|
||||
public function __construct()
|
||||
{
|
||||
$this->path = __DIR__;
|
||||
$this->plugin = 'finance';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\api\notify;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\enum\PaymentChannels;
|
||||
use plugin\finance\app\model\PluginFinanceOrders;
|
||||
use plugin\finance\app\model\PluginFinanceOrdersLog;
|
||||
use plugin\finance\expose\helper\Account;
|
||||
use plugin\finance\utils\enum\OrdersState;
|
||||
use plugin\finance\utils\enum\OrdersType;
|
||||
use plugin\finance\utils\enum\PointsBillScene;
|
||||
use plugin\marketing\app\model\PluginMarketingPlan;
|
||||
use plugin\marketing\app\model\PluginMarketingPlanPrice;
|
||||
use plugin\marketing\app\model\PluginMarketingPoints;
|
||||
use plugin\user\app\model\PluginUserVip;
|
||||
use support\Log;
|
||||
use think\facade\Db;
|
||||
|
||||
class Wechat extends Basic
|
||||
{
|
||||
public function transaction($data)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = PluginFinanceOrders::where(['trade_no' => $data['out_trade_no']])->find();
|
||||
if (!$order) {
|
||||
return false;
|
||||
}
|
||||
$order->state = OrdersState::PAID['value'];
|
||||
$order->pay_time = date('Y-m-d H:i:s');
|
||||
$order->finish_time = date('Y-m-d H:i:s');
|
||||
$order->transaction_id = $data['transaction_id'];
|
||||
$order->save();
|
||||
PluginFinanceOrdersLog::info($order, PaymentChannels::WXPAY['label'] . '支付成功');
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
try {
|
||||
PluginFinanceOrders::finish(['id' => $order->id]);
|
||||
} catch (\Throwable $th) {
|
||||
Log::error("订单完成失败:{$order->trade_no},{$th->getMessage()},{$th->getFile()}:{$th->getLine()}", $th->getTrace());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\app\admin\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\build\builder\FormBuilder;
|
||||
use app\expose\build\builder\TableBuilder;
|
||||
use app\expose\enum\Action;
|
||||
use app\expose\enum\State;
|
||||
use app\expose\enum\Week;
|
||||
use support\Request;
|
||||
|
||||
class IndexController extends Basic
|
||||
{
|
||||
public function indexGetTable(Request $request)
|
||||
{
|
||||
$builder = new TableBuilder();
|
||||
$builder->addAction('操作', [
|
||||
'width' => '200px',
|
||||
'fixed' => 'right'
|
||||
]);
|
||||
$builder->addTableAction('编辑', [
|
||||
'path' => 'Admin/update',
|
||||
'props' => [
|
||||
'type' => 'primary',
|
||||
'title' => '编辑《{nickname}》管理员'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'primary',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->addTableAction('删除', [
|
||||
'model' => Action::COMFIRM['value'],
|
||||
'path' => 'Admin/delete',
|
||||
'where' => [
|
||||
['is_system', '!=', 1]
|
||||
],
|
||||
'props' => [
|
||||
'type' => 'error',
|
||||
'message' => '确定要删除《{nickname}》管理员吗?',
|
||||
'confirmButtonClass' => 'el-button--danger'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'danger',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->addHeader();
|
||||
$builder->addHeaderAction('创建管理员', [
|
||||
'path' => 'Admin/create',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'title' => '创建管理员'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$formBuilder = new FormBuilder();
|
||||
$formBuilder->add('username', '账号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '账号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('mobile', '手机号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '手机号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$builder->addScreen($formBuilder);
|
||||
$builder->add('id', 'ID', [
|
||||
'props' => [
|
||||
'width' => '80px'
|
||||
]
|
||||
]);
|
||||
$builder->add('userinfo', '管理员', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'nickname',
|
||||
'avatar' => 'headimg',
|
||||
'info' => 'username',
|
||||
'nicknameTags' => [
|
||||
[
|
||||
'field' => 'new_text',
|
||||
'props' => [
|
||||
'type' => 'danger',
|
||||
'size' => 'small'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'new_text1',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
],
|
||||
'tags' => [
|
||||
[
|
||||
'field' => 'role_name',
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'minWidth' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('contact', '联系方式', [
|
||||
'props' => [
|
||||
'width' => '280px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'mobile',
|
||||
'label' => '手机号'
|
||||
],
|
||||
[
|
||||
'field' => 'email',
|
||||
'label' => '邮箱'
|
||||
],
|
||||
[
|
||||
'field' => 'wx_openid',
|
||||
'label' => 'OpenID'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('allow_week', '工作日', [
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => Week::getOptions()
|
||||
],
|
||||
'props' => [
|
||||
'width' => '240px'
|
||||
]
|
||||
]);
|
||||
$builder->add('allow_work', '工作时间', [
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => [
|
||||
[
|
||||
'index' => 0,
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
],
|
||||
[
|
||||
'index' => 1,
|
||||
'props' => [
|
||||
'type' => 'danger'
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('online_time', '活动', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'online_time',
|
||||
'label' => '在线'
|
||||
],
|
||||
[
|
||||
'field' => 'login_time',
|
||||
'label' => '登录'
|
||||
],
|
||||
[
|
||||
'component' => 'tag',
|
||||
'field' => 'login_ip',
|
||||
'label' => '登录IP',
|
||||
'props' => [
|
||||
'size' => 'small',
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('state', '状态', [
|
||||
'component' => [
|
||||
'name' => 'switch',
|
||||
'api' => 'Admin/indexUpdateState',
|
||||
'props' => [
|
||||
'active-value' => State::YES['value'],
|
||||
'inactive-value' => State::NO['value']
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('create_time', '时间', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'create_time',
|
||||
'label' => '创建'
|
||||
],
|
||||
[
|
||||
'field' => 'update_time',
|
||||
'label' => '更新'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder = $builder->builder();
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
return $this->success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,520 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\app\admin\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\build\builder\ComponentBuilder;
|
||||
use app\expose\build\builder\FormBuilder;
|
||||
use app\expose\build\builder\TableBuilder;
|
||||
use app\expose\enum\Action;
|
||||
use app\expose\enum\EventName;
|
||||
use app\expose\enum\PaymentChannels;
|
||||
use app\expose\enum\PaymentCurrency;
|
||||
use app\expose\enum\State;
|
||||
use app\model\PaymentTemplate;
|
||||
use plugin\apps\app\model\PluginAppsPrice;
|
||||
use plugin\apps\app\model\PluginAppsSpecifications;
|
||||
use plugin\apps\utils\enum\PaymentMethod;
|
||||
use plugin\finance\app\model\PluginFinanceOrders;
|
||||
use plugin\finance\app\model\PluginFinanceOrdersLog;
|
||||
use plugin\finance\app\model\PluginFinanceWallet;
|
||||
use plugin\finance\utils\enum\OrdersState;
|
||||
use plugin\finance\utils\enum\OrdersType;
|
||||
use plugin\marketing\app\model\PluginMarketingCoupon;
|
||||
use plugin\marketing\app\model\PluginMarketingCouponCode;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use support\Log;
|
||||
use support\Request;
|
||||
use think\facade\Db;
|
||||
use Webman\Event\Event;
|
||||
|
||||
class OrdersController extends Basic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new PluginFinanceOrders();
|
||||
}
|
||||
public function indexGetTable(Request $request)
|
||||
{
|
||||
$builder = new TableBuilder();
|
||||
$builder->addAction('操作', [
|
||||
'width' => '160px',
|
||||
'fixed' => 'right'
|
||||
]);
|
||||
$builder->addTableAction('完成', [
|
||||
'model' => Action::COMFIRM['value'],
|
||||
'path' => '/app/finance/admin/Orders/finish',
|
||||
'props' => [
|
||||
'title' => '完成《{title}》订单'
|
||||
],
|
||||
'where' => [
|
||||
['state', '=', OrdersState::PAID['value']]
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->addTableAction('实收', [
|
||||
'model' => Action::DIALOG['value'],
|
||||
'path' => '/app/finance/admin/Orders/real_money',
|
||||
'props' => [
|
||||
'title' => '实收《{title}》订单'
|
||||
],
|
||||
'where' => [
|
||||
['state', '=', OrdersState::WAIT_PAY['value']]
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'primary',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->addTableAction('收付', [
|
||||
'model' => Action::DIALOG['value'],
|
||||
'path' => '/app/finance/admin/Orders/receipt_money',
|
||||
'props' => [
|
||||
'title' => '确认已收到《{title}》订单对公转账'
|
||||
],
|
||||
'where' => [
|
||||
['state', '=', OrdersState::WAIT_VERIFIED['value']]
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'primary',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$formBuilder = new FormBuilder(null, null, [
|
||||
'inline' => true
|
||||
]);
|
||||
$formBuilder->add('title', '订单标题', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '订单标题搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('trade_no', '订单号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '订单号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('state', '状态', 'select', null, [
|
||||
'options' => OrdersState::getOptions(),
|
||||
'props' => [
|
||||
'placeholder' => '状态搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('type', '订单类型', 'select', null, [
|
||||
'options' => OrdersType::getOptions(),
|
||||
'props' => [
|
||||
'placeholder' => '订单类型搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('uid', '用户', 'select', null, [
|
||||
'options' => [],
|
||||
'remote' => [
|
||||
'url' => '/app/finance/admin/Orders/queryUser',
|
||||
],
|
||||
'props' => [
|
||||
'placeholder' => '用户搜索',
|
||||
'clearable' => true,
|
||||
'filterable' => true
|
||||
]
|
||||
]);
|
||||
$builder->addScreen($formBuilder);
|
||||
$builder->add('id', 'ID', [
|
||||
'props' => [
|
||||
'width' => '80px'
|
||||
]
|
||||
]);
|
||||
$builder->add('order', '订单', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'title',
|
||||
'info' => 'trade_no',
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'minWidth' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('user', '用户', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'user.nickname',
|
||||
'avatar' => 'user.headimg',
|
||||
'info' => 'user.mobile',
|
||||
'tags' => [
|
||||
[
|
||||
'field' => 'uid',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'minWidth' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('state', '状态', [
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => OrdersState::getOptions()
|
||||
],
|
||||
'props' => [
|
||||
'width' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('type', '订单类型', [
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => OrdersType::getOptions()
|
||||
],
|
||||
'props' => [
|
||||
'width' => '140px'
|
||||
]
|
||||
]);
|
||||
$builder->add('statistic', '数据', [
|
||||
'component' => [
|
||||
'name' => 'statistic',
|
||||
'options' => [
|
||||
[
|
||||
'label' => '原价',
|
||||
'value' => 'origin_money'
|
||||
],
|
||||
[
|
||||
'label' => '实付',
|
||||
'value' => 'money'
|
||||
],
|
||||
[
|
||||
'label' => '数量',
|
||||
'value' => 'num'
|
||||
]
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'minWidth' => '380px'
|
||||
]
|
||||
]);
|
||||
$builder->add('coupon', '优惠券', [
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
],
|
||||
'props' => [
|
||||
'minWidth' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('create_time', '时间', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'create_time',
|
||||
'label' => '创建'
|
||||
],
|
||||
[
|
||||
'field' => 'update_time',
|
||||
'label' => '更新'
|
||||
],
|
||||
[
|
||||
'field' => 'pay_time',
|
||||
'label' => '支付'
|
||||
],
|
||||
[
|
||||
'field' => 'expire_time',
|
||||
'label' => '过期'
|
||||
],
|
||||
[
|
||||
'field' => 'cancel_time',
|
||||
'label' => '取消'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder = $builder->builder();
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function queryUser(Request $request)
|
||||
{
|
||||
$query = $request->post('query');
|
||||
if (empty($query)) {
|
||||
return $this->resData([]);
|
||||
}
|
||||
$where = [];
|
||||
$where[] = ['nickname|mobile', 'like', "%{$query}%"];
|
||||
return $this->resData(PluginUser::options($where));
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
$where = [];
|
||||
$title = $request->get('title');
|
||||
if ($title) {
|
||||
$where[] = ['title', 'like', "%{$title}%"];
|
||||
}
|
||||
$trade_no = $request->get('trade_no');
|
||||
if ($trade_no) {
|
||||
$where[] = ['trade_no', '=', $trade_no];
|
||||
}
|
||||
$state = $request->get('state');
|
||||
if ($state !== null) {
|
||||
$where[] = ['state', '=', $state];
|
||||
}
|
||||
$type = $request->get('type');
|
||||
if ($type !== null) {
|
||||
$where[] = ['type', '=', $type];
|
||||
}
|
||||
$uid = $request->get('uid');
|
||||
if ($uid) {
|
||||
$where[] = ['uid', '=', $uid];
|
||||
}
|
||||
$list = PluginFinanceOrders::where($where)->with(['user' => function ($query) {
|
||||
$query->field('id,nickname,headimg,mobile,channels_uid');
|
||||
}])
|
||||
->order('id desc')->paginate($limit)->each(function ($item) {});
|
||||
return $this->resData($list);
|
||||
}
|
||||
public function finish(Request $request)
|
||||
{
|
||||
$id = $request->post('id');
|
||||
try {
|
||||
PluginFinanceOrders::finish(['id' => $id]);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
return $this->success('完成订单成功');
|
||||
}
|
||||
public function real_money(Request $request)
|
||||
{
|
||||
if ($request->method() == 'POST') {
|
||||
$id = $request->post('id');
|
||||
$order = PluginFinanceOrders::where(['id' => $id])->find();
|
||||
if (!$order) {
|
||||
return $this->fail('订单不存在');
|
||||
}
|
||||
if ($order->state != OrdersState::WAIT_PAY['value']) {
|
||||
return $this->fail('订单状态不是待支付');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order->state = OrdersState::PAID['value'];
|
||||
$order->pay_type = PaymentChannels::ADMIN['value'];
|
||||
$order->pay_time = date('Y-m-d H:i:s');
|
||||
$order->system_money = $request->post('system_money');
|
||||
$order->money = $order->origin_money - $order->system_money - $order->channels_money - $order->developer_money;
|
||||
$order->save();
|
||||
PluginFinanceOrdersLog::info($order, '管理员操作实收成功');
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
PluginFinanceOrdersLog::fail($order, $th->getMessage());
|
||||
return $this->exception($th);
|
||||
}
|
||||
Event::emit(EventName::ORDERS_PAY['value'], [
|
||||
'data' => $order,
|
||||
'payment_channel' => PaymentChannels::ADMIN['value'],
|
||||
'plugin' => 'finance'
|
||||
]);
|
||||
try {
|
||||
PluginFinanceOrders::finish(['id' => $order->id]);
|
||||
} catch (\Throwable $th) {
|
||||
PluginFinanceOrdersLog::fail($order, $th->getMessage());
|
||||
Log::error("订单完成失败:{$order->trade_no},{$th->getMessage()},{$th->getFile()}:{$th->getLine()}", $th->getTrace());
|
||||
return $this->exception($th);
|
||||
}
|
||||
return $this->success('实收订单成功');
|
||||
}
|
||||
$id = $request->get('id');
|
||||
$order = PluginFinanceOrders::where(['id' => $id])->find();
|
||||
if (!$order) {
|
||||
return $this->fail('订单不存在');
|
||||
}
|
||||
if ($order->state != OrdersState::WAIT_PAY['value']) {
|
||||
return $this->fail('订单状态不是待支付');
|
||||
}
|
||||
$Component = new ComponentBuilder;
|
||||
$builder = new FormBuilder(null, null, [
|
||||
'translations' => true,
|
||||
'size' => 'large',
|
||||
]);
|
||||
$builder->add('title', '订单', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 12,
|
||||
'xl' => 12
|
||||
],
|
||||
]);
|
||||
$builder->add('trade_no', '订单号', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 12,
|
||||
'xl' => 12
|
||||
],
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]);
|
||||
$builder->add('create_time', '下单时间', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 12,
|
||||
'xl' => 12
|
||||
],
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]);
|
||||
$builder->add('expire_time', '过期时间', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 12,
|
||||
'xl' => 12
|
||||
],
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]);
|
||||
$builder->add('settle_accounts_time', '结算日期', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
]);
|
||||
$builder->add('num', '数量', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
]);
|
||||
$builder->add('origin_money', '原价', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
]);
|
||||
$builder->add('unit_money', '单价', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
]);
|
||||
$builder->add('money', '应付', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
'props' => [
|
||||
'type' => 'danger'
|
||||
]
|
||||
]);
|
||||
$maxSystemMoney = $order->money;
|
||||
$builder->add('system_money', '平台优惠金额', 'input-number', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
'required' => true,
|
||||
'props' => [
|
||||
'min' => 0,
|
||||
'max' => $maxSystemMoney,
|
||||
'step' => 0.01,
|
||||
'controls' => false
|
||||
],
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '最大可优惠金额:' . $maxSystemMoney . '元'], ['type' => 'danger', 'size' => 'small'])->builder(),
|
||||
],
|
||||
'children' => [
|
||||
'suffix' => [
|
||||
'component' => 'el-text',
|
||||
'props' => [
|
||||
'size' => 'small'
|
||||
],
|
||||
'children' => [
|
||||
'default' => '元'
|
||||
]
|
||||
],
|
||||
'prefix' => [
|
||||
'component' => 'el-text',
|
||||
'props' => [
|
||||
'size' => 'small'
|
||||
],
|
||||
'children' => [
|
||||
'default' => '¥'
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$formula = 'money - system_money';
|
||||
$builder->add('real_money', '实收金额', 'compute', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '请确认财务已收到款项'], ['type' => 'info', 'size' => 'small'])->builder(),
|
||||
$Component->add('text', ['default' => '实收后订单状态将变为:'], ['type' => 'info', 'size' => 'small'])->add('tag', ['default' => OrdersState::FINISH['label']], ['type' => OrdersState::FINISH['props']['type'], 'size' => 'small'])->builder(),
|
||||
],
|
||||
'props' => [
|
||||
'formula' => $formula,
|
||||
'type' => 'danger',
|
||||
'size' => 'large',
|
||||
'tag' => 'b'
|
||||
]
|
||||
]);
|
||||
$builder->setData($order->toArray());
|
||||
return $this->resData($builder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\app\admin\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\trait\Config;
|
||||
|
||||
class SettingsController extends Basic
|
||||
{
|
||||
use Config;
|
||||
public function basic()
|
||||
{
|
||||
return $this->builder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\app\api\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\enum\PaymentChannels;
|
||||
use plugin\finance\app\model\PluginFinanceOrders;
|
||||
use plugin\finance\app\model\PluginFinanceOrdersLog;
|
||||
use plugin\finance\utils\enum\OrdersState;
|
||||
use plugin\marketing\app\model\PluginMarketingCoupon;
|
||||
use plugin\marketing\app\model\PluginMarketingCouponCode;
|
||||
use support\Log;
|
||||
use support\Request;
|
||||
use think\facade\Db;
|
||||
|
||||
class IndexController extends Basic
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
$where = [];
|
||||
$title = $request->get('title');
|
||||
if ($title) {
|
||||
$where[] = ['title|trade_no', 'like', "%{$title}%"];
|
||||
}
|
||||
$state = $request->get('state');
|
||||
if ($state !== null) {
|
||||
$where[] = ['state', '=', $state];
|
||||
}
|
||||
$type = $request->get('type');
|
||||
if ($type) {
|
||||
$where[] = ['type', '=', $type];
|
||||
}
|
||||
$where[] = ['uid', '=', $request->uid];
|
||||
$config = config('plugin.shopwwi.filesystem.app.storage.public');
|
||||
$list = PluginFinanceOrders::where($where)->with(['site' => function ($query) {
|
||||
$query->field('id,title,logo,domain,ip')->hidden(['id']);
|
||||
}])
|
||||
->order('id desc')->paginate($limit)->scene('external')->each(function ($item) use ($config) {
|
||||
$item->state_text = OrdersState::get($item->state);
|
||||
$pay_type = PaymentChannels::get($item->pay_type);
|
||||
if ($pay_type) {
|
||||
$pay_type['icon'] = $config['url'] . $pay_type['icon'];
|
||||
$item->pay_type_text = $pay_type;
|
||||
}
|
||||
if (!empty($item->coupon)) {
|
||||
$coupon_ids = PluginMarketingCouponCode::whereIn('id', $item->coupon)->column('coupon_id');
|
||||
$item->coupon = PluginMarketingCoupon::whereIn('id', array_unique($coupon_ids))->column('title');
|
||||
}
|
||||
});
|
||||
return $this->resData($list);
|
||||
}
|
||||
public function details(Request $request)
|
||||
{
|
||||
$trade_no = $request->get('trade_no');
|
||||
$order = PluginFinanceOrders::where('trade_no', $trade_no)->find()->scene('external');
|
||||
$order->state_text = OrdersState::get($order->state);
|
||||
return $this->resData($order);
|
||||
}
|
||||
public function OrdersStateEnum(Request $request)
|
||||
{
|
||||
$list = OrdersState::getOptions();
|
||||
return $this->resData($list);
|
||||
}
|
||||
public function cancel(Request $request)
|
||||
{
|
||||
$trade_no = $request->post('trade_no');
|
||||
$where = [
|
||||
['trade_no', '=', $trade_no],
|
||||
['uid', '=', $request->uid],
|
||||
['state', '=', OrdersState::WAIT_PAY['value']]
|
||||
];
|
||||
$order = PluginFinanceOrders::where($where)->find();
|
||||
if (!$order) {
|
||||
return $this->fail('订单不存在');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
PluginFinanceOrders::cancel($order);
|
||||
PluginFinanceOrdersLog::info($order, '用户订单取消');
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Log::error('User Orders Cancel Error:' . $th->getMessage(), $th->getTrace());
|
||||
return $this->fail('取消失败');
|
||||
}
|
||||
return $this->success('取消成功');
|
||||
}
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$trade_no = $request->post('trade_no');
|
||||
$where = [
|
||||
['trade_no', '=', $trade_no],
|
||||
['uid', '=', $request->uid],
|
||||
];
|
||||
$order = PluginFinanceOrders::where($where)->find();
|
||||
if (!$order) {
|
||||
return $this->fail('订单不存在');
|
||||
}
|
||||
if ($order->state == OrdersState::WAIT_PAY['value']) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
PluginFinanceOrders::cancel($order);
|
||||
PluginFinanceOrdersLog::info($order, '用户删除订单取消');
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Log::error('User Orders Delete Error:' . $th->getMessage(), $th->getTrace());
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
$order->delete();
|
||||
return $this->success('删除成功');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\app\api\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\enum\EventName;
|
||||
use app\expose\enum\PaymentChannels;
|
||||
use app\expose\enum\ResponseCode;
|
||||
use app\expose\helper\Payment;
|
||||
use app\model\PaymentConfig;
|
||||
use plugin\finance\app\model\PluginFinanceOrders;
|
||||
use plugin\finance\app\model\PluginFinanceOrdersLog;
|
||||
use plugin\finance\app\model\PluginFinanceWallet;
|
||||
use plugin\finance\utils\enum\OrdersState;
|
||||
use plugin\finance\utils\enum\OrdersType;
|
||||
use plugin\marketing\app\model\PluginMarketingPlan;
|
||||
use plugin\marketing\app\model\PluginMarketingPlanPrice;
|
||||
use plugin\marketing\app\model\PluginMarketingPoints;
|
||||
use support\Log;
|
||||
use support\Request;
|
||||
use think\facade\Db;
|
||||
use Webman\Event\Event;
|
||||
|
||||
class OrdersController extends Basic
|
||||
{
|
||||
public function payOrder(Request $request)
|
||||
{
|
||||
$data = $request->post();
|
||||
if (empty($data['trade_no'])) {
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
$order = PluginFinanceOrders::where(['trade_no' => $data['trade_no'], 'uid' => $request->uid])->find();
|
||||
if (!$order) {
|
||||
return $this->fail('订单不存在');
|
||||
}
|
||||
if ($order->state !== OrdersState::WAIT_PAY['value']) {
|
||||
return $this->fail('订单状态错误');
|
||||
}
|
||||
try {
|
||||
return $this->builderPay($request, $order);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
}
|
||||
public function create(Request $request)
|
||||
{
|
||||
$data = $request->post();
|
||||
if (empty($data['type'])) {
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
try {
|
||||
switch ($data['type']) {
|
||||
case OrdersType::POINTS['value']:
|
||||
$order = $this->createPoints($request);
|
||||
break;
|
||||
case OrdersType::VIP['value']:
|
||||
$order = $this->createVip($request);
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('订单类型错误');
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
Event::emit(EventName::ORDERS_CREATE['value'], $order);
|
||||
try {
|
||||
return $this->builderPay($request, $order);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
}
|
||||
private function builderPay(Request $request, PluginFinanceOrders $order)
|
||||
{
|
||||
if ($order->state === OrdersState::PAID['value']) {
|
||||
try {
|
||||
PluginFinanceOrders::finish(['trade_no' => $order->trade_no]);
|
||||
} catch (\Throwable $th) {
|
||||
PluginFinanceOrdersLog::fail($order, $th->getMessage());
|
||||
Log::error("订单完成失败:{$order->trade_no},{$th->getMessage()},{$th->getFile()}:{$th->getLine()}", $th->getTrace());
|
||||
throw $th;
|
||||
}
|
||||
return $this->code(ResponseCode::PAY_SUCCESS, '支付成功');
|
||||
} else {
|
||||
$data = $request->post();
|
||||
if (empty($data['payment_id'])) {
|
||||
throw new \Exception('支付方式不存在');
|
||||
}
|
||||
$PaymentConfig = PaymentConfig::where(['id' => $data['payment_id']])->find();
|
||||
if (!$PaymentConfig) {
|
||||
throw new \Exception('支付方式不存在');
|
||||
}
|
||||
$order->plugin = 'finance';
|
||||
$order->trade = $order->trade_no;
|
||||
$order->price = $order->money;
|
||||
switch ($PaymentConfig->channels) {
|
||||
case PaymentChannels::WXPAY['value']:
|
||||
$result = Payment::wxPay($order, $PaymentConfig);
|
||||
$orderInfo = [
|
||||
'platform' => $PaymentConfig->platform,
|
||||
'title' => $order->title,
|
||||
'pay_info' => $result,
|
||||
'trade_no' => $order->trade_no,
|
||||
'origin_money' => $order->origin_money,
|
||||
'expire_time' => $order->expire_time,
|
||||
'money' => $order->money
|
||||
];
|
||||
return $this->resData($orderInfo);
|
||||
case PaymentChannels::ALIPAY['value']:
|
||||
break;
|
||||
case PaymentChannels::INTEGRAL['value']:
|
||||
break;
|
||||
case PaymentChannels::BALANCE['value']:
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = PluginFinanceOrders::where(['id' => $order->id])->find();
|
||||
if (!$order) {
|
||||
throw new \Exception('订单不存在');
|
||||
}
|
||||
$order->state = OrdersState::PAID['value'];
|
||||
$order->pay_type = PaymentChannels::BALANCE['value'];
|
||||
$order->pay_time = date('Y-m-d H:i:s');
|
||||
$order->save();
|
||||
PluginFinanceWallet::consume($order);
|
||||
PluginFinanceOrdersLog::info($order, '余额支付成功');
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
PluginFinanceOrdersLog::fail($order, $th->getMessage());
|
||||
throw $th;
|
||||
}
|
||||
Event::emit(EventName::ORDERS_PAY['value'], [
|
||||
'data' => $order,
|
||||
'payment_channel' => PaymentChannels::BALANCE['value'],
|
||||
'plugin' => 'finance',
|
||||
'template_id' => $PaymentConfig->template_id
|
||||
]);
|
||||
return $this->builderPay($request, $order);
|
||||
default:
|
||||
throw new \Exception('未知支付方式');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function createVip(Request $request){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data = $request->post();
|
||||
$vipInfoPrice = PluginMarketingPlanPrice::where(['id' => $data['id']])->find();
|
||||
if (!$vipInfoPrice) {
|
||||
throw new \Exception('会员套餐不存在');
|
||||
}
|
||||
$vipInfo = PluginMarketingPlan::where(['id' => $vipInfoPrice->plan_id])->find();
|
||||
if (!$vipInfo) {
|
||||
throw new \Exception('会员套餐不存在');
|
||||
}
|
||||
$order = new PluginFinanceOrders;
|
||||
$order->uid = $request->uid;
|
||||
$order->alias_id = $vipInfoPrice->id;
|
||||
$order->title = '购买会员:' . $vipInfo->name;
|
||||
$order->origin_money = $vipInfoPrice->price;
|
||||
$order->unit_money = $vipInfoPrice->price;
|
||||
$order->money = $vipInfoPrice->price;
|
||||
$order->num = 1;
|
||||
$order->pay_type = $data['pay_type'];
|
||||
$order->state = OrdersState::WAIT_PAY['value'];
|
||||
$order->type = OrdersType::VIP['value'];
|
||||
$order->channels_uid = $request->channels_uid;
|
||||
$order->plugin = 'finance';
|
||||
$order->expire_time = date('Y-m-d H:i:s', strtotime('+15 minutes'));
|
||||
$order->save();
|
||||
PluginFinanceOrdersLog::info($order, '创建订单');
|
||||
Db::commit();
|
||||
return $order;
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
private function createPoints(Request $request)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data = $request->post();
|
||||
$pointsInfo = PluginMarketingPoints::where(['id' => $data['id'], 'channels_uid' => $request->channels_uid])->find();
|
||||
if (!$pointsInfo) {
|
||||
throw new \Exception('积分套餐不存在');
|
||||
}
|
||||
$order = new PluginFinanceOrders;
|
||||
$order->uid = $request->uid;
|
||||
$order->alias_id = $pointsInfo->id;
|
||||
$order->title = '购买套餐:' . $pointsInfo->name;
|
||||
$order->origin_money = $pointsInfo->price;
|
||||
$order->unit_money = $pointsInfo->price;
|
||||
$order->money = $pointsInfo->price;
|
||||
$order->num = 1;
|
||||
$order->pay_type = $data['pay_type'];
|
||||
$order->state = OrdersState::WAIT_PAY['value'];
|
||||
$order->type = OrdersType::POINTS['value'];
|
||||
$order->channels_uid = $request->channels_uid;
|
||||
$order->plugin = 'finance';
|
||||
$order->expire_time = date('Y-m-d H:i:s', strtotime('+15 minutes'));
|
||||
$order->save();
|
||||
PluginFinanceOrdersLog::info($order, '创建订单');
|
||||
Db::commit();
|
||||
return $order;
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
private function createMoney(Request $request)
|
||||
{
|
||||
$data = $request->post();
|
||||
Db::startTrans();
|
||||
try {
|
||||
//组装订单数据
|
||||
$order = new PluginFinanceOrders;
|
||||
$order->uid = $request->uid;
|
||||
$order->money = (int)$data['num']; //原价 未实现优惠券逻辑
|
||||
if ($order->money < 1) {
|
||||
throw new \Exception('充值金额不能小于1元');
|
||||
}
|
||||
$order->origin_money = $order->money;
|
||||
$order->title = '充值金额:' . $order->money . '元';
|
||||
$order->state = OrdersState::WAIT_PAY['value'];
|
||||
$order['type'] = $data['type'];
|
||||
$order->save();
|
||||
PluginFinanceOrdersLog::info($order->id, '创建订单');
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看订单状态 是否支付
|
||||
* @Author: 贵州猿创科技有限公司
|
||||
* @Date: 2023-05-20
|
||||
*/
|
||||
public function state(Request $request)
|
||||
{
|
||||
$trade_no = $request->get('trade_no');
|
||||
if (!$trade_no) {
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
$info = PluginFinanceOrders::where(['trade_no' => $trade_no, 'uid' => $request->uid])->find();
|
||||
if (!$info) {
|
||||
return $this->fail('订单不存在');
|
||||
}
|
||||
switch ($info->state) {
|
||||
case OrdersState::WAIT_PAY['value']:
|
||||
return $this->code(ResponseCode::WAIT, '支付中');
|
||||
case OrdersState::PAID['value']:
|
||||
case OrdersState::FINISH['value']:
|
||||
return $this->code(ResponseCode::PAY_SUCCESS, '支付成功');
|
||||
case OrdersState::REFUND_ING['value']:
|
||||
case OrdersState::REFUND_SUCCESS['value']:
|
||||
case OrdersState::REFUND_FAIL['value']:
|
||||
return $this->fail('订单已退款或退款中');
|
||||
case OrdersState::INVALID['value']:
|
||||
return $this->fail('订单已作废');
|
||||
case OrdersState::NOTIFY_FAIL['value']:
|
||||
return $this->fail('订单通知失败');
|
||||
case OrdersState::CANCEL['value']:
|
||||
return $this->fail('订单已取消');
|
||||
default:
|
||||
return $this->fail('订单状态错误');
|
||||
}
|
||||
}
|
||||
public function cancel(Request $request)
|
||||
{
|
||||
$trade_no = $request->get('trade_no');
|
||||
if (!$trade_no) {
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
try {
|
||||
PluginFinanceOrders::cancel(['trade_no' => $trade_no, 'uid' => $request->uid]);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->fail($th->getMessage());
|
||||
}
|
||||
return $this->success('取消成功');
|
||||
}
|
||||
|
||||
public function getOrderStatus(Request $request)
|
||||
{
|
||||
$trade_no = $request->get('trade');
|
||||
if (!$trade_no) {
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
$order = PluginFinanceOrders::where(['trade_no' => $trade_no, 'uid' => $request->uid])->find();
|
||||
if (!$order) {
|
||||
return $this->fail('订单不存在');
|
||||
}
|
||||
return $this->resData(['status' => in_array($order->state, [OrdersState::PAID['value'], OrdersState::FINISH['value']])]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\app\api\controller;
|
||||
|
||||
use app\Basic;
|
||||
use plugin\finance\app\model\PluginFinanceWallet;
|
||||
use support\Request;
|
||||
|
||||
class UserController extends Basic
|
||||
{
|
||||
public function wallet(Request $request)
|
||||
{
|
||||
$uid = $request->uid;
|
||||
$PluginFinanceWallet = PluginFinanceWallet::where('uid', $uid)->find();
|
||||
if (!$PluginFinanceWallet) {
|
||||
$PluginFinanceWallet = new PluginFinanceWallet();
|
||||
$PluginFinanceWallet->uid = $uid;
|
||||
$PluginFinanceWallet->save();
|
||||
}
|
||||
return $this->resData($PluginFinanceWallet->hidden(['uid']));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,439 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\app\control\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\build\builder\DataboardBuilder;
|
||||
use app\expose\build\builder\databoardBuilder\component\Echarts;
|
||||
use app\expose\build\builder\databoardBuilder\component\Statistic;
|
||||
use app\expose\build\builder\FormBuilder;
|
||||
use app\expose\build\builder\TableBuilder;
|
||||
use app\expose\enum\Action;
|
||||
use app\expose\enum\State;
|
||||
use app\expose\enum\Week;
|
||||
use plugin\finance\app\model\PluginFinanceOrders;
|
||||
use plugin\finance\utils\enum\OrdersState;
|
||||
use support\Cache;
|
||||
use support\Request;
|
||||
|
||||
class IndexController extends Basic
|
||||
{
|
||||
public function indexGetTable(Request $request)
|
||||
{
|
||||
$builder = new TableBuilder();
|
||||
$builder->addAction('操作', [
|
||||
'width' => '200px',
|
||||
'fixed' => 'right'
|
||||
]);
|
||||
$builder->addTableAction('编辑', [
|
||||
'path' => 'Control/update',
|
||||
'props' => [
|
||||
'type' => 'primary',
|
||||
'title' => '编辑《{nickname}》管理员'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'primary',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->addTableAction('删除', [
|
||||
'model' => Action::COMFIRM['value'],
|
||||
'path' => 'Control/delete',
|
||||
'where' => [
|
||||
['is_system', '!=', 1]
|
||||
],
|
||||
'props' => [
|
||||
'type' => 'error',
|
||||
'message' => '确定要删除《{nickname}》管理员吗?',
|
||||
'confirmButtonClass' => 'el-button--danger'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'danger',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->addHeader();
|
||||
$builder->addHeaderAction('创建管理员', [
|
||||
'path' => 'Control/create',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'title' => '创建管理员'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$formBuilder = new FormBuilder();
|
||||
$formBuilder->add('username', '账号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '账号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('mobile', '手机号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '手机号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$builder->addScreen($formBuilder);
|
||||
$builder->add('id', 'ID', [
|
||||
'props' => [
|
||||
'width' => '80px'
|
||||
]
|
||||
]);
|
||||
$builder->add('userinfo', '管理员', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'nickname',
|
||||
'avatar' => 'headimg',
|
||||
'info' => 'username',
|
||||
'nicknameTags' => [
|
||||
[
|
||||
'field' => 'new_text',
|
||||
'props' => [
|
||||
'type' => 'danger',
|
||||
'size' => 'small'
|
||||
]
|
||||
],
|
||||
[
|
||||
'field' => 'new_text1',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
],
|
||||
'tags' => [
|
||||
[
|
||||
'field' => 'role_name',
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'minWidth' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('contact', '联系方式', [
|
||||
'props' => [
|
||||
'width' => '280px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'mobile',
|
||||
'label' => '手机号'
|
||||
],
|
||||
[
|
||||
'field' => 'email',
|
||||
'label' => '邮箱'
|
||||
],
|
||||
[
|
||||
'field' => 'wx_openid',
|
||||
'label' => 'OpenID'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('allow_week', '工作日', [
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => Week::getOptions()
|
||||
],
|
||||
'props' => [
|
||||
'width' => '240px'
|
||||
]
|
||||
]);
|
||||
$builder->add('allow_work', '工作时间', [
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => [
|
||||
[
|
||||
'index' => 0,
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
],
|
||||
[
|
||||
'index' => 1,
|
||||
'props' => [
|
||||
'type' => 'danger'
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]);
|
||||
$builder->add('online_time', '活动', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'online_time',
|
||||
'label' => '在线'
|
||||
],
|
||||
[
|
||||
'field' => 'login_time',
|
||||
'label' => '登录'
|
||||
],
|
||||
[
|
||||
'component' => 'tag',
|
||||
'field' => 'login_ip',
|
||||
'label' => '登录IP',
|
||||
'props' => [
|
||||
'size' => 'small',
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('state', '状态', [
|
||||
'component' => [
|
||||
'name' => 'switch',
|
||||
'api' => 'Control/indexUpdateState',
|
||||
'props' => [
|
||||
'active-value' => State::YES['value'],
|
||||
'inactive-value' => State::NO['value']
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('create_time', '时间', [
|
||||
'props' => [
|
||||
'width' => '200px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'create_time',
|
||||
'label' => '创建'
|
||||
],
|
||||
[
|
||||
'field' => 'update_time',
|
||||
'label' => '更新'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder = $builder->builder();
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$builder = new DataboardBuilder([
|
||||
'gutter' => 6
|
||||
]);
|
||||
|
||||
// 今日支付订单数
|
||||
$today = PluginFinanceOrders::where(['channels_uid' => $request->channels_uid])->whereIn('state', [OrdersState::PAID['value'], OrdersState::FINISH['value']])->whereDay('create_time')->count();
|
||||
$yesterday = PluginFinanceOrders::where(['channels_uid' => $request->channels_uid])->whereIn('state', [OrdersState::PAID['value'], OrdersState::FINISH['value']])->whereDay('create_time', 'yesterday')->count();
|
||||
$statistic = new Statistic;
|
||||
$statistic->setLabel('今日支付订单数')
|
||||
->setUnit('笔')
|
||||
->setData([
|
||||
'today' => $today,
|
||||
'yesterday' => $yesterday,
|
||||
'growth_rate' => $yesterday ? round(($today - $yesterday) / $yesterday * 100, 2) : 0
|
||||
])
|
||||
->setClass('p-6');
|
||||
$builder->add($statistic, [
|
||||
'xs' => 24,
|
||||
'sm' => 12,
|
||||
'md' => 6,
|
||||
'lg' => 4,
|
||||
'class' => 'bg-white p-4 rounded-4 shadow-lighter'
|
||||
]);
|
||||
|
||||
// 今日支付金额
|
||||
$today = PluginFinanceOrders::where(['channels_uid' => $request->channels_uid])->whereIn('state', [OrdersState::PAID['value'], OrdersState::FINISH['value']])->whereDay('create_time')->sum('money');
|
||||
$yesterday = PluginFinanceOrders::where(['channels_uid' => $request->channels_uid])->whereIn('state', [OrdersState::PAID['value'], OrdersState::FINISH['value']])->whereDay('create_time', 'yesterday')->sum('money');
|
||||
$statistic = new Statistic;
|
||||
$statistic->setLabel('今日支付金额')
|
||||
->setUnit('元')
|
||||
->setData([
|
||||
'today' => $today,
|
||||
'yesterday' => $yesterday,
|
||||
'growth_rate' => $yesterday ? round(($today - $yesterday) / $yesterday * 100, 2) : 0
|
||||
])
|
||||
->setClass('p-6');
|
||||
$builder->add($statistic, [
|
||||
'xs' => 24,
|
||||
'sm' => 12,
|
||||
'md' => 6,
|
||||
'lg' => 4,
|
||||
'class' => 'bg-white p-4 rounded-4 shadow-lighter'
|
||||
]);
|
||||
|
||||
// 总订单数
|
||||
$total = PluginFinanceOrders::where(['channels_uid' => $request->channels_uid])->whereIn('state', [OrdersState::PAID['value'], OrdersState::FINISH['value']])->count();
|
||||
$lastMonthTotal = PluginFinanceOrders::where(['channels_uid' => $request->channels_uid])->whereIn('state', [OrdersState::PAID['value'], OrdersState::FINISH['value']])->whereMonth('create_time', '-1 month')->count();
|
||||
$statistic = new Statistic;
|
||||
$statistic->setLabel('总订单数')
|
||||
->setUnit('笔')
|
||||
->setData([
|
||||
'today' => $total,
|
||||
'yesterday' => $lastMonthTotal,
|
||||
'growth_rate' => $lastMonthTotal ? round(($total - $lastMonthTotal) / $lastMonthTotal * 100, 2) : 0
|
||||
])
|
||||
->setClass('p-6');
|
||||
$builder->add($statistic, [
|
||||
'xs' => 24,
|
||||
'sm' => 12,
|
||||
'md' => 6,
|
||||
'lg' => 4,
|
||||
'class' => 'bg-white p-4 rounded-4 shadow-lighter'
|
||||
]);
|
||||
|
||||
// 当月订单数
|
||||
$month = PluginFinanceOrders::where(['channels_uid' => $request->channels_uid])->whereIn('state', [OrdersState::PAID['value'], OrdersState::FINISH['value']])->whereMonth('create_time')->count();
|
||||
$lastMonth = PluginFinanceOrders::where(['channels_uid' => $request->channels_uid])->whereIn('state', [OrdersState::PAID['value'], OrdersState::FINISH['value']])->whereMonth('create_time', '-1 month')->count();
|
||||
$statistic = new Statistic;
|
||||
$statistic->setLabel('当月订单数')
|
||||
->setUnit('笔')
|
||||
->setData([
|
||||
'today' => $month,
|
||||
'yesterday' => $lastMonth,
|
||||
'growth_rate' => $lastMonth ? round(($month - $lastMonth) / $lastMonth * 100, 2) : 0
|
||||
])
|
||||
->setClass('p-6');
|
||||
$builder->add($statistic, [
|
||||
'xs' => 24,
|
||||
'sm' => 12,
|
||||
'md' => 6,
|
||||
'lg' => 4,
|
||||
'class' => 'bg-white p-4 rounded-4 shadow-lighter'
|
||||
]);
|
||||
|
||||
// 添加图表
|
||||
$this->echarts($builder, $request);
|
||||
|
||||
return $this->resData($builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加图表组件
|
||||
* @param DataboardBuilder $builder
|
||||
* @param Request $request
|
||||
*/
|
||||
private function echarts(DataboardBuilder $builder, Request $request)
|
||||
{
|
||||
$endTime = strtotime('23:59:59', time()) - time();
|
||||
$echarts = new Echarts;
|
||||
$echarts->setClass('bg-white p-4 rounded-4 shadow-lighter vh-65');
|
||||
$EchartsData = Cache::get('finance_echarts_data_' . $request->channels_uid);
|
||||
if (!$EchartsData) {
|
||||
$EchartsData = $this->getEchartsData($request);
|
||||
Cache::set('finance_echarts_data_' . $request->channels_uid, $EchartsData, $endTime);
|
||||
}
|
||||
$echarts->setData($EchartsData);
|
||||
$builder->add($echarts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图表数据
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
private function getEchartsData(Request $request)
|
||||
{
|
||||
$data = [
|
||||
'color' => ['#80FFA5', '#00DDFF', '#37A2FF', '#FF0087', '#FFBF00'],
|
||||
'title' => [
|
||||
'text' => '订单数据可视化'
|
||||
],
|
||||
'tooltip' => [
|
||||
'trigger' => 'axis',
|
||||
'axisPointer' => [
|
||||
'type' => 'cross',
|
||||
'label' => [
|
||||
'backgroundColor' => '#6a7985'
|
||||
]
|
||||
]
|
||||
],
|
||||
'legend' => [
|
||||
'data' => ["订单数", "支付金额"]
|
||||
],
|
||||
'toolbox' => [
|
||||
'show' => false
|
||||
],
|
||||
'grid' => [
|
||||
'left' => '3%',
|
||||
'right' => '4%',
|
||||
'bottom' => '3%',
|
||||
'containLabel' => true
|
||||
],
|
||||
'xAxis' => [
|
||||
[
|
||||
'type' => 'category',
|
||||
'boundaryGap' => false,
|
||||
'data' => []
|
||||
]
|
||||
],
|
||||
'yAxis' => [
|
||||
[
|
||||
'type' => 'value'
|
||||
]
|
||||
],
|
||||
'series' => [
|
||||
[
|
||||
'name' => "订单数",
|
||||
'type' => 'line',
|
||||
'smooth' => true,
|
||||
'data' => []
|
||||
],
|
||||
[
|
||||
'name' => "支付金额",
|
||||
'type' => 'line',
|
||||
'smooth' => true,
|
||||
'data' => []
|
||||
]
|
||||
]
|
||||
];
|
||||
for ($i = 7; $i > 0; $i--) {
|
||||
$date = date('Y-m-d', strtotime("-$i day"));
|
||||
$data['xAxis'][0]['data'][] = $date;
|
||||
$Order = PluginFinanceOrders::where(['channels_uid' => $request->channels_uid])->whereIn('state', [OrdersState::PAID['value'], OrdersState::FINISH['value']])->whereDay('create_time', $date)->count();
|
||||
if ($Order) {
|
||||
$data['series'][0]['data'][] = $Order;
|
||||
} else {
|
||||
$data['series'][0]['data'][] = 0;
|
||||
}
|
||||
$Payment = PluginFinanceOrders::where(['channels_uid' => $request->channels_uid])->whereIn('state', [OrdersState::PAID['value'], OrdersState::FINISH['value']])->whereDay('create_time', $date)->sum('money');
|
||||
if ($Payment) {
|
||||
$data['series'][1]['data'][] = $Payment;
|
||||
} else {
|
||||
$data['series'][1]['data'][] = 0;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,686 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\app\control\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\build\builder\ComponentBuilder;
|
||||
use app\expose\build\builder\FormBuilder;
|
||||
use app\expose\build\builder\TableBuilder;
|
||||
use app\expose\enum\Action;
|
||||
use app\expose\enum\EventName;
|
||||
use app\expose\enum\PaymentChannels;
|
||||
use app\expose\enum\PaymentCurrency;
|
||||
use app\expose\enum\State;
|
||||
use app\model\PaymentTemplate;
|
||||
use plugin\apps\app\model\PluginAppsPrice;
|
||||
use plugin\apps\app\model\PluginAppsSpecifications;
|
||||
use plugin\apps\utils\enum\PaymentMethod;
|
||||
use plugin\finance\app\model\PluginFinanceOrders;
|
||||
use plugin\finance\app\model\PluginFinanceOrdersLog;
|
||||
use plugin\finance\app\model\PluginFinanceWallet;
|
||||
use plugin\finance\utils\enum\OrdersState;
|
||||
use plugin\finance\utils\enum\OrdersType;
|
||||
use plugin\marketing\app\model\PluginMarketingCoupon;
|
||||
use plugin\marketing\app\model\PluginMarketingCouponCode;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use support\Log;
|
||||
use support\Request;
|
||||
use think\facade\Db;
|
||||
use Webman\Event\Event;
|
||||
|
||||
class OrdersController extends Basic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new PluginFinanceOrders();
|
||||
}
|
||||
public function indexGetTable(Request $request)
|
||||
{
|
||||
$builder = new TableBuilder();
|
||||
$builder->addAction('操作', [
|
||||
'width' => '160px',
|
||||
'fixed' => 'right'
|
||||
]);
|
||||
$builder->addTableAction('完成', [
|
||||
'model' => Action::COMFIRM['value'],
|
||||
'path' => '/app/finance/control/Orders/finish',
|
||||
'props' => [
|
||||
'title' => '完成《{title}》订单'
|
||||
],
|
||||
'where' => [
|
||||
['state', '=', OrdersState::PAID['value']]
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->addTableAction('实收', [
|
||||
'model' => Action::DIALOG['value'],
|
||||
'path' => '/app/finance/control/Orders/real_money',
|
||||
'props' => [
|
||||
'title' => '实收《{title}》订单'
|
||||
],
|
||||
'where' => [
|
||||
['state', '=', OrdersState::WAIT_PAY['value']]
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'primary',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->addTableAction('收付', [
|
||||
'model' => Action::DIALOG['value'],
|
||||
'path' => '/app/finance/control/Orders/receipt_money',
|
||||
'props' => [
|
||||
'title' => '确认已收到《{title}》订单对公转账'
|
||||
],
|
||||
'where' => [
|
||||
['state', '=', OrdersState::WAIT_VERIFIED['value']]
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'primary',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$formBuilder = new FormBuilder(null, null, [
|
||||
'inline' => true
|
||||
]);
|
||||
$formBuilder->add('title', '订单标题', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '订单标题搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('trade_no', '订单号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '订单号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('state', '状态', 'select', null, [
|
||||
'options' => OrdersState::getOptions(),
|
||||
'props' => [
|
||||
'placeholder' => '状态搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('type', '订单类型', 'select', null, [
|
||||
'options' => OrdersType::getOptions(),
|
||||
'props' => [
|
||||
'placeholder' => '订单类型搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('uid', '用户', 'select', null, [
|
||||
'options' => [],
|
||||
'remote' => [
|
||||
'url' => '/app/finance/control/Orders/queryUser',
|
||||
],
|
||||
'props' => [
|
||||
'placeholder' => '用户搜索',
|
||||
'clearable' => true,
|
||||
'filterable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('user_id', '用户ID', 'input', null, [
|
||||
'options' => [],
|
||||
'props' => [
|
||||
'placeholder' => '用户搜索',
|
||||
]
|
||||
]);
|
||||
$builder->addScreen($formBuilder);
|
||||
$builder->add('id', 'ID', [
|
||||
'props' => [
|
||||
'width' => '80px'
|
||||
]
|
||||
]);
|
||||
$builder->add('order', '订单', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'title',
|
||||
'info' => 'trade_no',
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'minWidth' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('user', '用户', [
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'user.nickname',
|
||||
'avatar' => 'user.headimg',
|
||||
'info' => 'user.mobile',
|
||||
'tags' => [
|
||||
[
|
||||
'field' => 'uid',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'minWidth' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('state', '状态', [
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => OrdersState::getOptions()
|
||||
],
|
||||
'props' => [
|
||||
'width' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('type', '订单类型', [
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
'options' => OrdersType::getOptions()
|
||||
],
|
||||
'props' => [
|
||||
'width' => '140px'
|
||||
]
|
||||
]);
|
||||
$builder->add('statistic', '数据', [
|
||||
'component' => [
|
||||
'name' => 'statistic',
|
||||
'options' => [
|
||||
[
|
||||
'label' => '原价',
|
||||
'value' => 'origin_money'
|
||||
],
|
||||
[
|
||||
'label' => '实付',
|
||||
'value' => 'money'
|
||||
],
|
||||
[
|
||||
'label' => '数量',
|
||||
'value' => 'num'
|
||||
]
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'minWidth' => '380px'
|
||||
]
|
||||
]);
|
||||
$builder->add('coupon', '优惠券', [
|
||||
'component' => [
|
||||
'name' => 'tag',
|
||||
],
|
||||
'props' => [
|
||||
'minWidth' => '300px'
|
||||
]
|
||||
]);
|
||||
$builder->add('create_time', '时间', [
|
||||
'props' => [
|
||||
'width' => '220px'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-times',
|
||||
'props' => [
|
||||
'group' => [
|
||||
[
|
||||
'field' => 'create_time',
|
||||
'label' => '创建'
|
||||
],
|
||||
[
|
||||
'field' => 'update_time',
|
||||
'label' => '更新'
|
||||
],
|
||||
[
|
||||
'field' => 'pay_time',
|
||||
'label' => '支付'
|
||||
],
|
||||
[
|
||||
'field' => 'expire_time',
|
||||
'label' => '过期'
|
||||
],
|
||||
[
|
||||
'field' => 'finish_time',
|
||||
'label' => '完成'
|
||||
],
|
||||
[
|
||||
'field' => 'comment_time',
|
||||
'label' => '评价'
|
||||
],
|
||||
[
|
||||
'field' => 'cancel_time',
|
||||
'label' => '取消'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder = $builder->builder();
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function queryUser(Request $request)
|
||||
{
|
||||
$query = $request->post('query');
|
||||
if (empty($query)) {
|
||||
return $this->resData([]);
|
||||
}
|
||||
$where = [];
|
||||
$where[] = ['nickname|mobile', 'like', "%{$query}%"];
|
||||
$where[] = ['channels_uid', '=', $request->channels_uid];
|
||||
return $this->resData(PluginUser::options($where));
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
$where = [];
|
||||
$where[] = ['channels_uid', '=', $request->channels_uid];
|
||||
$title = $request->get('title');
|
||||
if ($title) {
|
||||
$where[] = ['title', 'like', "%{$title}%"];
|
||||
}
|
||||
$trade_no = $request->get('trade_no');
|
||||
if ($trade_no) {
|
||||
$where[] = ['trade_no', '=', $trade_no];
|
||||
}
|
||||
$state = $request->get('state');
|
||||
if ($state !== null) {
|
||||
$where[] = ['state', '=', $state];
|
||||
}
|
||||
$type = $request->get('type');
|
||||
if ($type !== null) {
|
||||
$where[] = ['type', '=', $type];
|
||||
}
|
||||
$uid = $request->get('uid');
|
||||
if ($uid) {
|
||||
$where[] = ['uid', '=', $uid];
|
||||
}
|
||||
$user_id = $request->get('user_id');
|
||||
if ($user_id) {
|
||||
$where[] = ['uid', '=', $user_id];
|
||||
}
|
||||
$list = PluginFinanceOrders::where($where)
|
||||
->with(['user' => function ($query) {
|
||||
$query->field('id,nickname,headimg,mobile,channels_uid');
|
||||
}])
|
||||
->order('id desc')->paginate($limit)->each(function ($item) {});
|
||||
return $this->resData($list);
|
||||
}
|
||||
public function finish(Request $request)
|
||||
{
|
||||
$id = $request->post('id');
|
||||
try {
|
||||
PluginFinanceOrders::finish(['id' => $id, 'channels_uid' => $request->channels_uid]);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->exception($th);
|
||||
}
|
||||
return $this->success('完成订单成功');
|
||||
}
|
||||
public function real_money(Request $request)
|
||||
{
|
||||
if ($request->method() == 'POST') {
|
||||
$id = $request->post('id');
|
||||
$order = PluginFinanceOrders::where(['id' => $id, 'channels_uid' => $request->channels_uid])->find();
|
||||
if (!$order) {
|
||||
return $this->fail('订单不存在');
|
||||
}
|
||||
if ($order->state != OrdersState::WAIT_PAY['value']) {
|
||||
return $this->fail('订单状态不是待支付');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order->state = OrdersState::PAID['value'];
|
||||
$order->pay_type = PaymentChannels::ADMIN['value'];
|
||||
$order->pay_time = date('Y-m-d H:i:s');
|
||||
$order->system_money = $request->post('system_money');
|
||||
$order->money = $order->origin_money - $order->system_money - $order->channels_money - $order->developer_money;
|
||||
$order->save();
|
||||
PluginFinanceOrdersLog::info($order, '管理员操作实收成功');
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
PluginFinanceOrdersLog::fail($order, $th->getMessage());
|
||||
return $this->exception($th);
|
||||
}
|
||||
Event::emit(EventName::ORDERS_PAY['value'], [
|
||||
'data' => $order,
|
||||
'payment_channel' => PaymentChannels::ADMIN['value'],
|
||||
'plugin' => 'finance'
|
||||
]);
|
||||
try {
|
||||
PluginFinanceOrders::finish(['id' => $order->id, 'channels_uid' => $request->channels_uid]);
|
||||
} catch (\Throwable $th) {
|
||||
PluginFinanceOrdersLog::fail($order, $th->getMessage());
|
||||
Log::error("订单完成失败:{$order->trade_no},{$th->getMessage()},{$th->getFile()}:{$th->getLine()}", $th->getTrace());
|
||||
return $this->exception($th);
|
||||
}
|
||||
return $this->success('实收订单成功');
|
||||
}
|
||||
$id = $request->get('id');
|
||||
$order = PluginFinanceOrders::where(['id' => $id, 'channels_uid' => $request->channels_uid])->find();
|
||||
if (!$order) {
|
||||
return $this->fail('订单不存在');
|
||||
}
|
||||
if ($order->state != OrdersState::WAIT_PAY['value']) {
|
||||
return $this->fail('订单状态不是待支付');
|
||||
}
|
||||
$Component = new ComponentBuilder;
|
||||
$builder = new FormBuilder(null, null, [
|
||||
'translations' => true,
|
||||
'size' => 'large',
|
||||
]);
|
||||
$builder->add('title', '订单', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 12,
|
||||
'xl' => 12
|
||||
],
|
||||
]);
|
||||
$builder->add('trade_no', '订单号', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 12,
|
||||
'xl' => 12
|
||||
],
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]);
|
||||
$builder->add('create_time', '下单时间', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 12,
|
||||
'xl' => 12
|
||||
],
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]);
|
||||
$builder->add('expire_time', '过期时间', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 12,
|
||||
'xl' => 12
|
||||
],
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]);
|
||||
$builder->add('settle_accounts_time', '结算日期', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
]);
|
||||
$builder->add('num', '数量', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
]);
|
||||
$builder->add('origin_money', '原价', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
]);
|
||||
$builder->add('unit_money', '单价', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
]);
|
||||
$builder->add('money', '应付', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
'props' => [
|
||||
'type' => 'danger'
|
||||
]
|
||||
]);
|
||||
$maxSystemMoney = $order->money;
|
||||
$builder->add('system_money', '平台优惠金额', 'input-number', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
'required' => true,
|
||||
'props' => [
|
||||
'min' => 0,
|
||||
'max' => $maxSystemMoney,
|
||||
'step' => 0.01,
|
||||
'controls' => false
|
||||
],
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '最大可优惠金额:' . $maxSystemMoney . '元'], ['type' => 'danger', 'size' => 'small'])->builder(),
|
||||
],
|
||||
'children' => [
|
||||
'suffix' => [
|
||||
'component' => 'el-text',
|
||||
'props' => [
|
||||
'size' => 'small'
|
||||
],
|
||||
'children' => [
|
||||
'default' => '元'
|
||||
]
|
||||
],
|
||||
'prefix' => [
|
||||
'component' => 'el-text',
|
||||
'props' => [
|
||||
'size' => 'small'
|
||||
],
|
||||
'children' => [
|
||||
'default' => '¥'
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
$formula = 'money - system_money';
|
||||
$builder->add('real_money', '实收金额', 'compute', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '请确认财务已收到款项'], ['type' => 'info', 'size' => 'small'])->builder(),
|
||||
$Component->add('text', ['default' => '实收后订单状态将变为:'], ['type' => 'info', 'size' => 'small'])->add('tag', ['default' => OrdersState::FINISH['label']], ['type' => OrdersState::FINISH['props']['type'], 'size' => 'small'])->builder(),
|
||||
],
|
||||
'props' => [
|
||||
'formula' => $formula,
|
||||
'type' => 'danger',
|
||||
'size' => 'large',
|
||||
'tag' => 'b'
|
||||
]
|
||||
]);
|
||||
$builder->setData($order->toArray());
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function receipt_money(Request $request)
|
||||
{
|
||||
if ($request->method() == 'POST') {
|
||||
$id = $request->post('id');
|
||||
$order = PluginFinanceOrders::where(['id' => $id, 'channels_uid' => $request->channels_uid])->find();
|
||||
if (!$order) {
|
||||
return $this->fail('订单不存在');
|
||||
}
|
||||
if ($order->state != OrdersState::WAIT_VERIFIED['value']) {
|
||||
return $this->fail('订单状态不是待验证');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order->state = OrdersState::PAID['value'];
|
||||
$order->pay_type = PaymentChannels::ADMIN['value'];
|
||||
$order->pay_time = date('Y-m-d H:i:s');
|
||||
$order->save();
|
||||
PluginFinanceOrdersLog::info($order, '管理员确认对公转账成功');
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
PluginFinanceOrdersLog::fail($order, $th->getMessage());
|
||||
return $this->exception($th);
|
||||
}
|
||||
Event::emit(EventName::ORDERS_PAY['value'], [
|
||||
'data' => $order,
|
||||
'payment_channel' => PaymentChannels::ADMIN['value'],
|
||||
'plugin' => 'finance'
|
||||
]);
|
||||
try {
|
||||
PluginFinanceOrders::finish(['id' => $order->id, 'channels_uid' => $request->channels_uid]);
|
||||
} catch (\Throwable $th) {
|
||||
PluginFinanceOrdersLog::fail($order, $th->getMessage());
|
||||
Log::error("订单完成失败:{$order->trade_no},{$th->getMessage()},{$th->getFile()}:{$th->getLine()}", $th->getTrace());
|
||||
return $this->exception($th);
|
||||
}
|
||||
return $this->success('确认对公转账成功');
|
||||
}
|
||||
$id = $request->get('id');
|
||||
$order = PluginFinanceOrders::where(['id' => $id, 'channels_uid' => $request->channels_uid])->find();
|
||||
if (!$order) {
|
||||
return $this->fail('订单不存在');
|
||||
}
|
||||
if ($order->state != OrdersState::WAIT_VERIFIED['value']) {
|
||||
return $this->fail('订单状态不是待验证');
|
||||
}
|
||||
$Component = new ComponentBuilder;
|
||||
$builder = new FormBuilder(null, null, [
|
||||
'translations' => true,
|
||||
'size' => 'large',
|
||||
]);
|
||||
$builder->add('title', '订单', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 12,
|
||||
'xl' => 12
|
||||
],
|
||||
]);
|
||||
$builder->add('trade_no', '订单号', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 12,
|
||||
'xl' => 12
|
||||
],
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]);
|
||||
$builder->add('create_time', '下单时间', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 12,
|
||||
'xl' => 12
|
||||
],
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]);
|
||||
$builder->add('expire_time', '过期时间', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 12,
|
||||
'xl' => 12
|
||||
],
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]);
|
||||
$builder->add('num', '数量', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
]);
|
||||
$builder->add('origin_money', '原价', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
]);
|
||||
$builder->add('unit_money', '单价', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
]);
|
||||
$builder->add('money', '应付', 'text', null, [
|
||||
'col' => [
|
||||
'xs' => 24,
|
||||
'sm' => 24,
|
||||
'md' => 12,
|
||||
'lg' => 8,
|
||||
'xl' => 6
|
||||
],
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '请确认已收到该订单的对公转账款项'], ['type' => 'warning', 'size' => 'small'])->builder(),
|
||||
$Component->add('text', ['default' => '确认后订单状态将变为:'], ['type' => 'info', 'size' => 'small'])->add('tag', ['default' => OrdersState::FINISH['label']], ['type' => OrdersState::FINISH['props']['type'], 'size' => 'small'])->builder(),
|
||||
],
|
||||
'props' => [
|
||||
'type' => 'danger'
|
||||
]
|
||||
]);
|
||||
$builder->setData($order->toArray());
|
||||
return $this->resData($builder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\app\control\controller;
|
||||
|
||||
use app\Basic;
|
||||
use app\expose\build\builder\ActionBuilder;
|
||||
use app\expose\build\builder\ComponentBuilder;
|
||||
use app\expose\build\builder\FormBuilder;
|
||||
use app\expose\build\builder\TableBuilder;
|
||||
use app\expose\enum\Action;
|
||||
use app\expose\enum\State;
|
||||
use app\expose\helper\Uploads;
|
||||
use plugin\finance\app\model\PluginFinanceWallet;
|
||||
use plugin\finance\expose\helper\Account;
|
||||
use plugin\finance\utils\enum\BillScene;
|
||||
use plugin\finance\utils\enum\PointsBillScene;
|
||||
use plugin\finance\utils\enum\ValidityPeriod;
|
||||
use plugin\user\app\model\PluginUserPoints;
|
||||
use plugin\user\utils\enum\MoneyAction;
|
||||
use support\Request;
|
||||
|
||||
class WalletController extends Basic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new PluginFinanceWallet;
|
||||
}
|
||||
public function indexGetTable(Request $request)
|
||||
{
|
||||
$builder = new TableBuilder;
|
||||
$builder->addAction('操作', [
|
||||
'width' => '180px',
|
||||
'fixed' => 'right'
|
||||
]);
|
||||
$builder->addTableAction('余额', [
|
||||
'model' => Action::DIALOG['value'],
|
||||
'path' => '/app/finance/control/Wallet/recharge',
|
||||
'props' => [
|
||||
'title' => '余额操作《{nickname}》'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'primary',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->addTableAction('积分', [
|
||||
'model' => Action::DIALOG['value'],
|
||||
'path' => '/app/finance/control/Wallet/rechargePoints',
|
||||
'props' => [
|
||||
'title' => '积分操作《{nickname}》'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'info',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->addTableAction('临时积分', [
|
||||
'model' => Action::DIALOG['value'],
|
||||
'path' => '/app/finance/control/Wallet/rechargeTmpPoints',
|
||||
'props' => [
|
||||
'title' => '临时积分操作《{nickname}》'
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'button',
|
||||
'props' => [
|
||||
'type' => 'warning',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$formBuilder = new FormBuilder(null, null, [
|
||||
'inline' => true
|
||||
]);
|
||||
|
||||
$formBuilder->add('uid', 'UID', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => 'UID搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('mobile', '手机号', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '手机号搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$formBuilder->add('nickname', '昵称', 'input', '', [
|
||||
'props' => [
|
||||
'placeholder' => '昵称搜索',
|
||||
'clearable' => true
|
||||
]
|
||||
]);
|
||||
$builder->addScreen($formBuilder);
|
||||
$builder->add('id', 'ID', [
|
||||
'props' => [
|
||||
'width' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('user', '用户', [
|
||||
'where' => [
|
||||
['uid', '!=', null]
|
||||
],
|
||||
'component' => [
|
||||
'name' => 'table-userinfo',
|
||||
'props' => [
|
||||
'nickname' => 'nickname',
|
||||
'avatar' => 'headimg',
|
||||
'info' => 'mobile',
|
||||
'tags' => [
|
||||
[
|
||||
'field' => 'uid',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'size' => 'small'
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
],
|
||||
'props' => [
|
||||
'width' => '240px'
|
||||
]
|
||||
]);
|
||||
$builder->add('points', '可用积分', [
|
||||
'props' => [
|
||||
'minWidth' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('points_sum', '累计积分', [
|
||||
'props' => [
|
||||
'minWidth' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('points_used', '累计支出积分', [
|
||||
'props' => [
|
||||
'minWidth' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('tmp_points', '临时积分', [
|
||||
'props' => [
|
||||
'minWidth' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('tmp_points_sum', '累计临时积分', [
|
||||
'props' => [
|
||||
'minWidth' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('tmp_points_used', '累计支出临时积分', [
|
||||
'props' => [
|
||||
'minWidth' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('balance', '可用余额', [
|
||||
'props' => [
|
||||
'minWidth' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('balance_sum', '累计余额', [
|
||||
'props' => [
|
||||
'minWidth' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder->add('balance_used', '累计支出余额', [
|
||||
'props' => [
|
||||
'minWidth' => '100px'
|
||||
]
|
||||
]);
|
||||
$builder = $builder->builder();
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
$where = [];
|
||||
$where[] = ['w.channels_uid', '=', $request->channels_uid];
|
||||
$nickname = $request->get('nickname');
|
||||
if ($nickname) {
|
||||
$where[] = ['u.nickname', 'like', "%{$nickname}%"];
|
||||
}
|
||||
$mobile = $request->get('mobile');
|
||||
if ($mobile) {
|
||||
$where[] = ['u.mobile', '=', $mobile];
|
||||
}
|
||||
$uid = $request->get('uid');
|
||||
if ($uid) {
|
||||
$where[] = ['w.uid', '=', $uid];
|
||||
}
|
||||
$list = PluginFinanceWallet::alias('w')
|
||||
->join('plugin_user u', ' u.id=w.uid ')
|
||||
->field('w.*,u.id,u.nickname,u.headimg,u.mobile')
|
||||
->where($where)
|
||||
->order('w.uid desc')
|
||||
->paginate($limit)
|
||||
->each(function ($item) {
|
||||
$item->headimg = Uploads::url($item->headimg);
|
||||
});
|
||||
return $this->resData($list);
|
||||
}
|
||||
|
||||
|
||||
public function recharge(Request $request)
|
||||
{
|
||||
if ($request->method() == 'POST') {
|
||||
$data = $request->post();
|
||||
Account::updateAccount($data['id'], $request->channels_uid, $data['number'], $data['action'], BillScene::ADMIN['value'], 0, $data['remarks'], $data['is_accumulate'] == 1);
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
$builder = new FormBuilder();
|
||||
|
||||
$builder->add('action', '操作', 'radio', MoneyAction::INCREASE['value'], [
|
||||
'options' => MoneyAction::getOptions()
|
||||
]);
|
||||
$Component = new ComponentBuilder;
|
||||
$builder->add('is_accumulate', '是否计入累计', 'switch', State::NO['value'], [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '是否计入累计,如退款时,不计入累计'], ['type' => 'info', 'size' => 'small'])->builder()
|
||||
],
|
||||
'props' => [
|
||||
'active-value' => State::YES['value'],
|
||||
'inactive-value' => State::NO['value']
|
||||
]
|
||||
]);
|
||||
$builder->add('number', '操作数量', 'input-number', 0, [
|
||||
'required' => true,
|
||||
'props' => [
|
||||
'controls' => false,
|
||||
'min' => 1,
|
||||
'step' => 1,
|
||||
'style' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('remarks', '备注', 'input', '', [
|
||||
'required' => true,
|
||||
]);
|
||||
return $this->resData($builder);
|
||||
}
|
||||
|
||||
public function rechargePoints(Request $request)
|
||||
{
|
||||
if ($request->method() == 'POST') {
|
||||
$data = $request->post();
|
||||
Account::updatePermanentPoints($data['id'], $request->channels_uid, $data['number'], PointsBillScene::ADMIN['value'], 0, $data['action'], $data['remarks'], $data['is_accumulate']);
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
$builder = new FormBuilder();
|
||||
$builder->add('action', '操作', 'radio', MoneyAction::INCREASE['value'], [
|
||||
'options' => MoneyAction::getOptions()
|
||||
]);
|
||||
|
||||
$Component = new ComponentBuilder;
|
||||
$builder->add('is_accumulate', '是否计入累计', 'switch', State::NO['value'], [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '是否计入累计,如退款时,不计入累计消费'], ['type' => 'info', 'size' => 'small'])->builder()
|
||||
],
|
||||
'props' => [
|
||||
'active-value' => State::YES['value'],
|
||||
'inactive-value' => State::NO['value']
|
||||
|
||||
]
|
||||
]);
|
||||
$builder->add('number', '操作数量', 'input-number', 0, [
|
||||
'required' => true,
|
||||
'props' => [
|
||||
'controls' => false,
|
||||
'min' => 1,
|
||||
'step' => 1,
|
||||
'style' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('remarks', '备注', 'input', '', [
|
||||
'required' => true,
|
||||
]);
|
||||
return $this->resData($builder);
|
||||
}
|
||||
public function rechargeTmpPoints(Request $request)
|
||||
{
|
||||
if ($request->method() == 'POST') {
|
||||
$data = $request->post();
|
||||
|
||||
if ($data['action'] == MoneyAction::INCREASE['value']) {
|
||||
Account::incPoints($data['id'], $request->channels_uid, $data['number'], PointsBillScene::ADMIN['value'], 0, $data['remarks'], $data['is_accumulate'], $data['valid_time']);
|
||||
} else {
|
||||
Account::decTemporaryPoints($data['id'], $request->channels_uid, $data['number'], PointsBillScene::ADMIN['value'], 0, $data['action'], $data['remarks'], $data['is_accumulate'], $data['point_id']);
|
||||
}
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
$list = PluginUserPoints::field('id as value,points as label, valid_time as tips')
|
||||
->where('channels_uid', $request->channels_uid)
|
||||
->where('uid', $request->get('id'))
|
||||
->where('points', '>', 0)
|
||||
->where('valid_time', '>=', date('Y-m-d H:i:s'))
|
||||
->where('extended_time', '>=', date('Y-m-d H:i:s'))
|
||||
->order('extended_time ASC, valid_time ASC')
|
||||
->select();
|
||||
$list = $list->map(function ($item) {
|
||||
return [
|
||||
'value' => $item['value'],
|
||||
'label' => '剩余积分' . $item['label'],
|
||||
'tips' => '有效期至:' . $item['tips']
|
||||
];
|
||||
});
|
||||
$builder = new FormBuilder();
|
||||
$builder->add('action', '操作', 'radio', MoneyAction::INCREASE['value'], [
|
||||
'options' => MoneyAction::getOptions()
|
||||
]);
|
||||
|
||||
$builder->add('point_id', '选择扣除对象', 'select', null, [
|
||||
'options' => $list,
|
||||
'required' => true,
|
||||
'where' => [
|
||||
['action', '=', MoneyAction::DECREASE['value']]
|
||||
]
|
||||
]);
|
||||
$Component = new ComponentBuilder;
|
||||
$builder->add('is_accumulate', '是否计入累计', 'switch', State::NO['value'], [
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '是否计入累计,如退款时,不计入累计消费'], ['type' => 'info', 'size' => 'small'])->builder()
|
||||
],
|
||||
'props' => [
|
||||
'active-value' => State::YES['value'],
|
||||
'inactive-value' => State::NO['value']
|
||||
]
|
||||
]);
|
||||
$builder->add('number', '操作数量', 'input-number', 0, [
|
||||
'required' => true,
|
||||
'props' => [
|
||||
'controls' => false,
|
||||
'min' => 1,
|
||||
'step' => 1,
|
||||
'style' => [
|
||||
'width' => '200px'
|
||||
]
|
||||
]
|
||||
]);
|
||||
$builder->add('valid_time', '有效期', 'date-picker', null, [
|
||||
'required' => true,
|
||||
'where' => [
|
||||
['action', '=', MoneyAction::INCREASE['value']]
|
||||
]
|
||||
]);
|
||||
$builder->add('remarks', '备注', 'input', '', [
|
||||
'required' => true,
|
||||
]);
|
||||
return $this->resData($builder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Here is your custom functions.
|
||||
*/
|
||||
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\app\model;
|
||||
|
||||
use app\expose\enum\EventName;
|
||||
use app\expose\enum\PaymentChannels;
|
||||
use plugin\control\expose\helper\Uploads;
|
||||
use app\expose\utils\Str;
|
||||
use app\model\Basic;
|
||||
use plugin\finance\expose\helper\Account;
|
||||
use plugin\finance\utils\enum\OrdersState;
|
||||
use plugin\finance\utils\enum\OrdersType;
|
||||
use plugin\finance\utils\enum\PointsBillScene;
|
||||
use plugin\marketing\app\model\PluginMarketingCoupon;
|
||||
use plugin\marketing\app\model\PluginMarketingCouponCode;
|
||||
use plugin\marketing\app\model\PluginMarketingPlan;
|
||||
use plugin\marketing\app\model\PluginMarketingPlanPrice;
|
||||
use plugin\marketing\app\model\PluginMarketingPoints;
|
||||
use plugin\marketing\utils\enum\UseState;
|
||||
use plugin\user\app\model\PluginUser;
|
||||
use plugin\user\app\model\PluginUserVip;
|
||||
use think\facade\Db;
|
||||
use think\model\concern\SoftDelete;
|
||||
use Webman\Event\Event;
|
||||
|
||||
class PluginFinanceOrders extends Basic
|
||||
{
|
||||
use SoftDelete;
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
'type' => [
|
||||
// 设置JSON字段的类型
|
||||
'origin_money' => 'float',
|
||||
'unit_money' => 'float',
|
||||
'money' => 'float',
|
||||
'system_money' => 'float',
|
||||
'channels_money' => 'float',
|
||||
'developer_money' => 'float',
|
||||
'coupon' => 'json'
|
||||
]
|
||||
];
|
||||
}
|
||||
public function getTransferVoucherImageAttr($value, $data)
|
||||
{
|
||||
return Uploads::url($data['channels_uid'], $value);
|
||||
}
|
||||
public function setTransferVoucherImageAttr($value, $data)
|
||||
{
|
||||
return Uploads::path($data['channels_uid'], $value);
|
||||
}
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(PluginUser::class, 'id', 'uid');
|
||||
}
|
||||
protected function sceneExternal()
|
||||
{
|
||||
return $this->visible(['title', 'create_time', 'update_time', 'trade_no', 'origin_money', 'money', 'num', 'pay_type', 'state', 'state_text', 'pay_time', 'type', 'cancel_time', 'expire_time', 'comment_time', 'coupon', 'apps', 'pay_type_text', 'user', 'site']);
|
||||
}
|
||||
public static function onBeforeInsert($model)
|
||||
{
|
||||
$model->trade_no = self::generateTradeNo();
|
||||
}
|
||||
public static function generateTradeNo()
|
||||
{
|
||||
$get_random = Str::random(8, 1);
|
||||
$date = date('YmdHis');
|
||||
$trade_no = "{$date}{$get_random}";
|
||||
while (self::where('trade_no', '=', $trade_no)->find()) {
|
||||
$trade_no = self::generateTradeNo();
|
||||
}
|
||||
return $trade_no;
|
||||
}
|
||||
public static function finish($where)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$Orders = self::where($where)->find();
|
||||
if (!$Orders) {
|
||||
throw new \Exception('订单不存在');
|
||||
}
|
||||
$notify = null;
|
||||
switch ($Orders->payment_channels) {
|
||||
case PaymentChannels::WXPAY['value']:
|
||||
$notify = PluginFinancePaymentNotify::where(['transaction_id' => $Orders->transaction_id])->find();
|
||||
break;
|
||||
}
|
||||
switch ($Orders->type) {
|
||||
case OrdersType::POINTS['value']:
|
||||
$pointsInfo = PluginMarketingPoints::where(['id' => $Orders->alias_id])->find();
|
||||
if (!$pointsInfo) {
|
||||
throw new \Exception('积分套餐不存在');
|
||||
}
|
||||
$points = (int)$pointsInfo->points + (int)$pointsInfo->give;
|
||||
Account::incPoints($Orders->uid, $Orders->channels_uid, $points, PointsBillScene::RECHARGE['value'], $Orders->id, '购买套餐:' . $pointsInfo->name, true);
|
||||
break;
|
||||
case OrdersType::VIP['value']:
|
||||
$vipInfoPrice = PluginMarketingPlanPrice::where(['id' => $Orders->alias_id])->find();
|
||||
if (!$vipInfoPrice) {
|
||||
throw new \Exception('会员套餐不存在');
|
||||
}
|
||||
$vipInfo = PluginMarketingPlan::where(['id' => $vipInfoPrice->plan_id])->find();
|
||||
if (!$vipInfo) {
|
||||
throw new \Exception('会员套餐不存在');
|
||||
}
|
||||
// 会员完成逻辑
|
||||
self::vip($Orders->alias_id, $Orders->uid, $Orders->channels_uid, $Orders->id);
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('订单类型错误');
|
||||
}
|
||||
$Orders->state = OrdersState::FINISH['value'];
|
||||
$Orders->finish_time = date('Y-m-d H:i:s');
|
||||
$Orders->save();
|
||||
PluginFinanceOrdersLog::info($Orders, '订单处理完成');
|
||||
if ($notify) {
|
||||
$notify->state = OrdersState::FINISH['value'];
|
||||
$notify->save();
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
Event::emit(EventName::ORDERS_FINISH['value'], $Orders);
|
||||
}
|
||||
public static function cancel($model)
|
||||
{
|
||||
$model->state = OrdersState::CANCEL['value'];
|
||||
$model->cancel_time = date('Y-m-d H:i:s');
|
||||
$model->save();
|
||||
if (!empty($model->coupon)) {
|
||||
$PluginMarketingCouponCodes = PluginMarketingCouponCode::whereIn('id', $model->coupon)->select();
|
||||
if (!$PluginMarketingCouponCodes->isEmpty()) {
|
||||
foreach ($PluginMarketingCouponCodes as $coupon) {
|
||||
$coupon->state = UseState::ON['value'];
|
||||
$coupon->use_time = null;
|
||||
$coupon->save();
|
||||
$appCoupon = PluginMarketingCoupon::where('id', $coupon->coupon_id)->find();
|
||||
$appCoupon->use_num = Db::raw('use_num-1');
|
||||
$appCoupon->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static function vip($alias_id, $uid, $channels_uid, $order_id)
|
||||
{
|
||||
$vipInfoPrice = PluginMarketingPlanPrice::where(['id' => $alias_id])->find();
|
||||
if (!$vipInfoPrice) {
|
||||
return false;
|
||||
}
|
||||
$vipInfo = PluginMarketingPlan::where(['id' => $vipInfoPrice->plan_id])->find();
|
||||
if (!$vipInfo) {
|
||||
return false;
|
||||
}
|
||||
$vip = new PluginUserVip();
|
||||
$vip->uid = $uid;
|
||||
$vip->channels_uid = $channels_uid;
|
||||
$vip->plan_id = $vipInfo->id;
|
||||
$vip->plan_price_id = $vipInfoPrice->id;
|
||||
$vip->num = $vipInfo->key == 'basic' ? 2 : 11;
|
||||
$vip->key = $vipInfo->key;
|
||||
$vip->save();
|
||||
$time = date('Y-m-d H:i:s', strtotime('+ ' . $vipInfo->num + 1 . ' month'));
|
||||
Account::incPoints($uid, $channels_uid, $vipInfoPrice->points + $vipInfoPrice->give, PointsBillScene::RECHARGE['value'], $order_id, '购买会员:' . $vipInfo->name, true, $time);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
use plugin\finance\utils\enum\OrdersLogLevel;
|
||||
|
||||
class PluginFinanceOrdersLog extends Basic
|
||||
{
|
||||
public static function info($order, $remarks,$admin_id=null)
|
||||
{
|
||||
$log = new self();
|
||||
$log->orders_id = $order->id;
|
||||
$log->remarks = $remarks;
|
||||
$log->level = OrdersLogLevel::INFO['value'];
|
||||
$log->admin_id = $admin_id;
|
||||
$log->save();
|
||||
}
|
||||
public static function error($order, $remarks,$admin_id=null){
|
||||
$log = new self();
|
||||
$log->orders_id = $order->id;
|
||||
$log->remarks = $remarks;
|
||||
$log->level = OrdersLogLevel::ERROR['value'];
|
||||
$log->admin_id = $admin_id;
|
||||
$log->save();
|
||||
}
|
||||
public static function warning($order, $remarks,$admin_id=null){
|
||||
$log = new self();
|
||||
$log->orders_id = $order->id;
|
||||
$log->remarks = $remarks;
|
||||
$log->level = OrdersLogLevel::WARNING['value'];
|
||||
$log->admin_id = $admin_id;
|
||||
$log->save();
|
||||
}
|
||||
public static function success($order, $remarks,$admin_id=null){
|
||||
$log = new self();
|
||||
$log->orders_id = $order->id;
|
||||
$log->remarks = $remarks;
|
||||
$log->level = OrdersLogLevel::SUCCESS['value'];
|
||||
$log->admin_id = $admin_id;
|
||||
$log->save();
|
||||
}
|
||||
public static function fail($order, $remarks,$admin_id=null){
|
||||
$log = new self();
|
||||
$log->orders_id = $order->id;
|
||||
$log->remarks = $remarks;
|
||||
$log->level = OrdersLogLevel::FAIL['value'];
|
||||
$log->admin_id = $admin_id;
|
||||
$log->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
|
||||
class PluginFinancePaymentNotify extends Basic
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
use plugin\notification\expose\helper\Push;
|
||||
|
||||
class PluginFinanceWallet extends Basic
|
||||
{
|
||||
protected $pk = 'uid';
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
'type' => [
|
||||
'balance' => 'float',
|
||||
'balance_sum' => 'float',
|
||||
'balance_used' => 'float',
|
||||
]
|
||||
];
|
||||
}
|
||||
public static function onAfterRead($model)
|
||||
{
|
||||
$model->available_points = $model->points + $model->tmp_points;
|
||||
}
|
||||
public static function onAfterUpdate($model)
|
||||
{
|
||||
Push::send([
|
||||
'uid' => $model->uid,
|
||||
'channels_uid' => $model->channels_uid,
|
||||
'event' => 'wallet',
|
||||
], []);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
use support\Request;
|
||||
|
||||
return [
|
||||
'debug' => true,
|
||||
'controller_suffix' => 'Controller',
|
||||
'controller_reuse' => false
|
||||
];
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
'files' => [
|
||||
base_path() . '/plugin/finance/app/functions.php',
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
return new Webman\Container;
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use app\expose\enum\EventName;
|
||||
|
||||
return [
|
||||
EventName::ORDERS_PAY['value']=>[
|
||||
[\plugin\finance\event\Orders::class,'pay']
|
||||
],
|
||||
EventName::ORDERS_PAY_SUCCESS['value']=>[
|
||||
[\plugin\finance\event\Orders::class,'paySuccess']
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'' => app\exception\Handler::class,
|
||||
];
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'' => [
|
||||
app\expose\middleware\Platform::class
|
||||
],
|
||||
'admin' => [
|
||||
app\expose\middleware\AdminAuth::class
|
||||
],
|
||||
'control' => [
|
||||
plugin\control\expose\middleware\ControlAuth::class
|
||||
],
|
||||
'api' => [
|
||||
plugin\control\expose\middleware\DomainMapping::class,
|
||||
plugin\user\expose\middleware\UserAuth::class,
|
||||
plugin\user\expose\middleware\Twofa::class,
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
use plugin\finance\process\Expire;
|
||||
use Workerman\Events\Select;
|
||||
|
||||
return [
|
||||
'OrdersExpire' => [
|
||||
'eventLoop' => Select::class,
|
||||
'handler' => Expire::class
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use app\expose\build\builder\ComponentBuilder;
|
||||
|
||||
$Component = new ComponentBuilder;
|
||||
return [
|
||||
[
|
||||
'title' => '订单过期时间',
|
||||
'field' => 'expire_time',
|
||||
'value' => 15,
|
||||
'component' => 'input-number',
|
||||
'extra' => [
|
||||
'required' => true,
|
||||
'prompt' => [
|
||||
$Component->add('text', ['default' => '订单过期时间,单位:分钟'], ['type' => 'info', 'size' => 'small'])
|
||||
->builder()
|
||||
],
|
||||
'props' => [
|
||||
'min' => 1,
|
||||
'max' => 1440,
|
||||
'step' => 1,
|
||||
'precision' => 0,
|
||||
'controls' => false
|
||||
]
|
||||
]
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Multilingual configuration
|
||||
*/
|
||||
return [
|
||||
// Default language
|
||||
'locale' => 'zh_CN',
|
||||
// Fallback language
|
||||
'fallback_locale' => ['zh_CN', 'en'],
|
||||
// Folder where language files are stored
|
||||
'path' => base_path() . '/plugin/finance/resource/translations',
|
||||
];
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"title": "财务",
|
||||
"icon": "Wallet",
|
||||
"path": "/app/finance/control",
|
||||
"sort": 6,
|
||||
"children": [
|
||||
{
|
||||
"title": "控制台",
|
||||
"icon": "ElementPlus",
|
||||
"path": "/app/finance/control/Index/index",
|
||||
"component": "databoard"
|
||||
},
|
||||
{
|
||||
"title": "订单列表",
|
||||
"icon": "ShoppingCart",
|
||||
"path": "/app/finance/control/Orders/index",
|
||||
"component": "table",
|
||||
"children": [
|
||||
{
|
||||
"title": "实收",
|
||||
"path": "/app/finance/control/Orders/real_money",
|
||||
"component": "form",
|
||||
"show": false
|
||||
},
|
||||
{
|
||||
"title": "收付",
|
||||
"path": "/app/finance/control/Orders/receipt_money",
|
||||
"component": "form",
|
||||
"show": false
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\event;
|
||||
|
||||
use app\expose\enum\EventName;
|
||||
use app\expose\enum\PaymentChannels;
|
||||
use plugin\finance\app\model\PluginFinanceOrders;
|
||||
use plugin\finance\app\model\PluginFinanceOrdersLog;
|
||||
use plugin\finance\app\model\PluginFinancePaymentNotify;
|
||||
use plugin\finance\utils\enum\OrdersState;
|
||||
use support\Log;
|
||||
use Webman\Event\Event;
|
||||
|
||||
class Orders
|
||||
{
|
||||
public static function pay($data)
|
||||
{
|
||||
if($data['plugin']!=='finance'){
|
||||
return true;
|
||||
}
|
||||
switch($data['payment_channels']){
|
||||
case PaymentChannels::WXPAY['value']:
|
||||
self::transaction($data['data']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
public static function transaction($data)
|
||||
{
|
||||
if(PluginFinancePaymentNotify::where(['transaction_id'=>$data['transaction_id']])->count()){
|
||||
return true;
|
||||
}
|
||||
$PluginFinancePaymentNotify=new PluginFinancePaymentNotify;
|
||||
$PluginFinancePaymentNotify->mchid=$data['mchid'];
|
||||
$PluginFinancePaymentNotify->appid=$data['appid'];
|
||||
$PluginFinancePaymentNotify->out_trade_no=$data['out_trade_no'];
|
||||
$PluginFinancePaymentNotify->transaction_id=$data['transaction_id'];
|
||||
$PluginFinancePaymentNotify->trade_type=$data['trade_type'];
|
||||
$PluginFinancePaymentNotify->trade_state=$data['trade_state'];
|
||||
$PluginFinancePaymentNotify->trade_state_desc=$data['trade_state_desc'];
|
||||
$PluginFinancePaymentNotify->bank_type=$data['bank_type'];
|
||||
$PluginFinancePaymentNotify->attach=$data['attach'];
|
||||
$PluginFinancePaymentNotify->payer_openid=$data['payer']['openid'];
|
||||
$PluginFinancePaymentNotify->amount_total=$data['amount']['total'];
|
||||
$PluginFinancePaymentNotify->amount_payer_total=$data['amount']['payer_total'];
|
||||
$PluginFinancePaymentNotify->amount_currency=$data['amount']['currency'];
|
||||
$PluginFinancePaymentNotify->amount_payer_currency=$data['amount']['payer_currency'];
|
||||
$PluginFinanceOrders=PluginFinanceOrders::where(['trade'=>$data['out_trade_no']])->find();
|
||||
if($PluginFinanceOrders){
|
||||
$PluginFinancePaymentNotify->state=OrdersState::PAID['value'];
|
||||
$PluginFinancePaymentNotify->save();
|
||||
$PluginFinanceOrders->state=OrdersState::PAID['value'];
|
||||
$PluginFinanceOrders->pay_type=PaymentChannels::WXPAY['value'];
|
||||
$PluginFinanceOrders->pay_time=date('Y-m-d H:i:s');
|
||||
$PluginFinanceOrders->transaction_id=$data['transaction_id'];
|
||||
$PluginFinanceOrders->save();
|
||||
PluginFinanceOrdersLog::info($PluginFinanceOrders, PaymentChannels::WXPAY['label'].'支付成功');
|
||||
Event::emit(EventName::ORDERS_PAY_SUCCESS['value'],$PluginFinanceOrders);
|
||||
}else{
|
||||
$PluginFinancePaymentNotify->state=OrdersState::NOTIFY_FAIL['value'];
|
||||
$PluginFinancePaymentNotify->save();
|
||||
}
|
||||
}
|
||||
public static function paySuccess($order)
|
||||
{
|
||||
try {
|
||||
PluginFinanceOrders::finish(['id'=>$order->id]);
|
||||
} catch (\Throwable $th) {
|
||||
PluginFinanceOrdersLog::fail($order, $th->getMessage());
|
||||
Log::error("订单完成失败:{$order->trade_no},{$th->getMessage()},{$th->getFile()}:{$th->getLine()}", $th->getTrace());
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,513 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\expose\helper;
|
||||
|
||||
use app\expose\enum\State;
|
||||
use plugin\finance\app\model\PluginFinanceWallet;
|
||||
use plugin\finance\utils\enum\PointsBillScene;
|
||||
use plugin\finance\utils\enum\ValidityPeriod;
|
||||
use plugin\user\app\model\PluginUserBill;
|
||||
use plugin\user\app\model\PluginUserPoints;
|
||||
use plugin\user\app\model\PluginUserPointsBill;
|
||||
use plugin\user\utils\enum\MoneyAction;
|
||||
use think\facade\Db;
|
||||
|
||||
class Account
|
||||
{
|
||||
|
||||
/**
|
||||
* 增加积分
|
||||
* @param int $uid 用户ID
|
||||
* @param int $channels_uid 渠道ID
|
||||
* @param float $amount 操作金额
|
||||
* @param string $scene 场景
|
||||
* @param int $form_id 表单ID
|
||||
* @param string $remarks 备注
|
||||
* @param bool $is_accumulate 是否计入累计
|
||||
* @param string $validity_period 有效期
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function incPoints($uid, $channels_uid, $amount, $scene = '', $form_id = 0, $remarks = '', $is_accumulate = true, $valid_time = null)
|
||||
{
|
||||
$wallet = PluginFinanceWallet::where('uid', $uid)
|
||||
->where('channels_uid', $channels_uid)
|
||||
->find();
|
||||
if (!$wallet) {
|
||||
$wallet = new PluginFinanceWallet();
|
||||
$wallet->uid = $uid;
|
||||
$wallet->channels_uid = $channels_uid;
|
||||
$wallet->save();
|
||||
$wallet = PluginFinanceWallet::where('uid', $uid)
|
||||
->where('channels_uid', $channels_uid)
|
||||
->find();
|
||||
}
|
||||
$validity_period = empty($valid_time) ? ValidityPeriod::PERMANENT['value'] : ValidityPeriod::TEMPORARY['value'];
|
||||
|
||||
$log = new PluginUserPointsBill();
|
||||
$log->channels_uid = $channels_uid;
|
||||
$log->uid = $uid;
|
||||
$log->form_id = $form_id;
|
||||
$log->num = $amount;
|
||||
$log->remarks = $remarks;
|
||||
$log->action = MoneyAction::INCREASE['value'];
|
||||
$log->scene = $scene;
|
||||
$log->type = $validity_period;
|
||||
$log->is_sum = $is_accumulate ? State::YES['value'] : State::NO['value'];
|
||||
//永久积只累加
|
||||
if ($validity_period === ValidityPeriod::PERMANENT['value']) {
|
||||
$log->before = $wallet->points;
|
||||
$log->after = $wallet->points + $amount;
|
||||
$wallet->points = Db::raw('points+' . $amount);
|
||||
if ($is_accumulate) {
|
||||
$wallet->points_sum = Db::raw('points_sum + ' . $amount);
|
||||
}
|
||||
} else {
|
||||
$log->before = $wallet->tmp_points;
|
||||
$log->after = $wallet->tmp_points + $amount;
|
||||
$wallet->tmp_points = Db::raw('tmp_points + ' . $amount);
|
||||
if ($is_accumulate) {
|
||||
$wallet->tmp_points_sum = Db::raw('tmp_points_sum + ' . $amount);
|
||||
}
|
||||
|
||||
$userPoints = new PluginUserPoints();
|
||||
$userPoints->channels_uid = $channels_uid;
|
||||
$userPoints->uid = $uid;
|
||||
$userPoints->total_points = $amount;
|
||||
$userPoints->points = $amount;
|
||||
$userPoints->used_points = 0;
|
||||
$userPoints->valid_time = $valid_time;
|
||||
$userPoints->extended_time = $valid_time;
|
||||
$userPoints->scene = $scene;
|
||||
$userPoints->source_id = $form_id;
|
||||
$userPoints->save();
|
||||
$log->source_id = $userPoints->id;
|
||||
}
|
||||
$wallet->save();
|
||||
$log->save();
|
||||
return $log->id;
|
||||
}
|
||||
public static function hasPoints($uid, $channels_uid, $amount)
|
||||
{
|
||||
if ($amount <= 0) {
|
||||
return true;
|
||||
}
|
||||
$wallet = PluginFinanceWallet::where('uid', $uid)
|
||||
->where('channels_uid', $channels_uid)
|
||||
->lock(true)
|
||||
->find();
|
||||
if (!$wallet) {
|
||||
throw new \Exception('钱包不存在');
|
||||
}
|
||||
if ($wallet->points + $wallet->tmp_points < $amount) {
|
||||
throw new \Exception('积分不足');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 减少积分
|
||||
* @param int $uid 用户ID
|
||||
* @param int $channels_uid 渠道ID
|
||||
* @param float $amount 操作金额
|
||||
* @param string $scene 场景
|
||||
* @param int $form_id 表单ID
|
||||
* @param string $remarks 备注
|
||||
* @param bool $is_accumulate 是否计入累计
|
||||
* @param bool $is_ignore_balance 是否忽略余额
|
||||
* @throws \Exception
|
||||
* @author:1950781041@qq.com
|
||||
* @Date:2025-12-30
|
||||
*/
|
||||
public static function decPoints($uid, $channels_uid, $amount, $scene = '', $form_id = 0, $remarks = '', $is_accumulate = true,$is_ignore_balance=false)
|
||||
{
|
||||
if ($amount <= 0) return [];
|
||||
$wallet = PluginFinanceWallet::where('uid', $uid)
|
||||
->where('channels_uid', $channels_uid)
|
||||
->lock(true)
|
||||
->find();
|
||||
if (!$wallet) {
|
||||
throw new \Exception('钱包不存在');
|
||||
}
|
||||
if (!$is_ignore_balance && $wallet->points + $wallet->tmp_points < $amount) {
|
||||
throw new \Exception('积分不足');
|
||||
}
|
||||
$ids = [];
|
||||
$tempPointsList = PluginUserPoints::where('uid', $uid)
|
||||
->where('channels_uid', $channels_uid)
|
||||
->where('points', '>', 0)
|
||||
->where('valid_time', '>=', date('Y-m-d H:i:s'))
|
||||
->where('extended_time', '>=', date('Y-m-d H:i:s'))
|
||||
->order('extended_time ASC, valid_time ASC')
|
||||
->lock(true)
|
||||
->select();
|
||||
$tmp_points = 0;
|
||||
$tmp_points_used = 0;
|
||||
foreach ($tempPointsList as $point) {
|
||||
if ($amount <= 0) break;
|
||||
$deduct = min($point['points'] - $point['used_points'], $amount);
|
||||
if ($deduct <= 0) continue;
|
||||
$PluginUserPoints = PluginUserPoints::where('id', $point['id'])->find();
|
||||
if (!$PluginUserPoints) {
|
||||
continue;
|
||||
}
|
||||
$PluginUserPoints->used_points = Db::raw('used_points + ' . $deduct);
|
||||
$PluginUserPoints->points = Db::raw('points - ' . $deduct);
|
||||
$PluginUserPoints->save();
|
||||
$log = new PluginUserPointsBill();
|
||||
$log->channels_uid = $channels_uid;
|
||||
$log->uid = $uid;
|
||||
$log->form_id = $form_id;
|
||||
$log->source_id = $point['id'];
|
||||
$log->num = $deduct;
|
||||
$log->before = $wallet->tmp_points;
|
||||
$log->after = $wallet->tmp_points - $deduct;
|
||||
$log->remarks = $remarks;
|
||||
$log->action = MoneyAction::DECREASE['value'];
|
||||
$log->scene = $scene;
|
||||
$log->type = ValidityPeriod::TEMPORARY['value'];
|
||||
$log->is_sum = $is_accumulate ? State::YES['value'] : State::NO['value'];
|
||||
$log->save();
|
||||
$ids[] = $log->id;
|
||||
$amount -= $deduct;
|
||||
$tmp_points += $deduct;
|
||||
if ($is_accumulate) {
|
||||
$tmp_points_used += $deduct;
|
||||
}
|
||||
}
|
||||
$points = 0;
|
||||
$points_used = 0;
|
||||
if ($amount > 0) {
|
||||
$deduct = min($wallet->points, $amount);
|
||||
if ($deduct > 0) {
|
||||
$log = new PluginUserPointsBill();
|
||||
$log->channels_uid = $channels_uid;
|
||||
$log->uid = $uid;
|
||||
$log->form_id = $form_id;
|
||||
$log->source_id = 0;
|
||||
$log->num = $deduct;
|
||||
$log->before = $wallet->points;
|
||||
$log->after = $wallet->points - $deduct;
|
||||
$log->remarks = $remarks;
|
||||
$log->action = MoneyAction::DECREASE['value'];
|
||||
$log->scene = $scene;
|
||||
$log->type = ValidityPeriod::PERMANENT['value'];
|
||||
$log->is_sum = $is_accumulate ? State::YES['value'] : State::NO['value'];
|
||||
$log->save();
|
||||
$amount -= $deduct;
|
||||
$points += $deduct;
|
||||
if ($is_accumulate) {
|
||||
$points_used += $deduct;
|
||||
}
|
||||
$ids[] = $log->id;
|
||||
}
|
||||
}
|
||||
if ($tmp_points_used > 0) {
|
||||
$wallet->tmp_points_used = Db::raw('tmp_points_used + ' . $tmp_points_used);
|
||||
}
|
||||
if ($tmp_points > 0) {
|
||||
$wallet->tmp_points = Db::raw('tmp_points - ' . $tmp_points);
|
||||
}
|
||||
if ($points > 0) {
|
||||
$wallet->points = Db::raw('points - ' . $points);
|
||||
}
|
||||
if ($points_used > 0) {
|
||||
$wallet->points_used = Db::raw('points_used + ' . $points_used);
|
||||
}
|
||||
$wallet->save();
|
||||
return $ids;
|
||||
}
|
||||
public static function rollbackPoints($uid, $channels_uid, $ids)
|
||||
{
|
||||
$bills = PluginUserPointsBill::whereIn('id', $ids)->select();
|
||||
foreach ($bills as $bill) {
|
||||
$bill->action = MoneyAction::INCREASE['value'];
|
||||
$bill->save();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 操作永久积分
|
||||
* @param int $uid 用户ID
|
||||
* @param int $channels_uid 渠道ID
|
||||
* @param float $amount 操作金额
|
||||
* @param string $scene 场景
|
||||
* @param int $form_id 表单ID
|
||||
* @param string $remarks 备注
|
||||
* @param bool $is_accumulate 是否计入累计
|
||||
* @throws \Exception
|
||||
* @author:1950781041@qq.com
|
||||
* @Date:2025-12-30
|
||||
*/
|
||||
public static function updatePermanentPoints($uid, $channels_uid, $amount, $scene = '', $form_id = 0, $action = '', $remarks = '', $is_accumulate = 1)
|
||||
{
|
||||
if ($amount <= 0) {
|
||||
throw new \Exception('操作金额必须大于0');
|
||||
}
|
||||
if (!in_array($action, [MoneyAction::DECREASE['value'], MoneyAction::INCREASE['value']])) {
|
||||
throw new \Exception('操作类型错误');
|
||||
}
|
||||
$wallet = PluginFinanceWallet::where('uid', $uid)
|
||||
->where('channels_uid', $channels_uid)
|
||||
->lock(true)
|
||||
->find();
|
||||
|
||||
if (!$wallet) {
|
||||
throw new \Exception('钱包不存在');
|
||||
}
|
||||
if ($action === MoneyAction::DECREASE['value']) {
|
||||
if ($wallet->points < $amount) {
|
||||
throw new \Exception('金额不足');
|
||||
}
|
||||
}
|
||||
$log = new PluginUserPointsBill();
|
||||
$log->channels_uid = $channels_uid;
|
||||
$log->uid = $uid;
|
||||
$log->form_id = $form_id;
|
||||
$log->num = $amount;
|
||||
$log->remarks = $remarks;
|
||||
$log->action = $action;
|
||||
$log->scene = $scene;
|
||||
$log->before = $wallet->points;
|
||||
$log->type = ValidityPeriod::PERMANENT['value'];
|
||||
$log->is_accumulate = $is_accumulate ? State::YES['value'] : State::NO['value'];
|
||||
if ($action === MoneyAction::DECREASE['value']) {
|
||||
$log->after = $wallet->points - $amount;
|
||||
$wallet->points -= $amount;
|
||||
if ($is_accumulate) {
|
||||
$wallet->points_used += $amount;
|
||||
}
|
||||
} else {
|
||||
$log->after = $wallet->points + $amount;
|
||||
$wallet->points += $amount;
|
||||
if ($is_accumulate) {
|
||||
$wallet->points_sum += $amount;
|
||||
}
|
||||
}
|
||||
$wallet->save();
|
||||
$log->save();
|
||||
return $log->id;
|
||||
}
|
||||
/**
|
||||
* 操作临时积分
|
||||
* @param int $uid 用户ID
|
||||
* @param int $channels_uid 渠道ID
|
||||
* @param float $amount 操作金额
|
||||
* @param string $scene 场景
|
||||
* @param int $form_id 表单ID
|
||||
* @param string $remarks 备注
|
||||
* @param bool $is_accumulate 是否计入累计
|
||||
* @throws \Exception
|
||||
* @author:1950781041@qq.com
|
||||
* @Date:2025-12-30
|
||||
*/
|
||||
public static function decTemporaryPoints($uid, $channels_uid, $amount, $scene = '', $form_id = 0, $action = '', $remarks = '', $is_accumulate = 1, $id = 0)
|
||||
{
|
||||
$userPoints = PluginUserPoints::where('id', $id)->find();
|
||||
$wallet = PluginFinanceWallet::where('uid', $uid)
|
||||
->where('channels_uid', $channels_uid)
|
||||
->lock(true)
|
||||
->find();
|
||||
if (!$userPoints || !$wallet) {
|
||||
throw new \Exception('积分或钱包不存在');
|
||||
}
|
||||
if ($userPoints->points < $amount) {
|
||||
throw new \Exception('积分不足');
|
||||
}
|
||||
if ($wallet->tmp_points < $amount) {
|
||||
throw new \Exception('临时积分不足');
|
||||
}
|
||||
$log = new PluginUserPointsBill();
|
||||
$log->channels_uid = $channels_uid;
|
||||
$log->uid = $uid;
|
||||
$log->form_id = $form_id;
|
||||
$log->source_id = $id;
|
||||
$log->num = $amount;
|
||||
$log->remarks = $remarks;
|
||||
$log->action = $action;
|
||||
$log->scene = $scene;
|
||||
$log->type = ValidityPeriod::TEMPORARY['value'];
|
||||
$log->is_accumulate = $is_accumulate ? State::YES['value'] : State::NO['value'];
|
||||
if ($action === MoneyAction::DECREASE['value']) {
|
||||
$log->after = $wallet->tmp_points - $amount;
|
||||
$wallet->tmp_points -= $amount;
|
||||
if ($is_accumulate) {
|
||||
$wallet->tmp_points_used += $amount;
|
||||
$userPoints->used_points += $amount;
|
||||
}
|
||||
}
|
||||
$userPoints->points -= $amount;
|
||||
$userPoints->save();
|
||||
$wallet->save();
|
||||
$log->save();
|
||||
return $log->id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 操作用户资产(余额或积分)
|
||||
* @param int $uid 用户ID
|
||||
* @param int $channels_uid 渠道ID
|
||||
* @param float $amount 操作金额
|
||||
* @param string $action 操作类型 MoneyAction::DECREASE['value'] / MoneyAction::INCREASE['value']
|
||||
* @param string $type 操作类型 balance/points
|
||||
* @param string $scene 触发场景
|
||||
* @param int $form_id 表单ID
|
||||
* @param string|null $remarks 备注
|
||||
* @param bool $is_accumulate 是否计入累计 如退款时,不计入累计
|
||||
* @return int 日志ID
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function updateAccount($uid, $channels_uid, $amount, $action, $scene = '', $form_id = 0, $remarks = null, $is_accumulate = true, $validity_period = ValidityPeriod::PERMANENT['value'])
|
||||
{
|
||||
if ($amount <= 0) {
|
||||
throw new \Exception('操作金额必须大于0');
|
||||
}
|
||||
if (!in_array($action, [MoneyAction::DECREASE['value'], MoneyAction::INCREASE['value']])) {
|
||||
throw new \Exception('操作类型错误');
|
||||
}
|
||||
$wallet = PluginFinanceWallet::where('uid', $uid)
|
||||
->where('channels_uid', $channels_uid)
|
||||
->lock(true)
|
||||
->find();
|
||||
|
||||
if (!$wallet) {
|
||||
throw new \Exception('钱包不存在');
|
||||
}
|
||||
$fieldBalance = 'balance';
|
||||
$fieldUsed = 'balance_used';
|
||||
$fieldSum = 'balance_sum';
|
||||
//判断金额是否足够
|
||||
if ($action === MoneyAction::DECREASE['value']) {
|
||||
if ($wallet->$fieldBalance < $amount) {
|
||||
throw new \Exception('金额不足');
|
||||
}
|
||||
}
|
||||
|
||||
$log = new PluginUserBill();
|
||||
$log->channels_uid = $channels_uid;
|
||||
$log->uid = $uid;
|
||||
$log->form_id = $form_id;
|
||||
$log->num = $amount;
|
||||
$log->remarks = $remarks;
|
||||
$log->action = $action;
|
||||
$log->scene = $scene;
|
||||
$log->before = $wallet->$fieldBalance;
|
||||
$log->type = $validity_period;
|
||||
$log->is_accumulate = $is_accumulate ? State::YES['value'] : State::NO['value'];
|
||||
if ($action === MoneyAction::DECREASE['value']) {
|
||||
$log->after = $wallet->$fieldBalance - $amount;
|
||||
$wallet->$fieldBalance -= $amount;
|
||||
if ($is_accumulate) {
|
||||
$wallet->$fieldUsed += $amount;
|
||||
}
|
||||
} else {
|
||||
$log->after = $wallet->$fieldBalance + $amount;
|
||||
$wallet->$fieldBalance += $amount;
|
||||
if ($is_accumulate) {
|
||||
$wallet->$fieldSum += $amount;
|
||||
}
|
||||
}
|
||||
$wallet->save();
|
||||
$log->save();
|
||||
return $log->id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退费
|
||||
* @param int $log_id 账单ID
|
||||
* @param float $number 退费金额
|
||||
* @param string $type 操作类型 balance/points
|
||||
* @author:1950781041@qq.com
|
||||
* @Date:2025-12-20
|
||||
*/
|
||||
public static function refund($uid, $channels_uid, $billIds, $number = null, $remarks = '积分退还', $scene = 'refunded')
|
||||
{
|
||||
if ($number !== null && $number <= 0) {
|
||||
throw new \Exception('退费金额必须大于0');
|
||||
}
|
||||
$wallet = PluginFinanceWallet::where('uid', $uid)
|
||||
->where('channels_uid', $channels_uid)
|
||||
->lock(true)
|
||||
->find();
|
||||
if (!$wallet) {
|
||||
throw new \Exception('钱包不存在');
|
||||
}
|
||||
$bills = PluginUserPointsBill::whereIn('id', $billIds)->whereRaw('refunded < num')
|
||||
->where('action', 'decrease')
|
||||
->order('id', 'desc')
|
||||
->lock(true)
|
||||
->select();
|
||||
$tmp_points = 0;
|
||||
$tmp_points_used = 0;
|
||||
$points = 0;
|
||||
$points_used = 0;
|
||||
foreach ($bills as $bill) {
|
||||
if ($number === null) {
|
||||
$refund = $bill->num;
|
||||
} else {
|
||||
if ($number <= 0) {
|
||||
break;
|
||||
}
|
||||
$canRefund = $bill->num - $bill->refunded;
|
||||
if ($canRefund <= 0) {
|
||||
continue;
|
||||
}
|
||||
$refund = min($canRefund, $number);
|
||||
}
|
||||
$log = new PluginUserPointsBill();
|
||||
$log->channels_uid = $channels_uid;
|
||||
$log->uid = $uid;
|
||||
$log->form_id = $bill->form_id;
|
||||
$log->source_id = $bill->source_id;
|
||||
$log->num = $refund;
|
||||
$log->action = MoneyAction::INCREASE['value'];
|
||||
$log->scene = $scene;
|
||||
$log->remarks = "退款,原账单ID:{$bill->id}," . $remarks;
|
||||
$log->type = $bill->type;
|
||||
$log->is_sum = 0;
|
||||
if ($bill->type === 'temporary') {
|
||||
$points = PluginUserPoints::where('id', $bill->source_id)
|
||||
->lock(true)
|
||||
->find();
|
||||
if (!$points) {
|
||||
throw new \Exception('临时积分记录不存在');
|
||||
}
|
||||
$points->points = Db::raw('points + ' . $refund);
|
||||
$points->used_points = Db::raw('used_points - ' . $refund);
|
||||
$points->state = 0;
|
||||
$points->save();
|
||||
$log->source_id = $points->id;
|
||||
$log->before = $wallet->tmp_points;
|
||||
$tmp_points += $refund;
|
||||
$tmp_points_used += $refund;
|
||||
$log->after = $wallet->tmp_points;
|
||||
} else {
|
||||
$log->before = $wallet->points;
|
||||
$points += $refund;
|
||||
$points_used += $refund;
|
||||
$log->after = $wallet->points;
|
||||
}
|
||||
$bill->refunded = Db::raw('refunded + ' . $refund);
|
||||
$bill->save();
|
||||
|
||||
$log->save();
|
||||
|
||||
if ($number !== null) {
|
||||
$number -= $refund;
|
||||
}
|
||||
}
|
||||
if ($tmp_points > 0) {
|
||||
$wallet->tmp_points = Db::raw('tmp_points + ' . $tmp_points);
|
||||
}
|
||||
if ($tmp_points_used > 0) {
|
||||
$wallet->tmp_points_used = Db::raw('tmp_points_used - ' . $tmp_points_used);
|
||||
}
|
||||
if ($points > 0) {
|
||||
$wallet->points = Db::raw('points + ' . $points);
|
||||
}
|
||||
if ($points_used > 0) {
|
||||
$wallet->points_used = Db::raw('points_used - ' . $points_used);
|
||||
}
|
||||
$wallet->save();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "interface-example",
|
||||
"title": "应用示例项目",
|
||||
"version": "0.0.1",
|
||||
"description": "应用市场",
|
||||
"author": {
|
||||
"name": "余心",
|
||||
"email": "unknown.renloong@gmail.com"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\process;
|
||||
|
||||
use plugin\finance\app\model\PluginFinanceOrders;
|
||||
use plugin\finance\app\model\PluginFinanceOrdersLog;
|
||||
use plugin\finance\utils\enum\OrdersState;
|
||||
use support\Log;
|
||||
use Workerman\Crontab\Crontab;
|
||||
use think\facade\Db;
|
||||
use Webman\Event\Event;
|
||||
|
||||
class Expire
|
||||
{
|
||||
public function onWorkerStart()
|
||||
{
|
||||
// 每秒钟执行一次
|
||||
new Crontab('0 */1 * * * *', function () {
|
||||
try {
|
||||
$data = PluginFinanceOrders::where(['state' => OrdersState::WAIT_PAY['value']])->whereNotNull('expire_time')->whereTime('expire_time', '<=', date('Y-m-d H:i:s'))->limit(20)->select();
|
||||
foreach ($data as $item) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
PluginFinanceOrders::cancel($item);
|
||||
PluginFinanceOrdersLog::warning($item,'订单超时取消');
|
||||
Db::commit();
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Log::error('Process Orders Expire Error:'.$th->getMessage(),$th->getTrace());
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
Log::error('Process Orders Expire Error:'.$th->getMessage(),$th->getTrace());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'form_basic_title'=>'Basic',
|
||||
];
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'success' => 'Success',
|
||||
'fail' => 'Fail',
|
||||
];
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'Dashboard' => 'Dashboard',
|
||||
'Console' => 'Console',
|
||||
'User' => 'User',
|
||||
'User List' => 'User List',
|
||||
'Create User' => 'Create User',
|
||||
'Edit User' => 'Edit User',
|
||||
'Update Status' => 'Update Status',
|
||||
'Functional' => 'Functional',
|
||||
'Administrator' => 'Administrator',
|
||||
'Staff List' => 'Staff List',
|
||||
'Create Administrator' => 'Create Administrator',
|
||||
'Edit Administrator' => 'Edit Administrator',
|
||||
'Delete Administrator' => 'Delete Administrator',
|
||||
'Move Role' => 'Move Role',
|
||||
'Role Management' => 'Role Management',
|
||||
'Role List' => 'Role List',
|
||||
'Create Role' => 'Create Role',
|
||||
'Edit Role' => 'Edit Role',
|
||||
'Delete Role' => 'Delete Role',
|
||||
'Systems' => 'Systems',
|
||||
'Basic Settings' => 'Basic Settings',
|
||||
'Control Settings' => 'Control Settings',
|
||||
'Upload Settings' => 'Upload Settings',
|
||||
'SMS Settings' => 'SMS Settings',
|
||||
'Payment Management' => 'Payment Management',
|
||||
'Payment Settings' => 'Payment Settings',
|
||||
'Payment Template' => 'Payment Template',
|
||||
'Create Payment Template' => 'Create Payment Template',
|
||||
'Edit Payment Template' => 'Edit Payment Template',
|
||||
'Delete Payment Template' => 'Delete Payment Template',
|
||||
'Platform Management' => 'Platform Management',
|
||||
'WeChat Mini Program' => 'WeChat Mini Program',
|
||||
'WeChat Official Account' => 'WeChat Official Account',
|
||||
'Alipay Mini Program' => 'Alipay Mini Program',
|
||||
'WeChat Open Platform' => 'WeChat Open Platform',
|
||||
'App Platform' => 'App Platform',
|
||||
'H5 Platform' => 'H5 Platform',
|
||||
'PC Platform' => 'PC Platform',
|
||||
'Public Permissions' => 'Public Permissions',
|
||||
'Edit Profile' => 'Edit Profile',
|
||||
'Get Profile' => 'Get Profile',
|
||||
'Logout' => 'Logout',
|
||||
'Get Upload Categories' => 'Get Upload Categories',
|
||||
'Edit Upload Category' => 'Edit Upload Category',
|
||||
'Delete Upload Category' => 'Delete Upload Category',
|
||||
'Upload File' => 'Upload File',
|
||||
'Delete Upload File' => 'Delete Upload File',
|
||||
'Edit Upload File' => 'Edit Upload File',
|
||||
'Get Upload File List' => 'Get Upload File List',
|
||||
'Login Title'=>'Admin Login',
|
||||
'toolbar Lock'=>'Lock',
|
||||
'toolbar Search'=>'Search',
|
||||
'toolbar Notification'=>'Notification',
|
||||
'toolbar FullScreen'=>'FullScreen',
|
||||
'toolbar House'=>'Home',
|
||||
'toolbar Control'=>'Control',
|
||||
'userDropdownMenu updateSelf'=>'Admin Info',
|
||||
'Logout Success'=>'Logout Success',
|
||||
'PIN Code Cannot Be Empty'=>'PIN Code Cannot Be Empty',
|
||||
'Please Enter 6 Digits PIN Code'=>'Please Enter 6 Digits PIN Code',
|
||||
'Lock Success'=>'Lock Success',
|
||||
'Unlock Success'=>'Unlock Success',
|
||||
'form_basic_title'=>'Basic',
|
||||
'Settings_basic_web_name'=>'Apps Name'
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'success' => 'Success',
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'form_basic_title'=>'基础信息',
|
||||
];
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'success' => '成功',
|
||||
'fail' => '失败',
|
||||
];
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'Dashboard' => '首页',
|
||||
'Console' => '控制台',
|
||||
'User' => '用户',
|
||||
'User List' => '用户列表',
|
||||
'Create User' => '创建用户',
|
||||
'Edit User' => '编辑用户',
|
||||
'Update Status' => '更新状态',
|
||||
'Functional' => '职能',
|
||||
'Administrator' => '管理员',
|
||||
'Staff List' => '人员列表',
|
||||
'Create Administrator' => '创建管理员',
|
||||
'Edit Administrator' => '编辑管理员',
|
||||
'Delete Administrator' => '删除管理员',
|
||||
'Move Role' => '移动角色',
|
||||
'Role Management' => '角色',
|
||||
'Role List' => '角色管理',
|
||||
'Create Role' => '创建角色',
|
||||
'Edit Role' => '编辑角色',
|
||||
'Delete Role' => '删除角色',
|
||||
'Systems' => '系统',
|
||||
'Basic Settings' => '基本配置',
|
||||
'Control Settings' => '控制台配置',
|
||||
'Upload Settings' => '上传配置',
|
||||
'SMS Settings' => '短信配置',
|
||||
'Payment Management' => '支付管理',
|
||||
'Payment Settings' => '支付配置',
|
||||
'Payment Template' => '支付模板',
|
||||
'Create Payment Template' => '新增支付模板',
|
||||
'Edit Payment Template' => '编辑支付模板',
|
||||
'Delete Payment Template' => '删除支付模板',
|
||||
'Platform Management' => '平台管理',
|
||||
'WeChat Mini Program' => '微信小程序',
|
||||
'WeChat Official Account' => '微信公众号',
|
||||
'Alipay Mini Program' => '支付宝小程序',
|
||||
'WeChat Open Platform' => '微信开放平台',
|
||||
'App Platform' => 'APP',
|
||||
'H5 Platform' => 'H5',
|
||||
'PC Platform' => 'PC',
|
||||
'Public Permissions' => '公共权限',
|
||||
'Edit Profile' => '修改自己的信息',
|
||||
'Get Profile' => '获取自己的信息',
|
||||
'Logout' => '退出登录',
|
||||
'Get Upload Categories' => '获取上传分类',
|
||||
'Edit Upload Category' => '编辑上传分类',
|
||||
'Delete Upload Category' => '删除上传分类',
|
||||
'Upload File' => '上传文件',
|
||||
'Delete Upload File' => '删除上传文件',
|
||||
'Edit Upload File' => '编辑上传文件',
|
||||
'Get Upload File List' => '获取上传文件列表',
|
||||
'Login Title'=>'管理员登录',
|
||||
'toolbar Lock'=>'锁屏',
|
||||
'toolbar Search'=>'搜索菜单',
|
||||
'toolbar Notification'=>'查看通知',
|
||||
'toolbar FullScreen'=>'全屏/退出全屏',
|
||||
'toolbar House'=>'网站首页',
|
||||
'toolbar Control'=>'网站前台控制台',
|
||||
'userDropdownMenu updateSelf'=>'管理员信息',
|
||||
'Logout Success'=>'退出成功',
|
||||
'PIN Code Cannot Be Empty'=>'PIN码不能为空',
|
||||
'Please Enter 6 Digits PIN Code'=>'请输入6位PIN码',
|
||||
'Lock Success'=>'锁定成功',
|
||||
'Unlock Success'=>'解锁成功',
|
||||
'form_basic_title'=>'基础信息',
|
||||
'Settings_basic_web_name'=>'应用名称'
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'success' => '成功',
|
||||
];
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\utils\enum;
|
||||
|
||||
use app\expose\enum\builder\Enum;
|
||||
|
||||
class BillScene extends Enum
|
||||
{
|
||||
const ADMIN = [
|
||||
'label' => '管理员操作',
|
||||
'value' => 'admin',
|
||||
'props' => [
|
||||
'type' => 'info'
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\utils\enum;
|
||||
|
||||
use app\expose\enum\builder\Enum;
|
||||
|
||||
class OrdersLogLevel extends Enum
|
||||
{
|
||||
const INFO = [
|
||||
'label' => '普通',
|
||||
'value' => 'info',
|
||||
'props' => [
|
||||
'type' => 'info'
|
||||
]
|
||||
];
|
||||
const ERROR = [
|
||||
'label' => '错误',
|
||||
'value' => 'error',
|
||||
'props' => [
|
||||
'type' => 'danger'
|
||||
]
|
||||
];
|
||||
const WARNING = [
|
||||
'label' => '警告',
|
||||
'value' => 'warning',
|
||||
'props' => [
|
||||
'type' => 'warning'
|
||||
]
|
||||
];
|
||||
const SUCCESS = [
|
||||
'label' => '成功',
|
||||
'value' => 'success',
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
];
|
||||
const FAIL = [
|
||||
'label' => '失败',
|
||||
'value' => 'fail',
|
||||
'props' => [
|
||||
'type' => 'danger'
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\utils\enum;
|
||||
|
||||
use app\expose\enum\builder\Enum;
|
||||
|
||||
class OrdersState extends Enum
|
||||
{
|
||||
const WAIT_PAY = [
|
||||
'label' => '待支付',
|
||||
'value' => 0,
|
||||
'props' => [
|
||||
'type' => 'info'
|
||||
]
|
||||
];
|
||||
const PAID = [
|
||||
'label' => '已支付',
|
||||
'value' => 10,
|
||||
'props' => [
|
||||
'type' => 'warning'
|
||||
]
|
||||
];
|
||||
const WAIT_VERIFIED = [
|
||||
'label' => '待验证',
|
||||
'value' => 11,
|
||||
'props' => [
|
||||
'type' => 'warning'
|
||||
]
|
||||
];
|
||||
const FINISH = [
|
||||
'label' => '已完成',
|
||||
'value' => 20,
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
];
|
||||
const REFUND_ING = [
|
||||
'label' => '退款中',
|
||||
'value' => 30,
|
||||
'props' => [
|
||||
'type' => 'warning'
|
||||
]
|
||||
];
|
||||
const REFUND_SUCCESS = [
|
||||
'label' => '退款成功',
|
||||
'value' => 40,
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
];
|
||||
const REFUND_FAIL = [
|
||||
'label' => '退款失败',
|
||||
'value' => 50,
|
||||
'props' => [
|
||||
'type' => 'danger'
|
||||
]
|
||||
];
|
||||
const INVALID = [
|
||||
'label' => '作废',
|
||||
'value' => 60,
|
||||
'props' => [
|
||||
'type' => 'danger'
|
||||
]
|
||||
];
|
||||
const NOTIFY_FAIL = [
|
||||
'label' => '通知失败',
|
||||
'value' => 70,
|
||||
'props' => [
|
||||
'type' => 'danger'
|
||||
]
|
||||
];
|
||||
const CANCEL = [
|
||||
'label' => '已取消',
|
||||
'value' => 99,
|
||||
'props' => [
|
||||
'type' => 'info'
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\utils\enum;
|
||||
|
||||
use app\expose\enum\builder\Enum;
|
||||
|
||||
class OrdersType extends Enum
|
||||
{
|
||||
const POINTS = [
|
||||
'label' => '充值',
|
||||
'value' => 'points',
|
||||
'props' => [
|
||||
'type' => 'danger',
|
||||
'allow_payment' => ['wxpay', 'alipay']
|
||||
]
|
||||
];
|
||||
const VIP = [
|
||||
'label' => '会员',
|
||||
'value' => 'vip',
|
||||
'props' => [
|
||||
'type' => 'success',
|
||||
'allow_payment' => ['wxpay', 'alipay']
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\utils\enum;
|
||||
|
||||
use app\expose\enum\builder\Enum;
|
||||
|
||||
class PointsBillScene extends Enum
|
||||
{
|
||||
const ADMIN = [
|
||||
'label' => '管理员操作',
|
||||
'value' => 'admin',
|
||||
'props' => [
|
||||
'type' => 'warning'
|
||||
]
|
||||
];
|
||||
const RECHARGE = [
|
||||
'label' => '充值',
|
||||
'value' => 'recharge',
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
];
|
||||
const VIP_UPGRADE = [
|
||||
'label' => 'VIP升级',
|
||||
'value' => 'vip_upgrade',
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
];
|
||||
const REGISTER = [
|
||||
'label' => '注册',
|
||||
'value' => 'register',
|
||||
'props' => [
|
||||
'type' => 'warning'
|
||||
]
|
||||
];
|
||||
const INVITE = [
|
||||
'label' => '邀请',
|
||||
'value' => 'invite',
|
||||
'props' => [
|
||||
'type' => 'warning'
|
||||
]
|
||||
];
|
||||
const CONSUME = [
|
||||
'label' => '消费',
|
||||
'value' => 'consume',
|
||||
'props' => [
|
||||
'type' => 'primary'
|
||||
]
|
||||
];
|
||||
const REFUNDED = [
|
||||
'label' => '退款',
|
||||
'value' => 'refunded',
|
||||
'props' => [
|
||||
'type' => 'danger'
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\finance\utils\enum;
|
||||
|
||||
use app\expose\enum\builder\Enum;
|
||||
|
||||
class ValidityPeriod extends Enum
|
||||
{
|
||||
const TEMPORARY = [
|
||||
'label' => '临时',
|
||||
'value' => 'temporary',
|
||||
'props' => [
|
||||
'type' => 'info'
|
||||
]
|
||||
];
|
||||
const PERMANENT = [
|
||||
'label' => '永久',
|
||||
'value' => 'permanent',
|
||||
'props' => [
|
||||
'type' => 'success'
|
||||
]
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user