Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
stage 1
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverBehave committed Sep 1, 2017
1 parent 1dc093b commit d797f35
Show file tree
Hide file tree
Showing 25 changed files with 729 additions and 67 deletions.
46 changes: 46 additions & 0 deletions app/Events/BuyStuff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Events;

use App\Resources;
use App\User;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class BuyStuff
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*
* @return void
*/

public $user;
public $item;
public $amount;

public function __construct(User $user, Resources $item, $amount)
{
//
$this->user = $user;
$this->item = $item;
$this->amount = $amount;
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
43 changes: 43 additions & 0 deletions app/Events/Logger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Events;

use App\User;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class Logger
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $user;
public $function;
public $message;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct(User $user, $function, $message)
{
$this->user = $user;
$this->function = $function;
$this->message = $message;
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
50 changes: 50 additions & 0 deletions app/Events/NewTransaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Events;

use App\Resources;
use App\User;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class NewTransaction
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $seller;
public $buyer;
public $sellerItem;
public $buyerItem;
public $sellerAmount;
public $buyerAmount;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(User $seller, User $buyer, Resources $sellerItem, Resources $buyerItem, $sellerAmount, $buyerAmount)
{
//
$this->seller = $seller;
$this->buyer = $buyer;
$this->sellerItem = $sellerItem;
$this->buyerItem = $buyerItem;
$this->sellerAmount = $sellerAmount;
$this->buyerAmount = $buyerAmount;
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
36 changes: 36 additions & 0 deletions app/Events/Transaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class Transaction
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
63 changes: 37 additions & 26 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,48 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\UserResource;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;

class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/

use AuthenticatesUsers;
use AuthenticatesUsers;

/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';

/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}

public function authenticated(Request $request, $user)
{
if (empty($user->Resources())) {
$Res = new UserResource();
$Res->user_id = $user->id;
$Res->save();
}
}
}
31 changes: 31 additions & 0 deletions app/Http/Controllers/PurchaseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Http\Controllers;

use App\Events\BuyStuff;
use App\Resources;
use Illuminate\Http\Request;

class PurchaseController extends Controller
{
//
public function __construct()
{
}

public function TopUp(Request $request)
{
$item = Resources::query()->where('id',$request->id)->first();
$user = $request->user();

foreach ($item->requirement as $key => $value){
if ($user->resources()->where('name',$key)->amount < $amount = $value * $request->amount){
return "材料 {$key} 不足,需要 {$amount} ";
}
}

event(new BuyStuff($user,$item,$request->amount));

return '成功';
}
}
23 changes: 23 additions & 0 deletions app/Http/Controllers/TransactionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TransactionController extends Controller
{
//
public function __construct()
{
}

public function createTransaction(Request $request)
{

}

public function handleTransaction(Request $request)
{

}
}
19 changes: 19 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UserController extends Controller
{
//
public function __construct()
{
}

public function index()
{
return view('dashboard');
}

}
40 changes: 40 additions & 0 deletions app/Listeners/CreateTransaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Listeners;

use App\Events\NewTransaction;
use App\Transaction;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class CreateTransaction
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Handle the event.
*
* @param NewTransaction $event
* @return void
*/
public function handle(NewTransaction $event)
{
//
$trans = new Transaction();
$trans->seller_id = $event->seller->id;
$trans->buyer_id = $event->buyer->id;
$trans->seller_item_id = $event->sellerItem->id;
$trans->buyer_item_id = $event->buyerItem->id;
$trans->seller_amount = $event->sellerAmount;
$trans->buyer_amount = $event->buyerAmount;
$trans->save();
}
}
Loading

0 comments on commit d797f35

Please sign in to comment.