'圆通', 'p02'=> '申通', 'p03'=> '韵达', 'p24'=> '韵达国际', 'p04'=> '中通', 'p25'=> '中通快运', 'p05'=> '顺丰', 'p06'=> '百世快运', 'p07'=> 'EMS', 'p08'=> '京广速运', 'p09'=> '百世极兔/百世快递', 'p10'=> '京东', 'p16'=> '安能', 'p17'=> '优速', 'p21'=> '运通速运', 'p18'=> '自提', 'p26'=> '德邦快递/德邦物流', 'p19'=> '零担', 'p20'=> '整车', 'p22'=> '邮政', 'p23'=> '跨越', 'p27'=> '壹米滴答', 'p32'=> '极兔速递', 'p34'=> '丰网速运', 'p30'=> '其他', 'p35'=> '邮政标快' ]; public function pos_form(){ $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $start = $params['start']; $storeid = $params['storeid']; $end = $params['end']; $OrderModel = new \app\common\model\datas\Poscount; $userid = $this->auth->id; $userStoreModel = new \app\common\model\UserStore; $fieldstr = 'create_date,postcode,weights'; if($this->auth->check("isstaff")){ if($storeid!=0){ $orderquery = $OrderModel->where(["STOREID"=>$storeid]); }else{ $orderquery = $OrderModel->where(["WAREHOUSEID"=>$WAREHOUSEID]); } }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); $storeids = []; foreach ($stores as $r){ array_push($storeids,$r["store_id"]); } if($storeid!=0){ $storeids = array_intersect([$storeid],$storeids); } $orderquery = $OrderModel->where("STOREID",'in',$storeids); } $orderquery->field(rtrim($fieldstr, ','))->where('create_date','BETWEEN',[strtotime($start),strtotime($end)]); $list = $orderquery->select(); $postcodes = []; foreach($list as $r){ $has = false; $r['POSTNAME']=$this->pcodes[$r['postcode']]; $weights = json_decode($r['weights'],true); foreach ($postcodes as $k => $rr){ if($rr["POSTCODE"]==$r["postcode"]){ $has = true; $postcodes[$k]["weight_0_300"] += ($weights["w1"] ?? null); $postcodes[$k]["weight_300_500"]+= $weights["w2"]; $postcodes[$k]["weight_500_1000"]+= $weights["w3"]; $postcodes[$k]["weight_1000_1500"]+= $weights["w4"]; $postcodes[$k]["weight_1500_2000"]+= $weights["w5"]; $postcodes[$k]["weight_2000_2500"]+= $weights["w6"]; $postcodes[$k]["weight_2500_3000"]+= $weights["w7"]; $postcodes[$k]["weight_gt_3000"]+= $weights["w8"]; $postcodes[$k]["count"]+= $weights["w8"]+ $weights["w7"]+$weights["w6"]+ $weights["w5"]+$weights["w4"]+ $weights["w3"]+$weights["w2"]+ $weights["w1"]; } } if(!$has){ $tmp = ["POSTCODE"=>$r["postcode"],"POSTNAME"=>$r["POSTNAME"]]; $tmp["weight_0_300"] = $weights["w1"]; $tmp["weight_300_500"]= $weights["w2"]; $tmp["weight_500_1000"]= $weights["w3"]; $tmp["weight_1000_1500"]= $weights["w4"]; $tmp["weight_1500_2000"]= $weights["w5"]; $tmp["weight_2000_2500"]= $weights["w6"]; $tmp["weight_2500_3000"]= $weights["w7"]; $tmp["weight_gt_3000"]= $weights["w8"]; $tmp["count"]= $weights["w8"]+ $weights["w7"]+$weights["w6"]+ $weights["w5"]+$weights["w4"]+ $weights["w3"]+$weights["w2"]+ $weights["w1"]; array_push($postcodes,$tmp); } } $this->success('成功',$postcodes); } public function pos_count(){ $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $start = $params['start']; $storeid = $params['storeid']; $end = $params['end']; $co = $this->getDailyStartTimestamps(strtotime($start),strtotime($end)); $OrderModel = new \app\common\model\datas\Poscount; $fieldstr = 'create_date,postcode,sum(count) as count'; $userid = $this->auth->id; $userStoreModel = new \app\common\model\UserStore; $Warestoress = []; if($this->auth->check("isstaff")){ if($storeid!=0){ $orderquery = $OrderModel->where(["STOREID"=>$storeid]); }else{ $orderquery = $OrderModel->where(["WAREHOUSEID"=>$WAREHOUSEID]); } }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); $storeids = []; foreach ($stores as $r){ array_push($storeids,$r["store_id"]); } if($storeid!=0){ $storeids = array_intersect([$storeid],$storeids); } $orderquery = $OrderModel->where("STOREID",'in',$storeids); } $orderquery->field(rtrim($fieldstr, ','))->where('create_date','BETWEEN',[strtotime($start),strtotime($end)])->group('create_date,postcode'); $list = $orderquery->select(); $postcodes = []; foreach($list as $r){ $has = false; $r['POSTNAME']=$this->pcodes[$r['postcode']]; foreach ($postcodes as $k => $rr){ if($rr["POSTCODE"]==$r["postcode"]){ $postcodes[$k]['t'.$r['create_date']] = $r['count']; $has = true; } } if(!$has){ $tmp = ["POSTCODE"=>$r["postcode"],"POSTNAME"=>$r["POSTNAME"]]; foreach ($co as $m){ $tmp['t'.$m['date']] = "0"; } $tmp['t'.$r['create_date']] = $r['count']; array_push($postcodes,$tmp); } } $this->success('成功',$postcodes); } public function order_structure(){ $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $start = $params['start']; $storeid = $params['storeid']; $end = $params['end']; $OrderModel = new \app\common\model\datas\Orderstructure; $userid = $this->auth->id; $userStoreModel = new \app\common\model\UserStore; $fieldstr = 'create_date,w1,w2'; if($this->auth->check("isstaff")){ if($storeid!=0){ $orderquery = $OrderModel->where(["STOREID"=>$storeid]); }else{ $orderquery = $OrderModel->where(["WAREHOUSEID"=>$WAREHOUSEID]); } }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); $storeids = []; foreach ($stores as $r){ array_push($storeids,$r["store_id"]); } if($storeid!=0){ $storeids = array_intersect([$storeid],$storeids); } $orderquery = $OrderModel->where("STOREID",'in',$storeids); } $orderquery->field(rtrim($fieldstr, ','))->where('create_date','BETWEEN',[strtotime($start),strtotime($end)]); $list = $orderquery->select(); $postcodes = []; foreach($list as $r){ $has = false; $weights = json_decode($r['w1'],true); $weights2 = json_decode($r['w2'],true); foreach ($postcodes as $k => $rr){ if($rr["create_date"]==$r["create_date"]){ $has = true; $postcodes[$k]["ITEMS_1"] += ($weights["w1"] ?? null); $postcodes[$k]["ITEMS_2_3"]+= $weights["w2"]; $postcodes[$k]["ITEMS_3_5"]+= $weights["w3"]; $postcodes[$k]["ITEMS_qt_5"]+= $weights["w4"]; $postcodes[$k]["GOODSCOUNT_1"] += ($weights2["w1"] ?? null); $postcodes[$k]["GOODSCOUNT_2_3"]+= $weights2["w2"]; $postcodes[$k]["GOODSCOUNT_3_5"]+= $weights2["w3"]; $postcodes[$k]["GOODSCOUNT_qt_5"]+= $weights2["w4"]; } } if(!$has){ $tmp = ["create_date"=>$r["create_date"],"date_field"=>date("Y-m-d", $r["create_date"])]; $tmp["ITEMS_1"] = $weights["w1"]; $tmp["ITEMS_2_3"]= $weights["w2"]; $tmp["ITEMS_3_5"]= $weights["w3"]; $tmp["ITEMS_qt_5"]= $weights["w4"]; $tmp["GOODSCOUNT_1"] = $weights2["w1"]; $tmp["GOODSCOUNT_2_3"]= $weights2["w2"]; $tmp["GOODSCOUNT_3_5"]= $weights2["w3"]; $tmp["GOODSCOUNT_qt_5"]= $weights2["w4"]; array_push($postcodes,$tmp); } } $this->success('成功',$postcodes); } public function mystockout(){ $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $start = $params['start']; $storeid = $params['storeid']; $end = $params['end']; $orderType = isset($params['orderType'])?$params['orderType']:1; $OrderModel = new \app\common\model\datas\Ordercombo; $userid = $this->auth->id; $userStoreModel = new \app\common\model\UserStore; $fieldstr = 'ITEMS,sum(count) as COUNT,STOCKS'; if($this->auth->check("isstaff")){ if($storeid!=0){ $orderquery = $OrderModel->where(["STOREID"=>$storeid]); }else{ $orderquery = $OrderModel->where(["WAREHOUSEID"=>$WAREHOUSEID]); } }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); $storeids = []; foreach ($stores as $r){ array_push($storeids,$r["store_id"]); } if($storeid!=0){ $storeids = array_intersect([$storeid],$storeids); } $orderquery = $OrderModel->where("STOREID",'in',$storeids); } $orderquery->field(rtrim($fieldstr, ','))->where('create_date','BETWEEN',[strtotime($start),strtotime($end)])->group("STOCKS")->order('COUNT','desc'); $list = $orderquery->select(); $stocks = []; foreach ($list as $r){ $itemsArr = array_filter(explode("|",$r["ITEMS"]),'trim'); foreach ($itemsArr as $rr){ $item = explode(",",$rr); if(array_key_exists($item[0], $stocks)){ $stocks[$item[0]]["count"] += (intval($item[1])*$r["COUNT"]); $stocks[$item[0]]["count2"] +=$r["COUNT"]; }else{ $stocks[$item[0]] = [ "count"=>(intval($item[1])*$r["COUNT"]), "count2"=>$r["COUNT"], "NAME"=>$item[2].$item[3] ]; } } } $stocks_list = []; foreach ($stocks as $k => $r){ array_push($stocks_list,["NAME"=>$r["NAME"],"count"=>$r["count"],"count2"=>$r["count2"]]); } if($orderType==1){ usort($stocks_list, function($a, $b) { return $b['count'] - $a['count']; }); }else{ usort($stocks_list, function($a, $b) { return $b['count2'] - $a['count2']; }); } $this->success('成功',$stocks_list); } public function order_combo(){ $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $start = $params['start']; $storeid = $params['storeid']; $end = $params['end']; $OrderModel = new \app\common\model\datas\Ordercombo; $userid = $this->auth->id; $userStoreModel = new \app\common\model\UserStore; $fieldstr = 'ITEMS,sum(count) as COUNT,STOCKS'; if($this->auth->check("isstaff")){ if($storeid!=0){ $orderquery = $OrderModel->where(["STOREID"=>$storeid]); }else{ $orderquery = $OrderModel->where(["WAREHOUSEID"=>$WAREHOUSEID]); } }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); $storeids = []; foreach ($stores as $r){ array_push($storeids,$r["store_id"]); } if($storeid!=0){ $storeids = array_intersect([$storeid],$storeids); } $orderquery = $OrderModel->where("STOREID",'in',$storeids); } $orderquery->field(rtrim($fieldstr, ','))->where('create_date','BETWEEN',[strtotime($start),strtotime($end)])->group("STOCKS")->order('COUNT','desc'); $list = $orderquery->select(); foreach ($list as $k => $r){ $list[$k]["COUNT"] = intval($r["COUNT"]); } usort($list, function($a, $b) { return $b['COUNT'] - $a['COUNT']; }); $postcodes = []; $this->success('成功',$list); } public function order_combo_export(){ $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $WAREHOUSEID = $this->auth->warehouseid; $start=$this->request->get('start'); $storeid=$this->request->get('storeid'); $end=$this->request->get('end'); $co = $this->getDailyStartTimestamps(strtotime($start),strtotime($end)); $OrderModel = new \app\common\model\wms\Deliveryorder; $STORESModel = new \app\common\model\wms\Store; $STORES = $STORESModel->field('STOREID,TITLE')->select(); $fieldstr = ' count(*) as COUNT, POSTNUM, ITEMS, STOREID '; $userid = $this->auth->id; $userStoreModel = new \app\common\model\UserStore; $Warestoress = []; if($this->auth->check("isstaff")){ if($storeid!=0){ $orderquery = $OrderModel->where(["STOREID"=>$storeid]); }else{ $orderquery = $OrderModel->where(["WAREHOUSEID"=>$WAREHOUSEID]); } }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); $storeids = []; foreach ($stores as $r){ array_push($storeids,$r["store_id"]); } if($storeid!=0){ $storeids = array_intersect([$storeid],$storeids); } $orderquery = $OrderModel->where("STOREID",'in',$storeids); } $orderquery->field(rtrim($fieldstr, ','))->where(["STATUS"=>4, "DISPLAYFLAG"=>0])->where('SENDDATE','BETWEEN',['00'.strtotime($start).'000','00'.(strtotime($end) + 86399).'000'])->group('ITEMS')->order('COUNT DESC'); $list = $orderquery->select(); $title = '历史订单结构'; $worksheet->setTitle($title); $worksheet->fromArray( [ ['组合','订单数量','货主'] ], '', 'A1' ); $lists = []; foreach ($list as $r){ $tmp_items = explode('|',$r['ITEMS']); $tmp_items = array_filter($tmp_items); $ITEMSS = []; $COUNT = intval($r['COUNT']); $STORENAME = ''; foreach ($STORES as $rr){ if($r['STOREID']==$rr["STOREID"]){ $STORENAME = $rr['TITLE']; } } foreach($tmp_items as $rr){ $tmp_infos = explode(',',$rr); array_push($ITEMSS,$tmp_infos[3].'('.$tmp_infos[1].')'); } $ITEMSS = implode("\r\n",$ITEMSS); array_push($lists,[$ITEMSS,$COUNT,$STORENAME]); } $worksheet->fromArray( $lists, '', 'A2' ); header('Content-Disposition: attachment;filename=order_combo_export.xlsx'); header('Cache-Control: max-age=0'); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); $write = IOFactory::createWriter($spreadsheet, 'Xlsx'); $write->save('php://output'); exit(); } public function clock_in(){ $clockinModel = new \app\common\model\workers\clock\In; $UserModel = new \app\common\model\User; $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $start = $params['start']; $end = $params['end']; $zhongjie = $params['zhongjie']; if($zhongjie!="全部"){ $clockinModel->where(["zhongjie"=>$zhongjie]); } $list = $clockinModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->with(['name'])->where('workDate','BETWEEN',[strtotime($start),strtotime($end) + 86399])->order("workDate,userid,zhongjie","desc")->select(); $zhongjieList = $UserModel->field("zhongjie,Max(id) as id,count(*) as count")->where(["WAREHOUSEID"=>$WAREHOUSEID])->group("zhongjie")->select(); foreach ($list as $r){ $rest = 0; $restTime1 = strtotime(date('Y-m-d', $r['stime'])) + 43200; $restTime2 = strtotime(date('Y-m-d', $r['stime'])) + 64800; if($r['xtime']>=$restTime1+3600 && $r['stime']<=$restTime1){ $rest++; } if($r['xtime']>=$restTime2+3600 && $r['stime']<=$restTime2){ $rest+=0.5; } $r['rest'] = $rest; if($r['xtime']){ $r['workingHours'] = number_format((($r['xtime'] - $r['stime'])/3600-$r['rest']),2); $r['endtimestr'] = date('H:i', $r['xtime']); }else{ $r['workingHours'] = '-'; } $r['print'] = 0.00; if($r['wages'] && $r['workingHours']!='-'){ $r['print'] = number_format((float)$r['workingHours']*(float)$r['wages'],2); } $r['createtimestr'] = date('H:i', $r['stime']); } $this->success('获取成功',["list"=>$list,"zhongjieList"=>$zhongjieList]); } public function clock_in_edit(){ $params=$this->request->post(); $WAREHOUSEID = $this->auth->warehouseid; $clockinModel = new \app\common\model\workers\clock\In; $clockin = $clockinModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"id"=>$params['data']['id']])->find(); if($clockin){ $params['data']['stime'] = isset($params['data']['stime'])?strtotime(date('Y-m-d ', $clockin['workDate']).$params['data']['stime']):null; $params['data']['xtime'] = isset($params['data']['xtime'])?strtotime(date('Y-m-d ', $clockin['workDate']).$params['data']['xtime']):null; $params['data']['xtime'] = $params['data']['xtime']&&$params['data']['xtime']<$clockin['stime']?$params['data']['xtime']+86400:$params['data']['xtime']; foreach ($params['data'] as $k =>$r){ if(!$r){ unset($params['data'][$k]); } } if(isset($params['data']['changeUser'])){ $userModel = new \app\common\model\User; $user = $userModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"id"=>$clockin->userid])->find(); if(!$user){ $this->error('用户不存在'); } if(isset($params['data']['wages'])){ $user->save(["wages"=>(float)$params['data']['wages']]); } if(isset($params['data']['zhongjie'])){ $user->save(["zhongjie"=>$params['data']['zhongjie']]); } unset($params['data']['changeUser']); } //print_r($params); $status = $clockin->save($params['data']); $this->success('保存成功',$params); } } public function clockin_zhongjie(){ $params=$this->request->post(); $start = $params['start']; $WAREHOUSEID = $this->auth->warehouseid; $end = $params['end']; $zhongjie = $this->auth->zhongjie; $clockinModel = new \app\common\model\workers\clock\In; $list = $clockinModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"zhongjie"=>$zhongjie])->where('workDate','BETWEEN',[strtotime($start),strtotime($end) + 86399])->with(['name'])->select(); foreach ($list as $r){ $rest = 0; $restTime1 = strtotime(date('Y-m-d', $r['stime'])) + 43200; $restTime2 = strtotime(date('Y-m-d', $r['stime'])) + 64800; if($r['xtime']>$restTime1+3600 && $r['stime']<$restTime1){ $rest++; } if($r['xtime']>$restTime2+3600 && $r['stime']<$restTime2){ $rest++; } $r['rest'] = $rest; if($r['xtime']){ $r['workingHours'] = number_format((($r['xtime'] - $r['stime'])/3600-$r['rest']),2); $r['endtimestr'] = date('H:i', $r['xtime']); }else{ $r['workingHours'] = '-'; } $r['print'] = 0.00; if($r['wages'] && $r['workingHours']!='-'){ $r['print'] = number_format((float)$r['workingHours']*(float)$r['wages'],2); } $r['createtimestr'] = date('H:i', $r['stime']); } $this->success('获取成功',$list); } public function clockin_zhongjie_export(){ $workDate = $this->request->get('workDate'); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $params=$this->request->post(); $start = $params['start']; $WAREHOUSEID = $this->auth->warehouseid; $end = $params['end']; $zhongjie = $this->auth->zhongjie; $clockinModel = new \app\common\model\workers\clock\In; $title = '员工上班概况导出'; $worksheet->setTitle($title); $worksheet->fromArray( [ ['上班日期','姓名','上班时间','上班打卡时间','下班时间','下班打卡时间','休息时间(小时)','工时','工价','应付'] ], '', 'A1' ); $list = $clockinModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"zhongjie"=>$zhongjie])->where('workDate','BETWEEN',[strtotime($start),strtotime($end) + 86399])->with(['name'])->select(); $workers = []; foreach ($list as $r){ $rest = 0; $restTime1 = strtotime(date('Y-m-d', $r['stime'])) + 43200; $restTime2 = strtotime(date('Y-m-d', $r['stime'])) + 64800; if($r['xtime']>$restTime1+3600 && $r['stime']<$restTime1){ $rest++; } if($r['xtime']>$restTime2+3600 && $r['stime']<$restTime2){ $rest++; } $r['rest'] = $rest; $endtimestr=""; $endtimestr2=""; if($r['xtime']){ $workingHours = number_format((($r['xtime'] - $r['stime'])/3600-$r['rest']),2); $endtimestr = date('H:i', $r['xtime']); $endtimestr2 = date('Y-m-d H:i:s', $r['endtime']); }else{ $workingHours = ''; } $print = 0.00; if($r['wages'] && $workingHours!=''){ $print = number_format((float)$workingHours*(float)$r['wages'],2); } $createtimestr = date('H:i', $r['stime']); array_push($workers,[date('Y-m-d', $r['workDate']),$r['name']['real_name'],$createtimestr,date('Y-m-d H:i:s', $r['createtime']),$endtimestr,$endtimestr2,$rest,$workingHours,$r['wages'],$print]); } $worksheet->fromArray( $workers, '', 'A2' ); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename=Excel导出.xlsx'); header('Cache-Control: max-age=0'); $write = IOFactory::createWriter($spreadsheet, 'Xlsx'); $write->save('php://output'); } public function clockin_export(){ $workDate = $this->request->get('workDate'); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $clockinModel = new \app\common\model\workers\clock\In; $UserModel = new \app\common\model\User; $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $start = $params['start']; $end = $params['end']; $zhongjie = $params['zhongjie']; if($zhongjie!="全部"){ $clockinModel->where(["zhongjie"=>$zhongjie]); } $title = '员工上班概况'; $worksheet->setTitle($title); $worksheet->fromArray( [ ['上班日期','姓名','中介','上班时间','上班打卡时间','下班时间','下班打卡时间','休息时间(小时)','工时','工价','应付'] ], '', 'A1' ); $list = $clockinModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->with(['name'])->where('workDate','BETWEEN',[strtotime($start),strtotime($end) + 86399])->order("workDate,userid,zhongjie","desc")->select(); $workers = []; foreach ($list as $r){ $rest = 0; $restTime1 = strtotime(date('Y-m-d', $r['stime'])) + 43200; $restTime2 = strtotime(date('Y-m-d', $r['stime'])) + 64800; if($r['xtime']>$restTime1+3600 && $r['stime']<$restTime1){ $rest++; } if($r['xtime']>$restTime2+3600 && $r['stime']<$restTime2){ $rest++; } $r['rest'] = $rest; $endtimestr=""; $endtimestr2=""; if($r['xtime']){ $workingHours = number_format((($r['xtime'] - $r['stime'])/3600-$r['rest']),2); $endtimestr = date('Y-m-d H:i:s', $r['xtime']); $endtimestr2 = date('Y-m-d H:i:s', $r['endtime']); }else{ $workingHours = ''; } $print = 0.00; if($r['wages'] && $workingHours!=''){ $print = number_format((float)$workingHours*(float)$r['wages'],2); } $createtimestr = date('Y-m-d H:i:s', $r['stime']); array_push($workers,[date('Y-m-d', $r['workDate']),$r['name']['real_name'],$r['zhongjie'],$createtimestr,date('Y-m-d H:i:s', $r['createtime']),$endtimestr,$endtimestr2,$rest,$workingHours,$r['wages'],$print]); } $worksheet->fromArray( $workers, '', 'A2' ); $zj_list = []; foreach($list as $r){ if(!in_array($r['zhongjie'],$zj_list)){ array_push($zj_list,$r['zhongjie']); } } foreach ($zj_list as $r){ $tmpworksheet = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, $r); $spreadsheet->addSheet($tmpworksheet); $tmpworksheet->fromArray( [ ['上班日期','姓名','上班时间','上班打卡时间','下班时间','下班打卡时间','休息时间(小时)','工时','工价','应付'] ], '', 'A1' ); $works = []; foreach($list as $rr){ if($rr['zhongjie']==$r){ $rest = 0; $restTime1 = strtotime(date('Y-m-d', $rr['stime'])) + 43200; $restTime2 = strtotime(date('Y-m-d', $rr['stime'])) + 64800; if($rr['xtime']>$restTime1+3600 && $rr['stime']<$restTime1){ $rest++; } if($rr['xtime']>$restTime2+3600 && $rr['stime']<$restTime2){ $rest++; } $rr['rest'] = $rest; $endtimestr=""; $endtimestr2=""; if($rr['xtime']){ $workingHours = number_format((($rr['xtime'] - $rr['stime'])/3600-$rr['rest']),2); $endtimestr = date('Y-m-d H:i:s', $rr['xtime']); $endtimestr2 = date('Y-m-d H:i:s', $rr['endtime']); }else{ $workingHours = ''; } $print = 0.00; if($rr['wages'] && $workingHours!=''){ $print = number_format((float)$workingHours*(float)$rr['wages'],2); } $createtimestr = date('Y-m-d H:i:s', $rr['stime']); array_push($works,[date('Y-m-d', $rr['workDate']),$rr['name']['real_name'],$createtimestr,date('Y-m-d H:i:s', $rr['createtime']),$endtimestr,$endtimestr2,$rest,$workingHours,$rr['wages'],$print]); } } $tmpworksheet->fromArray( $works, '', 'A2' ); } header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename=Excel导出.xlsx'); header('Cache-Control: max-age=0'); $write = IOFactory::createWriter($spreadsheet, 'Xlsx'); $write->save('php://output'); } public function sale(){ $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $storeid = $params["storeid"]; $userid = $this->auth->id; $OrderModel = new \app\common\model\wms\Order; $userStoreModel = new \app\common\model\UserStore; $WarestoreModel = new \app\common\model\wms\Warestore; $Warestoress = []; if($this->auth->check("isstaff")){ if($storeid!=0){ $orderquery = $OrderModel->where(["STOREID"=>$storeid]); }else{ $orderquery = $OrderModel->where(["WAREHOUSEID"=>$WAREHOUSEID]); } }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); $storeids = []; foreach ($stores as $r){ array_push($storeids,$r["store_id"]); } if($storeid!=0){ $storeids = array_intersect([$storeid],$storeids); } $orderquery = $OrderModel->where("STOREID",'in',$storeids); } $orderquery->field('PROVINCE,POSTNAME,SENDDATE+0 as SENDDATE,CREATIONDATE+0 as CREATIONDATE,JDFLAG,WEIGHT,ORDERWEIGHT,GOODSCOUNT,GRABNUM')->where(["FLAG"=>0])->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000); $datas = $orderquery->select(); foreach($datas as $r){ if($r['WEIGHT']==0){ $r['WEIGHT'] = $r['ORDERWEIGHT']; } unset($r['ORDERWEIGHT']); } $this->success("获取成功",$datas); } public function sale2(){ $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $storeid = $params["storeid"]; //结构 $OrderModel = new \app\common\model\wms\Order; $userid = $this->auth->id; $userStoreModel = new \app\common\model\UserStore; $WarestoreModel = new \app\common\model\wms\Warestore; $Warestoress = []; if($this->auth->check("isstaff")){ if($storeid!=0){ $orderquery = $OrderModel->where(["STOREID"=>$storeid]); }else{ $orderquery = $OrderModel->where(["WAREHOUSEID"=>$WAREHOUSEID]); } }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); $storeids = []; foreach ($stores as $r){ array_push($storeids,$r["store_id"]); } if($storeid!=0){ $storeids = array_intersect([$storeid],$storeids); } $orderquery = $OrderModel->where("STOREID",'in',$storeids); } $orderquery->field('ITEMS,count(*) as count')->where(["FLAG"=>0])->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000); $datas = $orderquery->group('ITEMS')->order('count','desc')->limit(10)->select(); //动销 if($this->auth->check("isstaff")){ if($storeid!=0){ $orderquery2 = $OrderModel->where(["STOREID"=>$storeid]); }else{ $orderquery2 = $OrderModel->where(["WAREHOUSEID"=>$WAREHOUSEID]); } }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); $storeids = []; foreach ($stores as $r){ array_push($storeids,$r["store_id"]); } if($storeid!=0){ $storeids = array_intersect([$storeid],$storeids); } $orderquery2 = $OrderModel->where("STOREID",'in',$storeids); } $orderquery2->field('ID')->where(["FLAG"=>0])->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000); $IDS = $orderquery2->select(); $IDSS = []; foreach($IDS as $r){ array_push($IDSS,$r['ID']); } $OrderModel = new \app\common\model\wms\Picking; $datas2 = $OrderModel->field("DETAILS,sum(COUNT) as COUNT")->where("WMSORDERID","in",$IDSS)->group("STOCKID")->order("COUNT","desc")->limit(10)->select(); $this->success("获取成功",["jiegou"=>$datas,"dongxiao"=>$datas2]); } private function getDailyStartTimestamps($startTime, $endTime) { // 将结束时间戳转为第二天开始时间戳 $endTime = strtotime(date('Y-m-d', $endTime)) + 86400; // 计算时间戳差值 $diff = $endTime - $startTime; // 计算天数 $days = ceil($diff / 86400); // ������开始时间戳以天为数组 $timestamps = []; for ($i = 0; $i < $days; $i++) { $timestamps[]['date'] = $startTime + $i * 86400; } return $timestamps; } public function mystock(){ $stockModel = new \app\common\model\wms\Stock; $StockImgsModel = new \app\common\model\wms\StockImgs; $StockBoxsModel = new \app\common\model\wms\StockBoxs; header("Cache-Control: no-cache, no-store, must-revalidate"); header("Pragma: no-cache"); header("Expires: 0"); $errors = ""; $list = []; $count = 0; $params = []; try { $params=$this->request->post(); $page = isset($params["pages"])?$params["pages"]:1; $storeid = $params["storeid"]; $keyword = isset($params['keyword'])?$params['keyword']:''; $WAREHOUSEID = $this->auth->warehouseid; $userid = $this->auth->id; $logModel = new \app\common\model\method\Log; $userStoreModel = new \app\common\model\UserStore; $WarestoreModel = new \app\common\model\wms\Warestore; $OrderModel = new \app\common\model\wms\Order; $order = $OrderModel->where(["POSTNUM"=>$keyword,"WAREHOUSEID"=>$WAREHOUSEID])->find(); $Warestoress = []; if($this->auth->check("isstaff")){ if($storeid!=0){ $Warestores = $WarestoreModel->where(["STOREID"=>$storeid,"WAREHOUSEID"=>$WAREHOUSEID])->select(); }else{ $Warestores = $WarestoreModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select(); } }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); $storeids = []; foreach ($stores as $r){ array_push($storeids,$r["store_id"]); } if($storeid!=0){ $storeids = array_intersect([$storeid],$storeids); } $Warestores = $WarestoreModel->where("STOREID","in",$storeids)->select(); } foreach ($Warestores as $r){ array_push($Warestoress,$r["ID"]); } if(!$Warestores){ $this->success("获取成功",["list"=>[],"count"=>0]); } $stockModel = new \app\common\model\wms\Stock; $query = $stockModel->alias("stock") ->field(" stock.BARCODE as BARCODE, stock.IMG as IMG, goods.NAME as NAME, stock.STOCKID as STOCKID, stock.WEIGHT as WEIGHT, stock.YXQ as YXQ, (COALESCE(storage_total.copycount, 0) - COALESCE(wmsitem_total.count_sum, 0)) as DISPLAYCOUNT ") ->where("stock.WARESTOREID", "in", $Warestoress) ->join('yj_goods goods', 'stock.GOODSID = goods.GOODSID') // 添加 storage 子查询 ->join('(SELECT STOCKID, SUM(COUNT) as copycount FROM yj_storage GROUP BY STOCKID) storage_total', 'stock.STOCKID = storage_total.STOCKID', 'LEFT') // 添加 wmsitem 子查询 ->join('(SELECT wmsitem.STOCKID, SUM(wmsitem.COUNT) as count_sum FROM yj_wmsitem wmsitem INNER JOIN yj_wmsorder wmsorder ON wmsitem.WMSORDERID = wmsorder.ID WHERE wmsitem.DISPLAYFLAG = 0 GROUP BY wmsitem.STOCKID) wmsitem_total', 'stock.STOCKID = wmsitem_total.STOCKID', 'LEFT') ->order("stock.STOCKID", "desc"); if ($keyword) { $query->where('stock.BARCODE like "%'.$keyword.'%" or goods.NAME like "%'.$keyword.'%"'); } $list = $query->limit(($page-1)*50, 50)->select(); $STOCKS = []; foreach($list as $r){ array_push($STOCKS,$r["STOCKID"]); } $imgs = $StockImgsModel->where("stock_id","in",$STOCKS)->select(); $boxs = $StockBoxsModel->where("stock_id","in",$STOCKS)->select(); foreach ($list as $r){ $imgs_temp = []; foreach ($imgs as $img){ if($img->stock_id==$r["STOCKID"]){ array_push($imgs_temp,$img['url']); } } $r['IMGS'] = $imgs_temp; } foreach ($list as $r){ $boxs_temp = [ "large"=>[ "count"=>0, "length"=>0, "width"=>0, "height"=>0 ], "medium"=>[ "count"=>0, "length"=>0, "width"=>0, "height"=>0 ], ]; foreach ($boxs as $box){ if($box->stock_id==$r["STOCKID"]){ $boxs_temp[$box->type] = [ "count"=>$box->count, "length"=>$box->length, "width"=>$box->width, "height"=>$box->height ]; } } $r['boxs'] = $boxs_temp; } $query2 = $stockModel->alias("stock") ->join('yj_goods goods', 'stock.GOODSID = goods.GOODSID') ->where("WARESTOREID","in",$Warestoress); if($keyword){ $query2->where('stock.BARCODE like "%'.$keyword.'%" or goods.NAME like "%'.$keyword.'%"'); } $count = $query2->count(); } catch (Exception $e) { $errors = $e; } $log_data = [ "method"=>"mystock", "time"=>time(), "userid"=>$userid, "query"=>json_encode($params), "result"=>json_encode(["list"=>$list,"count"=>$count]), "errors"=>$errors ]; $logModel->save($log_data); $this->success("获取成功",["list"=>$list,"count"=>$count,"isstaff"=>$this->auth->check("isstaff")]); } public function mystock2(){ header("Cache-Control: no-cache, no-store, must-revalidate"); header("Pragma: no-cache"); header("Expires: 0"); $errors = ""; $list = []; $count = 0; $params = []; try { $params=$this->request->post(); $page = isset($params["pages"])?$params["pages"]:1; $storeid = $params["storeid"]; $keyword = isset($params['keyword'])?$params['keyword']:''; $WAREHOUSEID = $this->auth->warehouseid; $userid = $this->auth->id; $logModel = new \app\common\model\method\Log; $userStoreModel = new \app\common\model\UserStore; $WarestoreModel = new \app\common\model\wms\Warestore; $OrderModel = new \app\common\model\wms\Order; $order = $OrderModel->where(["POSTNUM"=>$keyword,"WAREHOUSEID"=>$WAREHOUSEID])->find(); $Warestoress = []; if($this->auth->check("isstaff")){ if($storeid!=0){ $Warestores = $WarestoreModel->where(["STOREID"=>$storeid,"WAREHOUSEID"=>$WAREHOUSEID])->select(); }else{ $Warestores = $WarestoreModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select(); } }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); $storeids = []; foreach ($stores as $r){ array_push($storeids,$r["store_id"]); } if($storeid!=0){ $storeids = array_intersect([$storeid],$storeids); } $Warestores = $WarestoreModel->where("STOREID","in",$storeids)->select(); } foreach ($Warestores as $r){ array_push($Warestoress,$r["ID"]); } if(!$Warestores){ $this->success("获取成功",["list"=>[],"count"=>0]); } $stockModel = new \app\common\model\wms\Stock; $StockImgsModel = new \app\common\model\wms\StockImgs; $StockBoxsModel = new \app\common\model\wms\StockBoxs; $field = " stock.BARCODE as BARCODE, stock.IMG as IMG, goods.NAME as NAME, stock.SKU as SKU, stock.STYLE as STYLE, stock.PRICE2 as price2, stock.PRICE3 as price3, stock.STOCKID as STOCKID, stock.WEIGHT as WEIGHT, stock.YXQ as YXQ, (COALESCE(storage_total.copycount, 0) - COALESCE(wmsitem_total.count_sum, 0)) as DISPLAYCOUNT "; if($this->auth->check("isboss")||$this->auth->check("isstaff")){ $field = " stock.BARCODE as BARCODE, stock.IMG as IMG, goods.NAME as NAME, stock.SKU as SKU, stock.STYLE as STYLE, stock.PRICE1 as price1, stock.PRICE2 as price2, stock.PRICE3 as price3, stock.STOCKID as STOCKID, stock.WEIGHT as WEIGHT, stock.YXQ as YXQ, (COALESCE(storage_total.copycount, 0) - COALESCE(wmsitem_total.count_sum, 0)) as DISPLAYCOUNT "; } $query = $stockModel->alias("stock") ->field($field) ->where("stock.WARESTOREID", "in", $Warestoress) ->join('yj_goods goods', 'stock.GOODSID = goods.GOODSID') // 添加 storage 子查询 ->join('(SELECT STOCKID, SUM(COUNT) as copycount FROM yj_storage GROUP BY STOCKID) storage_total', 'stock.STOCKID = storage_total.STOCKID', 'LEFT') // 添加 wmsitem 子查询 ->join('(SELECT wmsitem.STOCKID, SUM(wmsitem.COUNT) as count_sum FROM yj_wmsitem wmsitem INNER JOIN yj_wmsorder wmsorder ON wmsitem.WMSORDERID = wmsorder.ID WHERE wmsitem.DISPLAYFLAG = 0 GROUP BY wmsitem.STOCKID) wmsitem_total', 'stock.STOCKID = wmsitem_total.STOCKID', 'LEFT') ->order("stock.STOCKID", "desc"); if ($keyword) { $query->where('stock.BARCODE like "%'.$keyword.'%" or goods.NAME like "%'.$keyword.'%"'); } $list = $query->limit(($page-1)*50, 50)->select(); $STOCKS = []; foreach($list as $r){ array_push($STOCKS,$r["STOCKID"]); } $imgs = $StockImgsModel->where("stock_id","in",$STOCKS)->select(); $boxs = $StockBoxsModel->where("stock_id","in",$STOCKS)->select(); foreach ($list as $r){ $imgs_temp = []; foreach ($imgs as $img){ if($img->stock_id==$r["STOCKID"]){ array_push($imgs_temp,$img['url']); } } $r['IMGS'] = $imgs_temp; } foreach ($list as $r){ $boxs_temp = [ "large"=>[ "count"=>0, "length"=>0, "width"=>0, "height"=>0 ], "medium"=>[ "count"=>0, "length"=>0, "width"=>0, "height"=>0 ], ]; foreach ($boxs as $box){ if($box->stock_id==$r["STOCKID"]){ $boxs_temp[$box->type] = [ "count"=>$box->count, "length"=>$box->length, "width"=>$box->width, "height"=>$box->height ]; } } $r['boxs'] = $boxs_temp; } $query2 = $stockModel->alias("stock") ->join('yj_goods goods', 'stock.GOODSID = goods.GOODSID') ->where("WARESTOREID","in",$Warestoress); if($keyword){ $query2->where('stock.BARCODE like "%'.$keyword.'%" or goods.NAME like "%'.$keyword.'%"'); } $count = $query2->count(); $query3 = $stockModel->alias("stock") ->field("sum((COALESCE(storage_total.copycount, 0) - COALESCE(wmsitem_total.count_sum, 0))) as zkc,sum((COALESCE(storage_total.copycount, 0) - COALESCE(wmsitem_total.count_sum, 0))*stock.PRICE1) as zcb") ->join('yj_goods goods', 'stock.GOODSID = goods.GOODSID') ->join('(SELECT STOCKID, SUM(COUNT) as copycount FROM yj_storage GROUP BY STOCKID) storage_total', 'stock.STOCKID = storage_total.STOCKID', 'LEFT') ->join('(SELECT wmsitem.STOCKID, SUM(wmsitem.COUNT) as count_sum FROM yj_wmsitem wmsitem INNER JOIN yj_wmsorder wmsorder ON wmsitem.WMSORDERID = wmsorder.ID WHERE wmsitem.DISPLAYFLAG = 0 GROUP BY wmsitem.STOCKID) wmsitem_total', 'stock.STOCKID = wmsitem_total.STOCKID', 'LEFT') ->where("WARESTOREID","in",$Warestoress); if($keyword){ $query3->where('stock.BARCODE like "%'.$keyword.'%" or goods.NAME like "%'.$keyword.'%"'); } [$count2] = $query3->select(); $query4 = $stockModel->alias("stock") ->field("count(*) as wsz") ->join('yj_goods goods', 'stock.GOODSID = goods.GOODSID') ->where("WARESTOREID","in",$Warestoress) ->where("stock.PRICE1 is null"); if($keyword){ $query4->where('stock.BARCODE like "%'.$keyword.'%" or goods.NAME like "%'.$keyword.'%"'); } $count3 = $query4->count(); } catch (Exception $e) { $errors = $e; } $log_data = [ "method"=>"mystock", "time"=>time(), "userid"=>$userid, "query"=>json_encode($params), "result"=>json_encode(["list"=>$list,"count"=>$count]), "errors"=>$errors ]; $logModel->save($log_data); $this->success("获取成功",["list"=>$list,"count"=>$count,"count2"=>$count2['zkc'],"count3"=>$count2['zcb'],"count4"=>$count3]); } public function getStock(){ $params=$this->request->post(); $STOCKID = $params["STOCKID"]; $stockModel = new \app\common\model\wms\Stock; $StorageModel = new \app\common\model\wms\Storage; $datas = $StorageModel->alias("storage") ->field("space.CUSTOMNUM") ->where(["STOCKID"=>$STOCKID]) ->join('yj_space space', 'storage.SPACEID = space.ID') ->select(); $this->success("获取成功",["list"=>$datas]); } public function uploadStockImg(){ $result = Http::get('http://ye4s.com/util/uploadStockImg.jsp'); preg_match("/form1.([a-zA-Z0-9]+);/", $result, $matches); $str = isset($matches[1])?$matches[1]:''; $file = $this->request->file('file'); // 构建请求参数 $parameters = [ 'picname' => $str, 'status' => 'save', 'forward' => 'util/uploadStockImg.jsp' ]; $fileinfo = $file->getInfo(); $fileName = $fileinfo['name']; $fileTmpPath = $file->getRealPath(); // 创建一个新的CURL资源 $curl = curl_init(); $fields = array_merge($parameters, [ $str => new \CURLFile($fileTmpPath, '', $fileName) ]); // 设置CURL选项 curl_setopt_array($curl, [ CURLOPT_URL => 'http://ye4s.com/multipartformserv', CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $fields, ]); // 发送请求并获取响应 $response = curl_exec($curl); // 关闭CURL资源 curl_close($curl); preg_match('/onclick="selectpic\(\'(.*?)\'\)/', $response, $matches); $this->success("获取成功",["imgurl"=>$matches[1],"str"=>$str]); } public function updatePrice(){ if($this->auth->check("isboss")||$this->auth->check("isstaff")){ $datas = $params=$this->request->post(); $stockModel = new \app\common\model\wms\Stock; $price1 = preg_match('/^\d+(\.\d{1,2})?$/', $datas['data']['price1']) ? $datas['data']['price1'] : ''; $price2 = preg_match('/^\d+(\.\d{1,2})?$/', $datas['data']['price2']) ? $datas['data']['price2'] : ''; $price3 = preg_match('/^\d+(\.\d{1,2})?$/', $datas['data']['price3']) ? $datas['data']['price3'] : ''; $stockModel = new \app\common\model\wms\Stock; $data = $stockModel ->where(["STOCKID"=>intval($datas['data']['stockId'])])->find(); if($data){ $data->PRICE1 = $price1; $data->PRICE2 = $price2; $data->PRICE3 = $price3; $data->save(); $this->success('保存成功',$data); }else{ $this->error('无相关商品'); } }else{ $this->error('无权限设置'); } } public function updateStock(){ $datas = $params=$this->request->post(); $stockModel = new \app\common\model\wms\Stock; $StockImgsModel = new \app\common\model\wms\StockImgs; $StockBoxsModel = new \app\common\model\wms\StockBoxs; $imgs = isset($params["imgs"])?$params["imgs"]:[]; $defaultBox = [ "large"=>[ "count"=>0, "length"=>0, "width"=>0, "height"=>0 ], "medium"=>[ "count"=>0, "length"=>0, "width"=>0, "height"=>0 ], ]; $boxs = isset($params['formData']["boxs"])?$params['formData']["boxs"]:$defaultBox; $imgs = array_values(array_unique(array_filter($imgs))); $imgs_tmp = []; foreach ($imgs as $img){ if(strpos($img, 'http') === false){ array_push($imgs_tmp,"http://ye4s.file.gzxunren.com/".$img); }else{ array_push($imgs_tmp,$img); } } $StockImgsModel->where(["stock_id"=>$datas['formData']['STOCKID']])->where("url","not in",$imgs_tmp)->delete(); foreach ($imgs_tmp as $img){ $exitImg = $StockImgsModel->where(["stock_id"=>$datas['formData']['STOCKID'],"url"=>$img])->find(); if(!$exitImg){ $StockImgsModel->insert(["stock_id"=>$datas['formData']['STOCKID'],"url"=>$img]); } } foreach($boxs as $key => $box){ $exitImg = $StockBoxsModel->where(["stock_id"=>$datas['formData']['STOCKID'],"type"=>$key])->find(); if(!$exitImg){ $StockBoxsModel->insert(["stock_id"=>$datas['formData']['STOCKID'],"type"=>$key,"count"=>$box["count"],"length"=>$box["length"],"width"=>$box["width"],"height"=>$box["height"]]); }else{ $exitImg->save(["count"=>$box["count"],"length"=>$box["length"],"width"=>$box["width"],"height"=>$box["height"]]); } } $data = $stockModel ->where(["STOCKID"=>intval($datas['formData']['STOCKID'])])->find(); $YXQ = isset($datas['formData']['YXQ'])?$datas['formData']['YXQ']:($data['YXQ'] ?? null); $saveData = [intval($datas['formData']['STOCKID']),intval($datas['formData']['WEIGHT']),0,0,0,$YXQ]; $data->save(["YXQ"=>$YXQ,"WEIGHT"=>$datas['formData']['WEIGHT']]); //$result = Wsdl::webservice($saveData,'upateStock'); $this->success('保存成功',[$saveData,$imgs,$boxs]); } public function ranking(){ $WAREHOUSEID = $this->auth->warehouseid; $orderModel = new \app\common\model\wms\Order; $orderquery = $orderModel->where(["WAREHOUSEID"=>$WAREHOUSEID]); $datas = $orderquery->field(' SUM(CASE WHEN a.POSTFLAG=0 and a.FLAG=0 THEN 1 ELSE 0 END) AS dfp, SUM(CASE WHEN a.PRINTTIMES=0 and a.POSTFLAG=1 and a.FLAG=0 THEN 1 ELSE 0 END) AS ddy, SUM(CASE WHEN a.PRINTTIMES=1 and a.PICKINGFLAG=0 and a.FLAG=0 and a.OPERATERECORDS not like "%领料%" and a.OPERATERECORDS not like "%领取快递面单%" and a.GRABNUM != "" THEN 1 ELSE 0 END) AS dll, SUM(CASE WHEN a.PICKINGFLAG=0 and a.FLAG=0 and (a.OPERATERECORDS like "%领料%" or a.OPERATERECORDS like "%领取快递面单%") and a.GRABNUM != "" THEN 1 ELSE 0 END) AS djh, SUM(CASE WHEN a.PICKINGFLAG=3 and a.FLAG=0 and a.PLSENDFLAG=0 THEN 1 ELSE 0 END) AS dfh, SUM(CASE WHEN a.PLSENDFLAG=1 and a.FLAG=0 and WEIGHT = "" THEN 1 ELSE 0 END) AS dcz, SUM(CASE WHEN a.PLSENDFLAG=1 and a.FLAG=0 and a.OPERATERECORDS not like "%打包%" THEN 1 ELSE 0 END) AS ddb, SUM(CASE WHEN 1=1 THEN 1 ELSE 0 END) AS yjd, SUM(CASE WHEN a.POSTFLAG=1 and a.FLAG=0 THEN 1 ELSE 0 END) AS yfp, SUM(CASE WHEN a.PRINTTIMES=1 and a.FLAG=0 THEN 1 ELSE 0 END) AS ydy, SUM(CASE WHEN a.WEIGHT <> "" and a.FLAG=0 THEN 1 ELSE 0 END) AS ycz, SUM(CASE WHEN a.OPERATERECORDS like "%打包%" and a.FLAG=0 THEN 1 ELSE 0 END) AS ydb, SUM(CASE WHEN (a.OPERATERECORDS like "%领料%" or a.OPERATERECORDS like "%领取快递面单%" or a.PICKINGFLAG=3) and FLAG=0 THEN 1 ELSE 0 END) AS yll, SUM(CASE WHEN a.PICKINGFLAG=3 and a.FLAG=0 THEN 1 ELSE 0 END) AS yjh, SUM(CASE WHEN a.PLSENDFLAG=1 and a.FLAG=0 THEN 1 ELSE 0 END) AS yfh, SUM(CASE WHEN a.FLAG=1 THEN 1 ELSE 0 END) AS ylj, store.TITLE as TITLE ')->alias('a')->join('yj_store store', 'store.STOREID = a.STOREID')->where('cast(a.CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->group('a.STOREID')->order('yjd','desc')->select(); $this->success('获取成功',$datas); } public function box(){ $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $start = $params['start']; $storeid = $params['storeid']; $end = $params['end']; $OrderModel = new \app\common\model\datas\Pack; $userid = $this->auth->id; $userStoreModel = new \app\common\model\UserStore; $fieldstr = 'sum(count) as COUNT,PACKID'; if($this->auth->check("isstaff")){ if($storeid!=0){ $orderquery = $OrderModel->where(["STOREID"=>$storeid]); }else{ $orderquery = $OrderModel->where(["WAREHOUSEID"=>$WAREHOUSEID]); } }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); $storeids = []; foreach ($stores as $r){ array_push($storeids,$r["store_id"]); } if($storeid!=0){ $storeids = array_intersect([$storeid],$storeids); } $orderquery = $OrderModel->where("STOREID",'in',$storeids); } $orderquery->field(rtrim($fieldstr, ','))->where('create_date','BETWEEN',[strtotime($start),strtotime($end)])->group("PACKID")->order('COUNT','desc'); $list = $orderquery->select(); $PACKIDS = []; foreach ($list as $r){ array_push($PACKIDS,$r['PACKID']); } $PACKIDS = array_unique($PACKIDS); $PackModel = new \app\common\model\wms\Pack; $PACKS = $PackModel->where("ID","in",$PACKIDS)->select(); foreach ($list as $k => $r){ $list[$k]["COUNT"] = intval($r["COUNT"]); foreach ($PACKS as $pack){ if($pack["ID"]==$r["PACKID"]){ $list[$k]["PACKNAME"] = $pack["NAME"]; } } } usort($list, function($a, $b) { return $b['COUNT'] - $a['COUNT']; }); $postcodes = []; $this->success('成功',$list); } public function box_export(){ $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $start = $params['start']; $storeid = $params['storeid']; $end = $params['end']; $co = $this->getDailyStartTimestamps(strtotime($start),strtotime($end)); $OrderModel = new \app\common\model\wms\Order1; $OrderModel2 = new \app\common\model\wms\Order2; $STORESModel = new \app\common\model\wms\Store; $STORES = $STORESModel->field('STOREID,TITLE')->select(); $fieldstr = ' count(*) as COUNT, a.PACKID as PACKID, pack.NAME as PACKNAME, a.STOREID as STOREID '; $userid = $this->auth->id; $userStoreModel = new \app\common\model\UserStore; $Warestoress = []; if($this->auth->check("isstaff")){ if($storeid!=0){ $orderquery = $OrderModel->where(["a.STOREID"=>$storeid]); $orderquery2 = $OrderModel2->where(["a.STOREID"=>$storeid]); }else{ $orderquery = $OrderModel->where(["a.WAREHOUSEID"=>$WAREHOUSEID]); $orderquery2 = $OrderModel2->where(["a.WAREHOUSEID"=>$WAREHOUSEID]); } }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); $storeids = []; foreach ($stores as $r){ array_push($storeids,$r["store_id"]); } if($storeid!=0){ $storeids = array_intersect([$storeid],$storeids); } $orderquery = $OrderModel->where("a.STOREID",'in',$storeids); $orderquery2 = $OrderModel2->where("a.STOREID",'in',$storeids); } $orderquery->field(rtrim($fieldstr, ','))->alias('a')->where(["a.STATUS"=>4, "a.DISPLAYFLAG"=>0])->where('a.SENDDATE','BETWEEN',['00'.strtotime($start).'000','00'.(strtotime($end) + 86399).'000'])->join('yj_pack pack', 'pack.ID = a.PACKID')->where('a.PACKID>0')->group('a.PACKID')->order('COUNT DESC'); $orderquery2->field(rtrim($fieldstr, ','))->alias('a')->where(["a.STATUS"=>4, "a.DISPLAYFLAG"=>0])->where('a.SENDDATE','BETWEEN',['00'.strtotime($start).'000','00'.(strtotime($end) + 86399).'000'])->join('yj_pack pack', 'pack.ID = a.PACKID')->where('a.PACKID>0')->group('a.PACKID')->order('COUNT DESC'); $list = $orderquery->select(); $list2 = $orderquery2->select(); $list = array_merge($list,$list2); $title = '包装统计'; $worksheet->setTitle($title); $worksheet->fromArray( [ ['包装','数量','货主'] ], '', 'A1' ); $lists = []; foreach ($list as $r){ $COUNT = intval($r['COUNT']); $PACKNAME = $r['PACKNAME']; $STORENAME = ''; foreach ($STORES as $rr){ if($r['STOREID']==$rr["STOREID"]){ $STORENAME = $rr['TITLE']; } } array_push($lists,[$PACKNAME,$COUNT,$STORENAME]); } $worksheet->fromArray( $lists, '', 'A2' ); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename=Excel导出.xlsx'); header('Cache-Control: max-age=0'); $write = IOFactory::createWriter($spreadsheet, 'Xlsx'); $write->save('php://output'); $this->success('成功',$list); } public function shops(){ $params=$this->request->post(); $page = isset($params["pages"])?$params["pages"]:1; $storeid = $params["storeid"]; $WAREHOUSEID = $this->auth->warehouseid; $userid = $this->auth->id; $userStoreModel = new \app\common\model\UserStore; $WarestoreModel = new \app\common\model\wms\Warestore; $Warestoress = []; if($this->auth->check("isstaff")){ if($storeid!=0){ $Warestores = $WarestoreModel->where(["STOREID"=>$storeid])->select(); }else{ $Warestores = $WarestoreModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select(); } }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); $storeids = []; foreach ($stores as $r){ array_push($storeids,$r["store_id"]); } if($storeid!=0){ $storeids = array_intersect([$storeid],$storeids); } $Warestores = $WarestoreModel->where("STOREID","in",$storeids)->select(); } foreach ($Warestores as $r){ array_push($Warestoress,$r["STOREID"]); } if(!$Warestores){ $this->success("获取成功",["list"=>[],"count"=>0]); } $orderModel = new \app\common\model\wms\Order; $query = $orderModel->field("COUNT(*) as count,STORENAME") ->where("STOREID","in",$Warestoress) ->group('STORENAME') ->order("count","desc"); $list = $query->limit(($page-1)*50,50)->select(); $query2 = $orderModel->group('STORENAME') ->where("STOREID","in",$Warestoress); $count = $query2->count(); $this->success("获取成功",["list"=>$list,"count"=>$count]); } public function abnormal_tracking(){ $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $this->Exceptionwmsorder = new \app\common\model\wms\Exceptionwmsorder; $start = $params["start"]; $end = $params["end"]; $STOREID = $params["storeid"]; if($STOREID>0){ $res = $this->Exceptionwmsorder->where(["STOREID"=>$STOREID])->where('CREATIONDATE','BETWEEN',['00'.strtotime($start).'000','00'.(strtotime($end) + 86399).'000'])->where(["WAREHOUSEID"=>$WAREHOUSEID])->select(); }else{ $res = $this->Exceptionwmsorder->where(["WAREHOUSEID"=>$WAREHOUSEID])->where('CREATIONDATE','BETWEEN',['00'.strtotime($start).'000','00'.(strtotime($end) + 86399).'000'])->select(); } $this->success("获取成功",$res); } public function calculate_the_average_weight(){ $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $selectTime = $params['selectTime']; $startTime= strtotime($selectTime[0]); $endTime = strtotime($selectTime[1]); $STOREID = $params['storeid']; $AverageWeightModel = new \app\common\model\datas\AverageWeight; $RuleModel = new \app\common\model\cost\Rules; $SummaryModel = new \app\common\model\cost\Summary; $HisordersummaryModel = new \app\common\model\Hisordersummary; $startOfMonth = strtotime(date('Y-m-d', strtotime('first day of', $startTime))); $endOfMonth = strtotime(date('Y-m-d', strtotime('last day of', $startTime)))+ 86399; [$otheritemprice,$otherprice_list,$cdoutprice,$cdinprice,$outAllprice,$wfk] = $this->getincidental($startTime,$endTime,$WAREHOUSEID,$STOREID); //return json([$otheritemprice,$otherprice_list,$cdoutprice,$cdinprice,$outAllprice]); $AverageWeightSummary = $AverageWeightModel->field("CEIL(sum(weight)/sum(count)) as weight,ruluid,sum(count) as count,create_date,STOREID,iscost")->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("STOREID>0")->where("create_date","BETWEEN",[$startOfMonth,$endOfMonth]); if($STOREID>0){ $AverageWeightSummary = $AverageWeightSummary->where("STOREID=".$STOREID); } $AverageWeightSummary = $AverageWeightSummary->group("create_date,ruluid")->select(); $AverageWeightSummary2 = $AverageWeightModel->field("CEIL(sum(weight)/sum(count)) as weight,ruluid,sum(count) as count,create_date,STOREID")->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("create_date","BETWEEN",[$startOfMonth,$endOfMonth]); if($STOREID>0){ $AverageWeightSummary2 = $AverageWeightSummary2->where("STOREID=".$STOREID." or STOREID=0"); } $AverageWeightSummary2 = $AverageWeightSummary2->group("ruluid")->select(); $Hisordersummary = $SummaryModel->field("sum(unrulescount) as unrulescount,sum(costunrulescount) as costunrulescount,sum(rulescount) as rulescount,sum(costrulescount) as costrulescount,sum(totalprice) as totalprice,sum(costtotalprice) as costtotalprice,sum(totalprice2) as totalprice2,sum(costtotalprice2) as costtotalprice2,sum(packpricecost) as packpricecost,sum(packprice) as packprice,sum(packingprice) as packingprice,createTime,STOREID")->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("createTime","BETWEEN",[$startOfMonth,$endOfMonth]); if($STOREID>0){ $Hisordersummary = $Hisordersummary->where("STOREID=".$STOREID." or STOREID=0"); } $Hisordersummary = $Hisordersummary->group("createTime")->select(); //return json($Hisordersummary); //整月均重 foreach ($Hisordersummary as $r){ $price = 0; $priced1 = ""; $price2 = 0; $priced2 = ""; $packcostprice = 0; $packprice = 0; $packingprice = 0; $r["othercostprice"] = round($otheritemprice*($r["rulescount"]+$r["unrulescount"]),2); foreach ($AverageWeightSummary as $rrr){ //成本 if($r["createTime"]==$rrr["create_date"]){ $ruleprice = 0; $ruleprice2 = 0; if($rrr["iscost"]==0){ foreach ($AverageWeightSummary2 as $rr){ if($rr["ruluid"]==$rrr["ruluid"]){ $rule = $RuleModel->where(["id"=>$rr["ruluid"]])->find(); $ruleprice = $this->getOrderPrice($rr["weight"],$rule); //print_r($rr["weight"]);die(); $price+=$ruleprice*$rrr["count"]; $priced1.=$ruleprice."|".$rrr["count"].";"; } } }else{ foreach ($AverageWeightSummary2 as $rr){ if($rr["ruluid"]==$rrr["ruluid"]){ $rule = $RuleModel->where(["id"=>$rr["ruluid"]])->find(); $ruleprice2 = $this->getOrderPrice($rr["weight"],$rule); //print_r($rr["weight"]);die(); $price2+=$ruleprice2*$rrr["count"]; $priced2.=$ruleprice2."|".$rrr["count"].";"; } } } /*foreach ($AverageWeightSummary2 as $rr){ print_r($rr["ruluid"]); /*if($rrr["iscost"]==0){ $rule = $RuleModel->where(["id"=>$rr["ruluid"]])->find(); print_r($rr["weight"]."|".($rule["id"] ?? null)."|"); $ruleprice = $this->getOrderPrice($rr["weight"],$rule); print_r($ruleprice2."|||"); } /*if($rr["ruluid"]==$rrr["ruluid"] && $rrr["iscost"]>0){ $rule = $RuleModel->where(["id"=>$rr["ruluid"]])->find(); $ruleprice2 = $this->getOrderPrice($rr["weight"],$rule); } }*/ } } $r["r111"] = round($price,2); $r["d111"] = $priced1; $r["r112"] = round($price2,2); $r["d112"] = $priced2; $r["packcostprice"] = $r["packpricecost"]; $r["packprice"] = $r["packprice"]; $r["packingprice"] = $r["packingprice"]; } $this->success("获取成功",[$AverageWeightSummary2,$AverageWeightSummary,$Hisordersummary,$cdoutprice,$cdinprice,$outAllprice,$wfk,$otheritemprice]); } private function getOrderPrice($weight,$rule){ $price = 0; $price=$weight<$rule["fristweight"]?$rule["firstprice"]:round((($weight-$rule["fristweight"])/$rule["continuedweight"])*$rule["continuedweightprice"]+$rule["firstprice"],2); return round($price,2); } private function getincidental($startTime,$endTime,$WAREHOUSEID,$storeid){ $SummaryModel = new \app\common\model\cost\Summary; $DailyaccountModel = new \app\common\model\datas\Dailyaccount; //总单量 $Hisordersummary = $SummaryModel->field("sum(unrulescount) as unrulescount,sum(costunrulescount) as costunrulescount,sum(rulescount) as rulescount,sum(costrulescount) as costrulescount,sum(totalprice) as totalprice,sum(costtotalprice) as costtotalprice,sum(totalprice2) as totalprice2,sum(costtotalprice2) as costtotalprice2,sum(packpricecost) as packpricecost,sum(packprice) as packprice,sum(packingprice) as packingprice,createTime,STOREID")->where(["WAREHOUSEID"=>$WAREHOUSEID])->where("createTime","BETWEEN",[$startTime,$endTime+86399]); $Hisordersummary = $Hisordersummary->group("createTime")->select(); $costrulescount = 0; $cdoutprice = 0; foreach($Hisordersummary as $r){ $costrulescount+=intval($r["rulescount"])+intval($r["unrulescount"]); } //流水 $accountList = $DailyaccountModel->alias("a")->field("a.type as type,a.id as id,a.account as price,a.STOREID as STOREID,c.isin as isin,c.counted as counted,a.occurrenceTime as occurrenceTime,c.isExpress as isExpress,c.isExpressOut as isExpressOut")->join("ye4s_accounttype c","c.id = a.type")->where("a.occurrenceTime","BETWEEN",[$startTime,$endTime+86399])->where(["a.isDelete"=>0,"a.issettlement"=>1])->select(); $IDS = []; foreach ($accountList as $R){ array_push($IDS,$R["id"]); } $subList = $DailyaccountModel->alias("a")->field("a.type as type,a.id as id,a.account as price,a.STOREID as STOREID,c.isin as isin,c.counted as counted,a.occurrenceTime as occurrenceTime")->join("ye4s_accounttype c","c.id = a.type")->order("id")->select(); foreach ($accountList as $key => $R){ if($R["counted"]==0){ $accountList[$key] = null; } } $allprice = 0; $wf = 0; $other = []; $accountList = array_filter($accountList); $cdinprice = 0; //应付 $BillModel = new \app\common\model\supplier\Bill; $yf = $BillModel->field("sum(account) as price")->where("occTime","BETWEEN",[$startTime,$endTime+86399])->where("isPay<2")->select(); foreach ($yf as $r){ $allprice=round($r["price"]+$allprice,2); $wf=round($wf+$r["price"]); } foreach ($accountList as $R){ if($R["STOREID"]==0 && $R["isin"]==0){ if($R["isExpressOut"]==1){ $cdoutprice=round($R["price"]+$cdoutprice,2); }else{ $allprice=round($R["price"]+$allprice,2); } }else if($R["STOREID"]==0 && $R["isin"]==1){ $allprice=round($allprice-$R["price"],2); }else{ if($R["isin"]==1 && $R["isExpress"]==1){ if($storeid==0){ $cdinprice=round($cdinprice+$R["price"],2); }else{ if($storeid==$R["STOREID"]){ $cdinprice=round($cdinprice+$R["price"],2); } } }else{ array_push($other,$R); } } } //echo ($storeid); //print_r($cdinprice);die(); foreach ($other as $r){ if($r["isin"]==1 && $r["isExpress"]==1){ } } //每票均杂费保留8位小数 $itemprice = $costrulescount>0?round(($allprice/$costrulescount),2):0; //print_r($allprice);die(); return [$itemprice,$other,$cdoutprice,$cdinprice,$allprice,$wf]; } private function getOtherPrice($n1,$n2,$n3,$n4,$n5){ $price = 0; $price2 = 0; $price+=$n1*intval($n2); foreach ($n3 as $r){ if($n4>0){ if($r["STOREID"]==$n4 && $r["occurrenceTime"]==$n5){ if($r["isin"]==1){ $price2 +=$r["price"]; }else{ $price+=$r["price"]; } } }else{ if($r["STOREID"]>0 && $r["occurrenceTime"]==$n5){ if($r["isin"]==1){ $price2 +=$r["price"]; }else{ $price+=$r["price"]; } } } } return [round($price,2),round($price2,2)]; } public function account(){ $WAREHOUSEID = $this->auth->warehouseid; $params=$this->request->post(); $storeid = $params["storeid"]; $userid = $this->auth->id; $StoreModel = new \app\common\model\wms\Store; $OrderModel = new \app\common\model\wms\Order; $WarestoreModel = new \app\common\model\wms\Warestore; $AccountModel = new \app\common\model\wms\Account; $AccountdetailModel = new \app\common\model\wms\Accountdetail; $userStoreModel = new \app\common\model\UserStore; $Time = time(); $startOfMonth = strtotime(date('Y-m-d', strtotime('first day of', $Time))); $endOfMonth = strtotime(date('Y-m-d', strtotime('last day of', $Time)))+ 86399; $Warestoress = []; $USERIDS = []; $STORES = []; if($this->auth->check("isstaff")){ if($storeid>0){ $storeids = $StoreModel->where(["STOREID"=>$storeid])->find(); array_push($USERIDS,($storeids["USERID"] ?? null)); array_push($STORES,$storeids["STOREID"]); }else{ $STORESS = $WarestoreModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->select(); $tmpStores = []; foreach ($STORESS as $r){ array_push($tmpStores,$r["STOREID"]); array_push($STORES,$r["STOREID"]); } $storeids = $StoreModel->where("STOREID","in",$tmpStores)->select(); foreach ($storeids as $r){ array_push($USERIDS,$r["USERID"]); } } }else{ $tmpStores = []; if($storeid>0){ array_push($STORES,$storeid); }else{ $stores = $userStoreModel->where(["user_id"=>$userid])->select(); foreach ($stores as $r){ array_push($STORES,$r["store_id"]); } } $storeids = $StoreModel->where("STOREID","in",$STORES)->select(); foreach ($storeids as $r){ array_push($USERIDS,$r["USERID"]); } } //print_r($STORES);die(); $Account=$AccountModel->where("USERID","in",$USERIDS)->select(); $ACCOUNTID = []; $allprice = 0; foreach ($Account as $r){ array_push($ACCOUNTID,$r["ID"]); $allprice+=$r["CURRENTBALANCE"]; } $Accountdetail=$AccountdetailModel->where("ACCOUNTID","in",$ACCOUNTID)->order("CREATIONDATE","desc")->limit(100)->select(); $orders = $OrderModel->field('SUM(CASE WHEN POSTFLAG=0 THEN 1 ELSE 0 END) AS dfp,SUM(CASE WHEN POSTFLAG=1 THEN 1 ELSE 0 END) AS yfp')->where("STOREID","in",$STORES)->find(); $inAccount = 0; $outAccount = 0; $Accountdetailout=$AccountdetailModel->field("sum(BALANCE) as BALANCE")->where("ACCOUNTID","in",$ACCOUNTID)->where("CREATIONDATE","BETWEEN",["00".$startOfMonth."000","00".$endOfMonth."999"])->where("TYPE>0")->find(); $Accountdetailin=$AccountdetailModel->field("sum(BALANCE) as BALANCE")->where("ACCOUNTID","in",$ACCOUNTID)->where("CREATIONDATE","BETWEEN",["00".$startOfMonth."000","00".$endOfMonth."999"])->where(["TYPE"=>0])->find(); $inAccount = ($Accountdetailin["BALANCE"] ?? null)?($Accountdetailin["BALANCE"] ?? null):0; $outAccount = ($Accountdetailout["BALANCE"] ?? null)?($Accountdetailout["BALANCE"] ?? null):0; $this->success("获取成功",["allprice"=>$allprice,"STORES"=>$STORES,"orders"=>$orders,"inAccount"=>$inAccount,"outAccount"=>$outAccount,"Accountdetail"=>$Accountdetail]); } }