with(['get_address', 'get_order_detail'])->get(); $attr = Goodattr::where('pid', 0)->get(); $hard_id = []; $simple_id = []; $old_id = []; $hard_good = []; $simple_good = []; $old_good = []; foreach ($attr as $k => $v) { if ($v->name == '大卫博士精装版') { $hard_id = Goodattr::where('pid', $v->id)->select('id')->pluck('id'); $hard_good = Goodtest::whereIn('attr_id', $hard_id)->pluck('id')->toArray(); } elseif ($v->name == '大卫博士简约版') { $simple_id = Goodattr::where('pid', $v->id)->pluck('id'); $simple_good = Goodtest::whereIn('attr_id', $simple_id)->pluck('id')->toArray(); } elseif ($v->name == '大卫博士老人版') { $old_id = Goodattr::where('pid', $v->id)->pluck('id'); $old_good = Goodtest::whereIn('attr_id', $old_id)->pluck('id')->toArray(); } } $money = 0; $hard = 0; $simple = 0; $old = 0; $re = []; foreach ($order as $k => $v) { $hard_pro = 0; $simple_pro = 0; $old_pro = 0; foreach ($v->get_order_detail as $ke => $va) { if (in_array($va->goods_id, $hard_good)) { $hard += $va->num; $hard_pro = $va->num; } elseif (in_array($va->goods_id, $simple_good)) { $simple += $va->num; $simple_pro = $va->num; } elseif (in_array($va->goods_id, $old_good)) { $old += $va->num; $old_pro = $va->num; } } $money += $v->money; } $datas = [ 'hard' => $hard, 'simple' => $simple, 'old' => $old, 'money' => $money, ]; return $this->success($datas); } public function data() { $active = Activity::where('is_ing', 1)->first(); $now = Carbon::now()->toDateTimeString(); $order = Ordertest::where('is_deleted', 0)->whereBetween('created_at', [$active->start_time, $active->end_time])->with(['get_address', 'get_order_detail']); $order_1=clone $order; $order_2=clone $order; $order=$order->get(); $order_1=$order_1->where('store_id',17)->sum('money'); $order_2=$order_2->where('store_id',18)->sum('money'); $order_today = []; if ($now < $active->end_time && $now > $active->start_time) { if (Carbon::now()->toDateString() == Carbon::parse($active->start_time)->toDateString()) { $start_time = $active->start_time; } else { $start_time = Carbon::today(); } if (Carbon::now()->toDateString() == Carbon::parse($active->end_time)->toDateString()) { $end_time = $active->end_time; } else { $end_time = Carbon::tomorrow(); } $order_today = Ordertest::where('is_deleted', 0)->with(['get_order_detail'])->whereBetween('created_at', [$start_time, $end_time])->get(); } $act_gifts = Gifts::where('activity_id',$active->id)->get();//活动所有礼品 $gifts_num=[]; if(count($act_gifts)>0){ foreach($act_gifts as $key=>$val){ $gifts_num[$val->name]=OrderGift::whereHas('order_test',function($query){ $query->where('is_deleted',0); })->where('activity_id',$active->id)->where('gift_id',$val->id)->sum('num'); // $honor[$val->title]= OrderGift::join('order_test','order_test.id','=','order_gift.order_id')->where('order_test.is_deleted',0)->where('order_gift.activity_id',$active->id)->where('order_gift.gift_id',5)->sum('order_gift.num'); } } $gift_sh=OrderGift::join('order_test','order_test.id','=','order_gift.order_id')->where('order_test.is_deleted',0)->where('order_gift.activity_id',$active->id)->where('order_gift.gift_id',5)->sum('order_gift.num'); $gift_xl=OrderGift::join('order_test','order_test.id','=','order_gift.order_id')->where('order_test.is_deleted',0)->where('order_gift.activity_id',$active->id)->where('order_gift.gift_id',6)->sum('order_gift.num'); $user_data=User::select('users.id','users.nickname','users.realname', DB::raw('SUM(order_test.money) as account'), DB::raw('SUM(order_test.pay_money) as pay_account')) ->leftJoin('order_test', 'order_test.user_id', '=', 'users.id') ->where('order_test.is_deleted',0) ->whereBetween('order_test.created_at',[$active->start_time,$active->end_time]) ->groupBy('users.id') ->having('account','>=',$active->big_gift) ->orderBy('type','asc') ->orderBy('pay_account','desc') ->orderBy('account','desc'); $count = $user_data->get()->count(); $honor_limit=ActivityLimit::where('activity_id',$active->id)->where('type',1)->get(); $honor_num=[]; if(count($honor_limit)>0){ foreach($honor_limit as $key=>$val){ $honor_num[$val->title]=User::select('users.id','users.nickname','users.realname', DB::raw('SUM(order_test.money) as account'), DB::raw('SUM(order_test.pay_money) as pay_account')) ->leftJoin('order_test', 'order_test.user_id', '=', 'users.id') ->where('order_test.is_deleted',0) ->whereBetween('order_test.created_at',[$active->start_time,$active->end_time]) ->groupBy('users.id') ->having('account','>=',$val->account) ->orderBy('type','asc') ->orderBy('pay_account','desc') ->orderBy('account','desc')->get()->count(); } } $down_limit=Activity::where('id',$active->id)->value('crown_down'); // $down_info=[]; if($down_limit>0){ // foreach($down_limit as $key=>$val){ // foreach(Activity::$levels as $k=>$v){ // if($val->title==$v){ // $level=$k; // } // } // User::withCount('order_test',function($query){ // $query->select(DB::raw('SUM(money) as account'), DB::raw('SUM(pay_money) as pay_account')); // }) //// // User::with('order_test') // ->whereHas('order_test',function($query)use($active){ // $query->where('is_deleted',0)->whereBetween('order_test.created_at',[$active->start_time,$active->end_time]);}) // ->where('level',$level)->get(); $down_info['up']=User::select('users.id','users.nickname','users.realname', DB::raw('SUM(order_test.money) as account'), DB::raw('SUM(order_test.pay_money) as pay_account')) ->leftJoin('order_test', 'order_test.user_id', '=', 'users.id') ->where('users.level',3) ->where('order_test.is_deleted',0) ->whereBetween('order_test.created_at',[$active->start_time,$active->end_time]) ->groupBy('users.id') ->having('account','>=',$down_limit) ->orderBy('type','asc') ->orderBy('pay_account','desc') ->orderBy('account','desc')->get()->count(); $down_info['down']=User::select('users.id','users.nickname','users.realname', DB::raw('SUM(order_test.money) as account'), DB::raw('SUM(order_test.pay_money) as pay_account')) ->leftJoin('order_test', 'order_test.user_id', '=', 'users.id') ->where('users.level',3) ->where('order_test.is_deleted',0) ->whereBetween('order_test.created_at',[$active->start_time,$active->end_time]) ->groupBy('users.id') ->having('account','<',$down_limit) ->orderBy('type','asc') ->orderBy('pay_account','desc') ->orderBy('account','desc')->get()->count(); // } }else{ $down_info['up']=0; $down_info['down']=0; } $attr = Goodattr::where('pid', 0)->get(); $hard_id = []; $simple_id = []; $old_id = []; $hard_good = []; $simple_good = []; $old_good = []; $newold_good = []; foreach ($attr as $k => $v) { if ($v->name == '大卫博士精装版') { $hard_id = Goodattr::where('pid', $v->id)->select('id')->pluck('id'); $hard_good = Goodtest::whereIn('attr_id', $hard_id)->pluck('id')->toArray(); } elseif ($v->name == '大卫博士简约版') { $simple_id = Goodattr::where('pid', $v->id)->pluck('id'); $simple_good = Goodtest::whereIn('attr_id', $simple_id)->pluck('id')->toArray(); } elseif ($v->name == '大卫博士老人版') { $old_id = Goodattr::where('pid', $v->id)->pluck('id'); $old_good = Goodtest::whereIn('attr_id', $old_id)->pluck('id')->toArray(); } elseif ($v->name == '大卫博士纯棉老人版') { $newold_id = Goodattr::where('pid', $v->id)->pluck('id'); $newold_good = Goodtest::whereIn('attr_id', $newold_id)->pluck('id')->toArray(); } } $money = 0; $hard = 0; $simple = 0; $old = 0; $newold = 0; $hard_today = 0; $newold_today = 0; $simple_today = 0; $old_today = 0; $money_today = 0; $re = []; // dd($order); foreach ($order_today as $k => $v) { foreach ($v->get_order_detail as $ke => $va) { if (in_array($va->goods_id, $hard_good)) { $hard_today += $va->num; } elseif (in_array($va->goods_id, $simple_good)) { $simple_today += $va->num; } elseif (in_array($va->goods_id, $old_good)) { $old_today += $va->num; } elseif (in_array($va->goods_id, $newold_good)) { $newold_today += $va->num; } } $money_today += $v->money; } $h = 0; $hard_pro = 0; $simple_pro = 0; $old_pro = 0; $newold_pro = 0; $money_pro = 0; $hard_money = 0; $simple_money = 0; $old_money = 0; $newold_money = 0; foreach ($order as $k => $v) { $hard_pro = 0; $simple_pro = 0; $old_pro = 0; $newold_pro = 0; foreach ($v->get_order_detail as $ke => $va) { if (in_array($va->goods_id, $hard_good)) { $hard += $va->num; $hard_money += $va->money; $hard_pro += $va->num; } if (in_array($va->goods_id, $simple_good)) { $simple += $va->num; $simple_money += $va->money; $simple_pro += $va->num; } if (in_array($va->goods_id, $old_good)) { $old += $va->num; $old_money += $va->money; $old_pro += $va->num; } if (in_array($va->goods_id, $newold_good)) { $newold += $va->num; $newold_money += $va->money; $newold_pro += $va->num; } } $money += $v->money; $h += $newold_pro; $re = $this->province($v->get_address->province, $hard_pro, $simple_pro, $old_pro, $newold_pro, $v->money, $re); } $datas = [ 'hard' => $hard, 'simple' => $simple, 'old' => $old, 'newold' => $newold, 'money' => $money, 'hard_today' => $hard_today, 'simple_today' => $simple_today, 'old_today' => $old_today, 'newold_today' => $newold_today, 'money_today' => $money_today, 'activity_title'=>$active->title, 'shouhuan'=>$gift_sh, 'xianglian'=>$gift_xl, 'big_gift'=>$count, '临沭体验店'=>$order_1, '吴桥体验店'=>$order_2, 'activity_time'=>'('.date('m月d日',strtotime($active->start_time)).'-'.date('d日',strtotime($active->end_time)).')', 'list' => $re, 'gifts_num'=>$gifts_num, 'honor_num'=>$honor_num, 'down_info'=>$down_info, 'hard_money' => $hard_money, 'simple_money' =>$simple_money, 'old_money' => $old_money, 'newold_money' => $newold_money, ]; return $this->success($datas); // $data=['北京', '天津', '上海', '重庆', '河北', '河南', '云南', '辽宁', '黑龙江', '湖南', '安徽', '山东', '新疆', '江苏','浙江', '江西', '湖北', '广西', '甘肃', '山西', '内蒙古', '陕西', '吉林', '福建', '贵州', '广东', '青海', '西藏', '四川', '宁夏', '海南', '台湾','香港', '澳门']; } public function province($name, $hard, $simple, $old, $newold, $money, $res = []) { // $data=['北京', '天津', '上海', '重庆', '河北', '河南', '云南', '辽宁', '黑龙江', '湖南', '安徽', '山东', '新疆', '江苏','浙江', '江西', '湖北', '广西', '甘肃', '山西', '内蒙古', '陕西', '吉林', '福建', '贵州', '广东', '青海', '西藏', '四川', '宁夏', '海南', '台湾','香港', '澳门']; // $s='河北省、山西省、辽宁省、吉林省、黑龙江省、江苏省、浙江省、安徽省、福建省、江西省、山东省、河南省、湖北省、湖南省、广东省、海南省、四川省、贵州省、云南省、陕西省、甘肃省、青海省、台湾省'; // $ss='内蒙古自治区、广西壮族自治区、西藏自治区、宁夏回族自治区、新疆维吾尔自治区'; // $sss='北京市、天津市、上海市、重庆市'; // $ssss='香港特别行政区、澳门特别行政区'; $datas = [ ['北京', '北京市'], ['天津', '天津市'], ['上海', '上海市'], ['重庆', '重庆市'], ['河北', '河北省'], ['河南', '河南省'], ['云南', '云南省'], ['辽宁', '辽宁省'], ['黑龙江', '黑龙江省'], ['湖南', '湖南省'], ['安徽', '安徽省'], ['山东', '山东省'], ['新疆', '新疆维吾尔自治区'], ['江苏', '江苏省'], ['浙江', '浙江省'], ['江西', '江西省'], ['湖北', '湖北省'], ['广西', '广西壮族自治区'], ['甘肃', '甘肃省'], ['山西', '山西省'], ['内蒙古', '内蒙古自治区'], ['陕西', '陕西省'], ['吉林', '吉林省'], ['福建', '福建省'], ['贵州', '贵州省'], ['广东', '广东省'], ['青海', '青海省'], ['西藏', '西藏自治区'], ['四川', '四川省'], ['宁夏', '宁夏回族自治区'], ['海南', '海南省'], ['台湾', '台湾'], ['香港', '香港'], ['澳门', '澳门'] ]; foreach ($datas as $k => $v) { $re[$k]['name'] = $v[0]; if ($res) { if ($v[1] == $name) { $re[$k]['hard'] = $hard + $res[$k]['hard']; $re[$k]['simple'] = $simple + $res[$k]['simple']; $re[$k]['old'] = $old + $res[$k]['old']; $re[$k]['newold'] = $newold + $res[$k]['newold']; $re[$k]['value'] = $money + $res[$k]['value']; } else { $re[$k]['hard'] = $res[$k]['hard']; $re[$k]['simple'] = $res[$k]['simple']; $re[$k]['old'] = $res[$k]['old']; $re[$k]['newold'] = $res[$k]['newold']; $re[$k]['value'] = $res[$k]['value']; } } else { if ($v[1] == $name) { $re[$k]['hard'] = $hard; $re[$k]['simple'] = $simple; $re[$k]['old'] = $old; $re[$k]['newold'] = $newold; $re[$k]['value'] = $money; // $re[$k]['money']=$money; } else { $re[$k]['hard'] = 0; $re[$k]['simple'] = 0; $re[$k]['old'] = 0; $re[$k]['newold'] = 0; $re[$k]['value'] = 0; } } } Log::error($re); $last_ages = array_column($re,'value'); array_multisort($last_ages ,SORT_DESC,$re); Log::error($re); return $re; } public function crown_rank() { } public function money() { $order = Ordertest::where('is_deleted', 0)->with(['get_address', 'get_order_detail'])->get(); $attr = Goodattr::where('pid', 0)->get(); $hard_id = []; $simple_id = []; $old_id = []; $hard_good = []; $simple_good = []; $old_good = []; foreach ($attr as $k => $v) { if ($v->name == '大卫博士精装版') { $hard_id = Goodattr::where('pid', $v->id)->select('id')->pluck('id'); $hard_good = Goodtest::whereIn('attr_id', $hard_id)->pluck('id')->toArray(); } elseif ($v->name == '大卫博士简约版') { $simple_id = Goodattr::where('pid', $v->id)->pluck('id'); $simple_good = Goodtest::whereIn('attr_id', $simple_id)->pluck('id')->toArray(); } elseif ($v->name == '大卫博士老人版') { $old_id = Goodattr::where('pid', $v->id)->pluck('id'); $old_good = Goodtest::whereIn('attr_id', $old_id)->pluck('id')->toArray(); } } $money = 0; $hard = 0; $simple = 0; $old = 0; $re = []; foreach ($order as $k => $v) { $hard_pro = 0; $simple_pro = 0; $old_pro = 0; foreach ($v->get_order_detail as $ke => $va) { if (in_array($va->goods_id, $hard_good)) { $hard += $va->num; $hard_pro = $va->num; } elseif (in_array($va->goods_id, $simple_good)) { $simple += $va->num; $simple_pro = $va->num; } elseif (in_array($va->goods_id, $old_good)) { $old += $va->num; $old_pro = $va->num; } } $money += $v->money; } $datas = [ 'hard' => $hard, 'simple' => $simple, 'old' => $old, 'money' => $money, ]; return $this->success_list($datas); } // public function get_crown(){ // $user=User::where('level',3)->get(); // $attr=Goodattr::where('pid',0)->get(); // $hard_id=[]; // $simple_id=[]; // $old_id=[]; // foreach ($attr as $k=>$v){ // if ($v->name=='大卫博士精装版'){ // $hard_id=Goodattr::where('pid',$v->id)->select('id')->pluck('id'); // $hard_good=Goodtest::whereIn('attr_id',$hard_id)->pluck('id')->toArray(); // }elseif ($v->name=='大卫博士简约版'){ // $simple_id=Goodattr::where('pid',$v->id)->pluck('id'); // $simple_good=Goodtest::whereIn('attr_id',$simple_id)->pluck('id')->toArray(); // }elseif ($v->name=='大卫博士老人版'){ // $old_id=Goodattr::where('pid',$v->id)->pluck('id'); // $old_good=Goodtest::whereIn('attr_id',$old_id)->pluck('id')->toArray(); // } // } // foreach ($user as $k=>$v){ // $money=0; // $hard=0; // $simple=0; // $old=0; // $order=Ordertest::where('user_id',$v->id)->where('is_deleted',0)->get(); // $count=count($order); // if ($count==0){ // $re[$k]['hard']=0; // $re[$k]['simple']=0; // $re[$k]['old']=0; // $re[$k]['money']=0; // }else{ // foreach ($v->get_order_detail as $ke=>$va){ // if (in_array($va->goods_id,$hard_good)){ // $hard+=$va->num; // }elseif (in_array($va->goods_id,$simple_good)){ // $simple+=$va->num; // }elseif (in_array($va->goods_id,$old_good)){ // $old+=$va->num; // } // } // $money+=$v->money; // $re[$k]['money']=$money; // $re[$k]['hard']=$hard; // $re[$k]['simple']=$simple; // $re[$k]['old']=$old; // } // return $n; // $re[$k]['nickname']=$v->nickname; // } // return $this->success_list($re); // } //======= // foreach ($datas as $k=>$v){ // $re[$k]['name']=$v[0]; // if ($res){ // if ($v[1]==$name){ // $re[$k]['hard']=$hard+$res[$k]['hard']; // $re[$k]['simple']=$simple+$res[$k]['simple']; // $re[$k]['old']=$old+$res[$k]['old']; // $re[$k]['value']=$money+$res[$k]['value']; // }else{ // $re[$k]['hard']=$res[$k]['hard']; // $re[$k]['simple']=$res[$k]['simple']; // $re[$k]['old']=$res[$k]['old']; // $re[$k]['value']=$res[$k]['value']; // } // }else{ // if ($v[1]==$name){ // $re[$k]['hard']=$hard; // $re[$k]['simple']=$simple; // $re[$k]['old']=$old; // $re[$k]['value']=$money; // // $re[$k]['money']=$money; // }else{ // $re[$k]['hard']=0; // $re[$k]['simple']=0; // $re[$k]['old']=0; // $re[$k]['value']=0; // } // } // // } // return $re; // } // public function get_crown() { $active = Activity::where('is_ing', 1)->first(); $start_time = $active->start_time; $end_time = $active->end_time; $user = User::where('level', 3)->with(['get_order_de' => function ($q) use ($start_time, $end_time) { $q->where('order_test.is_deleted', 0)->whereBetween('order_test.created_at', [$start_time, $end_time]); }])->get(); $attr = Goodattr::where('pid', 0)->get(); $hard_id = []; $simple_id = []; $old_id = []; foreach ($attr as $k => $v) { if ($v->name == '大卫博士精装版') { $hard_id = Goodattr::where('pid', $v->id)->select('id')->pluck('id'); $hard_good = Goodtest::whereIn('attr_id', $hard_id)->pluck('id')->toArray(); } elseif ($v->name == '大卫博士简约版') { $simple_id = Goodattr::where('pid', $v->id)->pluck('id'); $simple_good = Goodtest::whereIn('attr_id', $simple_id)->pluck('id')->toArray(); } elseif ($v->name == '大卫博士老人版') { $old_id = Goodattr::where('pid', $v->id)->pluck('id'); $old_good = Goodtest::whereIn('attr_id', $old_id)->pluck('id')->toArray(); } elseif ($v->name == '大卫博士纯棉老人版') { $newold_id = Goodattr::where('pid', $v->id)->pluck('id'); $newold_good = Goodtest::whereIn('attr_id', $newold_id)->pluck('id')->toArray(); } } foreach ($user as $k => $v) { $money = 0; $hard = 0; $simple = 0; $old = 0; $newold = 0; $count = count($v->get_order_de); if ($count == 0) { $re[$k]['hard'] = 0; $re[$k]['simple'] = 0; $re[$k]['old'] = 0; $re[$k]['newold'] = 0; $re[$k]['money'] = 0; } else { foreach ($v->get_order_de as $key => $value) { if (in_array($value->goods_id, $hard_good)) { $hard += $value->num; } elseif (in_array($value->goods_id, $simple_good)) { $simple += $value->num; } elseif (in_array($value->goods_id, $old_good)) { $old += $value->num; } elseif (in_array($value->goods_id, $newold_good)) { $newold += $value->num; } $money += $value->money; } $re[$k]['money'] = $money; $re[$k]['hard'] = $hard; $re[$k]['simple'] = $simple; $re[$k]['old'] = $old; $re[$k]['newold'] = $newold; } $re[$k]['nickname'] = $v->nickname; } return $this->success_list($re); } // // //>>>>>>> 9aa477479386789a8615d89285e74706ec72fbab /***数据统计---------按照种类---***/ public function rank_type() { $hard_good = Goodtest::where('main_attr', '大卫博士精装版')->pluck('id')->toArray(); $simple_good = Goodtest::where('main_attr', '大卫博士简约版')->pluck('id')->toArray(); $old_good = Goodtest::where('main_attr', '大卫博士老人版')->pluck('id')->toArray(); $old_good_nan = Goodtest::where('main_attr', '大卫博士老人版')->where('sec_attr', '男款')->pluck('id')->toArray(); $old_good_nv = Goodtest::where('main_attr', '大卫博士老人版')->where('sec_attr', '女款')->pluck('id')->toArray(); $simple_good_nan = Goodtest::where('main_attr', '大卫博士简约版')->where('sec_attr', '男款')->pluck('id')->toArray(); $simple_good_nv = Goodtest::where('main_attr', '大卫博士简约版')->where('sec_attr', '女款')->pluck('id')->toArray(); $hard_good_nan = Goodtest::where('main_attr', '大卫博士精装版')->where('sec_attr', '男款')->pluck('id')->toArray(); $hard_good_nv = Goodtest::where('main_attr', '大卫博士精装版')->where('sec_attr', '女款')->pluck('id')->toArray(); $where = function ($query) { $query->where('is_deleted', 0); }; $orders = Ordertest::where($where)->get(); $hard = 0; $simple = 0; $old = 0; $old_money = 0; $simple_money = 0; $hard_money = 0; $hard_nan = 0; $hard_nv = 0; $simple_nan = 0; $simple_nv = 0; $old_nan = 0; $old_nv = 0; $hard_nan_money = 0; $hard_nv_money = 0; $simple_nan_money = 0; $simple_nv_money = 0; $old_nan_money = 0; $old_nv_money = 0; foreach ($orders as $k => $v) { $order = Ordertest::where('id', $v->id)->with(['get_order_detail'])->first(); foreach ($order->get_order_detail as $ke => $va) { if (in_array($va->goods_id, $hard_good)) { $hard += $va->num; $hard_money += $va->money; } elseif (in_array($va->goods_id, $simple_good)) { $simple += $va->num; $simple_money += $va->money; } elseif (in_array($va->goods_id, $old_good)) { $old += $va->num; $old_money += $va->money; } if (in_array($va->goods_id, $hard_good_nan)) { $hard_nan += $va->num; $hard_nan_money += $va->money; } elseif (in_array($va->goods_id, $hard_good_nv)) { $hard_nv += $va->num; $hard_nv_money += $va->money; } elseif (in_array($va->goods_id, $simple_good_nan)) { $simple_nan += $va->num; $simple_nan_money += $va->money; } elseif (in_array($va->goods_id, $simple_good_nv)) { $simple_nv += $va->num; $simple_nv_money += $va->money; } elseif (in_array($va->goods_id, $old_good_nan)) { $old_nan += $va->num; $old_nan_money += $va->money; } elseif (in_array($va->goods_id, $old_good_nv)) { $old_nv += $va->num; $old_nv_money += $va->money; } } } $data = [ 'hard' => $hard, 'simple' => $simple, 'old' => $old, 'hard_money' => $hard_money, 'simple_money' => $simple_money, 'old_money' => $old_money, 'hard_nan' => $hard_nan, 'simple_nan' => $simple_nan, 'old_nan' => $old_nan, 'hard_nan_money' => $hard_nan_money, 'simple_nan_money' => $simple_nan_money, 'old_nan_money' => $old_nan_money, 'hard_nv' => $hard_nv, 'simple_nv' => $simple_nv, 'old_nv' => $old_nv, 'hard_nv_money' => $hard_nv_money, 'simple_nv_money' => $simple_nv_money, 'old_nv_money' => $old_nv_money, ]; return $this->success($data); } public function rank_type2(Request $request) { $input = $request->all(); $start_time = $input['start_time']; $end_time = $input['end_time']; $data = Ordertest::where('is_deleted', 0); if ($request->has('order_status')) { $order_status = $input['order_status']; } else { $order_status = []; } if ($order_status || $order_status == 0) { if ('-1' == $order_status) { } elseif ($order_status == 0) { $data->where('status', $order_status)->where('is_deleted', 0); } elseif ($order_status == 1) { $data->where('status', $order_status)->where('is_deleted', 0); } elseif ($order_status == 2) { $data->where('status', $order_status)->where('is_deleted', 0); } elseif ($order_status == 3) { $data->where('status', $order_status)->where('is_deleted', 0); } elseif ($order_status == 4) { $data->where('status', $order_status)->where('is_deleted', 0); } } if ($start_time && $end_time) { $data->whereBetween('created_at', [$start_time, $end_time]); } $orders = $data->get(); $good_attrs = Goodtest::where('is_deleted', 0)->groupBy('main_attr')->select('id', 'name', 'main_attr')->get(); foreach ($good_attrs as $k => $v) { $good_attr[$k]['ids'] = Goodtest::where('is_deleted', 0)->where('main_attr', $v->main_attr)->pluck('id')->toArray(); $good_attr[$k]['name'] = $v->main_attr; } foreach ($good_attr as $key => $value) { if (empty($attr[$value['name']])) { $attr[$value['name']][0] = 0; $attr[$value['name']][1] = 0; } } $good_types = Goodtest::where('is_deleted', 0)->groupBy('attr_id')->orderBy('sort')->select('id', 'name', 'main_attr', 'attr_id')->get(); foreach ($good_types as $k => $v) { $good_type[$k]['ids'] = Goodtest::where('is_deleted', 0)->where('attr_id', $v->attr_id)->pluck('id')->toArray(); $good_type[$k]['name'] = $v->name; } foreach ($good_type as $key => $value) { if (empty($type[$value['name']])) { $type[$value['name']][0] = 0; $type[$value['name']][1] = 0; } } $good_singles = Goodtest::where('is_deleted', 0)->orderBy('sort')->orderBy('id')->select('id', 'name', 'size')->get(); foreach ($good_singles as $k => $v) { $good_single[$k]['ids'] = $v->id; $good_single[$k]['name'] = $v->name . '(' . $v->size . ')'; } foreach ($good_single as $key => $value) { $single[$value['name']][0] = 0; $single[$value['name']][1] = 0; } foreach ($orders as $k => $v) { $order = Ordertest::where('id', $v->id)->with(['get_order_detail'])->first(); foreach ($order->get_order_detail as $ke => $va) { foreach ($good_attr as $key => $value) { if (in_array($va->goods_id, $value['ids'])) { $attr[$value['name']][0] += $va->num; $attr[$value['name']][1] += $va->money; } } foreach ($good_type as $key => $value) { if (in_array($va->goods_id, $value['ids'])) { $type[$value['name']][0] += $va->num; $type[$value['name']][1] += $va->money; } } foreach ($good_single as $key => $value) { if ($va->goods_id == $value['ids']) { $single[$value['name']][0] += $va->num; $single[$value['name']][1] += $va->money; } } } } $data = [ 'attr' => $attr, 'type' => $type, 'single' => $single ]; return $this->success($data); } public function getOrderListInfo(Request $request) { $input = $request->all(); $start_time = $input['start_time']; $end_time = $input['end_time']; $type = $input['type']; $order_status = $input['order_status']; $search_name = $input['search_name']; $receive = $input['name']; $province = $input['provice']; $city = $input['city']; $area = $input['area']; // $activity_id=$input['activity_id']; $ids = $this->getOrderListIds($start_time, $end_time, $order_status, $search_name, $receive, $province, $city, $area); $data = Goodtest::leftJoin('order_detail', function ($query) use ($ids) { $query->on('goods_test.id', '=', 'order_detail.goods_id') ->whereIn('order_detail.order_id', $ids); }); if ($type == 3) {//种类 $data->select('goods_test.main_attr', DB::raw('sum(order_detail.num) as total'), DB::raw('sum(order_detail.money) as account')) ->groupBy('goods_test.main_attr'); } if ($type == 2) {//款式 $data->select('goods_test.main_attr', 'goods_test.sec_attr', DB::raw('sum(order_detail.num) as total'), DB::raw('sum(order_detail.money) as account')) ->groupBy('goods_test.main_attr', 'goods_test.sec_attr'); } if ($type == 1) {//尺码 $data->select('goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total'), DB::raw('SUM(order_detail.money) as account')) ->groupBy('goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size'); } $list = $data->get(); return $this->success($list); } public function getOrderListIds($start_time, $end_time, $order_status, $search_name, $receive, $province, $city, $area) { $order = Ordertest::where('is_deleted', 0); if (!empty($order_status) || $order_status == '0') { $order->where('status', '=', $order_status); } if ($start_time && $end_time) { $order->whereBetween('created_at', [$start_time, $end_time]); } if ($search_name) { $user_ids = $this->getUserIds($search_name); $order->whereIn('user_id', $user_ids); } if ($receive) { $address_ids = $this->getReceiveAddressIds($receive); $order->whereIn('address_id', $address_ids); } if ($province && $province != '省') { $province_ids = $this->getProvinceIds($province); $order->whereIn('address_id', $province_ids); } if ($city && $city != '市') { if ($city == '北京城区') { $city = '市辖区'; } if ($city == '天津城区') { $city = '市辖区'; } if ($city == '上海城区') { $city = '市辖区'; } $city_ids = $this->getCityIds($city); $order->whereIn('address_id', $city_ids); } if ($area && $area != '区') { $area_ids = $this->getProvinceIds($area); $order->whereIn('address_id', $area_ids); } return $order->pluck('id'); } //获取代理Ids public function getUserIds($search = null) { return User::where(function ($query) use ($search) { $query->where('nickname', 'like', '%' . $search . '%') ->orwhere('realname', 'like', '%' . $search . '%') ->orwhere('mobile', $search); })->pluck('id'); } //根据物流查询代理信息 public function getReceiveAddressIds($search = null) { return Address::where('username', 'like', '%' . $search . '%') ->orWhere('mobile', $search) ->pluck('id'); } //根据省查询代理信息 public function getProvinceIds($search = null) { //<<<<<<< HEAD return Address::where('province', $search) ->pluck('id'); } //根据市查询代理信息 public function getCityIds($search = null) { if ($search == '北京城区' || $search == '天津城区' || $search == '上海城区') { $search = '市辖区'; } return Address::where('city', $search) //======= // return Address::where('province',$search ) // ->pluck('id'); // } // // //根据省查询代理信息 // public function getCityIds($search = null) // { // return Address::where('city', $search ) //>>>>>>> 9aa477479386789a8615d89285e74706ec72fbab ->pluck('id'); } //<<<<<<< HEAD //根据区查询代理信息 public function getAreaIds($search = null) { return Address::where('town', $search) //======= // //根据省查询代理信息 // public function getAreaIds($search = null) // { // return Address::where('town', $search ) //>>>>>>> 9aa477479386789a8615d89285e74706ec72fbab ->pluck('id'); } public function orderBreakUpCourier(Request $request) { ini_set('memory_limit', '1024M'); $input = $request->all(); if ($request->has('provice')) { $order_no = $input['order_no']; $start_time = $input['start_time']; $end_time = $input['end_time']; $activity_id = $input['activity_id']; $user_name = $input['user_name']; $receive_info = $input['receive_info']; $goods_info = $input['goods_info']; $province = $input['provice']; $city = $input['city']; $town = $input['area']; if ($request->has('order_status')) { $order_status = $input['order_status']; } else { $order_status = []; } if ($request->has('pay_status')) { $pay_status = $input['pay_status']; } else { $pay_status = []; } $order_type = $input['order_type']; $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id') ->leftJoin('users', 'order_test.user_id', '=', 'users.id') // ->join('warea','warea.id','=','users.warea_id') ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id') ->leftJoin('address', 'address.id', '=', 'order_test.address_id') ->select('order_test.order_num','order_test.created_at', 'order_test.good_user_id','users.warea_id','order_test.id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total')); $admin = Auth::user(); if ($admin->role_id == 23) { $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id'); $data->whereIn('users.warea_id', $warea_ids); } if ($order_no) { $data->where('order_test.order_num', $order_no); } if ($start_time && $end_time && empty($activity_id)) { $data->whereBetween('order_test.created_at', [$start_time, $end_time]); } if ($activity_id) { // $data->where('order_test.activity_id', $activity_id); $actice=Activity::find($activity_id); $data->whereBetween('order_test.created_at',[$actice->start_time,$actice->end_time]); } if ($user_name) { $user_id = $this->getUserNameIds($user_name); $data->whereIn('order_test.user_id', $user_id); } if ($receive_info) { $address_ids = $this->getReceiveAddressIds($receive_info); $data->whereIn('order_test.address_id', $address_ids); } if ($province && $province != '省') { $province_ids = $this->getProvinceIds($province); $data->whereIn('order_test.address_id', $province_ids); } if ($city && $city != '市') { $city_ids = $this->getCityIds($city); $data->whereIn('order_test.address_id', $city_ids); } if ($town && $town != '区') { $town_ids = $this->getAreaIds($town); $data->whereIn('order_test.address_id', $town_ids); } //商品信息 if ($goods_info) { $order_ids = $this->getGoodsOrderIds($goods_info); $data->whereIn('order_test.id', $order_ids); } if ($order_status) { if (!in_array('-1', $order_status)) { if (!in_array('5', $order_status)) { $data->whereIn('order_test.status', $order_status)->where('order_test.is_deleted', 0); } else { $data->where('order_test.is_deleted', 1) ->orWhere(function ($query) use ($order_status) { $query->where('order_test.is_deleted', 0) ->whereIn('order_test.status', $order_status); }); } } } if ($pay_status) { if (!in_array('-1', $pay_status)) { $data->whereIn('order_test.pay_status', $pay_status); } } if (in_array($order_type, [0, 1])) { $data->where('order_test.order_type', $order_type); } $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr') ->orderBy('order_test.id', 'order_detail.id') ->get()->toArray(); } else { if ($request->has('id')) { $list = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id') ->leftJoin('users', 'order_test.user_id', '=', 'users.id') // ->join('warea','warea.id','=','users.warea_id') ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id') ->leftJoin('address', 'address.id', '=', 'order_test.address_id') ->select('order_test.order_num','order_test.created_at', 'order_test.good_user_id','order_test.id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile','users.warea_id', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total')) ->whereIn('order_test.id', $request->id) ->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr') ->orderBy('order_test.id', 'order_detail.id') ->get()->toArray(); } else { if ($request->has('order_no')) { $order_no = $input['order_no']; } else { $order_no = ''; } $start_time = $input['start_time'] ?? ''; $end_time = $input['end_time'] ?? ''; $activity_id = $input['activity_id'] ?? ''; $search_name = $input['search_name'] ?? ''; if ($request->has('order_status')) { $order_status = $input['order_status']; } else { $order_status = []; } $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id') ->leftJoin('users', 'order_test.user_id', '=', 'users.id') // ->join('warea','warea.id','=','users.warea_id') ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id') ->leftJoin('address', 'address.id', '=', 'order_test.address_id') ->select('order_test.order_num','order_test.created_at', 'order_test.good_user_id', 'order_test.id','users.warea_id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total')); $admin = Auth::user(); if ($admin->role_id == 23) { $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id'); $data->whereIn('users.warea_id', $warea_ids); } if ($order_status || $order_status == 0) { if ('-1' == $order_status) { $data->whereIn('order_test.is_deleted', [0, 1]); } elseif ($order_status == 5) { $data->where('order_test.is_deleted', 1); } elseif ($order_status == 0) { $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0); } elseif ($order_status == 1) { $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0); } elseif ($order_status == 2) { $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0); } elseif ($order_status == 3) { $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0); } elseif ($order_status == 4) { $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0); } elseif ($order_status == 6) { $data->whereIn('order_test.pay_status', [0, 1])->where('order_test.order_test.is_deleted', 0); } } if ($order_no) { $data->where('order_test.order_num', $order_no); } if ($search_name) { // $s=substr(trim($search_name),0,4); // if($s=='DWBS'){ // $data->where('order_test.order_num',trim($search_name)); // }else{ $ids = $this->getUserIds($search_name); $data->whereIn('order_test.user_id', $ids); // } } if ($start_time && $end_time && empty($activity_id)) { $data->whereBetween('order_test.created_at', [$start_time, $end_time]); } if ($activity_id) { $actice = Activity::find($activity_id); $data->whereBetween('order_test.created_at', [$actice->start_time, $actice->end_time]); } // $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr') $list = $data->groupBy('order_detail.order_id', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size') ->orderBy('order_test.id', 'order_detail.id') ->get()->toArray(); } } $dd = $this->dataGroup($list, 'order_num'); $d = []; foreach ($dd as $key => $val) { $info['gift'] = OrderGift::leftJoin('gifts', 'order_gift.gift_id', '=', 'gifts.id') ->where('order_gift.order_id', $val[0]['id']) ->where('order_gift.num', '>', '0') ->select('gifts.name', 'order_gift.num')->get(); $info['u_nickname'] = $val[0]['u_nickname']; $info['u_name'] = $val[0]['u_name']; $info['u_mobile'] = $val[0]['u_mobile']; $info['username'] = $val[0]['username']; $info['mobile'] = $val[0]['mobile']; $info['address'] = $val[0]['address']; $info['province'] = $val[0]['province']; $info['city'] = $val[0]['city']; $info['town'] = $val[0]['town']; if ($val[0]['good_user_id']){ $gooduser=User::where('id',$val[0]['good_user_id'])->select('mobile','nickname')->first(); $info['belong']='('.$gooduser->nickname.','.$gooduser->mobile.')'; }else{ $info['belong']=''; } $admin_name=Warea::where('id',$val[0]['warea_id'])->value('admin_name'); $info['admin_name'] =$admin_name; $info['created_at'] = $val[0]['created_at']; // $info['remark'] = (string)$val[0]['remark']; $info['remark'] = $this->getOrderRemark($val[0]['id']); $d[$key]['data'] = $info; $d[$key]['精装'] = []; $d[$key]['普通'] = []; $d[$key]['精装混合'] = []; $d[$key]['普通混合'] = []; $x1 = 0; $y1 = [];//精装 $x = 0; $y = [];//普通 foreach ($val as $k => $v) { if ($v['main_attr'] == '大卫博士精装版') { $main_attr = '精'; $n = floor($v['total'] / 10); for ($i = 0; $i < $n; $i++) { $cc = []; $cc['main_attr'] = $main_attr; $cc['sec_attr'] = $v['sec_attr']; $cc['size'] = $v['size']; $cc['num'] = 10; array_push($d[$key]['精装'], $cc); } if ($v['total'] % 10 > 0) { $t1 = $v['total'] % 10; if ($x1 + $t1 >= 10) { $x1 = $x1 + $t1 - 10; $z1['main_attr'] = $main_attr; $z1['sec_attr'] = $v['sec_attr']; $z1['size'] = $v['size']; $z1['num'] = $t1 - $x1; if ($y1) { array_pop($d[$key]['精装混合']); } array_push($y1, $z1); $z1 = []; array_push($d[$key]['精装混合'], $y1); $y1 = []; if ($x1 > 0) { $z1['main_attr'] = $main_attr; $z1['sec_attr'] = $v['sec_attr']; $z1['size'] = $v['size']; $z1['num'] = $x1; array_push($y1, $z1); array_push($d[$key]['精装混合'], $y1); } } else { $x1 += $t1; $z1['main_attr'] = $main_attr; $z1['sec_attr'] = $v['sec_attr']; $z1['size'] = $v['size']; $z1['num'] = $v['total'] % 10; if ($y1) { array_pop($d[$key]['精装混合']); } array_push($y1, $z1); array_push($d[$key]['精装混合'], $y1); } } } else { $n = floor($v['total'] / 6); if ($v['main_attr'] == '大卫博士老人版') { $main_attr = '老'; } elseif ($v['main_attr'] == '大卫博士简约版') { $main_attr = '简'; } else { $main_attr = '棉'; } for ($i = 0; $i < $n; $i++) { $cc = []; $cc['main_attr'] = $main_attr; $cc['sec_attr'] = $v['sec_attr']; $cc['size'] = $v['size']; $cc['num'] = 6; array_push($d[$key]['普通'], $cc); } if ($v['total'] % 6 > 0) { $t = $v['total'] % 6; if ($x + $t >= 6) { $x = $x + $t - 6; $z['main_attr'] = $main_attr; $z['sec_attr'] = $v['sec_attr']; $z['size'] = $v['size']; $z['num'] = $t - $x; if ($y) { array_pop($d[$key]['普通混合']); } array_push($y, $z); $z = []; array_push($d[$key]['普通混合'], $y); $y = []; if ($x > 0) { $z['main_attr'] = $main_attr; $z['sec_attr'] = $v['sec_attr']; $z['size'] = $v['size']; $z['num'] = $x; array_push($y, $z); array_push($d[$key]['普通混合'], $y); } } else { $x += $t; $z['main_attr'] = $main_attr; $z['sec_attr'] = $v['sec_attr']; $z['size'] = $v['size']; $z['num'] = $v['total'] % 6; if ($y) { array_pop($d[$key]['普通混合']); } array_push($y, $z); array_push($d[$key]['普通混合'], $y); } } } } } return $this->success($d); } public function orderStoreBreakUpCourier(Request $request) { ini_set('memory_limit', '1024M'); $input = $request->all(); if (!$request->has('id')) { $page_index = $input['page_index']; $page_size = $input['page_size']; $num = ($page_index - 1) * $page_size; $order_no = $input['order_no']; $start_time = $input['start_time']; $end_time = $input['end_time']; $search_name = $input['search_name']; $activity_id = $input['activity_id']; $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id') ->leftJoin('users', 'order_test.user_id', '=', 'users.id') // ->join('warea','warea.id','=','users.warea_id') ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id') ->leftJoin('address', 'address.id', '=', 'order_test.address_id') ->select('order_test.order_num','order_test.created_at', 'order_test.good_user_id','users.warea_id','order_test.id','order_test.store_id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total')); $admin = Auth::user(); if ($admin->role_id == 23) { $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id'); $data->whereIn('users.warea_id', $warea_ids); } if ($order_no) { $data->where('order_test.order_num', 'like','%'.$order_no.'%'); } if ($search_name){ $ids=$this->getUserIds($search_name); $data->whereIn('order_test.user_id', $ids); } if ($start_time && $end_time && empty($activity_id)) { $data->whereBetween('order_test.created_at', [$start_time, $end_time]); } if($activity_id){ $actice=Activity::find($activity_id); $data->whereBetween('order_test.created_at',[$actice->start_time,$actice->end_time]); } if ($request->store_id){ $data->where('order_test.store_id',$request->store_id); } $data->whereNotNull('order_test.store_id'); $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr') ->orderBy('order_test.id', 'order_detail.id') ->get()->toArray(); } else { $list = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id') ->leftJoin('users', 'order_test.user_id', '=', 'users.id') // ->join('warea','warea.id','=','users.warea_id') ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id') ->leftJoin('address', 'address.id', '=', 'order_test.address_id') ->select('order_test.order_num','order_test.created_at', 'order_test.good_user_id','order_test.id','order_test.store_id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile','users.warea_id', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total')) ->whereIn('order_test.id', $request->id) ->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr') ->orderBy('order_test.id', 'order_detail.id') ->get()->toArray(); } $dd = $this->dataGroup($list, 'order_num'); $d = []; foreach ($dd as $key => $val) { $info['gift'] = OrderGift::leftJoin('gifts', 'order_gift.gift_id', '=', 'gifts.id') ->where('order_gift.order_id', $val[0]['id']) ->where('order_gift.num', '>', '0') ->select('gifts.name', 'order_gift.num')->get(); $info['u_nickname'] = $val[0]['u_nickname']; $info['u_name'] = $val[0]['u_name']; $info['u_mobile'] = $val[0]['u_mobile']; $info['username'] = $val[0]['username']; $info['mobile'] = $val[0]['mobile']; $info['address'] = $val[0]['address']; $info['province'] = $val[0]['province']; $info['city'] = $val[0]['city']; $info['town'] = $val[0]['town']; $info['get_store'] =Store::where('id',$val[0]['store_id'])->select('name')->first(); if ($val[0]['good_user_id']){ $gooduser=User::where('id',$val[0]['good_user_id'])->select('mobile','nickname')->first(); $info['belong']='('.$gooduser->nickname.','.$gooduser->mobile.')'; }else{ $info['belong']=''; } $admin_name=Warea::where('id',$val[0]['warea_id'])->value('admin_name'); $info['admin_name'] =$admin_name; $info['created_at'] = $val[0]['created_at']; // $info['remark'] = (string)$val[0]['remark']; $info['remark'] = $this->getOrderRemark($val[0]['id']); $d[$key]['data'] = $info; $d[$key]['精装'] = []; $d[$key]['普通'] = []; $d[$key]['精装混合'] = []; $d[$key]['普通混合'] = []; $x1 = 0; $y1 = [];//精装 $x = 0; $y = [];//普通 foreach ($val as $k => $v) { if ($v['main_attr'] == '大卫博士精装版') { $main_attr = '精'; $n = floor($v['total'] / 10); for ($i = 0; $i < $n; $i++) { $cc = []; $cc['main_attr'] = $main_attr; $cc['sec_attr'] = $v['sec_attr']; $cc['size'] = $v['size']; $cc['num'] = 10; array_push($d[$key]['精装'], $cc); } if ($v['total'] % 10 > 0) { $t1 = $v['total'] % 10; if ($x1 + $t1 >= 10) { $x1 = $x1 + $t1 - 10; $z1['main_attr'] = $main_attr; $z1['sec_attr'] = $v['sec_attr']; $z1['size'] = $v['size']; $z1['num'] = $t1 - $x1; if ($y1) { array_pop($d[$key]['精装混合']); } array_push($y1, $z1); $z1 = []; array_push($d[$key]['精装混合'], $y1); $y1 = []; if ($x1 > 0) { $z1['main_attr'] = $main_attr; $z1['sec_attr'] = $v['sec_attr']; $z1['size'] = $v['size']; $z1['num'] = $x1; array_push($y1, $z1); array_push($d[$key]['精装混合'], $y1); } } else { $x1 += $t1; $z1['main_attr'] = $main_attr; $z1['sec_attr'] = $v['sec_attr']; $z1['size'] = $v['size']; $z1['num'] = $v['total'] % 10; if ($y1) { array_pop($d[$key]['精装混合']); } array_push($y1, $z1); array_push($d[$key]['精装混合'], $y1); } } } else { $n = floor($v['total'] / 6); if ($v['main_attr'] == '大卫博士老人版') { $main_attr = '老'; } elseif ($v['main_attr'] == '大卫博士简约版') { $main_attr = '简'; } else { $main_attr = '棉'; } for ($i = 0; $i < $n; $i++) { $cc = []; $cc['main_attr'] = $main_attr; $cc['sec_attr'] = $v['sec_attr']; $cc['size'] = $v['size']; $cc['num'] = 6; array_push($d[$key]['普通'], $cc); } if ($v['total'] % 6 > 0) { $t = $v['total'] % 6; if ($x + $t >= 6) { $x = $x + $t - 6; $z['main_attr'] = $main_attr; $z['sec_attr'] = $v['sec_attr']; $z['size'] = $v['size']; $z['num'] = $t - $x; if ($y) { array_pop($d[$key]['普通混合']); } array_push($y, $z); $z = []; array_push($d[$key]['普通混合'], $y); $y = []; if ($x > 0) { $z['main_attr'] = $main_attr; $z['sec_attr'] = $v['sec_attr']; $z['size'] = $v['size']; $z['num'] = $x; array_push($y, $z); array_push($d[$key]['普通混合'], $y); } } else { $x += $t; $z['main_attr'] = $main_attr; $z['sec_attr'] = $v['sec_attr']; $z['size'] = $v['size']; $z['num'] = $v['total'] % 6; if ($y) { array_pop($d[$key]['普通混合']); } array_push($y, $z); array_push($d[$key]['普通混合'], $y); } } } } } return $this->success($d); } //<<<<<<< HEAD //订单拆分快递单 public function orderBreakUpCouriers(Request $request) { ini_set('memory_limit', '1024M'); $input = $request->all(); if ($request->has('provice')) { $order_no = $input['order_no']; $start_time = $input['start_time']; $end_time = $input['end_time']; $activity_id = $input['activity_id']; $user_name = $input['user_name']; $receive_info = $input['receive_info']; $goods_info = $input['goods_info']; $province = $input['provice']; $city = $input['city']; $town = $input['area']; if ($request->has('order_status')) { $order_status = $input['order_status']; } else { $order_status = []; } if ($request->has('pay_status')) { $pay_status = $input['pay_status']; } else { $pay_status = []; } $order_type = $input['order_type']; $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id') ->leftJoin('users', 'order_test.user_id', '=', 'users.id') // ->join('warea','warea.id','=','users.warea_id') ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id') ->leftJoin('address', 'address.id', '=', 'order_test.address_id') ->select('order_test.order_num','order_test.created_at', 'order_test.good_user_id','users.warea_id','order_test.id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total')); $admin = Auth::user(); if ($admin->role_id == 23) { $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id'); $data->whereIn('users.warea_id', $warea_ids); } if ($order_no) { $data->where('order_test.order_num', $order_no); } if ($start_time && $end_time && empty($activity_id)) { $data->whereBetween('order_test.created_at', [$start_time, $end_time]); } if ($activity_id) { // $data->where('order_test.activity_id', $activity_id); $actice=Activity::find($activity_id); $data->whereBetween('order_test.created_at',[$actice->start_time,$actice->end_time]); } if ($user_name) { $user_id = $this->getUserNameIds($user_name); $data->whereIn('order_test.user_id', $user_id); } if ($receive_info) { $address_ids = $this->getReceiveAddressIds($receive_info); $data->whereIn('order_test.address_id', $address_ids); } if ($province && $province != '省') { $province_ids = $this->getProvinceIds($province); $data->whereIn('order_test.address_id', $province_ids); } if ($city && $city != '市') { $city_ids = $this->getCityIds($city); $data->whereIn('order_test.address_id', $city_ids); } if ($town && $town != '区') { $town_ids = $this->getAreaIds($town); $data->whereIn('order_test.address_id', $town_ids); } //商品信息 if ($goods_info) { $order_ids = $this->getGoodsOrderIds($goods_info); $data->whereIn('order_test.id', $order_ids); } if ($order_status) { if (!in_array('-1', $order_status)) { if (!in_array('5', $order_status)) { $data->whereIn('order_test.status', $order_status)->where('order_test.is_deleted', 0); } else { $data->where('order_test.is_deleted', 1) ->orWhere(function ($query) use ($order_status) { $query->where('order_test.is_deleted', 0) ->whereIn('order_test.status', $order_status); }); } } } if ($pay_status) { if (!in_array('-1', $pay_status)) { $data->whereIn('order_test.pay_status', $pay_status); } } if (in_array($order_type, [0, 1])) { $data->where('order_test.order_type', $order_type); } $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr') ->orderBy('order_test.id', 'order_detail.id') ->get()->toArray(); } else { if ($request->has('id')) { $list = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id') ->leftJoin('users', 'order_test.user_id', '=', 'users.id') // ->join('warea','warea.id','=','users.warea_id') ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id') ->leftJoin('address', 'address.id', '=', 'order_test.address_id') ->select('order_test.order_num','order_test.good_user_id','order_test.created_at','order_test.id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile','users.warea_id', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total')) ->whereIn('order_test.id', $request->id) ->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr') ->orderBy('order_test.id', 'order_detail.id') ->get()->toArray(); } else { if ($request->has('order_no')) { $order_no = $input['order_no']; } else { $order_no = ''; } $start_time = $input['start_time'] ?? ''; $end_time = $input['end_time'] ?? ''; $activity_id = $input['activity_id'] ?? ''; $search_name = $input['search_name'] ?? ''; if ($request->has('order_status')) { $order_status = $input['order_status']; } else { $order_status = []; } $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id') ->leftJoin('users', 'order_test.user_id', '=', 'users.id') // ->join('warea','warea.id','=','users.warea_id') ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id') ->leftJoin('address', 'address.id', '=', 'order_test.address_id') ->select('order_test.order_num','order_test.good_user_id','order_test.created_at', 'order_test.id','users.warea_id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total')); $admin = Auth::user(); if ($admin->role_id == 23) { $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id'); $data->whereIn('users.warea_id', $warea_ids); } if ($order_status || $order_status == 0) { if ('-1' == $order_status) { $data->whereIn('order_test.is_deleted', [0, 1]); } elseif ($order_status == 5) { $data->where('order_test.is_deleted', 1); } elseif ($order_status == 0) { $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0); } elseif ($order_status == 1) { $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0); } elseif ($order_status == 2) { $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0); } elseif ($order_status == 3) { $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0); } elseif ($order_status == 4) { $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0); } elseif ($order_status == 6) { $data->whereIn('order_test.pay_status', [0, 1])->where('order_test.order_test.is_deleted', 0); } } if ($order_no) { $data->where('order_test.order_num', $order_no); } if ($search_name) { // $s=substr(trim($search_name),0,4); // if($s=='DWBS'){ // $data->where('order_test.order_num',trim($search_name)); // }else{ $ids = $this->getUserIds($search_name); $data->whereIn('order_test.user_id', $ids); // } } if ($start_time && $end_time && empty($activity_id)) { $data->whereBetween('order_test.created_at', [$start_time, $end_time]); } if ($activity_id) { $actice = Activity::find($activity_id); $data->whereBetween('order_test.created_at', [$actice->start_time, $actice->end_time]); } $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr') ->orderBy('order_test.id', 'order_detail.id') ->get()->toArray(); } } $dd = $this->dataGroup($list, 'order_num'); $d = []; foreach ($dd as $key => $val) { // if($key==0){ // return $val; // } $info['gift'] = OrderGift::leftJoin('gifts', 'order_gift.gift_id', '=', 'gifts.id') ->where('order_gift.order_id', $val[0]['id']) ->where('order_gift.num', '>', '0') ->select('gifts.name', 'order_gift.num')->get(); $info['u_nickname'] = $val[0]['u_nickname']; $info['u_name'] = $val[0]['u_name']; $info['u_mobile'] = $val[0]['u_mobile']; $info['username'] = $val[0]['username']; $info['mobile'] = $val[0]['mobile']; $info['address'] = $val[0]['address']; $info['province'] = $val[0]['province']; $info['city'] = $val[0]['city']; $info['town'] = $val[0]['town']; if ($val[0]['good_user_id']){ $gooduser=User::where('id',$val[0]['good_user_id'])->select('mobile','nickname')->first(); $info['belong']='('.$gooduser->nickname.','.$gooduser->mobile.')'; }else{ $info['belong']=''; } $admin_name=Warea::where('id',$val[0]['warea_id'])->value('admin_name'); $info['admin_name'] =$admin_name; $info['created_at'] = $val[0]['created_at']; // $info['remark'] = (string)$val[0]['remark']; $info['remark'] = $this->getOrderRemark($val[0]['id']); $d[$key]['data'] = $info; $d[$key]['精装'] = []; $d[$key]['老'] = []; $d[$key]['简'] = []; $d[$key]['棉老'] = []; $d[$key]['普通'] = []; $d[$key]['精装混合'] = []; $d[$key]['老混'] = []; $d[$key]['简混'] = []; $d[$key]['棉老混'] = []; $d[$key]['普通混'] = []; $x1 = 0; $y1 = [];//精装 $x2 = 0; $y2 = [];//老 $x3 = 0; $y3 = [];//老 $x4 = 0; $y4 = [];//老 $x = 0; $y = [];//普通 foreach ($val as $k => $v) { if ($v['main_attr'] == '大卫博士精装版') { $main_attr = '精'; $n = floor($v['total'] / 10); for ($i = 0; $i < $n; $i++) { $cc = []; $cc['main_attr'] = $main_attr; $cc['sec_attr'] = $v['sec_attr']; $cc['size'] = $v['size']; $cc['num'] = 10; array_push($d[$key]['精装'], $cc); } if ($v['total'] % 10 > 0) { $t1 = $v['total'] % 10; if ($x1 + $t1 >= 10) { $x1 = $x1 + $t1 - 10; $z1['main_attr'] = $main_attr; $z1['sec_attr'] = $v['sec_attr']; $z1['size'] = $v['size']; $z1['num'] = $t1 - $x1; if ($y1) { array_pop($d[$key]['精装混合']); } array_push($y1, $z1); $z1 = []; array_push($d[$key]['精装混合'], $y1); $y1 = []; if ($x1 > 0) { $z1['main_attr'] = $main_attr; $z1['sec_attr'] = $v['sec_attr']; $z1['size'] = $v['size']; $z1['num'] = $x1; array_push($y1, $z1); array_push($d[$key]['精装混合'], $y1); } } else { $x1 += $t1; $z1['main_attr'] = $main_attr; $z1['sec_attr'] = $v['sec_attr']; $z1['size'] = $v['size']; $z1['num'] = $v['total'] % 10; if ($y1) { array_pop($d[$key]['精装混合']); } array_push($y1, $z1); array_push($d[$key]['精装混合'], $y1); } } } else { $n = floor($v['total'] / 6); if ($v['main_attr'] == '大卫博士老人版') { $main_attr = '老'; for ($i = 0; $i < $n; $i++) { $cc = []; $cc['main_attr'] = $main_attr; $cc['sec_attr'] = $v['sec_attr']; $cc['size'] = $v['size']; $cc['num'] = 6; array_push($d[$key]['老'], $cc); } if ($v['total'] % 6 > 0) { $t2 = $v['total'] % 6; if ($x2 + $t2 >= 6) { $x2 = $x2 + $t2 - 6; $z2['main_attr'] = $main_attr; $z2['sec_attr'] = $v['sec_attr']; $z2['size'] = $v['size']; $z2['num'] = $t2 - $x2; if ($y2) { array_pop($d[$key]['老混']); } array_push($y2, $z2); $z2 = []; array_push($d[$key]['老混'], $y2); $y2 = []; if ($x2 > 0) { $z2['main_attr'] = $main_attr; $z2['sec_attr'] = $v['sec_attr']; $z2['size'] = $v['size']; $z2['num'] = $x2; array_push($y2, $z2); array_push($d[$key]['老混'], $y2); } } else { $x2 += $t2; $z2['main_attr'] = $main_attr; $z2['sec_attr'] = $v['sec_attr']; $z2['size'] = $v['size']; $z2['num'] = $v['total'] % 6; if ($y2) { array_pop($d[$key]['老混']); } array_push($y2, $z2); array_push($d[$key]['老混'], $y2); } } } elseif ($v['main_attr'] == '大卫博士简约版') { $main_attr = '简'; for ($i = 0; $i < $n; $i++) { $cc = []; $cc['main_attr'] = $main_attr; $cc['sec_attr'] = $v['sec_attr']; $cc['size'] = $v['size']; $cc['num'] = 6; array_push($d[$key]['简'], $cc); } if ($v['total'] % 6 > 0) { $t3 = $v['total'] % 6; if ($x3 + $t3 >= 6) { $x3 = $x3 + $t3 - 6; $z3['main_attr'] = $main_attr; $z3['sec_attr'] = $v['sec_attr']; $z3['size'] = $v['size']; $z3['num'] = $t3 - $x3; if ($y3) { array_pop($d[$key]['简混']); } array_push($y3, $z3); $z3 = []; array_push($d[$key]['简混'], $y3); $y3 = []; if ($x3 > 0) { $z3['main_attr'] = $main_attr; $z3['sec_attr'] = $v['sec_attr']; $z3['size'] = $v['size']; $z3['num'] = $x3; array_push($y3, $z3); array_push($d[$key]['简混'], $y3); } } else { $x3 += $t3; $z3['main_attr'] = $main_attr; $z3['sec_attr'] = $v['sec_attr']; $z3['size'] = $v['size']; $z3['num'] = $v['total'] % 6; if ($y3) { array_pop($d[$key]['简混']); } array_push($y3, $z3); array_push($d[$key]['简混'], $y3); } } } else { $main_attr = '棉老'; for ($i = 0; $i < $n; $i++) { $cc = []; $cc['main_attr'] = $main_attr; $cc['sec_attr'] = $v['sec_attr']; $cc['size'] = $v['size']; $cc['num'] = 6; array_push($d[$key]['棉老'], $cc); } if ($v['total'] % 6 > 0) { $t4 = $v['total'] % 6; if ($x4 + $t4 >= 6) { $x4 = $x4 + $t4 - 6; $z4['main_attr'] = $main_attr; $z4['sec_attr'] = $v['sec_attr']; $z4['size'] = $v['size']; $z4['num'] = $t4 - $x4; if ($y4) { array_pop($d[$key]['棉老混']); } array_push($y4, $z4); $z4 = []; array_push($d[$key]['棉老混'], $y4); $y4 = []; if ($x4 > 0) { $z4['main_attr'] = $main_attr; $z4['sec_attr'] = $v['sec_attr']; $z4['size'] = $v['size']; $z4['num'] = $x4; array_push($y4, $z4); array_push($d[$key]['棉老混'], $y4); } } else { $x4 += $t4; $z4['main_attr'] = $main_attr; $z4['sec_attr'] = $v['sec_attr']; $z4['size'] = $v['size']; $z4['num'] = $v['total'] % 6; if ($y4) { array_pop($d[$key]['棉老混']); } array_push($y4, $z4); array_push($d[$key]['棉老混'], $y4); } } } } } $nb=0; $nd=[]; if(count($y2)>0){ foreach($y2 as $k=>$v){ $nb+=$v['num']; array_push($nd, $v); } array_pop($d[$key]['老混']); } if(count($y3)>0){ foreach($y3 as $k=>$v){ $nb+=$v['num']; if($nb>6){ $m=$v; $m['num']=$v['num']-($nb-6); array_push($nd, $m); array_push($d[$key]['普通混'],$nd); $nd=[]; $nb=$nb-6; $l=$v; $l['num']=$nb; array_push($nd, $l); }elseif($nb==6){ array_push($nd, $v); array_push($d[$key]['普通混'],$nd); $nd=[]; $nb=0; }else{ array_push($nd, $v); } } array_pop($d[$key]['简混']); } if(count($y4)>0){ foreach($y4 as $k=>$v){ $nb+=$v['num']; if($nb>6){ $m=$v; $m['num']=$v['num']-($nb-6); array_push($nd, $m); array_push($d[$key]['普通混'],$nd); $nd=[]; $nb=$nb-6; $l=$v; $l['num']=$nb; array_push($nd, $l); }elseif($nb==6){ array_push($nd, $v); array_push($d[$key]['普通混'],$nd); $nd=[]; $nb=0; }else{ array_push($nd, $v); } } array_pop($d[$key]['棉老混']); } if(count($nd)>0){ array_push($d[$key]['普通混'],$nd); } } return $this->success($d); } public function getMergerOrder(Request $request){ //<<<<<<< HEAD //<<<<<<< HEAD // $input=$request->all(); // $page_index=$input['page_index']; // $page_size=$input['page_size']; // $num=$page_size*($page_index-1); // $activity_id=$input['activity_id']; // $search_name=$input['search_name']; // $activity=Activity::where('id',$activity_id)->first(); // $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id') // ->leftJoin('users', 'order_test.user_id', '=', 'users.id') // ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id') // ->leftJoin('address', 'address.id', '=', 'order_test.address_id'); // if($search_name){ // $address_ids=Address::where(function($query) use ($search_name){ // $query->where('username','like','%'.$search_name.'%') // ->orWhere('mobile',$search_name); // })->pluck('id'); // $data->whereIn('order_test.address_id',$address_ids); // } // $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time]) // ->where('order_test.is_deleted',0) // ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', // 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town', // 'goods_test.unit',DB::raw('SUM(order_detail.num) as total')) // ->groupBy('order_test.address_id','order_test.user_id','goods_test.unit') // ->orderBy('order_test.created_at') // ->get(); // $array=[]; // foreach($list as $key => $val){ // $keys=$val->address_id.'-'.$val->u_id; // $array[$keys]['name']=$val->username; // $array[$keys]['mobile']=$val->mobile; // $array[$keys]['address']=$val->address; // $array[$keys]['address_id']=$val->address_id; // $array[$keys]['user_id']=$val->u_id; // $array[$keys]['province']=$val->province; // $array[$keys]['city']=$val->city; // $array[$keys]['town']=$val->town; // $array[$keys]['u_nickname']=$val->u_nickname; // $array[$keys]['u_mobile']=$val->u_mobile; // $array[$keys]['u_name']=$val->u_name; // // if($val->unit=='套'){ // if(empty($array[$keys]['num'])){ // $array[$keys]['num']=$val->total; // }else{ // $array[$keys]['num']+=$val->total; // } // }elseif($val->unit=='件'){ // if(empty($array[$keys]['num'])){ // $array[$keys]['num']=$val->total*2; // }else{ // $array[$keys]['num']+=$val->total*2; //======= // $input=$request->all(); // $page_index=$input['page_index']; // $page_size=$input['page_size']; // $num=$page_size*($page_index-1); // $activity_id=$input['activity_id']; // $search_name=$input['search_name']; // $activity=Activity::where('id',$activity_id)->first(); // $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id') // ->leftJoin('users', 'order_test.user_id', '=', 'users.id') // ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id') // ->leftJoin('address', 'address.id', '=', 'order_test.address_id'); // if($search_name){ // $address_ids=Address::where(function($query) use ($search_name){ // $query->where('username','like','%'.$search_name.'%') // ->orWhere('mobile',$search_name); // })->pluck('id'); // $data->whereIn('order_test.address_id',$address_ids); // } // $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time]) // ->where('order_test.is_deleted',0) // ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', // 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town', // 'goods_test.unit',DB::raw('SUM(order_detail.num) as total')) // ->groupBy('order_test.address_id','order_test.user_id','goods_test.unit') // ->orderBy('order_test.created_at') // ->get(); // $array=[]; // foreach($list as $key => $val){ // $keys=$val->address_id.'-'.$val->u_id; // $array[$keys]['name']=$val->username; // $array[$keys]['mobile']=$val->mobile; // $array[$keys]['address']=$val->address; // $array[$keys]['address_id']=$val->address_id; // $array[$keys]['user_id']=$val->u_id; // $array[$keys]['province']=$val->province; // $array[$keys]['city']=$val->city; // $array[$keys]['town']=$val->town; // $array[$keys]['u_nickname']=$val->u_nickname; // $array[$keys]['u_mobile']=$val->u_mobile; // $array[$keys]['u_name']=$val->u_name; // // if($val->unit=='套'){ // if(empty($array[$keys]['num'])){ // $array[$keys]['num']=$val->total; // }else{ // $array[$keys]['num']+=$val->total; // } // }elseif($val->unit=='件'){ // if(empty($array[$keys]['num'])){ // $array[$keys]['num']=$val->total*2; // }else{ // $array[$keys]['num']+=$val->total*2; // } //>>>>>>> 78008612722779b2a4d161ea6cec9067c149b72e //======= ini_set('memory_limit', '1024M'); $input=$request->all(); $page_index=$input['page_index']; $page_size=$input['page_size']; $num=$page_size*($page_index-1); $activity_id=$input['activity_id']; $search_name=$input['search_name']; $activity=Activity::where('id',$activity_id)->first(); $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id') ->leftJoin('users', 'order_test.user_id', '=', 'users.id') ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id') ->leftJoin('address', 'address.id', '=', 'order_test.address_id'); $admin=Auth::user(); if($admin->role_id==23){ $warea_ids = Warea::where('admin_id',$admin->id)->pluck('id'); $data->whereHas('get_user', function($query) use ($warea_ids){ $query->whereIn('warea_id',$warea_ids); }); } if($search_name){ $address_ids=Address::where(function($query) use ($search_name){ $query->where('username','like','%'.$search_name.'%') ->orWhere('mobile',$search_name); })->pluck('id'); $data->whereIn('order_test.address_id',$address_ids); } $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time]) ->where('order_test.is_deleted',0) ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town', 'goods_test.unit',DB::raw('SUM(order_detail.num) as total')) ->groupBy('order_test.address_id','order_test.user_id','goods_test.unit') ->orderBy('order_test.created_at') ->get(); $array=[]; foreach($list as $key => $val) { $keys = $val->address_id . '-' . $val->u_id; $array[$keys]['name'] = $val->username; $array[$keys]['mobile'] = $val->mobile; $array[$keys]['address'] = $val->address; $array[$keys]['address_id'] = $val->address_id; $array[$keys]['user_id'] = $val->u_id; $array[$keys]['province'] = $val->province; $array[$keys]['city'] = $val->city; $array[$keys]['town'] = $val->town; $array[$keys]['u_nickname'] = $val->u_nickname; $array[$keys]['u_mobile'] = $val->u_mobile; $array[$keys]['u_name'] = $val->u_name; if ($val->unit == '套') { if (empty($array[$keys]['num'])) { $array[$keys]['num'] = $val->total; } else { $array[$keys]['num'] += $val->total; } } elseif ($val->unit == '件') { if (empty($array[$keys]['num'])) { $array[$keys]['num'] = $val->total * 2; } else { $array[$keys]['num'] += $val->total * 2; //>>>>>>> comissar } } } $gifts = Gifts::where('activity_id', $activity_id)->get(); foreach ($array as $key => $val) { $arr = []; foreach ($gifts as $k => $v) { if (floor($val['num'] / $v->num) > 0) { $arr[] = $v->name . '*' . floor($val['num'] / $v->num); } $array[$key]['gift'] = implode(',', $arr); } } $count=count($array); return $this->success_list(array_slice($array,$num,$page_size),'成功',$count); } public function getOrderGoodsInfo(Request $request){ $input=$request->all(); $address_id=$input['address_id']; $user_id=$input['user_id']; $activity_id=$input['activity_id']; $activity=Activity::find($activity_id); $info=Ordertest::with(['get_order_detail'=>function($query){ $query->with('get_goods'); }])->where('is_deleted',0) ->where('address_id',$address_id) ->where('user_id',$user_id) ->whereBetween('created_at',[$activity->start_time,$activity->end_time]) ->get(); if($info){ return $this->success($info); }else{ return $this->error(); } } //<<<<<<< HEAD // public function exportMergerOrder(Request $request){ // $input=$request->all(); // $activity_id=$input['activity_id']; // $search_name=$input['search_name']; // $activity=Activity::where('id',$activity_id)->first(); // $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id') // ->leftJoin('users', 'order_test.user_id', '=', 'users.id') // ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id') // ->leftJoin('address', 'address.id', '=', 'order_test.address_id'); // if($search_name){ // $address_ids=Address::where(function($query) use ($search_name){ // $query->where('username','like','%'.$search_name.'%') // ->orWhere('mobile',$search_name); // })->pluck('id'); // $data->whereIn('order_test.address_id',$address_ids); // } // $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time]) // ->where('order_test.is_deleted',0) // ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', // 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town', // 'order_test.order_num', // 'goods_test.unit','goods_test.name','goods_test.main_attr','goods_test.sec_attr','goods_test.size', // DB::raw('SUM(order_detail.num) as total')) // ->groupBy('order_test.address_id','order_test.user_id','order_test.order_num','goods_test.unit','goods_test.main_attr','goods_test.sec_attr','goods_test.size') // ->orderBy('order_test.created_at') // ->get(); //// dd($list); // $array=[]; // foreach($list as $key => $val){ // $keys=$val->address_id.'-'.$val->u_id; // $array[$keys]['name']=$val->username; // $array[$keys]['mobile']=$val->mobile; // $array[$keys]['address']=$val->address; // $array[$keys]['address_id']=$val->address_id; // $array[$keys]['user_id']=$val->u_id; // $array[$keys]['province']=$val->province; // $array[$keys]['city']=$val->city; // $array[$keys]['town']=$val->town; // $array[$keys]['u_nickname']=$val->u_nickname; // $array[$keys]['u_mobile']=$val->u_mobile; // $array[$keys]['u_name']=$val->u_name; // $array[$keys]['goods'][$val->order_num][]=$val->name.'-'.$val->sec_attr.'-'.$val->size.'*'.$val->total; //// $array[$keys]['goods'][$val->order_num][]=[$val->name.$val->size,$val->name,$val->size,$val->sec_attr,$val->total]; // if($val->unit=='套'){ // if(empty($array[$keys]['num'])){ // $array[$keys]['num']=$val->total; // }else{ // $array[$keys]['num']+=$val->total; // } // }elseif($val->unit=='件'){ // if(empty($array[$keys]['num'])){ // $array[$keys]['num']=$val->total*2; // }else{ // $array[$keys]['num']+=$val->total*2; // } // } // } // $gifts=Gifts::where('activity_id',$activity_id)->get(); // foreach($array as $key=>$val){ // $array[$key]['shouhuan']=0; // $array[$key]['xianglian']=0; // $arr=[]; // foreach($gifts as $k => $v){ // if(floor($val['num']/$v->num)>0){ // if ($v->name=='手环'||$v->name=='赠品-手环'){ // $array[$key]['shouhuan']=floor($val['num']/$v->num); // } // if ($v->name=='项链'||$v->name=='赠品-项链'){ // $array[$key]['xianglian']=floor($val['num']/$v->num); // } // $arr[]=$v->name.'*'.floor($val['num']/$v->num); public function exportMergerOrder(Request $request){ $input=$request->all(); $activity_id=$input['activity_id']; $search_name=$input['search_name']; $activity=Activity::where('id',$activity_id)->first(); $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id') ->leftJoin('users', 'order_test.user_id', '=', 'users.id') ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id') ->leftJoin('address', 'address.id', '=', 'order_test.address_id'); $admin=Auth::user(); if($admin->role_id==23){ $warea_ids = Warea::where('admin_id',$admin->id)->pluck('id'); $data->whereHas('get_user', function($query) use ($warea_ids){ $query->whereIn('warea_id',$warea_ids); }); } if($search_name){ $address_ids=Address::where(function($query) use ($search_name){ $query->where('username','like','%'.$search_name.'%') ->orWhere('mobile',$search_name); })->pluck('id'); $data->whereIn('order_test.address_id',$address_ids); } $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time]) ->where('order_test.is_deleted',0) ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town', 'order_test.order_num', 'goods_test.unit','goods_test.name','goods_test.main_attr','goods_test.sec_attr','goods_test.size', DB::raw('SUM(order_detail.num) as total')) ->groupBy('order_test.address_id','order_test.user_id','order_test.order_num','goods_test.unit','goods_test.main_attr','goods_test.sec_attr','goods_test.size') ->orderBy('order_test.created_at') ->get(); $array=[]; foreach($list as $key => $val){ $keys=$val->address_id.'-'.$val->u_id; $array[$keys]['name']=$val->username; $array[$keys]['mobile']=$val->mobile; $array[$keys]['address']=$val->address; $array[$keys]['address_id']=$val->address_id; $array[$keys]['user_id']=$val->u_id; $array[$keys]['province']=$val->province; $array[$keys]['city']=$val->city; $array[$keys]['town']=$val->town; $array[$keys]['u_nickname']=$val->u_nickname; $array[$keys]['u_mobile']=$val->u_mobile; $array[$keys]['u_name']=$val->u_name; $array[$keys]['goods'][$val->order_num][]=$val->name.'-'.$val->sec_attr.'-'.$val->size.'*'.$val->total; // $array[$keys]['goods'][$val->order_num][]=[$val->name.$val->size,$val->name,$val->size,$val->sec_attr,$val->total]; if($val->unit=='套'){ if(empty($array[$keys]['num'])){ $array[$keys]['num']=$val->total; }else{ $array[$keys]['num']+=$val->total; } }elseif($val->unit=='件'){ if(empty($array[$keys]['num'])){ $array[$keys]['num']=$val->total*2; }else{ $array[$keys]['num']+=$val->total*2; } } } $gifts=Gifts::where('activity_id',$activity_id)->get(); foreach($array as $key=>$val){ $array[$key]['shouhuan']=0; $array[$key]['xianglian']=0; foreach($gifts as $k => $v){ if(floor($val['num']/$v->num)>0){ if ($v->name=='手环'||$v->name=='赠品-手环'){ $array[$key]['shouhuan']=floor($val['num']/$v->num); } if ($v->name=='项链'||$v->name=='赠品-项链'){ $array[$key]['xianglian']=floor($val['num']/$v->num); } } } } return $this->success($array); } //根据名称查询代理信息 public function getUserNameIds($search = null) { return User::where(function ($query) use ($search) { $query->where('nickname', 'like', '%' . $search . '%') ->orwhere('realname', 'like', '%' . $search . '%') ->orwhere('mobile', $search); })->pluck('id'); } //根据商品名称获取订单id public function getGoodsOrderIds($search = null) { return Orderdetail::where('goods_name', 'like', '%' . $search . '%') ->pluck('order_id'); } protected function dataGroup(array $dataArr, string $keyStr): array { $newArr = []; foreach ($dataArr as $k => $val) { //数据根据日期分组 $newArr[$val[$keyStr]][] = $val; } return $newArr; } public function getGoodsInfo($order_id) { $goods = Goodtest::leftJoin('order_detail', function ($query) use ($order_id) { $query->on('goods_test.id', '=', 'order_detail.goods_id') ->where('order_id', $order_id); }) ->select('goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total')) ->groupBy('goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr') ->get(); return $goods; } //======= /***T恤统计*/ public function get_t_data(Request $request) { $input = $request->all(); $page_index = $input['page_index']; $page_size = $input['page_size']; $num = ($page_index - 1) * $page_size; $data = CrownCount::orderBy('exchange')->orderBy('id'); $datas = CrownCount::orderBy('exchange')->orderBy('id'); if ($request->mobile) { $data->where('mobile', $request->mobile) ->orwhere('nickname', 'like', '%' . $request->mobile . '%'); $datas->where('mobile', $request->mobile) ->orwhere('nickname', 'like', '%' . $request->mobile . '%'); } if ($request->crown_mobile) { $data->where('crown_mobile', $request->crown_mobile) ->orwhere('crown_name', 'like', '%' . $request->crown_mobile . '%'); $datas->where('crown_mobile', $request->crown_mobile) ->orwhere('crown_name', 'like', '%' . $request->crown_mobile . '%'); } $count = $data->count(); $tt = clone $datas; $count_surplus = $datas->where('exchange', 0)->count(); $t = $tt->select(DB::raw('sum(crown_count.type_l) as total_L'), DB::raw('sum(crown_count.type_xl) as total_XL'), DB::raw('sum(crown_count.type_3XL) as total_3XL'))->get(); $count_write = $count - $count_surplus; if ($count == 0) { $percent = 0; } else { $percent = (round($count_write / $count, 4) * 100) . '%'; } if ($count == 0) { return $this->success_list([], '', $count); } $list = $data->skip($num)->take($page_size)->get(); $re = []; foreach ($list as $k => $v) { $re[$k]['序号'] = $v->id; $re[$k]['下单人昵称'] = $v->crown_name; $re[$k]['下单人手机号'] = $v->crown_mobile; $re[$k]['收货人昵称'] = $v->nickname; $re[$k]['收货人手机号'] = $v->mobile; $re[$k]['T恤总量'] = $v->total; $re[$k]['尺码:L'] = $v->type_l; $re[$k]['尺码:XL'] = $v->type_xl; $re[$k]['尺码:3XL'] = $v->type_3xl; $re[$k]['已统计T恤'] = $v->type_l + $v->type_xl + $v->type_3xl; $re[$k]['收货人省份'] = $v->province; $re[$k]['收货人城市'] = $v->city; $re[$k]['收货人地区'] = $v->area; $re[$k]['收货人地址'] = $v->address; } $all = [ 'total' => $count, 'write_count' => $count_write, 'surplus_count' => $count_surplus, 'percent' => $percent, 'total_L' => $t[0]['total_L'], 'total_XL' => $t[0]['total_XL'], 'total_3XL' => $t[0]['total_3XL'], 'total_all' => (string)($t[0]['total_3XL'] + $t[0]['total_XL'] + $t[0]['total_L']), 'list' => $re ]; return $this->success($all); // return $this->success_list($re,'',$count); } /**下载T恤详情**/ public function get_t_excel(Request $request) { $data = CrownCount::orderBy('id'); if ($request->mobile) { $data->where('mobile', $request->mobile) ->orwhere('nickname', 'like', '%' . $request->mobile . '%'); } if ($request->crown_mobile) { $data->where('mobile', $request->crown_mobile) ->orwhere('crown_name', 'like', '%' . $request->crown_mobile . '%'); } $list = $data->get(); foreach ($list as $k => $v) { $re[$k]['下单人昵称'] = $v->crown_name; $re[$k]['下单人手机号'] = $v->crown_mobile; $re[$k]['收货人昵称'] = $v->nickname; $re[$k]['收货人手机号'] = $v->mobile; $re[$k]['T恤总量'] = $v->total; $re[$k]['尺码:L'] = $v->type_l; $re[$k]['尺码:XL'] = $v->type_xl; $re[$k]['尺码:3XL'] = $v->type_3xl; $re[$k]['已统计T恤'] = $v->type_l + $v->type_xl + $v->type_3xl; $re[$k]['收货人省份'] = $v->province; $re[$k]['收货人城市'] = $v->city; $re[$k]['收货人地区'] = $v->area; $re[$k]['收货人地址'] = $v->address; } return $this->success_list($re); } /* * 修改T恤统计信息 * */ public function update_t(Request $request) { $re = $request->all(); $v = CrownCount::where('id', $re['序号'])->first(); if (!$v) { return $this->error(40013, '修改出错'); } try { $count = $re['尺码:L'] + $re['尺码:XL'] + $re['尺码:3XL']; if ($count > $re['T恤总量']) { return $this->error(40013, '尺码数量总和大于T恤总量'); } // if ($v->exchange!=$count){ // return $this->error(40013,'尺码数量总和不等于已统计数量'); // } $v->crown_name = $re['下单人昵称']; $v->crown_mobile = $re['下单人手机号']; $v->nickname = $re['收货人昵称']; $v->mobile = $re['收货人手机号']; $v->total = $re['T恤总量']; $v->type_l = $re['尺码:L']; $v->type_xl = $re['尺码:XL']; $v->type_3xl = $re['尺码:3XL']; $v->exchange = $re['尺码:L'] + $re['尺码:XL'] + $re['尺码:3XL']; $v->province = $re['收货人省份']; $v->city = $re['收货人城市']; $v->area = $re['收货人地区']; $v->address = $re['收货人地址']; $v->save(); return $this->success([]); } catch (\Exception $exception) { return $this->error(40013, $exception); } } /* * 新增 * **/ public function add_t(Request $request) { $re = $request->all(); $v = new CrownCount(); try { $count = $re['尺码:L'] + $re['尺码:XL'] + $re['尺码:3XL']; if ($count > $re['T恤总量']) { return $this->error(40013, '尺码数量总和大于T恤总量'); } $v->crown_name = $re['下单人昵称']; $v->crown_mobile = $re['下单人手机号']; $v->nickname = $re['收货人昵称']; $v->mobile = $re['收货人手机号']; $v->total = $re['T恤总量']; $v->type_l = $re['尺码:L']; $v->type_xl = $re['尺码:XL']; $v->type_3xl = $re['尺码:3XL']; $v->exchange = $re['尺码:L'] + $re['尺码:XL'] + $re['尺码:3XL']; $v->province = $re['收货人省份']; $v->city = $re['收货人城市']; $v->area = $re['收货人地区']; $v->address = $re['收货人地址']; $v->save(); return $this->success([]); } catch (\Exception $exception) { return $this->error(40013, '修改失败'); } } /* * 删除T恤统计 * **/ public function delete_t(Request $request) { $input = $request->all(); CrownCount::where('id', $input['序号'])->delete(); return $this->success([]); } public function get_user() { $data = [20218, 2533, 13649, 12336, 23488, 21256, 12487, 17769, 16377, 20363, 9736, 2568, 11718, 21221]; foreach ($data as $k => $v) { $user = User::find($v); $re[$k]['mobile'] = $user->mobile; $re[$k]['nickname'] = $user->nickname; $re[$k]['realname'] = $user->realname; } return $this->success_list($re); } /**尺码详情**/ public function size_data(){ $active=Activity::where('is_ing',1)->first(); $data=Orderdetail::join('order_test','order_test.id','=','order_detail.order_id') ->where('order_test.is_deleted',0) ->whereBetween('order_detail.created_at',[$active->start_time,$active->end_time]) ->select('order_detail.goods_id','order_detail.goods_name','order_detail.goods_size',DB::raw('sum(order_detail.num) as num')) ->groupBy('order_detail.goods_id')->orderBy('order_detail.goods_id')->get(); return $this->success_list($data); } //获取订单备注 private function getOrderRemark($order_id) { $remark = OrderRemark::where('order_id', $order_id) ->select('remark', 'name')->get(); $str_remark = ''; if ($remark) { foreach ($remark as $k => $v) { $str_remark .= '【' . $v->remark . '/---/' . $v->name . '】'; } } return $str_remark; } public function getActivityDataInfo(Request $request) { $input=$request->all(); $page_index=$input['page_index']; $page_size=$input['page_size']; $num=$page_size*($page_index-1); $search_name=$input['search_name']; $activity=Activity::where('disabled',0)->get(); foreach($activity as $key=>$val){ if($val->end_time <= date("Y-m-d H:i:s")){ $act_data_num = EveryActData::where('activity_id',$val->id)->count(); if($act_data_num <= 0){ $user=Ordertest::where('pay_status',2)->where('is_deleted',0)->whereBetween('created_at',[$val->start_time,$val->end_time]) ->groupBy('user_id')->pluck('user_id'); $info=User::select('id','nickname','realname','mobile','level')->withCount(['order_test as order_test_account'=>function($query)use($val){ $query->select(DB::raw('sum(pay_money)'))->whereBetween('created_at',[$val->start_time,$val->end_time]); }])->whereIn('id',$user)->get(); $act=[]; foreach($info as $k=>$v){ $act[$k]['user_id']=$v->id; $act[$k]['activity_id']=$val->id; $act[$k]['account']=$v->order_test_account; $act[$k]['created_at']=date("Y-m-d H:i:s"); $act[$k]['updated_at']=date("Y-m-d H:i:s"); } EveryActData::insert($act); } } } $user_ids=EveryActData::groupBy('user_id')->pluck('user_id'); $info=User::select('id','nickname','realname','mobile','level') ->with(['every_act_data'=>function($query){ $query->select('id','user_id','activity_id','account')->with(['activity:id,title']); }])->whereIn('id',$user_ids); if($search_name){ $info->where(function($query)use($search_name){ $query->where('nickname','like','%'.$search_name.'%') ->where('mobile',$search_name); }); } $count=$info ->count(); $list=$info -> OrderByDesc('level')->OrderByDesc('id')->skip($num)->take($page_size)->get(); // return $this->success($list); foreach($list as $key=>$val){ // $count[$key]=0; foreach($val as $k=>$v){ // $list[$v->id]['nickname']=$v['nickname']; // $list[$v->id]['realname']=$v['realname']; // $list[$v->id]['mobile']=$v['mobile']; // $list[$v->id]['level']=$v['level']; // $list[$v->id][$key]=$v->order_test_account; // $count[$key]+=$v->order_test_account; } } $every_act=EveryActData::with(['activity:id,title'])->groupBy('activity_id')->orderByDesc('activity_id')->get(); $account=[]; foreach($every_act as $key=>$val){ $account[$val->activity_id]['title']=$val->activity->title; $account[$val->activity_id]['account']=EveryActData::where('activity_id',$val->activity_id)->sum('account'); } $data['list']=$list; $data['account']=$account; return $this->success_list($data,'',$count); } }