|
|
@@ -0,0 +1,290 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Module\Mex\AdminControllers;
|
|
|
+
|
|
|
+use App\Module\Mex\Services\MexAdminService;
|
|
|
+use Spatie\RouteAttributes\Attributes\Get;
|
|
|
+use Spatie\RouteAttributes\Attributes\Post;
|
|
|
+use UCore\DcatAdmin\AdminController;
|
|
|
+use Dcat\Admin\Form;
|
|
|
+use Dcat\Admin\Layout\Content;
|
|
|
+use Dcat\Admin\Widgets\Card;
|
|
|
+use Dcat\Admin\Admin;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 农贸市场管理员工具
|
|
|
+ *
|
|
|
+ * 提供物品注入、回收等管理员操作功能
|
|
|
+ *
|
|
|
+ * @menu 游戏运营管理/农贸市场管理/🛠 管理工具
|
|
|
+ */
|
|
|
+class MexAdminToolController extends AdminController
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 页面标题
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $title = '农贸市场管理工具';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 工具页面
|
|
|
+ */
|
|
|
+ #[Get('mex-admin-tools', name: 'dcat.admin.mex-admin-tools.index')]
|
|
|
+ public function index(Content $content)
|
|
|
+ {
|
|
|
+ return $content
|
|
|
+ ->title($this->title)
|
|
|
+ ->description('管理员操作工具')
|
|
|
+ ->body($this->buildToolsPage());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 物品注入页面
|
|
|
+ */
|
|
|
+ #[Get('mex-admin-tools/inject', name: 'dcat.admin.mex-admin-tools.inject')]
|
|
|
+ public function inject(Content $content)
|
|
|
+ {
|
|
|
+ return $content
|
|
|
+ ->title('物品注入')
|
|
|
+ ->description('向市场注入物品,增加供应量')
|
|
|
+ ->body($this->buildInjectForm());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 物品回收页面
|
|
|
+ */
|
|
|
+ #[Get('mex-admin-tools/recycle', name: 'dcat.admin.mex-admin-tools.recycle')]
|
|
|
+ public function recycle(Content $content)
|
|
|
+ {
|
|
|
+ return $content
|
|
|
+ ->title('物品回收')
|
|
|
+ ->description('从市场回收物品,减少供应量')
|
|
|
+ ->body($this->buildRecycleForm());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理物品注入
|
|
|
+ */
|
|
|
+ #[Post('mex-admin-tools/inject', name: 'dcat.admin.mex-admin-tools.inject.store')]
|
|
|
+ public function storeInject(Request $request)
|
|
|
+ {
|
|
|
+ $request->validate([
|
|
|
+ 'item_id' => 'required|integer|min:1',
|
|
|
+ 'quantity' => 'required|integer|min:1',
|
|
|
+ 'price' => 'required|numeric|min:0',
|
|
|
+ 'remark' => 'nullable|string|max:255',
|
|
|
+ ], [
|
|
|
+ 'item_id.required' => '商品ID不能为空',
|
|
|
+ 'item_id.integer' => '商品ID必须是整数',
|
|
|
+ 'item_id.min' => '商品ID必须大于0',
|
|
|
+ 'quantity.required' => '数量不能为空',
|
|
|
+ 'quantity.integer' => '数量必须是整数',
|
|
|
+ 'quantity.min' => '数量必须大于0',
|
|
|
+ 'price.required' => '价格不能为空',
|
|
|
+ 'price.numeric' => '价格必须是数字',
|
|
|
+ 'price.min' => '价格不能为负数',
|
|
|
+ 'remark.max' => '备注不能超过255个字符',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ try {
|
|
|
+ $result = MexAdminService::injectItem(
|
|
|
+ adminUserId: Admin::user()->id,
|
|
|
+ itemId: $request->item_id,
|
|
|
+ quantity: $request->quantity,
|
|
|
+ price: $request->price,
|
|
|
+ remark: $request->remark ?? '后台管理员注入'
|
|
|
+ );
|
|
|
+
|
|
|
+ if ($result['success']) {
|
|
|
+ admin_success('注入成功!', '操作ID: ' . $result['operation_id'] . ', 成交ID: ' . $result['transaction_id']);
|
|
|
+ return redirect()->route('dcat.admin.mex-admin-tools.inject');
|
|
|
+ } else {
|
|
|
+ admin_error('注入失败', $result['message']);
|
|
|
+ return back()->withInput();
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ admin_error('注入失败', $e->getMessage());
|
|
|
+ return back()->withInput();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理物品回收
|
|
|
+ */
|
|
|
+ #[Post('mex-admin-tools/recycle', name: 'dcat.admin.mex-admin-tools.recycle.store')]
|
|
|
+ public function storeRecycle(Request $request)
|
|
|
+ {
|
|
|
+ $request->validate([
|
|
|
+ 'item_id' => 'required|integer|min:1',
|
|
|
+ 'quantity' => 'required|integer|min:1',
|
|
|
+ 'price' => 'required|numeric|min:0',
|
|
|
+ 'remark' => 'nullable|string|max:255',
|
|
|
+ ], [
|
|
|
+ 'item_id.required' => '商品ID不能为空',
|
|
|
+ 'item_id.integer' => '商品ID必须是整数',
|
|
|
+ 'item_id.min' => '商品ID必须大于0',
|
|
|
+ 'quantity.required' => '数量不能为空',
|
|
|
+ 'quantity.integer' => '数量必须是整数',
|
|
|
+ 'quantity.min' => '数量必须大于0',
|
|
|
+ 'price.required' => '价格不能为空',
|
|
|
+ 'price.numeric' => '价格必须是数字',
|
|
|
+ 'price.min' => '价格不能为负数',
|
|
|
+ 'remark.max' => '备注不能超过255个字符',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ try {
|
|
|
+ $result = MexAdminService::recycleItem(
|
|
|
+ adminUserId: Admin::user()->id,
|
|
|
+ itemId: $request->item_id,
|
|
|
+ quantity: $request->quantity,
|
|
|
+ price: $request->price,
|
|
|
+ remark: $request->remark ?? '后台管理员回收'
|
|
|
+ );
|
|
|
+
|
|
|
+ if ($result['success']) {
|
|
|
+ admin_success('回收成功!', '操作ID: ' . $result['operation_id'] . ', 成交ID: ' . $result['transaction_id']);
|
|
|
+ return redirect()->route('dcat.admin.mex-admin-tools.recycle');
|
|
|
+ } else {
|
|
|
+ admin_error('回收失败', $result['message']);
|
|
|
+ return back()->withInput();
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ admin_error('回收失败', $e->getMessage());
|
|
|
+ return back()->withInput();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建工具页面
|
|
|
+ */
|
|
|
+ private function buildToolsPage()
|
|
|
+ {
|
|
|
+ $card = new Card('农贸市场管理工具', '
|
|
|
+ <div class="row">
|
|
|
+ <div class="col-md-6">
|
|
|
+ <div class="card">
|
|
|
+ <div class="card-body text-center">
|
|
|
+ <i class="fa fa-plus-circle fa-3x text-success mb-3"></i>
|
|
|
+ <h5>物品注入</h5>
|
|
|
+ <p class="text-muted">向市场投放商品,增加供应量</p>
|
|
|
+ <a href="' . route('dcat.admin.mex-admin-tools.inject') . '" class="btn btn-success">
|
|
|
+ <i class="fa fa-plus"></i> 开始注入
|
|
|
+ </a>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="col-md-6">
|
|
|
+ <div class="card">
|
|
|
+ <div class="card-body text-center">
|
|
|
+ <i class="fa fa-minus-circle fa-3x text-warning mb-3"></i>
|
|
|
+ <h5>物品回收</h5>
|
|
|
+ <p class="text-muted">从市场回收商品,减少供应量</p>
|
|
|
+ <a href="' . route('dcat.admin.mex-admin-tools.recycle') . '" class="btn btn-warning">
|
|
|
+ <i class="fa fa-minus"></i> 开始回收
|
|
|
+ </a>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="row mt-4">
|
|
|
+ <div class="col-md-12">
|
|
|
+ <div class="alert alert-info">
|
|
|
+ <h6><i class="fa fa-info-circle"></i> 使用说明</h6>
|
|
|
+ <ul class="mb-0">
|
|
|
+ <li><strong>物品注入</strong>:相当于系统向仓库"卖出"物品,增加仓库库存,系统获得资金</li>
|
|
|
+ <li><strong>物品回收</strong>:相当于系统从仓库"买入"物品,减少仓库库存,系统支出资金</li>
|
|
|
+ <li>所有操作都会记录在管理员操作记录中,并生成对应的成交记录</li>
|
|
|
+ <li>操作前请确认商品ID、数量和价格的准确性</li>
|
|
|
+ </ul>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ ');
|
|
|
+
|
|
|
+ return $card;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建注入表单
|
|
|
+ */
|
|
|
+ private function buildInjectForm()
|
|
|
+ {
|
|
|
+ $form = new Form();
|
|
|
+
|
|
|
+ $form->action(route('dcat.admin.mex-admin-tools.inject.store'));
|
|
|
+
|
|
|
+ $form->number('item_id', '商品ID')
|
|
|
+ ->required()
|
|
|
+ ->min(1)
|
|
|
+ ->help('请输入要注入的商品ID');
|
|
|
+
|
|
|
+ $form->number('quantity', '注入数量')
|
|
|
+ ->required()
|
|
|
+ ->min(1)
|
|
|
+ ->help('请输入要注入的数量');
|
|
|
+
|
|
|
+ $form->decimal('price', '注入价格')
|
|
|
+ ->required()
|
|
|
+ ->help('请输入注入价格(每个商品的价格)');
|
|
|
+
|
|
|
+ $form->textarea('remark', '操作备注')
|
|
|
+ ->rows(3)
|
|
|
+ ->help('可选,记录本次操作的原因或说明');
|
|
|
+
|
|
|
+ $form->html('<div class="alert alert-warning">
|
|
|
+ <h6><i class="fa fa-exclamation-triangle"></i> 注意事项</h6>
|
|
|
+ <ul class="mb-0">
|
|
|
+ <li>注入操作相当于系统向仓库"卖出"物品</li>
|
|
|
+ <li>会增加仓库的库存数量</li>
|
|
|
+ <li>系统会获得相应的资金收入</li>
|
|
|
+ <li>操作不可撤销,请谨慎操作</li>
|
|
|
+ </ul>
|
|
|
+ </div>');
|
|
|
+
|
|
|
+ return $form;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建回收表单
|
|
|
+ */
|
|
|
+ private function buildRecycleForm()
|
|
|
+ {
|
|
|
+ $form = new Form();
|
|
|
+
|
|
|
+ $form->action(route('dcat.admin.mex-admin-tools.recycle.store'));
|
|
|
+
|
|
|
+ $form->number('item_id', '商品ID')
|
|
|
+ ->required()
|
|
|
+ ->min(1)
|
|
|
+ ->help('请输入要回收的商品ID');
|
|
|
+
|
|
|
+ $form->number('quantity', '回收数量')
|
|
|
+ ->required()
|
|
|
+ ->min(1)
|
|
|
+ ->help('请输入要回收的数量');
|
|
|
+
|
|
|
+ $form->decimal('price', '回收价格')
|
|
|
+ ->required()
|
|
|
+ ->help('请输入回收价格(每个商品的价格)');
|
|
|
+
|
|
|
+ $form->textarea('remark', '操作备注')
|
|
|
+ ->rows(3)
|
|
|
+ ->help('可选,记录本次操作的原因或说明');
|
|
|
+
|
|
|
+ $form->html('<div class="alert alert-warning">
|
|
|
+ <h6><i class="fa fa-exclamation-triangle"></i> 注意事项</h6>
|
|
|
+ <ul class="mb-0">
|
|
|
+ <li>回收操作相当于系统从仓库"买入"物品</li>
|
|
|
+ <li>会减少仓库的库存数量</li>
|
|
|
+ <li>系统会支出相应的资金</li>
|
|
|
+ <li>回收数量不能超过当前库存</li>
|
|
|
+ <li>操作不可撤销,请谨慎操作</li>
|
|
|
+ </ul>
|
|
|
+ </div>');
|
|
|
+
|
|
|
+ return $form;
|
|
|
+ }
|
|
|
+}
|