public function special(Request $request, $activity_id = 0) { $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.*']); $pagesize = $request->input('pagesize') ?: $this->site['pagesize']['m']; $this->_input = $request->all(); $product = new Product(); //查找猴子捞月所有在线,有效活动id $now = date("Y-m-d H:i:s"); if (!empty($activity_id)) { $activity = Activity::find($activity_id); } elseif (!empty($request->get('type_id'))) { $fids = $product->newQuery()->whereIn('bid', $this->_brands->pluck('id'))->pluck('fid'); if (!empty($fids)) { $fids = array_unique((array) $fids); } $builder = Activity::whereIn('fid', $fids)->where('type_id', $request->get('type_id')); $activity = $builder->first(); $activity_id = $builder->pluck('id'); } else { return $this->failure(NULL); } if (empty($activity)) { return $this->failure('activity::activity.no_activity'); } elseif ($activity->start_date > $now || $activity->end_date < $now || $activity->status != 1) { return $this->failure('activity::activity.failure_activity'); } //查看当前以以和店铺 猴子捞月 活动所有商品 $builder = $product->newQuery()->with(['sizes', 'covers']); $this->_activity = $activity; $this->_table_data = $builder->whereIn('activity_type', (array) $activity_id)->whereIn('bid', $this->_brands->pluck('id'))->paginate($pagesize); return $this->view('activity::m.special'); }
public function classify(Request $request) { $search_key = $request->input('search_key'); $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.*']); $pagesize = $request->input('pagesize') ?: $this->site['pagesize']['m']; $this->_input = $request->all(); $product = new Product(); $builder = $product->newQuery()->with(['sizes', 'covers']); if (!empty($search_key)) { $builder->where('title', 'like', '%' . $search_key . '%'); } $this->_search_key = $search_key; $this->_table_data = $builder->whereIn('bid', $this->_brands->pluck('id'))->paginate($pagesize); return $this->view('m.classify'); }
public function index(Request $request, $sid = NULL, $redirect_url = NULL) { if (!empty($sid)) { $store = Store::find($sid); !empty($store) && $this->user->stores()->sync([$sid], FALSE); } if (empty($this->user->stores->count())) { return $this->failure('store.failure_follow'); } if (!empty($redirect_url)) { return redirect()->intended($redirect_url); } $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.*']); $pagesize = $request->input('pagesize') ?: config('site.pagesize.m', $this->site['pagesize']['common']); $this->_input = $request->all(); $product = new Product(); $builder = $product->newQuery()->with(['sizes', 'covers']); $this->_table_data = $builder->whereIn('bid', $this->_brands->pluck('id'))->paginate($pagesize); return $this->view('m.index'); }
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); } }