Exemplo n.º 1
0
 public function start(Request $request)
 {
     if ($request->ajax()) {
         //get ip and store info
         $winner = Winner::where('user_id', '=', $request->ip())->first();
         if (!empty($winner)) {
             $result = ['msg' => '您已经抢过了,不能再抢了哦~', 'cdkey' => $winner->cdkey, 'status' => '2'];
         } else {
             $join = Join::create(['ip' => $request->ip()]);
             //get kucun
             if ($join->id) {
                 $award = Award::find($request->input('event_id'));
                 $result = ['msg' => '恭喜!您抢到了', 'cdkey' => $request->input('event_id'), 'status' => '1'];
                 if ($award->surplus <= 0) {
                     $result = ['msg' => '很遗憾,被抢光了!', 'status' => '0'];
                 } else {
                     //库存-1
                     $award->surplus = $award->surplus - 1;
                     $award->save();
                     //生成cdkey
                     $cdkey = $this->generateCdkey(5);
                     //
                     //保存中奖用户
                     $winner = Winner::create(['user_id' => $request->ip(), 'award_id' => $request->input('award_id'), 'cdkey' => $cdkey, 'event_id' => $request->input('event_id')]);
                     $result = ['msg' => '恭喜!您抢到了', 'cdkey' => $cdkey, 'status' => '1'];
                 }
             }
         }
     }
     return response()->json($result);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     //
     Award::destroy($id);
     Session::flash('flash_message', '奖品删除成功');
     return \Redirect::back();
 }
Exemplo n.º 3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     $faker = \Faker\Factory::create();
     foreach (range(1, 10) as $index) {
         Award::create(['name' => $faker->sentence(1), 'image_path' => $faker->sentence('1')]);
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     $user = User::find(2);
     foreach (range(11, 19) as $index) {
         $award = Award::find($index);
         $user->Award()->attach($award);
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     $faker = \Faker\Factory::create();
     foreach (range(1, 10) as $index) {
         $award = Award::find($index);
         $lottery = Lottery::create(['award_id' => $index, 'prob' => random_int(1, 100), 'number' => random_int(1, 100)]);
     }
 }
Exemplo n.º 6
0
 public function update(array $data, $id)
 {
     $award = Award::find($id);
     $award->name = $data['name'];
     $award->totals = $data['totals'];
     $award->surplus = $data['totals'];
     $award->event_id = $data['event_id'];
     $award->save();
     return $award;
 }
Exemplo n.º 7
0
 public function destroy($id)
 {
     $result = Award::find($id);
     $result->delete();
     if ($result->id) {
         flash()->success('操作成功');
     } else {
         flash()->error('操作失败');
     }
     return redirect()->back();
 }
Exemplo n.º 8
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     $infos = ['一等奖_耳机' => ['BEATS新版solo2头戴式耳机耳麦', 1, 100000], '二等奖_小米电源' => ['小米新款移动电源10000mAh 银色', 3, 10000], '二等奖_小米手环' => ['小米手环', 3, 10000], '二等奖_健康秤' => ['云康宝智能脂肪秤 蓝牙体脂仪', 3, 10000], '三等奖_自拍杆' => ['美逸线控自拍杆/自拍神器/迷你自拍器 太空蓝', 5, 5000], '三等奖_猪肉脯' => ['[百草味]靖江猪肉脯180g', 2, 3000], '三等奖_碧根果' => ['[百草味] 奶香碧根果218g', 2, 3000], '三等奖_巧克力' => ['amovo魔吻纯可可脂核桃伽纳彻', 1, 2000], '四等奖_焦糖咖啡' => ['雀巢(Nestle) 咖啡焦糖拿铁 100g', 1, 2000], '四等奖_辣条' => ['辣条', 1, 2000], '四等奖_麦吉士' => ['麦吉士图层酥塔', 1, 2000], '四等奖_摩卡咖啡' => ['Nestle雀巢咖啡摩卡咖啡条装105g', 4, 2000], '五等奖_旺仔牛奶苹果味' => ['旺旺 旺仔牛奶 苹果 (铁罐装) 245ml', 1, 2000], '五等奖_旺仔牛奶原味' => ['旺仔牛奶 原味(铁罐装) 245ml', 1, 2000], '五等奖_旺仔牛奶果汁味' => ['旺旺 旺仔牛奶 果汁味 (铁罐装) 245ml', 1, 2000], '五等奖_指甲刀' => ['简约时尚纯色折叠指甲钳', 1, 2000], '五等奖_包包' => ['可爱颜文字小钱包', 1, 2000], '五等奖_台历' => ['2016年田园风小清新年历计划本', 1, 2000], '五等奖_饭票' => ['儒林餐厅餐票', 4, 1000], '六等奖_便签本' => ['可爱喵星人N次贴', 6, 1000], '六等奖_裁纸刀' => ['迷你便携小号美工刀 快递开箱器', 5, 1000], '六等奖_彩色铅笔' => ['马可四色彩芯彩虹原木粗铅笔', 5, 1000], '六等奖_记事本' => ['简约纯色记事本', 5, 800], '六等奖_键盘刷' => ['长柄键盘清洁刷', 5, 800], '六等奖_搅拌勺' => ['不锈钢长柄搅拌勺', 5, 800], '六等奖_沐浴球' => ['糖果色海绵沐浴花 ', 5, 800], '六等奖_暖宝宝' => ['暖宝宝发热贴', 5, 800], '六等奖_贴纸' => ['可爱动物N次贴', 5, 800], '六等奖_文件袋' => ['可爱A4试卷文件袋', 5, 800], '六等奖_荧光笔' => ['彩色磨砂荧光笔记号', 5, 800], '六等奖_自动笔' => ['创意多功能复合笔:圆珠笔+自动铅笔一体笔', 5, 800]];
     # award create
     foreach ($infos as $key => $award) {
         Award::create(['name' => $award[0], 'image_path' => 'imgs/goods/' . $key . '.jpg']);
     }
     #lottery
     foreach (range(1, 7) as $index) {
         $award = Award::find($index);
         $lottery = Lottery::create(['award_id' => $index, 'prob' => $index * 10, 'number' => 10]);
     }
     # goods create
     foreach ($infos as $key => $goods) {
         Goods::create(['name' => $goods[0], 'number' => $goods[1], 'points' => $goods[2], 'available' => true, 'image_path' => 'imgs/goods/' . $key . '.jpg']);
     }
 }
Exemplo n.º 9
0
 public function setReward(Request $request)
 {
     $input = $request->all();
     $data['work_id'] = $input['workId'];
     $data['province_award'] = $input['award'];
     Award::create($data);
 }
Exemplo n.º 10
0
 /**
  * Get all of the awards info by ID.
  *
  * @param int $awardId
  *
  * @return Collection
  */
 public function byId($awardId)
 {
     return Award::find($awardId);
 }