Browse Source

打印订单

master
Lemon 5 years ago
parent
commit
ac19c6e4cc
  1. 76
      app/Commons/TencentMap.php
  2. 6
      app/Constants/v3/ErrorCode.php
  3. 8
      app/Model/v3/OrderGoods.php
  4. 9
      app/Service/v3/Implementations/AppointmentTimeService.php
  5. 30
      app/Service/v3/Implementations/FeiePrintService.php
  6. 12
      composer.lock

76
app/Commons/TencentMap.php

@ -0,0 +1,76 @@
<?php
namespace App\Commons;
use Hyperf\Guzzle\ClientFactory;
class TencentMap
{
/**
* @var \Hyperf\Guzzle\ClientFactory
*/
private $clientFactory;
public function __construct(ClientFactory $clientFactory)
{
$this->clientFactory = $clientFactory;
}
public function getClient()
{
// $options 等同于 GuzzleHttp\Client 构造函数的 $config 参数
$options = [
'timeout' => 2.0,
];
// $client 为协程化的 GuzzleHttp\Client 对象
$client = $this->clientFactory->create($options);
return $client;
}
public function event($labels=null,$datas){
co(function () use ($labels,$datas){
$client = $this->getClient();
$kv = [];
foreach ($datas as $key => $value) {
$kv[] = $key."=".$value;
}
$pushLabels = [];
$event_name = 'event_'.env('APP_ENV');
if(!empty($labels)) $pushLabels[$event_name] = $labels;
/*
* data format:
curl -v -H "Content-Type: application/json" -XPOST -s "http://39.96.12.39:3100/loki/api/v1/push" --data-raw \
'{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1596274538882028800", "fizzbuzz" ] ] }]}'
*/
$ts = $this->getMsecTime() . '000000';
$datas = implode("&",$kv);
$values = [[$ts,$datas]];
$app_name = env('APP_NAME').'_'.env('APP_ENV');
$pushLabels['app']= $app_name;
$pushDatas = [
'streams'=>[
[
'stream'=>$pushLabels,
'values'=>$values,
]
]
];
$client->post(
env('LOG_HOST','http://39.96.12.39:3100').'/loki/api/v1/push',
[
'headers'=>[
'Content-Type'=>'application/json'
],
'body' => json_encode($pushDatas)
]
);
//var_dump(json_encode($pushDatas) );
});
}
}

6
app/Constants/v3/ErrorCode.php

@ -156,6 +156,12 @@ class ErrorCode extends AbstractConstants
*/ */
const STORE_REST = 709; const STORE_REST = 709;
/**
* 商户已休息
* @Message("服务站已休息")
*/
const MARKET_REST = 710;
/************************************/ /************************************/
/* 定位相关 751-800 */ /* 定位相关 751-800 */
/************************************/ /************************************/

8
app/Model/v3/OrderGoods.php

@ -14,7 +14,8 @@ class OrderGoods extends Model
]; ];
protected $appends = [ protected $appends = [
'tags'
'tags',
'name_unit'
]; ];
protected $fillable = [ protected $fillable = [
@ -52,4 +53,9 @@ class OrderGoods extends Model
{ {
return Goods::query()->where(['id' => $this->attributes['goods_id']])->value('tags'); return Goods::query()->where(['id' => $this->attributes['goods_id']])->value('tags');
} }
public function getNameUnitAttribute()
{
return $this->attributes['name'] . ' ' . $this->attributes['goods_unit'];
}
} }

9
app/Service/v3/Implementations/AppointmentTimeService.php

@ -43,13 +43,18 @@ class AppointmentTimeService implements AppointmentTimeServiceInterface
$time4Arr = []; $time4Arr = [];
$nowTime = time(); $nowTime = time();
//服务站最晚营业时间 //服务站最晚营业时间
$closedTime = strtotime('19:30');
if (env('APP_ENV') === 'prod') {
$closedTime = strtotime('19:30');
if($nowTime > $closedTime){
throw new ErrorCodeException(ErrorCode::MARKET_REST);
}
}
//取得所有店铺营业时间交集 //取得所有店铺营业时间交集
foreach($stores as $store){ foreach($stores as $store){
//获取店铺开始营业时间 //获取店铺开始营业时间
$time1 = strtotime(($store['time1'])); $time1 = strtotime(($store['time1']));
//店铺是否在营业时间 店铺手动点击休息 || 小于店铺开始营业时间 || 当前时间大于服务站休业时间 //店铺是否在营业时间 店铺手动点击休息 || 小于店铺开始营业时间 || 当前时间大于服务站休业时间
if($store['is_rest'] == 1 || $nowTime < $time1 || $nowTime > $closedTime){
if($store['is_rest'] == 1 || $nowTime < $time1){
throw new ErrorCodeException(ErrorCode::STORE_REST); throw new ErrorCodeException(ErrorCode::STORE_REST);
} }

30
app/Service/v3/Implementations/FeiePrintService.php

@ -67,7 +67,7 @@ class FeiePrintService implements FeiePrintServiceInterface
$content = $this->printFormat($data, 4, 14, 7, 7); $content = $this->printFormat($data, 4, 14, 7, 7);
//$res = $this->printMsg('920527381', $content, 1);
$res = $this->printMsg('920527381', $content, 1);
return $content; return $content;
} }
@ -105,15 +105,22 @@ class FeiePrintService implements FeiePrintServiceInterface
$orderInfo = '<CB>懒族生活</CB><BR>'; $orderInfo = '<CB>懒族生活</CB><BR>';
$orderInfo .= '数量 名称 单价 金额<BR>'; $orderInfo .= '数量 名称 单价 金额<BR>';
$orderInfo .= '--------------------------------<BR>'; $orderInfo .= '--------------------------------<BR>';
//$shopnum 当前为第几个店铺
$shopnum = 0; $shopnum = 0;
//循环处理子订单
foreach ($arr->orders as $k5 => $order) { foreach ($arr->orders as $k5 => $order) {
$orderInfo .= ' <BR>'; $orderInfo .= ' <BR>';
$shopnum++; $shopnum++;
$orderInfo .= "<C>(" . $shopnum . ")" .$order->store->name . '</C><BR>'; $orderInfo .= "<C>(" . $shopnum . ")" .$order->store->name . '</C><BR>';
$subNum = 0;
//循环处理子订单下商品
foreach ($order['orderGoods'] as $goods){ foreach ($order['orderGoods'] as $goods){
//店铺商品数量小计
$subNum += $goods->number;
$orderInfo .= str_pad($goods->number,$A,' ',STR_PAD_RIGHT); $orderInfo .= str_pad($goods->number,$A,' ',STR_PAD_RIGHT);
$nameLength = mb_strwidth($goods->name);
$nameArr = mb_str_split($goods->name);
//商品名处理
$nameLength = mb_strwidth($goods->name_unit);
$nameArr = mb_str_split($goods->name_unit);
$length = $A; $length = $A;
foreach ($nameArr as $name){ foreach ($nameArr as $name){
$len = mb_strwidth($name); $len = mb_strwidth($name);
@ -124,15 +131,23 @@ class FeiePrintService implements FeiePrintServiceInterface
} }
$orderInfo .= $name; $orderInfo .= $name;
} }
//商品名长度是否超过一行
if($nameLength > ($B+$C+$D)){ if($nameLength > ($B+$C+$D)){
$orderInfo .= '<BR>'; $orderInfo .= '<BR>';
$orderInfo .= str_pad($goods->price,$A+$B+$C,' ',STR_PAD_LEFT); $orderInfo .= str_pad($goods->price,$A+$B+$C,' ',STR_PAD_LEFT);
$orderInfo .= str_pad(bcmul($goods->number,$goods->price,2),$D,' ',STR_PAD_LEFT);
}else{ }else{
$orderInfo .= str_pad($goods->price,$C+$B+$A-$length,' ',STR_PAD_LEFT); $orderInfo .= str_pad($goods->price,$C+$B+$A-$length,' ',STR_PAD_LEFT);
$orderInfo .= str_pad(bcmul($goods->number,$goods->price,2),$D,' ',STR_PAD_LEFT);
} }
$orderInfo .= str_pad(bcmul($goods->number,$goods->price,2),$D,' ',STR_PAD_LEFT);
} }
/**
* 订单商品处理结束
*/
//处理订单备注
$orderInfo .= '--------------------------------<BR>';
//订单小计
$orderInfo .= $this->space($subNum,$order->money);
if(!empty($order->note)){ if(!empty($order->note)){
$orderInfo .='<BR>'; $orderInfo .='<BR>';
$orderInfo .='<BR>'; $orderInfo .='<BR>';
@ -157,9 +172,10 @@ class FeiePrintService implements FeiePrintServiceInterface
} }
$userLength = preg_replace('/[^\x{4e00}-\x{9fa5}]/u', '', $userName); $userLength = preg_replace('/[^\x{4e00}-\x{9fa5}]/u', '', $userName);
$totalLength = preg_replace('/[^\x{4e00}-\x{9fa5}]/u', '', $total); $totalLength = preg_replace('/[^\x{4e00}-\x{9fa5}]/u', '', $total);
var_dump($userLength,$totalLength);
$userLength = mb_strlen($userLength);
$totalLength = mb_strlen($totalLength);
$orderInfo .= str_pad($userName,$A+$B+$userLength,' ',STR_PAD_RIGHT); $orderInfo .= str_pad($userName,$A+$B+$userLength,' ',STR_PAD_RIGHT);
$orderInfo .= str_pad($total,$C+$D+$totalLength,' ',STR_PAD_LEFT);
$orderInfo .= str_pad($total,$C+$D+$totalLength+1,' ',STR_PAD_LEFT);
$orderInfo .= '<BR>'; $orderInfo .= '<BR>';
$orderInfo .= '送货地点:' . $arr->address . '<BR>'; $orderInfo .= '送货地点:' . $arr->address . '<BR>';
$tel = substr_replace( $arr->tel, '****', 3, 4); $tel = substr_replace( $arr->tel, '****', 3, 4);

12
composer.lock

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "71c3d5cf05fbd7b480f24350362675e4",
"content-hash": "9f238a6a5e556f4061e56600f28bacfd",
"packages": [ "packages": [
{ {
"name": "adbario/php-dot-notation", "name": "adbario/php-dot-notation",
@ -2145,16 +2145,16 @@
}, },
{ {
"name": "hyperf/guzzle", "name": "hyperf/guzzle",
"version": "v2.0.2",
"version": "v2.0.11",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/hyperf/guzzle.git", "url": "https://github.com/hyperf/guzzle.git",
"reference": "34eca5665aa49a534bacf89d6b84c454ab622ebc"
"reference": "d0a5d72e93f4c6fa90c3e25a0eb192e1445cc1e0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/hyperf/guzzle/zipball/34eca5665aa49a534bacf89d6b84c454ab622ebc",
"reference": "34eca5665aa49a534bacf89d6b84c454ab622ebc",
"url": "https://api.github.com/repos/hyperf/guzzle/zipball/d0a5d72e93f4c6fa90c3e25a0eb192e1445cc1e0",
"reference": "d0a5d72e93f4c6fa90c3e25a0eb192e1445cc1e0",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -2200,7 +2200,7 @@
"php", "php",
"swoole" "swoole"
], ],
"time": "2020-07-07T07:50:52+00:00"
"time": "2020-09-07T10:26:15+00:00"
}, },
{ {
"name": "hyperf/http-message", "name": "hyperf/http-message",

Loading…
Cancel
Save