OrderClass.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. <?php
  2. namespace bizHd\order\classes;
  3. use biz\goods\classes\GoodsClass;
  4. use biz\goods\models\Goods;
  5. use biz\shop\classes\ShopAdminClass;
  6. use biz\shop\classes\ShopCapitalClass;
  7. use biz\shop\classes\ShopClass;
  8. use biz\shop\classes\ShopExtClass;
  9. use biz\shop\models\Shop;
  10. use biz\stat\classes\StatKdClass;
  11. use biz\stat\classes\StatOrderCountClass;
  12. use biz\stat\classes\StatSaleClass;
  13. use biz\stock\classes\GoodsStockRecordClass;
  14. use biz\wx\classes\WxMessageClass;
  15. use bizGhs\product\classes\ProductClass;
  16. use bizGhs\stat\classes\StatYjClass;
  17. use bizGhs\stock\classes\StockRecordClass;
  18. use bizGhs\ws\services\WsService;
  19. use bizHd\custom\classes\CustomClass;
  20. use bizHd\merchant\classes\SjClass;
  21. use bizHd\shop\classes\MainClass;
  22. use bizHd\stat\classes\StatIncomeClass;
  23. use bizHd\stat\classes\StatOrderClass;
  24. use bizHd\user\classes\UserClass;
  25. use bizHd\work\classes\WorkClass;
  26. use common\components\dict;
  27. use common\components\miniUtil;
  28. use common\components\orderSn;
  29. use common\components\printUtil;
  30. use common\components\util;
  31. use Yii;
  32. use bizHd\base\classes\BaseClass;
  33. class OrderClass extends BaseClass
  34. {
  35. public static $baseFile = '\bizHd\order\models\Order';
  36. //已取消
  37. const ORDER_STATUS_CANCEL = 5;
  38. //完成
  39. const ORDER_STATUS_COMPLETE = 4;
  40. //配送中
  41. const ORDER_STATUS_SENDING = 3;
  42. //待配送
  43. const ORDER_STATUS_UN_SEND = 2;
  44. //待付款
  45. const ORDER_STATUS_UN_PAY = 1;
  46. //订单总流程数
  47. const ORDER_TOTAL_FLOW = 4;
  48. //未确认配送方式
  49. const SEND_TYPE_UNKNOWN = 0;
  50. //自取
  51. const SEND_TYPE_NO = 1;
  52. //自己送
  53. const SEND_TYPE_MYSELF = 2;
  54. //快递送
  55. const SEND_TYPE_THIRD = 3;
  56. //正常订单
  57. const REFUND_NO = 0;
  58. //已退款订单
  59. const REFUND_YES = 1;
  60. //送达时间段
  61. public static $reachPeriod = [0 => '上午', 1 => '下午', 2 => '晚上'];
  62. //优惠金额
  63. public static $randDiscount = [
  64. 50 => [1, 3],
  65. 100 => [5, 9],
  66. 300 => [10, 15],
  67. 500 => [16, 18],
  68. 1000 => [18, 30],
  69. 20000 => [90, 100],
  70. ];
  71. public static function valid($order, $mainId)
  72. {
  73. if (isset($order->mainId) == false || $order->mainId != $mainId) {
  74. Yii::info(json_encode($order));
  75. Yii::info('mainId: ' . $mainId);
  76. util::fail('没有权限访问的订单');
  77. }
  78. return true;
  79. }
  80. //添加订单 ssh 2019.12.5
  81. public static function addOrder($data)
  82. {
  83. $data['orderSn'] = $data['orderSn'] ?? orderSn::getOrderSn();
  84. $data['payStatus'] = $data['payStatus'] ?? 0;
  85. $shopId = $data['shopId'] ?? 0;
  86. //累计订单增加
  87. $shop = ShopClass::getLockById($shopId);
  88. if (empty($shop)) {
  89. util::fail('没有找到门店信息');
  90. }
  91. $mainId = $shop->mainId ?? 0;
  92. $main = MainClass::getLockById($mainId);
  93. if (empty($main)) {
  94. util::fail('没有找到main信息');
  95. }
  96. $main->unPayOrder += 1;
  97. $main->totalOrder += 1;
  98. $main->save();
  99. $address = $data['address'] ?? '';
  100. $floor = $data['floor'] ?? '';
  101. $data['fullAddress'] = $address . $floor;
  102. $data['reachDate'] = isset($data['reachDate']) && !empty($data['reachDate']) ? $data['reachDate'] : '0000-00-00';
  103. //将花店每月的总订单数作为编号
  104. $riseNum = StatOrderCountClass::addOrder($shop, $main);
  105. $data['sendNum'] = date("d") . $riseNum;
  106. $data['totalFlow'] = OrderClass::ORDER_TOTAL_FLOW;
  107. $return = self::add($data, true);
  108. return $return;
  109. }
  110. public static function getByOrderSn($orderSn)
  111. {
  112. return self::getByCondition(['orderSn' => $orderSn]);
  113. }
  114. //评价 ssh 2019.12.16
  115. public static function comment($data)
  116. {
  117. $id = $data['id'];
  118. unset($data['id']);
  119. return self::updateById($id, $data);
  120. }
  121. public static function getFullInfo($id)
  122. {
  123. $order = self::getById($id);
  124. if (empty($order)) {
  125. return [];
  126. }
  127. $sn = $order['orderSn'] ?? '';
  128. $order['goodsInfoList'] = OrderGoodsClass::getListBySn($sn);
  129. $order['itemInfoList'] = OrderItemClass::getListBySn($sn);
  130. return $order;
  131. }
  132. //订单
  133. public static function getOrderById($id)
  134. {
  135. $order = self::getById($id);
  136. if (empty($order)) {
  137. return [];
  138. }
  139. $sn = $order['orderSn'] ?? '';
  140. $order['goodsInfoList'] = OrderGoodsClass::getListBySn($sn);
  141. return $order;
  142. }
  143. //根据订单查询 ssh 2020.1.4
  144. public static function getOrderBySn($orderSn)
  145. {
  146. $order = self::getByCondition(['orderSn' => $orderSn]);
  147. if (empty($order)) {
  148. return [];
  149. }
  150. $id = $order['id'];
  151. $order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
  152. return $order;
  153. }
  154. //返回随机优惠金额 ssh 2019.9.12
  155. public static function getRandDiscount($amount)
  156. {
  157. if ($amount <= 0) {
  158. return 0;
  159. }
  160. $randDiscount = self::$randDiscount;
  161. krsort($randDiscount);
  162. $rand = 0;
  163. foreach ($randDiscount as $currentAmount => $val) {
  164. if ($amount >= $currentAmount) {
  165. $rand = rand($val[0], $val[1]);
  166. break;
  167. }
  168. }
  169. return $rand / 10;
  170. }
  171. //第三方支付后回调处理流程 ssh 2021.4.30
  172. public static function thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId)
  173. {
  174. $order = self::getByCondition(['orderSn' => $orderSn], true);
  175. if (empty($order)) {
  176. $msg = "没有找到零售订单 orderSn:{$orderSn}";
  177. Yii::info($msg);
  178. util::fail($msg);
  179. }
  180. if ($order->realPrice != $totalFee) {
  181. $msg = "零售订单金额与回调通知金额不一致 orderSn:{$orderSn} {$order->realPrice} {$totalFee}";
  182. Yii::info($msg);
  183. util::fail($msg);
  184. }
  185. $id = $order->id;
  186. $order = self::getLockById($id);
  187. $date = date("Y-m-d H:i:s");
  188. $order->payTime = $date;
  189. $order->thirdNo = $transactionId;
  190. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  191. $order->save();
  192. self::payAfter($order, $payWay);
  193. }
  194. //订单完成 ssh 2021.4.20
  195. public static function payAfter($order, $payWay)
  196. {
  197. if (empty($order)) {
  198. util::fail('没有找到订单');
  199. }
  200. if (isset($order->status) == false || $order->status != self::ORDER_STATUS_UN_PAY) {
  201. util::fail('订单不是待付款状态');
  202. }
  203. $orderId = $order->id ?? 0;
  204. $order->status = self::ORDER_STATUS_COMPLETE;
  205. $order->payWay = $payWay;
  206. $order->payStatus = 1;
  207. $order->stockChange = 1;
  208. $order->save();
  209. \bizMall\order\classes\OrderGoodsClass::stockChange($order);
  210. $realPrice = $order->realPrice ?? 0;
  211. $shopId = $order->shopId;
  212. $shop = ShopClass::getLockById($shopId);
  213. if (empty($shop)) {
  214. util::fail('没有找到门店');
  215. }
  216. $mainId = $shop->mainId ?? 0;
  217. $main = MainClass::getLockById($mainId);
  218. if (empty($main)) {
  219. util::fail('没有main信息');
  220. }
  221. $main->unSendOrder += 1;
  222. $main->unPayOrder -= 1;
  223. $currentTotalIncome = bcadd($main->totalIncome, $realPrice, 2);
  224. $main->totalIncome = $currentTotalIncome;
  225. $main->save();
  226. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  227. $shopAdminId = $order->shopAdminId ?? 0;
  228. $shopAdminName = $order->shopAdminName ?? '';
  229. $sjId = $order->sjId;
  230. $fromType = $order->fromType ?? 1;
  231. $event = !empty($shopAdminId) ? '员工开单' : '客户下单';
  232. $capital = [
  233. 'capitalType' => $capitalType,
  234. 'relateId' => $orderId,
  235. 'io' => 1,
  236. 'totalIncome' => $currentTotalIncome,
  237. 'payWay' => $payWay,
  238. 'event' => $event,
  239. 'sjId' => $sjId,
  240. 'shopId' => $shopId,
  241. 'shopAdminId' => $shopAdminId,
  242. 'shopAdminName' => $shopAdminName,
  243. 'amount' => $realPrice,
  244. 'fromType' => $fromType,
  245. 'mainId' => $mainId,
  246. ];
  247. ShopCapitalClass::addCapital($capital);
  248. //每天和每月收入增加
  249. StatIncomeClass::updateOrInsert($main, $shop, $realPrice);
  250. //今日订单+1
  251. StatOrderClass::updateOrInsert($main, $shop);
  252. //销售收入增加
  253. StatSaleClass::replace($main, $shop, $realPrice);
  254. //各渠道收入金额统计
  255. StatKdClass::replace($shop, $realPrice, $payWay);
  256. //客户在线支付下单增加商家可提现余额
  257. if (isset($order->onlinePay) && $order->onlinePay == dict::getDict('onlinePay', 'yes')) {
  258. $amount = $order->actPrice;
  259. ShopClass::customKdAddBalance($main, $shop, $amount, $order, $capitalType);
  260. }
  261. }
  262. //转化出送到时间 ssh 2020.3.15
  263. public static function getReachTime($order)
  264. {
  265. $reachTime = '';
  266. if (isset($order['reachDate']) && !empty($order['reachDate'])) {
  267. $prev = date("n-j", strtotime($order['reachDate']));
  268. $periodData = self::$reachPeriod;
  269. $periodKey = $order['reachPeriod'];
  270. $period = isset($periodData[$periodKey]) ? $periodData[$periodKey] : '上午';
  271. $reachTime = $prev . ' ' . $period;
  272. }
  273. return $reachTime;
  274. }
  275. //支付成功获取unionId ssh 2020.5.12
  276. public static function payToUpdateUnionId($merchant, $merchantExtend, $orderSn, $user)
  277. {
  278. $mcId = $merchantExtend['wxPayMerchantId'];
  279. $miniOpenId = isset($user['miniOpenId']) ? $user['miniOpenId'] : '';
  280. $unionId = isset($user['unionId']) ? $user['unionId'] : '';
  281. $userId = $user['id'];
  282. if (empty($unionId)) {
  283. $unionId = miniUtil::getPaidUnionId($merchant, $miniOpenId, $mcId, (string)$orderSn, 0);
  284. if (!empty($unionId)) {
  285. $findUser = UserClass::getByUnionId($unionId);
  286. if (empty($findUser)) {
  287. UserClass::updateByCondition(['id' => $userId], ['unionId' => $unionId]);
  288. } else {
  289. UserClass::mergeUser($findUser, $user);
  290. }
  291. }
  292. }
  293. }
  294. //订单取消 ssh 20220516
  295. public static function setExpire($order)
  296. {
  297. $now = time();
  298. if ($order->deadline > $now) {
  299. return false;
  300. }
  301. if ($order->status != 1) {
  302. return false;
  303. }
  304. $order->status = 5;
  305. $order->save();
  306. //暂时只考虑花材库存的回滚。商品只有下单成功了才会占用库存。
  307. $orderSn = $order->orderSn ?? '';
  308. $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  309. if (!empty($itemList)) {
  310. foreach ($itemList as $item) {
  311. $ptItemId = $item->ptItemId ?? 0;
  312. $sjId = $item->sjId ?? 0;
  313. $shopId = $item->shopId ?? 0;
  314. $mainId = $item->mainId ?? 0;
  315. $ratio = $item->ratio ?? 20;
  316. $unitType = $item->unitType ?? 0;
  317. $bigNum = 0;
  318. $smallNum = 0;
  319. if ($unitType == 0) {
  320. $bigNum = $item->num;
  321. } else {
  322. $smallNum = $item->num;
  323. }
  324. $itemId = $item->itemId ?? 0;
  325. $stockInfo = ProductClass::addStock($itemId, $bigNum, $smallNum);
  326. $recordData = [];
  327. $recordData['sjId'] = $sjId;
  328. $recordData['shopId'] = $shopId;
  329. $recordData['mainId'] = $mainId;
  330. $recordData['itemId'] = $ptItemId;
  331. $recordData['itemNum'] = ProductClass::mergeItemNum($bigNum, $smallNum, $ratio);
  332. $recordData['oldStock'] = $stockInfo['oldStock'];
  333. $recordData['newStock'] = $stockInfo['newStock'];
  334. $recordData['productId'] = $itemId;
  335. $recordData['orderSn'] = $orderSn;
  336. $recordData['relateName'] = '系统';
  337. StockRecordClass::addSellStockOrderCancelRecord($recordData);
  338. }
  339. }
  340. }
  341. // 扣库存
  342. protected static function decGoodsStock($orderGoods)
  343. {
  344. foreach ($orderGoods as $goods) {
  345. GoodsClass::counters([
  346. 'stock' => -$goods['num']
  347. ], [
  348. 'and',
  349. ['id' => $goods['goodsId']],
  350. ['<>', 'stock', Goods::FULL_STOCK]
  351. ]);
  352. }
  353. }
  354. // 更新商品销量
  355. protected static function updateGoodsActualSold($orderGoods)
  356. {
  357. foreach ($orderGoods as $goods) {
  358. GoodsClass::counters([
  359. 'actualSold' => $goods['num']
  360. ], [
  361. 'id' => $goods['goodsId']
  362. ]);
  363. }
  364. }
  365. //云打印 ssh 20210709
  366. public static function onlinePrint($order, $must = false, $port = 'front')
  367. {
  368. if (empty($order)) {
  369. return false;
  370. }
  371. if ($must == false) {
  372. if ($order->needPrint != dict::getDict('needPrint', 'need')) {
  373. return false;
  374. }
  375. if ($order->payStatus != 1) {
  376. return false;
  377. }
  378. }
  379. $shopId = $order->shopId ?? 0;
  380. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  381. $printSn = $ext['printSn'] ?? '';
  382. if ($port == 'make') {
  383. $printSn = $ext['makePrintSn'] ?? '';
  384. }
  385. if (empty($printSn)) {
  386. return false;
  387. }
  388. $order->printNum += 1;
  389. $order->save();
  390. $customId = $order->customId ?? 0;
  391. $custom = CustomClass::getById($customId);
  392. $debtAmount = $custom['debtAmount'] ?? 0;
  393. $respond = self::getPrintData($order, $debtAmount);
  394. $fromType = $order->fromType ?? dict::getDict('fromType', 'shop');
  395. $fromTypeMap = dict::getDict('fromTypeMap');
  396. $fromTypeName = $fromTypeMap[$fromType] ?? '门店';
  397. //客服下的单则显示客服号和客户名称
  398. if ($fromType == dict::getDict('fromType', 'friend')) {
  399. $staffName = $order->shopAdminName ?? '';
  400. $bookName = $order->bookName ?? '';
  401. $fromTypeName = $staffName . ' ' . $bookName;
  402. }
  403. if ($fromType == dict::getDict('fromType', 'mt')) {
  404. $content = '<B>美团编号 ' . $order->thirdSn . '</B><BR>';
  405. } else {
  406. $content = '<B>' . $respond['sendNum'] . ' ' . $fromTypeName . '</B><BR>';
  407. }
  408. $content .= '--------------------------------<BR>';
  409. $readPeriod = $order->reachPeriod ?? 0;
  410. $reachPeriodName = dict::getDict('reachPeriodName');
  411. $period = $reachPeriodName[$readPeriod] ?? '上午';
  412. if (isset($order->receiveUserName) && !empty($order->receiveUserName)) {
  413. $content .= '<B>' . $order->receiveUserName . '</B><BR>';
  414. }
  415. if (isset($order->receiveMobile) && !empty($order->receiveMobile)) {
  416. $content .= '<B>' . $order->receiveMobile . '</B><BR><BR>';
  417. }
  418. if (isset($order->reachDate) && !empty($order->reachDate) && $order->reachDate != '0000-00-00') {
  419. $content .= '<B>' . $order->reachDate . ' ' . $period . '</B><BR><BR>';
  420. }
  421. if (isset($order->fullAddress) && !empty($order->fullAddress)) {
  422. $content .= '<B>' . $order->fullAddress . '(' . $order->showAddress . ')' . '</B><BR><BR>';
  423. }
  424. if ($order->needCard == 1) {
  425. $content .= '<B>需要贺卡</B><BR><BR>';
  426. }
  427. if (isset($order->cardInfo) && !empty($order->cardInfo)) {
  428. $content .= '贺卡内容:' . $order->cardInfo . '<BR><BR>';
  429. }
  430. if ($order->anonymity == 1) {
  431. $content .= '<B>匿名派送!!!</B><BR><BR>';
  432. } else {
  433. if (isset($order->bookMobile) && !empty($order->bookMobile)) {
  434. $content .= '订花人电话:' . $order->bookMobile . '<BR><BR>';
  435. }
  436. }
  437. if ($order->sendType == 1) {
  438. $content .= '<B>到店自取!!</B><BR><BR>';
  439. }
  440. if (isset($respond['remark']) && !empty($respond['remark'])) {
  441. $content .= '<BR>';
  442. $content .= '备注:<BR>';
  443. $content .= '<B>' . $respond['remark'] . '</B><BR>';
  444. }
  445. $content .= '<BR>';
  446. $content .= '花材 数量/单价 金额 <BR>';
  447. $content .= '--------------------------------<BR>';
  448. if (isset($respond['product']) && !empty($respond['product'])) {
  449. foreach ($respond['product'] as $current) {
  450. $content = self::printGroup($current, $content);
  451. }
  452. $content .= '--------------------------------<BR>';
  453. }
  454. if (isset($respond['refund']) && !empty($respond['refund'])) {
  455. $content .= '<B>已退款:</B><BR>';
  456. foreach ($respond['refund'] as $current) {
  457. //58mm的机器,一行打印16个汉字,32个字母
  458. $name = $current['name'] ?? '';
  459. $content .= $name . '<BR>';
  460. $name = str_repeat(' ', 10);
  461. $productNum = $current['num'] ?? '';
  462. $blankNum = bcsub(12, strlen($productNum));
  463. if ($blankNum > 0) {
  464. $productNum = $productNum . str_repeat(' ', $blankNum);
  465. }
  466. $productPrice = $current['price'] ?? '';
  467. $blankNum = bcsub(7, strlen($productPrice));
  468. if ($blankNum > 0) {
  469. $productPrice = $productPrice . str_repeat(' ', $blankNum);
  470. }
  471. $content .= $name . " " . $productNum . ' ' . $productPrice . '<BR>';
  472. }
  473. $content .= '--------------------------------<BR>';
  474. }
  475. if (isset($respond['sendCost']) && $respond['sendCost'] > 0) {
  476. $content .= ' 运费:' . floatval($respond['sendCost']) . '<BR>';
  477. }
  478. $content .= '订单金额:' . floatval($respond['orderPrice']) . '<BR>';
  479. if (isset($respond['discountAmount']) && !empty($respond['discountAmount']) && $respond['discountAmount'] > 0) {
  480. $content .= '优惠扣除:-' . floatval($respond['discountAmount']) . '<BR>';
  481. }
  482. if (isset($respond['refundPrice']) && $respond['refundPrice'] > 0) {
  483. $content .= '退款金额:' . floatval($respond['refundPrice']) . '<BR>';
  484. }
  485. $content .= '应付金额:' . floatval($respond['orderPrice']) . '<BR>';
  486. if (isset($respond['debt']) && $respond['debt'] == 1) {
  487. $content .= '实付金额:0<BR>';
  488. } else {
  489. $content .= '实付金额:' . floatval($respond['realPrice']) . '<BR>';
  490. }
  491. if (isset($order->remainDebtPrice) && $order->remainDebtPrice > 0) {
  492. $content .= '<B>待付尾款:' . floatval($order->remainDebtPrice) . '</B><BR>';
  493. }
  494. $shop = ShopClass::getById($shopId, true);
  495. $sjId = $shop->sjId ?? 0;
  496. $sj = SjClass::getById($sjId, true);
  497. $sjName = $sj->name ?? '';
  498. $currentName = $sjName;
  499. if (isset($shop->default) == false || $shop->default != 1) {
  500. $shopName = $shop->shopName ?? '';
  501. if (!empty($shopName)) {
  502. $currentName = $currentName . ' ' . $shopName;
  503. }
  504. }
  505. $content .= '--------------------------------<BR>';
  506. $content .= '订单日期:' . $order->addTime . '<BR>';
  507. $content .= '订单编号:' . $respond['orderSn'] . '<BR>';
  508. $content .= '门店名称:' . $currentName . '<BR>';
  509. $content .= "<BR>";
  510. $p = new printUtil($printSn);
  511. $orderSn = $order->orderSn ?? '';
  512. $workList = WorkClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  513. if (!empty($workList)) {
  514. $content .= "<BR>";
  515. $content .= '--------------------------------<BR>';
  516. foreach ($workList as $work) {
  517. $goodsSn = $work->goodsSn ?? '';
  518. $sn = $work->sn ?? '';
  519. $content .= '<B>制作号:' . $sn . '<B>';
  520. // 1-523 有-特殊符号,使用飞鹅自带的函数处理
  521. $content .= $p->bar_code($goodsSn);
  522. $content .= "<BR>";
  523. }
  524. }
  525. $p->printMsg($content);
  526. }
  527. //打印数据 ssh 20210702
  528. public static function getPrintData($order, $debtAmount)
  529. {
  530. $orderSn = $order->orderSn ?? '';
  531. $printProduct = [];
  532. $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  533. if (!empty($orderItemList)) {
  534. foreach ($orderItemList as $itemKey => $itemVal) {
  535. $unitName = $itemVal['unitName'] ?? '';
  536. $unitPrice = $itemVal['unitPrice'] ? floatval($itemVal['unitPrice']) : 0;
  537. $printProduct[] = [
  538. 'name' => $itemVal['name'] ?? '',
  539. 'num' => $itemVal['num'] . $unitName . '*' . $unitPrice,
  540. 'price' => floatval($itemVal['price']),
  541. ];
  542. }
  543. }
  544. $orderGoodsList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  545. if (!empty($orderGoodsList)) {
  546. foreach ($orderGoodsList as $itemKey => $itemVal) {
  547. $unitName = $itemVal['unitName'] ?? '份';
  548. $unitPrice = $itemVal['unitPrice'] ? floatval($itemVal['unitPrice']) : 0;
  549. $printProduct[] = [
  550. 'name' => $itemVal['name'] ?? '',
  551. 'num' => $itemVal['num'] . $unitName . '*' . $unitPrice,
  552. 'price' => floatval($itemVal['price']),
  553. ];
  554. }
  555. }
  556. $sendNum = $order['sendNum'] ?? '';
  557. //退款记录
  558. $refundList = [];
  559. $printData = [
  560. 'address' => '',
  561. 'sendCost' => $order->sendCost ?? '0.00',
  562. 'prePrice' => $order->prePrice ?? '0.00',
  563. 'orderPrice' => $order->orderPrice ?? '0',
  564. 'discountAmount' => $order->discountAmount ?? '0.00',
  565. 'realPrice' => $order->realPrice ?? '0.00',
  566. 'refundPrice' => $order->refundPrice ?? '0.00',
  567. 'debt' => $order->debt ?? 0,
  568. 'orderSn' => $order->orderSn ?? '',
  569. 'date' => $order->addTime ?? '',
  570. 'remark' => $order->remark ?? '',
  571. 'custom' => [
  572. 'customName' => $order->customName ?? '',
  573. 'customMobile' => $order->customMobile ?? '',
  574. 'fullAddress' => $order->fullAddress ?? '',
  575. ],
  576. 'product' => $printProduct,
  577. 'refund' => $refundList,
  578. 'sendNum' => $sendNum,
  579. 'debtAmount' => $debtAmount,
  580. ];
  581. return $printData;
  582. }
  583. public static function printGroup($current, $content)
  584. {
  585. //58mm的机器,一行打印16个汉字,32个字母
  586. $name = $current['name'] ?? '';
  587. $content .= $name . '<BR>';
  588. $name = str_repeat(' ', 10);
  589. $productNum = $current['num'] ?? '';
  590. $blankNum = bcsub(12, strlen($productNum));
  591. if ($blankNum > 0) {
  592. $productNum = $productNum . str_repeat(' ', $blankNum);
  593. }
  594. $productPrice = $current['price'] ?? '';
  595. $blankNum = bcsub(7, strlen($productPrice));
  596. if ($blankNum > 0) {
  597. $productPrice = $productPrice . str_repeat(' ', $blankNum);
  598. }
  599. $content .= $name . " " . $productNum . ' ' . $productPrice . '<BR>';
  600. return $content;
  601. }
  602. }