PHP如何输出合并单元格的表

PHP如何输出合并单元格的表

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

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

 

部分效果图如下

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>

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/112908.html原文链接:https://javaforall.net

(0)
上一篇 2021年10月28日 上午6:00
下一篇 2021年10月28日 上午7:00


相关推荐

  • c#windowsform应用_js调用webservice

    c#windowsform应用_js调用webserviceC#WinForm调用javaWebService开发环境Webservice:Eclipse202009+jdk11+Tomcat9WinForm:VS2019WebService搭建打开Eclipse,File->New->DynamicWebproject

    2022年10月16日
    5
  • vue中输入框事件的使用——@input、@keyup.enter、@change、@blur「建议收藏」

    vue中输入框事件的使用——@input、@keyup.enter、@change、@blur「建议收藏」一、@input(或者是v-on:input)使用:&lt;inputtype="text"placeholder="通过乘车人/订单号查询"v-model="inputVal"v-on:input="search"value=""/&gt;适用于实时查询,每输入一个字符都会触发该事件。如图:二、@keyup.enter该事件与v-on:input事件的区别在于:i

    2022年4月30日
    147
  • DSP28335数据类型

    DSP28335数据类型最近在用 DSP28335 时 发现数据类型与 ARM 体系的数据类型有些差异 做了以下测试 来确定 DSP28335 上数据类型的大小 nbsp nbsp nbsp nbsp nbsp 28335 单位中长度为是 16bit nbsp nbsp count sizeof char nbsp nbsp count sizeof int nbsp nbsp count nbsp sizeof double nbsp count nbsp sizeof long nbsp nbsp c

    2026年3月26日
    2
  • PCI和PCIE插槽有什么区别?[通俗易懂]

    PCI和PCIE插槽有什么区别?[通俗易懂]PCI是PeripheralComponentInterconnect(外设部件互连标准)的缩写,它是目前个人电脑中使用最为广泛的接口,几乎所有的主板产品上都带有这种插槽。PCI插槽也是主板带有最多数量的插槽类型,在目前流行的台式机主板上,ATX结构的主板一般带有5~6个PCI插槽,而小一点的MATX主板也都带有2~3个PCI插槽,可见其应用的广泛性。PCI是由Intel公司1991年推出的一

    2022年6月29日
    65
  • js 字符串转json对象_json字符串转java对象

    js 字符串转json对象_json字符串转java对象js对象转json字符串将js对象转为json格式的字符串,可以用JSON.stringify方法。varuser1={‘height’:170,’name’:’张三’};varuser1Str=JSON.stringify(user1)console.info(user1Str)typeofuser1Str使用typeof来获取对象user1Str的类型,能看到控制台输出的user1的值以及它的类型string。{“height”:170,“name”:“张三”}“s

    2025年12月16日
    4
  • QT之QFile[通俗易懂]

    QT之QFile[通俗易懂]1、QFile::QFile()构造一个没有名字的QFile对象2、QFile::QFile(constQString&name)构造一个以name为文件名的QFile对象。注:也可以QFile::QFile(),然后调用setName()方法来实现类似动作。3、bootQFile::atEnd()const[虚函数]如果已经到达文件末尾则返回TR

    2022年6月8日
    49

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号