_/___.' >'"". * | | : `- \`.;`\ _ /`;.`/ - ` : | | * \ \ `-. \_ __\ /__ _/ .-` / / * ======`-.____`-.___\_____/___.-`____.-'====== * `=---=' * ............................................. * 佛曰:bug泛滥,我已瘫痪! */ public function GetCrown(Request $request) { $user = User::where('id', $request->input('id'))->with(['agent:id,nickname,agent_id,level,warea_id'])->with(['warea'])->select('id', 'agent_id', 'level', 'nickname', 'warea_id')->first(); $data = []; if ($user->level == 3) { $data['nickname'] = $user->nickname; $data['id'] = $user->id; $data['warea_name'] = $user->warea->name; } else { if ($user->agent->level == 3) { $data['nickname'] = $user->agent->nickname; $data['id'] = $user->agent->id; $data['warea_name'] = Warea::where('id', $user->agent->warea_id)->value('name'); } else { $user = User::where('id', $user->agent->agent_id)->with(['warea'])->select('id', 'agent_id', 'level', 'nickname', 'warea_id')->first(); $data['nickname'] = $user->nickname; $data['id'] = $user->id; $data['warea_name'] = Warea::where('id', $user->warea_id)->value('name'); } } return $this->success($data); } /**客户申请表**/ public function GetApplyList(Request $request) { $page_index = $request->input('page_index', 1); $page_size = $request->input('size', 15); $num = ($page_index - 1) * $page_size; $search_name = $request->input('search_name'); $customer_name = $request->input('customer_name'); $warea_name = $request->input('warea_name'); $apply_status = $request->input('apply_status'); $is_finish = $request->input('is_finish'); $start_time = $request->input('start_time'); $end_time = $request->input('end_time'); $apply_number = $request->input('apply_number') ?? null; $re = CustomerReturn::query(); if (Auth::user()->role_id == 23) { $warea_names = Warea::where('admin_id', Auth::user()->id)->value('name'); $re->where('warea_name', $warea_names); } if (is_numeric($apply_status)) { $re->where('apply_status', $apply_status); } if ($start_time) { $re->whereBetween('created_at', [$start_time, $end_time]); } if (is_numeric($is_finish)) { $re->where('is_finish', $is_finish); } if ($apply_number) { $re->where('apply_number', $apply_number); } if ($warea_name) { $re->where('warea_name', $warea_name); } if ($search_name) { $re->where('user_nickname', 'like', '%' . $search_name . '%'); } if ($customer_name) { $re->where('customer_name', 'like', '%' . $customer_name . '%')->orWhere('customer_phone', 'like', '%' . $customer_name . '%'); } $count = $re->count(); $data = $re->with(['applydetail'])->orderByDesc('id')->take($page_size)->skip($num)->get(); return $this->success_list($data, '', $count); } /*客户申请**/ public function Apply(Request $request, CustomerReturn $customerReturn, CustomerReturnDetail $CustomerReturnDetail) { $applyUserID = $request->input('user_id'); $applyUserName = $request->input('user_nickname'); $applyCrownID = $request->input('crown_id'); $applyCrownName = $request->input('crown_nickname'); $warea_name = $request->input('warea_name'); $customer_name = $request->input('customer_name'); $customer_phone = $request->input('customer_phone'); $province = $request->input('province'); $city = $request->input('city'); $area = $request->input('area'); $address = $request->input('address'); $total = $request->input('total'); $remark = $request->input('remark'); $apply_number = $this->CreateApplyNumber(); $problemList=$request->input('detail'); $op_name = Auth::user()->name; $customerReturn->user_id = $applyUserID; $customerReturn->user_nickname = $applyUserName; $customerReturn->crown_id = $applyCrownID; $customerReturn->crown_nickname = $applyCrownName; $customerReturn->warea_name = $warea_name; $customerReturn->customer_name = $customer_name; $customerReturn->customer_phone = $customer_phone; $customerReturn->province = $province; $customerReturn->city = $city; $customerReturn->area = $area; $customerReturn->address = $address; $customerReturn->total = $total; $customerReturn->apply_status = 1; $customerReturn->remark = $remark; $customerReturn->apply_number = $apply_number; $customerReturn->op_name = $op_name; DB::beginTransaction(); try { if (!$customerReturn->save()) { throw new \Exception('1'); } $all_money=0; $all_return_money=0; foreach ($problemList as $k => $v) { $CustomerReturnDetail = new CustomerReturnDetail(); $CustomerReturnDetail->customer_id = $customerReturn->id; $CustomerReturnDetail->problem_info = $v['problem_info']; $CustomerReturnDetail->good_name = $v['good_name']; $CustomerReturnDetail->good_size = $v['good_size']; // $CustomerReturnDetail->good_sex = $v['good_sex']; $CustomerReturnDetail->total = $v['total']; $CustomerReturnDetail->problem_attr = $v['problem_attr']; $CustomerReturnDetail->is_vip = $v['is_vip']; $CustomerReturnDetail->wear_time = $v['wear_time']; $CustomerReturnDetail->type = $v['type']; $CustomerReturnDetail->order_num = $v['order_num']; if ($v['good_name']=='精装版'){ if ($v['is_vip']==1){ $money=359; }else{ $money=399; } $return_money=149; }elseif ($v['good_name']=='简约版'){ if ($v['is_vip']==1){ $money=154; }else{ $money=169; } $return_money=79; }elseif ($v['good_name']=='高腰版'){ if ($v['is_vip']==1){ $money=179; }else{ $money=199; } $return_money=89; }elseif ($v['good_name']=='纯棉版'){ if ($v['is_vip']==1){ $money=89; }else{ $money=99; } $return_money=47; }elseif ($v['good_name']=='青春版'){ if ($v['is_vip']==1){ $money=179; }else{ $money=199; } $return_money=89; } $CustomerReturnDetail->price = round(($v['total']*$money)/3,2); $CustomerReturnDetail->cost = ($money-$return_money)."/3"; $CustomerReturnDetail->return_price = round(($v['total']*($money-$return_money))/3,2); $all_money+=round(($v['total']*$money)/3,2); $all_return_money+=round(($v['total']*($money-$return_money))/3,2); ///价格未计算 if ($v['ImgList']) { $CustomerReturnDetail->ImgList = json_encode($v['ImgList']); } if ($v['money_info']) { $CustomerReturnDetail->money_info = json_encode($v['money_info']); } if (!$CustomerReturnDetail->save()) { throw new \Exception('1'); } } $customerReturn=CustomerReturn::find($customerReturn->id); $customerReturn->price=$all_money; $customerReturn->return_price=$all_return_money; if (!$customerReturn->save()) { throw new \Exception('1'); } DB::commit(); return $this->success([]); } catch (\Exception $exception) { DB::rollBack(); return $this->error(520014, $exception->getMessage()); } } public function GetApplyLists(){ $user = User::where('id','<', 100)->where('level',1)->with(['agent'])->first(); dd($user); } /**修改申请单**/ public function UpdateApply(Request $request) { $id = $request->input('id'); $applyUserID = $request->input('user_id'); $applyUserName = $request->input('user_nickname'); $applyCrownID = $request->input('crown_id'); $applyCrownName = $request->input('crown_nickname'); $warea_name = $request->input('warea_name'); $customer_name = $request->input('customer_name'); $customer_phone = $request->input('customer_phone'); $province = $request->input('province'); $city = $request->input('city'); $area = $request->input('area'); $address = $request->input('address'); $total = $request->input('total'); $remark = $request->input('remark'); $NewproblemList = $request->input('NewproblemList'); $UpdateproblemList = $request->input('UpdateproblemList'); $DelproblemList = $request->input('DelproblemList') ?? []; $apply_number = $this->CreateApplyNumber(); $op_name = Auth::user()->name; $applyCustomer = CustomerReturn::where('id', $id)->first(); $applyCustomer->user_id = $applyUserID; $applyCustomer->user_nickname = $applyUserName; $applyCustomer->crown_id = $applyCrownID; $applyCustomer->crown_nickname = $applyCrownName; $applyCustomer->warea_name = $warea_name; $applyCustomer->customer_name = $customer_name; $applyCustomer->customer_phone = $customer_phone; $applyCustomer->province = $province; $applyCustomer->city = $city; $applyCustomer->area = $area; $applyCustomer->address = $address; $applyCustomer->total = $total; $applyCustomer->remark = $remark; $applyCustomer->apply_number = $apply_number; $applyCustomer->op_name = $op_name; DB::beginTransaction(); try { if (!$applyCustomer->save()) { throw new \Exception('1'); } $all_money=0; $all_return_money=0; /**新增的**/ foreach ($NewproblemList as $k => $v) { $CustomerReturnDetail = new CustomerReturnDetail(); $CustomerReturnDetail->customer_id = $applyCustomer->id; $CustomerReturnDetail->problem_info = $v['problem_info']; $CustomerReturnDetail->good_name = $v['good_name']; $CustomerReturnDetail->good_size = $v['good_size']; // $CustomerReturnDetail->good_sex = $v['good_sex']; $CustomerReturnDetail->total = $v['total']; $CustomerReturnDetail->problem_attr = $v['problem_attr']; $CustomerReturnDetail->is_vip = $v['is_vip']; $CustomerReturnDetail->wear_time = $v['wear_time']; $CustomerReturnDetail->type = $v['type']; $CustomerReturnDetail->order_num = $v['order_num']; if ($v['good_name']=='精装版'){ if ($v['is_vip']==1){ $money=359; }else{ $money=399; } $return_money=149; }elseif ($v['good_name']=='简约版'){ if ($v['is_vip']==1){ $money=154; }else{ $money=169; } $return_money=79; }elseif ($v['good_name']=='高腰版'){ if ($v['is_vip']==1){ $money=179; }else{ $money=199; } $return_money=89; }elseif ($v['good_name']=='纯棉版'){ if ($v['is_vip']==1){ $money=89; }else{ $money=99; } $return_money=47; }elseif ($v['good_name']=='青春版'){ if ($v['is_vip']==1){ $money=179; }else{ $money=199; } $return_money=89; } $CustomerReturnDetail->price = round(($v['total']*$money)/3,2); $CustomerReturnDetail->cost = ($money-$return_money)."/3"; $CustomerReturnDetail->return_price = round(($v['total']*($money-$return_money))/3,2); $all_money+=round(($v['total']*$money)/3,2); $all_return_money+=round(($v['total']*($money-$return_money))/3,2); ///价格未计算 if ($v['ImgList']) { $CustomerReturnDetail->ImgList = json_encode($v['ImgList']); } if ($v['money_info']) { $CustomerReturnDetail->money_info = json_encode($v['money_info']); } if (!$CustomerReturnDetail->save()) { throw new \Exception('1'); } } /**修改的*/ foreach ($UpdateproblemList as $k => $v) { $CustomerReturnDetail = CustomerReturnDetail::where('id', $v['id'])->first(); $CustomerReturnDetail->problem_info = $v['problem_info']; $CustomerReturnDetail->good_name = $v['good_name']; $CustomerReturnDetail->good_size = $v['good_size']; // $CustomerReturnDetail->good_sex = $v['good_sex']; $CustomerReturnDetail->total = $v['total']; $CustomerReturnDetail->problem_attr = $v['problem_attr']; $CustomerReturnDetail->is_vip = $v['is_vip']; $CustomerReturnDetail->wear_time = $v['wear_time']; $CustomerReturnDetail->type = $v['type']; $CustomerReturnDetail->order_num = $v['order_num']; if ($v['good_name']=='精装版'){ if ($v['is_vip']==1){ $money=359; }else{ $money=399; } $return_money=149; }elseif ($v['good_name']=='简约版'){ if ($v['is_vip']==1){ $money=154; }else{ $money=169; } $return_money=79; }elseif ($v['good_name']=='高腰版'){ if ($v['is_vip']==1){ $money=179; }else{ $money=199; } $return_money=89; }elseif ($v['good_name']=='纯棉版'){ if ($v['is_vip']==1){ $money=89; }else{ $money=99; } $return_money=47; }elseif ($v['good_name']=='青春版'){ if ($v['is_vip']==1){ $money=179; }else{ $money=199; } $return_money=89; } $CustomerReturnDetail->price = round(($v['total']*$money)/3,2); $CustomerReturnDetail->cost = ($money-$return_money)."/3"; $CustomerReturnDetail->return_price = round(($v['total']*($money-$return_money))/3,2); $all_money+=round(($v['total']*$money)/3,2); $all_return_money+=round(($v['total']*($money-$return_money))/3,2); ///价格未计算 if ($v['ImgList']) { $CustomerReturnDetail->ImgList = json_encode($v['ImgList']); } if ($v['money_info']) { $CustomerReturnDetail->money_info = json_encode($v['money_info']); } if (!$CustomerReturnDetail->save()) { throw new \Exception('1'); } } /**删除的*/ foreach ($DelproblemList as $k => $v) { $applyCustomerDetail = CustomerReturnDetail::find($v); $applyCustomerDetail->delete(); } $customerReturn=CustomerReturn::find($id); $customerReturn->price=$all_money; $customerReturn->return_price=$all_return_money; if (!$customerReturn->save()) { throw new \Exception('1'); } DB::commit(); return $this->success([]); } catch (\Exception $exception) { DB::rollBack(); return $this->error(520014, $exception->getMessage()); } } /*客户退换申请单号**/ public function CreateApplyNumber() { $id = Auth::user()->id; $str = 'DWBS-TH-'; $string = $str . $id . substr(time(), 6, 9) . rand(1111, 9999); return $string; } /**上传订单号**/ public function UploadCustomerInfo(Request $request) { $file = $request->file('file'); if (!$file->isValid()) { //判断文件是否有效 return redirect() ->back() ->withErrors('文件上传失败,请重新上传'); } $array = Excel::toArray(new ExpressImport, request()->file('file')); if (count($array) > 5001) { return $this->error('450001', "单次最多导入5000条数据"); } $one = array_shift($array[0]); $express_num_keys = array_search('快递单号', $one); if (!$express_num_keys && !is_numeric($express_num_keys)) { return $this->error('450001', "表头无'快递单号'字段"); } $order_num_keys = array_search('申请单编号', $one); if (!$order_num_keys && !is_numeric($order_num_keys)) { return $this->error('450001', "表头无'申请单编号'字段"); } $express_com_keys = array_search('快递公司', $one); if (!$express_com_keys) { return $this->error('450001', "表头无'快递公司'字段"); } $express_code_keys = array_search('快递公司代码', $one); if (!$express_code_keys) { return $this->error('450001', "表头无'快递公司代码'字段"); } $arr = $array[0]; $express_nums = array_column($arr, $express_num_keys); $unique_express_nums = array_unique($express_nums); $que_express_nums = array_diff_assoc($express_nums, $unique_express_nums); if (count($que_express_nums) > 0) { $que_express_str = implode(',', $que_express_nums); return $this->error('450001', '快递单号' . $que_express_str . '重复出现'); } $new_arr = []; $new_arrs = []; $z = 0; foreach ($array[0] as $k => $v) { $st = ''; if ($v[$express_com_keys] == '中通快递') { $patterns = "/\d+/"; preg_match_all($patterns, $v[$express_num_keys], $aa); foreach ($aa[0] as $kee => $vaa) { $st .= $vaa; } $new_arr[$z] = $st; } else { $new_arr[$z] = $v[$express_num_keys]; } $new_arrs[$z] = $v[$order_num_keys]; $z++; } $res = ApplyCustomer::whereIn('express_num', $new_arr)->pluck('express_num')->toArray(); if (count($res) > 0) { $ar_r = array_intersect($new_arr, $res); $que_express_str = implode(',', $ar_r); return $this->error('450001', '快递单号:' . $que_express_str . '已经上传', $ar_r); } $apply_arr = ApplyCustomer::whereIn('apply_number', $new_arrs)->whereNotNull('express_num')->pluck('apply_number')->toArray(); if ($apply_arr) { return $this->error(500214, implode(',', $apply_arr) . '已经上传过快递单号,请核实数据'); } DB::beginTransaction(); try { foreach ($arr as $k => $v) { $apply_number = $v[$order_num_keys]; $apply_info = ApplyCustomer::where('apply_number', $apply_number)->first(); if (!$apply_info) { return $this->error(20014, '申请单号:' . $apply_number . '不存在'); } $st = ''; if ($v[$express_com_keys] == '中通快递') { $patterns = "/\d+/"; preg_match_all($patterns, $v[$express_num_keys], $aa); foreach ($aa[0] as $kee => $vaa) { $st .= $vaa; } $apply_info->express_num = $st; } else { $apply_info->express_num = $v[$express_num_keys]; } $apply_info->express_com = $v[$express_com_keys]; $apply_info->express_code = $v[$express_code_keys]; $apply_info->express_time = Carbon::now(); $apply_info->apply_status = 2; $apply_info->is_owe = 0; if (!$apply_info->save()) { throw new \Exception(1); } } DB::commit(); /**发送 快递信息*/ foreach ($arr as $k => $v) { $apply_info = ApplyCustomer::where('apply_number', $v[$order_num_keys])->first(); $data = [ 'mobile' => $apply_info->customer_phone, 'express_com' => $apply_info->express_com, 'express_num' => $apply_info->express_num, 'status' => 0 ]; event(new CustomerSendSmsEvent($data)); } return $this->success([]); } catch (\Exception $exception) { DB::rollBack(); return $this->error(500214, $exception->getMessage()); } } /**上传单个物流信息**/ public function Express(Request $request) { $re = ApplyCustomer::find($request->input('id')); $re->express_num = $request->input('express_number'); $re->express_time = Carbon::now(); $re->apply_status = 2; $re->is_owe = 0; $re->express_com = $request->input('express_name'); $re->express_code = $request->input('express_code'); $data = [ 'mobile' => $re->customer_phone, 'express_com' => $re->express_com, 'express_num' => $re->express_num, 'status' => 0 ]; event(new CustomerSendSmsEvent($data)); $re->save(); return $this->success([]); } /**上传订单号**/ public function UpdateCustomerInfo(Request $request) { $file = $request->file('file'); if (!$file->isValid()) { //判断文件是否有效 return redirect() ->back() ->withErrors('文件上传失败,请重新上传'); } $array = Excel::toArray(new ExpressImport, request()->file('file')); if (count($array) > 5001) { return $this->error('450001', "单次最多导入5000条数据"); } $one = array_shift($array[0]); $express_num_keys = array_search('旧快递单号', $one); if (!$express_num_keys && !is_numeric($express_num_keys)) { return $this->error('450001', "表头无'旧快递单号'字段"); } $new_express_num_keys = array_search('新快递单号', $one); if (!$express_num_keys && !is_numeric($express_num_keys)) { return $this->error('450001', "表头无'新快递单号'字段"); } $express_com_keys = array_search('快递公司', $one); if (!$express_com_keys) { return $this->error('450001', "表头无'快递公司'字段"); } $express_code_keys = array_search('快递公司代码', $one); if (!$express_code_keys) { return $this->error('450001', "表头无'快递公司代码'字段"); } $arr = $array[0]; $express_nums = array_column($arr, $express_num_keys); $unique_express_nums = array_unique($express_nums); $que_express_nums = array_diff_assoc($express_nums, $unique_express_nums); if (count($que_express_nums) > 0) { $que_express_str = implode(',', $que_express_nums); return $this->error('450001', '快递单号' . $que_express_str . '重复出现'); } DB::beginTransaction(); try { foreach ($arr as $k => $v) { $apply_info = ApplyCustomer::where('express_num', $v[$express_num_keys])->first(); if (!$apply_info) { return $this->error(20014, '申请单号:' . $v[$express_num_keys] . '不存在'); } $st = ''; if ($v[$express_com_keys] == '中通快递') { $patterns = "/\d+/"; preg_match_all($patterns, $v[$new_express_num_keys], $aa); foreach ($aa[0] as $kee => $vaa) { $st .= $vaa; } $apply_info->express_num = $st; } else { $apply_info->express_num = $v[$new_express_num_keys]; } $apply_info->express_com = $v[$express_com_keys]; $apply_info->express_code = $v[$express_code_keys]; $apply_info->express_time = Carbon::now(); $apply_info->apply_status = 2; $apply_info->is_owe = 0; if (!$apply_info->save()) { throw new \Exception(1); } } DB::commit(); /**发送 快递信息*/ foreach ($arr as $k => $v) { $apply_info = ApplyCustomer::where('express_num', $v[$new_express_num_keys])->first(); $data = [ 'mobile' => $apply_info->customer_phone, 'express_com' => $apply_info->express_com, 'express_num' => $apply_info->express_num, 'status' => 1, 'old_express_num' => $v[$express_num_keys] ]; try { event(new CustomerSendSmsEvent($data)); } catch (\Exception $exception) { } } return $this->success([]); } catch (\Exception $exception) { DB::rollBack(); return $this->error(500214, $exception->getMessage()); } } /**添加退货原因**/ public function AddProblemCollection(Request $request, ProblemCollection $problemCollection) { $problem = $request->input('problem'); $problem_id = $request->input('problem_id', 0); $problemCollection->problem = $problem; $problemCollection->type = 2; $problemCollection->problem_id = $problem_id; $problemCollection->save(); return $this->success([]); } public function GetProblemCollection(Request $request) { $type = $request->input('type') ?? 2; $re = ProblemCollection::where('type', $type)->with(['children' => function ($q) { $q->select('problem as label', 'id as value', 'problem_id'); }])->where('problem_id', 0)->select('problem as label', 'id as value', 'problem_id')->orderByDesc('created_at')->get(); return $this->success($re); } public function GetGoodNum() { $re = StoreHouseStorage::groupBy('good_name')->with(['GetGood'])->select('*')->get(); return $this->success($re); } /**添加退货原因**/ public function AddLabelCollection(Request $request, ProblemCollection $problemCollection) { $problem = $request->input('label'); $problemCollection->problem = $problem; $problemCollection->type = 2; $problemCollection->save(); return $this->success([]); } public function GetLabelCollection(Request $request) { $type = $request->input('type') ?? 2; $re = ProblemCollection::where('type', $type)->where('type', $type)->select('problem as label', 'id')->orderByDesc('created_at')->get(); return $this->success($re); } /**问题统计分析**/ public function ProblemAnalyse(Request $request) { $start_time = $request->input('start_time'); $end_time = $request->input('end_time'); $re = ApplyCustomerDetail::query(); if ($start_time && $end_time) { $re->whereBetween('created_at', [$start_time, $end_time]); } $re = $re->groupBy('problem_info')->select('problem_info', DB::raw('sum(total) as total'))->get(); return $this->success($re); } /**战区调换数量统计**/ public function WareaProblemAnalyse(Request $request) { $start_time = $request->input('start_time'); $end_time = $request->input('end_time'); $re = ApplyCustomer::query(); if ($start_time && $end_time) { $re->whereBetween('created_at', [$start_time, $end_time]); } $re = $re->groupBy('warea_name')->select('warea_name', DB::raw('sum(total) as total'))->get(); return $this->success($re); } /**代理公司调换数量统计**/ public function CrownProblemAnalyse(Request $request) { $start_time = $request->input('start_time'); $end_time = $request->input('end_time'); $re = ApplyCustomer::query(); if ($start_time && $end_time) { $re->whereBetween('created_at', [$start_time, $end_time]); } $re = $re->groupBy('apply_crown_id')->select('apply_crown_nickname', 'apply_crown_id', DB::raw('sum(total) as total'))->get(); return $this->success($re); } /**战区调换数量统计**/ public function WareaProblemAnalyseOnlyOne(Request $request) { $start_time = $request->input('start_time'); $end_time = $request->input('end_time'); $warea_name = $request->input('warea_name'); $re = ApplyCustomerDetail::query(); $ids = ApplyCustomer::where('warea_name', $warea_name); if ($start_time && $end_time) { $ids->whereBetween('created_at', [$start_time, $end_time]); } $ids = $ids->pluck('id'); $re = $re->whereIn('customer_id', $ids)->groupBy('problem_info')->select('problem_info', DB::raw('sum(total) as total'))->get(); return $this->success($re); } /**代理公司调换数量统计**/ public function CrownProblemAnalyseOnlyOne(Request $request) { $start_time = $request->input('start_time'); $end_time = $request->input('end_time'); $search_id = $request->input('search_id'); $re = ApplyCustomerDetail::query(); $ids = ApplyCustomer::where('apply_crown_id', $search_id); if ($start_time && $end_time) { $ids->whereBetween('created_at', [$start_time, $end_time]); } $ids = $ids->pluck('id'); $re = $re->whereIn('customer_id', $ids)->groupBy('problem_info')->select('problem_info', DB::raw('sum(total) as total'))->get(); return $this->success($re); } /**获取物流轨迹**/ public function ExpressSearch(Request $request, ExpressHandler $expressHandler) { $express = CustomerReturn::find($request->id); if (!$express) { return $this->error(40011, '', '该物流订单不存在'); } if ($express->express_status == 1) { return $this->success(json_decode($express->express_data)); } else { $re = $expressHandler->search($express->express_num, $express->express_code); $re = (array)$re; if ($re['State'] == 3) { DB::beginTransaction(); try { $express->express_data = json_encode($re); $express->express_status = 1; $express->save(); DB::commit(); } catch (\Exception $exception) { Log::error('-------物流信息保存出错--------' . $exception); DB::rollBack(); } } return $this->success($re); } } /*导出申请单**/ // public function ExportApplyList(Request $request){ // $search_name=$request->input('search_name'); // $customer_name=$request->input('customer_name'); // $warea_name=$request->input('warea_name'); // $apply_status=$request->input('apply_status'); // $is_finish=$request->input('is_finish'); // $re=ApplyCustomer::query(); // // if (is_numeric($apply_status)){ // $re->where('apply_status',$apply_status); // } // if (is_numeric($is_finish)){ // $re->where('is_finish',$is_finish); // } // // if ($warea_name){ // $re->where('warea_name',$warea_name); // } // if ($search_name){ // $re->where('apply_user_nickname','like',"$search_name"); // } // if ($customer_name){ // $re->where('customer_name','like',"$customer_name")->orWhere('customer_phone','like',"$customer_name"); // } // $data=$re->where('audit_status',1)->with(['applydetail'])->orderByDesc('id')->get(); // return $this->success($data); // } /**毛毛审核**/ public function AuditApplyList(Request $request) { $ids = $request->input('id'); ApplyCustomer::whereIn('id', $ids)->update(['audit_status' => 1]); return $this->success([]); } /*退回审核**/ public function AuditBackApply(Request $request) { $id = $request->input('id'); ApplyCustomer::where('id', $id)->update(['audit_status' => 0]); return $this->success([]); } /*导出申请单**/ public function ExportApplyLists(Request $request) { $search_name = $request->input('search_name'); $customer_name = $request->input('customer_name'); $warea_name = $request->input('warea_name'); $apply_status = $request->input('apply_status'); $is_finish = $request->input('is_finish'); $start_time = $request->input('start_time') ?? null; $end_time = $request->input('end_time'); $re = CustomerReturn::query(); if (is_numeric($apply_status)) { $re->where('apply_status', $apply_status); } if (is_numeric($is_finish)) { $re->where('is_finish', $is_finish); } if ($warea_name) { $re->where('warea_name', $warea_name); } if ($search_name) { $re->where('user_nickname', 'like', "$search_name"); } if ($customer_name) { $re->where('customer_name', 'like', "$customer_name")->orWhere('customer_phone', 'like', "$customer_name"); } if (Auth::user()->role_id == 23) { $warea_names = Warea::where('admin_id', Auth::user()->id)->value('name'); $re->where('warea_name', $warea_names); } if ($start_time) { $re->whereBetween('created_at', [$start_time, $end_time]); } /**只能导出已经审核的申请表**/ $data = $re->with(['applydetail'])->orderByDesc('id')->get(); $arr = [ '男款-L' => '男L', '男款-XL' => '男XL', '男款-XXL' => '男XXL', '男款-3XL' => '男3XL', '男款-4XL' => '男4XL', '女款-M' => '女M', '女款-L' => '女L', '女款-XL' => '女XL', '女款-XXL' => '女XXL', '女款-3XL' => '女3XL', '女款-4XL' => '女4XL', '男款-5XL' => '男5XL' ]; // $a=["L" => null,"XL" => null,"XXL" => null, "XXXL" => null, "女M" => null, "女L" => null, "女XL" => null, "女XXL" => null, "女XXXL" => null, "女4XL" => null, "5XL" => null]; // $arrs=array_keys($arr); $res = []; foreach ($data as $k => $v) { $res[$k]['退货单号'] = $v->apply_number; $res[$k]['政委'] = $v->op_name; $res[$k]['代理公司'] = $v->crown_nickname; $res[$k]['所属代理'] = $v->user_nickname; $res[$k]['顾客'] = $v->customer_name; $res[$k]['顾客手机号'] = $v->customer_phone; $res[$k]['省份'] = $v->province; $res[$k]['城市'] = $v->city; $res[$k]['地区'] = $v->area; $res[$k]['详细地址'] = $v->address; $res[$k]['总数量'] = $v->total; $res[$k]['登记时间'] = $v->created_at->toDateTimeString(); $res[$k]['退货原因'] = ''; $res[$k]['男款'] = 0; $res[$k]['女款'] = 0; $res[$k]['男L'] = ''; $res[$k]['男XL'] = ''; $res[$k]['男XXL'] = ''; $res[$k]['男3XL'] = ''; $res[$k]['男4XL'] = ''; $res[$k]['女M'] = ''; $res[$k]['女L'] = ''; $res[$k]['女XL'] = ''; $res[$k]['女XXL'] = ''; $res[$k]['女3XL'] = ''; $res[$k]['女4XL'] = ''; $res[$k]['男5XL'] = ''; $res[$k]['备注'] = $v->remark ?? '退'; $res[$k]['款式'] = ''; $arrs = []; foreach ($v->applydetail as $ke => $va) { if ($ke == 0) { $res[$k]['款式'] = $va->good_name; } else { $good = $va->good_name; if ($good != $res[$k]['款式']) { $res[$k]['款式'] = '杂'; } } if (isset($arrs[$va->good_name])) { $size_arr = array_column($arrs[$va->good_name], 'good_size'); if (in_array($va->good_size, $size_arr)) { foreach ($arrs[$va->real_change_good] as $kes => $vals) { if ($vals['size'] == $va->good_size) { $arrs[$va->good_name][$kes]['total'] += $va->totals; } } } else { $arrs[$va->good_name][] = ['total' => $va->total, 'size' => $va->good_size, 'customer_id' => $va->customer_id]; } } else { $arrs[$va->good_name][] = ['total' => $va->total, 'size' => $va->good_size, 'customer_id' => $va->customer_id]; } $sex = strpos($va->real_change_size, '男'); if (is_numeric($sex)) { $res[$k]['男款'] += $va->total; } else { $res[$k]['女款'] += $va->total; } $res[$k]['退货原因'] .= $va->problem_info . ','; } $res[$k]['arrs'] = $arrs; foreach ($arrs as $ke => $vas) { $nu = strpos($ke, '棉'); foreach ($vas as $kes => $val) { if (is_numeric($nu)) { $res[$k][$arr[$val['size']]] .= $val['total'] . '条棉'; } else { $res[$k][$arr[$val['size']]] .= $val['total'] . '条' . mb_substr($ke, 0, 1); } } } } return $this->success($res); } /**异常统计*/ public function GetExceptionList(Request $request) { $start_time = $request->input('start_time'); $end_time = $request->input('end_time'); $page_index = $request->input('page_index'); $page_size = $request->input('page_size'); $type = $request->input('type') ?? 1; $num = ($page_index - 1) * $page_size; $re = ApplyCustomer::query(); if ($start_time) { $re->whereBetween('created_at', [$start_time, $end_time]); } if (Auth::user()->role_id == 23) { $warea_names = Warea::where('admin_id', Auth::user()->id)->value('name'); $re->where('warea_name', $warea_names); } if ($type == 0) { $re = $re->groupBy('customer_phone') ->select('*', DB::raw('sum(total) as totals')) ->having('totals', '>=', 2); $res = clone $re; $res = $res->get(); $count = count($res); } else { $re->whereNotNull('express_time')->where('express_status', 0) ->where('express_time', '<', Carbon::now()->addDays(-4)) ->select('*'); $count = $re->count(); } $list = $re->take($page_size)->skip($num)->get(); return $this->success_list($list, '', $count); } public function GetExceptionExpressList(Request $request) { $start_time = $request->input('start_time'); $end_time = $request->input('end_time'); $page_index = $request->input('page_index'); $page_size = $request->input('page_size'); $num = ($page_index - 1) * $page_size; $re = ApplyCustomer::query(); if ($start_time) { $re->whereBetween('created_at', [$start_time, $end_time]); } if (Auth::user()->role_id == 23) { $warea_names = Warea::where('admin_id', Auth::user()->id)->value('name'); $re->where('warea_name', $warea_names); } $re = $re->whereNotNull('express_time')->where('express_status', 0) ->where('express_time', '<', Carbon::now()->addDays(-4))->groupBy('customer_phone') ->select('*'); $count = $re->count(); $list = $re->take($page_size)->skip($num)->get(); return $this->success_list($list, '', $count); } /**更新状态**/ public function UpdateApplyInfos(Request $request) { $file = $request->file('file'); if (!$file->isValid()) { //判断文件是否有效 return redirect() ->back() ->withErrors('文件上传失败,请重新上传'); } $array = Excel::toArray(new ExpressImport, request()->file('file')); if (count($array) > 10001) { return $this->error('450001', "单次最多导入10000条数据"); } $one = array_shift($array[0]); $express_num_keys = array_search('快递单号', $one); if (!$express_num_keys && !is_numeric($express_num_keys)) { return $this->error('450001', "表头无'快递单号'字段"); } $arr = array_column($array[0], $express_num_keys); } /**标记为欠货**/ public function TagOwe(Request $request) { $ids = $request->input('id'); ApplyCustomer::whereIn('id', $ids)->update(['is_owe' => 1]); return $this->success([]); } /**取消标记为欠货**/ public function CancelTagOwe(Request $request) { $ids = $request->input('id'); ApplyCustomer::whereIn('id', $ids)->update(['is_owe' => 0]); return $this->success([]); } /**校验是否有重复的*/ public function CheckRepeatInfo(Request $request) { $customer_phone = $request->input('customer_phone'); $customer_name = $request->input('customer_name'); $time = Carbon::now()->addDays(-6); $count = ApplyCustomer::where('customer_phone', $customer_phone) ->where('customer_name', $customer_name) ->where('created_at', '>', $time) ->count(); if ($count > 0) { return $this->success(['status' => 1]); } return $this->success(['status' => 0]); } /* * 删除申请 * **/ public function DelApplyCustomer(Request $request) { $id = $request->input('id'); // $CustomerApply=ApplyCustomer::find($id); $ApplyDetail = ApplyCustomerDetail::where('customer_id', $id)->get(); foreach ($ApplyDetail as $k => $v) { $re = StoreHouseStorage::where('good_name', $v->real_change_good) ->where('size', $v->real_change_size) ->lockForUpdate() ->first(); $re->storage += $v->total; $re->save(); ApplyCustomerDetail::where('id', $v->id)->delete(); } ApplyCustomer::where('id', $id)->delete(); return $this->success([]); } /* * 获取该代理下所有的退货人信息 * **/ public function GetCustomerInfo(Request $request) { $user_id = $request->input('user_id'); $re = ApplyCustomer::where('apply_user_id', $user_id)->with(['applydetail'])->get(); return $this->success($re); } /* * 手动签收 * ***/ public function Receipt(Request $request) { $re = ApplyCustomer::where('id', $request->input('id'))->first(); $re->express_status = 1; $re->remark = $re->remark . '**' . Auth::user()->name . '主动签收了改退货单'; $re->save(); return $this->success([]); } public function ExportApplyListss(Request $request) { $search_name = $request->input('search_name'); $customer_name = $request->input('customer_name'); $warea_name = $request->input('warea_name'); $apply_status = $request->input('apply_status'); $is_finish = $request->input('is_finish'); $start_time = $request->input('start_time') ?? null; $end_time = $request->input('end_time'); $re = ApplyCustomer::query(); if (is_numeric($apply_status)) { $re->where('apply_status', $apply_status); } if (is_numeric($is_finish)) { $re->where('is_finish', $is_finish); } if ($warea_name) { $re->where('warea_name', $warea_name); } if ($search_name) { $re->where('apply_user_nickname', 'like', "$search_name"); } if ($customer_name) { $re->where('customer_name', 'like', "$customer_name")->orWhere('customer_phone', 'like', "$customer_name"); } if ($start_time) { $re->whereBetween('created_at', [$start_time, $end_time]); } /**只能导出已经审核的申请表**/ $data = $re->with(['applydetail' => function ($q) { $q->select('id', 'real_change_good', 'real_change_size', 'total as totals', 'customer_id', 'problem_info'); }, 'applydetails' => function ($q) { $q->select('id', 'real_change_good', 'real_change_size', 'total as totals', 'customer_id', 'problem_info')->groupBy('real_change_good'); }])->orderByDesc('id')->get(); $arr = [ '男款-L' => '男L', '男款-XL' => '男XL', '男款-XXL' => '男XXL', '男款-3XL' => '男3XL', '男款-4XL' => '男4XL', '女款-M' => '女M', '女款-L' => '女L', '女款-XL' => '女XL', '女款-XXL' => '女XXL', '女款-3XL' => '女3XL', '女款-4XL' => '女4XL', '男款-5XL' => '男5XL' ]; // $a=["L" => null,"XL" => null,"XXL" => null, "XXXL" => null, "女M" => null, "女L" => null, "女XL" => null, "女XXL" => null, "女XXXL" => null, "女4XL" => null, "5XL" => null]; // $arrs=array_keys($arr); $res = []; foreach ($data as $k => $v) { $res[$k]['调换单号'] = $v->apply_number; $res[$k]['政委'] = $v->op_name; $res[$k]['代理公司'] = $v->apply_crown_nickname; $res[$k]['申请代理'] = $v->apply_user_nickname; $res[$k]['收货人'] = $v->customer_name; $res[$k]['收货手机号'] = $v->customer_phone; $res[$k]['省份'] = $v->province; $res[$k]['城市'] = $v->city; $res[$k]['地区'] = $v->area; $res[$k]['详细地址'] = $v->address; $res[$k]['总数量'] = $v->total; $res[$k]['穿着时间'] = $v->wear_time; $res[$k]['登记时间'] = $v->created_at->toDateTimeString(); $res[$k]['调换原因'] = ''; $res[$k]['男款'] = 0; $res[$k]['女款'] = 0; $res[$k]['男L'] = ''; $res[$k]['男XL'] = ''; $res[$k]['男XXL'] = ''; $res[$k]['男3XL'] = ''; $res[$k]['男4XL'] = ''; $res[$k]['女M'] = ''; $res[$k]['女L'] = ''; $res[$k]['女XL'] = ''; $res[$k]['女XXL'] = ''; $res[$k]['女3XL'] = ''; $res[$k]['女4XL'] = ''; $res[$k]['男5XL'] = ''; $res[$k]['备注'] = $v->remark ?? '调'; $res[$k]['款式'] = ''; $arrs = []; foreach ($v->applydetail as $ke => $va) { if ($ke == 0) { $res[$k]['款式'] = $va->real_change_good; } else { $good = $va->real_change_good; if ($good != $res[$k]['款式']) { $res[$k]['款式'] = '杂'; } } if (isset($arrs[$va->real_change_good])) { $size_arr = array_column($arrs[$va->real_change_good], 'size'); if (in_array($va->real_change_size, $size_arr)) { foreach ($arrs[$va->real_change_good] as $kes => $vals) { if ($vals['size'] == $va->real_change_size) { $arrs[$va->real_change_good][$kes]['total'] += $va->totals; } } } else { $arrs[$va->real_change_good][] = ['total' => $va->totals, 'size' => $va->real_change_size, 'customer_id' => $va->customer_id]; } } else { $arrs[$va->real_change_good][] = ['total' => $va->totals, 'size' => $va->real_change_size, 'customer_id' => $va->customer_id]; } dump($arrs); // $arrs[$va->real_change_good]=['total'=>$va->total,'']; $sex = strpos($va->real_change_size, '男'); if (is_numeric($sex)) { $res[$k]['男款'] += $va->totals; } else { $res[$k]['女款'] += $va->totals; } $res[$k]['调换原因'] .= $va->problem_info . ','; } foreach ($arrs as $ke => $vas) { $nu = strpos($ke, '棉'); foreach ($vas as $kes => $val) { if (is_numeric($nu)) { $res[$k][$arr[$val['size']]] .= $val['total'] . '条棉'; } else { $res[$k][$arr[$val['size']]] .= $val['total'] . '条' . mb_substr($ke, 0, 1); } } } $res[$k]['arr'] = $arrs; } return $this->success($res); } /* * 政委登记物流 * **/ public function UploadReturnExpressInfo(Request $request){ $data=$request->all(); $customser=CustomerReturn::where('id',$data['id'])->first(); $customser->express_num=$data['express_num']; $customser->express_com=$data['express_com']; $customser->apply_status=2; $customser->save(); return $this->success([]); } /* * 政委登记 * **/ public function UploadReturnInfo(Request $request){ $data=$request->all(); $customser=CustomerReturn::where('id',$data['id'])->first(); $customser->sendback_imgList=$data['imgurl']; $customser->sendback_time=$data['sendback_time']; $customser->apply_status=3; $customser->save(); return $this->success([]); } /* * 政委登记 * **/ public function UploadCrownReturnInfo(Request $request){ $data=$request->all(); $customser=CustomerReturn::where('id',$data['id'])->first(); $customser->crown_img=$data['crown_img']; $customser->crown_time=$data['crown_time']; $customser->fact_money=$data['fact_money']; $customser->factList=$data['factList']; $customser->fact_log=$data['fact_log']; $customser->apply_status=4; $customser->is_finish=1; $customser->save(); return $this->success([]); } /**获取历史信息**/ public function GetHistory(Request $request){ $data=$request->all(); if ($data['status']==0){ // $name='test_456'; $name=Auth::user()->name; $num=CustomerReturn::where('customer_phone',$data['phone'])->where('op_name','<>',$name)->first(); if ($num){ return $this->error(500214,'该顾客在政委'.$num->op_name.'退过货'); } } $total=CustomerReturn::where('customer_phone',$data['phone'])->sum('total'); $info=CustomerReturn::where('customer_phone',$data['phone'])->orderBy('created_at')->first(); $day=''; if ($info){ $day=Carbon::parse($info->created_at)->diffInDays(); if ($day>32){ $day=Carbon::parse($info->created_at)->diffInMonths(); if ($day>12){ $day=Carbon::parse($info->created_at)->diffInYears(); $day=$day.'年'; }else{ $day=$day.'月'; } }else{ $day=$day.'天'; } } return $this->success(['total'=>$total,'time'=>$day]); } /**获取微店关联信息**/ public function GetStore(Request $request){ $data=$request->all(); $user=WdUser::where('phone',$data['phone'])->value('id'); $users=WdOrder::where('user_id',$user)->value('store_id'); $user_id=WdStore::where('id',$users)->value('user_id'); $re=User::where('id',$user_id)->with(['crown','warea']) ->select('nickname','mobile','headimgurl','crown_id','id as user_id','warea_id')->first(); return $this->success($re); } /* * * 根据级别分类 * **/ public function GetLevelAnalysis(Request $request){ $start_time=$request->input('start_time')??null; $end_time=$request->input('end_time')??null; $re=CustomerReturn::query(); if ($start_time){ $re->whereBetween('customer_return.created_at',[$start_time,$end_time]); }else{ $re->where('customer_return.created_at','>=',Carbon::now()->addDays(-30)); } // $re->where('is_finish',1); $res=$re->leftJoin('users','users.id','=','customer_return.user_id') ->select('users.level',DB::raw('sum(customer_return.total) as total'))->groupBy('users.level')->orderBy('users.level')->get(); $data=[ ['level'=>null,'total'=>0], ['level'=>1,'total'=>0], ['level'=>2,'total'=>0], ['level'=>3,'total'=>0], ]; foreach ($data as $k=>$v){ foreach ($res as $ke=>$va){ if ($va->level==$v['level']){ $data[$k]=$va; } } } return $this->success($data); } /* * * 根据级别分类 * **/ public function GetNumPriceAnalysis(Request $request){ $start_time=$request->input('start_time')??null; $end_time=$request->input('end_time')??null; $re=CustomerReturn::query(); if ($start_time){ $re->whereBetween('created_at',[$start_time,$end_time]); }else{ $re->where('created_at','>=',Carbon::now()->addDays(-30)); } // $re->where('is_finish',1); $ids=$re->pluck('id')->toArray(); $res=CustomerReturnDetail::whereIn('customer_id',$ids) ->select(DB::raw('sum(total) as total'),DB::raw('sum(price) as price'),'good_name')->groupBy('good_name')->get(); return $this->success($res); } public function GetCustomerAnalysis(Request $request){ $start_time=$request->input('start_time')??null; $end_time=$request->input('end_time')??null; $start_status=true; $re=CustomerReturn::query(); if ($start_time){ $re->whereBetween('created_at',[$start_time,$end_time]); }else{ $start_time=Carbon::now()->addDays(-7); $end_time=Carbon::now(); $re->where('created_at','>=',Carbon::now()->addDays(-7)); } // $re->where('is_finish',1); $res=$re->select(DB::raw('sum(total) as totals'),DB::raw('sum(price) as price'),'customer_name','customer_phone','id') ->orderByDesc('totals') ->groupBy('customer_phone')->get()->toArray(); foreach ($res as $k=>$v){ $ids=CustomerReturn::where('customer_phone',$v['customer_phone'])->whereBetween('created_at',[$start_time,$end_time])->pluck('id'); $good_info=CustomerReturnDetail::whereIn('customer_id',$ids) ->select(DB::raw('sum(total) as total'),DB::raw('sum(price) as price'),'good_name')->groupBy('good_name')->get(); $ress=CustomerReturn::where('customer_phone',$v['customer_phone'])->groupBy('op_name')->get(); if (count($ress)>1){ $res[$k]['Exception']=1; }else{ $res[$k]['Exception']=0; } $res[$k]['good_info']=$good_info; } return $this->success($res); } public function Getinfo(){ // $s='http://qny.d0w.cc/daweiboshi-app/20221125/14583080627638067967e993.jpg'; // $b='tp://api.app.jiuweiyun.cn'; // $sa=stripos($s,$b); // if ($sa==2){ // dd(10); // } // $re=WdStore::where('id',105)->get(); // dd($re->toArray()); // 获取七牛云配置信息 $config = config('filesystems.disks.qiniunew'); Log::info($config); // 构建鉴权对象 $auth = new Auths($config['access_key'], $config['secret_key']); // 生成上传 Token $token = $auth->uploadToken($config['bucket']); //获取文件的绝对路径,但是获取到的在本地不能打开 $filePath = 'http://api.app.jiuweiyun.cn/cert/20210323/09453560567.jpg'; $filename = 111 . '_' . time() . '_' . str_random(10) . '.png' ; // 初始化 UploadManager 对象并进行文件的上传。 $data=['QrCode/a.jpg','QrCode/b.jpg']; foreach ($data as $k=>$v){ $uploadMgr = new UploadManager(); // 调用 UploadManager 的 putFile 方法进行文件的上传。 $pathname= $config['dirname'].'/cert/20090327/1153001115'.$k.'.jpg'; $uploadMgr->putFile($token, $pathname, $v); } dd(1); } public function uploadImg(Request $request){ $file= $request->file('file'); $path_url='goods/refundGoods'; $upload= new UploadFilesHandler(); $result= $upload->save($file, $path_url, null, 'image'); if($result){ return $this->success($result['path']); } return $this->error(); } public function uploadStoreImg(Request $request){ $file= $request->file('file'); $path_url='store/store'; $upload= new UploadFilesHandler(); $result= $upload->save($file, $path_url, null, 'image'); if($result){ return $this->success($result['path']); } return $this->error(); } }