/** * Run the database seeds. * * @return void */ public function run() { GiftFresher::truncate(); $data = [['item_id' => '408382', 'name' => 'tanthu1', 'KNB' => 5000, 'point' => 50000, 'image' => 'images/goi1.png', 'description' => 'qua tan thu so 1', 'status' => true], ['item_id' => '408383', 'name' => 'tanthu2', 'KNB' => 5000, 'point' => 50000, 'image' => 'images/goi2.png', 'description' => 'qua tan thu so 2', 'status' => true], ['item_id' => '408384', 'name' => 'tanthu3', 'KNB' => 10000, 'point' => 100000, 'image' => 'images/goi3.png', 'description' => 'qua tan thu so 3', 'status' => true], ['item_id' => '408385', 'name' => 'tanthu4', 'KNB' => 10000, 'point' => 100000, 'image' => 'images/goi4.png', 'description' => 'qua tan thu so 4', 'status' => true]]; GiftFresher::insert($data); }
public function getAcGoitanthu($server_id, $gift_type) { $user = session('user'); if (User::findOrfail(Auth::user()->id)->fresher) { $server = Server::findOrfail($server_id); $giftFresher = GiftFresher::findOrfail($gift_type); $account = Session::get('account'); $oldKNB = $account->yuanbao; $oldPoint = $account->point; if ($oldKNB >= $giftFresher->KNB && $oldPoint >= $giftFresher->point) { $user = User::findOrfail(Auth::user()->id); $giftBox = new GiftBox(); $giftBox->setConnection($server->user_db); $giftBox->acct_id = session('account')->acct_id; $giftBox->item_id = $giftFresher->item_id; $giftBox->itemtype = 0; $giftBox->quantity = 1; $giftBox->serialNo = 0; try { $update = $giftBox->save(); } catch (\Exception $e) { return redirect()->back()->with('error', 'Thao tác xảy ra lỗi'); } if ($update) { try { $newKNB = $oldKNB - $giftFresher->KNB; $newPoint = $oldPoint - $giftFresher->point; $account->yuanbao = $newKNB; $account->point = $newPoint; $account->save(); $user->update(['fresher' => false]); Session::forget('account'); Session::put('account', $account); return redirect()->back()->with('message', 'Nhận quà thành công!'); } catch (\Exception $e) { return redirect()->back()->with('error', 'Thao tác xảy ra lỗi'); } } } else { return redirect()->back()->with('error', 'Không đủ KNB hoặc điểm tích lũy'); } } else { return redirect()->back()->with('error', 'Quà chỉ dành cho tân game thủ'); } }