123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908 |
- <?php
- namespace app\admin\controller;
- use think\App;
- use think\Db;
- use think\Exception;
- class DinnerOrder extends Auth
- {
- public function __construct(App $app = null) {
- parent::__construct($app);
- $this->table='dinner_order';
- $this->model= new \app\common\model\DinnerOrder();
- }
- public function index(){
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $offset = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx','id','trim'); //排序列
- $sort = input('sord','desc','trim'); //排序方式
- $order = $sortRow.' '.$sort;
- $title = input('title','','trim');
- if($title){
- $map[] = ['a.name|a.sn','like','%'.$title.'%'];
- }
- $is_ok = input('is_ok',0,'trim');
- if($is_ok>=0){
- $map[] = ['a.is_ok','=',$is_ok];
- }
- $is_spot = input('is_spot/d',0);
- if($is_spot == 2){
- $map[] = ['a.cate','=',1];
- $start = input('start',date('Y-m-d'),'trim');
- $oids = Db::name('dinner_order_item')
- ->where('day',$start)
- ->group('order_id')
- ->distinct(true)
- ->column('order_id');
- if($oids){
- $map[] = ['a.id','in',$oids];
- }else{
- $map[] = ['a.id','=',-1];
- }
- }else{
- $map[] = ['a.is_spot','=',$is_spot];
- $map[] = ['a.cate','=',0];
- $start = input('start',date('Y-m-d'),'trim');
- $map[] = ['a.ymd','=',date('Ymd',strtotime($start))];
- }
- $dinner_type_id = input('type','','trim');
- if($dinner_type_id != ''){
- $dinner_order_item = Db::name('dinner_order_item')
- ->where('dinner_type_id',$dinner_type_id)
- ->where('is_refuse',0)
- ->column('order_id');
- if(empty($dinner_order_item)){
- $map[] = ['a.id','=',-1];
- }else{
- $map[] = ['a.id','in',$dinner_order_item];
- }
- }
- $map[] = ['a.org_id','=',$this->orgId];
- $map[] = ['a.state','<>',0];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = Db::name($this->table)
- ->alias('a')
- ->field('a.*')
- ->where($map)->limit($offset,$length)->order(
- ['a.id'=>'desc']
- )->select();
- foreach ($lists as $k=>$v){
- $dmap = [];
- $dmap[] = ['a.order_id','=',$v['id']];
- $dmap[] = ['a.is_refuse','=',0];
- if($dinner_type_id > 0){
- $dmap[] = ['a.dinner_type_id','=',$dinner_type_id];
- }
- if($is_spot == 2){
- $dmap[] = ['a.day','=',$start];
- }
- $all = Db::name('dinner_order_item')
- ->alias('a')
- ->join('dinner b','a.dinner_id=b.id')
- ->join('dinner_type c','a.dinner_type_id=c.id')
- ->field('a.*,b.money as oldmoney,b.name as dinner_name,c.color,c.name as dinner_type_name')
- ->where($dmap)
- ->select();
- $typeIdS = $all?array_unique(array_column($all,'dinner_type_id')):[];
- $typeName = '';
- foreach ($typeIdS as $k1=>$v1){
- $tInfo = Db::name('dinner_type')
- ->where('id',$v1)
- ->find();
- $typeName.='<span class="label" style="border-radius:0rem !important;background-color: '.$tInfo['color'].';color: white">'.$tInfo['name'].'</span>';
- if(count($typeIdS)>1 && $k1<count($typeIdS)-1){
- $typeName.='<br/>';
- }
- }
- $lists[$k]['tName'] = $typeName;
- $item = '';
- foreach ($all as $k2=>$v2){
- if($v2['money'] == 0 && $v2['oldmoney'] > 0){
- $v2['money'] = $v2['oldmoney'];
- }
- $ss = $k2+1;
- if($ss<10){
- $ss= '0'.$ss;
- }
- $ur = url('dinner/detail').'?id='.$v2['dinner_id'];
- $item.=''.$ss.',<span class="label" style="border-radius:0rem !important;background-color: '.$v2['color'].';color: white">'.$v2['dinner_type_name'].'</span><a data-title="详情" href="javascript:;" url="'.$ur.'">'.$v2['dinner_name'].'*'.$v2['num'];
- if(count($all)>1 && $k2<count($all)){
- $item.='<br/>';
- }
- }
- $lists[$k]['item'] = $item;
- }
- //数据返回
- $totalCount = db($this->table)
- ->alias('a')
- ->where($map)->count();
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }else{
- $this->assign('start',date('Y-m-d'));
- $typeList = model('DinnerType')->getList($this->orgId);
- $this->assign('typeList',$typeList);
- return $this->fetch();
- }
- }
- public function index1(){
- $is_spot = input('is_spot/d',0);
- if($is_spot == 2){
- $map[] = ['cate','=',1];
- $start = input('start',date('Y-m-d'),'trim');
- $oids = Db::name('dinner_order_item')
- ->where('day',$start)
- ->group('order_id')
- ->distinct(true)
- ->column('order_id');
- if($oids){
- $map[] = ['id','in',$oids];
- }else{
- $map[] = ['id','=',-1];
- }
- }else{
- $map[] = ['is_spot','=',$is_spot];
- $map[] = ['cate','=',0];
- $start = input('start',date('Y-m-d'),'trim');
- $map[] = ['ymd','=',date('Ymd',strtotime($start))];
- }
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['state','<>',0];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = Db::name($this->table)->where($map)->column('id');
- $newArr = [];
- $type = [];
- $rows = [];
- if(!empty($lists)){
- $dmap[] = ['a.order_id','in',$lists];
- $dmap[] = ['a.is_refuse','=',0];
- if($is_spot == 2){
- $dmap[] = ['a.day','=',$start];
- }
- $all = Db::name('dinner_order_item')
- ->alias('a')
- ->join('dinner_type c','a.dinner_type_id=c.id')
- ->field('c.id,a.order_id,c.color,c.name as dinner_type_name')
- ->where($dmap)
- ->group('a.dinner_type_id')
- ->select();
- $type = $all;
- $maxrow = 0;
- foreach ($type as $k=>$v){
- $total = Db::name('dinner_order_item')
- ->alias('a')
- ->join('dinner b','a.dinner_id=b.id')
- ->join('dinner_type c','a.dinner_type_id=c.id')
- ->field('sum(a.num) as nums,b.name as dinner_name,c.color,c.name as dinner_type_name')
- ->where('a.dinner_type_id',$v['id'])
- ->where($dmap)
- ->group('a.dinner_id')
- ->select();
- $total = $total?$total:[];
- $count = count($total);
- if($count > $maxrow){
- $maxrow = $count;
- }
- $newArr[] = $total;
- }
- $i = 0;
- while (true){
- if($maxrow <= 0){
- break;
- }
- $d = [];
- foreach ($type as $k=>$v){
- $dd = $newArr[$k];
- $d['name'.$v['id']] = isset($dd[$i])?$dd[$i]['dinner_name']:'';
- $d['nums'.$v['id']] = isset($dd[$i])?$dd[$i]['nums']:'';
- }
- $rows[] = $d;
- $maxrow--;
- $i++;
- }
- }
- $this->assign('type',$type);
- $this->assign('data',$rows);
- $this->assign('is_spot',$is_spot);
- $this->assign('start',$start);
- return $this->fetch();
- }
- public function day(){
- $cate = input('cate/d',0);
- $this->assign('cate',$cate);
- $map[] = ['cate','=',$cate];
- if($cate == 1){
- $start = input('start',date('Y-m-d'),'trim');
- $oids = Db::name('dinner_order_item')
- ->where('day',$start)
- ->group('order_id')
- ->distinct(true)
- ->column('order_id');
- if($oids){
- $map[] = ['id','in',$oids];
- }else{
- $map[] = ['id','=',-1];
- }
- }else{
- $start = input('start',date('Y-m-d'),'trim');
- $map[] = ['ymd','=',date('Ymd',strtotime($start))];
- }
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['state','<>',0];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = Db::name($this->table)
- ->where($map)->column('id');
- $newArr = [];
- $type = [];
- $rows = [];
- if(!empty($lists)){
- $dmap = [];
- $dmap[] = ['a.order_id','in',$lists];
- $dmap[] = ['a.is_refuse','=',0];
- if($cate == 1){
- $dmap[] = ['a.day','=',$start];
- }
- $all = Db::name('dinner_order_item')
- ->alias('a')
- ->join('dinner_type c','a.dinner_type_id=c.id')
- ->field('c.id,c.color,c.name as dinner_type_name')
- ->where($dmap)
- ->group('a.dinner_type_id')
- ->select();
- $type = $all;
- $maxrow = 0;
- foreach ($type as $k=>$v){
- $total = Db::name('dinner_order_item')
- ->alias('a')
- ->join('dinner b','a.dinner_id=b.id')
- ->join('dinner_type c','a.dinner_type_id=c.id')
- ->field('sum(a.price) as nums,b.name as dinner_name,c.color,c.name as dinner_type_name')
- ->where('a.dinner_type_id',$v['id'])
- ->where($dmap)
- ->group('a.dinner_id')
- ->select();
- $count = Db::name('dinner_order_item')
- ->alias('a')
- ->join('dinner b','a.dinner_id=b.id')
- ->join('dinner_type c','a.dinner_type_id=c.id')
- ->where('a.dinner_type_id',$v['id'])
- ->where($dmap)
- ->sum('a.price');
- $type[$k]['total'] = sprintf("%.2f",$count);
- $newArr[] = $total;
- $count = count($total);
- if($count > $maxrow){
- $maxrow = $count;
- }
- }
- $i = 0;
- while (true){
- if($maxrow <= 0){
- break;
- }
- $d = [];
- foreach ($type as $k=>$v){
- $dd = $newArr[$k];
- $d['name'.$v['id']] = isset($dd[$i])?$dd[$i]['dinner_name']:'';
- $d['price'.$v['id']] = isset($dd[$i])?$dd[$i]['nums']:'';
- }
- $rows[] = $d;
- $maxrow--;
- $i++;
- }
- }
- $this->assign('type',$type);
- $this->assign('data',$rows);
- $this->assign('start',$start);
- return $this->fetch();
- }
- public function typeTj(){
- $start = input('start',date('Y-m-d'),'trim');
- $end = input('end',date('Y-m-d'),'trim');
- $data = $this->typeTjData($start,$end);
- $this->assign('total',$data['b']);
- $this->assign('data',$data['a']);
- $this->assign('start',$start);
- $this->assign('end',$end);
- return $this->fetch();
- }
- public function typeTjData($start,$end){
- $cate = input('cate/d',0);
- $this->assign('cate',$cate);
- $map[] = ['org_id','=',$this->orgId];
- $map[] = ['state','<>',0];
- $map[] = ['cate','=',$cate];
- $map= empty($map) ? true: $map;
- //数据查询
- $day = getDateFromRange($start,$end);
- $a = [];
- $b0 = $b1 = $b2=$b3=$b4=0;
- foreach ($day as $k=>$v){
- $map1 = $map;
- $day = date('Ymd',strtotime($v));
- if($cate == 1){
- $oids = Db::name('dinner_order_item')
- ->where('day',$day)
- ->group('order_id')
- ->distinct(true)
- ->column('order_id');
- if($oids){
- $map1[] = ['id','in',$oids];
- }else{
- $map1[] = ['id','=',-1];
- }
- }else{
- $map1[] = ['ymd','=',$day];
- }
- $a0 = Db::name($this->table)
- ->where($map1)
- ->column('id');
- if(empty($a0)){
- $k0 = 0;
- }else{
- $map2 = [];
- $map2[] = ['a.is_refuse','=',0];
- $map2[] = ['a.order_id','in',$a0];
- if($cate == 1){
- $map2[] = ['a.day','=',$day];
- }
- $k0= Db::name('dinner_order_item')
- ->alias('a')
- ->where($map2)
- ->sum('a.price');
- }
- $b0+=$k0;
- $a1 = Db::name($this->table)
- ->where($map)
- ->where('ymd',date('Ymd',strtotime($v)))
- ->where('order_type',1)
- ->column('id');
- if(empty($a1)){
- $k1 = 0;
- }else{
- $k1 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a1)
- ->sum('a.price');
- }
- $b1+=$k1;
- $a2 = Db::name($this->table)
- ->where($map)
- ->where('ymd',date('Ymd',strtotime($v)))
- ->where('order_type',2)
- ->column('id');
- if(empty($a1)){
- $k2 = 0;
- }else{
- $k2 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a2)
- ->sum('a.price');
- }
- $b2+=$k2;
- $a3 = Db::name($this->table)
- ->where($map)
- ->where('ymd',date('Ymd',strtotime($v)))
- ->where('order_type',3)
- ->column('id');
- if(empty($a1)){
- $k3 = 0;
- }else{
- $k3 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a3)
- ->sum('a.price');
- }
- $b3+=$k3;
- $a4 = Db::name($this->table)
- ->where($map)
- ->where('ymd',date('Ymd',strtotime($v)))
- ->count();
- $b4+=$a4;
- $a[] = [
- 'title'=>$v,
- 'a0'=>$k0,
- 'a1'=>$k1,
- 'a2'=>$k2,
- 'a3'=>$k3,
- 'a4'=>$a4,
- ];
- }
- $b = [
- 'b0'=>$b0,
- 'b1'=>$b1,
- 'b2'=>$b2,
- 'b3'=>$b3,
- 'b4'=>$b4,
- ];
- return ['a'=>$a,'b'=>$b];
- }
- /**
- * 删除记录
- * @param int $id
- */
- public function del($id=0){
- if(!$id){
- $this->error('参数错误');
- }
- $res = db($this->table)->where('id',$id)->setField('del',1);
- if($res){
- $this->success('删除成功');
- }else{
- $this->error('删除失败');
- }
- }
- /**
- * 改变字段值
- * @param int $fv
- * @param string $fn
- * @param int $fv
- */
- public function changeField($id=0,$fn='',$fv=0){
- if(!$fn||!$id){
- $this->error('参数错误');
- }
- $res = db($this->table)->where('id',$id)->setField($fn,$fv);
- if($res){
- $this->success('操作成功');
- }else{
- $this->error('操作失败');
- }
- }
- public function print($id=0){
- $info = db($this->table)->where('id',$id)->find();
- $all = Db::name('dinner_order_item')
- ->alias('a')
- ->join('dinner b','a.dinner_id=b.id')
- ->join('dinner_type c','a.dinner_type_id=c.id')
- ->field('a.*,b.name as dinner_name,c.color,c.name as dinner_type_name')
- ->where('a.order_id',$id)
- ->where('a.is_refuse',0)
- ->select();
- $info['item'] = $all;
- $this->assign('info',$info);
- return $this->fetch();
- }
- public function option($fv=0,$id=0){
- $res = db($this->table)
- ->where('org_id',$this->orgId)
- ->where('id',$id)
- ->update([
- 'is_ok'=>$fv,
- 'update_time'=>getTime()
- ]);
- if($res){
- $this->success('操作成功');
- }else{
- $this->error('操作失败');
- }
- }
- public function export(){
- $ex_type = input('ex_type',1);//1导出2发饭表导出
- if($ex_type==1){
- $data = $this->ex_type_data1();
- $this->ex_type_export1($data);
- }elseif ($ex_type==2){
- $data = $this->ex_type_data2();
- $this->ex_type_export2($data);
- }
- }
- public function ex_type_export1($data){
- $lists = $data['list'];
- $count = $data['total'];
- //实例化PHPExcel类
- include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
- $objPHPExcel = new \PHPExcel();
- //激活当前的sheet表
- $sheet = $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '序号')
- ->setCellValue('B1', '单号')
- ->setCellValue('C1', '总价')
- ->setCellValue('D1', '下单人')
- ->setCellValue('E1', '下单人电话')
- ->setCellValue('F1', '送货地址')
- ->setCellValue('G1', '床号及备注')
- ->setCellValue('H1', '下单时间')
- ->setCellValue('I1', '类别')
- ->setCellValue('J1', '购买物品');
- // 设置表格头水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('I1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('J1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置列水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('I')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('J')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置单元格宽度
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('I')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('J')->setWidth(20);
- //循环刚取出来的数组,将数据逐一添加到excel表格。
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['id']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['price']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['name']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['mobile']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['address']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['remark']);
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['pay_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['tName']);
- $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['item']);
- }
- //$objPHPExcel->getActiveSheet()->setCellValue('J' .(count($lists)+3), '总价:'.$count);
- $titles = array('序号','单号','总价','下单人','下单人电话','送货地址','床号及备注','下单时间','类别','购买物品');
- $count_length = count($titles)-1;
- $num =count($lists)+2;
- $sheet->setCellValue(\PHPExcel_Cell::stringFromColumnIndex(0).$num, '总价');
- $sheets = sprintf('%s:%s', chr(65).$num, \PHPExcel_Cell::stringFromColumnIndex($count_length-1).$num);
- $objPHPExcel->setActiveSheetIndex(0)->mergeCells($sheets);
- $objPHPExcel->getActiveSheet()->getStyle($sheets)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
- //
- $sheet->setCellValue(\PHPExcel_Cell::stringFromColumnIndex($count_length).$num,$count.'元');
- //设置保存的Excel表格名称
- $filename = '订单列表' . date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle('订单列表');
- //设置浏览器窗口下载表格
- ob_end_clean();
- header("Content-Type: application/force-download");
- header("Content-Type: application/octet-stream");
- header("Content-Type: application/download");
- header('Content-Disposition:inline;filename="' . $filename);
- //生成excel文件
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- //下载文件在浏览器窗口
- return $objWriter->save('php://output');
- }
- public function ex_type_data1(){
- $title = input('title','','trim');
- if($title){
- $map[] = ['a.name|a.sn','like','%'.$title.'%'];
- }
- $is_ok = input('is_ok',0,'trim');
- if($is_ok>=0){
- $map[] = ['a.is_ok','=',$is_ok];
- }
- $is_spot = input('is_spot',0,'trim');
- if($is_spot>=0){
- $map[] = ['a.is_spot','=',$is_spot];
- }
- $start = input('start','','trim');
- if($start){
- $map[] = ['a.ymd','=',date('Ymd',strtotime($start))];
- }
- $dinner_type_id = input('type','','trim');
- if($dinner_type_id != ''){
- $dinner_order_item = Db::name('dinner_order_item')
- ->where('dinner_type_id',$dinner_type_id)
- ->where('is_refuse',0)
- ->column('order_id');
- if(empty($dinner_order_item)){
- $map[] = ['a.id','=',-1];
- }else{
- $map[] = ['a.id','in',$dinner_order_item];
- }
- }
- $map[] = ['a.org_id','=',$this->orgId];
- $map[] = ['a.state','<>',0];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = db($this->table)
- ->alias('a')
- ->field('a.*')
- ->where($map)->order(
- ['a.id'=>'desc']
- )->select();
- foreach ($lists as $k=>$v){
- $all = Db::name('dinner_order_item')
- ->alias('a')
- ->join('dinner b','a.dinner_id=b.id')
- ->join('dinner_type c','a.dinner_type_id=c.id')
- ->field('a.*,b.name as dinner_name,c.color,c.name as dinner_type_name')
- ->where('a.order_id',$v['id'])
- ->where('a.is_refuse',0)
- ->select();
- $typeIdS = $all?array_unique(array_column($all,'dinner_type_id')):[];
- $typeName = '';
- foreach ($typeIdS as $k1=>$v1){
- $tInfo = Db::name('dinner_type')
- ->where('id',$v1)
- ->find();
- $typeName.=$tInfo['name'];
- if(count($typeIdS)>1 && $k1<count($typeIdS)-1){
- $typeName.=',';
- }
- }
- $lists[$k]['tName'] = $typeName;
- $item = '';
- foreach ($all as $k2=>$v2){
- $item.=$v2['dinner_name'].'('.$v2['dinner_type_name'].')'.'*'.$v2['num'];
- if(count($all)>1 && $k2<count($all)-1){
- $item.=',';
- }
- }
- if(!$item){
- unset($lists[$k]);
- continue;
- }else{
- $lists[$k]['item'] = $item;
- }
- }
- sort($lists);
- $num = db($this->table)
- ->alias('a')
- ->where($map)->sum('price');
- $data = [
- 'list'=>$lists,
- 'total'=>$num
- ];
- return $data;
- }
- public function ex_type_data2(){
- $title = input('title','','trim');
- if($title){
- $map[] = ['a.name|a.sn','like','%'.$title.'%'];
- }
- $is_ok = input('is_ok',0,'trim');
- if($is_ok>=0){
- $map[] = ['a.is_ok','=',$is_ok];
- }
- // $is_spot = input('is_spot',0,'trim');
- // if($is_spot>=0){
- // $map[] = ['a.is_spot','=',$is_spot];
- // }
- // $start = input('start','','trim');
- // if($start){
- // $map[] = ['a.ymd','=',date('Ymd',strtotime($start))];
- // }
- $is_spot = input('is_spot/d',0);
- if($is_spot == 2){
- $map[] = ['a.cate','=',1];
- $start = input('start',date('Y-m-d'),'trim');
- $oids = Db::name('dinner_order_item')
- ->where('day',$start)
- ->group('order_id')
- ->distinct(true)
- ->column('order_id');
- if($oids){
- $map[] = ['a.id','in',$oids];
- }else{
- $map[] = ['a.id','=',-1];
- }
- }else{
- $map[] = ['a.is_spot','=',$is_spot];
- $map[] = ['a.cate','=',0];
- $start = input('start',date('Y-m-d'),'trim');
- $map[] = ['a.ymd','=',date('Ymd',strtotime($start))];
- }
- $dinner_type_id = input('type','','trim');
- if($dinner_type_id != ''){
- $dinner_order_item = Db::name('dinner_order_item')
- ->where('dinner_type_id',$dinner_type_id)
- ->where('is_refuse',0)
- ->column('order_id');
- if(empty($dinner_order_item)){
- $map[] = ['a.id','=',-1];
- }else{
- $map[] = ['a.id','in',$dinner_order_item];
- }
- }
- $map[] = ['a.org_id','=',$this->orgId];
- $map[] = ['a.state','<>',0];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = Db::name($this->table)
- ->alias('a')
- ->field('a.*')
- ->where($map)->order(
- ['a.address'=>'asc','a.id'=>'desc']
- )->select();
- foreach ($lists as $k=>$v){
- $dmap = [];
- $dmap[] = ['a.order_id','=',$v['id']];
- $dmap[] = ['a.is_refuse','=',0];
- if($dinner_type_id > 0){
- $dmap[] = ['a.dinner_type_id','=',$dinner_type_id];
- }
- if($is_spot == 2){
- $dmap[] = ['a.day','=',$start];
- }
- $all = Db::name('dinner_order_item')
- ->alias('a')
- ->join('dinner b','a.dinner_id=b.id')
- ->join('dinner_type c','a.dinner_type_id=c.id')
- ->field('a.*,b.name as dinner_name,c.color,c.name as dinner_type_name')
- ->where($dmap)
- ->select();
- $typeIdS = $all?array_unique(array_column($all,'dinner_type_id')):[];
- $typeName = [];
- foreach ($typeIdS as $k1=>$v1){
- $tInfo = Db::name('dinner_type')
- ->where('id',$v1)
- ->find();
- $typeName[] = $tInfo['name'];
- }
- $lists[$k]['tName'] = implode(',',$typeName);
- $item = '';
- foreach ($all as $k2=>$v2){
- $item.=$v2['dinner_name'].'('.$v2['dinner_type_name'].')'.'*'.$v2['num'];
- if(count($all)>1 && $k2<count($all)-1){
- $item.=',';
- }
- }
- if(!$item){
- unset($lists[$k]);
- continue;
- }else{
- $lists[$k]['item'] = $item;
- }
- }
- sort($lists);
- $orderId = array_column($lists,'id');
- $dmap2 = [];
- $dmap2[] = ['a.order_id','in',$orderId];
- $dmap2[] = ['a.is_refuse','=',0];
- if($dinner_type_id > 0){
- $dmap2[] = ['a.dinner_type_id','=',$dinner_type_id];
- }
- if($is_spot == 2){
- $dmap2[] = ['a.day','=',$start];
- }
- $total = Db::name('dinner_order_item')
- ->alias('a')
- ->join('dinner b','a.dinner_id=b.id')
- ->join('dinner_type c','a.dinner_type_id=c.id')
- ->field('sum(a.num) as nums,b.name as dinner_name,c.color,c.name as dinner_type_name')
- ->where($dmap2)
- ->group('a.dinner_id')
- ->select();
- $items = '';
- foreach ($total as $k3=>$v3){
- $items.=$v3['dinner_name'].'('.$v3['dinner_type_name'].')'.'*'.$v3['nums'];
- if(count($total)>1 && $k3<count($total)-1){
- $items.=',';
- }
- }
- $data = [
- 'list'=>$lists,
- 'total'=>$items
- ];
- return $data;
- }
- public function print_all(){
- $data = $this->ex_type_data2();
- $this->assign('day',date('Y年m月d日'));
- $this->assign('data',$data);
- return $this->fetch();
- }
- public function ex_type_export2($data){
- $lists = $data['list'];
- $count = $data['total'];
- //实例化PHPExcel类
- include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
- $objPHPExcel = new \PHPExcel();
- //激活当前的sheet表
- $sheet = $objPHPExcel->setActiveSheetIndex(0);
- $titles = array('地址'=>30,'床号及备注'=>14,'姓名'=>10,'手机号'=>14,'餐别'=>8,'总价'=>8,'内容'=>60);
- $count_length = count($titles)-1;
- $objPHPExcel->setActiveSheetIndex(0)->setCellValueExplicit('A1', '分餐列表', \PHPExcel_Cell_DataType::TYPE_STRING);
- $sheet = sprintf('%s:%s', chr(65).'1', \PHPExcel_Cell::stringFromColumnIndex($count_length).'1');
- $objPHPExcel->setActiveSheetIndex(0)->mergeCells($sheet);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle($sheet)->getFont()->getColor($sheet)->setARGB(\PHPExcel_Style_Color::COLOR_BLACK);
- $as = $objPHPExcel->getActiveSheet();
- $as->getStyle($sheet)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $as->getStyle($sheet)->getFont()->setBold(true);
- $as->getStyle($sheet)->getFont()->setSize(18);
- $column=0;
- foreach ($titles as $key => $value) {
- $k = \PHPExcel_Cell::stringFromColumnIndex($column);
- $objPHPExcel->setActiveSheetIndex(0)->setCellValue($k.'2', $key);
- $objPHPExcel->getActiveSheet()->getColumnDimension($k)->setWidth($value);
- // $objPHPExcel->getActiveSheet()->getColumnDimension($k)->setAutoSize(true);
- $objPHPExcel->getActiveSheet(0)->getStyle($k.'2')->getFont()->setBold(true);
- $column++;
- }
- $num=3;
- $cell = $objPHPExcel->setActiveSheetIndex(0);
- // 订餐
- $dinner_order = array();
- foreach ($lists as $key => $value) {
- if(empty($value['item'])){
- continue;
- }
- $column = 0;
- // 床号
- $objPHPExcel->getActiveSheet()->getStyle(\PHPExcel_Cell::stringFromColumnIndex($column).$num)->getAlignment()->setWrapText(true)->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $cell->setCellValue(\PHPExcel_Cell::stringFromColumnIndex($column++).$num, $value['address'].' ');
- $objPHPExcel->getActiveSheet()->getStyle(\PHPExcel_Cell::stringFromColumnIndex($column).$num)->getAlignment()->setWrapText(true)->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $cell->setCellValue(\PHPExcel_Cell::stringFromColumnIndex($column++).$num, $value['remark'].' ');
- // 姓名
- $objPHPExcel->getActiveSheet()->getStyle(\PHPExcel_Cell::stringFromColumnIndex($column).$num)->getAlignment()->setWrapText(true)->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $cell->setCellValue(\PHPExcel_Cell::stringFromColumnIndex($column++).$num, $value['name']);
- $objPHPExcel->getActiveSheet()->getStyle(\PHPExcel_Cell::stringFromColumnIndex($column).$num)->getAlignment()->setWrapText(true)->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $cell->setCellValue(\PHPExcel_Cell::stringFromColumnIndex($column++).$num, $value['mobile'].' ');
- $objPHPExcel->getActiveSheet()->getStyle(\PHPExcel_Cell::stringFromColumnIndex($column).$num)->getAlignment()->setWrapText(true)->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $cell->setCellValue(\PHPExcel_Cell::stringFromColumnIndex($column++).$num, $value['tName']);
- // 总价
- $objPHPExcel->getActiveSheet()->getStyle(\PHPExcel_Cell::stringFromColumnIndex($column).$num)->getAlignment()->setWrapText(true)->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $cell->setCellValue(\PHPExcel_Cell::stringFromColumnIndex($column++).$num, $value['price'].' ');
- // 内容
- $objPHPExcel->getActiveSheet()->getStyle(\PHPExcel_Cell::stringFromColumnIndex($column).$num)->getAlignment()->setWrapText(true)->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $cell->setCellValue(\PHPExcel_Cell::stringFromColumnIndex($column++).$num, $value['item']);
- $num++;
- }
- $sheet = sprintf('%s:%s', chr(65).$num, \PHPExcel_Cell::stringFromColumnIndex($count_length).$num);
- $objPHPExcel->setActiveSheetIndex(0)->mergeCells($sheet);
- $objPHPExcel->getActiveSheet()->getStyle($sheet)->getAlignment()->setWrapText(true)->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER)->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle($sheet)->getFont()->setBold(20);
- $cell->setCellValue(\PHPExcel_Cell::stringFromColumnIndex(0).$num, '合计:'.$count);
- $styleThinBlackBorderOutline = array(
- 'borders' => array(
- 'allborders' => array( //设置全部边框
- 'style' => \PHPExcel_Style_Border::BORDER_THIN, //粗的是thick
- 'color' => array('argb' => 'FF000000'),
- ),
- ),
- );
- $count = \PHPExcel_Cell::stringFromColumnIndex($count_length).$num;
- // var_dump(sprintf('A1:%s',$count));exit;
- $objPHPExcel->getActiveSheet()->getStyle(sprintf('A1:%s', $count))->applyFromArray($styleThinBlackBorderOutline);
- //设置保存的Excel表格名称
- $filename = '分餐列表' . date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle('分餐列表');
- //设置浏览器窗口下载表格
- ob_end_clean();
- header("Content-Type: application/force-download");
- header("Content-Type: application/octet-stream");
- header("Content-Type: application/download");
- header('Content-Disposition:inline;filename="' . $filename);
- //生成excel文件
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- //下载文件在浏览器窗口
- return $objWriter->save('php://output');
- }
- public function exportTypeTj(){
- $start = input('start',date('Y-m-d'),'trim');
- $end = input('end',date('Y-m-d'),'trim');
- $data = $this->typeTjData($start,$end);
- //实例化PHPExcel类
- include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
- $objPHPExcel = new \PHPExcel();
- //激活当前的sheet表
- $sheet = $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '订餐日期')
- ->setCellValue('B1', '订单金额(元)')
- ->setCellValue('C1', '微信支付(元)')
- ->setCellValue('D1', '食堂卡(元)')
- ->setCellValue('E1', '现金(元)')
- ->setCellValue('F1', '订单数');
- // 设置表格头水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('I1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('J1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置列水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('I')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('J')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置单元格宽度
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('I')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('J')->setWidth(20);
- $lists = $data['a'];
- //循环刚取出来的数组,将数据逐一添加到excel表格。
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['title']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['a0']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['a1']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['a2']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['a3']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['a4']);
- }
- $objPHPExcel->getActiveSheet()->setCellValue('A' . (count($lists) + 2), '合计:');
- $objPHPExcel->getActiveSheet()->setCellValue('B' . (count($lists) + 2), $data['b']['b0']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . (count($lists) + 2), $data['b']['b1']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . (count($lists) + 2), $data['b']['b2']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . (count($lists) + 2), $data['b']['b3']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . (count($lists) + 2), $data['b']['b4']);
- //设置保存的Excel表格名称
- $filename = '订餐统计表' . date('YmdHis', time()) . '.xls';
- //设置浏览器窗口下载表格
- ob_end_clean();
- header("Content-Type: application/force-download");
- header("Content-Type: application/octet-stream");
- header("Content-Type: application/download");
- header('Content-Disposition:inline;filename="' . $filename);
- //生成excel文件
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- //下载文件在浏览器窗口
- return $objWriter->save('php://output');
- }
- public function orgasdinner(){
- $start = input('start',date('Y-m-d'),'trim');
- $end = input('end',date('Y-m-d'),'trim');
- $type = input('type',0);
- $orgId = input('org_id',0);
- $data = $this->orgasdinnerData($start,$end,$type,$orgId);
- $this->assign('total',$data['b']);
- $this->assign('data',$data['a']);
- $this->assign('start',$start);
- $this->assign('end',$end);
- $this->assign('type',$type);
- $this->assign('orgId',$orgId);
- $orgList = Db::name('org')
- ->where('del',0)
- ->where('enable',1)
- ->where('type',2)
- ->where('parent_id','>',0)
- ->select();
- $this->assign('orgList',$orgList);
- return $this->fetch();
- }
- public function orgasdinnerData($start,$end,$type,$orgId){
- $cate = input('cate/d',0);
- $this->assign('cate',$cate);
- if($orgId >0){
- $map[] = ['org_id','=',$orgId];
- }
- $map[] = ['cate','=',0];
- $map[] = ['state','<>',0];
- $map= empty($map) ? true: $map;
- //数据查询
- if($type==0){//按天
- $day = getDateFromRange($start,$end);
- $a = [];
- $b0 = $b1 = $b2=$b3=$b4=0;
- foreach ($day as $k=>$v){
- $a0 = Db::name($this->table)
- ->where($map)
- ->where('ymd',date('Ymd',strtotime($v)))
- ->column('id');
- if(empty($a0)){
- $k0 = 0;
- }else{
- $k0= Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a0)
- ->sum('a.price');
- }
- $b0+=$k0;
- $a1 = Db::name($this->table)
- ->where($map)
- ->where('ymd',date('Ymd',strtotime($v)))
- ->where('order_type',1)
- ->column('id');
- if(empty($a1)){
- $k1 = 0;
- }else{
- $k1 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a1)
- ->sum('a.price');
- }
- $b1+=$k1;
- $a2 = Db::name($this->table)
- ->where($map)
- ->where('ymd',date('Ymd',strtotime($v)))
- ->where('order_type',2)
- ->column('id');
- if(empty($a1)){
- $k2 = 0;
- }else{
- $k2 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a2)
- ->sum('a.price');
- }
- $b2+=$k2;
- $a3 = Db::name($this->table)
- ->where($map)
- ->where('ymd',date('Ymd',strtotime($v)))
- ->where('order_type',3)
- ->column('id');
- if(empty($a1)){
- $k3 = 0;
- }else{
- $k3 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a3)
- ->sum('a.price');
- }
- $b3+=$k3;
- $a4 = Db::name($this->table)
- ->where($map)
- ->where('ymd',date('Ymd',strtotime($v)))
- ->count();
- $b4+=$a4;
- $a[] = [
- 'title'=>$v,
- 'a0'=>$k0,
- 'a1'=>$k1,
- 'a2'=>$k2,
- 'a3'=>$k3,
- 'a4'=>$a4,
- ];
- }
- $b = [
- 'b0'=>$b0,
- 'b1'=>$b1,
- 'b2'=>$b2,
- 'b3'=>$b3,
- 'b4'=>$b4,
- ];
- }else{//按项目
- $map[] = ['ymd','>=',date('Ymd',strtotime($start))];
- $map[] = ['ymd','<=',date('Ymd',strtotime($end))];
- $ow = [];
- if($orgId >0){
- $ow[] = ['id','=',$orgId];
- }
- $day = Db::name('org')
- ->where('del',0)
- ->where('enable',1)
- ->where('type',2)
- ->where('parent_id','>',0)
- ->where($ow)
- ->select();
- $a = [];
- $b0 = $b1 = $b2=$b3=$b4=0;
- foreach ($day as $k=>$v){
- $a0 = Db::name($this->table)
- ->where($map)
- ->where('org_id',$v['id'])
- ->column('id');
- if(empty($a0)){
- $k0 = 0;
- }else{
- $k0= Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a0)
- ->sum('a.price');
- }
- $b0+=$k0;
- $a1 = Db::name($this->table)
- ->where($map)
- ->where('org_id',$v['id'])
- ->where('order_type',1)
- ->column('id');
- if(empty($a1)){
- $k1 = 0;
- }else{
- $k1 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a1)
- ->sum('a.price');
- }
- $b1+=$k1;
- $a2 = Db::name($this->table)
- ->where($map)
- ->where('org_id',$v['id'])
- ->where('order_type',2)
- ->column('id');
- if(empty($a1)){
- $k2 = 0;
- }else{
- $k2 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a2)
- ->sum('a.price');
- }
- $b2+=$k2;
- $a3 = Db::name($this->table)
- ->where($map)
- ->where('org_id',$v['id'])
- ->where('order_type',3)
- ->column('id');
- if(empty($a1)){
- $k3 = 0;
- }else{
- $k3 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a3)
- ->sum('a.price');
- }
- $b3+=$k3;
- $a4 = Db::name($this->table)
- ->where($map)
- ->where('org_id',$v['id'])
- ->count();
- $b4+=$a4;
- $a[] = [
- 'title'=>$v['name'],
- 'a0'=>$k0,
- 'a1'=>$k1,
- 'a2'=>$k2,
- 'a3'=>$k3,
- 'a4'=>$a4,
- ];
- }
- $b = [
- 'b0'=>$b0,
- 'b1'=>$b1,
- 'b2'=>$b2,
- 'b3'=>$b3,
- 'b4'=>$b4,
- ];
- }
- return ['a'=>$a,'b'=>$b];
- }
- public function exportorgasdinner(){
- $start = input('start',date('Y-m-d'),'trim');
- $end = input('end',date('Y-m-d'),'trim');
- $type = input('type',0);
- $orgId = input('org_id',0);
- $data = $this->orgasdinnerData($start,$end,$type,$orgId);
- //实例化PHPExcel类
- include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
- $objPHPExcel = new \PHPExcel();
- //激活当前的sheet表
- $sheet = $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', $type==0?'订餐日期':'项目')
- ->setCellValue('B1', '订单金额(元)')
- ->setCellValue('C1', '微信支付(元)')
- ->setCellValue('D1', '食堂卡(元)')
- ->setCellValue('E1', '现金(元)')
- ->setCellValue('F1', '订单数');
- // 设置表格头水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('I1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('J1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置列水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('I')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('J')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置单元格宽度
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('I')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('J')->setWidth(20);
- $lists = $data['a'];
- //循环刚取出来的数组,将数据逐一添加到excel表格。
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['title']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['a0']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['a1']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['a2']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['a3']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['a4']);
- }
- $objPHPExcel->getActiveSheet()->setCellValue('A' . (count($lists) + 2), '合计:');
- $objPHPExcel->getActiveSheet()->setCellValue('B' . (count($lists) + 2), $data['b']['b0']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . (count($lists) + 2), $data['b']['b1']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . (count($lists) + 2), $data['b']['b2']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . (count($lists) + 2), $data['b']['b3']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . (count($lists) + 2), $data['b']['b4']);
- //设置保存的Excel表格名称
- $filename = '各项目营业报表' . date('YmdHis', time()) . '.xls';
- //设置浏览器窗口下载表格
- ob_end_clean();
- header("Content-Type: application/force-download");
- header("Content-Type: application/octet-stream");
- header("Content-Type: application/download");
- header('Content-Disposition:inline;filename="' . $filename);
- //生成excel文件
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- //下载文件在浏览器窗口
- return $objWriter->save('php://output');
- }
- public function orgcasdinner(){
- $start = input('start',date('Y-m-d'),'trim');
- $end = input('end',date('Y-m-d'),'trim');
- $type = input('type',0);
- $orgId = input('org_id',0);
- $data = $this->orgcasdinnerData($start,$end,$type,$orgId);
- $this->assign('total',$data['b']);
- $this->assign('data',$data['a']);
- $this->assign('start',$start);
- $this->assign('end',$end);
- $this->assign('type',$type);
- $this->assign('orgId',$orgId);
- $orgList = Db::name('org')
- ->where('del',0)
- ->where('enable',1)
- ->where('type',2)
- ->where('parent_id','>',0)
- ->select();
- $this->assign('orgList',$orgList);
- return $this->fetch();
- }
- public function orgcasdinnerData($start,$end,$type,$orgId){
- $cate = input('cate/d',0);
- $this->assign('cate',$cate);
- if($orgId >0){
- $map[] = ['org_id','=',$orgId];
- }
- $map[] = ['state','<>',0];
- $map[] = ['cate','=',0];
- $map= empty($map) ? true: $map;
- //数据查询
- if($type==0){//按天
- $day = getDateFromRange($start,$end);
- $a = [];
- $b0 = $b1 = $b2=$b3=$b4=0;
- foreach ($day as $k=>$v){
- $a0 = Db::name($this->table)
- ->where($map)
- ->where('ymd',date('Ymd',strtotime($v)))
- ->column('id');
- if(empty($a0)){
- $k0 = 0;
- }else{
- $k0= Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a0)
- ->sum('a.price');
- }
- $b0+=$k0;
- $a1 = Db::name($this->table)
- ->where($map)
- ->where('ymd',date('Ymd',strtotime($v)))
- ->where('order_type',1)
- ->column('id');
- if(empty($a1)){
- $k1 = 0;
- }else{
- $k1 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a1)
- ->sum('a.price');
- }
- $b1+=$k1;
- $k2 = round($k1*0.006,2);
- $b2+=$k2;
- $a3 = Db::name($this->table)
- ->where($map)
- ->where('ymd',date('Ymd',strtotime($v)))
- ->where('order_type',2)
- ->column('id');
- if(empty($a3)){
- $k3 = 0;
- }else{
- $k3 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a3)
- ->sum('a.price');
- }
- $b3+=$k3;
- $a4 = Db::name($this->table)
- ->where($map)
- ->where('ymd',date('Ymd',strtotime($v)))
- ->where('order_type',3)
- ->column('id');
- if(empty($a1)){
- $k4 = 0;
- }else{
- $k4 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a4)
- ->sum('a.price');
- }
- $b4+=$k4;
- $a[] = [
- 'title'=>$v,
- 'a0'=>$k0,
- 'a1'=>$k1,
- 'a2'=>$k2,
- 'a3'=>$k3,
- 'a4'=>$k4,
- ];
- }
- $b = [
- 'b0'=>$b0,
- 'b1'=>$b1,
- 'b2'=>$b2,
- 'b3'=>$b3,
- 'b4'=>$b4,
- ];
- }else{//按项目
- $map[] = ['ymd','>=',date('Ymd',strtotime($start))];
- $map[] = ['ymd','<=',date('Ymd',strtotime($end))];
- $ow = [];
- if($orgId >0){
- $ow[] = ['id','=',$orgId];
- }
- $day = Db::name('org')
- ->where('del',0)
- ->where('enable',1)
- ->where('type',2)
- ->where('parent_id','>',0)
- ->where($ow)
- ->select();
- $a = [];
- $b0 = $b1 = $b2=$b3=$b4=0;
- foreach ($day as $k=>$v){
- $a0 = Db::name($this->table)
- ->where($map)
- ->where('org_id',$v['id'])
- ->column('id');
- if(empty($a0)){
- $k0 = 0;
- }else{
- $k0= Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a0)
- ->sum('a.price');
- }
- $b0+=$k0;
- $a1 = Db::name($this->table)
- ->where($map)
- ->where('org_id',$v['id'])
- ->where('order_type',1)
- ->column('id');
- if(empty($a1)){
- $k1 = 0;
- }else{
- $k1 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a1)
- ->sum('a.price');
- }
- $b1+=$k1;
- $k2 = round($k1*0.006,2);
- $b2+=$k2;
- $a3 = Db::name($this->table)
- ->where($map)
- ->where('org_id',$v['id'])
- ->where('order_type',2)
- ->column('id');
- if(empty($a3)){
- $k3 = 0;
- }else{
- $k3 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a3)
- ->sum('a.price');
- }
- $b3+=$k3;
- $a4 = Db::name($this->table)
- ->where($map)
- ->where('org_id',$v['id'])
- ->where('order_type',3)
- ->column('id');
- if(empty($a1)){
- $k4 = 0;
- }else{
- $k4 = Db::name('dinner_order_item')
- ->alias('a')
- ->where('a.is_refuse',0)
- ->where('a.order_id','in',$a4)
- ->sum('a.price');
- }
- $b4+=$k4;
- $a[] = [
- 'title'=>$v['name'],
- 'a0'=>$k0,
- 'a1'=>$k1,
- 'a2'=>$k2,
- 'a3'=>$k3,
- 'a4'=>$k4,
- ];
- }
- $b = [
- 'b0'=>$b0,
- 'b1'=>$b1,
- 'b2'=>$b2,
- 'b3'=>$b3,
- 'b4'=>$b4,
- ];
- }
- return ['a'=>$a,'b'=>$b];
- }
- public function exportorgcasdinner(){
- $start = input('start',date('Y-m-d'),'trim');
- $end = input('end',date('Y-m-d'),'trim');
- $type = input('type',0);
- $orgId = input('org_id',0);
- $data = $this->orgcasdinnerData($start,$end,$type,$orgId);
- //实例化PHPExcel类
- include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
- $objPHPExcel = new \PHPExcel();
- //激活当前的sheet表
- $sheet = $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', $type==0?'订餐日期':'项目')
- ->setCellValue('B1', '订单金额(元)')
- ->setCellValue('C1', '微信支付(元)')
- ->setCellValue('D1', '微信手续费0.6%(元)')
- ->setCellValue('E1', '食堂卡(元)')
- ->setCellValue('F1', '现金(元)');
- // 设置表格头水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('I1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('J1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置列水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('I')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('J')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置单元格宽度
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('I')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('J')->setWidth(20);
- $lists = $data['a'];
- //循环刚取出来的数组,将数据逐一添加到excel表格。
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['title']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['a0']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['a1']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['a2']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['a3']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['a4']);
- }
- $objPHPExcel->getActiveSheet()->setCellValue('A' . (count($lists) + 2), '合计:');
- $objPHPExcel->getActiveSheet()->setCellValue('B' . (count($lists) + 2), $data['b']['b0']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . (count($lists) + 2), $data['b']['b1']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . (count($lists) + 2), $data['b']['b2']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . (count($lists) + 2), $data['b']['b3']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . (count($lists) + 2), $data['b']['b4']);
- //设置保存的Excel表格名称
- $filename = '各项目财务报表' . date('YmdHis', time()) . '.xls';
- //设置浏览器窗口下载表格
- ob_end_clean();
- header("Content-Type: application/force-download");
- header("Content-Type: application/octet-stream");
- header("Content-Type: application/download");
- header('Content-Disposition:inline;filename="' . $filename);
- //生成excel文件
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- //下载文件在浏览器窗口
- return $objWriter->save('php://output');
- }
- public function refund($id=0){
- $info = Db::name('dinner_order')->where('org_id',$this->orgId)->where('id',$id)->find();
- if(request()->isPost()){
- if(!$info){
- $this->error('订单不存在');
- }
- if($info['cate'] != 1){
- $this->error('特殊套餐才能退餐');
- }
- $days = input('days','','trim');
- $remark = input('remark','','trim');
- if(!$days){
- $this->error('请选择退餐日期');
- }
- $days = explode(',',$days);
- $olddays = Db::name('dinner_order_item')->where('order_id',$id)->where('is_refuse',0)->group('day')->distinct(true)->column('day');
- $olddays = $olddays?$olddays:[];
- foreach ($days as $v){
- if(!in_array($v,$olddays)){
- $this->error($v.'已退餐,勿重复操作');
- }
- }
- $dinners = Db::name('dinner_order_item')
- ->where('order_id',$id)
- ->where('day','in',$days)
- ->where('is_refuse',0)
- ->select();
- Db::startTrans();
- try{
- Db::name('dinner_order_item')
- ->where('order_id',$id)
- ->where('day','in',$days)
- ->update(['is_refuse'=>1,'refuse_time'=>date('Y-m-d H:i:s')]);
- $rid = Db::name('dinner_order_refuse')->insertGetId([
- 'dinner_order_id'=>$id
- ,'refuse_price'=>0
- ,'refuse_y'=>date('Y')
- ,'refuse_ymd'=>date('Ymd')
- ,'refuse_ym'=>date('Ym')
- ,'created_user_id'=>$this->userId
- ,'create_time'=>date('Y-m-d H:i:s')
- ,'refuse_w'=>date('Y').date('W')
- ,'order_type'=>$info['order_type']
- ,'is_replace'=>$info['is_replace']
- ,'org_id'=>$this->orgId
- ,'status'=>5
- ,'op_user_id'=>$this->userId
- ,'op_time'=>date('Y-m-d H:i:s')
- ,'refuse_remark'=>$remark
- ]);
- if(!$rid){
- \exception('操作失败');
- }
- $items = [];
- foreach ($dinners as $k=>$v){
- $items[] = [
- 'dinner_id' => $v['dinner_id'],
- 'order_refuse_id' => $rid,
- 'price'=>$v['price'],
- 'num'=>$v['num'],
- 'dinner_type_id'=>$v['dinner_type_id'],
- 'day' => $v['day'],
- 'group_id' => $v['group_id']
- ];
- }
- $rr = Db::name('dinner_order_refuse_item')->insertAll($items);
- if(!$rr){
- \exception('操作失败');
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success('操作成功');
- }else{
- if(!$info){
- exit('订单不存在');
- }
- if($info['cate'] != 1){
- exit('特殊套餐才能退餐');
- }
- $days = Db::name('dinner_order_item')->where('order_id',$id)->where('is_refuse',0)->group('day')->distinct(true)->column('day');
- $news = [];
- foreach ($days as $v){
- $news[] = ['id'=>$v,'title'=>$v];
- }
- $this->assign('days',$news);
- $this->assign('id',$id);
- return $this->fetch();
- }
- }
- }
|