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

<?php

namespace App\Repository;

use App\Model\Allot;
use App\Model\AllotDetail;
use App\Model\AllotSkuBatch;
use App\Repository\CommonRepository; class AllotRepository extends CommonRepository
{
/**
* @var array
*/
protected $fieldSearchable = [
'allot_id',
]; /**
* Configure the Model
**/
public function model()
{
return Allot::class;
} public function search($param = [])
{ $model = $this->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

<div class="box" style="overflow-x:scroll;">
<div class="box-body">
<table class="table table-bordered table-hover lastTd" id="allots-table" style="font-size:12px;">
<thead>
<tr class="nowrap">
<th>调拨单号</th>
<th>制单时间</th>
<th>调出仓库</th> <th>商品SKU</th>
<th>商品名称</th>
<th>商品属性</th>
<th>单位</th>
<th>调拨数量</th> <th>调入仓库</th>
<th>调拨备注</th>
<th>审核状态</th>
<th>审核人</th>
<th>是否出库</th>
<th>是否入库</th>
<th style="width:135px;min-width:135px;">操作</th>
</tr>
</thead>
<tbody>
@foreach($allots as $allot)
<?php
if(isset($param['goods_name']) && !empty($param['goods_name'])){
$detail = $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); ?>
<tr>
<td {!! $rowspan !!}>{!! $allot->allot_sn !!}</td>
<td {!! $rowspan !!}>{!! $allot->created_at !!}</td>
<td {!! $rowspan !!}>{!! $allot['out_ware']['name'] !!}</td> <td>{!! !empty($first_detail) ? $first_detail->change_sku : '--' !!}</td>
<td>{!! !empty($first_detail) ? $first_detail->sku->goods->goods_name : '--' !!}</td>
<td>{!! !empty($first_detail) ? $first_detail->sku->value_name : '--' !!}</td>
<td>{!! !empty($first_detail) ? $first_detail->sku->goods->goods_unit : '--' !!}</td>
<td>{!! !empty($first_detail) ? $first_detail->send_number : '--' !!}</td> <td {!! $rowspan !!}>{!! $allot['entry_ware']['name'] !!}</td>
<td {!! $rowspan !!}>{!! $allot->remark !!}</td>
<td {!! $rowspan !!}>
<small class="label pull-left bg-blue">{!! config('const.ware.entry_status')[$allot->status] !!}</small>
</td>
<td {!! $rowspan !!}>{!! $allot->confirm_admin_name ? $allot->confirm_admin_name : '--'!!}</td>
<td {!! $rowspan !!}>{!! config('const.ware.entry_or_out_ware')[$allot->out_ware_status] !!}</td>
<td {!! $rowspan !!}>{!! config('const.ware.entry_or_out_ware')[$allot->entry_ware_status] !!}</td>
<td {!! $rowspan !!}>
{!! Form::open(['route' => ['admin.allots.destroy', $allot->getKey()], 'method' => 'delete']) !!}
<div class='btn-group'>
<a href="@if($allot->status==1) javascript:; @else {!! route('admin.allots.edit', [$allot->getKey()]) !!} @endif"
class='btn btn-default btn-xs' @if($allot->status==1) disabled="disabled" @endif title="编辑" alt="编辑"><i class="fa fa-edit"></i></a>
<a href="@if($allot->status==1) javascript:; @else{!! route('admin.allots.examine', [$allot->getKey()]) !!} @endif"
class='btn btn-default btn-xs' @if($allot->status==1) disabled="disabled" @endif title="审核" alt="审核"><i class="fa fa-user"></i></a> <a href="@if($allot->is_out_ware == 1 || $from_admin_ware ==0)javascript:; @else {!! route('admin.allots.out_ware', [$allot->getKey()]) !!} @endif"
class='btn btn-default btn-xs' @if($allot->is_out_ware==1 ||$allot->status==0 || $from_admin_ware ==0) disabled="disabled" @endif title="办理出库" alt="办理出库"><i class="fa fa-share"></i></a> <a href="@if($allot->entry_ware_status == 1 || $allot->out_ware_status==0 || $allot->is_entry_ware==1 || $to_admin_ware == 0) javascript:; @else {!! route('admin.allots.entry_ware', [$allot->getKey()]) !!} @endif"
class='btn btn-default btn-xs' @if($allot->entry_ware_status==1 || $allot->out_ware_status==0 ||$allot->is_entry_ware==1 || $to_admin_ware == 0) disabled="disabled" @endif title="办理入库" alt="办理入库"><i class="fa fa-reply"></i></a> <a @if($allot->status > 0) disabled="disabled" @endif href="{!! route('admin.allots.destroy', [$allot->getKey()]) !!}" title="删除" alt="删除" class='btn btn-default btn-xs'><i class="fa fa-trash"></i></a>
</div>
{!! Form::close() !!}
</td>
</tr> @if($rowspan != '')
@foreach($detail as $row)
<tr>
<td>{{ $row->change_sku }}</td>
<td>{{ $row->sku->goods->goods_name }}</td>
<td>{{ $row->sku->value_name }}</td>
<td>{{ $row->sku->goods->goods_unit }}</td>
<td>{{ $row->send_number }}</td>
</tr>
@endforeach
@endif
@endforeach
</tbody>
</table>
</div>
</div>

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

PHP如何输出合并单元格的表的更多相关文章

  1. 议:如何将树形菜单形式的数据转化成HTML的二维表(相同内容需合并单元格)

    一般做OA类管理系统,经常涉及到“组织架构”的概念,那么像这种有上下层级关系的数据一般会做成树形菜单的方式显示,底层代码必定会用到递归算法.这篇随笔的目的就是要谈谈除了用树形菜单来显示这种上下层级关系 ...

  2. NPOI扩展--判断指定单元格是否为合并单元格和输出该单元格的行列跨度(维度)

    因工作需要用到跨合并单元格获取数据,所以写了个NPOI扩展类. 主要方法如下: 1.判断指定行/列索引(单元格)是否为合并单元格. 2.获取指定列索引的实际含有数据的单元格. 3.返回指定行/列索引的 ...

  3. Java导出Excel表,POI 实现合并单元格以及列自适应宽度(转载)

    POI是apache提供的一个读写Excel文档的开源组件,在操作excel时常要合并单元格,合并单元格的方法是: sheet.addMergedRegion(new CellRangeAddress ...

  4. C# 获取Excel中的合并单元格

    C# 获取Excel中的合并单元格 我们在制作表格时,有时经常需要合并及取消合并一些单元格.在取消合并单元格时需要逐个查找及取消,比较麻烦.这里分享一个简单的方法来识别Excel中的合并单元格,识别这 ...

  5. 带复杂表头合并单元格的HtmlTable转换成DataTable并导出Excel

    步骤: 一.前台JS取HtmlTable数据,根据设定的分隔符把数据拼接起来 <!--导出Excel--> <script type="text/javascript&qu ...

  6. PHPEXCEL xls模板导入,及格式自定义:合并单元格、加粗、居中等操作

    PHPExcel 是用来操作Office Excel 文档的一个PHP类库,它基于微软的OpenXML标准和PHP语言.可以使用它来读取.写入不同格式的电子表格,如 Excel (BIFF) .xls ...

  7. 20170622xlVBA多部门分类汇总同类合并单元格

    Public Sub Basic_CodeFrame() AppSettings On Error GoTo ErrHandler Dim StartTime, UsedTime As Variant ...

  8. 在Asp.Net MVC中使用NPOI插件实现对Excel的操作(导入,导出,合并单元格,设置样式,输入公式)

    前言 NPOI 是 POI 项目的.NET版本,它不使用 Office COM 组件,不需要安装 Microsoft Office,目前支持 Office 2003 和 2007 版本. 1.整个Ex ...

  9. jquery操作表格 合并单元格

    jquery操作table,合并单元格,合并相同的行 合并的方法 $("#tableid").mergeCell({ cols:[X,X] ///参数为要合并的列}) /** * ...

随机推荐

  1. HDFS命名空间管理

  2. chown权限命令

    chown 命令用途更改与文件关联的所有者或组. 语法chown[  -f ] [ -h] [  -R ] Owner [ :Group ] { File ... | Directory ... } ...

  3. Linux User and Group Management

    linux is a multi-user and multitasking OS. In Linux, you can create any number of user account and g ...

  4. Python缩进和选择

    Python缩进和选择 缩进 Python最具特色的是用缩进来标明成块的代码.我下面以if选择结构来举例.if后面跟随条件,如果条件成立,则执行归属于if的一个代码块. 先看C语言的表达方式(注意,这 ...

  5. 【同余最短路】洛谷 P2662 牛场围栏

    关于同余最短路的部分 [同余最短路]P3403跳楼机/P2371墨墨的等式 [P2662牛场围栏] 题目背景 小L通过泥萌的帮助,成功解决了二叉树的修改问题,并因此写了一篇论文, 成功报送了叉院(羡慕 ...

  6. JSP-response(HttpServletResponse)

    1 HttpServletResponse概述 2 Response 运行过程 3 通过抓包工具抓取Http响应 4 响应行 5 设置响应头 set  和add的区别 6 重定向 需要完成分析‘ 6 ...

  7. ROWID的使用——快速删除重复的记录

    ROWID是数据的详细地址,通过rowid,oracle可以快速的定位某行具体的数据的位置.ROWID可以分为物理rowid和逻辑rowid两种.普通的表中的rowid是物理rowid,索引组织表(I ...

  8. NOIP模拟赛 6.29

    2017-6-29 NOIP模拟赛 Problem 1 机器人(robot.cpp/c/pas) [题目描述] 早苗入手了最新的Gundam模型.最新款自然有着与以往不同的功能,那就是它能够自动行走, ...

  9. Leetcode55. Jump Game跳跃游戏

    给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] 输出: true ...

  10. Leetcode665.Non-decreasing Array非递减数组

    给定一个长度为 n 的整数数组,你的任务是判断在最多改变 1 个元素的情况下,该数组能否变成一个非递减数列. 我们是这样定义一个非递减数列的: 对于数组中所有的 i (1 <= i < n ...