This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
forked from LinZihong/BusinessSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
NeverBehave
committed
Sep 1, 2017
1 parent
1dc093b
commit d797f35
Showing
25 changed files
with
729 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 '成功'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.