OrderClass.php 25 KB

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