response()->error('商品ID不能为空且必须大于0'); } if (empty($input['quantity']) || $input['quantity'] <= 0) { return $this->response()->error('回收数量不能为空且必须大于0'); } if (!isset($input['price']) || $input['price'] < 0) { return $this->response()->error('回收价格不能为空且不能为负数'); } try { $result = MexAdminService::recycleItem( adminUserId: Admin::user()->id, itemId: (int)$input['item_id'], quantity: (int)$input['quantity'], price: (float)$input['price'], remark: $input['remark'] ?? '后台管理员回收' ); if ($result['success']) { return $this->response() ->success('回收成功!操作ID: ' . $result['operation_id'] . ', 成交ID: ' . $result['transaction_id']) ->refresh(); // 刷新当前页面 } else { return $this->response()->error('回收失败: ' . $result['message']); } } catch (\Exception $e) { return $this->response()->error('回收失败: ' . $e->getMessage()); } } /** * 构建表单 */ public function form() { $this->number('item_id', '商品ID') ->required() ->min(1) ->help('请输入要回收的商品ID'); $this->number('quantity', '回收数量') ->required() ->min(1) ->help('请输入要回收的数量'); $this->decimal('price', '回收价格') ->required() ->help('请输入回收价格(每个商品的价格)'); $this->textarea('remark', '操作备注') ->rows(3) ->help('可选,记录本次操作的原因或说明'); $this->html('
注意事项
'); } /** * 返回表单默认数据 */ public function default() { return [ 'item_id' => '', 'quantity' => '', 'price' => '', 'remark' => '', ]; } }