OrderClass.php 26 KB

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