1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414 |
- <?php
- namespace Modules\Service\Http\Controllers;
- use Modules\Service\Events\CustomerSendSmsEvent;
- use App\Handlers\ExpressHandler;
- use App\Imports\ExpressImport;
- use App\Models\ApplyCustomer;
- use App\Models\ApplyCustomerDetail;
- use App\Models\Express;
- use App\Models\ProblemCollection;
- use App\Models\StoreHouseLog;
- use App\Models\StoreHouseStorage;
- use App\Models\User;
- use App\Models\Warea;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- use Maatwebsite\Excel\Facades\Excel;
- class CustomerChangeController extends Controller
- {
- /***
- * _ooOoo_
- * o8888888o
- * 88" . "88
- * (| -_- |)
- * O\ = /O
- * ___/`---'\____
- * . ' \\| |// `.
- * / \\||| : |||// \
- * / _||||| -:- |||||- \
- * | | \\\ - /// | |
- * | \_| ''\---/'' | |
- * \ .-\__ `-` ___/-. /
- * ___`. .' /--.--\ `. . __
- * ."" '< `.___\_<|>_/___.' >'"".
- * | | : `- \`.;`\ _ /`;.`/ - ` : | |
- * \ \ `-. \_ __\ /__ _/ .-` / /
- * ======`-.____`-.___\_____/___.-`____.-'======
- * `=---='
- * .............................................
- * 佛曰: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');
- $audit_status=$request->input('audit_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=ApplyCustomer::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 (Auth::user()->role_id==29){
- $re->whereIn('apply_status',[2,1]);
- $re->where('is_owe',$request->input('is_owe')??0);
- }else{
- if ($request->has('is_owe')){
- if (is_numeric($request->input('is_owe'))){
- $re->where('is_owe',$request->input('is_owe'));
- }
- }
- 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 (is_numeric($audit_status)){
- $re->where('audit_status',$audit_status);
- }
- 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.'%');
- }
- $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,ApplyCustomer $applyCustomer,ApplyCustomerDetail $applyCustomerDetail){
- $applyUserID=$request->input('apply_user_id');
- $applyUserName=$request->input('apply_user_nickname');
- $applyCrownID=$request->input('apply_crown_id');
- $applyCrownName=$request->input('apply_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');
- $wear_time=$request->input('wear_time');;
- $is_agent=$request->input('is_agent');;
- $problemList=$request->input('problemList');
- $sendback_info='';
- $apply_number=$this->CreateApplyNumber();
- $op_name=Auth::user()->name;
- $applyCustomer->apply_user_id=$applyUserID;
- $applyCustomer->apply_user_nickname=$applyUserName;
- $applyCustomer->apply_crown_id=$applyCrownID;
- $applyCustomer->apply_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->is_agent=$is_agent;
- $applyCustomer->wear_time=$wear_time;
- $applyCustomer->remark=$remark;
- $applyCustomer->apply_number=$apply_number;
- $applyCustomer->op_name=$op_name;
- DB::beginTransaction();
- try {
- if (!$applyCustomer->save()){
- throw new \Exception('1');
- }
- foreach ($problemList as $k=>$v){
- $re=StoreHouseStorage::where('good_name',$v['real_good_name'])->where('size',$v['real_good_size'])->first();
- if (!$re){
- return $this->error();
- }
- $res=StoreHouseStorage::where('id',$re->id)->lockForUpdate()->first();
- if ($res->storage<$v['total']){
- throw new \Exception('商品:'.$res->good_name.'的'.$res->size.'库存不足');
- }
- $res->storage-=$v['total'];
- if (!$res->save()){
- throw new \Exception('商品保存出错');
- }
- $logs=new StoreHouseLog();
- $log=Auth::user()->name.'调换了商品:'.$res->good_name.',尺码:'.$res->size.'。数量为:'.$v['total'];
- $logs->log=$log;
- $logs->customer_id=$applyCustomer->id;
- if (!$logs->save()){
- throw new \Exception('1');
- }
- $applyCustomerDetail=new ApplyCustomerDetail();
- $applyCustomerDetail->customer_id=$applyCustomer->id;
- $applyCustomerDetail->problem_info=$v['problem'];
- $applyCustomerDetail->good_name=$v['good_name'];
- $applyCustomerDetail->good_size=$v['good_size'];
- $applyCustomerDetail->total=$v['total'];
- $applyCustomerDetail->real_change_size=$v['real_good_size'];
- $applyCustomerDetail->real_change_good=$v['real_good_name'];
- $applyCustomerDetail->problem_attr=$v['problem_attr'];
- $applyCustomerDetail->label=$v['label'];
- if ($v['ImgList']){
- $applyCustomerDetail->ImgList=json_encode($v['ImgList']);
- }
- if (!$applyCustomerDetail->save()){
- throw new \Exception('1');
- }
- }
- DB::commit();
- return $this->success([]);
- }catch (\Exception $exception){
- DB::rollBack();
- return $this->error(520014,$exception->getMessage());
- }
- }
- /**修改申请单**/
- public function UpdateApply(Request $request){
- $id=$request->input('id');
- $applyUserID=$request->input('apply_user_id');
- $applyUserName=$request->input('apply_user_nickname');
- $applyCrownID=$request->input('apply_crown_id');
- $applyCrownName=$request->input('apply_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');
- // $wear_time=$request->input('wear_time');
- $is_agent=$request->input('is_agent');;
- $wear_time=$request->input('wear_time')??null;
- $NewproblemList=$request->input('NewproblemList');
- $UpdateproblemList=$request->input('UpdateproblemList');
- $DelproblemList=$request->input('DelproblemList')??[];
- $sendback_info='';
- $apply_number=$this->CreateApplyNumber();
- $op_name=Auth::user()->name;
- $applyCustomer=ApplyCustomer::where('id',$id)->first();
- if ($applyCustomer->audit_status==1){
- return $this->error(500213,'请联系审核人员退回后修改');
- }
- $applyCustomer->apply_user_id=$applyUserID;
- $applyCustomer->apply_user_nickname=$applyUserName;
- $applyCustomer->apply_crown_id=$applyCrownID;
- $applyCustomer->apply_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->is_agent=$is_agent;
- $applyCustomer->remark=$remark;
- $applyCustomer->apply_number=$apply_number;
- $applyCustomer->op_name=$op_name;
- $applyCustomer->wear_time=$wear_time;
- DB::beginTransaction();
- try {
- if (!$applyCustomer->save()){
- throw new \Exception('1');
- }
- /**新增的**/
- foreach ($NewproblemList as $k=>$v){
- $applyCustomerDetail=new ApplyCustomerDetail();
- $applyCustomerDetail->customer_id=$applyCustomer->id;
- $applyCustomerDetail->problem_info=$v['problem'];
- $applyCustomerDetail->good_name=$v['good_name'];
- $applyCustomerDetail->good_size=$v['good_size'];
- $applyCustomerDetail->total=$v['total'];
- $applyCustomerDetail->real_change_size=$v['real_good_size'];
- $applyCustomerDetail->real_change_good=$v['real_good_name'];
- $applyCustomerDetail->problem_attr=$v['problem_attr'];
- $applyCustomerDetail->label=$v['label'];
- if ($v['ImgList']){
- $applyCustomerDetail->ImgList=json_encode($v['ImgList']);
- }
- if (!$applyCustomerDetail->save()){
- throw new \Exception('1');
- }
- $re=StoreHouseStorage::where('good_name',$v['real_good_name'])->where('size',$v['real_good_size'])->first();
- if (!$re){
- return $this->error();
- }
- $res=StoreHouseStorage::where('id',$re->id)->lockForUpdate()->first();
- if ($res->storage<$v['total']){
- throw new \Exception('商品:'.$res->good_name.'的'.$res->size.'库存不足');
- }
- $res->storage-=$v['total'];
- if (!$res->save()){
- throw new \Exception('商品保存出错');
- }
- $logs=new StoreHouseLog();
- $log=Auth::user()->name.'调换了商品:'.$res->good_name.',尺码:'.$res->size.'。数量为:'.$v['total'];
- $logs->log=$log;
- $logs->customer_id=$applyCustomer->id;
- if (!$logs->save()){
- throw new \Exception('1');
- }
- }
- /**修改的*/
- foreach ($UpdateproblemList as $k=>$v){
- $applyCustomerDetail=ApplyCustomerDetail::where('id',$v['id'])->first();
- if ($applyCustomerDetail->total<$v['total']){
- $num=$v['total']-$applyCustomerDetail->total;
- $re=StoreHouseStorage::where('good_name',$v['real_good_name'])->where('size',$v['real_good_size'])->first();
- if (!$re){
- return $this->error();
- }
- $res=StoreHouseStorage::where('id',$re->id)->lockForUpdate()->first();
- if ($res->storage<$num){
- throw new \Exception('商品:'.$res->good_name.'的'.$res->size.'库存不足');
- }
- $res->storage-=$num;
- if (!$res->save()){
- throw new \Exception('商品保存出错');
- }
- }
- else{
- $num=$applyCustomerDetail->total-$v['total'];
- $re=StoreHouseStorage::where('good_name',$v['real_good_name'])->where('size',$v['real_good_size'])->first();
- if (!$re){
- return $this->error();
- }
- $res=StoreHouseStorage::where('id',$re->id)->lockForUpdate()->first();
- // if ($res->storage<$num){
- // throw new \Exception('商品:'.$res->good_name.'的库存不足');
- // }
- $res->storage+=$num;
- if (!$res->save()){
- throw new \Exception('商品保存出错');
- }
- }
- $applyCustomerDetail->problem_info=$v['problem'];
- $applyCustomerDetail->good_name=$v['good_name'];
- $applyCustomerDetail->good_size=$v['good_size'];
- $applyCustomerDetail->total=$v['total'];
- $applyCustomerDetail->real_change_size=$v['real_good_size'];
- $applyCustomerDetail->real_change_good=$v['real_good_name'];
- $applyCustomerDetail->problem_attr=$v['problem_attr'];
- $applyCustomerDetail->label=$v['label'];
- if ($v['ImgList']){
- $applyCustomerDetail->ImgList=json_encode($v['ImgList']);
- }
- if (!$applyCustomerDetail->save()){
- throw new \Exception('1');
- }
- }
- /**删除的*/
- foreach ($DelproblemList as $k=>$v){
- $applyCustomerDetail=ApplyCustomerDetail::find($v);
- $re=StoreHouseStorage::where('good_name',$applyCustomerDetail->real_change_good)->where('size',$applyCustomerDetail->real_change_size)->first();
- if (!$re){
- return $this->error();
- }
- $res=StoreHouseStorage::where('id',$re->id)->lockForUpdate()->first();
- // if ($res->storage<$num){
- // throw new \Exception('商品:'.$res->good_name.'的库存不足');
- // }
- $res->storage+=$applyCustomerDetail->total;
- if (!$res->save()){
- throw new \Exception('商品保存出错');
- }
- $applyCustomerDetail->delete();
- }
- DB::commit();
- return $this->success([]);
- }catch (\Exception $exception){
- DB::rollBack();
- return $this->error(520014,$exception->getMessage());
- }
- }
- /**判断数量**/
- public function CheckNum(Request $request){
- $re=StoreHouseStorage::where('good_name',$request->input('real_change_good'))->where('size',$request->input('real_change_size'))
- ->lockForUpdate()
- ->first();
- if (!$re){
- return $this->error(500214,'没有此商品');
- }
- if ($re->storage<$request->input('total')){
- return $this->error(500214,'更换的商品库存不足');
- }
- return $this->success([]);
- }
- /*客户退换申请单号**/
- public function CreateApplyNumber(){
- $id=Auth::user()->id;
- $str='DWBS-CE-';
- $string=$str.$id.substr(time(),6,9).rand(1111,9999);
- return $string;
- }
- /**特殊尺码的库存信息**/
- public function StoreHouseStorage(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');
- $re=StoreHouseStorage::query();
- $count=$re->count();
- $re=$re->get();
- return $this->success_list($re,'',$count);
- }
- /**更新库存**/
- public function UpdateStoreHouseStorage(Request $request){
- $id=$request->input('id');
- $storage=$request->input('storage');
- $re=StoreHouseStorage::where('id',$id)->lockForUpdate()->first();
- $num=$re->storage;
- $re->storage=$storage;
- $logs=new StoreHouseLog();
- $log=Auth::user()->name.'更新了商品:'.$re->good_name.',尺码:'.$re->size.'。更改前数量为:'.$num.',更新后数量为:'.$storage;
- $logs->log=$log;
- $logs->type=1;
- DB::beginTransaction();
- try {
- if ( !$re->save()){
- throw new \Exception('1');
- }
- if (!$logs->save()){
- throw new \Exception('1');
- }
- DB::commit();
- return $this->success([]);
- }catch (\Exception $exception){
- DB::rollBack();
- return $this->error(500214,$exception->getMessage());
- }
- }
- /**更新库存**/
- public function AddStoreHouseStorage(Request $request){
- $storage=$request->input('storage');
- $good_name=$request->input('good_name');
- $size=$request->input('size');
- $re=new StoreHouseStorage();
- $re->storage=$storage;
- $re->good_name=$good_name;
- $re->size=$size;
- $logs=new StoreHouseLog();
- $log=Auth::user()->name.'增加了商品:'.$good_name.',尺码:'.$size.'。数量为:'.$storage;
- $logs->log=$log;
- $logs->type=1;
- DB::beginTransaction();
- try {
- if ( !$re->save()){
- throw new \Exception('1');
- }
- if (!$logs->save()){
- throw new \Exception('1');
- }
- DB::commit();
- return $this->success([]);
- }catch (\Exception $exception){
- DB::rollBack();
- return $this->error(500214,$exception->getMessage());
- }
- }
- /**上传订单号**/
- 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=1;
- $problemCollection->problem_id=$problem_id;
- $problemCollection->save();
- return $this->success([]);
- }
- public function GetProblemCollection(Request $request){
- $type=$request->input('type')??1;
- $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=ApplyCustomer::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=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 (Auth::user()->role_id==23){
- $warea_names=Warea::where('admin_id',Auth::user()->id)->value('name');
- $re->where('warea_name',$warea_names);
- }
- if (Auth::user()->role_id==29){
- $re->where('audit_status',1);
- $re->where('is_owe',0);
- }else{
- if ($request->has('is_owe')){
- if (is_numeric($request->input('is_owe'))){
- $re->where('is_owe',$request->input('is_owe'));
- }
- }
- $audit_status=$request->input('audit_status');
- if (is_numeric($audit_status)){
- $re->where('audit_status',$audit_status);
- }
- 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');
- }])->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];
- }
- $sex=strpos($va->real_change_size,'男');
- if (is_numeric($sex)){
- $res[$k]['男款']+=$va->totals;
- }else{
- $res[$k]['女款']+=$va->totals;
- }
- $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 SearchUser(Request $request){
- $search_name=$request->input('search_name');
- $warea_id=$request->input('warea_id')??null;
- $user=User::whereNull('deleted_at');
- if ($warea_id){
- $user->where('warea_id',$warea_id);
- }
- $user=$user->where(function ($q)use($search_name){
- $q->where('nickname','like',"%$search_name%")->orwhere('mobile','like',"%$search_name%")->orwhere('remark_name','like',"%$search_name%");
- })->with(['warea'])->select('id','nickname','remark_name','mobile','level','headimgurl','warea_id')->get();
- return $this->success($user);
- }
- 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);
- }
- }
|