博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP如何输出合并单元格的表
阅读量:6002 次
发布时间:2019-06-20

本文共 9119 字,大约阅读时间需要 30 分钟。

https://mp.weixin.qq.com/s/ChPIKIv9tqmuqGyfc9Zi7Q

合并单元格的表,很多地方可以见到,比如购物车,订单合并等,今天给大家讲解一下,如何操作,虽然我用的laravel,但是都是PHP。以下只做参考!

 

部分效果图如下

路由文件

 Route::get('admin/allots/index', ['as'=> 'admin.allots.index', 'uses' => 'AllotController@index']); 

控制器文件:AllotController.php

/**     * Display a listing of the Allot.     *     * @param Request $request     * @return Response     */    public function index(Request $request)    {        $param  = $request->all();        $params  = [            'orderBy' => ['allot_id', 'desc'],            'groupBy' => 'allot_sn'        ];        $params['left_join'][] = ['allot_detail','allot.allot_id','=','allot_detail.allot_id'];        $params['left_join'][] = ['goods_sku','allot_detail.sku_id','=','goods_sku.sku_id'];        $params['left_join'][] = ['goods','goods_sku.goods_id','=','goods.goods_id'];        $params['select']   = [            'allot.*',            'allot_detail.sku_id',            'goods_sku.sku_id',            'goods_sku.goods_id',            'goods.goods_id',            'goods.goods_name'        ];        if(!empty($param['goods_name'])){            $params['where'] = $this->entryWareRepository->getLikeGoods(trim($param['goods_name']));            $search_sku_id = $this->entryWareRepository->getLikeSkuID(trim($param['goods_name']));        }        //用户所属对应仓库的信息        $admin_ware = $this->allotRepository->getAdminWare();        if($admin_ware > 0){            $params['whereIn'] = ['allot.from_ware_id', $admin_ware];        }        $this->allotRepository->pushCriteria(new RequestCriteria($request));        $allots = $this->allotRepository->paginate(config('config.pagesize'),[            'detail.sku.goods','out_ware','entry_ware'        ],$params);        $allots->each(function($item,$key){            $item->is_out_ware = count($this->allotRepository->out_ware($item->allot_sn));            $item->is_entry_ware = count($this->allotRepository->entry_ware($item->allot_sn));        });        foreach ($allots as $val){            $val->detail->each(function($vo,$k){                $vo->change_sku = $vo->sku->getShowSku();            });        }        //dd($allots);        return view('admin.allots.index', compact('allots','admin_ware','param'));    }

model文件:Allot.php

class Allot extends Model{    public $table = 'allot';    const CREATED_AT = 'created_at';    const UPDATED_AT = 'updated_at';    protected $primaryKey = 'allot_id';    public $fillable = [        'allot_sn',        'remark',        'status',        'from_ware_id',        'to_ware_id',        'create_admin_id',        'create_admin_name',        'examine_admin_id',        'examine_admin_name',        'entry_ware_status',        'out_ware_status',        'confirm_admin_id',        'confirm_admin_name'    ];    /**     * The attributes that should be casted to native types.     *     * @var array     */    protected $casts = [        'allot_id' => 'integer',        'allot_sn' => 'string',        'remark' => 'string',        'status' => 'integer',        'from_ware_id' => 'integer',        'to_ware_id' => 'integer',        'create_admin_id' => 'integer',        'create_admin_name' => 'string',        'examine_admin_id' => 'integer',        'examine_admin_name' => 'string',        'confirm_admin_id' => 'integer',        'confirm_admin_name' => 'string',        'entry_ware_status' =>'integer',        'out_ware_status' => 'integer',    ];    /**     * Validation rules     *     * @var array     */    public static $rules = [    ];

容器文件:AllotRepository.php

model(); $model = new $model; $rs = $model; if (!empty($param['goods_name'])) { $rs = $model->where('goods_name', '=', $param['goods_name']); } //创建时间开始 if (!empty($param['add_time_start'])) { $rs = $rs->where('created_at', '>=', $param['created_at'] . ' 00:00:00'); } //创建时间结束 if (!empty($param['add_time_end'])) { $rs = $rs->where('created_at', '<=', $param['created_at'] . ' 23:59:59'); } return $rs; } /** * Function:自动生成入单号 * User:wucy * @return string */ public function createAllotSn() { $model = $this->model(); $allot_id = $model::max('allot_id'); $date = date('Ymd',time()); $allot_id = $allot_id +1; $allot_sn = 'A' .$date. str_repeat('0', 8 - strlen($allot_id)) . $allot_id; $sn_list = $model::where('allot_sn','like','%'.$allot_id.'%')->where('allot_id','<>',$allot_id)->get()->toArray(); if (in_array($allot_sn, $sn_list)) { $max = pow(10, strlen($sn_list[0]) - strlen($allot_sn) + 1) - 1; $new_sn = $allot_sn . mt_rand(0, $max); while (in_array($new_sn, $sn_list)) { $new_sn = $allot_sn . mt_rand(0, $max); } $allot_sn = $new_sn; } return $allot_sn; }

模板文件table.blade.php

@foreach($allots as $allot)
detail->whereInLoose('sku_id',$search_sku_id); }else{ $detail = $allot->detail; } $count = count($detail); $rowspan = $count == 1 ? '' : "rowspan='{
$count}'"; //单元格合并 $first_detail = $detail->shift(); $admin_id = Auth::id(); if(($admin_ware > 0 && in_array( $allot->from_ware_id,$admin_ware)) || $admin_ware==0){ $from_admin_ware =1; }else{ $from_admin_ware =0; } if(($admin_ware > 0 && in_array( $allot->to_ware_id,$admin_ware)) || $admin_ware==0){ $to_admin_ware =1; }else{ $to_admin_ware =0; } //dd($from_admin_ware); ?>
@if($rowspan != '') @foreach($detail as $row)
@endforeach @endif @endforeach
调拨单号 制单时间 调出仓库 商品SKU 商品名称 商品属性 单位 调拨数量 调入仓库 调拨备注 审核状态 审核人 是否出库 是否入库 操作
{!! $allot->allot_sn !!} {!! $allot->created_at !!} {!! $allot['out_ware']['name'] !!} {!! !empty($first_detail) ? $first_detail->change_sku : '--' !!} {!! !empty($first_detail) ? $first_detail->sku->goods->goods_name : '--' !!} {!! !empty($first_detail) ? $first_detail->sku->value_name : '--' !!} {!! !empty($first_detail) ? $first_detail->sku->goods->goods_unit : '--' !!} {!! !empty($first_detail) ? $first_detail->send_number : '--' !!} {!! $allot['entry_ware']['name'] !!} {!! $allot->remark !!} {!! config('const.ware.entry_status')[$allot->status] !!} {!! $allot->confirm_admin_name ? $allot->confirm_admin_name : '--'!!} {!! config('const.ware.entry_or_out_ware')[$allot->out_ware_status] !!} {!! config('const.ware.entry_or_out_ware')[$allot->entry_ware_status] !!} { !! Form::open(['route' => ['admin.allots.destroy', $allot->getKey()], 'method' => 'delete']) !!}
{ !! Form::close() !!}
{ { $row->change_sku }} { { $row->sku->goods->goods_name }} { { $row->sku->value_name }} { { $row->sku->goods->goods_unit }} { { $row->send_number }}

一个功能模块包括增删改查,贴出来的代码会很多!这里只贴出列表的功能,有问题的可以留言

转载地址:http://egbmx.baihongyu.com/

你可能感兴趣的文章
Python获取当前页面内的所有链接的五种方法
查看>>
【进阶2-3期】JavaScript深入之闭包面试题解
查看>>
【Chrome扩展开发】定制HTTP请求响应头域
查看>>
利用 CocoaPod 和 Git 管理组件中的一些细节梳理
查看>>
聊聊storm trident spout的_maxTransactionActive
查看>>
面向Vue新人:写一个简单的倒计时按钮
查看>>
区块链初体验
查看>>
关于手势处理
查看>>
super
查看>>
5G美洲白皮书:5G开源的现状(pdf)
查看>>
世界移动通信大会
查看>>
基于Spring Security Role过滤Jackson JSON输出内容
查看>>
从设计者的角度看 React
查看>>
js常见问题
查看>>
CentOS6系统编译部署LAMP(Linux, Apache, MySQL, PHP)环境
查看>>
71. Simplify Path
查看>>
海量大数据大屏分析展示一步到位:DataWorks数据服务对接DataV最佳实践
查看>>
PAT A1043
查看>>
JavaScript之手写Promise
查看>>
PHP_SELF变量解析和重复路径解决
查看>>