| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace Tests\Integration;
- use App\Http\Controllers\admin\Agent as AdminAgent;
- use App\Models\Agent\Agent;
- use App\Models\Agent\AgentEquityOrder;
- use App\Models\Agent\AgentSetting;
- use App\Services\Agent\AgentEquityService;
- use App\Services\Agent\AgentWalletService;
- use Illuminate\Http\Request;
- use PHPUnit\Framework\TestCase;
- use Tests\Support\AgentTestEnvironment;
- /** 总后台入股购买记录:列表筛选、汇总、取消待付款订单。 */
- class AgentEquityOrderAdminTest extends TestCase
- {
- use AgentTestEnvironment;
- private function call(string $method, array $params)
- {
- $request = Request::create('/admin/agent/equity-orders', $method === 'cancelEquityOrder' ? 'POST' : 'GET', $params);
- $request->user = (object) ['id' => 7];
- $this->app->instance('request', $request);
- return (new AdminAgent())->{$method}($request, new AgentEquityService(new AgentWalletService()))->getData(true);
- }
- public function test_admin_lists_all_purchases_with_summary_and_cancels_pending_orders(): void
- {
- AgentSetting::current()->update(['equity_enabled' => 1, 'equity_price_per_percent' => 10000,
- 'equity_min_percent' => 0.1, 'equity_max_percent' => 1]);
- $equity = new AgentEquityService(new AgentWalletService());
- $rich = $this->agent(Agent::TYPE_EQUITY);
- Agent::query()->whereKey($rich->id)->update(['balance' => 5000, 'realtime_balance' => 5000]);
- $poor = $this->agent(Agent::TYPE_EQUITY);
- $done = $equity->order($rich->fresh(), '0.3'); // 3000,余额够,直接开通
- $pending = $equity->order($poor, '0.5'); // 5000,待付款
- $this->assertSame(AgentEquityOrder::STATUS_COMPLETED, $done->status);
- $all = $this->call('equityOrders', []);
- $this->assertSame(0, $all['code'], (string) $all['msg']);
- $this->assertSame(2, $all['data']['total']);
- $this->assertSame(['0.3000', '3000.0000', 1, '5000.0000', '0.3000'], [
- $all['data']['summary']['completed_percent'], $all['data']['summary']['completed_amount'],
- $all['data']['summary']['pending_count'], $all['data']['summary']['pending_amount'], $all['data']['summary']['total_equity_percent'],
- ]);
- $first = $all['data']['list'][0];
- $this->assertSame($pending->id, $first['id']);
- $this->assertSame($poor->username, $first['agent']['username']);
- $this->assertSame('待付款', $first['status_text']);
- $this->assertSame(1, $this->call('equityOrders', ['username' => $rich->username])['data']['total']);
- $this->assertSame(1, $this->call('equityOrders', ['status' => 'completed'])['data']['total']);
- $this->assertSame(0, $this->call('equityOrders', ['date_type' => 'completed_at', 'start_date' => '2026-09-08'])['data']['total']);
- $this->assertNotSame(0, $this->call('cancelEquityOrder', ['id' => $pending->id])['code'], 'remark required');
- $this->assertSame('只有待付款订单可以取消', $this->call('cancelEquityOrder', ['id' => $done->id, 'remark' => 'x'])['msg']);
- $cancelled = $this->call('cancelEquityOrder', ['id' => $pending->id, 'remark' => '长期未充值']);
- $this->assertSame(0, $cancelled['code']);
- $this->assertSame(['cancelled', 7, '长期未充值'], [$cancelled['data']['status'], $cancelled['data']['cancelled_by'], $cancelled['data']['cancel_remark']]);
- $own = $equity->order($poor, '0.2');
- $this->assertNull($equity->cancel($poor, $own->id)->cancelled_by, 'agent self-cancel has no admin');
- }
- }
|