| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737 |
- <?php
- namespace bizHd\order\classes;
- use biz\goods\classes\GoodsClass;
- use biz\goods\models\Goods;
- use biz\shop\classes\ShopAdminClass;
- use biz\shop\classes\ShopCapitalClass;
- use biz\shop\classes\ShopClass;
- use biz\shop\classes\ShopExtClass;
- use biz\shop\models\Shop;
- use biz\stat\classes\StatKdClass;
- use biz\stat\classes\StatOrderCountClass;
- use biz\stat\classes\StatSaleClass;
- use biz\stock\classes\GoodsStockRecordClass;
- use biz\wx\classes\WxMessageClass;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\stat\classes\StatYjClass;
- use bizGhs\stock\classes\StockRecordClass;
- use bizGhs\ws\services\WsService;
- use bizHd\custom\classes\CustomClass;
- use bizHd\merchant\classes\SjClass;
- use bizHd\shop\classes\MainClass;
- use bizHd\stat\classes\StatIncomeClass;
- use bizHd\stat\classes\StatOrderClass;
- use bizHd\user\classes\UserClass;
- use bizHd\work\classes\WorkClass;
- use common\components\dict;
- use common\components\miniUtil;
- use common\components\orderSn;
- use common\components\printUtil;
- use common\components\util;
- use Yii;
- use bizHd\base\classes\BaseClass;
- class OrderClass extends BaseClass
- {
- public static $baseFile = '\bizHd\order\models\Order';
- //已取消
- const ORDER_STATUS_CANCEL = 5;
- //完成
- const ORDER_STATUS_COMPLETE = 4;
- //配送中
- const ORDER_STATUS_SENDING = 3;
- //待配送
- const ORDER_STATUS_UN_SEND = 2;
- //待付款
- const ORDER_STATUS_UN_PAY = 1;
- //订单总流程数
- const ORDER_TOTAL_FLOW = 4;
- //未确认配送方式
- const SEND_TYPE_UNKNOWN = 0;
- //自取
- const SEND_TYPE_NO = 1;
- //自己送
- const SEND_TYPE_MYSELF = 2;
- //快递送
- const SEND_TYPE_THIRD = 3;
- //正常订单
- const REFUND_NO = 0;
- //已退款订单
- const REFUND_YES = 1;
- //送达时间段
- public static $reachPeriod = [0 => '上午', 1 => '下午', 2 => '晚上'];
- //优惠金额
- public static $randDiscount = [
- 50 => [1, 3],
- 100 => [5, 9],
- 300 => [10, 15],
- 500 => [16, 18],
- 1000 => [18, 30],
- 20000 => [90, 100],
- ];
- public static function valid($order, $mainId)
- {
- if (isset($order->mainId) == false || $order->mainId != $mainId) {
- util::fail('没有权限访问的订单');
- }
- return true;
- }
- //添加订单 ssh 2019.12.5
- public static function addOrder($data)
- {
- $data['orderSn'] = $data['orderSn'] ?? orderSn::getOrderSn();
- $data['payStatus'] = $data['payStatus'] ?? 0;
- $shopId = $data['shopId'] ?? 0;
- //累计订单增加
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- util::fail('没有找到门店信息');
- }
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有找到main信息');
- }
- $main->unPayOrder += 1;
- $main->totalOrder += 1;
- $main->save();
- //将花店每月的总订单数作为编号
- $riseNum = StatOrderCountClass::addOrder($shop, $main);
- $data['sendNum'] = date("d") . $riseNum;
- $data['totalFlow'] = OrderClass::ORDER_TOTAL_FLOW;
- $return = self::add($data, true);
- return $return;
- }
- public static function getByOrderSn($orderSn)
- {
- return self::getByCondition(['orderSn' => $orderSn]);
- }
- //评价 ssh 2019.12.16
- public static function comment($data)
- {
- $id = $data['id'];
- unset($data['id']);
- return self::updateById($id, $data);
- }
- public static function getFullInfo($id)
- {
- $order = self::getById($id);
- if (empty($order)) {
- return [];
- }
- $sn = $order['orderSn'] ?? '';
- $order['goodsInfoList'] = OrderGoodsClass::getListBySn($sn);
- $order['itemInfoList'] = OrderItemClass::getListBySn($sn);
- return $order;
- }
- //订单
- public static function getOrderById($id)
- {
- $order = self::getById($id);
- if (empty($order)) {
- return [];
- }
- $sn = $order['orderSn'] ?? '';
- $order['goodsInfoList'] = OrderGoodsClass::getListBySn($sn);
- return $order;
- }
- //根据订单查询 ssh 2020.1.4
- public static function getOrderBySn($orderSn)
- {
- $order = self::getByCondition(['orderSn' => $orderSn]);
- if (empty($order)) {
- return [];
- }
- $id = $order['id'];
- $order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
- return $order;
- }
- //返回随机优惠金额 ssh 2019.9.12
- public static function getRandDiscount($amount)
- {
- if ($amount <= 0) {
- return 0;
- }
- $randDiscount = self::$randDiscount;
- krsort($randDiscount);
- $rand = 0;
- foreach ($randDiscount as $currentAmount => $val) {
- if ($amount >= $currentAmount) {
- $rand = rand($val[0], $val[1]);
- break;
- }
- }
- return $rand / 10;
- }
- //第三方支付后回调处理流程 ssh 2021.4.30
- public static function thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId)
- {
- $order = self::getByCondition(['orderSn' => $orderSn], true);
- if (empty($order)) {
- $msg = "没有找到零售订单 orderSn:{$orderSn}";
- Yii::info($msg);
- util::fail($msg);
- }
- if ($order->realPrice != $totalFee) {
- $msg = "零售订单金额与回调通知金额不一致 orderSn:{$orderSn} {$order->realPrice} {$totalFee}";
- Yii::info($msg);
- util::fail($msg);
- }
- $id = $order->id;
- $order = self::getLockById($id);
- $date = date("Y-m-d H:i:s");
- $order->payTime = $date;
- $order->thirdNo = $transactionId;
- $order->onlinePay = dict::getDict('onlinePay', 'yes');
- $order->save();
- self::payAfter($order, $payWay);
- }
- //订单完成 ssh 2021.4.20
- public static function payAfter($order, $payWay)
- {
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if (isset($order->status) == false || $order->status != self::ORDER_STATUS_UN_PAY) {
- util::fail('订单不是待付款状态');
- }
- $orderId = $order->id ?? 0;
- $order->status = self::ORDER_STATUS_COMPLETE;
- $order->payWay = $payWay;
- $order->payStatus = 1;
- $order->stockChange = 1;
- $order->save();
- \bizMall\order\classes\OrderGoodsClass::stockChange($order);
- $realPrice = $order->realPrice ?? 0;
- $shopId = $order->shopId;
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- util::fail('没有找到门店');
- }
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息');
- }
- $main->unSendOrder += 1;
- $main->unPayOrder -= 1;
- $currentTotalIncome = bcadd($main->totalIncome, $realPrice, 2);
- $main->totalIncome = $currentTotalIncome;
- $main->save();
- $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
- $shopAdminId = $order->shopAdminId ?? 0;
- $shopAdminName = $order->shopAdminName ?? '';
- $sjId = $order->sjId;
- $fromType = $order->fromType ?? 1;
- $event = !empty($shopAdminId) ? '员工开单' : '客户下单';
- $capital = [
- 'capitalType' => $capitalType,
- 'relateId' => $orderId,
- 'io' => 1,
- 'totalIncome' => $currentTotalIncome,
- 'payWay' => $payWay,
- 'event' => $event,
- 'sjId' => $sjId,
- 'shopId' => $shopId,
- 'shopAdminId' => $shopAdminId,
- 'shopAdminName' => $shopAdminName,
- 'amount' => $realPrice,
- 'fromType' => $fromType,
- 'mainId' => $mainId,
- ];
- ShopCapitalClass::addCapital($capital);
- //每天和每月收入增加
- StatIncomeClass::updateOrInsert($main, $shop, $realPrice);
- //今日订单+1
- StatOrderClass::updateOrInsert($main, $shop);
- //销售收入增加
- StatSaleClass::replace($main, $shop, $realPrice);
- //各渠道收入金额统计
- StatKdClass::replace($shop, $realPrice, $payWay);
- //客户在线支付下单增加商家可提现余额
- if (isset($order->onlinePay) && $order->onlinePay == dict::getDict('onlinePay', 'yes')) {
- $amount = $order->actPrice;
- ShopClass::customKdAddBalance($main, $shop, $amount, $order, $capitalType);
- }
- }
- //转化出送到时间 ssh 2020.3.15
- public static function getReachTime($order)
- {
- $reachTime = '';
- if (isset($order['reachDate']) && !empty($order['reachDate'])) {
- $prev = date("n-j", strtotime($order['reachDate']));
- $periodData = self::$reachPeriod;
- $periodKey = $order['reachPeriod'];
- $period = isset($periodData[$periodKey]) ? $periodData[$periodKey] : '上午';
- $reachTime = $prev . ' ' . $period;
- }
- return $reachTime;
- }
- //支付成功获取unionId ssh 2020.5.12
- public static function payToUpdateUnionId($merchant, $merchantExtend, $orderSn, $user)
- {
- $mcId = $merchantExtend['wxPayMerchantId'];
- $miniOpenId = isset($user['miniOpenId']) ? $user['miniOpenId'] : '';
- $unionId = isset($user['unionId']) ? $user['unionId'] : '';
- $userId = $user['id'];
- if (empty($unionId)) {
- $unionId = miniUtil::getPaidUnionId($merchant, $miniOpenId, $mcId, (string)$orderSn, 0);
- if (!empty($unionId)) {
- $findUser = UserClass::getByUnionId($unionId);
- if (empty($findUser)) {
- UserClass::updateByCondition(['id' => $userId], ['unionId' => $unionId]);
- } else {
- UserClass::mergeUser($findUser, $user);
- }
- }
- }
- }
- //订单取消 ssh 20220516
- public static function setExpire($order)
- {
- $now = time();
- if ($order->deadline > $now) {
- return false;
- }
- if ($order->status != 1) {
- return false;
- }
- $order->status = 5;
- $order->save();
- //暂时只考虑花材库存的回滚
- $orderSn = $order->orderSn ?? '';
- $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($itemList)) {
- foreach ($itemList as $item) {
- $ptItemId = $item->ptItemId ?? 0;
- $sjId = $item->sjId ?? 0;
- $shopId = $item->shopId ?? 0;
- $mainId = $item->mainId ?? 0;
- $ratio = $item->ratio ?? 20;
- $unitType = $item->unitType ?? 0;
- $bigNum = 0;
- $smallNum = 0;
- if ($unitType == 0) {
- $bigNum = $item->num;
- } else {
- $smallNum = $item->num;
- }
- $itemId = $item->itemId ?? 0;
- $stockInfo = ProductClass::addStock($itemId, $bigNum, $smallNum);
- $recordData = [];
- $recordData['sjId'] = $sjId;
- $recordData['shopId'] = $shopId;
- $recordData['mainId'] = $mainId;
- $recordData['itemId'] = $ptItemId;
- $recordData['itemNum'] = ProductClass::mergeItemNum($bigNum, $smallNum, $ratio);
- $recordData['oldStock'] = $stockInfo['oldStock'];
- $recordData['newStock'] = $stockInfo['newStock'];
- $recordData['productId'] = $itemId;
- $recordData['orderSn'] = $orderSn;
- $recordData['relateName'] = '系统';
- StockRecordClass::addSellStockOrderCancelRecord($recordData);
- }
- }
- $goodsList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($goodsList)) {
- foreach ($goodsList as $key => $info) {
- $sjId = $info->sjId ?? 0;
- $shopId = $info->shopId ?? 0;
- $mainId = $info->mainId ?? 0;
- $goodsId = $info->goodsId ?? 0;
- $num = $info->num ?? 0;
- $respond = \bizHd\goods\classes\GoodsClass::addStock($goodsId, $mainId, $num);
- $oldStock = $respond['oldStock'] ?? 0;
- $newStock = $respond['newStock'] ?? 0;
- $data = [];
- $data['sjId'] = $sjId;
- $data['shopId'] = $shopId;
- $data['mainId'] = $mainId;
- $data['orderSn'] = $orderSn;
- $data['goodsId'] = $goodsId;
- $data['goodsNum'] = $num;
- $data['oldStock'] = $oldStock;
- $data['newStock'] = $newStock;
- $data['relateName'] = '';
- GoodsStockRecordClass::cancelOrder($data);
- }
- }
- }
- // 扣库存
- protected static function decGoodsStock($orderGoods)
- {
- foreach ($orderGoods as $goods) {
- GoodsClass::counters([
- 'stock' => -$goods['num']
- ], [
- 'and',
- ['id' => $goods['goodsId']],
- ['<>', 'stock', Goods::FULL_STOCK]
- ]);
- }
- }
- // 更新商品销量
- protected static function updateGoodsActualSold($orderGoods)
- {
- foreach ($orderGoods as $goods) {
- GoodsClass::counters([
- 'actualSold' => $goods['num']
- ], [
- 'id' => $goods['goodsId']
- ]);
- }
- }
- //云打印 ssh 20210709
- public static function onlinePrint($order)
- {
- if (empty($order)) {
- return false;
- }
- if ($order->needPrint != dict::getDict('needPrint', 'need')) {
- return false;
- }
- if ($order->payStatus != 1) {
- return false;
- }
- $shopId = $order->shopId ?? 0;
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
- $printSn = $ext['printSn'] ?? '';
- if (empty($printSn)) {
- return false;
- }
- $order->printNum += 1;
- $order->save();
- $customId = $order->customId ?? 0;
- $custom = CustomClass::getById($customId);
- $debtAmount = $custom['debtAmount'] ?? 0;
- $respond = self::getPrintData($order, $debtAmount);
- $content = '<B>' . $respond['sendNum'] . '</B><BR>';
- $content .= '--------------------------------<BR>';
- $content .= '<B>' . $respond['custom']['fullAddress'] . '</B><BR>';
- $content .= '<B>' . $respond['custom']['customName'] . '</B><BR>';
- $content .= '<B>' . $respond['custom']['customMobile'] . '</B><BR>';
- $payDate = date("Y-m-d", strtotime($order->payTime));
- $sendTimeWant = $order->sendTimeWant ?? '';
- if (!empty($sendTimeWant) && $payDate != $sendTimeWant) {
- $content .= '<BR>';
- $content .= '送货时间:<BR>';
- $content .= '<B>' . $sendTimeWant . '</B><BR>';
- }
- if (isset($respond['remark']) && !empty($respond['remark'])) {
- $content .= '<BR>';
- $content .= '备注:<BR>';
- $content .= '<B>' . $respond['remark'] . '</B><BR>';
- }
- $content .= '<BR>';
- $content .= '花材 数量/单价 金额 <BR>';
- $content .= '--------------------------------<BR>';
- if (isset($respond['product']) && !empty($respond['product'])) {
- foreach ($respond['product'] as $current) {
- $content = self::printGroup($current, $content);
- }
- $content .= '--------------------------------<BR>';
- }
- if (isset($respond['refund']) && !empty($respond['refund'])) {
- $content .= '<B>已退款:</B><BR>';
- foreach ($respond['refund'] as $current) {
- //58mm的机器,一行打印16个汉字,32个字母
- $name = $current['name'] ?? '';
- $content .= $name . '<BR>';
- $name = str_repeat(' ', 10);
- $productNum = $current['num'] ?? '';
- $blankNum = bcsub(12, strlen($productNum));
- if ($blankNum > 0) {
- $productNum = $productNum . str_repeat(' ', $blankNum);
- }
- $productPrice = $current['price'] ?? '';
- $blankNum = bcsub(7, strlen($productPrice));
- if ($blankNum > 0) {
- $productPrice = $productPrice . str_repeat(' ', $blankNum);
- }
- $content .= $name . " " . $productNum . ' ' . $productPrice . '<BR>';
- }
- $content .= '--------------------------------<BR>';
- }
- if (isset($respond['sendCost']) && $respond['sendCost'] > 0) {
- $content .= ' 运费:' . floatval($respond['sendCost']) . '<BR>';
- }
- $content .= '订单金额:' . floatval($respond['orderPrice']) . '<BR>';
- if (isset($respond['discountAmount']) && !empty($respond['discountAmount']) && $respond['discountAmount'] > 0) {
- $content .= '优惠扣除:-' . floatval($respond['discountAmount']) . '<BR>';
- }
- if (isset($respond['refundPrice']) && $respond['refundPrice'] > 0) {
- $content .= '退款金额:' . floatval($respond['refundPrice']) . '<BR>';
- }
- $content .= '应付金额:' . floatval($respond['orderPrice']) . '<BR>';
- if (isset($respond['debt']) && $respond['debt'] == 1) {
- $content .= '实付金额:0<BR>';
- } else {
- $content .= '实付金额:' . floatval($respond['realPrice']) . '<BR>';
- }
- if ($debtAmount > 0) {
- $content .= '累计欠款:' . floatval($debtAmount) . '<BR>';
- }
- $shop = ShopClass::getById($shopId, true);
- $sjId = $shop->sjId ?? 0;
- $sj = SjClass::getById($sjId, true);
- $sjName = $sj->name ?? '';
- $currentName = $sjName;
- if (isset($shop->default) == false || $shop->default != 1) {
- $shopName = $shop->shopName ?? '';
- if (!empty($shopName)) {
- $currentName = $currentName . ' ' . $shopName;
- }
- }
- $content .= '--------------------------------<BR>';
- $content .= '订单日期:' . $order->addTime . '<BR>';
- $content .= '订单编号:' . $respond['orderSn'] . '<BR>';
- $content .= '门店名称:' . $currentName . '<BR>';
- $content .= "<BR>";
- $orderSn = $order->orderSn ?? '';
- $workList = WorkClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($workList)) {
- foreach ($workList as $work) {
- $goodsSn = $work->goodsSn ?? '';
- $sn = $work->sn ?? '';
- $content .= '<BOLD>制作单号:' . $sn.'<BOLD>';
- $content .= self::bar_code($goodsSn);
- }
- }
- $p = new printUtil($printSn);
- $p->printMsg($content);
- }
- //飞鹅自带函数 ssh 20220601
- public static function bar_code($strnum)
- {
- $chr = '';
- $codeB = array("\x30","\x31","\x32","\x33","\x34","\x35","\x36","\x37","\x38","\x39");//匹配字符集B
- $codeC = array("\x00","\x01","\x02","\x03","\x04","\x05","\x06","\x07","\x08","\x09","\x0A","\x0B","\x0C","\x0D","\x0E","\x0F","\x10","\x11","\x12","\x13","\x14","\x15","\x16","\x17","\x18","\x19","\x1A","\x1B","\x1C","\x1D","\x1E","\x1F","\x20","\x21","\x22","\x23","\x24","\x25","\x26","\x27","\x28","\x29","\x2A","\x2B","\x2C","\x2D","\x2E","\x2F","\x30","\x31","\x32","\x33","\x34","\x35","\x36","\x37","\x38","\x39","\x3A","\x3B","\x3C","\x3D","\x3E","\x3F","\x40","\x41","\x42","\x43","\x44","\x45","\x46","\x47","\x48","\x49","\x4A","\x4B","\x4C","\x4D","\x4E","\x4F","\x50","\x51","\x52","\x53","\x54","\x55","\x56","\x57","\x58","\x59","\x5A","\x5B","\x5C","\x5D","\x5E","\x5F","\x60","\x61","\x62","\x63");//匹配字符集C
- $length = strlen($strnum);
- $b=array();
- $b[0] = "\x1b";
- $b[1] = "\x64";
- $b[2] = "\x02";
- $b[3] = "\x1d";
- $b[4] = "\x48";
- $b[5] = "\x32";//条形码显示控制,\x32上图下字,\x31上字下图,\x30只显示条形码
- $b[6] = "\x1d";
- $b[7] = "\x68";
- $b[8] = "\x50";// \x30 设置条形码高度,7F是最大的高度
- $b[9] = "\x1d";
- $b[10] = "\x77";
- $b[11] = "\x02";// \x01 设置条形码宽度,1-6
- $b[12] = "\x1d";
- $b[13] = "\x6b";
- $b[14] = "\x49";//选择条形码类型code128,code39,codabar等等
- $b[15] = chr($length + 2);
- $b[16] = "\x7b";
- $b[17] = "\x42";//选择字符集
- if($length > 14 && is_numeric($strnum)){//大于14个字符,且为纯数字的进来这个区间
- $b[17] = "\x43";
- $j = 0;
- $key = 18;
- $ss = $length/2;//初始化数组长度
- if($length%2 == 1){//判断条形码为单数
- $ss = $ss-0.5;
- }
- for ($i = 0; $i < $ss; $i++){
- $temp = substr($strnum,$j,2);
- $iindex = intval($temp);
- $j = $j+2;
- if($iindex == 0){
- $chr = '';
- if($b[$key + $i-1] == '0' && $b[$key + $i-2] == '0'){//判断前面的为字符集B,此时不需要转换字符集
- $b[$key + $i] = $codeB[0];
- $b[$key + $i + 1] = $codeB[0];
- $key += 1;
- }else{
- if($b[$key + $i-1] == 'C' && $b[$key + $i-2] == '{'){//判断前面的为字符集C时转换字符集B
- $b[$key + $i - 2] = "\x7b";
- $b[$key + $i - 1] = "\x42";
- $b[$key + $i] = $codeB[0];
- $b[$key + $i + 1] = $codeB[0];
- $key += 1;
- }else{
- $b[$key + $i] = "\x7b";
- $b[$key + $i + 1] = "\x42";
- $b[$key + $i + 2] = $codeB[0];
- $b[$key + $i + 3] = $codeB[0];
- $key += 3;
- }
- }
- }else{
- if($b[$key + $i-1] == '0' && $b[$key + $i-2] == '0' && $chr != 'chr'){//判断前面的为字符集B,此时要转换字符集C
- $b[$key + $i] = "\x7b";
- $b[$key + $i + 1] = "\x43";
- $b[$key + $i + 2] = $codeC[$iindex];
- $key += 2;
- }else{
- $chr = '';
- $b[$key + $i] = $codeC[$iindex];
- if($iindex == 48) $chr = 'chr';//判断chr(48)等于0的情况
- }
- }
- }
- @$lastkey = end(array_keys($b));//取得数组的最后一个元素的键
- if($length % 2 > 0){
- $lastnum = substr($strnum,-1);//取得字符串的最后一个数字
- if($b[$lastkey] == '0' && $b[$lastkey-1] == '0'){//判断前面的为字符集B,此时不需要转换字符集
- $b[$lastkey + 1] = $codeB[$lastnum];
- }else{
- $b[$lastkey + 1] = "\x7b";
- $b[$lastkey + 2] = "\x42";
- $b[$lastkey + 3] = $codeB[$lastnum];
- }
- }
- @$b[15] = chr(end(array_keys($b)) - 15);//得出条形码长度
- $str = implode("",$b);
- }else{//1-14个字符的纯数字和非纯数字的条形码进来这个区间,支持数字,大小写字母,特殊字符例如: !@#$%^&*()-=+_
- $str = "\x1b\x64\x02\x1d\x48\x32\x1d\x68\x50\x1d\x77\x02\x1d\x6b\x49".chr($length + 2)."\x7b\x42".$strnum;
- }
- return $str;
- }
- //打印数据 ssh 20210702
- public static function getPrintData($order, $debtAmount)
- {
- $orderSn = $order->orderSn ?? '';
- $printProduct = [];
- $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- if (!empty($orderItemList)) {
- foreach ($orderItemList as $itemKey => $itemVal) {
- $unitName = $itemVal['unitName'] ?? '';
- $unitPrice = $itemVal['unitPrice'] ? floatval($itemVal['unitPrice']) : 0;
- $printProduct[] = [
- 'name' => $itemVal['name'] ?? '',
- 'num' => $itemVal['num'] . $unitName . '*' . $unitPrice,
- 'price' => floatval($itemVal['price']),
- ];
- }
- }
- $orderGoodsList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
- if (!empty($orderGoodsList)) {
- foreach ($orderGoodsList as $itemKey => $itemVal) {
- $unitName = $itemVal['unitName'] ?? '份';
- $unitPrice = $itemVal['unitPrice'] ? floatval($itemVal['unitPrice']) : 0;
- $printProduct[] = [
- 'name' => $itemVal['name'] ?? '',
- 'num' => $itemVal['num'] . $unitName . '*' . $unitPrice,
- 'price' => floatval($itemVal['price']),
- ];
- }
- }
- $sendNum = $order['sendNum'] ?? '';
- //退款记录
- $refundList = [];
- $printData = [
- 'address' => '',
- 'sendCost' => $order->sendCost ?? '0.00',
- 'prePrice' => $order->prePrice ?? '0.00',
- 'orderPrice' => $order->orderPrice ?? '0',
- 'discountAmount' => $order->discountAmount ?? '0.00',
- 'realPrice' => $order->realPrice ?? '0.00',
- 'refundPrice' => $order->refundPrice ?? '0.00',
- 'debt' => $order->debt ?? 0,
- 'orderSn' => $order->orderSn ?? '',
- 'date' => $order->addTime ?? '',
- 'remark' => $order->remark ?? '',
- 'custom' => [
- 'customName' => $order->customName ?? '',
- 'customMobile' => $order->customMobile ?? '',
- 'fullAddress' => $order->fullAddress ?? '',
- ],
- 'product' => $printProduct,
- 'refund' => $refundList,
- 'sendNum' => $sendNum,
- 'debtAmount' => $debtAmount,
- ];
- return $printData;
- }
- public static function printGroup($current, $content)
- {
- //58mm的机器,一行打印16个汉字,32个字母
- $name = $current['name'] ?? '';
- $content .= $name . '<BR>';
- $name = str_repeat(' ', 10);
- $productNum = $current['num'] ?? '';
- $blankNum = bcsub(12, strlen($productNum));
- if ($blankNum > 0) {
- $productNum = $productNum . str_repeat(' ', $blankNum);
- }
- $productPrice = $current['price'] ?? '';
- $blankNum = bcsub(7, strlen($productPrice));
- if ($blankNum > 0) {
- $productPrice = $productPrice . str_repeat(' ', $blankNum);
- }
- $content .= $name . " " . $productNum . ' ' . $productPrice . '<BR>';
- return $content;
- }
- }
|