input('page'); $pageSize = 20; if($page<=0){ $page = 1; } $offset = ($page-1) * $pageSize; $self_role = session('role_name'); if($self_role == '超级管理员' || $self_role == '团队主管' || $self_role == '管理员' || $self_role == '售后管理员'){ $admin_id = $request->input('admin_id'); $search_admin = 1; }else{ $admin_id = session('admin_id'); $search_admin = 0; } $team_id = $request->input('team_id'); #只能看自己团队的 if($self_role != '超级管理员' && $self_role != '售后管理员'){ $self_id = session('admin_id'); $team_id = DB::table('admin')->where('id', $self_id)->pluck('team_id'); } //假如有团队筛选,检索销售队员 $sale_ids = null; if($team_id>0){ $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id'); } $stime = $request->input('stime'); $etime = $request->input('etime'); $receiverName = trim($request->input('receiverName')); $receiverMobile = trim($request->input('receiverMobile')); $status = $request->input('status'); $id = (int)$request->input('id'); if($status === null){ $status = -1; } if($etime){ $etime = $etime. ' 23:59:59'; } $count = Order::where(function($query) use($admin_id, $stime, $etime, $receiverName, $receiverMobile, $self_role, $sale_ids, $status, $id){ if($admin_id) $query->where('admin_id', $admin_id); if($stime) $query->where('createTime', '>=', $stime); if($etime) $query->where('createTime', '<=', $etime); if($receiverName) $query->where('receiverName', 'like', $receiverName . '%'); if($receiverMobile) $query->where('receiverMobile', $receiverMobile); if($self_role == '管理员') $query->where('status','>',0); if(!empty($sale_ids)) $query->whereIn('admin_id', $sale_ids); if(($status>=0)) $query->where('status', $status); if(($id>0)) $query->where('id', $id); })->where('is_del',0)->count(); if ($count > 1) { // 总页数 $pages = ceil($count/$pageSize); }else{ // 总页数 $pages = 1; } $result = Order::where(function($query) use($admin_id, $stime, $etime, $receiverName, $receiverMobile, $self_role, $sale_ids, $status, $id){ if($admin_id) $query->where('admin_id', $admin_id); if($stime) $query->where('createTime', '>=', $stime); if($etime) $query->where('createTime', '<=', $etime); if($receiverName) $query->where('receiverName', 'like', $receiverName . '%'); if($receiverMobile) $query->where('receiverMobile', $receiverMobile); if($self_role == '管理员') $query->where('status','>',0); if(!empty($sale_ids)) $query->whereIn('admin_id', $sale_ids); if(($status>=0)) $query->where('status', $status); if(($id>0)) $query->where('id', $id); })->where('is_del',0)->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get(); $result = json_decode(json_encode($result),true); $status_arr = array( 0 => '已录入', 1 => '待审核', 2 => '已审核', 3 => '已发货', ); foreach($result as $k=>&$v){ /* //获取商品信息 $v['goods'] = ''; $goods = DB::table('order_goods')->where('outerParentCode', $v['outerCode'])->get(); foreach($goods as $item){ $v['goods'][] = $item->goodsName.'  单价:¥'.$item->price.'  件数:'.$item->quantity.''; } */ #加粉时间 $fanTime = DB::table('customers')->select('fanTime')->where('phone', $v['receiverMobile'])->first(); $v['fanTime'] = isset($fanTime->fanTime) ? $fanTime->fanTime : ''; $v['receiverMobile'] = substr($v['receiverMobile'], 0, 3).'****'.substr($v['receiverMobile'], 7); #获取状态机 if($self_role == '销售' && !in_array($v['status'], [0]) ){ $v['enable_status'] = []; }else{ $v['enable_status'] = $this->getEnableStatus($v['status']); } $v['status_name'] = $status_arr[$v['status']]; } #销售筛选 //$saler_ids = DB::table('admin_role')->where('role_name', '销售')->lists('user_id'); $adminList = DB::table('admin')->select('id', 'realname', 'username')->where(function($query) use($team_id){ if($team_id>0) $query->where('team_id', $team_id); })->where('id','>', 1)->get(); $adminList = json_decode(json_encode($adminList), true); return view('order/orderlist', ['result' =>$result, 'page' =>$page, 'count' =>$count, 'pages' =>$pages, 'admin_id' =>$admin_id, 'team_id' =>$team_id, 'stime' =>$stime, 'etime' =>$etime, 'adminlist' =>$adminList, 'search_admin' =>$search_admin, 'self_role' =>$self_role, 'receiverName' =>$receiverName, 'receiverMobile' =>$receiverMobile, 'status' =>$status, 'id' =>$id, 'last_url' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], ]); } /** * 仓库管理员订单列表 */ public function warehouse(Request $request){ $page = (int)$request->input('page'); $pageSize = 20; if($page<=0){ $page = 1; } $offset = ($page-1) * $pageSize; $admin_id = $request->input('admin_id'); $search_admin = 1; $self_role = session('role_name'); if($self_role == 'A仓库管理员'){ $warehouse = 1; }elseif($self_role == 'B仓库管理员'){ $warehouse = 2; }else{ $warehouse = 0; } $stime = $request->input('stime'); $etime = $request->input('etime'); $delivery_type = (int)$request->input('delivery_type'); //发货状态 0到发货时间(未填物流信息) 2到发货时间全部 $receiverName = trim($request->input('receiverName')); $receiverMobile = trim($request->input('receiverMobile')); $id = (int)$request->input('id'); //仓库管理员只能看到 918之后的数据 $_start = '2019-09-18'; //仓库管理员只能看到已审核订单 $today_date = date('Y-m-d'); $count = Order::where(function($query) use($admin_id, $stime, $etime, $today_date, $delivery_type, $receiverName, $receiverMobile, $_start, $id){ if($admin_id) $query->where('admin_id', $admin_id); if($stime) $query->where('createTime', '>=', $stime); if($etime) $query->where('createTime', '<=', $etime); if($delivery_type==0) $query->where('logistics_id', '=', ''); if($receiverName) $query->where('receiverName', 'like', $receiverName . '%'); if($receiverMobile) $query->where('receiverMobile', $receiverMobile); if($id>0) $query->where('id', $id); $query->where('createTime', '>=', $_start); })->where('is_del',0)->where('warehouse', $warehouse)->where('status', '>', 1)->where('delivery_date', '<=', $today_date)->count(); if ($count > 1) { // 总页数 $pages = ceil($count/$pageSize); }else{ // 总页数 $pages = 1; } $result = Order::where(function($query) use($admin_id, $stime, $etime, $today_date, $delivery_type, $receiverName, $receiverMobile, $_start, $id){ if($admin_id) $query->where('admin_id', $admin_id); if($stime) $query->where('createTime', '>=', $stime); if($etime) $query->where('createTime', '<=', $etime); if($delivery_type==0) $query->where('logistics_id', '=', ''); if($receiverName) $query->where('receiverName', 'like', $receiverName . '%'); if($receiverMobile) $query->where('receiverMobile', $receiverMobile); $query->where('createTime', '>=', $_start); if($id>0) $query->where('id', $id); })->where('is_del',0)->where('warehouse', $warehouse)->where('status', '>', 1)->where('delivery_date', '<=', $today_date)->orderBy('verify_time', 'asc')->offset($offset)->limit($pageSize)->get(); $result = json_decode(json_encode($result),true); $yestoday = date('Y-m-d', strtotime('-1 day')); //获取超时未发订单 $order_overtime = Order::where('is_del',0)->where('warehouse', $warehouse)->where('status', '>', 1)->where('delivery_date', '<', $yestoday)->where('createTime', '>=', $_start)->where('logistics_id', '=', '')->lists('id'); $overtime = []; if(!empty($order_overtime)){ $overtime['list'] = json_decode(json_encode($order_overtime), true); $overtime['count'] = count($order_overtime); } $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get(); $adminList = json_decode(json_encode($adminList), true); return view('order/warehouselist', ['result' =>$result, 'page' =>$page, 'count' =>$count, 'pages' =>$pages, 'admin_id' =>$admin_id, 'stime' =>$stime, 'etime' =>$etime, 'delivery_type' =>$delivery_type, 'adminlist' =>$adminList, 'receiverName' =>$receiverName, 'receiverMobile' =>$receiverMobile, 'id' =>$id, 'today' =>$today_date, 'yestoday' => $yestoday, 'overtime' => $overtime, ]); } /** * 预售订单列表 */ public function predictOrder(Request $request){ $page = (int)$request->input('page'); $pageSize = 20; if($page<=0){ $page = 1; } $offset = ($page-1) * $pageSize; $self_role = session('role_name'); if($self_role == '超级管理员' || $self_role == '团队主管' || $self_role == '管理员' || $self_role == '售后管理员'){ $admin_id = $request->input('admin_id'); $search_admin = 1; }else{ $admin_id = session('admin_id'); $search_admin = 0; } $team_id = $request->input('team_id'); #只能看自己团队的 if($self_role != '超级管理员' && $self_role != '售后管理员'){ $self_id = session('admin_id'); $team_id = DB::table('admin')->where('id', $self_id)->pluck('team_id'); } //假如有团队筛选,检索销售队员 $sale_ids = null; if($team_id>0){ $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id'); } $stime = $request->input('stime'); $etime = $request->input('etime'); $receiverName = trim($request->input('receiverName')); $receiverMobile = trim($request->input('receiverMobile')); $status = $request->input('status'); $if_all = (int)$request->input('if_all'); if($status === null){ $status = -1; } //预售逻辑 -> 预发货时间大于下单时间 $today = date('Y-m-d'); //DB::connection()->enableQueryLog(); $count = Order::where(function($query) use($admin_id, $stime, $etime, $receiverName, $receiverMobile, $self_role, $sale_ids, $status, $if_all, $today){ if($admin_id) $query->where('admin_id', $admin_id); if($stime) $query->where('createTime', '>=', $stime); if($etime) $query->where('createTime', '<=', $etime); if($receiverName) $query->where('receiverName', 'like', $receiverName . '%'); if($receiverMobile) $query->where('receiverMobile', $receiverMobile); if($self_role == '管理员') $query->where('status','>',0); if(!empty($sale_ids)) $query->whereIn('admin_id', $sale_ids); if(($status>=0)) $query->where('status', $status); if(!$if_all) $query->where('delivery_date','>=',$today); })->where('is_del',0)->whereRaw('delivery_date>createTime')->count(); //print_r(DB::getQueryLog());exit; if ($count > 1) { // 总页数 $pages = ceil($count/$pageSize); }else{ // 总页数 $pages = 1; } $result = Order::where(function($query) use($admin_id, $stime, $etime, $receiverName, $receiverMobile, $self_role, $sale_ids, $status, $if_all, $today){ if($admin_id) $query->where('admin_id', $admin_id); if($stime) $query->where('createTime', '>=', $stime); if($etime) $query->where('createTime', '<=', $etime); if($receiverName) $query->where('receiverName', 'like', $receiverName . '%'); if($receiverMobile) $query->where('receiverMobile', $receiverMobile); if($self_role == '管理员') $query->where('status','>',0); if(!empty($sale_ids)) $query->whereIn('admin_id', $sale_ids); if(($status>=0)) $query->where('status', $status); if(!$if_all) $query->where('delivery_date','>=',$today); })->where('is_del',0)->whereRaw('delivery_date>createTime')->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get(); $result = json_decode(json_encode($result),true); $status_arr = array( 0 => '已录入', 1 => '待审核', 2 => '已审核', 3 => '已发货', ); foreach($result as $k=>&$v){ /* //获取商品信息 $v['goods'] = ''; $goods = DB::table('order_goods')->where('outerParentCode', $v['outerCode'])->get(); foreach($goods as $item){ $v['goods'][] = $item->goodsName.'  单价:¥'.$item->price.'  件数:'.$item->quantity.''; } */ #加粉时间 $fanTime = DB::table('customers')->select('fanTime')->where('phone', $v['receiverMobile'])->first(); $v['fanTime'] = isset($fanTime->fanTime) ? $fanTime->fanTime : ''; $v['receiverMobile'] = substr($v['receiverMobile'], 0, 3).'****'.substr($v['receiverMobile'], 7); #获取状态机 if($self_role == '销售' && !in_array($v['status'], [0]) ){ $v['enable_status'] = []; }else{ $v['enable_status'] = $this->getEnableStatus($v['status']); } $v['status_name'] = $status_arr[$v['status']]; } #销售筛选 //$saler_ids = DB::table('admin_role')->where('role_name', '销售')->lists('user_id'); $adminList = DB::table('admin')->select('id', 'realname', 'username')->where(function($query) use($team_id){ if($team_id>0) $query->where('team_id', $team_id); })->where('id','>', 1)->get(); $adminList = json_decode(json_encode($adminList), true); return view('order/predictorderlist', ['result' =>$result, 'page' =>$page, 'count' =>$count, 'pages' =>$pages, 'admin_id' =>$admin_id, 'team_id' =>$team_id, 'stime' =>$stime, 'etime' =>$etime, 'adminlist' =>$adminList, 'search_admin' =>$search_admin, 'self_role' =>$self_role, 'receiverName' =>$receiverName, 'receiverMobile' =>$receiverMobile, 'status' =>$status, 'if_all' =>$if_all, 'last_url' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], ]); } /** * 添加订单 * @return \Illuminate\View\View */ public function ordercreate(Request $request) { $catelist = DB::table('goods_category')->select(DB::raw('distinct goods_category_name'))->lists('goods_category_name'); $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get(); $teamList = DB::table('teams')->select('id', 'name')->get(); $teamList = json_decode(json_encode($teamList), true); $adminList = json_decode(json_encode($adminList), true); $self_role = session('role_name'); $createTime = date('Y-m-d H:i:s'); return view('order/ordercreate', ['categorylist' => $catelist, 'adminlist'=>$adminList, 'teamlist'=>$teamList, 'self_role'=>$self_role, 'createTime'=>$createTime, 'last_url' => $_SERVER['HTTP_REFERER']]); } /** * 分组管理-进行添加操作 * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function orderstore(Request $request) { $this->validate($request, [ 'customerName' => 'required|between:1,6', 'receiverName' => 'required|between:1,6', 'receiverMobile' => 'required|regex:/^1[3456789]\d{9}$/', 'fanTime' => 'required|date', 'receiverState' => 'required|between:1,5', 'receiverCity' => 'required|between:1,10', 'receiverAddress' => 'required', 'delivery_date' => 'required|date', 'createTime' => 'required|date', 'receivedAmount' => 'required|numeric|min:1', 'goods_note' => 'required|min:1', 'warehouse' => 'required|integer|min:1', ], [ 'customerName.required' => '买家姓名不能为空', 'customerName.between' => '买家姓名不能超过6个字符', 'receiverName.required' => '收货人不能为空', 'receiverName.between' => '收货人不能超过6个字符', 'receiverMobile.required' => '收货人手机号不能为空', 'receiverMobile.regex' => '收货人手机号格式有误', 'fanTime.required' => '加粉时间不能为空', 'receiverState.required' => '省不能为空', 'receiverState.between' => '省填写有误', 'receiverCity.required' => '市不能为空', 'receiverCity.between' => '市填写有误', 'receiverAddress.required' => '详细地址不能为空', 'delivery_date.required' => '预发货时间不能为空', 'createTime.required' => '下单时间不能为空', 'receivedAmount.required' => '付款金额不能为空', 'receivedAmount.numeric' => '付款金额必须为数字', 'goods_note.required' => '商品信息不能为空', 'warehouse.required' => '仓库必须选择', 'warehouse.min' => '仓库必须选择', ]); //数据库-新增数据 $order = array(); $order['eshopCode'] = '99|34881'; //默认 $order['outerCode'] = Order::createOuterCode();//随机生成 $order['status'] = (int)$request->input('status'); $order['customerName'] = trim($request->input('customerName')); //买家名称 $order['shippingType'] = '卖家包邮'; $order['expressCompanyCode'] = '10084'; $order['expressCompanyName'] = '顺丰快递'; $order['receiverName'] = trim($request->input('receiverName')); //收件人 $order['receiverMobile'] = trim($request->input('receiverMobile')); //收件人手机 $order['receiverPhone'] = trim($request->input('receiverMobile')); //收件人手机 $order['receiverState'] = trim($request->input('receiverState')); //省份 $order['receiverCity'] = trim($request->input('receiverCity')); //市 #省市格式处理 $order['receiverState'] = str_replace(['省', '市'], '', $order['receiverState']); $order['receiverCity'] = str_replace('市', '', $order['receiverCity']); $order['receiverDistrict'] = $request->input('receiverDistrict'); //区 $order['receiverStreet'] = $request->input('receiverStreet'); //街道 $order['receiverAddress'] = trim($request->input('receiverAddress')); //详细地址 $order['buyerPostageFee'] = 0; //买家邮费 $order['discountFee'] = 0; //订单优惠 $order['adjustFee'] = 0; //订单调价 $order['serviceFee'] = 0; //服务费 $order['paymentMethod'] = '在线付款'; $order['paymentType'] = '网银'; $order['paymentAccount'] = '18322223333'; // 付款账号,暂时默认写死 $order['paymentTime'] = date('Y-m-d H:i:s'); // 付款时间 $order['receivedAmount'] = trim($request->input('receivedAmount')); //付款金额 $order['buyerMemo'] = trim($request->input('buyerMemo', '')); // 买家备注 $order['sellerMemo'] = trim($request->input('sellerMemo', '')); // 卖家备注 $order['createTime'] = !empty($request->input('createTime')) ? $request->input('createTime') : date('Y-m-d H:i:s'); // 订单创建时间 $order['modifyTime'] = date('Y-m-d H:i:s'); // 订单修改时间 $order['goods_note'] = trim($request->input('goods_note')); if($request->input('cost')) $order['cost'] = trim($request->input('cost')); //成本 $order['logistics_id'] = trim($request->input('logistics_id')); //物流单号 $order['is_refund'] = (int)$request->input('is_refund'); //是否退过单 if($request->input('refund_price')) $order['refund_price'] = trim($request->input('refund_price')); //应该退补差价 $order['is_fugou'] = (int)$request->input('is_fugou'); //是否复购 $order['warehouse'] = (int)$request->input('warehouse'); //仓库 $order['delivery_date'] = !empty($request->input('delivery_date')) ? $request->input('delivery_date') : date('Y-m-d'); //发货日期 $order['order_status'] = (int)$request->input('order_status'); $order['payment_type'] = (int)$request->input('payment_type'); //支付方式 //商品信息 /* $g_info = trim($request->input('g_info'),';'); //var_dump($g_info); $g_info = explode(';' , $g_info); $goods_info = array(); foreach($g_info as $k=>$info){ $info = explode(':', $info); $goods_info[$k]['id'] = $info[0]; $goods_info[$k]['num'] = $info[1]; } foreach($goods_info as $k=>$v){ $goods = DB::table('goods_sku_list')->where('id', $v['id'])->first(); $params = array(); $params['outerCode'] = $order['outerCode']+$k+1; //外部平台中子订单编码 $params['outerParentCode'] = $order['outerCode']; //外部平台中订单编码 $params['goodsCode'] = $goods->code;// strstr($goods->code,'-',true); $params['skuCode'] = $goods->code; #商品名称 $params['goodsName'] = DB::table('goods_category')->where('goods_id', $goods->goods_id)->pluck('goods_name'); //$params['goodsName'] = '海钓黄翅鱼';//$goods->code; $params['price'] = $goods->price; $params['quantity'] = $v['num']; $params['discountFee'] = 0; $params['adjustFee'] = 0; $params['refundStatus'] = '正常'; $order['skuList'][] = $params; } */ //卖家云添加订单 //$mj_add = Order::mjOrderAdd($order); if(true){ #更新客户表 $customer = array(); $customers['name'] = $order['receiverName']; $customers['receiverState'] = $order['receiverState']; $customers['receiverCity'] = $order['receiverCity']; $customers['receiverDistrict'] = $order['receiverDistrict']; $customers['receiverStreet'] = $order['receiverStreet']; $customers['receiverAddress'] = $order['receiverAddress']; $customers['fanTime'] = $request->input('fanTime'); $if_e = DB::table('customers')->select('id')->where('phone', $order['receiverMobile'])->first(); if(isset($if_e->id)){ $customers['is_fugou'] = 1; $order['is_fugou'] = 1; $up_c = DB::table('customers')->where('id', $if_e->id)->update($customers); }else{ $customers['phone'] = $order['receiverMobile']; $customers['is_fugou'] = $order['is_fugou']; $in_c = DB::table('customers')->insert($customers); } //$order_goods = $order['skuList']; //unset($order['skuList']); //DB::table('order_goods')->insert($order_goods); //$order['orderCode'] = $mj_add['order']['code']; $admin_id = (int)$request->input('admin_id'); if($admin_id>0){ $admin_info = DB::table('admin')->select('realname', 'team_id')->where('id', $admin_id)->first(); $order['admin_id'] = $admin_id; $order['admin_name'] = $admin_info->realname; $order['team_id'] = $admin_info->team_id; }else{ $order['admin_id'] = session('admin_id'); $order['admin_name'] = session('real_name'); $order['team_id'] = session('team_id'); } $res = DB::table('order')->insertGetId($order); if($res){ #记录操作日志 $self_id = session('admin_id'); $self_name = session('real_name'); if($order['status'] == 0){ $status_text = '仅录入'; }else{ $status_text = '录入并提审'; } $context = "录入订单:".$status_text; $type = 0; //订单录入 $tables = 'order'; $data_id = $res; Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id); #如果提交审核,发短信 //if( $order['status'] == 1 ) $this->sendRemind($self_id, $res, 1); } /* $last_url = $request->input('last_url'); if(!empty($last_url)){ header('Location:'.$last_url);exit; } */ return redirect('/admin/order/index')->with('info', '添加成功'); } } /** * 分组管理-编辑分组界面 * @param $id * @return \Illuminate\View\View */ public function orderedit($id,Request $request) { $stime = $request->input('stime'); $etime = $request->input('etime'); $receiverName = $request->input('receiverName'); $receiverMobile = $request->input('receiverMobile'); $admin_id = (int)$request->input('admin_id'); $page = (int)$request->input('page'); $last_url = $request->input('last_url'); $self_role = session('role_name'); //$catelist = DB::table('goods_category')->select(DB::raw('distinct goods_category_name'))->lists('goods_category_name'); $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get(); $teamList = DB::table('teams')->select('id', 'name')->get(); $teamList = json_decode(json_encode($teamList), true); $adminList = json_decode(json_encode($adminList), true); $order = Order::findOrFail($id); $order = json_decode(json_encode($order), true); $order['receiverMobile'] = substr($order['receiverMobile'], 0, 3).'****'.substr($order['receiverMobile'], 7); return view('order/orderedit', [ 'order' => $order, //'categorylist' => $catelist, 'adminlist'=>$adminList, 'teamlist'=>$teamList, 'self_role'=>$self_role, 'str_query'=> 'page='.$page.'&admin_id='.$admin_id.'&stime='.$stime.'&etime='.$etime.'&receiverName='.$receiverName.'&receiverMobile='.$receiverMobile, 'last_url' => $last_url, ]); } /** * 分组管理-进行编辑操作 * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function orderupdate(Request $request) { $this->validate($request, [ 'id' => 'required', 'customerName' => 'required|between:1,6', 'receiverName' => 'required|between:1,6', 'receiverMobile' => 'required|regex:/^1[3456789][\d\*]{9}$/', 'receiverState' => 'required|between:1,5', 'receiverCity' => 'required|between:1,10', 'receiverAddress' => 'required', 'delivery_date' => 'required|date', 'createTime' => 'required|date', 'receivedAmount' => 'required|numeric|min:1', 'goods_note' => 'required|min:1', 'warehouse' => 'required|integer|min:1', ], [ 'customerName.required' => '买家姓名不能为空', 'customerName.between' => '买家姓名不能超过6个字符', 'receiverName.required' => '收货人不能为空', 'receiverName.between' => '收货人不能超过6个字符', 'receiverMobile.required' => '收货人手机号不能为空', 'receiverMobile.regex' => '收货人手机号格式有误', 'receiverState.required' => '省不能为空', 'receiverState.between' => '省填写有误', 'receiverCity.required' => '市不能为空', 'receiverCity.between' => '市填写有误', 'receiverAddress.required' => '详细地址不能为空', 'delivery_date.required' => '预发货时间不能为空', 'createTime.required' => '下单时间不能为空', 'receivedAmount.required' => '付款金额不能为空', 'receivedAmount.numeric' => '付款金额必须为数字', 'goods_note.required' => '商品信息不能为空', 'warehouse.required' => '仓库必须选择', 'warehouse.min' => '仓库必须选择', ]); $str_query = trim($request->input('str_query')); $last_url = trim($request->input('last_url')); $phone = trim($request->input('receiverMobile')); //更新数据 $order = array(); $order['customerName'] = trim($request->input('customerName')); //买家名称 $order['receiverName'] = trim($request->input('receiverName')); //收件人 if(preg_match('/^1\d{10}$/', $phone)) $order['receiverMobile'] = $phone; //收件人手机 $order['receiverState'] = trim($request->input('receiverState')); //省份 $order['receiverCity'] = trim($request->input('receiverCity')); //市 $order['receiverState'] = str_replace(['省', '市'], '', $order['receiverState']); $order['receiverCity'] = str_replace('市', '', $order['receiverCity']); //$order['receiverDistrict'] = trim($request->input('receiverDistrict')); //区 //$order['receiverStreet'] = trim($request->input('receiverStreet')); //街道 $order['receiverAddress'] = trim($request->input('receiverAddress')); //详细地址 $order['receivedAmount'] = trim($request->input('receivedAmount')); //付款金额 $order['buyerMemo'] = trim($request->input('buyerMemo', '')); // 买家备注 $order['sellerMemo'] = trim($request->input('sellerMemo', '')); // 卖家备注 $order['goods_note'] = trim($request->input('goods_note')); if($request->input('cost')) $order['cost'] = trim($request->input('cost')); //成本 $order['logistics_id'] = trim($request->input('logistics_id')); //物流单号 $order['is_refund'] = (int)$request->input('is_refund'); //是否退过单 if($request->input('refund_price')) $order['refund_price'] = trim($request->input('refund_price')); //应该退补差价 $order['is_fugou'] = (int)$request->input('is_fugou'); //是否复购 $order['warehouse'] = (int)$request->input('warehouse'); //仓库 $order['delivery_date'] = !empty($request->input('delivery_date')) ? $request->input('delivery_date') : date('Y-m-d'); //发货日期 if(!empty($request->input('createTime'))) $order['createTime'] = $request->input('createTime'); // 订单创建时间 $order['order_status'] = (int)$request->input('order_status'); $order['payment_type'] = (int)$request->input('payment_type'); //支付方式 //$order['status'] = (int)$request->input('status'); $admin_id = (int)$request->input('admin_id'); if($admin_id>0){ $admin_info = DB::table('admin')->select('realname', 'team_id')->where('id', $admin_id)->first(); $order['admin_id'] = $admin_id; $order['admin_name'] = $admin_info->realname; $order['team_id'] = $admin_info->team_id; } $id = (int)$request->input('id'); $res = DB::table('order')->where('id', $id)->update($order); if($res){ #记录操作日志 $self_id = session('admin_id'); $self_name = session('real_name'); $context = "修改订单"; $type = 0; $tables = 'order'; $data_id = $id; Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id); } if(!empty($last_url)){ header('Location:'.$last_url);exit; } return redirect('/admin/order/index?'.$str_query)->with('info', '更新成功'); } /** * 分组管理-进行删除操作 * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function orderdelete($id) { $order = Order::find($id); $order->is_del = 1; if ($order ->save()){ #记录操作日志 $self_id = session('admin_id'); $self_name = session('real_name'); $context = "删除订单"; $type = 0; $tables = 'order'; $data_id = $id; Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id); exit(''); //return redirect('/admin/order/index')->with('info', '删除成功'); } } public function setrefund($id){ $order = Order::find($id); $order->order_status = 2; if ($order ->save()){ exit('0'); } exit('1'); } public function setverify($id, Request $request){ $order = Order::find($id); $old_status = $order->status; $order->status = (int)$request->input('status'); if($order->status == 0){ $refuse_reason = trim($request->input('refuse_reason')); if(!empty($refuse_reason)){ $order->refuse_reason = $refuse_reason; } } if($order->status == 2 || $order->status == 0){ $order->verify_time = date('Y-m-d H:i:s'); //审核时间 } $res = $order ->save(); if($res){ #记录操作日志 $status_arr = array( 0 => '已录入', 1 => '待审核', 2 => '已审核', 3 => '已发货', ); $self_id = session('admin_id'); $self_name = session('real_name'); $context = "订单状态变更:【".$status_arr[$old_status]."】变更为【". $status_arr[$order->status]."】({$old_status}->{$order->status})"; $type = 1; //状态变更 $tables = 'order'; $data_id = $id; Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id); #发提醒短信 //$this->sendRemind($self_id, $id, $order->status); } exit(''); $stime = $request->input('stime'); $etime = $request->input('etime'); $receiverName = $request->input('receiverName'); $receiverMobile = $request->input('receiverMobile'); $admin_id = (int)$request->input('admin_id'); $page = (int)$request->input('page'); $str_query = 'page='.$page.'&admin_id='.$admin_id.'&stime='.$stime.'&etime='.$etime.'&receiverName='.$receiverName.'&receiverMobile='.$receiverMobile; return redirect('/admin/order/index?'.$str_query)->with('info', '操作成功'); } public function setverifymore(Request $request){ $ids = $request->get('id'); foreach($ids as $id){ $order = Order::find($id); $order->status = 1; $order ->save(); } $stime = $request->input('stime'); $etime = $request->input('etime'); $receiverName = $request->input('receiverName'); $receiverMobile = $request->input('receiverMobile'); $admin_id = (int)$request->input('admin_id'); $page = (int)$request->input('page'); $str_query = 'page='.$page.'&admin_id='.$admin_id.'&stime='.$stime.'&etime='.$etime.'&receiverName='.$receiverName.'&receiverMobile='.$receiverMobile; return redirect('/admin/order/index?'.$str_query)->with('info', '操作成功'); } /** * 分组管理-分组展示 * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function orderup($id) { //数据库-修改status字段值 $order = Order::find($id); $order ->status = 1; if ($order ->update()){ return redirect('/admin/order/index')->with('info', '启用成功'); } } /** * 分组管理-取消展示 * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function orderdown($id) { //数据库-修改status字段值 $order = Order::find($id); $order ->status = 0; if ($order ->update()){ return redirect('/admin/order/index')->with('info', '禁用成功'); } } /** * 分类取商品 */ public function categoods($category){ $goods_ids = DB::table('goods_category')->where('goods_category_name', $category)->lists('goods_id'); $goods = DB::table('goods_sku_list')->select('id', 'price', 'props_name', 'goods_id')->whereIn('goods_id', $goods_ids)->orderBy('goods_id', 'asc')->get(); foreach($goods as $item){ $gname = DB::table('goods_category')->select('goods_name')->where('goods_id', $item->goods_id)->first(); $item->goods_name = $gname->goods_name; } $goods = json_decode(json_encode($goods), true); return json_encode($goods); } /** * 操作员列表 */ public function teamAdmins($team_id){ //$saler_ids = DB::table('admin_role')->where('role_name', '销售')->lists('user_id'); $res = DB::table('admin')->select('id', 'realname', 'username')->where('team_id', $team_id)->where('id','>', 1)->get(); $res = json_decode(json_encode($res),true); return json_encode($res); } /** * 客户地址信息 */ public function getCustomer(Request $request){ $phone = $request->input('phone'); if(!preg_match('/^1\d{10}$/')){ return 0; } $res = DB::table('customers')->where('phone', $phone)->first(); if(isset($res->id)){ $result = json_decode(json_encode($res),true); return json_encode($result); } } public function order_export(Request $request){ $self_role = session('role_name'); if($self_role == '超级管理员' || $self_role == '团队主管' || $self_role == '管理员' || $self_role == 'A仓库管理员' || $self_role == 'B仓库管理员' || $self_role == '售后管理员'){ $admin_id = $request->input('admin_id'); }else{ $admin_id = session('admin_id'); } $is_saler = 0; if($self_role == '销售'){ $is_saler = 1; } if($self_role == 'A仓库管理员'){ $warehouse = 1; }elseif($self_role == 'B仓库管理员'){ $warehouse = 2; }else{ $warehouse = 0; } $team_id = $request->input('team_id'); #只能看自己团队的 if($self_role != '超级管理员' && $self_role != '售后管理员'){ $admin_id = session('admin_id'); $team_id = DB::table('admin')->where('id', $admin_id)->pluck('team_id'); } //假如有团队筛选,检索销售队员 $sale_ids = null; if($team_id>0){ $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id'); } $stime = $request->input('stime'); $etime = $request->input('etime'); $receiverName = $request->input('receiverName'); $receiverMobile = $request->input('receiverMobile'); $status = $request->input('status'); $id = (int)$request->input('id'); if($status === null){ $status = -1; } if($etime){ $etime = $etime. ' 23:59:59'; } $result = Order::where(function($query) use($admin_id, $stime, $etime, $warehouse, $receiverMobile, $receiverName, $self_role, $sale_ids, $status, $id){ if($admin_id) $query->where('admin_id', $admin_id); if($warehouse) $query->where('warehouse', $warehouse); if($stime) $query->where('createTime', '>=', $stime); if($etime) $query->where('createTime', '<=', $etime); if($receiverName) $query->where('receiverName', 'like', $receiverName . '%'); if($receiverMobile) $query->where('receiverMobile', $receiverMobile); if($self_role == '管理员') $query->where('status','>',0); if(!empty($sale_ids)) $query->whereIn('admin_id', $sale_ids); if($status>=0) $query->where('status', $status); if($id>0) $query->where('id', $id); })->where('is_del',0)->orderBy('id', 'desc')->get(); $result = json_decode(json_encode($result),true); $filename="订单数据.xls"; header("Content-type:application/vnd.ms-excel"); Header("Accept-Ranges:bytes"); Header("Content-Disposition:attachment;filename=".$filename); //$filename导出的文件名 header("Pragma: no-cache"); header("Expires: 0"); $data_str = ' '; $data_str .= ""; if($warehouse==0) $data_str .= ""; if($warehouse==0) $data_str .= ""; if($warehouse==0) $data_str .= ""; $data_str .= ""; if($warehouse==0) $data_str .= ""; if($warehouse==0) $data_str .= ""; if($warehouse==0) $data_str .= ""; $data_str .= ""; if($warehouse==0) $data_str .= ""; $data_str .= ""; $data_str .= ""; $data_str .= ""; if($is_saler==0) $data_str .= ""; $data_str .=""; foreach ($result as $k => $v) { #销售 $admin = DB::table('admin')->where('id', $v['admin_id'])->first(); $v['wx_id'] = isset($admin->wx_id) ? $admin->wx_id : ''; #team $team = DB::table('teams')->where('id', $v['team_id'])->first(); $v['team_name'] = isset($team->name) ? $team->name : ''; #加粉时间 $customr = DB::table('customers')->where('phone', $v['receiverMobile'])->first(); $v['fanTime'] = isset($customr->fanTime) ? $customr->fanTime : ''; $v['receiverMobile'] = substr($v['receiverMobile'], 0, 3).'****'.substr($v['receiverMobile'], 7); $fugou = $v['is_fugou']==1? '是' : '否'; $is_refund = $v['is_refund']==1? '是' : '否'; $address = $v['receiverState'].$v['receiverCity'].$v['receiverDistrict'].$v['receiverAddress']; $data_str .= ""; if($warehouse==0) $data_str .= ""; if($warehouse==0) $data_str .= ""; if($warehouse==0) $data_str .= ""; $data_str .= ""; if($warehouse==0) $data_str .= ""; if($warehouse==0) $data_str .= ""; if($warehouse==0) $data_str .= ""; $data_str .= ""; if($warehouse==0) $data_str .= ""; $data_str .= ""; $data_str .= ""; $data_str .= ""; if($is_saler==0) $data_str .= ""; $data_str .= ""; $data_str .= ""; } $data_str .= "
".iconv("UTF-8", "GB2312//IGNORE","销售微信号")."".iconv("UTF-8", "GB2312//IGNORE","销售团队")."".iconv("UTF-8", "GB2312//IGNORE","销售")."".iconv("UTF-8", "GB2312//IGNORE","订单时间")."".iconv("UTF-8", "GB2312//IGNORE","加粉时间")."".iconv("UTF-8", "GB2312//IGNORE","是否复购")."".iconv("UTF-8", "GB2312//IGNORE","订单金额")."".iconv("UTF-8", "GB2312//IGNORE","订单商品")."".iconv("UTF-8", "GB2312//IGNORE","是否退补单")."".iconv("UTF-8", "GB2312//IGNORE","配送地址")."".iconv("UTF-8", "GB2312//IGNORE","配送姓名")."".iconv("UTF-8", "GB2312//IGNORE","配送电话")."".iconv("UTF-8", "GB2312//IGNORE","供应商成本")."".iconv("UTF-8", "GB2312//IGNORE","顺丰单号")."
".$v['wx_id']."".iconv("UTF-8", "GB2312//IGNORE", $v["team_name"])."".iconv("UTF-8", "GB2312//IGNORE", $v["admin_name"])."".$v['createTime']."".$v['fanTime']."".iconv("UTF-8", "GB2312//IGNORE", $fugou)."".$v['receivedAmount']."".iconv("UTF-8", "GB2312//IGNORE", $v["goods_note"])."".iconv("UTF-8", "GB2312//IGNORE", $is_refund)."".iconv("UTF-8", "GB2312//IGNORE", $address)."".iconv("UTF-8", "GB2312//IGNORE", $v["receiverName"])."".$v['receiverMobile']."".$v['cost']."".$v["logistics_id"]."
"; echo $data_str; exit; } public function editLogisticsId(Request $request){ $id = $request->input('id'); $logistics_id = $request->input('logistics_id'); $cost = $request->input('cost'); $freight_cost = $request->input('freight_cost'); $send_note = $request->input('send_note'); $refund_note = $request->input('refund_note'); $buyerMemo = $request->input('buyerMemo'); $sellerMemo = $request->input('sellerMemo'); $data = array(); if(isset($logistics_id)) $data['logistics_id'] = $logistics_id; if(isset($cost)){ if(empty($cost)) $cost = null; $data['cost'] = $cost; } if(isset($freight_cost)){ if(empty($freight_cost)) $freight_cost = null; $data['freight_cost'] = $freight_cost; } if(isset($buyerMemo)) $data['buyerMemo'] = trim($buyerMemo); if(isset($sellerMemo)) $data['sellerMemo'] = trim($sellerMemo); if(isset($send_note)) $data['send_note'] = trim($send_note); if(isset($refund_note)) $data['refund_note'] = trim($refund_note); if($id>0 && !empty($data)){ $res = Order::where('id', $id)->update($data); } return 1; } public function warehouse_export(Request $request){ $self_role = session('role_name'); $admin_id = $request->input('admin_id'); if($self_role == 'A仓库管理员'){ $warehouse = 1; }elseif($self_role == 'B仓库管理员'){ $warehouse = 2; }else{ $warehouse = 0; } $stime = $request->input('stime'); $etime = $request->input('etime'); $receiverName = $request->input('receiverName'); $receiverMobile = $request->input('receiverMobile'); $delivery_type = (int)$request->input('delivery_type'); //发货状态 0到发货时间(未填物流信息) 2全部 $id = (int)$request->input('id'); $_start = '2019-09-18';// 只看18号之后数据 $today_date = date('Y-m-d'); $result = Order::where(function($query) use($admin_id, $stime, $etime, $warehouse, $receiverMobile, $receiverName, $today_date, $delivery_type, $_start, $id){ if($admin_id) $query->where('admin_id', $admin_id); if($warehouse) $query->where('warehouse', $warehouse); if($stime) $query->where('createTime', '>=', $stime); if($etime) $query->where('createTime', '<=', $etime); if($receiverName) $query->where('receiverName', 'like', $receiverName . '%'); if($receiverMobile) $query->where('receiverMobile', $receiverMobile); if($id>0) $query->where('id', $id); if($delivery_type==0) $query->where('logistics_id', '=', ''); $query->where('createTime', '>=', $_start); })->where('is_del',0)->where('status', '>', 1)->where('delivery_date', '<=', $today_date)->orderBy('id', 'desc')->get(); $result = json_decode(json_encode($result),true); foreach ($result as $k => &$v) { $v['address'] = $v['receiverState'].$v['receiverCity'].$v['receiverDistrict'].$v['receiverStreet'].$v['receiverAddress']; } $indexKey = ['id','goods_note','receiverName','receiverMobile','address','createTime','sellerMemo','buyerMemo','cost','logistics_id','freight_cost','send_note']; $title = ['订单编号', '商品信息', '收货人', '收货人手机号', '收货地址', '下单时间', '卖家备注', '买家备注', '供应商成本', '顺丰单号', '运费成本', '发货备注']; $filename = 'dingdan_'.date('Y-m-d_H').'.xlsx'; return $this->export_excel($result, $filename, $indexKey, $title); } /** * excel导入订单信息 * @param Request $request */ public function importGoodsExcel(Request $request) { $excelFile = $request->file('orderFile'); //实例化Excel读取类 $objReader = new PHPExcel_Reader_Excel2007(); if(!$objReader->canRead($excelFile)){ $objReader = new PHPExcel_Reader_Excel5(); if(!$objReader->canRead($excelFile)){ echo "\n".'无法识别的Excel文件!'; return false; } } $objPHPExcel=$objReader->load($excelFile); $worksheet=$objPHPExcel->getSheet(0);//获取第一个工作表 $highestRow=$worksheet->getHighestRow();//取得总行数 $highestColumn=$worksheet->getHighestColumn(); //取得总列数 $lines = $highestRow - 1; if ($lines <= 0) { //'Excel表格中没有数据'; return false; } $errorArr=[]; $okStr = ''; for ($row = 2; $row <= $highestRow; ++$row) { $params = array(); $order_id = (int)$worksheet->getCellByColumnAndRow(0, $row)->getValue(); $cost = trim($worksheet->getCellByColumnAndRow(8, $row)->getValue()); $logistics_id = trim($worksheet->getCellByColumnAndRow(9, $row)->getValue()); $freight_cost = trim($worksheet->getCellByColumnAndRow(10, $row)->getValue()); $send_note = trim($worksheet->getCellByColumnAndRow(11, $row)->getValue()); if($cost>0){ $params['cost'] = $cost; }else{ $params['cost'] = null; } if($logistics_id){ $params['logistics_id'] = $logistics_id; }else{ $params['logistics_id'] = ''; } if($send_note){ $params['send_note'] = $send_note; }else{ $params['send_note'] = ''; } if($freight_cost>0){ $params['freight_cost'] = $freight_cost; }else{ $params['freight_cost'] = null; } $result = Order::where('id', $order_id)->update($params); if (!$result) { $errorArr[] = $order_id; }else{ $okStr .= $order_id.','; } } if (count($errorArr)) { $desc = '共'.($highestRow-1).'个订单, 其中'.count($errorArr).'个订单录入失败'; }else { $desc = '订单导入成功'; } #记录操作日志 $self_id = session('admin_id'); $self_name = session('real_name'); $context = "仓管excel导入订单成本等信息 ".$desc; $type = 0; $tables = 'order'; $data_id = $okStr; Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id); return redirect('admin/order/warehouse')->with('info',$desc); } /** * 导出excel * @param $data * @param string */ public function export_excel($data, $filename = '未命名.xlsx', $indexKey, $title) { if( !is_array($indexKey)) return false; $header_arr = array('A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); //初始化PHPExcel() $objPHPExcel = new PHPExcel(); $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); //接下来就是写数据到表格里面去 $objActSheet = $objPHPExcel->getActiveSheet(); foreach($title as $k=>$item){ $objActSheet->setCellValue($header_arr[$k].'1',$item); } $startRow = 2; foreach ($data as $row) { foreach ($indexKey as $key => $value){ //这里是设置单元格的内容 $objActSheet->setCellValue($header_arr[$key].$startRow,$row[$value]); } $startRow++; } header("Pragma: public"); header("Expires: 0"); header("Cache-Control:must-revalidate, post-check=0, pre-check=0"); header("Content-Type:application/force-download"); header("Content-Type:application/vnd.ms-execl"); header("Content-Type:application/octet-stream"); header("Content-Type:application/download");; header('Content-Disposition:attachment;filename='.$filename.''); header("Content-Transfer-Encoding:binary"); $objWriter->save('php://output'); exit(); } /** * 根据手机号获取默认地址信息 * */ public function getAddress(Request $request){ $phone = $request->input('phone'); if(!preg_match('/^1\d{10}$/', $phone)){ exit('0'); } $result = DB::table('customers')->select('receiverState', 'receiverCity', 'receiverDistrict', 'receiverStreet', 'receiverAddress', 'fanTime')->where('phone', $phone)->first(); if(empty($result)) exit('0'); $result = json_decode(json_encode($result), true); exit( json_encode($result) ); } /** * 订单状态机制,获取可变更状态 * @param status:0已录入 1提交审核 2已审核 3已发货 */ public function getEnableStatus($status){ $status_arr = [ 0 => ['status'=>0, 'name'=>'已录入'], 1 => ['status'=>1, 'name'=>'提交审核'], 2 => ['status'=>2, 'name'=>'审核通过'], 3 => ['status'=>3, 'name'=>'设为发货'], ]; $status = (int)$status; $result = array(); switch ($status) { case '0': $result[] = $status_arr[1]; break; case '1': $result[] = $status_arr[2]; $result[] = $status_arr[0]; break; case '2': $result[] = $status_arr[3]; break; default: break; } return $result; } /** * 根据订单状态发短信提醒 */ public function sendRemind($user_id, $id, $status){ if($status == 0 || $status == 3){ //被驳回,获取销售手机号 $saler_id = DB::table('order')->where('id', $id)->pluck('admin_id'); $phone = DB::table('admin')->where('id, $saler_id')->pluck('phone'); $type = $status == 0 ? 5 : 3; }elseif($status == 1){ //待审核,获取团队管理员手机号 $admin_ids = DB::table('admin_role')->where('role_name','管理员')->lists('user_id'); $team_id = DB::table('admin')->where('id', $user_id)->pluck('team_id'); $admin_info = DB::table('admin')->where('team_id', $team_id)->whereIn('id', $admin_ids)->first(); $phone = $admin_info->phone; $type = 1; }elseif($status == 2){ //审核通过,通知仓管发货 $warehouse = DB::table('order')->where('id', $id)->pluck('warehouse'); if($warehouse == 1){ $warehouse_admin = DB::table('admin_role')->select('user_id')->where('role_name','A仓库管理员')->orderBy('id', 'desc')->first(); $admin_info = DB::table('admin')->where('id', $warehouse_admin->user_id)->first(); $phone = $admin_info->phone; $type = 2; } } if(!$phone){ return false; } $res = YPSMS::sendMsg($phone,$type,$id); return $res; } }