protected function check_meal($meal_id) { $database_meal = D('Meal'); $condition_meal['meal_id'] = $meal_id; $now_meal = $database_meal->field(true)->where($condition_meal)->find(); if (!empty($now_meal['image'])) { $meal_image_class = new meal_image(); $now_meal['see_image'] = $meal_image_class->get_image_by_path($now_meal['image'], $this->config['site_url'], 's'); } if (empty($now_meal)) { $this->error('商品不存在!'); } return $now_meal; }
public function mergoods() { $sid = intval($_GET['sid']); if ($this->merchant_store_data['have_meal'] != 1) { $this->error_tips('商家的主店铺没有开通' . $this->config['meal_alias_name'] . '功能!'); } $m_store_id = $this->merchant_store_data['store_id']; $ord = intval($_GET['ord']); switch ($ord) { case 1: $order = 'meal_id DESC'; break; case 2: $order = 'price ASC'; break; default: $order = 'meal_id DESC'; $ord = 0; break; } $where = array('store_id' => $m_store_id, 'status' => 1); if ($sid > 0) { $where['sort_id'] = $sid; } else { $sid = 0; } $meal_Db = D('Meal'); /*$_count = $meal_Db->where($where)->count(); import('@.ORG.common_page'); $p = new Page($_count, 20); $pagebar = $p->show(); $this->assign('pagebar', $pagebar); $meal_pro = D('Meal')->where($where)->order($order)->limit($p->firstRow . ',' . $p->listRows)->select(); */ $meal_pro = D('Meal')->where($where)->order($order)->select(); $meal_image_class = new meal_image(); foreach ($meal_pro as $kk => $vv) { $m['image'] = !empty($vv['image']) ? $meal_pro[$kk]['image'] = $meal_image_class->get_image_by_path($vv['image'], $this->config['site_url'], 's') : ''; } $meal_mulu = D('Meal_sort')->where(array('store_id' => $m_store_id))->order('sort ASC,sort_id DESC')->select(); $this->assign('ord', $ord); $this->assign('sortid', $sid); $this->assign('mstoreid', $m_store_id); $this->assign('meal_pro', $meal_pro); $this->assign('mealmulu', $meal_mulu); $this->display(); }
public function thissort() { $sort_id = intval($_GET['sort_id']); $meals = M("Meal")->where(array('store_id' => $this->store_id, 'sort_id' => $sort_id, 'status' => 1))->select(); /* 粉丝行为分析 */ $this->behavior(array('mer_id' => $this->mer_id, 'biz_id' => $sort_id)); $meal_image_class = new meal_image(); $html = ''; foreach ($meals as $meal) { $meal['image'] = $meal_image_class->get_image_by_path($meal['image'], $this->config['site_url'], 's'); $html .= '<dd><span class="count_zero" id="num_' . $meal['meal_id'] . '_1">0</span><div class="tupian">' . '<img src="' . $meal['image'] . '" onclick="htmlit(' . $meal['meal_id'] . ')">' . '<div class="add" data-foodid="' . $meal['meal_id'] . '_1">' . '<h3>' . $meal['name'] . '</h3>' . '<em>' . $meal['price'] . '元/' . $meal['unit'] . '</em>' . '<div onclick="addProduct(\'' . $meal['meal_id'] . '\',\'1\',\'' . $meal['name'] . '\',\'' . $meal['price'] . '\',\'' . $sort_id . '\',1);" class="reduce2"><span class="ico_increase">加一份</span></div>' . '<div>' . '<a href="javascript:reduceProduct(\'' . $meal['meal_id'] . '\',\'1\',1,\'' . $sort_id . '\');" class="reduce" id="del_' . $meal['meal_id'] . '_1" style="display: none;"><span class="ico_reduce">减一份</span></a>' . '</div></div></div></dd>'; } echo $html; }
/** * 确认购物车 */ public function cart() { $this->isLogin(); $isclean = $this->_get('isclean', 'trim'); $orid = $this->_get('orid', 'intval'); if ($this->check_order($orid)) { $this->assign('action_url', U('Food/saveorder', array('mer_id' => $this->mer_id, 'store_id' => $this->store_id, 'orid' => $orid))); $level_off = false; if (!empty($this->user_level) && !empty($this->leveloff) && !empty($this->user_session) && isset($this->user_session['level'])) { /****type:0无优惠 1百分比 2立减*******/ if (isset($this->leveloff[$this->user_session['level']]) && isset($this->user_level[$this->user_session['level']])) { $level_off = $this->leveloff[$this->user_session['level']]; if ($level_off['type'] == 1) { $level_off['offstr'] = '按此次总价' . $level_off['vv'] . '%来结算'; } elseif ($level_off['type'] == 2) { $level_off['offstr'] = '此次总价立减' . $level_off['vv'] . '元'; } } } $this->assign('level_off', $level_off); $this->assign('orid', $orid); } else { $this->assign('action_url', U('Food/sureorder', array('mer_id' => $this->mer_id, 'store_id' => $this->store_id))); $this->assign('orid', 0); } if ($isclean == 1) { $_SESSION[$this->session_index] = ''; $disharr = ''; } else { $disharr = unserialize($_SESSION[$this->session_index]); } if (!empty($disharr)) { $idarr = array_keys($disharr); $meal_image_class = new meal_image(); $dish = M("Meal")->where(array('store_id' => $this->store_id, 'meal_id' => array('in', $idarr), 'status' => 1))->select(); foreach ($dish as $val) { $val['image'] = $meal_image_class->get_image_by_path($val['image'], $this->config['site_url'], 's'); $disharr[$val['meal_id']] = array_merge($disharr[$val['meal_id']], $val); } } // echo "<pre/>"; // print_r($disharr);die; $allmark = $_SESSION["allmark" . $this->store_id . $this->mer_id]; $this->assign('allmark', $allmark); $this->assign('ordishs', $disharr); $this->display(); die; // if (IS_POST) { // $phone = isset($_POST['phone']) ? htmlspecialchars($_POST['phone']) : ''; // $name = isset($_POST['name']) ? htmlspecialchars($_POST['name']) : ''; // $address = isset($_POST['address']) ? htmlspecialchars($_POST['address']) : ''; // $note = isset($_POST['note']) ? htmlspecialchars($_POST['note']) : ''; // if (empty($name)) { // $this->error('联系人不能为空'); // } // if (empty($phone)) { // $this->error('联系电话不能为空'); // } // $goodsData = isset($_POST['goodsData']) ? htmlspecialchars($_POST['goodsData']) : ''; // if (empty($goodsData)) { // $this->error('您还没有点菜'); // } // $products = explode(";", $goodsData); // $dish = array(); // $meal = array(); // foreach ($products as $p) { // $t = explode(",", $p); // $dish[$t[0]] = $t[1]; // $meal[] = $t[0]; // } // $total = $price = 0; // if ($meal) { // $meals = M("Meal")->where(array('meal_id' => array('in', $meal), 'store_id' => $this->store_id))->select(); // $info = array(); // foreach ($meals as $m) { // $info[] = array('id' => $m['meal_id'],'name' => $m['name'], 'num' => $dish[$m['meal_id']], 'price' => $m['price']); // $total += $dish[$m['meal_id']]; // $price += $dish[$m['meal_id']] * $m['price']; // } // } // $data = array('mer_id' => $this->mer_id, 'store_id' => $this->store_id, 'name' => $name, 'phone' => $phone, 'address' => $address, 'note' => $note, 'info' => serialize($info), 'dateline' => time(), 'total' => $total, 'price' => $price); // $data['orderid'] = $this->mer_id . $this->store_id . date("YmdHis") . rand(1000000, 9999999); // // $data['wecha_id'] = $this->wecha_id; // $data['uid'] = $this->user_session['uid']; // $data['note'] = isset($_POST['note']) ? htmlspecialchars($_POST['note']) : ''; // $orderid = D("Meal_order")->add($data); // if ($orderid) { // if ($this->user_session['openid']) { // $keyword2 = ''; // $pre = ''; // foreach (unserialize($data['info']) as $menu) { // $keyword2 .= $pre . $menu['name'] . ':' . $menu['price'] . '*' . $menu['num']; // $pre = '\n\t\t\t'; // } // $href = C('config.site_url').'/wap.php?c=Meal&a=detail&orderid='. $orderid . '&mer_id=' . $data['mer_id'] . '&store_id=' . $data['store_id']; // $model = new templateNews(C('config.wechat_appid'), C('config.wechat_appsecret')); // $model->sendTempMsg('OPENTM201682460', array('href' => $href, 'wecha_id' => $this->user_session['openid'], 'first' => '您好,您的订单已生成', 'keyword3' => $orderid, 'keyword1' => date('Y-m-d H:i:s'), 'keyword2' => $keyword2, 'remark' => '您的该次订餐下单成功,感谢您的使用!')); // } // $msg = array(); // $msg['user_name'] = $data['name']; // $msg['user_phone'] = $data['phone']; // $msg['user_address'] = $data['address']; // $msg['user_message'] = $data['note']; // $msg['buy_time'] = date("Y-m-d H:i:s", $data['dateline']); // $msg['goods_list'] = $info; // $msg['goods_count'] = $data['total']; // $msg['goods_price'] = $data['price']; // $msg['orderid'] = $orderid; // $msg['pay_status'] = ''; // $msg['pay_type'] = ''; // $msg['store_name'] = $this->_store['name']; // $msg['store_phone'] = $this->_store['phone']; // $msg['store_address'] = $this->_store['adress']; // $msg = ArrayToStr::array_to_str($msg, 0, $this->config['print_format']); // $op = new orderPrint($this->config['print_server_key'], $this->config['print_server_topdomain']); // $op->printit($this->mer_id, $this->store_id, $msg, 0); // /* 粉丝行为分析 */ // $this->behavior(array('mer_id' => $this->mer_id, 'biz_id' => $orderid)); // redirect(U('Pay/check',array('order_id' => $orderid, 'type'=>'meal'))); // //$this->success('订餐成功', U("Meal/detail", array('mer_id' => $this->mer_id, 'store_id' => $this->store_id, 'orderid' => $orderid))); // } // } else { // $now_group['user_adress'] = D('User_adress')->get_one_adress($this->user_session['uid'],intval($_GET['adress_id'])); // $this->assign('now_group',$now_group); // $sorts = M("Meal_sort")->where(array('store_id' => $this->store_id))->select(); // $temp = array(); // foreach ($sorts as $sort) { // $temp[$sort['sort_id']] = $sort['sort_name']; // } // $this->assign("categories", json_encode($temp)); // $this->assign('class', 3); // $this->assign('title', '购物车'); // $this->display(); // } }
/** * 订单信息确认 */ public function sureOrder() { $this->isLogin(); if (empty($this->_store)) { $this->error("不存在的商家店铺!", U('Takeout/index', array('mer_id' => $this->mer_id, 'store_id' => $this->store_id))); } // $merchant_store_meal = M("Merchant_store_meal")->where(array('store_id' => $this->store_id, 'mer_id' => $this->mer_id))->find(); // $merchant_store = array_merge($this->_store, $merchant_store_meal); // $this->assign('store', $merchant_store); $dishtmp = $_POST['dish']; if (empty($dishtmp)) { $disharr = unserialize($_SESSION[$this->session_index]); } else { $disharr = array(); foreach ($dishtmp as $id => $num) { $num = $num ? intval($num) : 0; $num && ($disharr[$id] = array('id' => $id, 'num' => $num)); } } if (empty($disharr)) { $this->error('您尚未点菜!', U('Takeout/menu', array('mer_id' => $this->mer_id, 'store_id' => $this->store_id))); } $_SESSION[$this->session_index] = serialize($disharr); $merchant_store_meal = M("Merchant_store_meal")->where(array('store_id' => $this->store_id, 'mer_id' => $this->mer_id))->find(); $merchant_store = array_merge($this->_store, $merchant_store_meal); $now_time = time(); $flag = true; foreach ($merchant_store['office_time'] as $time) { $open = strtotime(date("Y-m-d ") . $time['open'] . ':00'); $close = strtotime(date("Y-m-d ") . $time['close'] . ':00'); if ($open < $now_time && $now_time < $close) { $flag = false; break; } } if ($flag) { $this->error('抱歉!尚未不在营业时间内!', U('Takeout/index', array('mer_id' => $this->mer_id, 'store_id' => $this->store_id))); } $ids = array_keys($disharr); $meal_image_class = new meal_image(); $temp = M("Meal")->where(array('store_id' => $this->store_id, 'meal_id' => array('in', $ids), 'status' => 1))->select(); foreach ($temp as $m) { if (isset($disharr[$m['meal_id']])) { $m['num'] = $disharr[$m['meal_id']]['num']; } else { $m['num'] = 0; } $m['image'] = $meal_image_class->get_image_by_path($m['image'], $this->config['site_url'], 's'); $meals[] = $m; } /* 粉丝行为分析 */ $this->behavior(array('mer_id' => $this->mer_id, 'biz_id' => $this->store_id, 'keyword' => strval($_GET['keywords']))); $now_group['user_adress'] = D('User_adress')->get_one_adress($this->user_session['uid'], intval($_GET['adress_id'])); $time_list = array(); $hour = date("G"); $minute = intval(date("i")); $stat = $minute > 45 ? '00' : ($minute > 30 ? 45 : ($minute > 15 ? 30 : 15)); $stat == '00' && $hour++; $flag = false; for ($i = $hour; $i < 24; $i++) { foreach (array('00', '15', '30', '45') as $m) { if ($i == $hour) { if ($m == $stat) { $flag = true; } if ($flag) { $i = $i < 10 ? '0' . $i : $i; $time_list[] = $i . ':' . $m; } } else { $i = $i < 10 ? '0' . $i : $i; $time_list[] = $i . ':' . $m; } } } $this->assign('time_list', $time_list); $this->assign('now_group', $now_group); $this->assign('meals', $meals); $this->display(); }
public function index() { //判断登录 if (empty($this->user_session)) { // $this->assign('jumpUrl',U('Index/Login/index')); // $this->error('请先登录!'); } //右侧广告 $index_right_adver = D('Adver')->get_adver_by_key('index_right', 3); $this->assign('index_right_adver', $index_right_adver); //导航条 $web_index_slider = D('Slider')->get_slider_by_key('web_slider'); $this->assign('web_index_slider', $web_index_slider); $all_category_list = D('Group_category')->get_category(); $this->assign('all_category_list', $all_category_list); $store_id = intval($_GET['store_id']); //店铺信息 $store = D('Merchant_store')->where(array('store_id' => $store_id))->find(); if (empty($store)) { $this->group_noexit_tips(); } $store['office_time'] = unserialize($store['office_time']); $pre = $str = ''; $store['state'] = 0; $now_time = time(); foreach ($store['office_time'] as $time) { $str = $pre . $time['open'] . '-' . $time['close']; $pre = ','; $open = strtotime(date("Y-m-d ") . $time['open'] . ':00'); $close = strtotime(date("Y-m-d ") . $time['close'] . ':00'); if ($open < $now_time && $now_time < $close) { $store['state'] = 1; //根据营业时间判断 } } $store['office_time'] = $str; $store_image_class = new store_image(); $store['images'] = $store_image_class->get_allImage_by_path($store['pic_info']); $store_meal = D('Merchant_store_meal')->where(array('store_id' => $store_id))->find(); $store_meal['deliver_time'] = unserialize($store['deliver_time']); $store_meal['width'] = 72 / 5 * $store_meal['score_mean']; $store = array_merge($store, $store_meal); //商家信息 $merchant = M("Merchant")->where(array('mer_id' => $store['mer_id']))->find(); $merchant_image = new merchant_image(); $merchant['merchant_pic'] = $merchant_image->get_allImage_by_path($merchant['pic_info']); $sorts = M("Meal_sort")->where(array('store_id' => $store_id))->order('sort ASC')->select(); $list = $temp = array(); $id = 0; $sids = array(); foreach ($sorts as $sort) { if ($sort['is_weekshow']) { $week = explode(",", $sort['week']); if (in_array(date("w"), $week)) { $sids[] = $sort['sort_id']; } } else { $sids[] = $sort['sort_id']; } } $sort_type = isset($_GET['sort_type']) ? intval($_GET['sort_type']) : 0; $this->assign('sort_type', $sort_type); switch ($sort_type) { case 0: $order = 'meal_id DESC'; break; case 1: $order = 'price DESC'; break; case 2: $order = 'price ASC'; break; } //菜单信息 $meals = M('Meal')->field(true)->where(array('store_id' => $store_id, 'sort_id' => array('in', $sids), 'status' => 1))->order($order)->select(); $meal_image_class = new meal_image(); $txt = $pic = array(); foreach ($meals as &$m) { $m['image'] = $meal_image_class->get_image_by_path($m['image'], $this->config['site_url'], 's'); // $temp[$m['sort_id']] = isset($temp[$m['sort_id']]) ? $temp[$m['sort_id']] : array(); // if ($m['image']) { // array // } $pic[$m['sort_id']] = isset($pic[$m['sort_id']]) ? $pic[$m['sort_id']] : array(); $txt[$m['sort_id']] = isset($txt[$m['sort_id']]) ? $txt[$m['sort_id']] : array(); $lst[$m['sort_id']] = isset($lst[$m['sort_id']]) ? $lst[$m['sort_id']] : array(); if ($m['image']) { $pic[$m['sort_id']][] = $m; } else { $txt[$m['sort_id']][] = $m; } $lst[$m['sort_id']][] = $m; } $list = array(); foreach ($sorts as &$s) { $s['meals']['pic'] = isset($pic[$s['sort_id']]) ? $pic[$s['sort_id']] : ''; $s['meals']['txt'] = isset($txt[$s['sort_id']]) ? $txt[$s['sort_id']] : ''; $s['meals']['list'] = isset($lst[$s['sort_id']]) ? $lst[$s['sort_id']] : ''; } //被收藏的次数 $collect_count = D('User_collect')->where(array('type' => 'meal_detail', 'id' => $store_id))->count(); $is_collect = 0; if ($collect = D('User_collect')->where(array('type' => 'meal_detail', 'id' => $store_id, 'uid' => $this->user_session['uid']))->find()) { $is_collect = 1; } $this->assign('collect_count', $collect_count); $this->assign('is_collect', $is_collect); //菜品分类信息 // $sorts = M('Meal_sort')->where(array('store_id' => $store_id))->select(); $area = M("Area")->where(array('area_id' => $store['circle_id']))->find(); $this->assign('area', $area); $this->assign('merchant', $merchant); $this->assign('store', $store); $this->assign('sorts', $sorts); $this->display(); }