| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace App\Module\Mex\Validators;
- use App\Module\GameItems\Logics\ItemQuantity;
- use App\Module\Fund\Services\FundService;
- use App\Module\Fund\Enums\FUND_CURRENCY_TYPE;
- use App\Module\Mex\Enums\OrderStatus;
- use App\Module\Mex\Enums\OrderType;
- use App\Module\Mex\Logic\FundLogic;
- use App\Module\Mex\Models\MexOrder;
- use UCore\Validator;
- use Uraus\Kku\Common\MEX_DIRECTION;
- use Illuminate\Support\Facades\Log;
- /**
- * 农贸市场订单 数量 验证器
- * 等待的订单买入/卖出 各10个
- * 验证订单创建的各种条件,包括资金、物品数量等
- * 支持多币种验证,默认使用钻石币种
- */
- class MexOrderNumberValidator extends Validator
- {
- /**
- * 验证订单创建条件
- *
- * @param mixed $value 交易方向
- * @param array $data 所有数据
- * @return bool 验证是否通过
- */
- public function validate(mixed $value, array $data): bool
- {
- $direction = (int)$value;
- $itemIdKey = $this->args[1] ?? 'itemId';
- // 从 args 获取字段名
- $userIdKey = $this->args[0] ?? 'user_id';
- $userId = (int)$data[$userIdKey] ?? 0;
- $itemId = $data[$itemIdKey] ?? null;
- if ($direction === MEX_DIRECTION::SELL) {
- $count = MexOrder::query()->where(
- [
- 'user_id' => $userId,
- 'order_type' => OrderType::SELL,
- 'item_id' => $itemId,
- 'status' => OrderStatus::PENDING,
- ]
- )->count();
- } else {
- $count = MexOrder::query()->where(
- [
- 'user_id' => $userId,
- 'order_type' => OrderType::BUY,
- 'item_id' => $itemId,
- 'status' => OrderStatus::PENDING,
- ]
- )->count();
- }
- if ($count >= 10) {
- return false;
- }
- return true;
- }
- }
|