from('{{%ybwm_print}}')
->where('id=:id',[':id'=>$id])->one();
$rst=json_decode($message['data'],true);
if($message['type']==1) {
$content = "取单号:#001**";
$content .= "张周兄弟烧烤";
$content .= "--在线支付--";
$content .= "【立即送达】";
$content .= "期望送达时间:" . date("Y-m-d H:i") . "\n";
$content .= str_repeat('.', 32);
$content .= "订单编号:40807050607030\n";
$content .= "下单时间:" . date("Y-m-d H:i") . "\n";
$content .= '名称' . str_repeat(" ", 12) . "数量 单价\n";
$content .= "";
$content .= "烤土豆(超级辣) | x3 | 5.96 |
";
$content .= "烤排骨(超级辣) | x3 | 12.44 |
";
$content .= "烤韭菜(超级辣) | x3 | 8.96 |
";
$content .= "
";
$content .= str_repeat('.', 32);
$content .= "[折扣:¥4 ]\n";
$content .= "实付:¥78\n";
$content .= str_repeat('*', 32);
$content .= "这是二维码内容";
$content .= "**#1 完**";
$data = self::print($rst,$content);
}elseif ($message['type']==2){
$content = '测试打印
';
$content .= '名称 数量 金额
';
$content .= '--------------------------------
';
$content .= '鸡蛋炒饭 10 100.0
';
$content .= '西红柿炒饭 10 100.0
';
$content .= '西红柿鸡蛋炒饭 10 100.0
';
$content .= '--------------------------------
';
$content .= '备注:加辣
';
$content .= '合计:xx.0元
';
$content .= '送货地点:广州市南沙区xx路xx号
';
$content .= '联系电话:13888888888888
';
$content .= '订餐时间:2014-08-08 08:08:08
';
$content .= 'http://www.feieyun.com';
$data = self::feiPrint($rst,$content);
}elseif ($message['type']==3){
$content= "#001 五号桌 1/3可乐鸡翅张三先生 13800138000";
$data = self::labelPrint($rst,$content);
}
return $data;
}
//标签机打印设置
public function labelPrintSet($id,$type) {
$message=(new \yii\db\Query())
->from('{{%ybwm_print}}')
->where('id=:id',[':id'=>$id])->one();
$rst=json_decode($message['data'],true);
$content ="40,30";
if($type==1){
$content.="1";
}elseif ($type==2) {
$content.="0";
}
$data = self::labelPrint($rst,$content);
return $data;
}
//易联云打印
public static function print($params,$content='测试打印内容'){
try {
$outTradeNo = date("YmdHis") . rand(111111, 999999);
$config = new YlyConfig($params['userId'], $params['apiKey']);
$token = Yii::$app->cache->get($params['userId']);
if (!$token) {
//var_dump($token);die;
$client = new YlyOauthClient($config);
$token = $client->getToken();
if ($token->access_token) {
Yii::$app->cache->set($params['userId'], $token, 7200);
}
}
$print = new PrintService($token->access_token, $config);
$data = $print->index($params['number'], $content, $outTradeNo);
//return $data;
}catch (\Exception $e){
//var_dump($e);die;
return false;
}
}
//飞蛾打印
public static function feiPrint($params,$content='测试打印内容'){
//file_put_contents('1.txt','jijjjjjj'.$content);exit;
header("Content-type: text/html; charset=utf-8");
$contents = array(
'user' => $params['fenumber'],
'stime' => time(),
'sig' => sha1($params['fenumber'] . $params['feukey'] . time()),
'apiname' => 'Open_printMsg',
'sn' => $params['dyjnumber'],
'content' => $content,
'times' => $params['wmnum'] ?: 1, //打印次数
);
$contents['content'] = $content;
//file_put_contents('1.txt',$contents['content'],FILE_APPEND);
//return true;
$client = new HttpClient('api.feieyun.cn', '80');
if (!$client->post('/Api/Open/', $contents)) {
$result = 'error';
} else {
$result = $client->getContent();
}
file_put_contents('1.txt',$result);
$rst = json_decode($result, true);
if ($rst['msg'] == 'ok') {
return true;
}
return false;
}
static function labelPrint($params,$content) {
header("Content-type: text/html; charset=utf-8");
$contents = array(
'user' => $params['labelfenumber'],
'stime' => time(),
'sig' => sha1($params['labelfenumber'] . $params['labelfeukey'] . time()),
'apiname' => 'Open_printLabelMsg',
'sn' => $params['labeldyjnumber'],
'content' => $content,
'times' => $params['wmnum'] ?: 1, //打印次数
);
$contents['content'] = $content;
//var_dump($contents);die;
$client = new HttpClient('api.feieyun.cn', '80');
if (!$client->post('/Api/Open/', $contents)) {
$result = 'error';
} else {
$result = $client->getContent();
//var_dump($result);die;
}
$rst = json_decode($result, true);
//}
return true;
}
//易联云取消所有未打印
public static function cancelAllPrint($id){
$message=(new \yii\db\Query())
->from('{{%ybwm_print}}')
->where('id=:id',[':id'=>$id])->one();
$params=json_decode($message['data'],true);
$config = new YlyConfig($params['userId'], $params['apiKey']);
$token = Yii::$app->cache->get($params['number']);
if(!$token){
//var_dump($token);die;
$client = new YlyOauthClient($config);
$token = $client->getToken();
if($token->access_token){
Yii::$app->cache->set($params['number'], $token, 86400);
}
}
$print = new PrinterService($token->access_token, $config);
$data = $print->cancelAll($params['number']);
return $data;
}
//易联云整单
static function yiAllContent(array $order,array $store,array $goods,$note=null,$display=null,$qrContent=null){
if ($order['deliveryMode'] == 10) {
$ddName = "到店自提";
$qrContent=$order['selfCode'];
$order['serviceAt'] = date(" H:i", $order['serviceTime']);
} else {
$ddName = "立即送出";
$order['serviceAt'] = $order['serviceAt'];
$qrContent=$qrContent;
}
if($order['appointment']==1){
$ddName="预约单";
$order['serviceAt'] = date("m-d H:i", $order['serviceTime']);
}
$payType = '微信支付';
switch ($order['payMode']) {
case 2:
$payType = '支付宝支付';
break;
case 5:
$payType = '余额支付';
break;
case 10:
$payType = '货到付款';
break;
}
$content = "取单号:#" . $order['takeNo'] . "\n";
$content .= "
*" . $store['name'] . "*\n";
if ($order['state'] == 9 or $order['state'] == 10) {
$content .= "--售后订单--\n";
$content .= "有订单申请售后了\n";
$content .= "请尽快处理!\n";
} elseif ($order['state'] == 7) {
$content .= "--取消订单--\n";
$content .= "订单已取消,请尽快处理\n";
} else {
$content .= "--" . $payType . "--\n";
$content .= "【" . $ddName . "】\n";
}
/* if ($order['selfCode']) {
$content .= "取货码:" . $order['selfCode'] . "\n";
}*/
if($order['deliveryMode']==10 and $order['isOut']==1){
$eatType='店内就餐';
}else{
$eatType='打包带走';
}
if($order['deliveryMode']==10){
$content .= "取单方式:" . $eatType . "\n";
$content .= "预计到店时间:" . $order['serviceAt'] . "\n";
$order['receivedName']="预留信息:";
}else{
$content .= "期望送达时间:" . $order['serviceAt'] . "\n";
}
$content .= "--------------------------------\n";
$content .= "订单编号:" . $order['outTradeNo'] . "\n";
$content .= "下单时间:" . date('Y-m-d H:i:s', $order['createdAt']) . "\n";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "\n";
}
$content .= "--------------------------------\n";
$content .= '名称' . str_repeat(" ", 12) . "数量 单价\n";
$content .= "";
foreach ($goods as $key => $value) {
$name = $value['name'];
if ($value['data']) {
$name = $value['name'] . '(' . $value['data'] . ')';
}
if ($value['attribute']) {
$name = $name . '(' . $value['attribute'] . ')';
}
if ($value['material']) {
/* $material = json_decode($value['material'], true);
$mes = '';
foreach ($material as $v) {
$mes .= $v['name'] . '(' . $v['number'] . '),';
}*/
$name = $name . '(' .$value['material'] . ')';
}
if ($value['vipMoney'] > 0) {
$value['money'] = $value['vipMoney'];
}
$content .= "" . $name . " | " . $value['num'] . " | " . $value['money'] . " |
";
}
$content .= "
\n";
$content .= "合计: | " . $order['num'] . " | " . $order['originMoney'] . " |
";
$content .= "----------其它费用----------\n";
if ($order['deliveryMoney'] > 0) {
$content .= "[配送费:+" . $order['deliveryMoney'] . "]\n";
}
if ($order['boxMoney'] > 0) {
$content .= "[餐盒费:+" . $order['boxMoney'] . "]\n";
}
if ($order['preferentialMoney'] > 0) {
$content .= "[满减优惠:-" . $order['preferentialMoney'] . "]\n";
}
if ($order['platformCouponPreferential'] > 0) {
$content .= "[平台优惠券优惠:-" . $order['platformCouponPreferential'] . "]\n";
}
if ($order['couponPreferential'] > 0) {
$content .= "[优惠券优惠:-" . $order['couponPreferential'] . "]\n";
}
if ($order['newMoney'] > 0) {
$content .= "[新客立减:-" . $order['newMoney'] . "]\n";
}
if ($order['deliveryPreferential'] > 0) {
$content .= "[减免配送费:-" . $order['deliveryPreferential'] . "]\n";
}
if ($order['giveName']) {
$content .= "[赠送:-" . $order['giveName'] . "]\n";
}
if($order['payMode']==10){
$content .= "应付:¥" . $order['money'] . "\n";
}else{
$content .= "实付:¥" . $order['money'] . "\n";
}
$content .= "--------------------------------\n";
$content .= "" . $order['receivedAddress'] . "\n\n";
$content .= "" . $order['receivedName']. $order['receivedTel'] . "\n\n";
if($note){
$content .= "" . $note . "\n";
}
$content .= "门店电话:" . $store['storeTel'] . "\n\n";
if($display==1) {
$content .= "" . $qrContent . "";
}
$content .= "----#" . $order['takeNo'] . "完----\n";
return $content;
}
static function yiOneContent(array $order,array $store,array $goods,$note=null){
$content = "取单号:#" . $order['takeNo'] . "\n";
$content .= "*" . $store['name'] . "*\n";
$content .= "订单编号:" . $order['outTradeNo'] . "\n";
$content .= "下单时间:" . date('Y-m-d H:i:s', $order['createdAt']) . "\n";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "\n";
}
$content .= "--------------------------------\n";
$content .= '名称' . str_repeat(" ", 12) . "数量 单价\n";
$content .= "";
$name = $goods['name'];
if ($goods['data']) {
$name = $goods['name'] . '(' . $goods['data'] . ')';
}
if ($goods['attribute']) {
$name = $name . '(' . $goods['attribute'] . ')';
}
if ($goods['material']) {
/* $material = json_decode($goods['material'], true);
$mes = '';
foreach ($material as $v) {
$mes .= $v['name'] . '(' . $v['number'] . '),';
}*/
$name = $name . '(' . $goods['material'] . ')';
}
if ($goods['vipMoney'] > 0) {
$value['money'] = $goods['vipMoney'];
}
$content .= "" . $name . " | " . $goods['num'] . " | " . $goods['money'] . " |
";
$content .= "
\n";
if($note){
$content .= "" . $note . "\n";
}
$content .= "----#" . $order['takeNo'] . "完----\n";
return $content;
}
static function yiTypeContent(array $order,array $store,array $goods){
$content = "取单号:#" . $order['takeNo'] . "\n";
$content .= "*" . $store['name'] . "*\n";
if($order['deliveryMode']==10 and $order['isOut']==1){
$eatType='店内就餐';
}else{
$eatType='打包带走';
}
if($order['deliveryMode']==10){
$content .= "取单方式:" . $eatType . "\n";
$content .= "预计到店时间:" . $order['serviceAt'] . "\n";
$order['receivedName']="预留信息:";
}else{
$content .= "期望送达时间:" . $order['serviceAt'] . "\n";
}
//$content .= "期望送达时间:" . $order['serviceAt'] . "\n";
$content .= "--------------------------------\n";
$content .= "订单编号:" . $order['outTradeNo'] . "\n";
$content .= "下单时间:" . date('Y-m-d H:i:s', $order['createdAt']) . "\n";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "\n";
}
$content .= "--------------------------------\n";
$content .= '名称' . str_repeat(" ", 12) . "数量 单价\n";
$content .= "";
foreach ($goods as $key => $value) {
$name = $value['name'];
if ($value['data']) {
$name = $value['name'] . '(' . $value['data'] . ')';
}
if ($value['attribute']) {
$name = $name . '(' . $value['attribute'] . ')';
}
if ($value['material']) {
/* $material = json_decode($value['material'], true);
$mes = '';
foreach ($material as $v) {
$mes .= $v['name'] . '(' . $v['number'] . '),';
}*/
$name = $name . '(' . $value['material'] . ')';
}
if ($value['vipMoney'] > 0) {
$value['money'] = $value['vipMoney'];
}
$content .= "" . $name . " | " . $value['num'] . " | " . $value['money'] . " |
";
}
$content .= "
\n";
$content .= "----#" . $order['takeNo'] . "完----\n";
return $content;
}
//整单打印或一菜一单内容
static function allContent($orderId,$type=1,$printMode=1,$note=null,$display=null,$qrContent=null){
$order=(new \yii\db\Query())
->from('{{%ybwm_takeout_order}}')
->where('id=:id',[':id'=>$orderId])->one();
$store=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('id=:id',[':id'=>$order['storeId']])->one();
$goods=(new \yii\db\Query())
->from('{{%ybwm_order_goods}}')
->where(' orderId=:orderId AND item=1',[':orderId'=>$orderId])->All();
//整单打印
if($printMode==1) {
if ($type == 1) {
$content = self::yiAllContent($order, $store, $goods,$note,$display,$qrContent);
return $content;
}
if ($type == 2) {
$content = self::feiAllContent($order, $store, $goods,$note,$display,$qrContent);
return $content;
}
if ($type == 3) {
$data['order']=$order;
$data['store']=$store;
$data['goods']=$goods;
return $data;
}
}elseif($printMode==3){//一菜一单
$data['order']=$order;
$data['store']=$store;
$data['goods']=$goods;
return $data;
}
}
//分组打印或标签打印内容
static function typeContent($orderId,$type=1,$printMode=1,$json){
$categoryArr = json_decode($json);
$categoryStr = implode(',', $categoryArr)?:[];
$where='a.orderId=:orderId';
$order=(new \yii\db\Query())
->from('{{%ybwm_takeout_order}}')
->where('id=:id',[':id'=>$orderId])->one();
$store=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('id=:id',[':id'=>$order['storeId']])->one();
if($printMode==2 AND $categoryStr){
$where .=" and item=1 and b.typePid in ($categoryStr)";
}elseif ($printMode==4 AND $categoryStr){
$where .=" and item=1 and b.printLabel in ($categoryStr)";
}
$goods=(new \yii\db\Query())
->select(['a.*','b.typePid'])
->from('{{%ybwm_order_goods}} as a')
->join('LEFT JOIN', '{{%ybwm_core_goods}} as b', 'a.goodsId=b.id')
->where($where,[':orderId'=>$orderId])
->all();
if(!$goods){
return false;
}
if ($type == 1) {
$content = self::yiTypeContent($order, $store, $goods);
return $content;
}elseif ($type == 2) {
$content = self::feiTypeContent($order, $store, $goods);
return $content;
}elseif ($type == 3){
$data['order']=$order;
$data['store']=$store;
$data['goods']=$goods;
return $data;
}
}
static function feiStyle($arr, $A = 20, $B = 6, $C = 3, $D = 6) {
$orderInfo = '';
$nums='';
$prices='';
foreach ($arr as $k5 => $v5) {
$name = $v5['name'];
if ($v5['data']) {
$name = $v5['name'] . '(' . $v5['data'] . ')';
}
if ($v5['attribute']) {
$name = $name . '(' . $v5['attribute'] . ')';
}
if ($v5['material']) {
$name = $name .'('.$v5['material']. ')';
}
$name = $name;
$num = $v5['num'];
$price = $v5['money'];
if ($v5['vipMoney'] > 0) {
$price = $v5['vipMoney'];
}
//$prices = $v5['money']*$v5['num'];
$kw3 = '';
$kw1 = '';
$kw2 = '';
$kw4 = '';
$str = $name;
$blankNum = $A; //名称控制为14个字节
$lan = mb_strlen($str, 'utf-8');
$m = 0;
$j = 1;
$blankNum++;
$result = array();
/* if(strlen($price) < $B){
$k1 = $B - strlen($price);
for($q=0;$q<$k1;$q++){
$kw1 .= ' ';
}
$price = $price.$kw1;
}*/
if (strlen($num) < $C) {
$k2 = $C - strlen($num);
for ($q = 0; $q < $k2; $q++) {
$kw2 .= ' ';
}
$num = $num . $kw2;
}
/* if(strlen($prices) < $D){
$k3 = $D - strlen($prices);
for($q=0;$q<$k3;$q++){
$kw4 .= ' ';
}
$prices = $prices.$kw4;
}*/
for ($i = 0; $i < $lan; $i++) {
$new = mb_substr($str, $m, $j, 'utf-8');
$j++;
if (mb_strwidth($new, 'utf-8') < $blankNum) {
if ($m + $j > $lan) {
$m = $m + $j;
$tail = $new;
$lenght = iconv("UTF-8", "GBK//IGNORE", $new);
$k = $A - strlen($lenght);
for ($q = 0; $q < $k; $q++) {
$kw3 .= ' ';
}
if ($m == $j) {
$tail .= $kw3 . ' ' . $num . ' ' . $price . ' ' . $prices;
} else {
$tail .= $kw3 . '
';
}
break;
} else {
$next_new = mb_substr($str, $m, $j, 'utf-8');
if (mb_strwidth($next_new, 'utf-8') < $blankNum) {
continue;
} else {
$m = $i + 1;
$result[] = $new;
$j = 1;
}
}
}
}
$head = '';
foreach ($result as $key => $value) {
if ($key < 1) {
$v_lenght = iconv("UTF-8", "GBK//IGNORE", $value);
$v_lenght = strlen($v_lenght);
if ($v_lenght == 13) {
$value = $value . " ";
}
$head .= $value . ' ' . $num . ' ' . $price . ' ' . $prices;
} else {
$head .= $value . '
';
}
}
$orderInfo .= $head . $tail . '
';
@$nums += $prices;
}
return $orderInfo;
}
static function feiAllContent(array $order,array $store,array $goods,$note=null,$display=null,$qrContent=null){
if ($order['deliveryMode'] == 10) {
$ddName = "到店自提";
$qrContent=$order['selfCode'];
$order['serviceAt'] = date(" H:i", $order['serviceTime']);
} else {
$ddName = "立即送出";
$order['serviceAt'] = $order['serviceAt'];
$qrContent=$qrContent;
}
if($order['appointment']==1){
$ddName="预约单";
$order['serviceAt'] = date("m-d H:i", $order['serviceTime']);
}
$payType = '微信支付';
switch ($order['payMode']) {
case 2:
$payType = '支付宝支付';
break;
case 5:
$payType = '余额支付';
break;
case 10:
$payType = '货到付款';
break;
}
$content= "取单号 #" . $order['takeNo'] . "
";
$content .= "*" . $store['name'] . "*
";
if($order['state']==9 or $order['state']==10){
$content .= "--售后订单--
";
$content .= "有订单申请售后了
";
$content .= "请尽快处理!
";
}elseif($order['state']==7){
$content .= "--取消订单--
";
$content .= "订单已取消,请尽快处理
";
}else{
$content .= "--".$payType."--
";
$content .= "【".$ddName."】
";
}
/* if ($order['selfCode']) {
$content .= "取货码: " . $order['selfCode'] . "
";
}*/
if($order['deliveryMode']==10 and $order['isOut']==1){
$eatType='店内就餐';
}else{
$eatType='打包带走';
}
if($order['deliveryMode']==10){
$content .= "取单方式:" . $eatType . "
";
$content .= "预计到店时间:" . $order['serviceAt'] . "
";
$order['receivedName']="预留信息:";
}else{
$content .= "期望送达时间:" . $order['serviceAt'] . "
";
}
$content .= "--------------------------------
";
$content .= "订单号:" . $order['outTradeNo'] . "
";
$content .= "下单时间:" . date('Y-m-d H:i:s', $order['createdAt']) . "
";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "
";
}
$content .= "--------------------------------
";
$content .= "名称 数量 单价
";
$content .= "".self::feiStyle($goods,20,6,3)."";
$content .= self::feiStyle(['0'=>['name'=>'合计','num'=>$order['num'],'money'=>$order['originMoney']]],20,6,3);
$content .= "----------其它费用----------\n";
if ($order['deliveryMoney'] > 0) {
$content .= "配送费:" . $order['deliveryMoney'] . "
";
}
if ($order['boxMoney'] > 0) {
$content .= "[餐盒费:+" . $order['boxMoney'] . "]
";
}
if ($order['preferentialMoney'] > 0) {
$content .= "[满减优惠:-" . $order['preferentialMoney'] . "]
";
}
if ($order['platformCouponPreferential'] > 0) {
$content .= "[平台优惠券优惠:-" . $order['platformCouponPreferential'] . "]
";
}
if ($order['couponPreferential'] > 0) {
$content .= "[优惠券优惠:-" . $order['couponPreferential'] . "]
";
}
if ($order['newMoney'] > 0) {
$content .= "[新客立减:-" . $order['newMoney'] . "]
";
}
if ($order['deliveryPreferential'] > 0) {
$content .= "[减免配送费:-" . $order['deliveryPreferential'] . "]
";
}
if ($order['giveName']) {
$content .= "[赠送:" . $order['giveName'] . "]
";
}
if($order['payMode']==10){
$content .= "应付:¥" . $order['money'] . "
";
}else{
$content .= "实付:¥" . $order['money'] . "
";
}
$content .= "" . $order['receivedAddress'] . "
";
$content .= "" . $order['receivedName'] . $order['receivedTel'] . "
";
if ($note) {
$content .= "" .$note . "
";
}
$content .= "门店电话:" . $store['storeTel'] . "
";
if($display==1) {
$content .= "" . $qrContent . "";
}
$content .= "----#" . $order['takeNo'] . "完----\n";
return $content;
}
static function feiOneContent(array $order,array $store,array $goods,$note=null){
$goodsInfo[]=$goods;
$content= "取单号 #" . $order['takeNo'] . "
";
$content .= "*" . $store['name'] . "*
";
if($order['deliveryMode']==10 and $order['isOut']==1){
$eatType='店内就餐';
}else{
$eatType='打包带走';
}
if($order['deliveryMode']==10){
$content .= "取单方式:" . $eatType . "
";
$content .= "预计到店时间:" . $order['serviceAt'] . "
";
}else{
$content .= "期望送达时间:" . $order['serviceAt'] . "
";
}
$content .= "--------------------------------
";
$content .= "订单号:" . $order['outTradeNo'] . "
";
$content .= "下单时间:" . date('Y-m-d H:i:s', $order['createdAt']) . "
";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "
";
}
$content .= "--------------------------------
";
$content .= "名称 数量 单价
";
$content .= "".self::feiStyle($goodsInfo,20,6,3)."";
if($note){
$content .= "" . $note . "\n";
}
$content .= "门店电话:" . $store['storeTel'] . "\n\n";
$content .= "----#" . $order['takeNo'] . "完----\n";
return $content;
}
static function feiTypeContent(array $order,array $store,array $goods,$note=null){
if ($order['deliveryMode'] == 10) {
$ddName = "到店自提";
$order['serviceAt'] = date("Y-m-d H:i", $order['serviceTime']);
} else {
$ddName = "立即送出";
$order['serviceAt'] = $order['serviceAt'];
}
if($order['appointment']==1){
$ddName="预约单";
$order['serviceAt'] = date("m-d H:i", $order['serviceTime']);
}
$payType = '微信支付';
switch ($order['payMode']) {
case 2:
$payType = '支付宝支付';
break;
case 5:
$payType = '余额支付';
break;
case 10:
$payType = '货到付款';
break;
}
$content= "取单号 #" . $order['takeNo'] . "
";
$content .= "*" . $store['name'] . "*
";
if($order['state']==9){
$content .= "--售后订单--
";
$content .= "订单申请售后,请尽快处理
";
}elseif($order['state']==7){
$content .= "--取消订单--
";
$content .= "订单已取消,请尽快处理
";
}else{
$content .= "--".$payType."--
";
$content .= "【".$ddName."】
";
}
/* if ($order['selfCode']) {
$content .= "取货码 " . $order['selfCode'] . "
";
}*/
if($order['deliveryMode']==10 and $order['isOut']==1){
$eatType='店内就餐';
}else{
$eatType='打包带走';
}
if($order['deliveryMode']==10){
$content .= "取单方式:" . $eatType . "
";
$content .= "预计到店时间:" . $order['serviceAt'] . "
";
}else{
$content .= "期望送达时间:" . $order['serviceAt'] . "
";
}
$content .= "--------------------------------
";
$content .= "订单号:" . $order['outTradeNo'] . "
";
$content .= "下单时间:" . date('Y-m-d H:i:s', $order['createdAt']) . "
";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "
";
}
$content .= "--------------------------------
";
$content .= "名称 数量 单价
";
$content .= "".self::feiStyle($goods,20,6,3)."";
if($note){
$content .= "" . $note . "\n";
}
$content .= "门店电话:" . $store['storeTel'] . "\n\n";
$content .= "----#" . $order['takeNo'] . "完----\n";
return $content;
}
static function labelAllContent(array $order,array $store,array $goods,$num,$typeArr=[]){
$goodsInfo[]=$goods;
$content = '';
foreach ($goodsInfo as $key => $value) {
$money = $value["money"];
if ($value["vipMoney"] > 0) {
$money = $value["vipMoney"];
}
$symbol='/';
$tableName='单号';
$sign='#';
if($typeArr['orderType']==1){
$orderType='堂食';
$orderTex='';
$symbol='';
$tableName='桌号';
$order['takeNo']=$order['number'];
$sign='';
}elseif ($typeArr['orderType']==2){
$orderType='快餐';
$orderTex='店内';
$sign='';
$order['takeNo']=$order['callNo'];
if($typeArr['isOut']==2){
$orderTex='打包';
}
}elseif ($typeArr['orderType']==3){
$orderType='外卖';
$orderTex='配送';
if($typeArr['isOut']==2&&$typeArr['deliveryMode']==10){
$orderType='自提';
$orderTex='打包';
}
if($typeArr['isOut']==1&&$typeArr['deliveryMode']==10){
$orderType='自提';
$orderTex='到店';
}
}
$goodsNum=$order['num']?:$order['goodsNum'];
//$num = $key + 1;
$content .= ''.$tableName.':'.$sign. $order['takeNo']." ". ' 杯数:' . $num . '/' . $goodsNum . '';
$content .= '' . $value["name"] . '';
if ($value["data"]) {
$content .= '规格:' . $value["data"] . '';
}
if ($value["attribute"]) {
$content .= '属性:' . $value["attribute"] . '';
}
if ($value['material']) {
$content .= '加料:' . $value['material'] . '';
}
//$content.= '1×'. $money.' '.$location.'';
//$content .= ''.$value["title"].'';
$content .= '' . date('m-d H:i', $order['createdAt']) ." ".$orderType. $symbol.$orderTex .'';//
}
return $content;
}
//外卖订单打印
public static function takeoutOrderPrint($orderId){
$order=(new \yii\db\Query())
->from('{{%ybwm_takeout_order}}')
->where('id=:id',[':id'=>$orderId])->one();
$print=(new \yii\db\Query())
->from('{{%ybwm_print}}')
->where('deleteAt=0 AND display=1 AND uniacid=:uniacid AND storeId=:storeId AND support=1',[':uniacid'=>$order['uniacid'],':storeId'=>$order['storeId']])->All();
if (!$print) {
return false;
}
$systemSet=Config::getSystemSet('print',$order['uniacid']);
foreach ($print as $value){
$rst=json_decode($value['data'],true);
//易联云
if($value['type']==1){
$dynum=$rst['wmnum']?:1;
$note=$systemSet['sjlNote']?:'';
$display=$systemSet['display']?:2;
$qrContent=$systemSet['codeUrl']?:'';
//商家联
if($value['pattern']==1){
//整单打印
if($value['printMode']==1){
$content=self::allContent($orderId,$value['type'],$value['printMode'],$note,$display,$qrContent);
//var_dump($content);die;
$content= "{$dynum}".$content;
self::print($rst,$content);
}
//一菜一单
if($value['printMode']==3){
$note=$systemSet['oneNote']?:'';
$info=self::allContent($orderId,$value['type'],$value['printMode'],$note);
foreach ($info['goods'] as $value){
$content = self::yiOneContent($info['order'], $info['store'], $value,$note);
// var_dump($content);die;
$content= "{$dynum}".$content;
self::print($rst,$content);
}
}
}
//顾客联
if($value['pattern']==2){
$content=self::allContent($orderId,$value['type'],$value['printMode'],$note,$display,$qrContent);
$content= "{$dynum}".$content;
self::print($rst,$content);
}
//厨房联
if($value['pattern']==3){
//整单打印
if($value['printMode']==1){
$content=self::allContent($orderId,$value['type'],$value['printMode']);
$content= "{$dynum}".$content;
self::print($rst,$content);
}
//分组打印
if($value['printMode']==2){
$content=self::typeContent($orderId,$value['type'],$value['printMode'],$value['categoryIds']);
if(!$content){
continue;
}
$content= "{$dynum}".$content;
self::print($rst,$content);
}
//一菜一单
if($value['printMode']==3){
$note=$systemSet['oneNote']?:'';
$info=self::allContent($orderId,$value['type'],$value['printMode'],$note);
foreach ($info['goods'] as $value){
$content = self::yiOneContent($info['order'], $info['store'], $value,$note);
// var_dump($content);die;
$content= "{$dynum}".$content;
self::print($rst,$content);
}
}
//标签打印
if($value['printMode']==4){
$content=self::typeContent($orderId,$value['type'],$value['printMode'],$value['label']);
if(!$content){
continue;
}
$content= "{$dynum}".$content;
self::print($rst,$content);
}
}
}
//飞蛾云
if($value['type']==2){
$note=$systemSet['gklNote']?:'';
$display=$systemSet['display2']?:2;
$qrContent=$systemSet['codeUrl2']?:'';
//商家联
if($value['pattern']==1){
//整单打印
if($value['printMode']==1){
$content=self::allContent($orderId,$value['type'],$value['printMode'],$note,$display,$qrContent);
//var_dump($content);die;
self::feiPrint($rst,$content);
}
//一菜一单
if($value['printMode']==3){
$note=$systemSet['oneNote']?:'';
$info=self::allContent($orderId,$value['type'],$value['printMode'],$note);
foreach ($info['goods'] as $value){
$content = self::feiOneContent($info['order'], $info['store'], $value,$note);
self::feiPrint($rst,$content);
}
}
}
//顾客联
if($value['pattern']==2){
$content=self::allContent($orderId,$value['type'],$value['printMode'],$note,$display,$qrContent);
self::feiPrint($rst,$content);
}
//厨房联
if($value['pattern']==3){
//整单打印
if($value['printMode']==1){
$content=self::allContent($orderId,$value['type'],$value['printMode']);
self::feiPrint($rst,$content);
}
//分组打印
if($value['printMode']==2){
$content=self::typeContent($orderId,$value['type'],$value['printMode'],$value['categoryIds']);
if(!$content){
continue;
}
self::feiPrint($rst,$content);
}
//一菜一单
if($value['printMode']==3){
$note=$systemSet['oneNote']?:'';
$info=self::allContent($orderId,$value['type'],$value['printMode'],$note);
foreach ($info['goods'] as $value){
$content = self::feiOneContent($info['order'], $info['store'], $value,$note);
// var_dump($content);die;
self::feiPrint($rst,$content);
}
}
//标签打印
if($value['printMode']==4){
$content=self::typeContent($orderId,$value['type'],$value['printMode'],$value['label']);
if(!$content){
continue;
}
self::feiPrint($rst,$content);
}
}
}
//飞蛾标签打印机
if($value['type']==3){
$info=self::allContent($orderId,$value['type'],$value['printMode'],$note='');
if($value['printMode']==2){
$info=self::typeContent($orderId,$value['type'],$value['printMode'],$value['categoryIds']);
}
if($value['printMode']==4 ){
$info=self::typeContent($orderId,$value['type'],$value['printMode'],$value['label']);
}
$goods=$info['goods'];
$orderNum=0;
foreach ($goods as $key => $value) {
$orderNum+=$value['num'];
if($value['num']>1){
for ($i=0; $i <$value['num'] ; $i++) {
if($i>0){
array_push($goods,$value);
}
}
}
}
foreach ($goods as $key=>$value){
$num=$key+1;
$content = self::labelAllContent($info['order'], $info['store'], $value,$num,['orderType'=>3,'isOut'=>$order['isOut'],'deliveryMode'=>$order['deliveryMode']]);
// var_dump($content);die;
self::labelPrint($rst,$content);
}
}
}
}
//退款打印
public static function refundOrderPrint($orderId){
$order=(new \yii\db\Query())
->from('{{%ybwm_takeout_order}}')
->where('id=:id',[':id'=>$orderId])->one();
$print=(new \yii\db\Query())
->from('{{%ybwm_print}}')
->where('deleteAt=0 AND display=1 AND uniacid=:uniacid AND storeId=:storeId AND support=1',[':uniacid'=>$order['uniacid'],':storeId'=>$order['storeId']])
->All();
if (!$print) {
return false;
}
$systemSet=Config::getSystemSet('print',$order['uniacid']);
foreach ($print as $value){
$rst=json_decode($value['data'],true);
//易联云
if($value['type']==1){
$note=$systemSet['sjlNote']?:'';
$display=$systemSet['display']?:2;
$qrContent=$systemSet['codeUrl']?:'';
//商家联
if($value['pattern']==1){
//整单打印
if($value['printMode']==1){
$content=self::allContent($orderId,$value['type'],$value['printMode'],$note,$display,$qrContent);
//var_dump($content);die;
self::print($rst,$content);
}
}
}
//飞蛾云
if($value['type']==2){
$note=$systemSet['gklNote']?:'';
$display=$systemSet['display2']?:2;
$qrContent=$systemSet['codeUrl2']?:'';
//商家联
if($value['pattern']==1){
//整单打印
if($value['printMode']==1){
$content=self::allContent($orderId,$value['type'],$value['printMode'],$note,$display,$qrContent);
//var_dump($content);die;
self::feiPrint($rst,$content);
}
//一菜一单
if($value['printMode']==3){
$note=$systemSet['oneNote']?:'';
$info=self::allContent($orderId,$value['type'],$value['printMode'],$note);
foreach ($info['goods'] as $value){
$content = self::feiOneContent($info['order'], $info['store'], $value,$note);
self::feiPrint($rst,$content);
}
}
}
}
}
}
static function integralYi($order) {
$name = $order['receiveName'];
$address = $order['receiveAddress'];
$tel = $order['receiveTel'];
if($order['deliveryMode']==2){
$user=(new \yii\db\Query())
->from('{{%ybwm_users}}')
->where('id=:id',[':id'=>$order['userId']])->one();
$name = $user['userName'];
$tel = $user['userTel'];
}
$price = '';
if ($order['score']) {
$price = $order['score'] . '积分';
}
if ($order['money']) {
$price = $order['money'] . '元';
}
if ($order['money'] and $order['score']) {
$price = $order['score'] . '积分+' . $order['money'] . '元';
}
$psName = "快递配送";
if ($order['deliveryMode'] == 2) {
$psName = "到店自提";
}
$content= "--积分兑换--\n";
$content.= "领取方式:" . $psName . "\n";
$content.= "用户ID:" . $order['userId'] . "\n";
$content .= "--------------------------------\n";
$content.= "订单号:" . $order['outTradeNo'] . "\n";
$content .= "兑换时间:" . date('Y-m-d H:i:s', $order['createdAt']) . "\n";
$content .= "--------------------------------\n";
$content .= '商品名称' . str_repeat(" ", 10) . "数量 市场价\n";
$content .= "" . $order['goodsName'] . " | " . $order['convertNum'] . " | " .$order['price']. " |
";
$content .= "--------------------------------\n\n";
/*$content .= "配送费" . $order['deliveryMoney'] . "\n\n";*/
$content .= "实付:" . $price . "\n\n";
//$content .= "------------".$psName."------------\n";
$content .= "------------预留信息------------\n\n";
$content .= "" . $name . " " . $tel . "\n";
$content .= "" . $address . "\n";
return $content;
}
static function integralFei($order) {
$name = $order['receiveName'];
$address = $order['receiveAddress'];
$tel = $order['receiveTel'];
if($order['deliveryMode']==2){
$user=(new \yii\db\Query())
->from('{{%ybwm_users}}')
->where('id=:id',[':id'=>$order['userId']])->one();
$name = $user['userName'];
$tel = $user['userTel'];
}
$price = '';
if ($order['score']) {
$price = $order['score'] . '积分';
}
if ($order['money']) {
$price = $order['money'] . '元';
}
if ($order['money'] and $order['score']) {
$price = $order['score'] . '积分+' . $order['money'] . '元';
}
$psName = "快递配送";
if ($order['deliveryMode'] == 2) {
$psName = "到店自提";
}
$content= "--积分兑换--
";
$content.= "领取方式:" . $psName . "
";
$content.= "用户ID:" . $order['userId'] . "
";
$content .= "--------------------------------
";
$content.= "订单号:" . $order['outTradeNo'] . "
";
$content .= "兑换时间:" . date('Y-m-d H:i:s', $order['createdAt']) . "
";
$content .= "--------------------------------
";
$content .= '商品名称' . str_repeat(" ", 10) . "数量 市场价
";
$goods[0] = array('name' => $order['goodsName'], 'money' => $order['price'], 'num' => $order['convertNum']);
$content .= self::feiStyle($goods);
$content .= "--------------------------------
";
$content .= "实付" . $price . "
";
$content .= "------------预留信息------------
";
$content .= "" . $name . " " . $tel . "
";
$content .= "" . $address . "
";
return $content;
}
static function integralOrderPrint($orderId,$storeId){
$order=(new \yii\db\Query())
->from('{{%ybwm_integral_order}}')
->where('id=:id',[':id'=>$orderId])->one();
$print=(new \yii\db\Query())
->from('{{%ybwm_print}}')
->where('deleteAt=0 AND display=1 AND uniacid=:uniacid AND storeId=:storeId AND support=1 AND printMode=6',[':uniacid'=>$order['uniacid'],':storeId'=>$storeId])->All();
if (!$print) {
return false;
}
foreach ($print as $value) {
$rst = json_decode($value['data'], true);
if ($value['type'] == 1) {
if($value['printMode']==6 ) {
$content = self::integralYi($order);
//var_dump($content);die;
return self::print($rst, $content);
}
}
if ($value['type'] == 2) {
if($value['printMode']==6 ) {
$content = self::integralFei($order);
//var_dump($content);die;
return self::feiPrint($rst, $content);
}
}
}
}
static function billContent($data,$type=1) {
$line="\n";
$content= "---营业小结---\n";
if($type==2){
$line="
";
$content= "---营业小结---
";
}
$content.= "日期:" . $data['day'] . $line.$line;
$content.= "打印时间:" . date('Y-m-d H:i:s') . $line.$line;
$content.= "营业额:" . $data['turnover'] . $line.$line;
$content.= "用户实付金额:" . $data['payment'] . $line.$line;
$content.= "预计结算收益:" . $data['estimate'] . $line.$line;
$content.= "其他费用:" . $data['otherMoney'] . $line.$line;
$content.= "有效订单数:" . $data['payNum'] . $line.$line;
$content.= "付款人数:" . $data['payPeople'] . $line.$line;
$content.= "取消/售后订单:" . $data['refundNum'] .$line.$line;
$content.= "取消/售后金额:" . $data['refundMoney'] .$line.$line;
return $content;
}
static function billPrint($data){
$print=(new \yii\db\Query())
->from('{{%ybwm_print}}')
->where('deleteAt=0 AND display=1 AND uniacid=:uniacid AND storeId=:storeId AND support=1',[':uniacid'=>$data['uniacid'],':storeId'=>$data['storeId']])->All();
//var_dump($print);die;
if (!$print) {
echo json_encode(['code'=>2,'msg'=>'打印机未开启']);die;
//return false;
}
foreach ($print as $value) {
$rst = json_decode($value['data'], true);
if ($value['type'] == 1) {
if ($value['printMode'] == 5) {
$content = self::billContent($data, $value['type']);
//var_dump($content);die;
return self::print($rst, $content);
}
}
if ($value['type'] == 2) {
if($value['printMode']==5 ) {
$content = self::billContent($data, $value['type']);
//var_dump($content);die;
return self::feiPrint($rst, $content);
}
}
}
}
public static function cashierOrderPrint($orderId){
$order=(new \yii\db\Query())
->from('{{%ybwm_cashier_order}}')
->where('id=:id',[':id'=>$orderId])->one();
$print=(new \yii\db\Query())
->from('{{%ybwm_print}}')
->where('deleteAt=0 AND display=1 AND uniacid=:uniacid AND storeId=:storeId AND support=4',[':uniacid'=>$order['uniacid'],':storeId'=>$order['storeId']])->All();
if (!$print) {
return false;
}
$systemSet=Config::getSystemSet('print',$order['uniacid']);
foreach ($print as $value){
$rst=json_decode($value['data'],true);
$note=$systemSet['sjlNote']?:'';
$display=$systemSet['display']?:2;
$qrContent=$systemSet['codeUrl']?:'';
//易联云
if($value['type']==1){
//商家联
if($value['pattern']==1){
$content=self::cashYi($order,$note,$display,$qrContent,$value['pattern']);
self::print($rst,$content);
}
//顾客联
if($value['pattern']==2){
$content=self::cashYi($order,$note,$display,$qrContent,$value['pattern']);
self::print($rst,$content);
}
}
//飞蛾云
if($value['type']==2){
//商家联
if($value['pattern']==1){
$content=self::cashFei($order,$note,$display,$qrContent,$value['pattern']);
//var_dump($content);die;
self::feiPrint($rst,$content);
}
//顾客联
if($value['pattern']==2){
$content=self::cashFei($order,$note,$display,$qrContent,$value['pattern']);
self::feiPrint($rst,$content);
}
}
}
}
//收银易联云打印内容
static function cashYi($order,$note,$display,$qrContent,$pattern) {
$store=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('id=:id',[':id'=>$order['storeId']])->one();
$userInfo=(new \yii\db\Query())
->from('{{%ybwm_member}}')
->where('id=:id',[':id'=>$order['userId']])->one();
$payType = '微信支付';
switch ($order['payMode']) {
case 2:
$payType = '支付宝支付';
break;
case 5:
$payType = '余额支付';
break;
case 10:
$payType = '货到付款';
break;
}
$patternContent='商家联';
if($pattern==2){
$patternContent='顾客联';
}
//$system=Config::getSystemSet('print',$order['uniacid']);
$content= "当面付小票\n";
$content .= "*" . $store['name'] . "*\n";
$content .= "用户信息:" .$userInfo['userName']."(UID:".$userInfo['id'] .")\n";
$content .= "支付方式:" . $payType . "\n";
$content .= "--------------------------------\n";
$content .= "订单编号:" . $order['outTradeNo'] . "\n";
$content .= "交易时间:" . date('Y-m-d H:i:s', $order['createdAt']) . "\n";
$content .= "--------------------------------\n";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "\n\n";
}
$content .= "实付:¥" . $order['money'] . "\n\n";
if($note){
$content .= "" . $note . "\n";
}
$content .= "门店电话:" . $store['storeTel'] . "\n\n";
if($display==1) {
$content .= "" . $qrContent . "";
}
$content .= "----" . $patternContent . "----\n";
return $content;
}
//收银飞蛾打印内容
static function cashFei($order,$note,$display,$qrContent,$pattern) {
$store=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('id=:id',[':id'=>$order['storeId']])->one();
$userInfo=(new \yii\db\Query())
->from('{{%ybwm_member}}')
->where('id=:id',[':id'=>$order['userId']])->one();
switch ($order['payMode']) {
case 2:
$payType = '支付宝支付';
break;
case 5:
$payType = '余额支付';
break;
case 10:
$payType = '货到付款';
break;
}
$patternContent='商家联';
if($pattern==2){
$patternContent='顾客联';
}
//$system=Config::getSystemSet('print',$order['uniacid']);
$content= "当面付小票
";
$content .= "*" . $store['name'] . "*
";
$content .= "用户信息:" .$userInfo['userName']."(UID:".$userInfo['id'] .")
";
$content .= "支付方式:" . $payType . "
";
$content .= "--------------------------------
";
$content .= "订单编号:" . $order['outTradeNo'] . "
";
$content .= "交易时间:" . date('Y-m-d H:i:s', $order['createdAt']) . "
";
$content .= "--------------------------------
";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "
";
}
$content .= "实付:¥" . $order['money'] . "
";
if($note){
$content .= "" . $note . "
";
}
$content .= "门店电话:" . $store['storeTel'] . "
";
if($display==1) {
$content .= "" . $qrContent . "";
}
$content .= "----" . $patternContent . "----\n";
//var_dump($content);die;
return $content;
}
//整单打印或一菜一单内容
static function instoreAllContent($orderId,$type=1,$printMode=1,$note=null,$display=null,$qrContent=null,$goodsId=null,$pattern=null){
$order=(new \yii\db\Query())
->from('{{%ybwm_instore_order}}')
->where('id=:id',[':id'=>$orderId])->one();
$store=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('id=:id',[':id'=>$order['storeId']])->one();
if($goodsId){
$goods = (new \yii\db\Query())
->from('{{%ybwm_order_goods}}')
->where(['in','id',$goodsId])->All();
}else {
$goods = (new \yii\db\Query())
->from('{{%ybwm_order_goods}}')
->where(' orderId=:orderId AND addType<3 AND item !=1', [':orderId' => $orderId])->All();
}
//整单打印
if($printMode==1) {
if ($type == 1) {
// var_dump($goods);die;
$content = self::yiInAllContent($order, $store, $goods,$note,$display,$qrContent,$goodsId,$pattern);
return $content;
}
if ($type == 2) {
$content = self::feiInAllContent($order, $store, $goods,$note,$display,$qrContent,$goodsId,$pattern);
return $content;
}
if ($type == 3) {
$data['order']=$order;
$data['store']=$store;
$data['goods']=$goods;
return $data;
}
}elseif($printMode==3){//一菜一单
$data['order']=$order;
$data['store']=$store;
$data['goods']=$goods;
return $data;
}
}
//分组打印或标签打印内容
static function typeInContent($orderId,$type=1,$printMode=1,$json,$goodsId=null){
$categoryArr = json_decode($json);
$categoryStr = implode(',', $categoryArr)?:[];
$where='a.orderId=:orderId';
$order=(new \yii\db\Query())
->from('{{%ybwm_instore_order}}')
->where('id=:id',[':id'=>$orderId])->one();
$store=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('id=:id',[':id'=>$order['storeId']])->one();
if($printMode==2 AND $categoryStr){
$where .=" and item!=1 and b.typePid in ($categoryStr)";
}elseif ($printMode==4 AND $categoryStr){
$where .=" and item !=1 and b.printLabel in ($categoryStr)";
}
if($goodsId){
$goods = (new \yii\db\Query())
->select(['a.*', 'b.typePid'])
->from('{{%ybwm_order_goods}} as a')
->join('LEFT JOIN', '{{%ybwm_core_goods}} as b', 'a.goodsId=b.id')
->where($where, [':orderId' => $orderId])
->andWhere( ['in','a.id', $goodsId])
->all();
}else {
//echo $categoryStr;die;
$goods = (new \yii\db\Query())
->select(['a.*', 'b.typePid'])
->from('{{%ybwm_order_goods}} as a')
->join('LEFT JOIN', '{{%ybwm_core_goods}} as b', 'a.goodsId=b.id')
->where($where, [':orderId' => $orderId])
->all();
}
if(!$goods){
return false;
}
//var_dump($goods);die;
if ($type == 1) {
$content = self::yiTypeInContent($order, $store, $goods);
return $content;
}elseif ($type == 2) {
$content = self::feiTypeInContent($order, $store, $goods);
return $content;
}elseif ($type == 3){
$data['order']=$order;
$data['store']=$store;
$data['goods']=$goods;
return $data;
}
}
static function yiTypeInContent(array $order,array $store,array $goods){
if($order['orderMode']==1){
$content= "台号:" . $order['number'] . "\n";
$timeStr="开台时间:";
}else{
$content= "取餐码:" . $order['callNo'] . "\n";
$timeStr="下单时间:";
}
$content .= "*" . $store['name'] . "*\n";
if($order['orderMode']==1){
$tableName = $order['regionName'] . ' ' . $order['typeName'] . ' ' . $order['people'] . '人';
$content .= "餐桌信息:" . $tableName . "\n";
}else {
if ($order['isOut'] == 1) {
$eatType = '店内就餐';
} else {
$eatType = '打包带走';
}
$content .= "取单方式:" . $eatType . "\n";
}
$content .= "--------------------------------\n";
$content .= "订单编号:" . $order['outTradeNo'] . "\n";
$content .= $timeStr . date('Y-m-d H:i:s', $order['createdAt']) . "\n";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "\n";
}
$content .= "--------------------------------\n";
$content .= '名称' . str_repeat(" ", 12) . "数量 单价\n";
$content .= "";
foreach ($goods as $key => $value) {
$name = $value['name'];
if ($value['data']) {
$name = $value['name'] . '(' . $value['data'] . ')';
}
if ($value['attribute']) {
$name = $name . '(' . $value['attribute'] . ')';
}
if ($value['material']) {
/* $material = json_decode($value['material'], true);
$mes = '';
foreach ($material as $v) {
$mes .= $v['name'] . '(' . $v['number'] . '),';
}*/
$name = $name . '(' . $value['material'] . ')';
}
if ($value['vipMoney'] > 0) {
$value['money'] = $value['vipMoney'];
}
$content .= "" . $name . " | " . $value['num'] . " | " . $value['money'] . " |
";
}
$content .= "
\n";
$content .= "----#" . $order['takeNo'] . "完----\n";
return $content;
}
static function feiTypeInContent(array $order,array $store,array $goods,$note=null){
$payType = '微信支付';
switch ($order['payMode']) {
case 2:
$payType = '支付宝支付';
break;
case 5:
$payType = '余额支付';
break;
case 10:
$payType = '货到付款';
break;
}
if($order['orderMode']==1){
$content= "台号:" . $order['number'] . "
";
$timeStr="开台时间:";
}else{
$content= "取餐码:" . $order['callNo'] . "
";
$timeStr="下单时间:";
}
$content .= "*" . $store['name'] . "*
";
if($order['orderMode']==1){
$tableName = $order['regionName'] . ' ' . $order['typeName'] . ' ' . $order['people'] . '人';
$content .= "餐桌信息:" . $tableName . "
";
}else {
if ($order['isOut'] == 1) {
$eatType = '店内就餐';
} else {
$eatType = '打包带走';
}
$content .= "取单方式:" . $eatType . "
";
}
$content .= "--------------------------------
";
$content .= "订单号:" . $order['outTradeNo'] . "
";
$content .= $timeStr . date('Y-m-d H:i:s', $order['createdAt']) . "
";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "
";
}
$content .= "--------------------------------
";
$content .= "名称 数量 单价
";
$content .= "".self::feiStyle($goods)."";
if($note){
$content .= "" . $note . "\n";
}
$content .= "门店电话:" . $store['storeTel'] . "\n\n";
$content .= "----#" . $order['takeNo'] . "完----\n";
return $content;
}
static function yiOneInContent(array $order,array $store,array $goods,$note=null){
if($order['orderMode']==1){
$content= "台号:" . $order['number'] . "\n";
$timeStr="开台时间:";
}else{
$content= "取餐码:" . $order['callNo'] . "\n";
$timeStr="下单时间:";
}
$content .= "*" . $store['name'] . "*\n";
if($order['orderMode']==1){
$tableName = $order['regionName'] . ' ' . $order['typeName'] . ' ' . $order['people'] . '人';
$content .= "餐桌信息:" . $tableName . "\n";
}else {
if ($order['isOut'] == 1) {
$eatType = '店内就餐';
} else {
$eatType = '打包带走';
}
$content .= "取单方式:" . $eatType . "\n";
}
$content .= "--------------------------------\n";
$content .= "订单号:" . $order['outTradeNo'] . "\n";
$content .= $timeStr . date('Y-m-d H:i:s', $order['createdAt']) . "\n";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "\n";
}
$content .= "--------------------------------\n";
$content .= '名称' . str_repeat(" ", 12) . "数量 单价\n";
$content .= "";
$name = $goods['name'];
if ($goods['data']) {
$name = $goods['name'] . '(' . $goods['data'] . ')';
}
if ($goods['attribute']) {
$name = $name . '(' . $goods['attribute'] . ')';
}
if ($goods['material']) {
/* $material = json_decode($goods['material'], true);
$mes = '';
foreach ($material as $v) {
$mes .= $v['name'] . '(' . $v['number'] . '),';
}*/
$name = $name . '(' . $goods['material'] . ')';
}
if ($goods['vipMoney'] > 0) {
$value['money'] = $goods['vipMoney'];
}
$content .= "" . $name . " | " . $goods['num'] . " | " . $goods['money'] . " |
";
$content .= "
\n";
if($note){
$content .= "" . $note . "\n";
}
$content .= "----#" . $order['takeNo'] . "完----\n";
return $content;
}
static function feiOneInContent(array $order,array $store,array $goods,$note=null){
$goodsInfo[]=$goods;
if($order['orderMode']==1){
$content= "台号:" . $order['number'] . "
";
$timeStr="开台时间:";
}else{
$content= "取餐码:" . $order['callNo'] . "
";
$timeStr="下单时间:";
}
$content .= "*" . $store['name'] . "*
";
if($order['orderMode']==1){
$tableName = $order['regionName'] . ' ' . $order['typeName'] . ' ' . $order['people'] . '人';
$content .= "餐桌信息:" . $tableName . "
";
}else {
if ($order['isOut'] == 1) {
$eatType = '店内就餐';
} else {
$eatType = '打包带走';
}
$content .= "取单方式:" . $eatType . "
";
}
$content .= "--------------------------------
";
$content .= "订单号:" . $order['outTradeNo'] . "
";
$content .= $timeStr. date('Y-m-d H:i:s', $order['createdAt']) . "
";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "
";
}
$content .= "--------------------------------
";
$content .= "名称 数量 单价
";
$content .= "".self::feiStyle($goodsInfo)."";
if($note){
$content .= "" . $note . "\n";
}
//$content .= "门店电话:" . $store['storeTel'] . "\n\n";
$content .= "----#" . $order['takeNo'] . "完----\n";
return $content;
}
//易联云整单
static function yiInAllContent(array $order,array $store,array $goods,$note=null,$display=null,$qrContent=null,$goodsId=null,$pattern=null){
// var_dump($goodss);die;
$payType = '微信支付';
switch ($order['payMode']) {
case 2:
$payType = '支付宝支付';
break;
case 5:
$payType = '余额支付';
break;
case 10:
$payType = '货到付款';
break;
}
$orderPay="未支付";
if($order['payAt']>0){
$orderPay="已支付";
}
if($order['orderMode']==1){
$content= "台号:" . $order['number'] . "\n";
$timeStr="开台时间:";
}else{
$content= "取餐码:" . $order['callNo'] . "\n";
$timeStr="下单时间:";
}
$content .= "*" . $store['name'] . "*\n";
if($goodsId){
$num=$goods[0]['addNum']?:1;
$content.= "[加菜" . $num . "]\n";
}
if($order['orderMode']==1){
$tableName = $order['regionName'] . ' ' . $order['typeName'] . ' ' . $order['people'] . '人';
$content .= "餐桌信息:" . $tableName . "\n";
}else {
if ($order['isOut'] == 1) {
$eatType = '店内就餐';
} else {
$eatType = '打包带走';
}
$content .= "取单方式:" . $eatType . "\n";
}
$content .= "--------------------------------\n";
$content .= "订单号:" . $order['outTradeNo'] . "\n";
$content .= $timeStr . date('Y-m-d H:i:s', $order['createdAt']) . "\n";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "\n";
}
$content .= "--------------------------------\n";
$content .= '名称' . str_repeat(" ", 12) . "数量 单价\n";
$content .= "";
foreach ($goods as $key => $value) {
$name = $value['name'];
if ($value['data']) {
$name = $value['name'] . '(' . $value['data'] . ')';
}
if ($value['attribute']) {
$name = $name . '(' . $value['attribute'] . ')';
}
if ($value['material']) {
/* $material = json_decode($value['material'], true);
$mes = '';
foreach ($material as $v) {
$mes .= $v['name'] . '(' . $v['number'] . '),';
}*/
$name = $name . '(' . $value['material'] . ')';
}
if ($value['vipMoney'] > 0) {
$value['money'] = $value['vipMoney'];
}
$content .= "" . $name . " | " . $value['num'] . " | " . $value['money'] . " |
";
}
$content .= "
\n";
if(!$goodsId) {
$content .= "合计: | " . $order['goodsNum'] . " | " . $order['originMoney'] . " |
";
$content .= "----------其它费用----------\n";
if ($order['deliveryMoney'] > 0) {
$content .= "[配送费:+" . $order['deliveryMoney'] . "]\n";
}
if ($order['tablewareMoney'] > 0) {
$content .= "[餐桌费:+" . $order['tablewareMoney'] . "]\n";
}
if ($order['preferentialMoney'] > 0) {
$content .= "[满减优惠:-" . $order['preferentialMoney'] . "]\n";
}
if ($order['platformCouponPreferential'] > 0) {
$content .= "[平台优惠券优惠:-" . $order['platformCouponPreferential'] . "]\n";
}
if ($order['couponPreferential'] > 0) {
$content .= "[优惠券优惠:-" . $order['couponPreferential'] . "]\n";
}
if ($order['newMoney'] > 0) {
$content .= "[新客立减:-" . $order['newMoney'] . "]\n";
}
if ($order['deliveryPreferential'] > 0) {
$content .= "[减免配送费:-" . $order['deliveryPreferential'] . "]\n";
}
if ($order['giveName']) {
$content .= "[赠送:-" . $order['giveName'] . "]\n";
}
$content .= "应付:¥" . $order['money'] ."(".$orderPay.")". "\n";
if ($note) {
$content .= "" . $note . "\n";
}
$content .= "门店电话:" . $store['storeTel'] . "\n\n";
if ($display == 1) {
$content .= "" . $qrContent . "";
}
$content .= "----#" . $order['takeNo'] . "完----\n";
}
//var_dump($content);die;
return $content;
}
static function feiInAllContent(array $order,array $store,array $goods,$note=null,$display=null,$qrContent=null,$goodsId=null,$pattern){
$payType = '微信支付';
switch ($order['payMode']) {
case 2:
$payType = '支付宝支付';
break;
case 5:
$payType = '余额支付';
break;
case 10:
$payType = '货到付款';
break;
}
$orderPay="未支付";
if($order['payAt']>0){
$orderPay="已支付";
}
if($order['orderMode']==1){
$content= "台号:" . $order['number'] . "
";
$timeStr="开台时间:";
}else{
$content= "取餐码:" . $order['callNo'] . "
";
$timeStr="下单时间:";
}
$content .= "*" . $store['name'] . "*
";
if($goodsId){
$num=$goods[0]['addNum']?:1;
$content.= "[加菜" . $num . "]
";
}
if($order['orderMode']==1){
$tableName = $order['regionName'] . ' ' . $order['typeName'] . ' ' . $order['people'] . '人';
$content .= "餐桌信息:" . $tableName . "
";
}else {
if ($order['isOut'] == 1) {
$eatType = '店内就餐';
} else {
$eatType = '打包带走';
}
$content .= "取单方式:" . $eatType . "
";
}
$content .= "--------------------------------
";
$content .= "订单号:" . $order['outTradeNo'] . "
";
$content .= $timeStr. date('Y-m-d H:i:s', $order['createdAt']) . "
";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "
";
}
$content .= "--------------------------------
";
$content .= "名称 数量 单价
";
$content .= "".self::feiStyle($goods)."";
if(!$goodsId) {
$content .= self::feiStyle(['0' => ['name' => '合计', 'num' => $order['goodsNum'], 'money' => $order['originMoney']]]);
$content .= "----------其它费用----------\n";
if ($order['deliveryMoney'] > 0) {
$content .= "配送费:" . $order['deliveryMoney'] . "
";
}
if ($order['tablewareMoney'] > 0) {
$content .= "[餐桌费:+" . $order['tablewareMoney'] . "]
";
}
if ($order['preferentialMoney'] > 0) {
$content .= "[满减优惠:-" . $order['preferentialMoney'] . "]
";
}
if ($order['platformCouponPreferential'] > 0) {
$content .= "[平台优惠券优惠:-" . $order['platformCouponPreferential'] . "]
";
}
if ($order['couponPreferential'] > 0) {
$content .= "[优惠券优惠:-" . $order['couponPreferential'] . "]
";
}
if ($order['newMoney'] > 0) {
$content .= "[新客立减:-" . $order['newMoney'] . "]
";
}
if ($order['deliveryPreferential'] > 0) {
$content .= "[减免配送费:-" . $order['deliveryPreferential'] . "]
";
}
if ($order['giveName']) {
$content .= "[赠送:" . $order['giveName'] . "]
";
}
$content .= "应付:¥" . $order['money']."(".$orderPay.")
";
if ($note) {
$content .= "" . $note . "
";
}
$content .= "门店电话:" . $store['storeTel'] . "
";
if ($display == 1) {
$content .= "" . $qrContent . "";
}
$content .= "----#" . $order['takeNo'] . "完----\n";
}
return $content;
}
//快餐订单打印
public static function instoreOrderPrint($orderId,$support=3,$goodsId=null,$modePrint=true){
$order=(new \yii\db\Query())
->from('{{%ybwm_instore_order}}')
->where('id=:id',[':id'=>$orderId])->one();
$query=(new \yii\db\Query())
->from('{{%ybwm_print}}')
->where('deleteAt=0 AND display=1 AND uniacid=:uniacid AND storeId=:storeId AND support=:support',[':uniacid'=>$order['uniacid'],':storeId'=>$order['storeId'],'support'=>$support]);
if($support==2){
$tableInfo=(new \yii\db\Query())->select('areaId')
->from('{{%ybwm_table}}')
->where('id=:id',[':id'=>$order['tableId']])->one();
$areaId=$tableInfo['areaId'];
// $query=$query->andWhere(['like','areaId',$areaId]);
//如果是加菜
if($goodsId){
$query=$query->andWhere(['and',['in','pattern',[1,3]],['like','printMode2',1]]);
}
}
$print=$query->All();
if (!$print) {
return false;
}
$systemSet=Config::getSystemSet('print',$order['uniacid']);
foreach ($print as $value){
$rst=json_decode($value['data'],true);
//易联云
if($value['type']==1){
$dynum=$rst['wmnum']?:1;
$note=$systemSet['sjlNote']?:'';
$display=$systemSet['display']?:2;
$qrContent=$systemSet['codeUrl']?:'';
//商家联
if($value['pattern']==1){
//整单打印
if($value['printMode']==1){
$content=self::instoreAllContent($orderId,$value['type'],$value['printMode'],$note,$display,$qrContent,$goodsId);
//var_dump($content);die;
$content= "{$dynum}".$content;
self::print($rst,$content);
}
//一菜一单
if($value['printMode']==3){
$note=$systemSet['oneNote']?:'';
$info=self::instoreAllContent($orderId,$value['type'],$value['printMode'],$note,0,0,$goodsId);
foreach ($info['goods'] as $value){
$content = self::yiOneInContent($info['order'], $info['store'], $value,$note);
// var_dump($content);die;
$content= "{$dynum}".$content;
self::print($rst,$content);
}
}
}
//顾客联
if($value['pattern']==2){
$content=self::instoreAllContent($orderId,$value['type'],$value['printMode'],$note,$display,0,$goodsId);
$content= "{$dynum}".$content;
self::print($rst,$content);
}
//厨房联
if($value['pattern']==3&&$modePrint){
//整单打印
if($value['printMode']==1){
$content=self::instoreAllContent($orderId,$value['type'],$value['printMode'],0,0,0,$goodsId,$value['pattern']);
$content= "{$dynum}".$content;
self::print($rst,$content);
}
//分组打印
if($value['printMode']==2){
$content=self::typeInContent($orderId,$value['type'],$value['printMode'],$value['categoryIds'],$goodsId);
if(!$content){
continue;
}
if($value['printModeType']==2){
$info=self::typeInContent($orderId,3,$value['printMode'],$value['categoryIds'],$goodsId);
foreach ($info['goods'] as $value){
$content = self::yiOneInContent($info['order'], $info['store'], $value,$note);
//var_dump($content);die;
$content= "{$dynum}".$content;
self::print($rst,$content);
}
}else{
$content= "{$dynum}".$content;
self::print($rst,$content);
}
}
//一菜一单
if($value['printMode']==3){
$note=$systemSet['oneNote']?:'';
$info=self::instoreAllContent($orderId,$value['type'],$value['printMode'],$note,0,0,$goodsId);
foreach ($info['goods'] as $value){
$content = self::yiOneInContent($info['order'], $info['store'], $value,$note);
// var_dump($content);die;
$content= "{$dynum}".$content;
self::print($rst,$content);
}
}
//标签打印
if($value['printMode']==4){
$content=self::typeInContent($orderId,$value['type'],$value['printMode'],$value['label'],$goodsId);
if(!$content){
continue;
}
$content= "{$dynum}".$content;
self::print($rst,$content);
}
}
}
//飞蛾云
if($value['type']==2){
$note=$systemSet['gklNote']?:'';
$display=$systemSet['display2']?:2;
$qrContent=$systemSet['codeUrl2']?:'';
// file_put_contents('1.txt', $value['printMode']);
//商家联
if($value['pattern']==1){
//整单打印
if($value['printMode']==1){
$content=self::instoreAllContent($orderId,$value['type'],$value['printMode'],$note,$display,$qrContent,$goodsId);
// var_dump($content);die;
self::feiPrint($rst,$content);
}
//一菜一单
if($value['printMode']==3){
$note=$systemSet['oneNote']?:'';
$info=self::instoreAllContent($orderId,$value['type'],$value['printMode'],$note,0,0,$goodsId);
foreach ($info['goods'] as $value){
$content = self::feiOneInContent($info['order'], $info['store'], $value,$note);
self::feiPrint($rst,$content);
}
}
}
//顾客联
if($value['pattern']==2){
$content=self::instoreAllContent($orderId,$value['type'],$value['printMode'],$note,$display,$qrContent,$goodsId);
self::feiPrint($rst,$content);
}
//厨房联
if($value['pattern']==3&&$modePrint){
//整单打印
if($value['printMode']==1){
$content=self::instoreAllContent($orderId,$value['type'],$value['printMode'],0,0,0,$goodsId);
self::feiPrint($rst,$content);
}
//分组打印
if($value['printMode']==2){
$content=self::typeInContent($orderId,$value['type'],$value['printMode'],$value['categoryIds']);
//var_dump($content);die;
if(!$content){
continue;
}
if($value['printModeType']==2){
$info=self::typeInContent($orderId,3,$value['printMode'],$value['categoryIds'],$goodsId);
foreach ($info['goods'] as $value){
$content = self::feiOneInContent($info['order'], $info['store'], $value,$note);
self::feiPrint($rst,$content);
}
}else {
self::feiPrint($rst, $content);
}
}
//一菜一单
if($value['printMode']==3){
$note=$systemSet['oneNote']?:'';
//$info=self::instoreAllContent($orderId,$value['type'],$value['printMode'],$note);
$info=self::instoreAllContent($orderId,$value['type'],$value['printMode'],$note,0,0,$goodsId);
foreach ($info['goods'] as $value){
$content = self::feiOneInContent($info['order'], $info['store'], $value,$note);
self::feiPrint($rst,$content);
}
}
//标签打印
if($value['printMode']==4){
$content=self::typeInContent($orderId,$value['type'],$value['printMode'],$value['label'],$goodsId);
// var_dump($content);die;
if(!$content){
continue;
}
self::feiPrint($rst,$content);
}
}
}
//飞蛾标签打印机
if(($value['type']==3&&$modePrint) or($value['type']==3&&!$modePrint&&$value['pattern']!=3)){
$info=self::instoreAllContent($orderId,$value['type'],$value['printMode'],$note='',0,0,$goodsId);
if($value['printMode']==2){
$info=self::typeInContent($orderId,$value['type'],$value['printMode'],$value['categoryIds']);
}
if($value['printMode']==4 ){
$info=self::typeInContent($orderId,$value['type'],$value['printMode'],$value['label'],$goodsId);
}
$goods=$info['goods'];
$orderNum=0;
foreach ($goods as $key => $value) {
$orderNum+=$value['num'];
if($value['num']>1){
for ($i=0; $i <$value['num'] ; $i++) {
if($i>0){
array_push($goods,$value);
}
}
}
}
foreach ($goods as $key=>$value){
$num=$key+1;
$content = self::labelAllContent($info['order'], $info['store'], $value,$num,['orderType'=>$order['orderMode'],'isOut'=>$order['isOut']]);
// var_dump($content);die;
self::labelPrint($rst,$content);
}
}
}
}
static function instoreCashierContent($orderId,$type=1){
$order=(new \yii\db\Query())
->from('{{%ybwm_instore_order}}')
->where('id=:id',[':id'=>$orderId])->one();
$store=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('id=:id',[':id'=>$order['storeId']])->one();
$goods = (new \yii\db\Query())
->from('{{%ybwm_order_goods}}')
->where(' orderId=:orderId AND item=2 and addType=3', [':orderId' => $orderId])->All();
// return $goods;
// var_dump($goodss);die;
$payType = '微信支付';
switch ($order['payMode']) {
case 2:
$payType = '支付宝支付';
break;
case 5:
$payType = '余额支付';
break;
case 10:
$payType = '货到付款';
break;
}
if($type==1){
if($order['orderMode']==1){
$content= "台号:" . $order['number'] . "\n";
$timeStr="开台时间:";
}else{
$content= "取餐码:" . $order['callNo'] . "\n";
$timeStr="下单时间:";
}
$content .= "*" . $store['name'] . "*\n";
$content.= "[退菜]\n";
if($order['orderMode']==1){
$tableName = $order['regionName'] . ' ' . $order['typeName'] . ' ' . $order['people'] . '人';
$content .= "餐桌信息:" . $tableName . "\n";
}else {
if ($order['deliveryMode'] == 10 and $order['isOut'] == 1) {
$eatType = '店内就餐';
} else {
$eatType = '打包带走';
}
$content .= "取单方式:" . $eatType . "\n";
}
$content .= "--------------------------------\n";
$content .= "订单编号:" . $order['outTradeNo'] . "\n";
$content .= $timeStr . date('Y-m-d H:i:s', $order['createdAt']) . "\n";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "\n";
}
$content .= "--------------------------------\n";
$content .= '名称' . str_repeat(" ", 12) . "数量 单价\n";
$content .= "";
foreach ($goods as $key => $value) {
$name = $value['name'];
if ($value['data']) {
$name = $value['name'] . '(' . $value['data'] . ')';
}
if ($value['attribute']) {
$name = $name . '(' . $value['attribute'] . ')';
}
if ($value['material']) {
/* $material = json_decode($value['material'], true);
$mes = '';
foreach ($material as $v) {
$mes .= $v['name'] . '(' . $v['number'] . '),';
}*/
$name = $name . '(' . $value['material'] . ')';
}
if ($value['vipMoney'] > 0) {
$value['money'] = $value['vipMoney'];
}
$content .= "" . $name . " | " . $value['num'] . " | " . $value['money'] . " |
";
}
$content .= "
\n";
}else{
if($order['orderMode']==1){
$content= "台号:" . $order['number'] . "
";
$timeStr="开台时间:";
}else{
$content= "取餐码:" . $order['callNo'] . "
";
$timeStr="下单时间:";
}
$content .= "*" . $store['name'] . "*
";
$content.= "[退菜]
";
if($order['orderMode']==1){
$tableName = $order['regionName'] . ' ' . $order['typeName'] . ' ' . $order['people'] . '人';
$content .= "餐桌信息:" . $tableName . "
";
}else {
if ($order['deliveryMode'] == 10 and $order['isOut'] == 1) {
$eatType = '店内就餐';
} else {
$eatType = '打包带走';
}
$content .= "取单方式:" . $eatType . "
";
}
$content .= "--------------------------------
";
$content .= "订单号:" . $order['outTradeNo'] . "
";
$content .= $timeStr. date('Y-m-d H:i:s', $order['createdAt']) . "
";
if ($order['userNote']) {
$content .= "备注:" . $order['userNote'] . "
";
}
$content .= "--------------------------------
";
$content .= "名称 数量 单价
";
$content .= self::feiStyle($goods);
}
if ($order['deliveryMoney'] > 0) {
$content .= "[配送费:+" . $order['deliveryMoney'] . "]\n";
}
if ($order['tablewareMoney'] > 0) {
$content .= "[餐桌费:+" . $order['tablewareMoney'] . "]\n\n";
}
if ($order['preferentialMoney'] > 0) {
$content .= "[满减优惠:-" . $order['preferentialMoney'] . "]\n";
}
if ($order['couponPreferential'] > 0) {
$content .= "[优惠券优惠:-" . $order['couponPreferential'] . "]\n";
}
if ($order['newMoney'] > 0) {
$content .= "[新客立减:-" . $order['newMoney'] . "]\n";
}
if ($order['deliveryPreferential'] > 0) {
$content .= "[减免配送费:-" . $order['deliveryPreferential'] . "]\n";
}
if ($order['giveName']) {
$content .= "[赠送:-" . $order['giveName'] . "]\n";
}
if($type==1){
$content .= "门店电话:" . $store['storeTel'] . "\n\n";
$content .= "----#" . $order['takeNo'] . "完----\n";
}else{
$content .= "门店电话:" . $store['storeTel'] . "
";
$content .= "----#" . $order['takeNo'] . "完----\n";
}
return $content;
}
//var_dump($content);die;
//收银台退菜
static function returnFoodPrint($orderId){
$order=(new \yii\db\Query())
->from('{{%ybwm_instore_order}}')
->where('id=:id',[':id'=>$orderId])->one();
$tableInfo=(new \yii\db\Query())->select('areaId')
->from('{{%ybwm_table}}')
->where('id=:id',[':id'=>$order['tableId']])->one();
$areaId=$tableInfo['areaId'];
$print=(new \yii\db\Query())
->from('{{%ybwm_print}}')
->where('deleteAt=0 AND display=1 AND uniacid=:uniacid AND storeId=:storeId AND support=:support',[':uniacid'=>$order['uniacid'],':storeId'=>$order['storeId'],'support'=>2])
->andWhere(['and',['in','pattern',[1,3]],['like','printMode2',2]])->All();
//->andWhere(['like','areaId',$areaId])
if (!$print) {
return false;
}
foreach ($print as $value){
$rst=json_decode($value['data'],true);
//易联云
if($value['type']==1){
$dynum=$rst['wmnum']?:1;
$content=self::instoreCashierContent($orderId,1);
$content= "{$dynum}".$content;
self::print($rst,$content);
}
//飞蛾云
if($value['type']==2){
// file_put_contents('1.txt','tuicai'.$orderId.'---');
$content=self::instoreCashierContent($orderId,2);
//var_dump($content);die;
self::feiPrint($rst,$content);
}
}
}
//排队易联云打印内容
static function queuingContent($order,$type) {
$store=(new \yii\db\Query())
->from('{{%ybwm_store}}')
->where('id=:id',[':id'=>$order['storeId']])->one();
$count=(new \yii\db\Query())
->from('{{%ybwm_queuing}}')
->where('storeId=:storeId AND tableId=:tableId AND day=:day AND state=1',[':storeId'=>$order['storeId'],':tableId'=>$order['tableId'],':day'=>$order['day']])->count()?:0;
if($type==1) {
$content= "*" . $store['name'] . "*\n";
$content.= "排队号码:" . $order['code'] . "\n";
$content.= "前面需等待" . $count . "桌,请稍后...\n";
$content.= "--------------------------------\n";
$content.= "就餐人数:" . $order['people'] . "人\n";
$content.= "取号时间:" . date('Y-m-d H:i:s', $order['createdAt']) . "\n";
$content.= "--------------------------------\n";
$content.= "温馨提示:听到叫号后请到服务台,过号作废!\n";
}else{
$content= "*" . $store['name'] . "*\n";
$content.= "排队号码:" . $order['code'] . "\n";
$content.= "前面需等待" . $count . "桌,请稍后...\n";
$content.= "--------------------------------\n";
$content.= "就餐人数:" . $order['people'] . "人\n";
$content.= "取号时间:" . date('Y-m-d H:i:s', $order['createdAt']) . "\n";
$content.= "--------------------------------\n";
$content.= "温馨提示:听到叫号后请到服务台,过号作废!\n";
}
return $content;
}
//排队
static function queuingPrint($orderId){
$order=(new \yii\db\Query())
->from('{{%ybwm_queuing}}')
->where('id=:id',[':id'=>$orderId])->one();
$print=(new \yii\db\Query())
->from('{{%ybwm_print}}')
->where('deleteAt=0 AND display=1 AND uniacid=:uniacid AND storeId=:storeId AND support=:support',[':uniacid'=>$order['uniacid'],':storeId'=>$order['storeId'],'support'=>5])
->All();
if (!$print) {
return false;
}
foreach ($print as $value){
$rst=json_decode($value['data'],true);
//易联云
if($value['type']==1){
$dynum=$rst['wmnum']?:1;
$content=self::queuingContent($order,$value['type']);
$content= "{$dynum}".$content;
self::print($rst,$content);
}
//飞蛾云
if($value['type']==2){
$content=self::queuingContent($order,$value['type']);
//var_dump($content);die;
self::feiPrint($rst,$content);
}
}
}
}