OrderClass.php 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  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\order\classes\CheckOrderClass;
  16. use bizGhs\product\classes\ProductClass;
  17. use bizGhs\stat\classes\StatYjClass;
  18. use bizGhs\stock\classes\StockRecordClass;
  19. use bizGhs\ws\services\WsService;
  20. use bizHd\custom\classes\CustomClass;
  21. use bizHd\merchant\classes\SjClass;
  22. use bizHd\order\classes\OrderItemClass;
  23. use bizHd\refund\classes\HdRefundClass;
  24. use bizHd\shop\classes\MainClass;
  25. use bizHd\shop\classes\ShopMoneyChangeClass;
  26. use bizHd\stat\classes\StatIncomeClass;
  27. use bizHd\stat\classes\StatOrderClass;
  28. use bizHd\user\classes\UserClass;
  29. use bizHd\work\classes\WorkClass;
  30. use bizHd\wx\classes\WxOpenClass;
  31. use common\components\dict;
  32. use common\components\imgUtil;
  33. use common\components\miniUtil;
  34. use common\components\noticeUtil;
  35. use common\components\orderSn;
  36. use common\components\printUtil;
  37. use common\components\util;
  38. use Yii;
  39. use bizHd\base\classes\BaseClass;
  40. use common\components\lakala\Lakala;
  41. class OrderClass extends BaseClass
  42. {
  43. public static $baseFile = '\bizHd\order\models\Order';
  44. //已取消
  45. const ORDER_STATUS_CANCEL = 5;
  46. //完成
  47. const ORDER_STATUS_COMPLETE = 4;
  48. //配送中
  49. const ORDER_STATUS_SENDING = 3;
  50. //待配送
  51. const ORDER_STATUS_UN_SEND = 2;
  52. //待付款
  53. const ORDER_STATUS_UN_PAY = 1;
  54. //订单总流程数
  55. const ORDER_TOTAL_FLOW = 4;
  56. //未确认配送方式
  57. const SEND_TYPE_UNKNOWN = 0;
  58. //自取
  59. const SEND_TYPE_NO = 1;
  60. //自己送
  61. const SEND_TYPE_MYSELF = 2;
  62. //快递送
  63. const SEND_TYPE_THIRD = 3;
  64. //正常订单
  65. const REFUND_NO = 0;
  66. //已退款订单
  67. const REFUND_YES = 1;
  68. //送达时间段
  69. public static $reachPeriod = [0 => '上午', 1 => '下午', 2 => '晚上'];
  70. //优惠金额
  71. public static $randDiscount = [
  72. 50 => [1, 3],
  73. 100 => [5, 9],
  74. 300 => [10, 15],
  75. 500 => [16, 18],
  76. 1000 => [18, 30],
  77. 20000 => [90, 100],
  78. ];
  79. /**
  80. * 售后付款单是否已经充值过了 ssh 20250801
  81. * @param $order
  82. * @param $set false 判断是否充值 true 标记为充值
  83. */
  84. public static function shOrderRecharge($order, $set = false)
  85. {
  86. $orderId = $order->id;
  87. $cacheKey = "sh_order_recharge_" . $orderId;
  88. if ($set) {
  89. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  90. } else {
  91. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  92. if (!empty($has)) {
  93. util::fail('已经充值过了,请勿重复操作');
  94. }
  95. }
  96. }
  97. //因为开负数订单时引导库存变化 ssh 20250731
  98. public static function shPayChange($order, $shop, $staff, $originOrder = null)
  99. {
  100. $forward = $order['forward'] ?? 0;
  101. if ($forward == 0) {
  102. return false;
  103. }
  104. $forwardStock = $order['forwardStock'] ?? 0;
  105. $orderSn = $order['orderSn'] ?? '';
  106. $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  107. $orderGoodsList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  108. if (empty($orderItemList) && empty($orderGoodsList)) {
  109. return false;
  110. }
  111. $shopId = $shop->id ?? 0;
  112. $sjId = $shop->sjId ?? 0;
  113. $adminId = $staff->adminId;
  114. $staffName = $staff->name ?? '';
  115. $mainId = $shop->mainId;
  116. if (!empty($orderItemList)) {
  117. $itemInfo = [];
  118. $ids = array_column($orderItemList, 'itemId');
  119. $infoList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  120. foreach ($orderItemList as $orderItem) {
  121. $unitType = $orderItem['unitType'] ?? 0;
  122. $num = $orderItem['num'] ?? 0;
  123. $productId = $orderItem['itemId'] ?? 0;
  124. $info = $infoList[$productId] ?? [];
  125. $stock = $info['stock'] ?? 0;
  126. $ratio = $info['ratio'] ?? 20;
  127. $map = ProductClass::formatStock($stock, $ratio);
  128. $bigNum = $map['bigNum'] ?? 0;
  129. $smallNum = $map['smallNum'] ?? 0;
  130. $num = $forwardStock == 0 ? $num * 2 : $num;
  131. if ($unitType == 0) {
  132. $bigNum = $bigNum + $num;
  133. } else {
  134. $smallNum = $smallNum + $num;
  135. }
  136. $itemInfo[] = ['productId' => $productId, 'bigNum' => $bigNum, 'smallNum' => $smallNum];
  137. }
  138. $remark = $forwardStock == 0 ? '开负数订单,退货并退款' : '开负数订单,只退款';
  139. $itemData = [
  140. 'remark' => $remark,
  141. 'itemInfo' => $itemInfo,
  142. 'sjId' => $sjId,
  143. 'shopId' => $shopId,
  144. 'adminId' => $adminId,
  145. 'staffName' => $staffName,
  146. ];
  147. CheckOrderClass::opOrder($itemData);
  148. }
  149. if (!empty($orderGoodsList)) {
  150. foreach ($orderGoodsList as $orderGoods) {
  151. $goodsId = $orderGoods['goodsId'] ?? 0;
  152. $num = $orderGoods['num'] ?? 0;
  153. $num = $forwardStock == 0 ? $num * 2 : $num;
  154. $ret = \bizHd\goods\classes\GoodsClass::addStock($goodsId, $mainId, $num);
  155. $oldStock = $ret['oldStock'] ?? 0;
  156. $newStock = $ret['newStock'] ?? 0;
  157. $recordData = [];
  158. $recordData['sjId'] = $sjId;
  159. $recordData['shopId'] = $shopId;
  160. $recordData['mainId'] = $mainId;
  161. $recordData['orderSn'] = '';
  162. $recordData['goodsId'] = $goodsId;
  163. $recordData['goodsNum'] = $num;
  164. $recordData['oldStock'] = $oldStock;
  165. $recordData['newStock'] = $newStock;
  166. $recordData['relateName'] = $staffName;
  167. GoodsStockRecordClass::pdGoods($recordData);
  168. }
  169. }
  170. if (is_object($order) && !empty($originOrder)) {
  171. //建立关系
  172. $originOrder->hasForward = 1;
  173. $originOrder->save();
  174. $orderId = $originOrder->id ?? 0;
  175. $orderSn = $originOrder->orderSn ?? '';
  176. $shOrderId = $order->id ?? 0;
  177. $shOrderSn = $order->orderSn ?? '';
  178. $map = ['orderId' => $orderId, 'orderSn' => $orderSn, 'shOrderId' => $shOrderId, 'shOrderSn' => $shOrderSn];
  179. OrderForwardClass::add($map, true);
  180. }
  181. return true;
  182. }
  183. /**
  184. * @param $order
  185. * @param $mainId
  186. * @return array
  187. * $shAddPay 0走正常流程售后,1走售后付款单
  188. * $shAddPayReason 走售后付款单的原因:0、售后金额大于剩余欠款(剩余欠款可能没有了,可能还有);1、可售后时间到了
  189. */
  190. public static function ifShPay($order, $main, $refundAmount = 0)
  191. {
  192. $shAddPay = 0;
  193. $shAddPayReason = 0;
  194. $payStatus = $order['payStatus'] ?? 0;
  195. if ($payStatus == 1) {
  196. if ($order['payWay'] == 3) {
  197. if ($order['remainDebtPrice'] <= 0) {
  198. //不管是否要售后,没有剩余欠款了,只能走开负数订单模式
  199. $shAddPay = 1;
  200. } else {
  201. if ($refundAmount > 0 && $refundAmount > $order['remainDebtPrice']) {
  202. //如果需要售后,并且售后金额大于剩余欠款,走开负数订单模式
  203. $shAddPay = 1;
  204. }
  205. }
  206. }
  207. $cRet = OrderClass::couldRefund($order, $main);
  208. $could = $cRet['could'];
  209. if (!$could) {
  210. //可售后时间到了
  211. $shAddPay = 1;
  212. $shAddPayReason = 1;
  213. }
  214. }
  215. return ['shAddPay' => $shAddPay, 'shAddPayReason' => $shAddPayReason];
  216. }
  217. //订单是否过了可以售后的时间 ssh 20250730
  218. // $could false 过了售后时间,不能售后,true可以
  219. public static function couldRefund($order, $main)
  220. {
  221. $refundLimit = $main->refundLimit ?? 0;
  222. $payTime = $order['payTime'];
  223. $currentPayTime = strtotime($payTime);
  224. $addDateTime = $refundLimit * 86400;
  225. $couldRefundTime = $currentPayTime + $addDateTime;
  226. $now = time();
  227. $could = $couldRefundTime > $now;
  228. return ['could' => $could];
  229. }
  230. public static function valid($order, $mainId)
  231. {
  232. if (!isset($order->mainId) || $order->mainId != $mainId) {
  233. Yii::info(json_encode($order));
  234. Yii::info('mainId: ' . $mainId);
  235. util::fail('无法访问的订单');
  236. }
  237. return true;
  238. }
  239. //添加订单 ssh 2019.12.5
  240. public static function addOrder($data)
  241. {
  242. $data['orderSn'] = $data['orderSn'] ?? orderSn::getOrderSn();
  243. $data['payStatus'] = $data['payStatus'] ?? 0;
  244. $shopId = $data['shopId'] ?? 0;
  245. //累计订单增加
  246. $shop = ShopClass::getLockById($shopId);
  247. if (empty($shop)) {
  248. util::fail('没有找到门店信息54');
  249. }
  250. $mainId = $shop->mainId ?? 0;
  251. $main = MainClass::getLockById($mainId);
  252. if (empty($main)) {
  253. util::fail('没有找到main信息');
  254. }
  255. $main->unPayOrder += 1;
  256. $main->totalOrder += 1;
  257. $main->save();
  258. $address = $data['address'] ?? '';
  259. $floor = $data['floor'] ?? '';
  260. if (isset($data['fullAddress']) == false || empty($data['fullAddress'])) {
  261. $data['fullAddress'] = $address . $floor;
  262. }
  263. //非自取订单考虑配送时间
  264. $data['reachDate'] = isset($data['reachDate']) && !empty($data['reachDate']) ? $data['reachDate'] : date("Y-m-d");
  265. $sendType = $data['sendType'] ?? 0;
  266. if ($sendType != 1) {
  267. if (isset($data['reachPeriod']) == false || empty($data['reachPeriod'])) {
  268. util::fail('请选择配送时间');
  269. }
  270. $data['reachTime'] = strtotime($data['reachDate'] . ' ' . $data['reachPeriod']);
  271. }
  272. //将花店每月的总订单数作为编号
  273. $riseNum = StatOrderCountClass::addOrder($shop, $main);
  274. $data['sendNum'] = date("d") . $riseNum;
  275. $data['totalFlow'] = OrderClass::ORDER_TOTAL_FLOW;
  276. return self::add($data, true);
  277. }
  278. public static function getByOrderSn($orderSn)
  279. {
  280. return self::getByCondition(['orderSn' => $orderSn]);
  281. }
  282. //评价 ssh 2019.12.16
  283. public static function comment($data)
  284. {
  285. $id = $data['id'];
  286. unset($data['id']);
  287. return self::updateById($id, $data);
  288. }
  289. public static function getFullInfo($id)
  290. {
  291. $order = self::getById($id);
  292. if (empty($order)) {
  293. return [];
  294. }
  295. $sn = $order['orderSn'] ?? '';
  296. $order['goodsInfoList'] = OrderGoodsClass::getListBySn($sn);
  297. $order['itemInfoList'] = OrderItemClass::getListBySn($sn);
  298. $workList = WorkClass::getAllByCondition(['orderId' => $id], null, '*');
  299. if (!empty($workList)) {
  300. foreach ($workList as $key => $work) {
  301. $shortCover = $work['cover'] ?? '';
  302. $workList[$key]['shortCover'] = $shortCover;
  303. $workList[$key]['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  304. }
  305. }
  306. $order['workList'] = $workList;
  307. $debtPrice = $order['debtPrice'] ?? 0;
  308. $remainDebtPrice = $order['remainDebtPrice'] ?? 0;
  309. $orderId = $order['id'] ?? 0;
  310. $osList = [];
  311. if ($debtPrice > $remainDebtPrice) {
  312. $osList = OrderSettleClass::getAllByCondition(['orderId' => $orderId, 'status' => 1], null, '*', null, true);
  313. }
  314. //结账记录关系
  315. $order['orderSettleList'] = $osList;
  316. $order['today'] = date("Y-m-d");
  317. $order['tomorrow'] = date("Y-m-d", strtotime("+1 day"));
  318. return $order;
  319. }
  320. //订单
  321. public static function getOrderById($id)
  322. {
  323. $order = self::getById($id);
  324. if (empty($order)) {
  325. return [];
  326. }
  327. $sn = $order['orderSn'] ?? '';
  328. $order['goodsInfoList'] = OrderGoodsClass::getListBySn($sn);
  329. return $order;
  330. }
  331. //根据订单查询 ssh 2020.1.4
  332. public static function getOrderBySn($orderSn)
  333. {
  334. $order = self::getByCondition(['orderSn' => $orderSn]);
  335. if (empty($order)) {
  336. return [];
  337. }
  338. $id = $order['id'];
  339. $order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
  340. return $order;
  341. }
  342. //返回随机优惠金额 ssh 2019.9.12
  343. public static function getRandDiscount($amount)
  344. {
  345. if ($amount <= 0) {
  346. return 0;
  347. }
  348. $randDiscount = self::$randDiscount;
  349. krsort($randDiscount);
  350. $rand = 0;
  351. foreach ($randDiscount as $currentAmount => $val) {
  352. if ($amount >= $currentAmount) {
  353. $rand = rand($val[0], $val[1]);
  354. break;
  355. }
  356. }
  357. return $rand / 10;
  358. }
  359. //第三方支付后回调处理流程 ssh 2021.4.30
  360. public static function thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId)
  361. {
  362. $order = self::getByCondition(['orderSn' => $orderSn], true);
  363. if (empty($order)) {
  364. noticeUtil::push('散客下单,付款成功,支付回调,单号:' . $orderSn . ' 金额:' . $totalFee . ' 回调id:' . $transactionId . ' 附件:' . $attach . ',没有找到订单', '15280215347');
  365. $msg = "没有找到零售订单 orderSn:{$orderSn}";
  366. Yii::info($msg);
  367. util::fail($msg);
  368. }
  369. if ($order->mainPay != $totalFee) {
  370. noticeUtil::push("散客下单,付款成功,支付回调错误,零售订单金额与回调通知金额不一致 orderSn:{$orderSn} {$order->mainPay} {$totalFee} 附件:{$attach}", '15280215347');
  371. $msg = "零售订单金额与回调通知金额不一致 orderSn:{$orderSn} {$order->mainPay} {$totalFee}";
  372. Yii::info($msg);
  373. util::fail($msg);
  374. }
  375. $id = $order->id;
  376. $order = self::getLockById($id);
  377. $date = date("Y-m-d H:i:s");
  378. $order->payTime = $date;
  379. $order->thirdNo = $transactionId;
  380. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  381. $order->save();
  382. self::payAfter($order, $payWay);
  383. }
  384. //订单完成 ssh 2021.4.20
  385. public static function payAfter($order, $payWay)
  386. {
  387. if (empty($order)) {
  388. util::fail('没有找到订单');
  389. }
  390. if (!isset($order->status)) {
  391. util::fail('没有找到订单的状态');
  392. }
  393. $orderSn = $order->orderSn ?? '';
  394. if ($order->status == self::ORDER_STATUS_CANCEL) {
  395. $shopId = $order->shopId;
  396. $shop = ShopClass::getById($shopId, true);
  397. if (empty($shop)) {
  398. noticeUtil::push('注意,零售订单:' . $orderSn . ',付款成功但订单已取消,没有找到门店,关键词 cancel_get_money', '15280215347');
  399. util::stop("SUCCESS");
  400. }
  401. Yii::$app->params['errorReport'] = 1;
  402. try {
  403. //恢复取消的订单
  404. self::recoverOrderToPay($order);
  405. noticeUtil::push('注意,零售订单:' . $orderSn . ',付款成功,取消的订单,已恢复 SUCCESS', '15280215347');
  406. } catch (\Exception $exception) {
  407. $ret = HdRefundClass::onlyRefundAmount($shop, $order);
  408. if ($ret['status'] == 0) {
  409. $errMsg = $exception->getMessage();
  410. noticeUtil::push('注意,零售订单:' . $orderSn . ',付款成功但订单取消。订单没有恢复成功,原因' . $errMsg . ',也没有退款成功。请手动处理。关键词 cancel_get_money', '15280215347');
  411. }
  412. util::stop("SUCCESS");
  413. }
  414. }
  415. if ($order->payStatus == 1) {
  416. noticeUtil::push('注意,零售订单:' . $orderSn . ',已经付过款了,无需重复请求和操作', '15280215347');
  417. util::fail('订单已经付过款了');
  418. }
  419. $orderId = $order->id ?? 0;
  420. $customId = $order->customId ?? 0;
  421. if ($order->fromType == 3) {
  422. //客服下的单要配送流程
  423. $order->status = self::ORDER_STATUS_UN_SEND;
  424. } else {
  425. $order->status = self::ORDER_STATUS_COMPLETE;
  426. }
  427. $order->payWay = $payWay;
  428. $order->payStatus = 1;
  429. $order->payTime = date("Y-m-d H:i:s");
  430. $order->stockChange = 1;
  431. $order->save();
  432. \bizMall\order\classes\OrderGoodsClass::stockChange($order);
  433. $realPrice = $order->realPrice ?? 0;
  434. $shopId = $order->shopId;
  435. $shop = ShopClass::getLockById($shopId);
  436. if (empty($shop)) {
  437. util::fail('没有找到门店,编号5115');
  438. }
  439. $mainId = $shop->mainId ?? 0;
  440. $main = MainClass::getLockById($mainId);
  441. if (empty($main)) {
  442. util::fail('没有main信息,编号3096');
  443. }
  444. $main->unSendOrder += 1;
  445. $main->unPayOrder -= 1;
  446. $currentTotalIncome = bcadd($main->totalIncome, $realPrice, 2);
  447. $main->totalIncome = $currentTotalIncome;
  448. $main->save();
  449. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  450. $shopAdminId = $order->shopAdminId ?? 0;
  451. $shopAdminName = $order->shopAdminName ?? '';
  452. $sjId = $order->sjId;
  453. $fromType = $order->fromType ?? 1;
  454. $event = !empty($shopAdminId) ? '员工开单' : '客户下单';
  455. $capital = [
  456. 'capitalType' => $capitalType,
  457. 'relateId' => $orderId,
  458. 'io' => 1,
  459. 'totalIncome' => $currentTotalIncome,
  460. 'payWay' => $payWay,
  461. 'event' => $event,
  462. 'sjId' => $sjId,
  463. 'shopId' => $shopId,
  464. 'shopAdminId' => $shopAdminId,
  465. 'shopAdminName' => $shopAdminName,
  466. 'amount' => $realPrice,
  467. 'fromType' => $fromType,
  468. 'mainId' => $mainId,
  469. ];
  470. ShopCapitalClass::addCapital($capital);
  471. //每天和每月收入增加
  472. //StatIncomeClass::updateOrInsert($main, $shop, $realPrice);
  473. //今日订单+1
  474. //StatOrderClass::updateOrInsert($main, $shop);
  475. //销售收入增加
  476. //StatSaleClass::replace($main, $shop, $realPrice);
  477. //各渠道收入金额统计
  478. //StatKdClass::replace($shop, $realPrice, $payWay);
  479. //当天同个人同地址的订单汇总
  480. $sameDate = date("Y_m_d");
  481. $sameAddress = $order->showAddress ?? '';
  482. $addressMd5 = md5($sameAddress);
  483. $sameKey = $customId . '_' . $addressMd5 . '_' . $sameDate . '_retail';
  484. $sameString = Yii::$app->redis->executeCommand('GET', [$sameKey]);
  485. if (!empty($sameString)) {
  486. $newString = $sameString . ',' . $orderId;
  487. $newIdsArray = explode(',', $newString);
  488. if (count($newIdsArray) <= 90) {
  489. Yii::$app->redis->executeCommand('SETEX', [$sameKey, 186400, $newString]);
  490. foreach ($newIdsArray as $currentOrderId) {
  491. OrderClass::updateById($currentOrderId, ['sameTimeIds' => $newString]);
  492. }
  493. //noticeUtil::push($sameKey . '' . $sameAddress . " 花掌柜当天汇总ids:" . $newString, '15280215347');
  494. }
  495. } else {
  496. Yii::$app->redis->executeCommand('SETEX', [$sameKey, 186400, $orderId]);
  497. $order->sameTimeIds = $orderId;
  498. $order->save();
  499. //noticeUtil::push($sameKey . '' . $sameAddress . " 花掌柜当天汇总ids:" . $orderId, '15280215347');
  500. }
  501. //客户在线支付下单增加商家可提现余额
  502. if (isset($order->onlinePay) && $order->onlinePay == dict::getDict('onlinePay', 'yes')) {
  503. $amount = $order->mainPay;
  504. ShopClass::customKdAddBalance($main, $shop, $amount, $order, $capitalType);
  505. }
  506. //客户使用余额付款
  507. if ($payWay == dict::getDict('payWay', 'balancePay')) {
  508. CustomClass::payToChangeBalance($order);
  509. }
  510. //有欠款时
  511. if ($payWay == dict::getDict('payWay', 'debtPay')) {
  512. if (isset($order->remainDebtPrice) && $order->remainDebtPrice > 0) {
  513. $newCustom = CustomClass::getLockById($customId);
  514. CustomClass::cgDebtAmountAdd($newCustom, $order);
  515. }
  516. }
  517. //全部现金付款余额增加
  518. if ($payWay == dict::getDict('payWay', 'cash')) {
  519. $moneyBalance = bcadd($main->money, $order->mainPay, 2);
  520. $main->money = $moneyBalance;
  521. $main->save();
  522. $moneyEvent = "客户现金下单" . floatval($order->mainPay) . "元(单号 {$order->orderSn})";
  523. $moneyRemark = '';
  524. $change = [
  525. 'relateId' => $orderId,
  526. 'amount' => $order->mainPay,
  527. 'balance' => $moneyBalance,
  528. 'io' => 1,
  529. 'mainId' => $mainId,
  530. 'capitalType' => $capitalType,
  531. 'ptStyle' => dict::getDict('ptStyle', 'hd'),
  532. 'event' => $moneyEvent,
  533. 'remark' => $moneyRemark,
  534. ];
  535. ShopMoneyChangeClass::addData($change);
  536. } else {
  537. //部分现金付款
  538. $orderCash = $order->cash ?? 0;
  539. $orderCash = floatval($orderCash);
  540. if ($orderCash > 0) {
  541. $moneyBalance = bcadd($main->money, $orderCash, 2);
  542. $main->money = $moneyBalance;
  543. $main->save();
  544. $moneyEvent = "客户部分现金付款{$orderCash}元(单号 {$order->orderSn})";
  545. $moneyRemark = '';
  546. $change = [
  547. 'relateId' => $orderId,
  548. 'amount' => $orderCash,
  549. 'balance' => $moneyBalance,
  550. 'io' => 1,
  551. 'mainId' => $mainId,
  552. 'capitalType' => $capitalType,
  553. 'ptStyle' => dict::getDict('ptStyle', 'hd'),
  554. 'event' => $moneyEvent,
  555. 'remark' => $moneyRemark,
  556. ];
  557. ShopMoneyChangeClass::addData($change);
  558. }
  559. }
  560. }
  561. //转化出送到时间 ssh 2020.3.15
  562. public static function getReachTime($order)
  563. {
  564. $reachTime = '';
  565. if (isset($order['reachDate']) && !empty($order['reachDate'])) {
  566. $prev = date("n-j", strtotime($order['reachDate']));
  567. $periodData = self::$reachPeriod;
  568. $periodKey = $order['reachPeriod'];
  569. $period = isset($periodData[$periodKey]) ? $periodData[$periodKey] : '上午';
  570. $reachTime = $prev . ' ' . $period;
  571. }
  572. return $reachTime;
  573. }
  574. //支付成功获取unionId ssh 2020.5.12
  575. public static function payToUpdateUnionId($merchant, $merchantExtend, $orderSn, $user)
  576. {
  577. $mcId = $merchantExtend['wxPayMerchantId'];
  578. $miniOpenId = isset($user['miniOpenId']) ? $user['miniOpenId'] : '';
  579. $unionId = isset($user['unionId']) ? $user['unionId'] : '';
  580. $userId = $user['id'];
  581. if (empty($unionId)) {
  582. $unionId = miniUtil::getPaidUnionId($merchant, $miniOpenId, $mcId, (string)$orderSn, 0);
  583. if (!empty($unionId)) {
  584. $findUser = UserClass::getByUnionId($unionId);
  585. if (empty($findUser)) {
  586. UserClass::updateByCondition(['id' => $userId], ['unionId' => $unionId]);
  587. } else {
  588. UserClass::mergeUser($findUser, $user);
  589. }
  590. }
  591. }
  592. }
  593. //订单取消 ssh 20220516
  594. public static function setExpire($order, $force = false)
  595. {
  596. $now = time();
  597. if ($order->deadline > $now && $force == false) {
  598. return false;
  599. }
  600. if ($order->status != 1) {
  601. return false;
  602. }
  603. $order->status = 5;
  604. $order->cancelTime = date("Y-m-d H:i:s");
  605. $order->save();
  606. //暂时只考虑花材库存的回滚。商品只有下单成功了才会占用库存。
  607. $orderSn = $order->orderSn ?? '';
  608. $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  609. if (!empty($itemList)) {
  610. foreach ($itemList as $item) {
  611. $ptItemId = $item->ptItemId ?? 0;
  612. $sjId = $item->sjId ?? 0;
  613. $shopId = $item->shopId ?? 0;
  614. $mainId = $item->mainId ?? 0;
  615. $ratio = $item->ratio ?? 20;
  616. $unitType = $item->unitType ?? 0;
  617. if ($unitType == 0) {
  618. $bigNum = $item->num;
  619. $smallNum = 0;
  620. } else {
  621. $bigNum = 0;
  622. $smallNum = $item->num;
  623. }
  624. $itemId = $item->itemId ?? 0;
  625. $stockInfo = ProductClass::addStock($itemId, $bigNum, $smallNum);
  626. $recordData = [];
  627. $recordData['sjId'] = $sjId;
  628. $recordData['shopId'] = $shopId;
  629. $recordData['mainId'] = $mainId;
  630. $recordData['itemId'] = $ptItemId;
  631. $recordData['itemNum'] = ProductClass::mergeItemNum($bigNum, $smallNum, $ratio);
  632. $recordData['oldStock'] = $stockInfo['oldStock'];
  633. $recordData['newStock'] = $stockInfo['newStock'];
  634. $recordData['productId'] = $itemId;
  635. $recordData['orderSn'] = $orderSn;
  636. $recordData['relateName'] = '系统';
  637. StockRecordClass::addSellStockOrderCancelRecord($recordData);
  638. }
  639. }
  640. $shopId = $order->shopId ?? 0;
  641. $shop = ShopClass::getById($shopId, true);
  642. if (!empty($shop)) {
  643. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  644. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  645. $params = [
  646. 'appid' => 'OP00002119',
  647. 'serial_no' => '018b08cfddbd',
  648. 'merchant_no' => $shop->lklSjNo,
  649. 'term_no' => $shop->lklScanTermNo,
  650. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  651. 'lklCertificatePath' => $lklCertificatePath,
  652. ];
  653. $laResource = new Lakala($params);
  654. $closeParams = [
  655. 'orderSn' => $orderSn,
  656. ];
  657. $response = $laResource->close($closeParams);
  658. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  659. //noticeUtil::push('零售订单:' . $orderSn . ',关单没有成功。', '15280215347');
  660. } else {
  661. //noticeUtil::push('零售订单:' . $orderSn . ',关单成功。', '15280215347');
  662. }
  663. }
  664. }
  665. // 恢复订单 -- 即:把订单的状态从取消状态变成待付款状态
  666. public static function recoverOrderToPay($order)
  667. {
  668. $now = time();
  669. $order->status = 1;
  670. $order->deadline = $now + 86400;
  671. $order->save();
  672. // 重新占用库存(与取消订单时的库存回滚相反)
  673. $itemList = OrderItemClass::getAllByCondition(['orderSn' => $order->orderSn], null, '*', null, true);
  674. if (!empty($itemList)) {
  675. foreach ($itemList as $item) {
  676. $ptItemId = $item->ptItemId ?? 0;
  677. $sjId = $item->sjId ?? 0;
  678. $shopId = $item->shopId ?? 0;
  679. $mainId = $item->mainId ?? 0;
  680. $ratio = $item->ratio ?? 20;
  681. $unitType = $item->unitType ?? 0;
  682. if ($unitType == 0) {
  683. $bigNum = $item->num;
  684. $smallNum = 0;
  685. } else {
  686. $bigNum = 0;
  687. $smallNum = $item->num;
  688. }
  689. $itemId = $item->itemId ?? 0;
  690. // 重新扣减库存(占用库存)
  691. $stockInfo = ProductClass::decreaseStock($itemId, $bigNum, $smallNum, true);
  692. $recordData = [];
  693. $recordData['sjId'] = $sjId;
  694. $recordData['shopId'] = $shopId;
  695. $recordData['mainId'] = $mainId;
  696. $recordData['itemId'] = $ptItemId;
  697. $recordData['itemNum'] = ProductClass::mergeItemNum($bigNum, $smallNum, $ratio);
  698. $recordData['oldStock'] = $stockInfo['oldStock'];
  699. $recordData['newStock'] = $stockInfo['newStock'];
  700. $recordData['productId'] = $itemId;
  701. $recordData['orderSn'] = $order->orderSn;
  702. $recordData['relateName'] = $order->customName ?? '';
  703. StockRecordClass::hdKdAddRecord($recordData);
  704. }
  705. }
  706. return true;
  707. }
  708. // 扣库存
  709. protected static function decGoodsStock($orderGoods)
  710. {
  711. foreach ($orderGoods as $goods) {
  712. GoodsClass::counters([
  713. 'stock' => -$goods['num']
  714. ], [
  715. 'and',
  716. ['id' => $goods['goodsId']],
  717. ['<>', 'stock', Goods::FULL_STOCK]
  718. ]);
  719. }
  720. }
  721. //云打印 ssh 20210709
  722. public static function onlinePrint($order, $must = false, $port = 'front')
  723. {
  724. if (empty($order)) {
  725. return false;
  726. }
  727. if (!$must) {
  728. if ($order->needPrint != dict::getDict('needPrint', 'need')) {
  729. return false;
  730. }
  731. if ($order->payStatus != 1) {
  732. return false;
  733. }
  734. }
  735. if ($order->forward == 1) {
  736. //售后付款单暂时不能打印
  737. return false;
  738. }
  739. $shopId = $order->shopId ?? 0;
  740. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  741. $printSn = $ext['printSn'] ?? '';
  742. if ($port == 'make') {
  743. $printSn = $ext['makePrintSn'] ?? '';
  744. if ($order->fromType == 4) {
  745. $printSn = $ext['mtPrintSn'] ?? '';
  746. }
  747. $workList = WorkClass::getAllByCondition(['orderId' => $order->id], null, '*', null, true);
  748. $hasSh = 0;
  749. if (!empty($workList)) {
  750. foreach ($workList as $work) {
  751. $sh = $work->sh ?? 0;
  752. if ($sh == 1) {
  753. $hasSh = 1;
  754. }
  755. }
  756. }
  757. if ($hasSh == 1) {
  758. $printSn = $ext['printSn'] ?? '';
  759. }
  760. }
  761. if (empty($printSn)) {
  762. return false;
  763. }
  764. $order->printNum += 1;
  765. $order->save();
  766. $customId = $order->customId ?? 0;
  767. $custom = CustomClass::getById($customId);
  768. $debtAmount = $custom['debtAmount'] ?? 0;
  769. $respond = self::getPrintData($order, $debtAmount);
  770. $fromType = $order->fromType ?? dict::getDict('fromType', 'shop');
  771. $fromTypeMap = dict::getDict('fromTypeMap');
  772. $fromTypeName = $fromTypeMap[$fromType] ?? '门店';
  773. //客服下的单则显示客服号和客户名称
  774. if ($fromType == dict::getDict('fromType', 'friend')) {
  775. $staffName = $order->shopAdminName ?? '';
  776. $bookName = $order->bookName ?? '';
  777. $fromTypeName = $staffName . ' ' . $bookName;
  778. }
  779. $content = '';
  780. //$content .= "<CB>【零售】</CB><BR>";
  781. if ($fromType == dict::getDict('fromType', 'mt')) {
  782. $content .= '<B>美团 ' . $order->thirdSn . '</B><BR>';
  783. if (isset($order->goodsNum) && $order->goodsNum > 1) {
  784. $content .= '<B>美团 ' . $order->thirdSn . ' (' . $order->goodsNum . '份)</B><BR>';
  785. }
  786. $content .= '--------------------------------<BR>';
  787. $content .= date("Y-m-d", strtotime($order->addTime)) . '<BR>';
  788. } else {
  789. $content .= '<CB>' . $fromTypeName . ' ' . $respond['sendNum'] . '</CB><BR>';
  790. $content .= '--------------------------------<BR>';
  791. }
  792. $readPeriod = $order->reachPeriod ?? 0;
  793. if ($order->sendType == 1) {
  794. if (isset($order->reachDate) && !empty($order->reachDate) && $order->reachDate != '0000-00-00') {
  795. $currentReachDate = date("m-d", strtotime($order->reachDate));
  796. $content .= '<B>' . $currentReachDate . ' ' . $readPeriod . '前</B><BR>';
  797. $content .= '<B>到店自取</B><BR><BR>';
  798. } else {
  799. $content .= '<B>到店自取</B><BR><BR>';
  800. }
  801. } else {
  802. if ($order->sendType == 0) {
  803. $content .= '<B>送货上门</B><BR><BR>';
  804. } else if ($order->sendType == 2) {
  805. $content .= '<B>跑腿到付</B><BR><BR>';
  806. } else if ($order->sendType == 3) {
  807. $content .= '<B>物流到付</B><BR><BR>';
  808. } else if ($order->sendType == 4) {
  809. $content .= '<B>快递到付</B><BR><BR>';
  810. } else {
  811. $content .= '';
  812. }
  813. if (isset($order->reachDate) && !empty($order->reachDate) && $order->reachDate != '0000-00-00') {
  814. $currentReachDate = date("m-d", strtotime($order->reachDate));
  815. $content .= '<B>' . $currentReachDate . ' ' . $readPeriod . '前</B><BR><BR>';
  816. }
  817. }
  818. if (isset($order->receiveUserName) && !empty($order->receiveUserName)) {
  819. $content .= '收花人:<BR>';
  820. $content .= '<B>' . $order->receiveUserName . '</B><BR>';
  821. }
  822. if (isset($order->receiveMobile) && !empty($order->receiveMobile)) {
  823. $content .= '<B>' . $order->receiveMobile . '</B><BR><BR>';
  824. }
  825. if (isset($order->fullAddress) && !empty($order->fullAddress)) {
  826. $content .= '<B>' . $order->fullAddress . '(' . $order->showAddress . ')' . '</B><BR><BR>';
  827. }
  828. if (isset($order->cardInfo) && !empty($order->cardInfo)) {
  829. $content .= '<B>贺卡内容:' . $order->cardInfo . '</B><BR><BR>';
  830. }
  831. if ($order->anonymity == 1) {
  832. $content .= '<B>匿名派送!!</B><BR><BR>';
  833. } else {
  834. if (isset($order->bookMobile) && !empty($order->bookMobile)) {
  835. $bookName = $order->bookName ?? '';
  836. $bookMobile = $order->bookMobile ?? '';
  837. $content .= '订花人:<BR>';
  838. if (!empty($bookName)) {
  839. $content .= '<B>' . $bookName . '</B><BR>';
  840. }
  841. if (!empty($bookMobile)) {
  842. $content .= '<B>' . $bookMobile . '</B><BR>';
  843. }
  844. }
  845. }
  846. if (isset($respond['remark']) && !empty($respond['remark'])) {
  847. $content .= '<BR>';
  848. $content .= '备注:<BR>';
  849. $content .= '<B>' . $respond['remark'] . '</B><BR>';
  850. }
  851. $content .= '<BR>';
  852. $content .= '商品 数量/单价 金额 <BR>';
  853. $content .= '--------------------------------<BR>';
  854. if (isset($respond['product']) && !empty($respond['product'])) {
  855. foreach ($respond['product'] as $current) {
  856. $content = self::printGroup($current, $content);
  857. }
  858. $content .= '--------------------------------<BR>';
  859. }
  860. if (isset($respond['refund']) && !empty($respond['refund'])) {
  861. $content .= '<B>已退款:</B><BR>';
  862. foreach ($respond['refund'] as $current) {
  863. //58mm的机器,一行打印16个汉字,32个字母
  864. $name = $current['name'] ?? '';
  865. $content .= $name . '<BR>';
  866. $name = str_repeat(' ', 10);
  867. $productNum = $current['num'] ?? '';
  868. $blankNum = bcsub(12, strlen($productNum));
  869. if ($blankNum > 0) {
  870. $productNum = $productNum . str_repeat(' ', $blankNum);
  871. }
  872. $productPrice = $current['price'] ?? '';
  873. $blankNum = bcsub(7, strlen($productPrice));
  874. if ($blankNum > 0) {
  875. $productPrice = $productPrice . str_repeat(' ', $blankNum);
  876. }
  877. $content .= $name . " " . $productNum . ' ' . $productPrice . '<BR>';
  878. }
  879. $content .= '--------------------------------<BR>';
  880. }
  881. if (isset($order->goodsPrice) && $order->goodsPrice > 0) {
  882. $content .= '商品合计:' . floatval($order->goodsPrice) . '<BR>';
  883. }
  884. if (isset($respond['sendCost']) && $respond['sendCost'] > 0 && $order->sendType == 2) {
  885. $content .= '运费:' . floatval($respond['sendCost']) . '<BR>';
  886. }
  887. if (isset($order->serviceFee) && $order->serviceFee > 0) {
  888. $content .= '手续费:' . floatval($order->serviceFee) . '<BR>';
  889. }
  890. if (isset($order->labourCost) && $order->labourCost > 0) {
  891. $content .= '包装费:' . floatval($order->labourCost) . '<BR>';
  892. }
  893. if (isset($order->prePrice) && $order->prePrice > 0) {
  894. $content .= '总计:' . floatval($order->prePrice) . '<BR>';
  895. }
  896. if (isset($respond['discountAmount']) && !empty($respond['discountAmount']) && $respond['discountAmount'] > 0) {
  897. $content .= '优惠扣除:-' . floatval($respond['discountAmount']) . '<BR>';
  898. }
  899. $content .= '订单金额:' . floatval($respond['orderPrice']) . '<BR>';
  900. if (isset($respond['refundPrice']) && $respond['refundPrice'] > 0) {
  901. $content .= '退款金额:' . floatval($respond['refundPrice']) . '<BR>';
  902. }
  903. if (isset($respond['debt']) && $respond['debt'] == 1) {
  904. $content .= '实付金额:0<BR>';
  905. } else {
  906. $content .= '实付金额:' . floatval($respond['realPrice']) . '<BR>';
  907. }
  908. if (isset($order->remainDebtPrice) && $order->remainDebtPrice > 0) {
  909. $content .= '<B>待付尾款:' . floatval($order->remainDebtPrice) . '</B><BR>';
  910. }
  911. $shop = ShopClass::getById($shopId, true);
  912. $sjId = $shop->sjId ?? 0;
  913. $sj = SjClass::getById($sjId, true);
  914. $sjName = $sj->name ?? '';
  915. $shopName = $shop->shopName ?? '';
  916. $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  917. $content .= '--------------------------------<BR>';
  918. $content .= '订单日期:' . $order->addTime . '<BR>';
  919. $content .= '订单编号:' . $respond['orderSn'] . '<BR>';
  920. $content .= '门店名称:' . $currentName . '<BR>';
  921. $content .= "<BR>";
  922. $p = new printUtil($printSn);
  923. $orderSn = $order->orderSn ?? '';
  924. $workList = WorkClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  925. if (!empty($workList)) {
  926. $content .= "<BR>";
  927. $content .= '--------------------------------<BR>';
  928. foreach ($workList as $work) {
  929. $goodsSn = $work->goodsSn ?? '';
  930. $sn = $work->sn ?? '';
  931. $content .= '<B>制作号:' . $sn . '<B>';
  932. // 1-523 有-特殊符号,使用飞鹅自带的函数处理
  933. $content .= $p->bar_code($goodsSn);
  934. $content .= "<BR>";
  935. }
  936. }
  937. $p->printMsg($content);
  938. }
  939. //打印数据 ssh 20210702
  940. public static function getPrintData($order, $debtAmount)
  941. {
  942. $orderSn = $order->orderSn ?? '';
  943. $printProduct = [];
  944. $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  945. if (!empty($orderItemList)) {
  946. foreach ($orderItemList as $itemKey => $itemVal) {
  947. $unitName = $itemVal['unitName'] ?? '';
  948. $unitPrice = $itemVal['unitPrice'] ? floatval($itemVal['unitPrice']) : 0;
  949. $printProduct[] = [
  950. 'name' => $itemVal['name'] ?? '',
  951. 'num' => $itemVal['num'] . $unitName . '*' . $unitPrice,
  952. 'price' => floatval($itemVal['price']),
  953. ];
  954. }
  955. }
  956. $orderGoodsList = OrderGoodsClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  957. if (!empty($orderGoodsList)) {
  958. foreach ($orderGoodsList as $itemKey => $itemVal) {
  959. $unitName = $itemVal['unitName'] ?? '份';
  960. $unitPrice = $itemVal['unitPrice'] ? floatval($itemVal['unitPrice']) : 0;
  961. $printProduct[] = [
  962. 'name' => $itemVal['name'] ?? '',
  963. 'num' => $itemVal['num'] . $unitName . '*' . $unitPrice,
  964. 'price' => floatval($itemVal['price']),
  965. ];
  966. }
  967. }
  968. $sendNum = $order['sendNum'] ?? '';
  969. //退款记录
  970. $refundList = [];
  971. $printData = [
  972. 'address' => '',
  973. 'sendCost' => $order->sendCost ?? '0.00',
  974. 'prePrice' => $order->prePrice ?? '0.00',
  975. 'orderPrice' => $order->orderPrice ?? '0',
  976. 'discountAmount' => $order->discountAmount ?? '0.00',
  977. 'realPrice' => $order->realPrice ?? '0.00',
  978. 'refundPrice' => $order->refundPrice ?? '0.00',
  979. 'debt' => $order->debt ?? 0,
  980. 'orderSn' => $order->orderSn ?? '',
  981. 'date' => $order->addTime ?? '',
  982. 'remark' => $order->remark ?? '',
  983. 'custom' => [
  984. 'customName' => $order->customName ?? '',
  985. 'customMobile' => $order->customMobile ?? '',
  986. 'fullAddress' => $order->fullAddress ?? '',
  987. ],
  988. 'product' => $printProduct,
  989. 'refund' => $refundList,
  990. 'sendNum' => $sendNum,
  991. 'debtAmount' => $debtAmount,
  992. ];
  993. return $printData;
  994. }
  995. public static function printGroup($current, $content)
  996. {
  997. //58mm的机器,一行打印16个汉字,32个字母
  998. $name = $current['name'] ?? '';
  999. $content .= $name . '<BR>';
  1000. $name = str_repeat(' ', 10);
  1001. $productNum = $current['num'] ?? '';
  1002. $blankNum = bcsub(12, strlen($productNum));
  1003. if ($blankNum > 0) {
  1004. $productNum = $productNum . str_repeat(' ', $blankNum);
  1005. }
  1006. $productPrice = $current['price'] ?? '';
  1007. $blankNum = bcsub(7, strlen($productPrice));
  1008. if ($blankNum > 0) {
  1009. $productPrice = $productPrice . str_repeat(' ', $blankNum);
  1010. }
  1011. $content .= $name . " " . $productNum . ' ' . $productPrice . '<BR>';
  1012. return $content;
  1013. }
  1014. }