/** * 获取成功的订单 * @return [type] [description] */ public function getSuccess() { $data = array('main' => url('/'), 'announce' => url('/announce'), 'category' => url('/category'), 'deliver' => url('/deliver'), 'good' => url('/good'), 'map' => url('/map'), 'shop_info' => url('/shop_info'), 'success' => url('/success'), 'widge_success' => array()); $shop_id = Auth::user()->shop_id; $orders = Order::where('shop_id', $shop_id)->where('state_of_shop', 3)->get(); $data['widge_success']['deal_count'] = count($orders); $data['widge_success']['deal'] = array(); $shop = Shop::find($shop_id); foreach ($orders as $order) { $comment = CommentOrder::where('order_id', $order->id)->get(); $one = array('deal_id' => $order->id, 'deal_statue' => $order->state, 'same_again' => '##', 'deal_again' => '##', 'shop_name' => $shop->name, 'deal_number' => $order->number, 'deal_time' => date('Y-m-d', $order->ordertime), 'deal_phone' => $shop->linktel, 'deliver_address' => $order->receive_address, 'deliver_phone' => $order->receive_phone, 'deliver_remark' => $order->beta, 'deal_speed' => isset($comment[0]) ? $comment[0]->speed : 0, 'deal_satisfied' => isset($comment[0]) ? $comment[0]->value : 0, 'good' => array(), 'others' => array(array('item_name' => '不知道', 'item_value' => '-5', 'item_amount' => '1', 'item_total' => '0'))); $one['total'] = $order->total; $menu_ids = array_count_values(explode(',', $order->order_menus)); foreach ($menu_ids as $menu_id => $amount) { $menuComment = CommentMenu::where('order_id', $order->id)->where('menu_id', $menu_id)->get(); $menu = Menu::find($menu_id); //var_dump($menuComment); $onemenu = array('goods_id' => $menu_id, 'goods_name' => $menu->title, 'goods_value' => $menu->price, 'goods_amount' => $amount, 'goods_total' => $amount * $menu->price, 'good_atisfied' => isset($menuComment[0]) ? $menuComment[0]->value : 0); array_push($one['good'], $onemenu); } array_push($data['widge_success']['deal'], $one); } return View::make("template.success.success")->with($data); //var_dump($data); }
/** * 获取商家的评论统计信息,在店铺页面指着店铺名称时所显示的那些信息、 * * 对应API:shop/blace/output/data * @param integer $sid 店铺ID * @return array 包含那些信息的ajax数据 */ public function getComment($sid) { $result = array(); $s_info = Shop::find($sid); $result['shop_id'] = $s_info->id; $result['place_id'] = '123'; // ------------------ $result['shop_logo'] = $s_info->pic; $result['shop_name'] = $s_info->name; $result['shop_type'] = $s_info->type; // 计算各种比例是有一点麻烦。。。 // shop表的id join 菜单表的id和shop_id join 评论表的menu_id和value,然后计算value在各个段的平均值。。。 $hehe = CommentMenu::join('menu', 'comment.menu_id', '=', 'menu.id')->select('comment.value')->where('menu.shop_id', '=', $sid); $total = count($hehe->get()); // 由于没有设置查询缓存,也只能这样子计算了 $min_5 = count($hehe->whereBetween('value', array(0.0, 5.0))->get()); $min_4 = count($hehe->whereBetween('value', array(0.0, 4.0))->get()); $min_3 = count($hehe->whereBetween('value', array(0.0, 3.0))->get()); $min_2 = count($hehe->whereBetween('value', array(0.0, 2.0))->get()); $min_1 = count($hehe->whereBetween('value', array(0.0, 1.0))->get()); $percent_1 = $min_1 / $total; $percent_2 = ($min_2 - $min_1) / $total; $percent_3 = ($min_3 - $min_2) / $total; $percent_4 = ($min_4 - $min_3) / $total; $percent_5 = ($min_5 - $min_4) / $total; $result['shop_level'] = ''; $result['shop_total'] = ''; $result['comment_count'] = ''; $result['shop_statement'] = ''; $result['shop_time'] = ''; $result['shop_address'] = ''; $result['deliver_begin'] = ''; $result['shop_distance'] = ''; $result['price_begin'] = ''; $result['is_collected'] = ''; return '------------------------------'; //return $result; }