| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\utils;
- use app\constants\OptionSetting;
- use app\models\FoodFlag;
- use app\models\Goods;
- use app\models\Mch;
- use app\models\Md;
- use app\models\Option;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\models\OrderForm;
- use app\models\OrderGoodsCancel;
- use app\models\OrderTransit;
- use app\models\Printer;
- use app\models\PrinterSetting;
- use app\models\PurchaseOrder;
- use app\modules\admin\models\SupplierForm;
- use yii\db\Exception;
- use yii\helpers\Json;
- use app\models\DeliveryInfo;
- class PrintOrder
- {
- public $store_id;
- public $mch_id;
- public $md_id;
- public $md;
- public $store_name;
- public $mch;
- public $order_id;
- /**
- * 打印设置
- * @var $setting
- */
- public $setting; // 打印设置
- /**
- * 打印机型号
- * @var $printer
- */
- public $printer;
- /**
- * 打印机配置
- * @var $printer_setting
- */
- public $printer_setting;
- /**
- * 订单类型 0--商城订单 1--秒杀订单 2--拼团订单 3--预约订单
- * @var $order_type
- */
- public $order_type;
- /**
- * 订单详情
- * @var $order
- */
- public $order;
- /**
- * 订单商品详情
- * @var $goods_list
- */
- public $goods_list;
- /**
- * 订单打印方式
- * @var $print_type
- */
- public $print_type;
- public $extra;
- public $type;
- public $supplier_id;
- public $is_refund = false;
- public function __construct($store_id, $order_id, $print_type, $order_type = 0, $md_id = 0, $type = 0, $mch_id = 0, $supplier_id = 0)
- {
- $this->store_id = $store_id;
- $this->mch_id = (int)$mch_id;
- $this->store_name = Option::get('name', $store_id, 'store')['value'];
- $md = Md::findOne($md_id);
- if ($md) {
- $this->md = $md;
- } else {
- $this->md = null;
- }
- $this->md_id = $md ? $md_id : -1;
- $this->order_id = $order_id;
- $this->print_type = $print_type;
- $this->order_type = $order_type;
- $this->type = $type;
- $this->supplier_id = $supplier_id;
- }
- public function print_order()
- {
- try {
- // 打印设置
- if (in_array((int)$this->type, [1, 2])) {
- $this->setting = PrinterSetting::findOne(['supplier_id' => $this->supplier_id ?: get_supplier_id()]);
- } else {
- $this->setting = PrinterSetting::findOne(['store_id' => $this->store_id, 'md_id' => $this->md_id]);
- if (!$this->setting) {
- $this->md_id = 0;
- $this->setting = PrinterSetting::findOne(['store_id' => $this->store_id, 'md_id' => $this->md_id]);
- }
- }
- if($this->mch_id){
- $this->setting = PrinterSetting::findOne(['mch_id' => $this->mch_id]);
- }
- if (!$this->setting) {
- \Yii::warning('未设置打印设置');
- throw new \Exception('未设置打印设置');
- }
- $type = json_decode($this->setting->type, true);
- if (!($type[$this->print_type] && $type[$this->print_type] == 1 || $this->print_type == 'reprint')) {
- \Yii::warning('打印设置打印方式');
- throw new \Exception('打印设置打印方式');
- }
- if (in_array((int)$this->type, [1, 2])) {
- $this->printer = Printer::findAll(['id' => explode(',',$this->setting->printer_id), 'is_delete' => 0]);
- } else {
- $this->printer = Printer::findAll(['id' => explode(',',$this->setting->printer_id), 'is_delete' => 0, 'md_id' => $this->md_id]);
- }
- if (count($this->printer) == 0) { // 打印机参数
- \Yii::warning('未找到设置的打印机');
- throw new \Exception('未找到设置的打印机');
- }
- // 整理订单打印信息 商城订单打印
- if (intval($this->type) === 0) {
- $order_id = $this->order_id;
- } else {
- $order_data = [
- 'order_id' => $this->order_id,
- 'status' => $this->type//1转单订单 2采购订单
- ];
- $domain = (new OptionSetting)->getCloudDomainName();
- $order_url = "/user/getOrder";
- $orderInfo = cloud_post($domain . $order_url,
- $order_data);
- $orderInfo = json_decode($orderInfo,true);
- if($orderInfo['code'] !== 0){
- return $orderInfo['msg'];
- }
- $orderInfo['data']['total_price'] = $orderInfo['data']['pay_price'];
- $orderInfo['data']['pay_type'] = 0;
- $goods_send_type = $orderInfo['data']['goods_send_type'];
- switch (intval($goods_send_type)) {
- case 1:
- $send_type = "集采";
- break;
- case 2:
- $send_type = "自主配送";
- break;
- case 3:
- $send_type = "代理配送";
- break;
- case 4:
- $send_type = "云仓库存";
- break;
- case 5:
- $send_type = "仓库同城";
- break;
- case 6:
- $send_type = "仓库快递";
- break;
- default:
- $send_type = "快递";
- break;
- }
- $orderInfo['data']['is_pay'] = intval($orderInfo['data']['status']) === 2 ? 0 : 1;
- $orderInfo['data']['created_at'] = $orderInfo['data']['pay_time'];
- $this->order = $orderInfo['data'];
- // 这里要根据商城订单的配送状态
- if($this->type){
- $orderT = OrderTransit::findOne(['cloud_order_id' => $this->order_id]);
- $storeOrder = Order::findOne($orderT->order_id);
- $this->order['md_id'] = $storeOrder->md_id;
- $this->order['is_offline'] = $storeOrder->is_offline;
- }
- $order_type = '供货商' . (intval($this->type) === 1 ? '转单订单' : '批发订单');
- $this->goods_list = $orderInfo['data']['goods_list'];
- }
- if (isset($order_id)) {
- $this->order = Order::find()->where(['id' => $order_id, 'is_delete' => 0])->asArray()->one();
- $this->goods_list = $this->getOrderGoodsList($this->order['id']);
- }
- if (intval($this->type) === 0) {
- if ($this->order['is_offline'] == 0) {
- if ($this->order['is_delivery'] == 0) {
- $send_type = '快递配送';
- } else {
- $send_type = '同城配送';
- }
- } else {
- $send_type = '到店自提';
- }
- $order_type = '商城订单';
- if (isset($this->order['order_origin']) && intval($this->order['order_origin']) === 4) {
- $send_type = '收银台';
- $order_type = '收银台订单';
- }
- }
- $this->extra = [
- 'order_type' => $order_type,
- 'send_type' => $send_type,
- ];
- switch ($this->order['pay_type']) {
- case 1:
- case 0:
- $this->extra['pay_type'] = "线上支付";
- break;
- case 2:
- $this->extra['pay_type'] = "货到付款";
- break;
- case 3:
- $this->extra['pay_type'] = "余额支付";
- break;
- default:
- $this->extra['pay_type'] = "";
- }
- foreach($this->printer as $printer){
- $this->handlePrint($printer);
- }
- return [
- 'code' => 0,
- 'msg' => '打印成功',
- 'data' => [],
- 'cc' => [$order_id, $this->order_id, $this->type, [], $this->goods_list, $this->order],
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage() . $e->getFile() . $e->getLine(),
- 'cc' => [$order_id, $this->order_id, $this->type, [], $this->goods_list, $this->order],
- 'data' => $e
- ];
- }
- }
- private function handlePrint($printer)
- {
- // 打印机配置
- $this->printer_setting = json_decode($printer->printer_setting, true);
- if ($printer->printer_type == 'kdt2') {
- $res = $this->printer_1();
- }
- if ($printer->printer_type == 'yilianyun-k4') {
- $res = $this->printer_2();
- }
- if ($printer->printer_type == 'feie') {
- $res = $this->printer_3();
- }
- if ($printer->printer_type == 'gp') {
- $res = $this->printer_4();
- }
- if ($printer->printer_type == 'xhy') {
- $res = $this->printer_5($printer);
- }
- if ($printer->printer_type == 'dqzn') {
- $res = $this->printer_6($printer);
- }
- if ($printer->printer_type == 'feie_label') {
- $res = $this->printer_7();
- }
- }
- /**
- * 365打印机
- */
- private function printer_1()
- {
- $big = [
- 1 => [
- 'start' => '',
- 'end' => ''
- ],
- 2 => [
- 'start' => "<B>",
- 'end' => "</B>"
- ],
- 3 => [
- 'start' => '<DB>',
- 'end' => '</DB>'
- ],
- ];
- $start = $big[$this->setting->big]['start'];
- $end = $big[$this->setting->big]['end'];
- date_default_timezone_set("Asia/Shanghai");
- $order = $this->order;
- $addtime = date('Y-m-d H:i:s', $order['created_at']);
- $goods_list = $this->goods_list;
- header("Content-Type: text/html;charset=utf-8");
- $DEVICE_NO = $this->printer_setting['name'];
- $key = $this->printer_setting['key'];
- $time = $this->printer_setting['time'];//打印联数
- $content = "";
- if ($this->mch && $this->mch->name){
- $title_name = $this->mch->name;
- }else{
- $title_name = $this->store_name;
- }
- $content .= "<CB>{$title_name}</CB><BR>";
- if (!empty($order['food_flag_id'])) {
- $FoodFlag = FoodFlag::findOne($order['food_flag_id']);
- $food_num = $FoodFlag->table_num;
- $content .= "桌号:{$food_num}\n";
- }
- if ($this->is_refund) {
- $content .= "订单类型:退款订单<BR>";
- } else {
- if ($order['food_code']) {
- $content .= "标识码:{$order['food_code']}<BR>";
- }
- $content .= "订单类型:{$this->extra['order_type']}<BR>";
- }
- $content .= "支付方式:{$this->extra['pay_type']}<BR>";
- $isPay = $order['is_pay'] == 1 ? '已支付' : '未支付';
- $content .= "支付状态:{$isPay}<BR>";
- $content .= "发货方式:{$this->extra['send_type']}<BR>";
- $content .= "订单号:{$order['order_no']}<BR>";
- $content .= "下单时间:{$addtime}<BR>";
- if ($this->setting->is_attr == 0) {
- $content .= "--------------------------------<BR>";
- $content .= "名称 单价 数量 金额<BR>";
- $content .= "--------------------------------<BR>";
- foreach ($goods_list as $k => $v) {
- $price = round($v['total_price'] / $v['num'], 2);
- $arr = $this->r_str_pad_1($v['name'], 7);
- foreach ($arr as $index => $value) {
- if ($index == 0) {
- $content .= $value . " " . str_pad($price, 5) . " " . str_pad($v['num'], 6) . " " . round($v['total_price'], 2) . '<BR>';
- } else {
- $content .= $value . '<BR>';
- }
- }
- }
- } else {
- /**
- * $content .= "--------------------------------<BR>";
- * $content .= "名称 规格 单价 数量 金额<BR>";
- * $content .= "--------------------------------<BR>";
- * foreach ($goods_list as $k => $v) {
- * $attr = json_decode($v['attr'], true);
- * $attr_arr = [];
- * foreach ($attr as $i => $j) {
- * $attr_arr[] = $j['attr_group_name'] . $j['attr_name'];
- * }
- * $attr_str = implode(',', $attr_arr);
- * $attr_arr_1 = $this->r_str_pad_1($attr_str, 4);
- * $price = round($v['total_price'] / $v['num'], 2);
- * $arr = $this->r_str_pad_1($v['name'], 4);
- * $a = count($attr_arr_1) >= count($arr) ? $attr_arr_1 : $arr;
- * foreach ($a as $index => $value) {
- * $string = "";
- * $string_1 = "";
- * if (isset($arr[$index])) {
- * $string = $arr[$index];
- * }
- * if (isset($attr_arr_1[$index])) {
- * if (!$string) {
- * $string = str_pad($string, 8);
- * }
- * $string_1 = $attr_arr_1[$index];
- * }
- * if ($index == 0) {
- * $content .= $string . " " . $string_1 . str_pad($price, 5) . " " . str_pad($v['num'], 3) . " " . round($v['total_price'], 2) . '<BR>';
- * } else {
- * $content .= $string . " " . $string_1 . '<BR>';
- * }
- * }
- * }
- * */
- $content .= "--------------------------------<BR>";
- $content .= "名称 数量 金额 <BR>";
- $content .= "--------------------------------<BR>";
- foreach ($goods_list as $k => $v) {
- $name = $v['name'];
- if (!empty($v['attr'])) {
- $attr = json_decode($v['attr'], true);
- $attr_arr = [];
- if ($attr['attr_list']) {
- $attr = $attr['attr_list'];
- }
- foreach ($attr as $i => $j) {
- $attr_arr[] = $j['attr_group_name'] . $j['attr_name'];
- }
- $attr_str = implode(',', $attr_arr);
- $name = $v['name'] . '(' . $attr_str . ')';
- }
- $name_arr = $this->r_str_pad_1($name, 8);
- foreach ($name_arr as $index => $value) {
- if ($index == count($name_arr) - 1) {
- $content .= $name_arr[$index] . " " . str_pad('×' . $v['num'], 7) . " " . round($v['total_price'], 2) . "<BR>";
- } else {
- $content .= $name_arr[$index] . '<BR>';
- }
- }
- }
- }
- $content .= "--------------------------------<BR>";
- if ($order['express_price']) {
- $content .= "运费:{$order['express_price']}元<BR>";
- }
- $content .= "总计:{$order['total_price']}元<BR>";
- if (isset($order['user_coupon_id'])) {
- $content .= "优惠券优惠:{$order['coupon_sub_price']}元<BR>";
- }
- if (isset($order['integral'])) {
- $integral = json_decode($order['integral'], true);
- if ($integral['forehead'] != 0) {
- $content .= "积分抵扣:{$integral['forehead']}元<BR>";
- }
- }
- if (isset($order['discount']) && $order['discount'] < 10) {
- $content .= "会员折扣:{$order['discount']}折<BR>";
- }
- if ($this->is_refund) {
- $content .= "实退:{$order['pay_price']}元<BR>";
- } else {
- $content .= $order['is_pay'] == 1 ? "实付:{$order['pay_price']}元<BR>" : "实付:0元<BR>";
- }
- if ($this->order_type != 3) {
- if ((isset($order['is_offline']) && $order['is_offline'] != 1) || (isset($order['offline']) && $order['offline'] != 2)) {
- $content .= "{$start}收货人:{$order['name']}<BR>";
- $content .= "收货地址:{$order['address']}<BR>";
- $content .= "收货人电话:{$order['mobile']}<BR>{$end}";
- $content .= "--------------------------------<BR>";
- } else {
- $content .= "{$start}联系人:{$order['name']}<BR>";
- $content .= "联系人电话:{$order['mobile']}<BR>{$end}";
- $content .= "--------------------------------<BR>";
- $content .= "门店信息<BR>";
- // 门店信息要根据订单上的md_id查询门店 不能根据get_md_id获取 也不能根据构造函数中传入的md_id 因为供货商打印 或者 平台打印 或者 商城打印的时候 是不会传md_id的
- $md = Md::findOne($order['md_id']);
- $content .= "{$md->name}<BR>";
- $content .= "{$md->mobile}<BR>";
- $content .= "{$md->address}<BR>";
- $content .= "--------------------------------<BR>";
- }
- }
- if ($order['remark']) {
- $content .= "备注:{$order['remark']}<BR>";
- } else {
- $orderForm = OrderForm::findAll([
- 'order_id' => $this->order['id'], 'store_id' => $this->store_id, 'is_delete' => 0
- ]);
- if ($orderForm) {
- /* @var $orderForm OrderForm[] */
- foreach ($orderForm as $item) {
- $content .= $item->key . ':' . $item->value . "<BR>";
- }
- }
- }
- if ($order['seller_comments']) {
- $content .= "商家备注:{$order['seller_comments']}<BR>";
- }
- $result = $this->sendSelfFormatOrderInfo($DEVICE_NO, $key, $time, $content);
- \Yii::warning('==>>' . $result);
- $result = Json::decode($result);
- if ($result['responseCode'] != 0) {
- throw new Exception($result['msg'], $result);
- }
- return $result;
- }
- /**
- * 365打印机
- */
- private function sendSelfFormatOrderInfo($device_no, $key, $times, $orderInfo)
- {
- // $times打印次数
- $selfMessage = array(
- 'deviceNo' => $device_no,
- 'printContent' => $orderInfo,
- 'key' => $key,
- 'times' => $times
- );
- $url = "http://open.printcenter.cn:8080/addOrder";
- $options = array(
- 'http' => array(
- 'header' => "Content-type: application/x-www-form-urlencoded ",
- 'method' => 'POST',
- 'content' => http_build_query($selfMessage),
- ),
- );
- $context = stream_context_create($options);
- $result = file_get_contents($url, false, $context);
- return $result;
- }
- /**
- * @param $order_id
- * @return mixed
- * 订单商品详情
- */
- public function getOrderGoodsList($order_id)
- {
- $order_detail_list = OrderDetail::find()->alias('od')
- ->leftJoin(['g' => Goods::tableName()], 'od.goods_id=g.id')
- ->where([
- 'od.is_delete' => 0,
- 'od.order_id' => $order_id,
- ])->select('od.*,g.name, g.product_type')->asArray()->all();
- $new_arr = [];
- foreach ($order_detail_list as $item) {
- $open = true;
- if (!empty($item['food_ext_goods'])) {
- $food_ext_goods = json_decode($item['food_ext_goods'], true);
- if (!empty($food_ext_goods)) {
- $open = false;
- foreach ($food_ext_goods as &$ext_item) {
- $ext_item['is_food_ext_goods'] = 1;
- $ext_item['total_price'] = $ext_item['price'];
- }
- $new_arr = array_merge($new_arr, [$item], $food_ext_goods);
- }
- }
- if ($open) {
- $orderGoodsCancel = OrderGoodsCancel::find()->where(['order_detail_id' => $item['id'], 'status' => [
- OrderGoodsCancel::STATUS_PASS,
- OrderGoodsCancel::STATUS_PAY,
- OrderGoodsCancel::STATUS_PAY_FAIL,
- ]])->groupBy('order_detail_id')
- ->select('SUM(num) as num, SUM(refund_price) as refund_price')
- ->asArray()->one();
- $this->order['total_price'] = bcsub($this->order['total_price'], $orderGoodsCancel['refund_price'], 2);
- $this->order['pay_price'] = bcsub($this->order['pay_price'], $orderGoodsCancel['refund_price'], 2);
- $item['total_price'] = bcsub($item['total_price'], $orderGoodsCancel['refund_price'], 2);
- $item['num'] = bcsub($item['num'], $orderGoodsCancel['num']);
- if ($item['num'] <= 0) {
- continue;
- }
- if ($item['total_price'] <= 0) {
- $item['total_price'] = 0;
- }
- $new_arr = array_merge($new_arr, [$item]);
- }
- }
- return $new_arr;
- }
- /**
- * 补齐空格
- * 截取七个中文字符长度
- */
- private function r_str_pad($input, $n = 7)
- {
- $string = "";
- $count = 0;
- $c_count = 0;
- for ($i = 0; $i < mb_strlen($input, 'UTF-8'); $i++) {
- $char = mb_substr($input, $i, 1, 'UTF-8');
- $string .= $char;
- if (strlen($char) == 3) {
- $count += 2;
- $c_count++;
- } else {
- $count += 1;
- }
- if ($count >= $n * 2) {
- break;
- }
- }
- if ($count < $n * 2) {
- $string = str_pad($string, $n * 2 + $c_count);
- }
- return $string;
- }
- /**
- * 补齐空格
- * 每n个中文字符长度为一个数组元素
- */
- private function r_str_pad_1($input, $n = 7)
- {
- $string = "";
- $count = 0;
- $c_count = 0;
- $arr = array();
- for ($i = 0; $i < mb_strlen($input, 'UTF-8'); $i++) {
- $char = mb_substr($input, $i, 1, 'UTF-8');
- $string .= $char;
- if (strlen($char) == 3) {
- $count += 2;
- $c_count++;
- } else {
- $count += 1;
- }
- if ($count >= $n * 2) {
- $arr[] = $string;
- $string = '';
- $count = 0;
- $c_count = 0;
- }
- }
- if ($count < $n * 2) {
- $string = str_pad($string, $n * 2 + $c_count);
- $arr[] = $string;
- }
- return $arr;
- }
- /**
- * 易联云打印机-k4
- */
- private function printer_2()
- {
- $big = [
- 1 => [
- 'start' => '',
- 'end' => ''
- ],
- 2 => [
- 'start' => '<FS>',
- 'end' => '</FS>'
- ],
- 3 => [
- 'start' => '<FS2>',
- 'end' => '</FS2>'
- ],
- ];
- $start = $big[$this->setting->big]['start'];
- $end = $big[$this->setting->big]['end'];
- date_default_timezone_set("Asia/Shanghai");
- $machine_code = $this->printer_setting['machine_code'];//终端编号
- $key = $this->printer_setting['key'];//终端密钥
- $client_id = $this->printer_setting['client_id'];//用户ID
- $client_key = $this->printer_setting['client_key'];//用户密钥
- $time = $this->printer_setting['time'];//打印联数
- $order = $this->order;
- $addtime = date('Y-m-d H:i:s', $order['created_at']);
- $goods_list = $this->goods_list;
- $print = new Yprint();
- $content = "<MN>{$time}</MN>";
- if ($this->mch && $this->mch->name) {
- $title_name = $this->mch->name;
- } else {
- $title_name = $this->store_name;
- }
- $content .= "<FB><center>{$title_name}</center></FB>\n";
- if (!empty($order['food_flag_id'])) {
- $FoodFlag = FoodFlag::findOne($order['food_flag_id']);
- $food_num = $FoodFlag->table_num;
- $content .= "桌号:{$food_num}\n";
- }
- if ($this->is_refund) {
- $content .= "订单类型:退款订单\n";
- } else {
- if ($order['food_code']) {
- $content .= "标识码:{$order['food_code']}\n";
- }
- $content .= "订单类型:{$this->extra['order_type']}\n";
- }
- $content .= "支付方式:{$this->extra['pay_type']}\n";
- $isPay = $order['is_pay'] == 1 ? '已支付' : '未支付';
- $content .= "支付状态:{$isPay}\n";
- $content .= "发货方式:{$this->extra['send_type']}\n";
- $content .= "订单号:{$order['order_no']}\n";
- $content .= "下单时间:{$addtime}\n";
- $content .= "--------------------------------\n";
- if ($this->setting->is_attr == 0) {
- $content .= "<table><tr><td>名称</td><td>单价</td><td>数量</td><td>金额</td></tr>";
- foreach ($goods_list as $k => $v) {
- $price = round($v['total_price'] / $v['num'], 2);
- $v['name'] = str_replace(',', ',', $v['name']);
- $arr = $this->r_str_pad_1($v['name'], 8);
- foreach ($arr as $index => $value) {
- if ($index == 0) {
- $content .= "<tr><td>" . $value . "</td><td>" . $price . "</td><td>" . $v['num'] . "</td><td>" . round($v['total_price'], 2) . "</td></tr>";
- } else {
- $content .= "<tr><td>" . $value . "</td></tr>";
- }
- }
- }
- $content .= "</table>";
- } else {
- /**
- * $content .= "<table><tr><td>名称</td><td>规格</td><td>数量</td><td>单价</td></tr>";
- * foreach ($goods_list as $k => $v) {
- * $attr = json_decode($v['attr'], true);
- * $attr_arr = [];
- * foreach ($attr as $i => $j) {
- * $attr_arr[] = $j['attr_group_name'] . $j['attr_name'];
- * }
- * $attr_str = implode(',', $attr_arr);
- * $attr_arr_1 = $this->r_str_pad_1($attr_str, 4);
- * $price = round($v['total_price'] / $v['num'], 2);
- * $v['name'] = str_replace(',', ',', $v['name']);
- * $arr = $this->r_str_pad_1($v['name'], 4);
- * $a = count($attr_arr_1) >= count($arr) ? $attr_arr_1 : $arr;
- * foreach ($a as $index => $value) {
- * $string = "";
- * $string_1 = "";
- * if (isset($arr[$index])) {
- * $string = $arr[$index];
- * }
- * if (isset($attr_arr_1[$index])) {
- * if (!$string) {
- * $string = str_pad($string, 8);
- * }
- * $string_1 = $attr_arr_1[$index];
- * }
- * if ($index == 0) {
- * $content .= "<tr><td>" . $string . "</td><td>" . $string_1 . "</td><td>" . $v['num'] . "</td><td>" . $price . "</td></tr>";
- * } else {
- * $content .= "<tr><td>" . $string . "</td><td>" . $string_1 . "</td></tr>";
- * }
- * }
- * }
- * $content .= "</table>";
- * */
- $content .= "<table><tr><td>名称</td><td>数量</td><td>总价</td></tr>";
- foreach ($goods_list as $k => $v) {
- $name = $v['name'];
- if (!empty($v['attr'])) {
- if (!is_array($v['attr'])) {
- $attr = json_decode($v['attr'], true);
- } else {
- $attr = $v['attr'];
- }
- if (intval($v['product_type']) === 0) {
- $attr_arr = [];
- if($attr['attr_list']){
- $attr = $attr['attr_list'];
- }
- foreach ($attr as $i => $j) {
- $attr_arr[] = ($j['attr_group_name'] ?? '') . ($j['attr_name'] ?? '');
- }
- $attr_str = implode(',', $attr_arr);
- $name = $v['name'] . '(' . $attr_str . ')';
- } elseif (intval($v['product_type']) === 1) {
- $name = $v['name'] . '(预约日期:' . $attr[0]['date'] . '-' . $attr[count($attr) - 1]['date'] . ')';
- } elseif (intval($v['product_type']) === 2) {
- $name = $v['name'] . '(预约时间:' . $attr['data'] . ' ' . $attr['time'] . ')';
- }
- }
- $name_arr = $this->r_str_pad_1($name, 6);
- foreach ($name_arr as $index => $value) {
- if ($index == count($name_arr) - 1) {
- $content .= "<tr><td>" . $name_arr[$index] . "</td><td>" . '×' . $v['num'] . "</td><td>" . round($v['total_price'], 2) . "</td></tr>";
- } else {
- $content .= "<tr><td>" . $name_arr[$index] . "</td><td></td><td></td></tr>";
- }
- }
- }
- $content .= "</table>";
- }
- $content .= "--------------------------------\n";
- if ($order['express_price']) {
- $content .= "运费:{$order['express_price']}元\n";
- }
- $content .= "总计:{$order['total_price']}元\n";
- if (isset($order['user_coupon_id'])) {
- $content .= "优惠券优惠:{$order['coupon_sub_price']}元\n";
- }
- if (isset($order['integral'])) {
- $integral = json_decode($order['integral'], true);
- if ($integral['forehead'] != 0) {
- $content .= "积分抵扣:{$integral['forehead']}元\n";
- }
- }
- if (isset($order['discount']) && $order['discount'] < 10) {
- $content .= "会员折扣:{$order['discount']}折\n";
- }
- if ($this->is_refund) {
- $content .= "实退:{$order['pay_price']}元\n";
- } else {
- $content .= $order['is_pay'] == 1 ? "实付:{$order['pay_price']}元\n" : "实付:0元\n";
- }
- if ($this->order_type != 3) {
- if ((isset($order['is_offline']) && $order['is_offline'] != 1) || (isset($order['offline']) && $order['offline'] != 2)) {
- $content .= "{$start}收货人:{$order['name']}\n";
- $content .= "收货地址:{$order['address']}\n";
- $content .= "收货人电话:{$order['mobile']}\n{$end}";
- $content .= "--------------------------------\n";
- } else {
- $content .= "{$start}联系人:{$order['name']}\n";
- $content .= "联系人电话:{$order['mobile']}\n{$end}";
- $content .= "--------------------------------\n";
- $content .= "门店信息\n";
- // 门店信息要根据订单上的md_id查询门店 不能根据get_md_id获取 也不能根据构造函数中传入的md_id 因为供货商打印 或者 平台打印 或者 商城打印的时候 是不会传md_id的
- $md = Md::findOne($order['md_id']);
- $content .= "{$md->name}\n";
- $content .= "{$md->mobile}\n";
- $content .= "{$md->address}\n";
- $content .= "--------------------------------\n";
- }
- }
- if ($order['remark']) {
- $content .= "备注:{$order['remark']}\n";
- } else {
- $orderForm = OrderForm::findAll([
- 'order_id' => $this->order['id'], 'store_id' => $this->store_id, 'is_delete' => 0
- ]);
- if ($orderForm) {
- /* @var $orderForm OrderForm[] */
- foreach ($orderForm as $item) {
- $content .= $item->key . ':' . $item->value . "\n";
- }
- }
- }
- if ($order['seller_comments']) {
- $content .= "商家备注:{$order['seller_comments']}<BR>";
- }
- $result = $print->action_print($client_id, $machine_code, $content, $client_key, $key);
- $result = Json::decode($result);
- switch ($result['state']) {
- case 1:
- return $result;
- break;
- case 2:
- throw new Exception('提交时间超时。验证你所提交的时间戳超过3分钟后拒绝接受', $result);
- break;
- case 3:
- throw new Exception('参数有误', $result);
- break;
- case 4:
- throw new Exception('sign加密验证失败', $result);
- break;
- default:
- throw new Exception('打印机设置错误', $result);
- break;
- }
- }
- /**
- * 补齐空格
- * 截取$n个中文字符长度
- */
- private function r_mb_str($input, $n)
- {
- $string = "";
- $count = 0;
- $c_count = 0;
- for ($i = 0; $i < mb_strlen($input, 'UTF-8'); $i++) {
- $char = mb_substr($input, $i, 1, 'UTF-8');
- $string .= $char;
- if (strlen($char) == 3) {
- $count += 2;
- $c_count++;
- } else {
- $count += 1;
- }
- if ($count >= 2 * $n) {
- break;
- }
- }
- if ($count < 2 * $n) {
- $string = str_pad($string, 2 * $n + $c_count);
- }
- return $string;
- }
- // 飞鹅打印机
- public function printer_3()
- {
- $big = [
- 1 => [
- 'start' => '',
- 'end' => ''
- ],
- 2 => [
- 'start' => '<B>',
- 'end' => '</B>'
- ],
- 3 => [
- 'start' => '<DB>',
- 'end' => '</DB>'
- ],
- ];
- $start = $big[$this->setting->big]['start'];
- $end = $big[$this->setting->big]['end'];
- date_default_timezone_set("Asia/Shanghai");
- // $order = Order::findOne(['id' => $this->order_id, 'is_delete' => 0]);
- $order = $this->order;
- $addtime = date('Y-m-d H:i:s', $order['created_at']);
- // $goods_list = $this->getOrderGoodsList($order->id);
- $goods_list = $this->goods_list;
- $time = $this->printer_setting['time'];//打印联数
- $content = "";
- if ($this->mch && $this->mch->name){
- $title_name = $this->mch->name;
- }else{
- $title_name = $this->store_name;
- }
- $content .= "<CB>{$title_name}</CB><BR>";
- if (!empty($order['food_flag_id'])) {
- $FoodFlag = FoodFlag::findOne($order['food_flag_id']);
- $food_num = $FoodFlag->table_num;
- $content .= "桌号:{$food_num}\n";
- }
- if ($this->is_refund) {
- $content .= "订单类型:退款订单<BR>";
- } else {
- if ($order['food_code']) {
- $content .= "标识码:{$order['food_code']}<BR>";
- }
- $content .= "订单类型:{$this->extra['order_type']}<BR>";
- }
- $content .= "支付方式:{$this->extra['pay_type']}<BR>";
- $isPay = $order['is_pay'] == 1 ? '已支付' : '未支付';
- $content .= "支付状态:{$isPay}<BR>";
- $content .= "发货方式:{$this->extra['send_type']}<BR>";
- $content .= "订单号:{$order['order_no']}<BR>";
- $content .= "下单时间:{$addtime}<BR>";
- if ($this->setting->is_attr == 0) {
- $content .= "--------------------------------<BR>";
- $content .= "名称 单价 数量 金额<BR>";
- $content .= "--------------------------------<BR>";
- // foreach ($goods_list as $k => $v) {
- // $price = round($v['total_price'] / $v['num'], 2);
- // $content .= $this->r_str_pad($v['name']) . " " . str_pad($price, 5) . " " . str_pad($v['num'], 4) . " " . round($v['total_price'], 2) . '<BR>';
- // }
- foreach ($goods_list as $k => $v) {
- $price = round($v['total_price'] / $v['num'], 2);
- $arr = $this->r_str_pad_1($v['name'], 7);
- foreach ($arr as $index => $value) {
- if ($index == 0) {
- $content .= $value . " " . str_pad($price, 5) . " " . str_pad($v['num'], 6) . " " . round($v['total_price'], 2) . '<BR>';
- } else {
- $content .= $value . '<BR>';
- }
- }
- }
- } else {
- /**
- * $content .= "--------------------------------<BR>";
- * $content .= "名称 规格 单价 数量 金额<BR>";
- * $content .= "--------------------------------<BR>";
- * foreach ($goods_list as $k => $v) {
- * $attr = json_decode($v['attr'], true);
- * $attr_arr = [];
- * foreach ($attr as $i => $j) {
- * $attr_arr[] = $j['attr_group_name'] . $j['attr_name'];
- * }
- * $attr_str = implode(',', $attr_arr);
- * $attr_arr_1 = $this->r_str_pad_1($attr_str, 4);
- * $price = round($v['total_price'] / $v['num'], 2);
- * $arr = $this->r_str_pad_1($v['name'], 4);
- * $a = count($attr_arr_1) >= count($arr) ? $attr_arr_1 : $arr;
- * foreach ($a as $index => $value) {
- * $string = "";
- * $string_1 = "";
- * if (isset($arr[$index])) {
- * $string = $arr[$index];
- * }
- * if (isset($attr_arr_1[$index])) {
- * if (!$string) {
- * $string = str_pad($string, 8);
- * }
- * $string_1 = $attr_arr_1[$index];
- * }
- * if ($index == 0) {
- * $content .= $string . " " . $string_1 . str_pad($price, 5) . " " . str_pad($v['num'], 3) . " " . round($v['total_price'], 2) . '<BR>';
- * } else {
- * $content .= $string . " " . $string_1 . '<BR>';
- * }
- * }
- * }
- * */
- $content .= "--------------------------------<BR>";
- $content .= "名称 数量 金额 <BR>";
- $content .= "--------------------------------<BR>";
- foreach ($goods_list as $k => $v) {
- $name = $v['name'];
- if (!empty($v['attr'])) {
- if (is_array($v['attr'])) {
- $attr = $v['attr'];
- } else {
- $attr = json_decode($v['attr'], true);
- }
- $attr_arr = [];
- if ($attr['attr_list']) {
- $attr = $attr['attr_list'];
- }
- foreach ($attr as $i => $j) {
- $attr_arr[] = ($j['attr_group_name'] ?? '') . $j['attr_name'];
- }
- $attr_str = implode(',', $attr_arr);
- $name = $v['name'] . '(' . $attr_str . ')';
- }
- $name_arr = $this->r_str_pad_1($name, 8);
- foreach ($name_arr as $index => $value) {
- if ($index == count($name_arr) - 1) {
- $content .= $name_arr[$index] . " " . str_pad('×' . $v['num'], 7) . " " . round($v['total_price'] ?? $v['price'], 2) . "<BR>";
- } else {
- $content .= $name_arr[$index] . '<BR>';
- }
- }
- }
- }
- $content .= "--------------------------------<BR>";
- if ($order['express_price']) {
- $content .= "运费:{$order['express_price']}元<BR>";
- }
- $content .= "总计:{$order['total_price']}元<BR>";
- if (isset($order['user_coupon_id'])) {
- $content .= "优惠券优惠:{$order['coupon_sub_price']}元<BR>";
- }
- if (isset($order['integral'])) {
- $integral = json_decode($order['integral'], true);
- if ($integral['forehead'] != 0) {
- $content .= "积分抵扣:{$integral['forehead']}元<BR>";
- }
- }
- // if (isset($order['discount']) && $order['discount'] < 10) {
- // $content .= "会员折扣:{$order['discount']}折<BR>";
- // }
- if ($this->is_refund) {
- $content .= "实退:{$order['pay_price']}元<BR>";
- } else {
- $content .= $order['is_pay'] == 1 ? "实付:{$order['pay_price']}元<BR>" : "实付: 0元<BR>";
- }
- // if ($this->order_type != 3) {
- // if ((isset($order['is_offline']) && $order['is_offline'] != 1) || (isset($order['offline']) && $order['offline'] != 2)) {
- //
- // } else {
- // $content .= "{$start}联系人:{$order['name']}<BR>";
- // $content .= "联系人电话:{$order['mobile']}<BR>{$end}";
- // $content .= "--------------------------------<BR>";
- // $content .= "门店信息<BR>";
- // $content .= "{$this->order->shop->name}<BR>";
- // $content .= "{$this->order->shop->mobile}<BR>";
- // $content .= "{$this->order->shop->address}<BR>";
- // $content .= "--------------------------------<BR>";
- // }
- // }
- if (isset($order['is_offline']) && $order['is_offline'] != 1) {
- $content .= "{$start}收货人:{$order['name']}<BR>";
- $content .= "收货地址:{$order['address']}<BR>";
- $content .= "收货人电话:{$order['mobile']}<BR>{$end}";
- $content .= "--------------------------------<BR>";
- } else {
- $content .= "{$start}联系人:{$order['name']}<BR>";
- $content .= "联系人电话:{$order['mobile']}<BR>{$end}";
- $content .= "--------------------------------<BR>";
- // 门店信息要根据订单上的md_id查询门店 不能根据get_md_id获取 也不能根据构造函数中传入的md_id 因为供货商打印 或者 平台打印 或者 商城打印的时候 是不会传md_id的
- $md = Md::findOne($order['md_id']);
- $content .= "门店信息<BR>";
- $content .= "门店名称:{$md->name}<BR>";
- $content .= "门店联系人:{$md->contact}<BR>";
- $content .= "门店电话:{$md->mobile}<BR>";
- $content .= "门店地址:{$md->address}<BR>";
- $content .= "--------------------------------<BR>";
- }
- if ($order['remark']) {
- $content .= "备注:{$order['remark']}<BR>";
- } else {
- $orderForm = OrderForm::findAll([
- 'order_id' => $this->order['id'], 'store_id' => $this->store_id, 'is_delete' => 0
- ]);
- if ($orderForm) {
- /* @var $orderForm OrderForm[] */
- foreach ($orderForm as $item) {
- $content .= $item->key . ':' . $item->value . "<BR>";
- }
- }
- }
- if ($order['seller_comments']) {
- $content .= "商家备注:{$order['seller_comments']}<BR>";
- }
- // var_dump($content);die;
- $resule = $this->wp_print($this->printer_setting['sn'], $content, $time);
- $resule = Json::decode($resule);
- if ($resule['ret'] != 0) {
- throw new Exception($resule['msg'], $resule);
- }
- return $resule;
- }
- // 飞鹅标签打印机
- public function printer_7(){
- date_default_timezone_set("Asia/Shanghai");
- $order = $this->order;
- $goods_list = $this->goods_list;
- $time = $this->printer_setting['time'];//打印联数
-
- //商品信息
- $glist = array(
- 'orderid'=>'001',
- 'remark'=>'',
- 'name'=>'',
- 'tel'=>'',
- 'z_number'=>'',
- 'goods'=>array(
- // '0'=>array('title'=>'可乐鸡翅'),
- ),
- );
-
- if (!empty($order['food_flag_id'])) {
- $FoodFlag = FoodFlag::findOne($order['food_flag_id']);
- $food_num = $FoodFlag->table_num;
- $glist['z_number'] = $food_num . '号桌';
- }else{
- $glist['z_number'] = " ";
- }
- if ($order['remark']) {
- $glist['remark'] = $order['remark'];
- }
- if ($this->is_refund) {
- $glist['remark'] = "**退款订单 {$order['pay_price']}元";
- }
- if ($order['food_code']) {
- $glist['orderid'] = $order['food_code'];
- }else{
- $glist['orderid'] = substr($order['order_no'], -4);
- }
- foreach ($goods_list as $k => $v) {
- if($v['is_food_ext_goods']){
- continue;
- }
- $food_ext_goods_names = [];
- if (!empty($v['food_ext_goods'])) {
- $food_ext_goods = json_decode($v['food_ext_goods'], true);
- if (!empty($food_ext_goods)) {
- $food_ext_goods_names = array_column($food_ext_goods, 'name');
- }
- }
- $name = $v['name'];
- if (!empty($v['attr'])) {
- if (is_array($v['attr'])) {
- $attr = $v['attr'];
- } else {
- $attr = json_decode($v['attr'], true);
- }
- $attr_arr = [];
- if ($attr['attr_list']) {
- $attr = $attr['attr_list'];
- }
- foreach ($attr as $i => $j) {
- $attr_arr[] = $j['attr_name'];
- }
- $attr_str = implode(',', $attr_arr);
- }
- for($i=1; $i<=$v['num']; $i++){
- $glist['goods'][] = [
- 'attr_str'=>$attr_str,
- 'title'=>$name,
- 'food_ext_goods_names'=>$food_ext_goods_names,
- ];
- }
- }
- $glist['name'] = $order['name'];
- $glist['tel'] = $order['mobile'];
-
- $num = count($glist['goods']);
- $itemI = 1;
- $contents = [];
- foreach ($glist['goods'] as $key => $value) {
- $content = '<TEXT x="0" y="10" font="12" w="1" h="1" r="0">'.$this->LR('#'.$glist['orderid'], $itemI.'/'.$num,23,$glist['z_number']) .'</TEXT>';
- $glist['remark'] && $content .= '<TEXT x="0" y="40" font="12" w="1" h="1" r="0">'.$glist['remark'].'</TEXT>';
- $content .= '<TEXT x="0" y="70" font="12" w="'. (mb_strlen($value["title"]) > 6 ? 1 : 2) .'" h="2" r="0">'.$this->LR('', '', (mb_strlen($value["title"]) > 6 ? 26 : 13), $value["title"]).'</TEXT>';
- $value['attr_str'] && $content .= '<TEXT x="0" y="130" font="12" w="1" h="1" r="0">'.$this->LR('', '', 26, mb_substr($value['attr_str'], 0, 12)).'</TEXT>';
- mb_strlen($value['attr_str']) > 12 && $content .= '<TEXT x="0" y="156" font="12" w="1" h="1" r="0">'.$this->LR('', '', 26, mb_substr($value['attr_str'], 12)).'</TEXT>';
- if($value['food_ext_goods_names']){
- $content .= '<TEXT x="0" y="185" font="12" w="1" h="1" r="0">'.$this->LR('', '', 26, implode(',', $value['food_ext_goods_names'])).'</TEXT>';
- }
- $content .= '<TEXT x="0" y="215" font="12" w="1" h="1" r="0">'. $this->LR(mb_substr($glist['name'], 0, 1) . '**', substr_replace($glist['tel'], '****', 3, 4), 23).'</TEXT>';//40mm宽度标签纸一行占用26个字符,50mm宽度标签纸请改成32个字符
- $contents[] = [
- 'content' => $content,
- 'times' => $time,
- ];
- $itemI++;
- }
- \Yii::error($contents);
- // var_dump($contents);die;
- $resule = $this->wp_print_label($this->printer_setting['sn'], json_encode($contents), 1);
- $resule = Json::decode($resule);
- debug_log($resule, __CLASS__);
- \Yii::error($resule);
- if ($resule['ret'] != 0) {
- throw new Exception($resule['msg'], $resule);
- }
- return $resule;
- }
- /**
- * [统计字符串字节数补空格,实现左右排版对齐]
- * @param [string] $str_left [左边字符串]
- * @param [string] $str_right [右边字符串]
- * @param [int] $length [输入当前纸张规格一行所支持的最大字母数量]
- * 58mm的机器,一行打印16个汉字,32个字母;76mm的机器,一行打印22个汉字,33个字母,80mm的机器,一行打印24个汉字,48个字母
- * 标签机宽度50mm,一行32个字母,宽度40mm,一行26个字母
- * @return [string] [返回处理结果字符串]
- */
- public function LR($str_left,$str_right,$length,$str_center = ''){
- if( empty($str_left) && empty($str_right) && empty($length) ) return '请输入正确的参数';
- $kw = '';
- $str_left_lenght = strlen(iconv("UTF-8", "GBK//IGNORE", $str_left));
- $str_right_lenght = strlen(iconv("UTF-8", "GBK//IGNORE", $str_right));
- $k = $length - ($str_left_lenght+$str_right_lenght);
- for($q=0;$q<$k;$q++){
- $kw .= ' ';
- }
- if($str_center){
- $str_center_lenght = strlen(iconv("UTF-8", "GBK//IGNORE", $str_center));
- if(strlen($kw) > $str_center_lenght){
- $kk = (strlen($kw) - $str_center_lenght) / 2;
- $kkw = '';
- for($q=1;$q<$kk;$q++){
- $kkw .= ' ';
- }
- $kw = $kkw . $str_center . $kkw;
- }else{
- $kw = $str_center;
- }
- }
- return $str_left.$kw.$str_right;
- }
- /**
- * 方法1
- * 拼凑订单内容时可参考如下格式
- * 根据打印纸张的宽度,自行调整内容的格式,可参考下面的样例格式
- */
- private function wp_print($printer_sn, $orderInfo, $times)
- {
- $user = $this->printer_setting['user'];
- $ukey = $this->printer_setting['ukey'];
- $time = time();
- $ip = 'api.feieyun.cn';
- $path = '/Api/Open/';
- $content = array(
- 'user' => $user,
- 'stime' => $time,
- 'sig' => sha1($user . $ukey . $time),
- 'apiname' => 'Open_printMsg',
- 'sn' => $printer_sn,
- 'content' => $orderInfo,
- 'times' => $times//打印次数
- );
- $client = new FeieYun($ip, 80);
- if (!$client->post($path, $content)) {
- return 'error';
- } else {
- //服务器返回的JSON字符串,建议要当做日志记录起来
- return $client->getContent();
- }
- }
- private function wp_print_label($printer_sn, $orderInfos, $times)
- {
- $user = $this->printer_setting['user'];
- $ukey = $this->printer_setting['ukey'];
- $time = time();
- $ip = 'api.feieyun.cn';
- $path = '/Api/Open/';
- $content = array(
- 'user' => $user,
- 'stime' => $time,
- 'sig' => sha1($user . $ukey . $time),
- 'apiname' => 'Open_printLabelMsg',
- 'sn' => $printer_sn,
- 'contents' => $orderInfos,
- 'times' => $times//打印次数
- );
- $client = new FeieYun($ip, 80);
- if (!$client->post($path, $content)) {
- return 'error';
- } else {
- //服务器返回的JSON字符串,建议要当做日志记录起来
- return $client->getContent();
- }
- }
- // 秒杀商品详情
- public function getMsOrderGoodsList()
- {
- $ms_goods = MsGoods::findOne(['id' => $this->order['goods_id']]);
- $list['name'] = $ms_goods->name;
- $list['total_price'] = $this->order['pay_price'];
- $list['num'] = $this->order['num'];
- $list['attr'] = $this->order['attr'];
- $new_list = [];
- array_push($new_list, $list);
- return $new_list;
- }
- // 拼团商品详情
- public function getPtOrderGoodsList()
- {
- $order_detail_list = PtOrderDetail::find()->alias('od')
- ->leftJoin(['g' => PtGoods::tableName()], 'od.goods_id=g.id')
- ->where(['od.is_delete' => 0, 'od.order_id' => $this->order['id']])
- ->select(['od.*', 'g.name'])->asArray()->all();
- return $order_detail_list;
- }
- // 预约商品详情
- public function getYyOrderGoodsList()
- {
- $order_detail_list = YyOrder::find()->alias('od')
- ->leftJoin(['g' => YyGoods::tableName()], 'od.goods_id = g.id')
- ->where(['od.is_delete' => 0, 'od.order_id' => $this->order['id']])
- ->select(['od.*', 'g.name'])->asArray()->one();
- $order_detail_list['num'] = 1;
- return [$order_detail_list];
- }
- public function printer_4()
- {
- $big = $this->setting->big;
- $order = $this->order;
- $addtime = date('Y-m-d H:i:s', $order['created_at']);
- $goods_list = $this->goods_list;
- header("Content-Type: text/html;charset=utf-8");
- $content = "";
- if ($this->mch && $this->mch->name) {
- $title_name = $this->mch->name;
- } else {
- $title_name = $this->store_name;
- }
- $content .= "{$title_name}<gpBr/>";
- if (!empty($order['food_flag_id'])) {
- $FoodFlag = FoodFlag::findOne($order['food_flag_id']);
- $food_num = $FoodFlag->table_num;
- $content .= "桌号:{$food_num}\n";
- }
- if ($this->is_refund) {
- $content .= "订单类型:退款订单<gpBr/>";
- } else {
- if ($order['food_code']) {
- $content .= "标识码:{$order['food_code']}<gpBr/>";
- }
- $content .= "订单类型:{$this->extra['order_type']}<gpBr/>";
- }
- $content .= "支付方式:{$this->extra['pay_type']}<gpBr/>";
- $isPay = $order['is_pay'] == 1 ? '已支付' : '未支付';
- $content .= "支付状态:{$isPay}<gpBr/>";
- $content .= "发货方式:{$this->extra['send_type']}<gpBr/>";
- $content .= "订单号:{$order['order_no']}<gpBr/>";
- $content .= "下单时间:{$addtime}<gpBr/>";
- if ($this->setting->is_attr == 0) {
- $content .= "--------------------------------<gpBr/>";
- $content .= "名称 单价 数量 金额<gpBr/>";
- $content .= "--------------------------------<gpBr/>";
- foreach ($goods_list as $k => $v) {
- $price = round($v['total_price'] / $v['num'], 2);
- $arr = $this->r_str_pad_1($v['name'], 7);
- foreach ($arr as $index => $value) {
- if ($index == 0) {
- $content .= $value . " " . str_pad($price, 5) . " " . str_pad($v['num'], 6) . " " . round($v['total_price'], 2) . '<gpBr/>';
- } else {
- $content .= $value . '<gpBr/>';
- }
- }
- }
- } else {
- $content .= "--------------------------------<gpBr/>";
- $content .= "名称 数量 金额 <gpBr/>";
- $content .= "--------------------------------<gpBr/>";
- foreach ($goods_list as $k => $v) {
- $name = $v['name'];
- if (!empty($v['attr'])) {
- $attr = json_decode($v['attr'], true);
- $attr_arr = [];
- if($attr['attr_list']){
- $attr = $attr['attr_list'];
- }
- foreach ($attr as $i => $j) {
- $attr_arr[] = $j['attr_group_name'] . $j['attr_name'];
- }
- $attr_str = implode(',', $attr_arr);
- $name = $v['name'] . '(' . $attr_str . ')';
- }
- $name_arr = $this->r_str_pad_1($name, 8);
- foreach ($name_arr as $index => $value) {
- if ($index == count($name_arr) - 1) {
- $content .= $name_arr[$index] . " " . str_pad('×' . $v['num'], 7) . " " . round($v['total_price'], 2) . "<gpBr/>";
- } else {
- $content .= $name_arr[$index] . '<gpBr/>';
- }
- }
- }
- }
- $content .= "--------------------------------<gpBr/>";
- if ($order['express_price']) {
- $content .= "运费:{$order['express_price']}元<gpBr/>";
- }
- $content .= "总计:{$order['total_price']}元<gpBr/>";
- if (isset($order['user_coupon_id'])) {
- $content .= "优惠券优惠:{$order['coupon_sub_price']}元<gpBr/>";
- }
- if (isset($order['integral'])) {
- $integral = json_decode($order['integral'], true);
- if ($integral['forehead'] != 0) {
- $content .= "积分抵扣:{$integral['forehead']}元<gpBr/>";
- }
- }
- if (isset($order['discount']) && $order['discount'] < 10) {
- $content .= "会员折扣:{$order['discount']}折<gpBr/>";
- }
- if ($this->is_refund) {
- $content .= "实退:{$order['pay_price']}元<gpBr/>";
- } else {
- $content .= $order['is_pay'] == 1 ? "实付:{$order['pay_price']}元<gpBr/>" : "实付:0元<gpBr/>";
- }
- if ($this->order_type != 3) {
- if ((isset($order['is_offline']) && $order['is_offline'] != 1) || (isset($order['offline']) && $order['offline'] != 2)) {
- $content .= "<gpWord Align=0 Bold=0 Wsize={$big} Hsize={$big} Reverse=0 Underline=0>收货人:{$order['name']}</gpWord><gpBr/>";
- $content .= "<gpWord Align=0 Bold=0 Wsize={$big} Hsize={$big} Reverse=0 Underline=0>收货地址:{$order['address']}</gpWord><gpBr/>";
- $content .= "<gpWord Align=0 Bold=0 Wsize={$big} Hsize={$big} Reverse=0 Underline=0>收货人电话:{$order['mobile']}</gpWord><gpBr/>";
- $content .= "--------------------------------<gpBr/>";
- } else {
- $content .= "<gpWord Align=0 Bold=0 Wsize={$big} Hsize={$big} Reverse=0 Underline=0>联系人:{$order['name']}</gpWord><gpBr/>";
- $content .= "<gpWord Align=0 Bold=0 Wsize={$big} Hsize={$big} Reverse=0 Underline=0>联系人电话:{$order['mobile']}</gpWord><gpBr/>";
- $content .= "--------------------------------<gpBr/>";
- $content .= "门店信息<gpBr/>";
- // 门店信息要根据订单上的md_id查询门店 不能根据get_md_id获取 也不能根据构造函数中传入的md_id 因为供货商打印 或者 平台打印 或者 商城打印的时候 是不会传md_id的
- $md = Md::findOne($order['md_id']);
- $content .= "{$md->name}<gpBr/>";
- $content .= "{$md->mobile}<gpBr/>";
- $content .= "{$md->address}<gpBr/>";
- $content .= "--------------------------------<gpBr/>";
- }
- }
- if ($order['remark']) {
- $content .= "备注:{$order['remark']}<gpBr/>";
- } else {
- $orderForm = OrderForm::findAll([
- 'order_id' => $this->order['id'], 'store_id' => $this->store_id, 'is_delete' => 0
- ]);
- if ($orderForm) {
- /* @var $orderForm OrderForm[] */
- foreach ($orderForm as $item) {
- $content .= $item->key . ':' . $item->value . "<gpBr/>";
- }
- }
- }
- if ($order['seller_comments']) {
- $content .= "商家备注:{$order['seller_comments']}<gpBr/>";
- }
- $content .= "<gpCut/>";
- $res = $this->poscom($content);
- $res = Json::decode($res);
- if ($res['code'] != 0) {
- throw new Exception($res['msg'], $res);
- }
- return $res;
- }
- public function printer_5($printer = null)
- {
- $big = [
- 1 => [
- 'start' => '',
- 'end' => ''
- ],
- 2 => [
- 'start' => "<B>",
- 'end' => "</B>"
- ],
- 3 => [
- 'start' => '<B2>',
- 'end' => '</B2>'
- ],
- ];
- $start = $big[$this->setting->big]['start'];
- $end = $big[$this->setting->big]['end'];
- date_default_timezone_set("Asia/Shanghai");
- $order = $this->order;
- $addtime = date('Y-m-d H:i:s', $order['created_at']);
- $goods_list = $this->goods_list;
- header("Content-Type: text/html;charset=utf-8");
- $time = $this->printer_setting['time'];//打印联数
- $content = "";
- if ($this->mch && $this->mch->name){
- $title_name = $this->mch->name;
- }else{
- $title_name = $this->store_name;
- }
- $content .= "<CB>{$title_name}<BR><BR></CB>";
- if (!empty($order['food_flag_id'])) {
- $FoodFlag = FoodFlag::findOne($order['food_flag_id']);
- $food_num = $FoodFlag->table_num;
- $content .= "桌号:{$food_num}\n";
- }
- if ($this->is_refund) {
- $content .= "订单类型:退款订单<BR>";
- } else {
- if ($order['food_code']) {
- $content .= "标识码:{$order['food_code']}<BR>";
- }
- $content .= "订单类型:{$this->extra['order_type']}<BR>";
- }
- $content .= "支付方式:{$this->extra['pay_type']}<BR>";
- $isPay = $order['is_pay'] == 1 ? '已支付' : '未支付';
- $content .= "支付状态:{$isPay}<BR>";
- $content .= "发货方式:{$this->extra['send_type']}<BR>";
- $content .= "订单号:{$order['order_no']}<BR>";
- $content .= "下单时间:{$addtime}<BR>";
- if ($this->setting->is_attr == 0) {
- $content .= "--------------------------------<BR>";
- $content .= "名称 单价 数量 金额<BR>";
- $content .= "--------------------------------<BR>";
- foreach ($goods_list as $k => $v) {
- $price = round($v['total_price'] / $v['num'], 2);
- $arr = $this->r_str_pad_1($v['name'], 7);
- foreach ($arr as $index => $value) {
- if ($index == 0) {
- $content .= $value . " " . str_pad($price, 5) . " " . str_pad($v['num'], 6) . " " . round($v['total_price'], 2) . '<BR>';
- } else {
- $content .= $value . '<BR>';
- }
- }
- }
- } else {
- $content .= "--------------------------------<BR>";
- $content .= "名称 数量 金额 <BR>";
- $content .= "--------------------------------<BR>";
- foreach ($goods_list as $k => $v) {
- $name = $v['name'];
- if (!empty($v['attr'])) {
- $attr = json_decode($v['attr'], true);
- $attr_arr = [];
- if($attr['attr_list']){
- $attr = $attr['attr_list'];
- }
- foreach ($attr as $i => $j) {
- $attr_arr[] = $j['attr_group_name'] . $j['attr_name'];
- }
- $attr_str = implode(',', $attr_arr);
- $name = $v['name'] . '(' . $attr_str . ')';
- }
- $name_arr = $this->r_str_pad_1($name, 8);
- foreach ($name_arr as $index => $value) {
- if ($index == count($name_arr) - 1) {
- $content .= $name_arr[$index] . " " . str_pad('×' . $v['num'], 7) . " " . round($v['total_price'], 2) . "<BR>";
- } else {
- $content .= $name_arr[$index] . '<BR>';
- }
- }
- }
- }
- $content .= "--------------------------------<BR>";
- if ($order['express_price']) {
- if ($order['express_price'] == 0) {
- $delivery_info = DeliveryInfo::findOne(['order_no' => $order['order_no']]);
- if ($delivery_info && $delivery_info->fee > 0) {
- $order['express_price'] = $delivery_info->fee;
- }
- }
- $content .= "运费:{$order['express_price']}元<BR>";
- }
- $content .= "总计:{$order['total_price']}元<BR>";
- if (isset($order['user_coupon_id'])) {
- $content .= "优惠券优惠:{$order['coupon_sub_price']}元<BR>";
- }
- if (isset($order['integral'])) {
- $integral = json_decode($order['integral'], true);
- if ($integral['forehead'] != 0) {
- $content .= "积分抵扣:{$integral['forehead']}元<BR>";
- }
- }
- if (isset($order['discount']) && $order['discount'] < 10) {
- $content .= "会员折扣:{$order['discount']}折<BR>";
- }
- if ($this->is_refund) {
- $content .= "实退:{$order['pay_price']}元<BR>";
- } else {
- $content .= $order['is_pay'] == 1 ? "实付:{$order['pay_price']}元<BR>" : "实付:0元<BR>";
- }
- if ($this->order_type != 3) {
- if ((isset($order['is_offline']) && $order['is_offline'] != 1) || (isset($order['offline']) && $order['offline'] != 2)) {
- $content .= "{$start}收货人:{$order['name']}<BR>";
- $content .= "收货地址:{$order['address']}<BR>";
- $content .= "收货人电话:{$order['mobile']}<BR>{$end}";
- $content .= "--------------------------------<BR>";
- } else {
- $content .= "{$start}联系人:{$order['name']}<BR>";
- $content .= "联系人电话:{$order['mobile']}<BR>{$end}";
- $content .= "--------------------------------<BR>";
- $content .= "门店信息<BR>";
- // 门店信息要根据订单上的md_id查询门店 不能根据get_md_id获取 也不能根据构造函数中传入的md_id 因为供货商打印 或者 平台打印 或者 商城打印的时候 是不会传md_id的
- $md = Md::findOne($order['md_id']);
- $content .= "{$md->name}<BR>";
- $content .= "{$md->mobile}<BR>";
- $content .= "{$md->address}<BR>";
- $content .= "--------------------------------<BR>";
- }
- }
- if ($order['content']) {
- $content .= "备注:{$order['content']}<BR>";
- } else {
- $orderForm = OrderForm::findAll([
- 'order_id' => $this->order['id'], 'store_id' => $this->store_id, 'is_delete' => 0
- ]);
- if ($orderForm) {
- /* @var $orderForm OrderForm[] */
- foreach ($orderForm as $item) {
- $content .= $item->key . ':' . $item->value . "<BR>";
- }
- }
- }
- if ($order['seller_comments']) {
- $content .= "商家备注:{$order['seller_comments']}<BR>";
- }
- try {
- $result = (new XhyPrint($printer->id))->print($this->printer_setting['sn'], $content, $time);
- \Yii::warning('==>>' . $result);
- } catch (\Exception $e) {
- throw new Exception($e->getMessage(), $result);
- }
- return $result;
- }
- public function printer_6($printer = null)
- {
- $big = [
- 1 => [
- 'start' => '',
- 'end' => ''
- ],
- 2 => [
- 'start' => "<font# bolder=0 height=2 width=2>",
- 'end' => "</font#>"
- ],
- 3 => [
- 'start' => '<font# bolder=0 height=3 width=3>',
- 'end' => '</font#>'
- ],
- ];
- $start = $big[$this->setting->big]['start'];
- $end = $big[$this->setting->big]['end'];
- date_default_timezone_set("Asia/Shanghai");
- $order = $this->order;
- $addtime = date('Y-m-d H:i:s', $order['created_at']);
- $goods_list = $this->goods_list;
- header("Content-Type: text/html;charset=utf-8");
- $time = $this->printer_setting['time'];//打印联数
- $content = "";
- if ($this->mch && $this->mch->name){
- $title_name = $this->mch->name;
- }else{
- $title_name = $this->store_name;
- }
- $content .= "<C><font# bolder=0 height=2 width=2>{$title_name}</font#></C><BR><BR>";
- if (!empty($order['food_flag_id'])) {
- $FoodFlag = FoodFlag::findOne($order['food_flag_id']);
- $food_num = $FoodFlag->table_num;
- $content .= "桌号:{$food_num}\n";
- }
- if ($this->is_refund) {
- $content .= "订单类型:退款订单<BR>";
- } else {
- if ($order['food_code']) {
- $content .= "标识码:{$order['food_code']}<BR>";
- }
- $content .= "订单类型:{$this->extra['order_type']}<BR>";
- }
- $content .= "支付方式:{$this->extra['pay_type']}<BR>";
- $isPay = $order['is_pay'] == 1 ? '已支付' : '未支付';
- $content .= "支付状态:{$isPay}<BR>";
- $content .= "发货方式:{$this->extra['send_type']}<BR>";
- $content .= "订单号:{$order['order_no']}<BR>";
- $content .= "下单时间:{$addtime}<BR>";
- if ($this->setting->is_attr == 0) {
- $content .= "--------------------------------<BR>";
- $content .= "名称 单价 数量 金额<BR>";
- $content .= "--------------------------------<BR>";
- foreach ($goods_list as $k => $v) {
- $price = round($v['total_price'] / $v['num'], 2);
- $arr = $this->r_str_pad_1($v['name'], 7);
- foreach ($arr as $index => $value) {
- if ($index == 0) {
- $content .= $value . " " . str_pad($price, 5) . " " . str_pad($v['num'], 6) . " " . round($v['total_price'], 2) . '<BR>';
- } else {
- $content .= $value . '<BR>';
- }
- }
- }
- } else {
- $content .= "--------------------------------<BR>";
- $content .= "名称 数量 金额 <BR>";
- $content .= "--------------------------------<BR>";
- foreach ($goods_list as $k => $v) {
- $name = $v['name'];
- if (!empty($v['attr'])) {
- $attr = json_decode($v['attr'], true);
- $attr_arr = [];
- if($attr['attr_list']){
- $attr = $attr['attr_list'];
- }
- foreach ($attr as $i => $j) {
- $attr_arr[] = $j['attr_group_name'] . $j['attr_name'];
- }
- $attr_str = implode(',', $attr_arr);
- $name = $v['name'] . '(' . $attr_str . ')';
- }
- $name_arr = $this->r_str_pad_1($name, 8);
- foreach ($name_arr as $index => $value) {
- if ($index == count($name_arr) - 1) {
- $content .= $name_arr[$index] . " " . str_pad('×' . $v['num'], 7) . " " . round($v['total_price'], 2) . "<BR>";
- } else {
- $content .= $name_arr[$index] . '<BR>';
- }
- }
- }
- }
- $content .= "--------------------------------<BR>";
- if ($order['express_price']) {
- if ($order['express_price'] == 0) {
- $delivery_info = DeliveryInfo::findOne(['order_no' => $order['order_no']]);
- if ($delivery_info && $delivery_info->fee > 0) {
- $order['express_price'] = $delivery_info->fee;
- }
- }
- $content .= "运费:{$order['express_price']}元<BR>";
- }
- $content .= "总计:{$order['total_price']}元<BR>";
- if (isset($order['user_coupon_id'])) {
- $content .= "优惠券优惠:{$order['coupon_sub_price']}元<BR>";
- }
- if (isset($order['integral'])) {
- $integral = json_decode($order['integral'], true);
- if ($integral['forehead'] != 0) {
- $content .= "积分抵扣:{$integral['forehead']}元<BR>";
- }
- }
- if (isset($order['discount']) && $order['discount'] < 10) {
- $content .= "会员折扣:{$order['discount']}折<BR>";
- }
- if ($this->is_refund) {
- $content .= "实退:{$order['pay_price']}元<BR>";
- } else {
- $content .= $order['is_pay'] == 1 ? "实付:{$order['pay_price']}元<BR>" : "实付:0元<BR>";
- }
- if ($this->order_type != 3) {
- if ((isset($order['is_offline']) && $order['is_offline'] != 1) || (isset($order['offline']) && $order['offline'] != 2)) {
- $content .= "{$start}收货人:{$order['name']}{$end}<BR>";
- $content .= "{$start}收货地址:{$order['address']}{$end}<BR>";
- $content .= "{$start}收货人电话:{$order['mobile']}{$end}<BR>";
- $content .= "--------------------------------<BR>";
- } else {
- $content .= "{$start}联系人:{$order['name']}{$end}<BR>";
- $content .= "{$start}联系人电话:{$order['mobile']}{$end}<BR>";
- $content .= "--------------------------------<BR>";
- $content .= "门店信息<BR>";
- // 门店信息要根据订单上的md_id查询门店 不能根据get_md_id获取 也不能根据构造函数中传入的md_id 因为供货商打印 或者 平台打印 或者 商城打印的时候 是不会传md_id的
- $md = Md::findOne($order['md_id']);
- $content .= "{$md->name}<BR>";
- $content .= "{$md->mobile}<BR>";
- $content .= "{$md->address}<BR>";
- $content .= "--------------------------------<BR>";
- }
- }
- if ($order['remark']) {
- $content .= "备注:{$order['content']}<BR>";
- } else {
- $orderForm = OrderForm::findAll([
- 'order_id' => $this->order['id'], 'store_id' => $this->store_id, 'is_delete' => 0
- ]);
- if ($orderForm) {
- /* @var $orderForm OrderForm[] */
- foreach ($orderForm as $item) {
- $content .= $item->key . ':' . $item->value . "<BR>";
- }
- }
- }
- if ($order['seller_comments']) {
- $content .= "商家备注:{$order['seller_comments']}<BR>";
- }
- try {
- $result = (new DqznPrint($printer->id))->print($this->printer_setting['sn'], $content, $time);
- \Yii::warning('==>>' . $result);
- } catch (\Exception $e) {
- throw new Exception($e->getMessage(), $result);
- }
- return $result;
- }
- public function poscom($msgDetail, $times = 1)
- {
- $reqTime = $this->getMillisecond();
- $memberCode = $this->printer_setting['memberCode'];
- $deviceNo = $this->printer_setting['deviceNo'];
- $apiKey = $this->printer_setting['apiKey'];
- $orderNo = $this->order['order_no'] . '-' . $times . '-' . $this->print_type;
- $securityCode = md5($memberCode . $deviceNo . $orderNo . $reqTime . $apiKey);
- $url = 'http://api.poscom.cn/apisc/sendMsg';
- $content['charset'] = 'UTF-8';
- $content['reqTime'] = $reqTime;
- $content['memberCode'] = $memberCode;
- $content['deviceNo'] = $deviceNo;
- $content['securityCode'] = $securityCode;
- $content['msgDetail'] = $msgDetail;
- $content['msgNo'] = $orderNo;
- $content['mode'] = 2;
- $content['times'] = $this->printer_setting['time'] > 5 ? 5 : $this->printer_setting['time'];
- $res = $this->request_post($url, $content);
- return $res;
- }
- public function getMillisecond()
- {
- list($t1, $t2) = explode(' ', microtime());
- return (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
- }
- public function request_post($url = '', $post_data = array())
- {
- if (empty($url) || empty($post_data)) {
- return false;
- }
- $postUrl = $url;
- $curlPost = $post_data;
- $ch = curl_init();//初始化curl
- curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
- curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
- curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
- curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
- $data = curl_exec($ch);//运行curl
- curl_close($ch);
- return $data;
- }
- /**
- * @param $order_id
- * @return mixed
- * 砍价订单商品详情
- */
- public function getBargainOrderGoodsList($order_id)
- {
- $order_detail_list = BargainOrderDetail::find()->alias('od')
- ->leftJoin(['g' => BargainGoods::tableName()], 'od.goods_id=g.id')
- ->where([
- 'od.is_delete' => 0,
- 'od.order_id' => $order_id,
- ])->select('od.*,g.name')->asArray()->all();
- return $order_detail_list;
- }
- // /**
- // * @param $order_id
- // * @return mixed
- // * 当面付订单商品详情
- // */
- // public function getScanOrderGoodsList($order_id)
- // {
- // $order_detail_list = \app\plugins\scanCodePay\models\OrderDetail::find()->alias('od')
- // ->leftJoin(['g' => Goods::tableName()], 'od.goods_id=g.id')
- // ->where([
- // 'od.is_delete' => 0,
- // 'od.order_id' => $order_id,
- // 'g.type' => 6
- // ])->select('od.*,g.name')->asArray()->all();
- // return $order_detail_list;
- // }
- }
|