/** * Run the database seeds. * * @return void */ public function run() { QuaDatMoc::truncate(); $data = [['item_id' => '10000', 'name' => 'Chìa khóa hòm báu', 'point' => 20000, 'image' => 'images/goi1.png', 'description' => 'qua tan thu so 1', 'status' => true], ['item_id' => '10001', 'name' => 'Cao - Bí tích bảo hợp', 'point' => 50000, 'image' => 'images/goi1.png', 'description' => 'qua tan thu so 1', 'status' => true], ['item_id' => '10002', 'name' => 'Hoàn x3 XP nhân vật', 'point' => 100000, 'image' => 'images/goi1.png', 'description' => 'qua tan thu so 1', 'status' => true], ['item_id' => '10003', 'name' => 'Kim Tỏa(trợ thủ môn phái)', 'point' => 150000, 'image' => 'images/goi1.png', 'description' => 'qua tan thu so 1', 'status' => true], ['item_id' => '10004', 'name' => 'Cao-Tăng bản đồ', 'point' => 200000, 'image' => 'images/goi1.png', 'description' => 'qua tan thu so 1', 'status' => true], ['item_id' => '10005', 'name' => 'Tuyệt học Bảo Hợp', 'point' => 500000, 'image' => 'images/goi1.png', 'description' => 'qua tan thu so 1', 'status' => true]]; QuaDatMoc::insert($data); }
public function getAcThuongdatmoc($server_id, $gift_id) { $user = session('user'); $server_key = 'server' . $server_id; $server = session($server_key); $gift = QuaDatMoc::findOrfail($gift_id); $account = new GAccount(); $account->setConnection($server->user_db); $account = $account->findOrfail(session('account')->acct_id); $oldPoint = $account->point; if ($oldPoint >= $gift->point) { $giftBox = new GiftBox(); $giftBox->setConnection($server->user_db); $giftBox->acct_id = session('account')->acct_id; $giftBox->item_id = $gift->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 { $newPoint = $oldPoint - $gift->point; $account->point = $newPoint; $account->save(); 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 đủ điểm tích lũy'); } }