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 activity_product() { if (!empty($this->activity_type)) { $activity = Activity::find($this->activity_type); if (!empty($activity) && $activity->start_date <= date("Y-m-d H:i:s") && $activity->end_date >= date("Y-m-d H:i:s") && $activity->status == 1) { $class_dir = ActivityType::find($activity->type_id)->class_dir; $config = json_decode($activity->argc, true); } else { return $this; } } else { return $this; } return with(new $class_dir())->config($config)->product_decorate($this); }
public function activity_bonus($uid) { $activity_type = Product::find($this->pid)->activity_type; if (!empty($activity_type)) { $activity = Activity::find($activity_type); if (!empty($activity) && $activity->start_date <= date("Y-m-d H:i:s") && $activity->end_date >= date("Y-m-d H:i:s") && $activity->status == 1) { $class_dir = ActivityType::find($activity->type_id)->class_dir; $config = json_decode($activity->argc, true); } else { return ''; } } else { return ''; } $bonus_config = ['fid' => Product::find($this->pid)->fid, 'uid' => $uid, 'aid' => $activity_type]; return with(new $class_dir())->config($config)->bonus($bonus_config); }
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); } }
public function destroy(Request $request, $id) { empty($id) && !empty($request->input('id')) && ($id = $request->input('id')); $id = (array) $id; foreach ($id as $v) { $activity = Activity::destroy($v); } return $this->success('', count($id) > 5, compact('id')); }