allStatus; return view('Yunshop\FightGroups::admin.order.index', ['data'=>json_encode($list)]); } // 列表字段 public function searchListFields() { return Order::uniacid()->select(['yz_order.*','yz_fight_groups_team_member.group_id', 'yz_fight_groups_team_member.level_id','yz_fight_groups_team_member.team_id', 'yz_fight_groups.title as group_title','mc_members.nickname as leader_name','mc_members.avatar','yz_fight_groups_level.member_num',]) ->with(['hasOnePayType', 'belongsToMember', 'hasManyOrderGoods' => function ($query) { $query->select('total', 'price', 'goods_price', 'title', 'thumb', 'order_id', 'goods_option_title'); }]); } // 价格统计 public function searchTotalPrice() { return Order::uniacid(); } public function searchWhere($search,$fight_groups_id,$fight_groups_title,$team_status,$leader_name,$order_sn,$status,$create_time) { $search = $search->leftJoin('yz_fight_groups_team_member','yz_order.id','=','yz_fight_groups_team_member.order_id') ->leftJoin('yz_fight_groups_level','yz_fight_groups_team_member.level_id','=','yz_fight_groups_level.id') ->leftJoin('yz_fight_groups','yz_fight_groups_team_member.group_id','=','yz_fight_groups.id') ->leftJoin('yz_fight_groups_team','yz_fight_groups_team_member.team_id','=','yz_fight_groups_team.id') ->leftJoin('mc_members','yz_fight_groups_team.leader_id','=','mc_members.uid') ->isPlugin() //->where('yz_order.is_member_deleted',0) ->where(app('OrderManager')->make('Order')->getTable() . '.is_member_deleted', 0) ->pluginId(); if (!empty($fight_groups_id)) { $search = $search->where('yz_fight_groups_team_member.group_id', $fight_groups_id); } if (!empty($fight_groups_title)) { $search = $search->where('yz_fight_groups.title', 'like', $fight_groups_title.'%'); } if (!empty($team_status) || $team_status === 0 || $team_status === "0") { $search = $search->where('yz_fight_groups_team.status', $team_status ); } if (!empty($leader_name)) { $search = $search->where('mc_members.nickname', 'like', $leader_name.'%' ); } if (!empty($order_sn)) { $search = $search->where('yz_order.order_sn', $order_sn ); } if (!empty($status) || $status === 0 || $status === "0") { $search = $search->where('yz_order.status', $status ); } if (!empty($create_time)) { $search = $search->whereBetween('yz_order.create_time', $create_time); } return $search; } // fight_groups_id,fight_groups_title,leader_name,order_sn,status,create_time public function search() { $page = (int)request()->page ? (int)request()->page : 1;//分页 $fight_groups_id = request()->fight_groups_id;// 活动编号 $fight_groups_title = request()->fight_groups_title;// 活动名称 $team_status = request()->team_status;// 团队状态 $leader_name = request()->leader_name;// 团长名称 $order_sn = request()->order_sn;// 订单号 $status = request()->status;// 订单状态 $create_time = request()->create_time;// 订单开始和结束时间 // 获取订单列表 $queryList = $this->searchListFields(); $queryList = $this->searchWhere($queryList,$fight_groups_id,$fight_groups_title,$team_status,$leader_name,$order_sn,$status,$create_time); $list = $queryList->orderBy('yz_order.created_at', 'desc')->paginate(static::PAGE_SIZE,['*'], 'page', $page)->toArray(); // 统计订单金额 $queryTotalPrice = $this->searchTotalPrice(); $queryTotalPrice = $this->searchWhere($queryTotalPrice,$fight_groups_id,$fight_groups_title,$team_status,$leader_name,$order_sn,$status,$create_time); $totalPrice = $queryTotalPrice->sum('yz_order.price'); $list['sum_price'] = !empty($totalPrice) ? $totalPrice : 0; /* $search = Order::uniacid()->select(['yz_order.*','yz_fight_groups_team_member.group_id', 'yz_fight_groups_team_member.level_id','yz_fight_groups_team_member.team_id', 'yz_fight_groups.title as group_title','mc_members.nickname as leader_name','mc_members.avatar','yz_fight_groups_level.member_num', ]) ->with(['hasOnePayType', 'belongsToMember', 'hasManyOrderGoods' => function ($query) { $query->select('total', 'price', 'goods_price', 'title', 'thumb', 'order_id', 'goods_option_title'); }]) ->leftJoin('yz_fight_groups_team_member','yz_order.id','=','yz_fight_groups_team_member.order_id') ->leftJoin('yz_fight_groups_level','yz_fight_groups_team_member.level_id','=','yz_fight_groups_level.id') ->leftJoin('yz_fight_groups','yz_fight_groups_team_member.group_id','=','yz_fight_groups.id') ->leftJoin('yz_fight_groups_team','yz_fight_groups_team_member.team_id','=','yz_fight_groups_team.id') ->leftJoin('mc_members','yz_fight_groups_team.leader_id','=','mc_members.uid') ->isPlugin() //->where('yz_order.is_member_deleted',0) ->where(app('OrderManager')->make('Order')->getTable() . '.is_member_deleted', 0) ->pluginId(); if (!empty($fight_groups_id)) { $search = $search->where('yz_fight_groups_team_member.group_id', $fight_groups_id); } if (!empty($fight_groups_title)) { $search = $search->where('yz_fight_groups.title', 'like', $fight_groups_title.'%'); } if (!empty($leader_name)) { $search = $search->where('mc_members.nickname', 'like', $leader_name.'%' ); } if (!empty($order_sn)) { $search = $search->where('yz_order.order_sn', $order_sn ); } if (!empty($status) || $status === 0 || $status === "0") { $search = $search->where('yz_order.status', $status ); } if (!empty($create_time)) { $search = $search->whereBetween('yz_order.create_time', $create_time); } $list = $search->orderBy('yz_order.created_at', 'desc')->paginate(static::PAGE_SIZE,['*'], 'page', $page)->toArray(); // 统计订单总金额 $list['sum'] = 0; foreach ($list['data'] as $order) { $list['sum'] += $order['price']; } */ return $this->successJson('成功',$list); } /** * @return string * @throws AppException * @throws \Throwable */ public function detail(){ $order = Order::orders()->with(['deductions', 'coupons', 'discounts', 'hasOnePayType', 'orderPays' => function ($query) { $query->with('payType'); }, 'hasManyOrderGoods'=> function ($query){ $query->with(['goods'=> function ($query){ $query->select(['id','goods_sn','product_sn','market_price','price','cost_price','status']); }]); }]); if (request()->has('order_id')) { $order = $order->find(request('order_id')); } if (request()->has('order_sn')) { $order = $order->where('order_sn', request('order_sn'))->first(); } if (!$order) { throw new AppException('未找到订单'); } if (!empty($order->express)) { $express = $order->express->getExpress($order->express->express_code, $order->express->express_sn); $dispatch['express_sn'] = $order->express->express_sn; $dispatch['company_name'] = $order->express->express_company_name; $dispatch['data'] = $express['data']; $dispatch['thumb'] = $order->hasManyOrderGoods[0]->thumb; $dispatch['tel'] = '95533'; $dispatch['status_name'] = $express['status_name']; } return view('Yunshop\FightGroups::admin.order.basicDetail', ['data' => json_encode($order)]); } /** * @return \Illuminate\Http\JsonResponse * @throws \app\common\exceptions\AppException */ public function pay() { $order = Order::find(request()->input('order_id')); $order->backendPay(); return $this->successJson(); } /** * @return \Illuminate\Http\JsonResponse * @throws \app\common\exceptions\AppException */ public function receive() { OrderService::orderReceive(['order_id'=>request()->input('order_id')]); return $this->successJson(); } /** * @return mixed * @throws AppException */ public function send() { /** * @var Order $order */ OrderService::orderSend(request()->only(['order_id','express_code','express_sn'])); return $this->successJson('成功'); } /** * @return \Illuminate\Http\JsonResponse * @throws \app\common\exceptions\AppException */ public function close() { /** * @var Order $order */ OrderService::orderClose(['order_id'=>request()->input('order_id')]); return $this->successJson('成功'); } }