public function destroy(Request $request, $id)
 {
     empty($id) && !empty($request->input('id')) && ($id = $request->input('id'));
     $id = (array) $id;
     foreach ($id as $v) {
         $activity = ActivityBonus::destroy($v);
     }
     return $this->success('', count($id) > 5, compact('id'));
 }
Example #2
0
 public function saveScore(Request $request)
 {
     $stores_ids = $this->user->stores->pluck('id');
     $this->_brands = Brand::join('store_brand as s', 's.bid', '=', 'brands.id')->whereIn('s.sid', $stores_ids)->get(['brands.*']);
     $fids = Product::whereIn('bid', $this->_brands->pluck('id'))->pluck('fid');
     $key = 'bonus_' . $this->user->getKey() . '_game';
     $times = intval(Cache::get($key, 0));
     $save_code_key = 'save_put_code_' . $this->user->getKey();
     $ver_code = $request->get('ver_code');
     if (session($save_code_key) == $ver_code && !empty($fids) && $times > 0) {
         $fids = array_unique((array) $fids);
         //把关注店铺,相关的厂商都加红包
         $score = $request->get('score');
         //分数
         if ($score < 1) {
             $data = ['err_msg' => '红包金额不能为空.'];
             return $this->failure(NULL, false, $data, true);
         }
         $type_id = $request->get('type_id');
         //活动id
         foreach ($fids as $fid) {
             $activity_bouns = new ActivityBonus();
             $activity_bouns->uid = $this->user->getKey();
             $activity_bouns->fid = $fid;
             $activity_bouns->activity_id = with(Activity::where('fid', $fid)->where('type_id', $type_id)->first())->id;
             $activity_bouns->bonus = intval($score) > 98 ? 98 : intval($score);
             $activity_bouns->status = 0;
             $activity_bouns->save();
         }
         Cache::decrement($key);
         session([$save_code_key => '']);
         //红包的个数
         $bonus_cnt = ActivityBonus::where('uid', $this->user->getKey())->where('status', 0)->count();
         $data = ['times' => --$times, 'bonus_cnt' => $bonus_cnt];
         return $this->success(NULL, false, $data);
     } else {
         $data = ['err_msg' => '暂时没添加相关活动。'];
         return $this->failure(NULL, false, $data, true);
     }
 }
Example #3
0
 function bonus($bonus_config)
 {
     //$fid,$uid,$aid
     static $show_bonus = false;
     $bonus = ActivityBonus::where("fid", $bonus_config['fid'])->where('uid', $bonus_config['uid'])->where('activity_id', 3)->where('status', 0)->get();
     if ($bonus->count() > 0 && $show_bonus == false) {
         $select_html = "红包:<select name=\"bonus_id\"><option value=\"0\">无</option>";
         foreach ($bonus as $bonus_item) {
             $select_html .= "<option value=\"" . $bonus_item->getKey() . "\">" . $bonus_item->bonus . "</option>";
         }
         $select_html .= "</select>";
         $show_bonus = true;
         return $select_html;
     }
     return '';
 }
Example #4
0
 public function bonus()
 {
     $bonus_str = "";
     if ($this->bonus_id > 0) {
         $bonus_str .= "&nbsp;&nbsp;&nbsp;&nbsp;红包抵扣:¥" . ActivityBonus::find($this->bonus_id)->bonus;
     }
     return $bonus_str;
 }