| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846 |
- <?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\shop\classes\ShopMoneyChangeClass;
- use bizHd\stat\classes\StatIncomeClass;
- use bizHd\stat\classes\StatOrderClass;
- use bizHd\user\classes\UserClass;
- use bizHd\work\classes\WorkClass;
- use bizHd\wx\classes\WxOpenClass;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\miniUtil;
- use common\components\noticeUtil;
- use common\components\orderSn;
- use common\components\printUtil;
- use common\components\util;
- use Yii;
- use bizHd\base\classes\BaseClass;
- use common\components\lakala\Lakala;
- 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) {
- Yii::info(json_encode($order));
- Yii::info('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('没有找到门店信息54');
- }
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有找到main信息');
- }
- $main->unPayOrder += 1;
- $main->totalOrder += 1;
- $main->save();
- $address = $data['address'] ?? '';
- $floor = $data['floor'] ?? '';
- if (isset($data['fullAddress']) == false || empty($data['fullAddress'])) {
- $data['fullAddress'] = $address . $floor;
- }
- //非自取订单考虑配送时间
- $data['reachDate'] = isset($data['reachDate']) && !empty($data['reachDate']) ? $data['reachDate'] : date("Y-m-d");
- $sendType = $data['sendType'] ?? 0;
- if ($sendType != 1) {
- if (isset($data['reachPeriod']) == false || empty($data['reachPeriod'])) {
- util::fail('请选择配送时间');
- }
- $data['reachTime'] = strtotime($data['reachDate'] . ' ' . $data['reachPeriod']);
- }
- //将花店每月的总订单数作为编号
- $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);
- $workList = WorkClass::getAllByCondition(['orderId' => $id], null, '*');
- if (!empty($workList)) {
- foreach ($workList as $key => $work) {
- $shortCover = $work['cover'] ?? '';
- $workList[$key]['shortCover'] = $shortCover;
- $workList[$key]['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- }
- }
- $order['workList'] = $workList;
- $order['today'] = date("Y-m-d");
- $order['tomorrow'] = date("Y-m-d", strtotime("+1 day"));
- 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)) {
- noticeUtil::push('散客下单,付款成功,支付回调,单号:' . $orderSn . ',没有找到订单', '15280215347');
- $msg = "没有找到零售订单 orderSn:{$orderSn}";
- Yii::info($msg);
- util::fail($msg);
- }
- if ($order->mainPay != $totalFee) {
- noticeUtil::push("散客下单,付款成功,支付回调错误,零售订单金额与回调通知金额不一致 orderSn:{$orderSn} {$order->mainPay} {$totalFee}", '15280215347');
- $msg = "零售订单金额与回调通知金额不一致 orderSn:{$orderSn} {$order->mainPay} {$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)) {
- util::fail('没有找到订单的状态');
- }
- $orderSn = $order->orderSn ?? '';
- if ($order->status == self::ORDER_STATUS_CANCEL) {
- noticeUtil::push('特别注意,零售订单:' . $orderSn . ',付款成功但订单是取消状态', '15280215347');
- util::fail('订单已取消');
- }
- if ($order->payStatus == 1) {
- noticeUtil::push('特别注意,零售订单:' . $orderSn . ',已经付过款了,无需重复请求和操作', '15280215347');
- util::fail('订单已经付过款了');
- }
- $orderId = $order->id ?? 0;
- $customId = $order->customId ?? 0;
- if ($order->fromType == 3) {
- //客服下的单要配送流程
- $order->status = self::ORDER_STATUS_UN_SEND;
- } else {
- $order->status = self::ORDER_STATUS_COMPLETE;
- }
- $order->payWay = $payWay;
- $order->payStatus = 1;
- $order->payTime = date("Y-m-d H:i:s");
- $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('没有找到门店55');
- }
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息36');
- }
- $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->mainPay;
- ShopClass::customKdAddBalance($main, $shop, $amount, $order, $capitalType);
- }
- //客户使用余额付款
- if ($payWay == dict::getDict('payWay', 'balancePay')) {
- //客户端余额减少
- //增加余额变动记录
- CustomClass::payByChangeBalance($order);
- }
- //有尾款或全欠款
- if (isset($order->remainDebtPrice) && $order->remainDebtPrice > 0) {
- $newCustom = CustomClass::getLockById($customId);
- CustomClass::cgDebtAmountAdd($newCustom, $order);
- }
- //全部现金付款余额增加
- if ($payWay == dict::getDict('payWay', 'cash')) {
- $moneyBalance = bcadd($main->money, $order->mainPay, 2);
- $main->money = $moneyBalance;
- $main->save();
- $moneyEvent = "客户现金下单" . floatval($order->mainPay) . "元(单号 {$order->orderSn})";
- $moneyRemark = '';
- $change = [
- 'relateId' => $orderId,
- 'amount' => $order->mainPay,
- 'balance' => $moneyBalance,
- 'io' => 1,
- 'mainId' => $mainId,
- 'capitalType' => $capitalType,
- 'ptStyle' => dict::getDict('ptStyle', 'hd'),
- 'event' => $moneyEvent,
- 'remark' => $moneyRemark,
- ];
- ShopMoneyChangeClass::addData($change);
- } else {
- //部分现金付款
- $orderCash = $order->cash ?? 0;
- $orderCash = floatval($orderCash);
- if ($orderCash > 0) {
- $moneyBalance = bcadd($main->money, $orderCash, 2);
- $main->money = $moneyBalance;
- $main->save();
- $moneyEvent = "客户部分现金付款{$orderCash}元(单号 {$order->orderSn})";
- $moneyRemark = '';
- $change = [
- 'relateId' => $orderId,
- 'amount' => $orderCash,
- 'balance' => $moneyBalance,
- 'io' => 1,
- 'mainId' => $mainId,
- 'capitalType' => $capitalType,
- 'ptStyle' => dict::getDict('ptStyle', 'hd'),
- 'event' => $moneyEvent,
- 'remark' => $moneyRemark,
- ];
- ShopMoneyChangeClass::addData($change);
- }
- }
- }
- //转化出送到时间 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, $force = false)
- {
- $now = time();
- if ($order->deadline > $now && $force == false) {
- return false;
- }
- if ($order->status != 1) {
- return false;
- }
- $order->status = 5;
- $order->cancelTime = date("Y-m-d H:i:s");
- $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);
- }
- }
- $shopId = $order->shopId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (!empty($shop)) {
- $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
- $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
- $params = [
- 'appid' => 'OP00002119',
- 'serial_no' => '018b08cfddbd',
- 'merchant_no' => $shop->lklSjNo,
- 'term_no' => $shop->lklScanTermNo,
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $closeParams = [
- 'orderSn' => $orderSn,
- ];
- $response = $laResource->close($closeParams);
- if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
- //noticeUtil::push('零售订单:' . $orderSn . ',关单没有成功。', '15280215347');
- } else {
- //noticeUtil::push('零售订单:' . $orderSn . ',关单成功。', '15280215347');
- }
- }
- }
- // 扣库存
- 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, $must = false, $port = 'front')
- {
- if (empty($order)) {
- return false;
- }
- if ($must == 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 ($port == 'make') {
- $printSn = $ext['makePrintSn'] ?? '';
- if ($order->fromType == 4) {
- $printSn = $ext['mtPrintSn'] ?? '';
- }
- $workList = WorkClass::getAllByCondition(['orderId' => $order->id], null, '*', null, true);
- $hasSh = 0;
- if (!empty($workList)) {
- foreach ($workList as $work) {
- $sh = $work->sh ?? 0;
- if ($sh == 1) {
- $hasSh = 1;
- }
- }
- }
- if ($hasSh == 1) {
- $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);
- $fromType = $order->fromType ?? dict::getDict('fromType', 'shop');
- $fromTypeMap = dict::getDict('fromTypeMap');
- $fromTypeName = $fromTypeMap[$fromType] ?? '门店';
- //客服下的单则显示客服号和客户名称
- if ($fromType == dict::getDict('fromType', 'friend')) {
- $staffName = $order->shopAdminName ?? '';
- $bookName = $order->bookName ?? '';
- $fromTypeName = $staffName . ' ' . $bookName;
- }
- $content = '';
- //$content .= "<CB>【零售】</CB><BR>";
- if ($fromType == dict::getDict('fromType', 'mt')) {
- $content .= '<B>美团 ' . $order->thirdSn . '</B><BR>';
- if (isset($order->goodsNum) && $order->goodsNum > 1) {
- $content .= '<B>美团 ' . $order->thirdSn . ' (' . $order->goodsNum . '份)</B><BR>';
- }
- $content .= '--------------------------------<BR>';
- $content .= date("Y-m-d", strtotime($order->addTime)) . '<BR>';
- } else {
- $content .= '<CB>' . $fromTypeName . ' ' . $respond['sendNum'] . '</CB><BR>';
- $content .= '--------------------------------<BR>';
- }
- $readPeriod = $order->reachPeriod ?? 0;
- if ($order->sendType == 1) {
- if (isset($order->reachDate) && !empty($order->reachDate) && $order->reachDate != '0000-00-00') {
- $currentReachDate = date("m-d", strtotime($order->reachDate));
- $content .= '<B>' . $currentReachDate . ' ' . $readPeriod . '前</B><BR>';
- $content .= '<B>到店自取</B><BR><BR>';
- } else {
- $content .= '<B>到店自取</B><BR><BR>';
- }
- } else {
- if ($order->sendType == 0) {
- $content .= '<B>送货上门</B><BR><BR>';
- } else if ($order->sendType == 2) {
- $content .= '<B>跑腿到付</B><BR><BR>';
- } else if ($order->sendType == 3) {
- $content .= '<B>物流到付</B><BR><BR>';
- } else if ($order->sendType == 4) {
- $content .= '<B>快递到付</B><BR><BR>';
- } else {
- $content .= '';
- }
- if (isset($order->reachDate) && !empty($order->reachDate) && $order->reachDate != '0000-00-00') {
- $currentReachDate = date("m-d", strtotime($order->reachDate));
- $content .= '<B>' . $currentReachDate . ' ' . $readPeriod . '前</B><BR><BR>';
- }
- }
- if (isset($order->receiveUserName) && !empty($order->receiveUserName)) {
- $content .= '收花人:<BR>';
- $content .= '<B>' . $order->receiveUserName . '</B><BR>';
- }
- if (isset($order->receiveMobile) && !empty($order->receiveMobile)) {
- $content .= '<B>' . $order->receiveMobile . '</B><BR><BR>';
- }
- if (isset($order->fullAddress) && !empty($order->fullAddress)) {
- $content .= '<B>' . $order->fullAddress . '(' . $order->showAddress . ')' . '</B><BR><BR>';
- }
- if (isset($order->cardInfo) && !empty($order->cardInfo)) {
- $content .= '<B>贺卡内容:' . $order->cardInfo . '</B><BR><BR>';
- }
- if ($order->anonymity == 1) {
- $content .= '<B>匿名派送!!</B><BR><BR>';
- } else {
- if (isset($order->bookMobile) && !empty($order->bookMobile)) {
- $bookName = $order->bookName ?? '';
- $bookMobile = $order->bookMobile ?? '';
- $content .= '订花人:<BR>';
- if (!empty($bookName)) {
- $content .= '<B>' . $bookName . '</B><BR>';
- }
- if (!empty($bookMobile)) {
- $content .= '<B>' . $bookMobile . '</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($order->goodsPrice) && $order->goodsPrice > 0) {
- $content .= '商品合计:' . floatval($order->goodsPrice) . '<BR>';
- }
- if (isset($respond['sendCost']) && $respond['sendCost'] > 0 && $order->sendType == 2) {
- $content .= '运费:' . floatval($respond['sendCost']) . '<BR>';
- }
- if (isset($order->serviceFee) && $order->serviceFee > 0) {
- $content .= '手续费:' . floatval($order->serviceFee) . '<BR>';
- }
- if (isset($order->labourCost) && $order->labourCost > 0) {
- $content .= '包装费:' . floatval($order->labourCost) . '<BR>';
- }
- if (isset($order->prePrice) && $order->prePrice > 0) {
- $content .= '总计:' . floatval($order->prePrice) . '<BR>';
- }
- if (isset($respond['discountAmount']) && !empty($respond['discountAmount']) && $respond['discountAmount'] > 0) {
- $content .= '优惠扣除:-' . floatval($respond['discountAmount']) . '<BR>';
- }
- $content .= '订单金额:' . floatval($respond['orderPrice']) . '<BR>';
- if (isset($respond['refundPrice']) && $respond['refundPrice'] > 0) {
- $content .= '退款金额:' . floatval($respond['refundPrice']) . '<BR>';
- }
- if (isset($respond['debt']) && $respond['debt'] == 1) {
- $content .= '实付金额:0<BR>';
- } else {
- $content .= '实付金额:' . floatval($respond['realPrice']) . '<BR>';
- }
- if (isset($order->remainDebtPrice) && $order->remainDebtPrice > 0) {
- $content .= '<B>待付尾款:' . floatval($order->remainDebtPrice) . '</B><BR>';
- }
- $shop = ShopClass::getById($shopId, true);
- $sjId = $shop->sjId ?? 0;
- $sj = SjClass::getById($sjId, true);
- $sjName = $sj->name ?? '';
- $shopName = $shop->shopName ?? '';
- $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
- $content .= '--------------------------------<BR>';
- $content .= '订单日期:' . $order->addTime . '<BR>';
- $content .= '订单编号:' . $respond['orderSn'] . '<BR>';
- $content .= '门店名称:' . $currentName . '<BR>';
- $content .= "<BR>";
- $p = new printUtil($printSn);
- $orderSn = $order->orderSn ?? '';
- $workList = WorkClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (!empty($workList)) {
- $content .= "<BR>";
- $content .= '--------------------------------<BR>';
- foreach ($workList as $work) {
- $goodsSn = $work->goodsSn ?? '';
- $sn = $work->sn ?? '';
- $content .= '<B>制作号:' . $sn . '<B>';
- // 1-523 有-特殊符号,使用飞鹅自带的函数处理
- $content .= $p->bar_code($goodsSn);
- $content .= "<BR>";
- }
- }
- $p->printMsg($content);
- }
- //打印数据 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;
- }
- }
|