常见问题:ECJia到家:如何修改到家小票机的小票模板内容

来自ECJiaWiki
跳转至: 导航搜索


小票机后台设置

  • 进入商家后台:店铺-小票机,对应的模板都开启,方便后续小票自动打印
如何修改到家小票打印机的小票模板内容01.png

对应模板位置

模板名称 模板代号 入驻商家
普通订单小票 print_buy_orders content/apps/printer/classes/Events/PrintBuyOrders.php
外卖订单小票 print_takeaway_orders content/apps/printer/classes/Events/PrintTakeawayOrders.php
到店购物小票 print_store_orders content/apps/printer/classes/Events/PrintStoreOrders.php
优惠买单小票 print_quickpay_orders content/apps/printer/classes/Events/PrintQuickpayOrders.php
订单退款小票 print_refund_orders content/apps/printer/classes/Events/PrintRefundOrders.php
会员充值小票 print_surplus_orders content/apps/printer/classes/Events/PrintSurplusOrders.php

修改模板中的固定值

  • 这里以修改到店购物订单小票为例,修改效果为在电话号码下面加上【门店自提】字样。找到content/apps/printer/classes/Events/PrintStoreOrders.php文件
  • 添加这行代码
    <FS><center>门店自提</center></FS>
    
如何修改到家小票打印机的小票模板内容02.png
  • 部分模板代码如下
public function getTemplate()
{
   if (empty($this->template)) {
            $this->template = '${print_number}<FS><center>${merchant_name}</center></FS>
<FS><center>${merchant_mobile}</center></FS>
<FS><center>门店自提</center></FS>
订单编号:${order_sn}
流水编号:${order_trade_no}
下单时间:${purchase_time}
商家地址:${merchant_address}
--------------------------------
${goods_lists}
--------------------------------
红包抵扣:-${bonus}
积分抵扣:-${integral_money}
优惠金额:-${discount_amount}
应收金额:${receivables}
实收金额:${order_amount}
${payment}:${order_amount}
                            		
<QR>${qrcode}</QR>
${tail_content}';
        }
        return $this->template;
    }
}


修改模板中的变量

  • 这里以在商品名称后添加货号为例。由于逐个模板修改比较复杂,这里根据阅读代码,找到商品列表实际为content/apps/printer/classes/Events/PrintStoreOrders.php文件中的goods_lists变量,从源头修改goods_lists变量,这样每个模板调用goods_lists的时候都会自动加上货号。
  • 找到getGoodsList方法,路径为:content/apps/orders/classes/OrderPrint.php,修改代码如下:
'goods_name'   => $row['goods_name'] .'['. $row['goods_sn'].']',
如何修改到家小票打印机的小票模板内容03.png


  • 完整的getGoodsList方法代码如下:
 /**
     * 获取商品列表
     * @return array
     */
    public function getGoodsList()
    {
        $goods_list = array();

        $data = RC_DB::table('order_goods as o')
            ->leftJoin('products as p', RC_DB::raw('p.product_id'), '=', RC_DB::raw('o.product_id'))
            ->leftJoin('goods as g', RC_DB::raw('o.goods_id'), '=', RC_DB::raw('g.goods_id'))
            ->select(RC_DB::raw('o.*'), RC_DB::raw("IF(o.product_id > 0, p.product_number, g.goods_number) AS storage"), RC_DB::raw('o.goods_attr'), RC_DB::raw('g.suppliers_id'), RC_DB::raw('p.product_sn'), RC_DB::raw('g.goods_img'), RC_DB::raw('g.goods_sn as goods_sn'))
            ->where(RC_DB::raw('o.order_id'), $this->order_id)
            ->get();

        if (!empty($data)) {
            foreach ($data as $key => $row) {
                $row['formated_subtotal']    = price_format($row['goods_price'] * $row['goods_number']);
                $row['formated_goods_price'] = price_format($row['goods_price']);
                if (!empty($row['goods_attr'])) {
                    $row['goods_attr'] = trim($row['goods_attr']);
                    $row['goods_name'] .= '【' . $row['goods_attr'] . '】';
                }
                $goods_list[] = array(
                    'goods_name'   => $row['goods_name'] .'['. $row['goods_sn'].']',
                    'goods_number' => $row['goods_number'],
                    'goods_amount' => $row['goods_price'],
                );
            }
        }

        return $goods_list;
    }

测试

  1. 小票机的打印结果测试需要用户在商城内下单,然后小票机打印订单后,查看效果
  2. 或者在小票机打印后,在商家后台,店铺-小票机-打印记录-查看打印内容