123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\Express;
- use App\Models\ExpressStorage;
- use App\Models\Goodtest;
- use App\Models\Ordertest;
- use App\Models\StorageLog;
- use App\Models\StoragePutLog;
- use App\Models\UserStorage;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\DB;
- class StorageController extends Controller{
- /**查看货物**/
- public function look_good(Request $request){
- $id=$request->id;
- $ids=Auth::user()->id;
- // $ids=39516;
- $re=Express::where('order_id',$id)->with(['get_express'=>function($q)use($id){
- $q->where('order_id',$id);
- },'get_order'])->orderByDesc('number')->groupBy('number')->get();
- $data=[];
- foreach ($re as $k=>$v){
- $data[$k]=$v;
- if ($ids==$v->get_order->good_user_id){
- $data[$k]['is_per']=true;
- }else{
- $data[$k]['is_per']=false;
- }
- }
- return $this->success_list($data);
- }
- /*
- * 货物详情
- * **/
- public function good_detail(Request $request){
- $re=ExpressStorage::where('express_id',$request->id)->groupBy('type')->get();
- $datas=Goodtest::where('is_deleted',0)->where('id','>',57)->groupBy('main_attr')->get();
- foreach ($datas as $k=>$v){
- $r[$v->main_attr]=$v->main_img;
- }
- $data=[
- 'hard'=>['spec'=>[],'imgurl'=>$r['大卫博士精装版'],'name'=>'大卫博士精装版'],
- 'simple'=>['spec'=>[],'imgurl'=>$r['大卫博士简约版'],'name'=>'大卫博士简约版'],
- 'old'=>['spec'=>[],'imgurl'=>$r['大卫博士高腰版'],'name'=>'大卫博士高腰版'],
- 'new_old'=>['spec'=>[],'imgurl'=>$r['大卫博士纯棉老人版'],'name'=>'大卫博士纯棉老人版'],
- 'youth'=>['spec'=>[],'imgurl'=>$r['大卫博士青春版'],'name'=>'大卫博士青春版'],
- 'right'=>['spec'=>[],'imgurl'=>$r['红色贺岁款(精装版)'],'name'=>'红色贺岁款(精装版)'],
- ];
- foreach ($re as $k=>$v){
- $res=ExpressStorage::where('express_id',$request->id)->where('type',$v->type)->select('size','sex','type','num')->get()->toArray();
- if ($v->type==0){
- $data['hard']['spec']=$res;
- }elseif ($v->type==1){
- $data['simple']['spec']=$res;
- }elseif ($v->type==2){
- $data['old']['spec']=$res;
- }elseif(($v->type==3)){
- $data['new_old']['spec']=$res;
- }elseif(($v->type==4)){
- $data['youth']['spec']=$res;
- }elseif(($v->type==5)){
- $data['right']['spec']=$res;
- }
- }
- return $this->success($data);
- }
- /*
- * 我的库存
- * **/
- public function my_storage(){
- $id=Auth::user()->id;
- // $id=39516;
- $re=UserStorage::where('user_id',$id)->groupBy('type')->select(DB::raw('sum(num) as total'),'type')->get();
- $res=UserStorage::where('user_id',$id)->first();
- $data=['hard'=>0,'simple'=>0,'old'=>0,'new_old'=>0,'youth'=>0];
- foreach ($re as $k=>$v){
- if ($v->type==0){
- $data['hard']=$v->total;
- }elseif ($v->type==1){
- $data['simple']=$v->total;
- }elseif ($v->type==2){
- $data['old']=$v->total;
- }elseif($v->type==3){
- $data['new_old']=$v->total;
- }elseif($v->type==4){
- $data['youth']=$v->total;
- }
- }
- if ($res){
- $data['status']=false;
- }else{
- $data['status']=true;
- }
- return $this->success($data);
- }
- /*
- *库存详情
- * **/
- public function storage_detail(Request $request){
- $id=Auth::user()->id;
- // $id=39516;
- $re=UserStorage::where('user_id',$id)->groupBy('type')->get();
- $datas=Goodtest::where('is_deleted',0)->where('id','>',57)->groupBy('main_attr')->get();
- foreach ($datas as $k=>$v){
- $r[$v->main_attr]=$v->main_img;
- }
- $data=[
- 'hard'=>['spec'=>[],'imgurl'=>$r['大卫博士精装版'],'name'=>'大卫博士精装版'],
- 'simple'=>['spec'=>[],'imgurl'=>$r['大卫博士简约版'],'name'=>'大卫博士简约版'],
- 'old'=>['spec'=>[],'imgurl'=>$r['大卫博士高腰版'],'name'=>'大卫博士高腰版'],
- 'new_old'=>['spec'=>[],'imgurl'=>$r['大卫博士纯棉老人版'],'name'=>'大卫博士纯棉版'],
- 'youth'=>['spec'=>[],'imgurl'=>$r['大卫博士青春版'],'name'=>'大卫博士青春版'],
- ];
- foreach ($re as $k=>$v){
- $res=UserStorage::where('user_id',$id)->where('type',$v->type)->select('size','sex','type','num')->get();
- if ($v->type==0){
- $data['hard']['spec']=$res;
- }elseif ($v->type==1){
- $data['simple']['spec']=$res;
- }elseif ($v->type==2){
- $data['old']['spec']=$res;
- }elseif($v->type==3){
- $data['new_old']['spec']=$res;
- }elseif($v->type==4){
- $data['youth']['spec']=$res;
- }
- }
- return $this->success($data);
- }
- /*
- * 待入库
- * ***/
- public function put_storage(Request $request){
- $input=$request->all();
- $id=Auth::user()->id;
- // $id=39516;
- $page_index=$input['page_index'];
- $data=Ordertest::where('user_id',$id)->where('good_user_id',$id)
- ->where('track_status','<>',0)
- ->where('created_at','>','2020-01-01 00:00:00')
- ->where('put_status',0)->select('id as order_id','created_at','number','order_num');
- $count=$data->count();
- $data=$data->take(20)->skip(($page_index-1)*20)->get();
- return $this->success_list($data,'',$count);
- }
- /*
- * 入库记录
- * ***/
- public function put_storage_group(Request $request){
- $input=$request->all();
- $id=Auth::user()->id;
- // $id=39516;
- $datas=Goodtest::where('is_deleted',0)->where('id','>',57)->groupBy('main_attr')->get();
- foreach ($datas as $k=>$v){
- $r[$v->main_attr]=$v->main_img;
- }
- $data=[
- 'hard'=>['imgurl'=>$r['大卫博士精装版'],'name'=>'大卫博士精装版','woman'=>0,'man'=>0],
- 'simple'=>['imgurl'=>$r['大卫博士简约版'],'name'=>'大卫博士简约版','woman'=>0,'man'=>0],
- 'old'=>['imgurl'=>$r['大卫博士高腰版'],'name'=>'大卫博士高腰版','woman'=>0,'man'=>0],
- 'new_old'=>['imgurl'=>$r['大卫博士纯棉老人版'],'name'=>'大卫博士纯棉老人版','woman'=>0,'man'=>0],
- 'youth'=>['imgurl'=>$r['大卫博士青春版'],'name'=>'大卫博士青春版','woman'=>0,'man'=>0],
- ];
- $where_type=[];
- $type=$input['record_type'];
- $status=$input['status'];
- if ($type){
- if ($type==1){
- if ($status==-1){
- $where_type=function ($q)use($type,$status){
- $q->where('storage_type',$type);
- };
- }else{
- $where_type=function ($q)use($type,$status){
- $q->where('storage_type',$type)->where('out_type',$status);
- };
- }
- }else{
- $where_type=function ($q)use($type,$status){
- $q->where('storage_type',$type);
- };
- }
- }
- $express=ExpressStorage::where('user_id',$id)->where($where_type);
- $where_start=[];
- $start=$input['start_time'];
- if ($start){
- $where_start=function ($q)use($start){
- $q->where('created_at','>=',$start);
- };
- }
- $where_end=[];
- $end=$input['end_time'];
- if ($end){
- $where_end=function ($q)use($end){
- $q->where('created_at','<=',$end);
- };
- }
- $re=$express->where($where_start)->where($where_end)->groupBy('type')->get();
- foreach ($re as $k=>$v){
- $woman=0;
- $man=0;
- if ($type==1){
- $res=ExpressStorage::where('user_id',$id)->where('type',$v->type)->where('storage_type',$type)->where($where_start)->where($where_end);
- if ($input['status']==-1){
- $res=$res->groupBy('sex')->select(DB::raw('sum(num) as total'),'sex')->get()->toArray();
- }else{
- $res=$res->where('out_type',$input['status'])->groupBy('sex')->select(DB::raw('sum(num) as total'),'sex')->get()->toArray();
- }
- foreach ($res as $ke=>$va){
- if ($va['sex']==0){
- $woman=$va['total'];
- }else{
- $man=$va['total'];
- }
- }
- }else{
- $res=ExpressStorage::where('user_id',$id)->where('type',$v->type)->where('storage_type',$type)->where($where_start)->where($where_end)->groupBy('sex')->select(DB::raw('sum(num) as total'),'sex')->get()->toArray();
- foreach ($res as $ke=>$va){
- if ($va['sex']==0){
- $woman=$va['total'];
- }else{
- $man=$va['total'];
- }
- }
- }
- if ($v->type==0){
- $data['hard']['man']=$man;
- $data['hard']['woman']=$woman;
- }elseif ($v->type==1){
- $data['simple']['man']=$man;
- $data['simple']['woman']=$woman;
- }elseif ($v->type==2){
- $data['old']['man']=$man;
- $data['old']['woman']=$woman;
- }elseif($v->type==3){
- $data['new_old']['man']=$man;
- $data['new_old']['woman']=$woman;
- }elseif($v->type==4){
- $data['youth']['man']=$man;
- $data['youth']['woman']=$woman;
- }
- }
- return $this->success($data);
- }
- public function put_storage_detail(Request $request){
- $input=$request->all();
- $id=Auth::user()->id;
- // $id=39516;
- $where_type=[];
- $status=$input['status'];
- if ($input['record_type']){
- $type=$input['record_type'];
- if ($type==1){
- if ($status!=-1){
- $where_type=function ($q)use($type,$status){
- $q->where('storage_type',$type)->where('out_type',$status);
- };
- }else{
- $where_type=function ($q)use($type,$status){
- $q->where('storage_type',$type);
- };
- }
- }else{
- $where_type=function ($q)use($type,$status){
- $q->where('storage_type',$type);
- };
- }
- }
- $express=ExpressStorage::where('user_id',$id)->where($where_type)->where('type',$input['type']);
- $where_start=[];
- $start=$input['start_time'];
- if ($start){
- if ($input['record_type']==1){
- $where_start=function ($q)use($start){
- $q->where('out_time','>=',$start);
- };
- }else{
- $where_start=function ($q)use($start){
- $q->where('created_at','>=',$start);
- };
- }
- }
- $where_end=[];
- $end=$input['end_time'];
- if ($end){
- if ($input['record_type']==1){
- $where_end=function ($q)use($end){
- $q->where('out_time','<=',$end);
- };
- }else{
- $where_end=function ($q)use($end){
- $q->where('created_at','<=',$end);
- };
- }
- }
- $re=$express->where($where_start)->where($where_end);
- $count=$re->count();
- $data=$re->take(20)->skip(($input['page_index']-1)*20)->get();
- return $this->success_list($data,'',$count);
- }
- public function put_good_storage(Request $request){
- // return $this->error(50026,'','入库操作暂停使用!如有疑问请联系客服!');
- $input=$request->all();
- $id=Auth::user()->id;
- // $id=39516;
- $d=UserStorage::where('user_id',$id)->first();
- if (!$d){
- return $this->error(50026,'','请盘库!');
- }
- $express=Express::find($input['id']);
- if ($express->put_status==1){
- return $this->error(50026,'','该货物已经入库,请退出刷新');
- }
- DB::beginTransaction();
- try{
- //查找这一箱的货物量
- $re=ExpressStorage::where('express_id',$input['id'])->select('sex','size','type','num')->get();
- //查找这一箱的信息
- foreach ($re as $k=>$v){
- //查找库存中有没有这个商品的记录
- $res=UserStorage::where('user_id',$id)->where('sex',$v->sex)->where('size',$v->size)->where('type',$v->type)->first();
- //有则加
- if ($res){
- if ($v->type==1||$v->type==2){
- $num=$v->num*4;
- }elseif ($v->type==3){
- $num=$v->num*6;
- }else{
- $num=$v->num;
- }
- $res->num+=$num;
- if (!$res->save()){
- throw new \Exception(1);
- }
- }else{
- //没有则新建
- $storage=new UserStorage();
- if ($v->type==1||$v->type==2){
- $storage->num=$v->num*4;
- }elseif ($v->type==3){
- $storage->num=$v->num*6;
- }else{
- $storage->num=$v->num;
- }
- $storage->size=$v->size;
- $storage->user_id=$id;
- $storage->sex=$v->sex;
- $storage->type=$v->type;
- if (!$storage->save()){
- throw new \Exception('1');
- }
- }
- $log=new StoragePutLog();
- $log->size=$v->size;
- $log->sex=$v->sex;
- $log->type=$v->type;;
- $log->user_id=$id;
- if ($v->type==1||$v->type==2){
- $log->num=$v->num*4;
- }elseif ($v->type==3){
- $log->num=$v->num*6;
- }else{
- $log->num=$v->num;
- }
- if (!$log->save()){
- throw new \Exception(1);
- }
- }
- //更改这一箱的状态为入库
- ExpressStorage::where('express_id',$input['id'])->select('sex','size','type','num')->update(['sure_time'=>Carbon::now(),'storage_type'=>2]);
- //更改这一样的装填为已完成
- $express->put_status=1;
- $express->put_time=Carbon::now();
- if (!$express->save()){
- throw new \Exception('1');
- }
- //查找订单
- $order=Ordertest::find($express->order_id);
- if ($order->track_status==2){
- //查看一下这个订单是不是都已经入库
- $count=Express::where('order_id',$order->id)->where('put_status',0)->count();
- if ($count==0){
- //全部入库后更改 订单状态为已完成的状态
- $order->put_status=1;
- if (!$order->save()){
- throw new \Exception(1);
- }
- }
- }
- DB::commit();
- return $this->success([]);
- }catch (\Exception $exception){
- DB::rollBack();
- return $this->error(50021,'','入库出错:'.$exception);
- }
- }
- /*
- * 判断是不是第一次盘库
- * ***/
- public function get_goodimg(){
- $datas=Goodtest::where('is_deleted',0)->where('id','>',57)->groupBy('main_attr')->get();
- foreach ($datas as $k=>$v){
- $r[$v->main_attr]=$v->main_img;
- }
- $data=[
- 'hard'=>['imgurl'=>$r['大卫博士精装版'],'name'=>'大卫博士精装版'],
- 'simple'=>['imgurl'=>$r['大卫博士简约版'],'name'=>'大卫博士简约版'],
- 'old'=>['imgurl'=>$r['大卫博士高腰版'],'name'=>'大卫博士高腰版'],
- 'new_old'=>['imgurl'=>$r['大卫博士纯棉老人版'],'name'=>'大卫博士纯棉老人版'],
- 'youth'=>['imgurl'=>$r['大卫博士青春版'],'name'=>'大卫博士青春版'],
- ];
- return $this->success($data);
- }
- /**一次性盘库**/
- public function one_sure_storage(Request $request){
- $id=Auth::user()->id;
- $re=UserStorage::where('user_id',$id)->first();
- if ($re){
- return $this->error(50024,'','该用户不能使用一次性盘货功能');
- }
- $input=$request->all();
- DB::beginTransaction();
- try{
- foreach ($input as $k=>$v){
- if($k=='hard'){
- $type=0;
- }elseif ($k=='simple'){
- $type=1;
- }elseif ($k=='old'){
- $type=2;
- }elseif($k=='new_old'){
- $type=3;
- }elseif($k=='youth'){
- $type=4;
- }
- foreach ($v as $ke=>$va){
- $storage=new UserStorage();
- $storage->user_id=$id;
- $storage->type=$type;
- $storage->size=$va['size'];
- $storage->num=$va['num'];
- $storage->sex=$va['sex'];
- $st_log=new StorageLog();
- $st_log->user_id=$id;
- $st_log->type=$type;
- $st_log->size=$va['size'];
- $st_log->num=$va['num'];
- $st_log->sex=$va['sex'];
- $st_log->number=1;
- $st_log->old_num=0;
- if (!$st_log->save()){
- throw new \Exception('1');
- }
- if (!$storage->save()){
- throw new \Exception('1');
- }
- }
- }
- DB::commit();
- return $this->success([]);
- }catch (\Exception $exception){
- DB::rollBack();
- return $this->error(50021,'',$exception);
- }
- }
- /*
- * 获取库存信息
- * ***/
- public function get_storage(Request $request){
- // $id=39516;
- $id=Auth::user()->id;
- $re=UserStorage::where('user_id',$id)->with(['get_storage'=>function($q)use($id){
- $q->where('user_id',$id)->select('sex','size','type','num');
- }])->groupBy('type')->get();
- $data=[
- 'hard'=>[],
- 'simple'=>[],
- 'old'=>[],
- 'new_old'=>[],
- 'youth'=>[],
- ];
- foreach ($re as $k=>$v){
- if ($v->type==0){
- $data['hard']=$v->get_storage;
- }elseif ($v->type==1){
- $data['simple']=$v->get_storage;
- }elseif ($v->type==2){
- $data['old']=$v->get_storage;
- }elseif ($v->type==4){
- $data['youth']=$v->get_storage;
- }else{
- $data['new_old']=$v->get_storage;
- }
- }
- return $this->success($data);
- }
- /**一次性盘库**/
- public function sure_storage(Request $request){
- $id=Auth::user()->id;
- $re=UserStorage::where('user_id',$id)->first();
- if (!$re){
- return $this->error(50024,'','该用户需要使用一次性盘货功能');
- }
- $number=StorageLog::where('user_id',$id)->max('number');
- $input=$request->all();
- DB::beginTransaction();
- try{
- foreach ($input as $k=>$v){
- if($k=='hard'){
- $type=0;
- }elseif ($k=='simple'){
- $type=1;
- }elseif ($k=='old'){
- $type=2;
- }elseif ($k=='youth'){
- $type=4;
- }else{
- $type=3;
- }
- foreach ($v as $ke=>$va){
- $storage=UserStorage::where('type',$type)->where('user_id',$id)->where('size',$va['size'])->where('sex',$va['sex'])->first();
- $st_log=new StorageLog();
- $st_log->number=$number+1;
- $st_log->sure_time=Carbon::now()->toDateTimeString();
- if ($storage){
- $st_log->old_num=$storage->num;
- if ($va['num']>$storage->num){
- $put_st=new StoragePutLog();
- $put_st->user_id=$id;
- $put_st->type=$type;
- $put_st->size=$va['size'];
- $put_st->num=$va['num']-$storage->num;
- $put_st->sex=$va['sex'];
- $put_st->storage_type=0;
- if (!$put_st->save()){
- throw new \Exception('1');
- }
- }elseif ($va['num']<$storage->num){
- $out_st=new ExpressStorage();
- $out_st->user_id=$id;
- $out_st->type=$type;
- $out_st->size=$va['size'];
- $out_st->num=$storage->num-$va['num'];
- $out_st->sex=$va['sex'];
- $out_st->storage_type=1;
- $out_st->out_time=Carbon::now();
- if (!$out_st->save()){
- throw new \Exception('1');
- }
- }
- $storage->num=$va['num'];
- }else{
- $storage=new UserStorage();
- $storage->user_id=$id;
- $storage->type=$type;
- $storage->size=$va['size'];
- $storage->num=$va['num'];
- $storage->sex=$va['sex'];
- $st_log->old_num=0;
- }
- $st_log->user_id=$id;
- $st_log->type=$type;
- $st_log->size=$va['size'];
- $st_log->num=$va['num'];
- $st_log->sex=$va['sex'];
- if (!$storage->save()){
- throw new \Exception('1');
- }
- if (!$st_log->save()){
- throw new \Exception('1');
- }
- }
- }
- DB::commit();
- return $this->success([]);
- }catch (\Exception $exception){
- DB::rollBack();
- return $this->error(50021,'',$exception);
- }
- }
- /***出库**/
- public function out_storage(Request $request){
- $id=Auth::user()->id;
- $re=UserStorage::where('user_id',$id)->first();
- if (!$re){
- return $this->error(50024,'','该用户需要使用一次性盘货功能');
- }
- $input=$request->all();
- DB::beginTransaction();
- try{
- foreach ($input['arr'] as $k=>$v){
- if($k=='hard'){
- $type=0;
- }elseif ($k=='simple'){
- $type=1;
- }elseif ($k=='old'){
- $type=2;
- }elseif ($k=='youth'){
- $type=4;
- }else{
- $type=3;
- }
- foreach ($v as $ke=>$va){
- if ($va['num']!=0){
- $storage=UserStorage::where('type',$type)->where('user_id',$id)->where('size',$va['size'])->where('sex',$va['sex'])->first();
- if (!$storage){
- return $this->error(50023,'','没有该商品的库存,请先使用盘库功能');
- }
- if ($storage->num<$va['num']){
- return $this->error(50023,'','该商品的出库量大于库存量,请先使用盘库修改库存');
- }
- $storage->num-=$va['num'];
- if (!$storage->save()){
- throw new \Exception('1');
- }
- $eStorage=new ExpressStorage();
- $eStorage->num=$va['num'];
- $eStorage->user_id=$id;
- $eStorage->out_type=$input['type'];
- $eStorage->size=$va['size'];
- $eStorage->sex=$va['sex'];
- $eStorage->type=$type;
- $eStorage->storage_type=1;
- $eStorage->out_time=Carbon::now();
- if (!$eStorage->save()){
- throw new \Exception('1');
- }
- }
- }
- }
- DB::commit();
- return $this->success([]);
- }catch (\Exception $exception){
- DB::rollBack();
- return $this->error(50021,'',$exception);
- }
- }
- /*
- * 盘库记录
- **/
- public function sure_storage_group(Request $request){
- $input=$request->all();
- $id=Auth::user()->id;
- // $id=39516;
- $datas=Goodtest::where('is_deleted',0)->where('id','>',57)->groupBy('main_attr')->get();
- foreach ($datas as $k=>$v){
- $r[$v->main_attr]=$v->main_img;
- }
- $data=[
- 'hard'=>['imgurl'=>$r['大卫博士精装版'],'name'=>'大卫博士精装版','woman'=>0,'man'=>0],
- 'simple'=>['imgurl'=>$r['大卫博士简约版'],'name'=>'大卫博士简约版','woman'=>0,'man'=>0],
- 'old'=>['imgurl'=>$r['大卫博士高腰版'],'name'=>'大卫博士高腰版','woman'=>0,'man'=>0],
- 'new_old'=>['imgurl'=>$r['大卫博士纯棉老人版'],'name'=>'大卫博士纯棉老人版','woman'=>0,'man'=>0],
- 'youth'=>['imgurl'=>$r['大卫博士青春版'],'name'=>'大卫博士青春版','woman'=>0,'man'=>0],
- ];
- $storage_log=StorageLog::where('user_id',$id);
- $where_start=[];
- $start=$input['start_time'];
- if ($start){
- $where_start=function ($q)use($start){
- $q->where('created_at','>=',$start);
- };
- }
- $where_end=[];
- $end=$input['end_time'];
- if ($end){
- $where_end=function ($q)use($end){
- $q->where('created_at','<=',$end);
- };
- }
- $re=$storage_log->where($where_start)->where($where_end)->groupBy('type')->get();
- foreach ($re as $k=>$v){
- $woman=0;
- $man=0;
- $res=StorageLog::where('user_id',$id)->where('type',$v->type)->where($where_start)->where($where_end)->groupBy('sex')->select(DB::raw('sum(num) as total'),'sex')->get()->toArray();
- foreach ($res as $ke=>$va){
- if ($va['sex']==0){
- $woman=$va['total'];
- }else{
- $man=$va['total'];
- }
- }
- if ($v->type==0){
- $data['hard']['man']=$man;
- $data['hard']['woman']=$woman;
- }elseif ($v->type==1){
- $data['simple']['man']=$man;
- $data['simple']['woman']=$woman;
- }elseif ($v->type==2){
- $data['old']['man']=$man;
- $data['old']['woman']=$woman;
- }elseif ($v->type==3){
- $data['new_old']['man']=$man;
- $data['new_old']['woman']=$woman;
- }elseif ($v->type==4){
- $data['youth']['man']=$man;
- $data['youth']['woman']=$woman;
- }
- }
- return $this->success($data);
- }
- public function sure_storage_detail(Request $request){
- $input=$request->all();
- $id=Auth::user()->id;
- // $id=39516;
- $express=StorageLog::where('user_id',$id)->where('type',$input['type']);
- $where_start=[];
- $start=$input['start_time'];
- if ($start){
- $where_start=function ($q)use($start){
- $q->where('created_at','>=',$start);
- };
- }
- $where_end=[];
- $end=$input['end_time'];
- if ($end){
- $where_end=function ($q)use($end){
- $q->where('created_at','<=',$end);
- };
- }
- $re=$express->where($where_start)->where($where_end);
- $count=$re->count();
- $data=$re->take(20)->skip(($input['page_index']-1)*20)->get();
- return $this->success_list($data,'',$count);
- }
- /*
- *订货入库和退货入库
- ***/
- public function put_storages(Request $request){
- $id=Auth::user()->id;
- $re=UserStorage::where('user_id',$id)->first();
- if (!$re){
- return $this->error(50024,'','该用户需要使用一次性盘货功能');
- }
- $input=$request->all();
- $data=$input['data'];
- // $put_type=0;
- $put_type=$input['put_type'];
- DB::beginTransaction();
- try{
- foreach ($data as $k=>$v){
- if($k=='hard'){
- $type=0;
- }elseif ($k=='simple'){
- $type=1;
- }elseif ($k=='old'){
- $type=2;
- }elseif ($k=='youth'){
- $type=4;
- }else{
- $type=3;
- }
- foreach ($v as $ke=>$va){
- if ($va['num']!=0){
- $st_log=new StoragePutLog();
- $storage=UserStorage::where('type',$type)->where('user_id',$id)->where('size',$va['size'])->where('sex',$va['sex'])->first();
- if ($put_type==0){
- if ($type==2||$type==1 || $type==4){
- $va['num']=$va['num']*4;
- }elseif ($type==3){
- $va['num']=$va['num']*6;
- }
- }
- if ($storage){
- $storage->num+=$va['num'];
- }else{
- $storage=new UserStorage();
- $storage->user_id=$id;
- $storage->type=$type;
- $storage->size=$va['size'];
- $storage->num=$va['num'];
- $storage->sex=$va['sex'];
- }
- $st_log->user_id=$id;
- $st_log->type=$type;
- $st_log->size=$va['size'];
- $st_log->num=$va['num'];
- $st_log->sex=$va['sex'];
- $st_log->put_type=$put_type;
- $st_log->storage_type=0;
- if (!$storage->save()){
- throw new \Exception('1');
- }
- if (!$st_log->save()){
- throw new \Exception('1');
- }
- }
- }
- }
- DB::commit();
- return $this->success([]);
- }catch (\Exception $exception){
- DB::rollBack();
- return $this->error(50021,'',$exception);
- }
- }
- /*
- * 入库记录
- * ***/
- public function put_storage_groups(Request $request){
- $input=$request->all();
- $id=Auth::user()->id;
- // $id=39516;
- $datas=Goodtest::where('is_deleted',0)->where('id','>',57)->groupBy('main_attr')->get();
- foreach ($datas as $k=>$v){
- $r[$v->main_attr]=$v->main_img;
- }
- $data=[
- 'hard'=>['imgurl'=>$r['大卫博士精装版'],'name'=>'大卫博士精装版','woman'=>0,'man'=>0],
- 'simple'=>['imgurl'=>$r['大卫博士简约版'],'name'=>'大卫博士简约版','woman'=>0,'man'=>0],
- 'old'=>['imgurl'=>$r['大卫博士高腰版'],'name'=>'大卫博士高腰版','woman'=>0,'man'=>0],
- 'new_old'=>['imgurl'=>$r['大卫博士纯棉老人版'],'name'=>'大卫博士纯棉老人版','woman'=>0,'man'=>0],
- 'youth'=>['imgurl'=>$r['大卫博士青春版'],'name'=>'大卫博士青春版','woman'=>0,'man'=>0],
- ];
- $where_type=[];
- $type=$input['record_type'];
- if ($type){
- if ($type==1){
- $where_type=function ($q)use($type){
- $q->where('storage_type',$type);
- };
- }else{
- $where_type=function ($q)use($type){
- $q->where('storage_type',$type);
- };
- }
- }
- $express=StoragePutLog::where('user_id',$id)->where($where_type);
- $where_start=[];
- $start=$input['start_time'];
- if ($start){
- $where_start=function ($q)use($start){
- $q->where('created_at','>=',$start);
- };
- }
- $where_end=[];
- $end=$input['end_time'];
- if ($end){
- $where_end=function ($q)use($end){
- $q->where('created_at','<=',$end);
- };
- }
- $re=$express->where($where_start)->where($where_end)->groupBy('type')->get();
- foreach ($re as $k=>$v){
- $woman=0;
- $man=0;
- if ($type==1){
- $res=StoragePutLog::where('user_id',$id)->where('type',$v->type)->where('storage_type',$type)->where($where_start)->where($where_end);
- if ($input['status']==-1){
- $res=$res->groupBy('sex')->select(DB::raw('sum(num) as total'),'sex')->get()->toArray();
- }else{
- $res=$res->where('out_type',$input['status'])->groupBy('sex')->select(DB::raw('sum(num) as total'),'sex')->get()->toArray();
- }
- foreach ($res as $ke=>$va){
- if ($va['sex']==0){
- $woman=$va['total'];
- }else{
- $man=$va['total'];
- }
- }
- }else{
- $res=StoragePutLog::where('user_id',$id)->where('type',$v->type)->where('storage_type',$type)->where($where_start)->where($where_end)->groupBy('sex')->select(DB::raw('sum(num) as total'),'sex')->get()->toArray();
- foreach ($res as $ke=>$va){
- if ($va['sex']==0){
- $woman=$va['total'];
- }else{
- $man=$va['total'];
- }
- }
- }
- if ($v->type==0){
- $data['hard']['man']=$man;
- $data['hard']['woman']=$woman;
- }elseif ($v->type==1){
- $data['simple']['man']=$man;
- $data['simple']['woman']=$woman;
- }elseif ($v->type==2){
- $data['old']['man']=$man;
- $data['old']['woman']=$woman;
- }elseif ($v->type==3){
- $data['new_old']['man']=$man;
- $data['new_old']['woman']=$woman;
- }elseif ($v->type==4){
- $data['youth']['man']=$man;
- $data['youth']['woman']=$woman;
- }
- }
- return $this->success($data);
- }
- public function put_storage_details(Request $request){
- $input=$request->all();
- $id=Auth::user()->id;
- // $id=39516;
- $where_type=[];
- if ($input['record_type']){
- $type=$input['record_type'];
- $where_type=function ($q)use($type){
- $q->where('storage_type',$type);
- };
- }
- $express=StoragePutLog::where('user_id',$id)->where($where_type)->where('type',$input['type']);
- $where_start=[];
- $start=$input['start_time'];
- if ($start){
- $where_start=function ($q)use($start){
- $q->where('created_at','>=',$start);
- };
- }
- $where_end=[];
- $end=$input['end_time'];
- if ($end){
- $where_end=function ($q)use($end){
- $q->where('created_at','<=',$end);
- };
- }
- $re=$express->where($where_start)->where($where_end);
- $count=$re->count();
- $data=$re->take(20)->skip(($input['page_index']-1)*20)->get();
- return $this->success_list($data,'',$count);
- }
- /*
- * 按照时间分组
- * ***/
- public function get_group(Request $request){
- // $data=DB::select('SELECT SUM(foo), DATE(mydate) FROM a_table GROUP BY DATE(a_table.mydate)');
- $id=Auth::user()->id;
- $data=Express::where('user_id',$id)->selectRaw('DATE_FORMAT(created_at,"%Y-%m-%d") as date')
- ->groupBy('date')->orderByDesc('date');
- $count=$data->get()->count();
- $data=$data->take($request->page_size)->skip(($request->page_index-1)*$request->page_size)->get();
- $arr=[];
- foreach ($data as $k=>$v){
- $start_time=date('Y-m-d H:i:s',strtotime($v->date));
- $end_time=Carbon::parse($start_time)->endOfDay();
- $counts=Express::where('user_id',$id)->whereBetween('created_at',[$start_time,$end_time])->groupBy('order_id')->get()->count();
- $arr[$k]=$v;
- $arr[$k]['count']=$counts;
- }
- return $this->success_list($arr,'',$count);
- }
- public function get_detail(Request $request){
- $time=$request->time;
- $start_time=date('Y-m-d H:i:s',strtotime($time));
- $end_time=Carbon::parse($start_time)->endOfDay();
- $id=Auth::user()->id;
- $data=Express::where('user_id',$id)->whereBetween('created_at',[$start_time,$end_time])->with(['get_order'=>function($q)use($start_time,$end_time,$id){
- $q->with(['get_express'=>function($qu)use($start_time,$end_time){
- $qu->whereBetween('created_at',[$start_time,$end_time])->select('id','express_com','order_id','express_number','put_status','is_gift','notes','remark');
- },'address'])->where('user_id',$id)->select('order_num','put_status','id','address_id','user_id','good_user_id','track_status');
- }])->select('order_id','user_id','created_at')->groupBy('order_id')->get();
- $arr=[];
- foreach ($data as $k=>$v){
- $arr[$k]=$v;
- if ($v['get_order']){
- foreach ($v['get_order']['get_express'] as $ke=>$va){
- $arrs[$ke]=$va;
- $arrs[$ke]['user_id']=$v['get_order']['user_id'];
- $arrs[$ke]['good_user_id']=$v['get_order']['good_user_id'];
- if ($va['is_gift']!=1){
- $arrs[$ke]['notes']=null;
- }
- if (!$va['put_status']){
- $arrs[$ke]['put_status']=0;
- }
- }
- $arr[$k]['get_order']['get_express']=$arrs;
- }
- }
- return $this->success_list($arr);
- }
- }
|