OrderItemClass.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. <?php
  2. namespace bizGhs\order\classes;
  3. use biz\product\classes\XjClass;
  4. use bizGhs\book\classes\BookItemClass;
  5. use bizGhs\custom\classes\CustomClass;
  6. use bizGhs\ghs\classes\GhsClass;
  7. use bizGhs\product\classes\ProductClass;
  8. use bizGhs\stock\classes\StockRecordClass;
  9. use bizHd\purchase\classes\PurchaseClass;
  10. use bizHd\purchase\classes\PurchaseItemClass;
  11. use common\components\dict;
  12. use common\components\imgUtil;
  13. use common\components\noticeUtil;
  14. use common\components\orderSn;
  15. use common\components\util;
  16. use Yii;
  17. use bizGhs\base\classes\BaseClass;
  18. class OrderItemClass extends BaseClass
  19. {
  20. public static $baseFile = '\bizGhs\order\models\OrderItem';
  21. //预订单删除花材项 ssh 20240123
  22. public static function delBookItem($order, $smallId, $params = [])
  23. {
  24. $son = self::getById($smallId, true);
  25. if (empty($son)) {
  26. util::fail('没有找到花材');
  27. }
  28. $ptItemId = $son->itemId ?? 0;
  29. $son->delete();
  30. $productId = $son->productId ?? 0;
  31. $cgId = $order->purchaseId ?? 0;
  32. $cg = PurchaseClass::getById($cgId, true);
  33. if (empty($cg)) {
  34. util::fail('没有采购单');
  35. }
  36. $cgOrderSn = $cg->orderSn ?? '';
  37. $cgList = PurchaseItemClass::getAllByCondition(['orderSn' => $cgOrderSn], null, '*', null, true);
  38. if (empty($cgList)) {
  39. util::fail('没有采购的花材');
  40. }
  41. $cgHasDelOk = 0;
  42. foreach ($cgList as $cgIt) {
  43. $itemId = $cgIt->itemId ?? 0;
  44. if ($itemId == $ptItemId) {
  45. $cgIt->delete();
  46. $cgHasDelOk = 1;
  47. }
  48. }
  49. if ($cgHasDelOk == 0) {
  50. util::fail('删除失败');
  51. }
  52. //删除预订
  53. $num = $son->xhNum ?? 0;
  54. $delData = [['productId' => $productId, 'num' => $num, 'last' => 0]];
  55. BookItemClass::delBathItem($delData, $order, $params);
  56. }
  57. //预订单添加花材项 ssh 20240123
  58. public static function addBookItemFn($order, $itemList, $params = [])
  59. {
  60. $orderSn = $order->orderSn ?? '';
  61. $addIds = array_column($itemList, 'productId');
  62. $existList = self::getAllByCondition(['orderSn' => $orderSn], null, '*');
  63. foreach ($existList as $ex) {
  64. $productId = $ex['productId'] ?? 0;
  65. $name = $ex['name'] ?? '';
  66. if (in_array($productId, $addIds)) {
  67. util::fail($name . ' 已经存在');
  68. }
  69. }
  70. $addInfo = ProductClass::getByIds($addIds, null, 'id');
  71. if (empty($addInfo)) {
  72. util::fail('没有花材');
  73. }
  74. $productList = [];
  75. $thisBookData = [];
  76. foreach ($itemList as $item) {
  77. $num = $item['num'] ?? 0;
  78. $price = $item['price'] ?? 0;
  79. $productId = $item['productId'] ?? 0;
  80. $info = $addInfo[$productId] ?? [];
  81. $current = [];
  82. $current['name'] = $info['name'] ?? '';
  83. $current['cover'] = $info['cover'] ?? '';
  84. $current['orderSn'] = $orderSn;
  85. $ptItemId = $info['itemId'] ?? 0;
  86. $current['itemId'] = $ptItemId;
  87. $current['productId'] = $productId;
  88. $classId = $info['classId'] ?? 0;
  89. $current['classId'] = $classId;
  90. $current['variety'] = $info['variety'] ?? 0;
  91. $current['shopId'] = $info['shopId'] ?? 0;
  92. $current['mainId'] = $info['mainId'] ?? 0;
  93. $current['smallUnit'] = $info['smallUnit'] ?? 0;
  94. $current['bigUnit'] = $info['bigUnit'] ?? 0;
  95. $current['price'] = 0;
  96. $current['unitWeight'] = $info['weight'] ?? 0;
  97. $current['cost'] = $info['cost'] ?? 0;
  98. $current['num'] = $num;
  99. $current['bigNum'] = $num;
  100. $current['preNum'] = $num;
  101. $current['preBigNum'] = $num;
  102. $current['ratio'] = $info['ratio'] ?? 0;
  103. $current['variety'] = $info['variety'] ?? 0;
  104. $current['xhNum'] = $num;
  105. $current['xhUnitName'] = $info['bigUnit'] ?? '';
  106. $current['xhUnitType'] = 0;
  107. $current['xhPreNum'] = $num;
  108. $current['xhPreUnitName'] = $info['bigUnit'] ?? '';
  109. $current['xhPreUnitType'] = 0;
  110. if ($price > 0) {
  111. $current['xhUnitPrice'] = $price;
  112. $current['xhPreUnitPrice'] = $price;
  113. }
  114. $current['itemInfo'] = '';
  115. $belongCost = $info['belongCost'] ?? 0;
  116. $current['belongCost'] = $belongCost;
  117. self::add($current);
  118. $productList[] = [
  119. 'productId' => $productId,
  120. 'num' => $num,
  121. 'bigNum' => $num,
  122. 'smallNum' => 0,
  123. 'classId' => $classId,
  124. 'itemId' => $ptItemId,
  125. 'userPrice' => 0,
  126. ];
  127. $thisBookData[] = ['productId' => $productId, 'num' => $num, 'lastNum' => $num];
  128. }
  129. BookItemClass::addBatchItem($thisBookData, $order, $params);
  130. $cgId = $order->purchaseId ?? 0;
  131. $cg = PurchaseClass::getById($cgId, true);
  132. if (empty($cg)) {
  133. util::fail('没有采购信息');
  134. }
  135. $shopId = $cg->shopId ?? 0;
  136. $sjId = $cg->sjId ?? 0;
  137. $mainId = $cg->mainId ?? 0;
  138. $ghsId = $cg->ghsId ?? 0;
  139. $ghs = GhsClass::getById($ghsId, true);
  140. if (empty($ghs)) {
  141. util::fail('供货商无效');
  142. }
  143. $productList = ProductClass::toggleProductList($productList, $shopId, $sjId, $mainId, $ghs);
  144. $cgProductIds = array_column($productList, 'productId');
  145. $cgProductInfoList = ProductClass::getByIds($cgProductIds, null, 'id');
  146. $cgOrderSn = $cg->orderSn ?? '';
  147. foreach ($productList as $key => $val) {
  148. $productId = $val['productId'] ?? 0;
  149. $num = $val['num'] ?? 0;
  150. $ghsProductId = $val['ghsProductId'] ?? 0;
  151. $thisInfo = $cgProductInfoList[$productId] ?? [];
  152. $newItem = [];
  153. $name = $thisInfo['name'] ?? '';
  154. $cover = $thisInfo['cover'] ?? '';
  155. $newItem['name'] = $name;
  156. $newItem['cover'] = $cover;
  157. $newItem['orderSn'] = $cgOrderSn;
  158. $newItem['productId'] = $productId;
  159. $newItem['itemId'] = $thisInfo['itemId'] ?? 0;
  160. $newItem['mainId'] = $cg->mainId ?? 0;
  161. $newItem['ghsId'] = $ghsId;
  162. $newItem['itemNum'] = $num;
  163. $newItem['preItemNum'] = $num;
  164. $newItem['ghsProductId'] = $ghsProductId;
  165. $ratio = $thisInfo['ratio'] ?? 0;
  166. $bigUnit = $thisInfo['bigUnit'] ?? '';
  167. $smallUnit = $thisInfo['smallUnit'] ?? '';
  168. $newItem['ratio'] = $ratio;
  169. $newItem['price'] = 0;
  170. $newItem['variety'] = $thisInfo['variety'] ?? 0;
  171. $newItem['unitWeight'] = $thisInfo['weight'] ?? 0;
  172. $newItem['xhNum'] = $num;
  173. $newItem['xhUnitName'] = $thisInfo['bigUnit'] ?? '';
  174. $newItem['xhUnitType'] = 0;
  175. $newItem['xhPreNum'] = $num;
  176. $newItem['xhPreUnitName'] = $thisInfo['bigUnit'] ?? '';
  177. $newItem['xhPreUnitType'] = 0;
  178. $newItem['itemInfo'] = '';
  179. $itemInfo = [
  180. 'itemName' => $name,
  181. 'itemCover' => $cover,
  182. 'bigNum' => $num,
  183. 'smallNum' => 0,
  184. 'bigNumStock' => 0,
  185. 'smallNumStock' => 0,
  186. 'itemUnit' => $ratio ? 2 : 1,
  187. 'ratio' => $ratio,
  188. 'rank' => '',
  189. 'bigUnit' => $bigUnit,
  190. 'smallUnit' => $smallUnit,
  191. ];
  192. $newItem['itemInfo'] = json_encode($itemInfo);
  193. PurchaseItemClass::add($newItem);
  194. }
  195. }
  196. public static function giveItem($order, $orderItem, $product, $num, $data)
  197. {
  198. $productId = $product->id ?? 0;
  199. $ptItemId = $product->itemId ?? 0;
  200. $name = $product->name ?? '';
  201. $cover = $product->cover ?? '';
  202. $ratio = $product->ratio ?? 20;
  203. $ratioType = $product->ratioType ?? 0;
  204. $mainId = $product->mainId ?? 0;
  205. $targetId = $order->id ?? 0;
  206. $targetSonId = $orderItem->id ?? 0;
  207. $orderItem->giveNum = bcadd($orderItem->giveNum, $num);
  208. $orderItem->save();
  209. $orderSn = orderSn::getGiveSn();
  210. $giveData = [
  211. 'orderSn' => $orderSn,
  212. 'mainId' => $mainId,
  213. 'productId' => $productId,
  214. 'name' => $name,
  215. 'cover' => $cover,
  216. 'ratio' => $ratio,
  217. 'ratioType' => $ratioType,
  218. 'ptItemId' => $ptItemId,
  219. 'giveNum' => $num,
  220. 'targetId' => $targetId,
  221. 'targetSonId' => $targetSonId,
  222. 'staffId' => $data['staffId'] ?? 0,
  223. 'staffName' => $data['staffName'] ?? '',
  224. 'ghsId' => $order->ghsId ?? 0,
  225. 'customId' => $order->customId ?? 0,
  226. 'customName' => $order->customName ?? '',
  227. 'customNamePy' => $order->customNamePy ?? '',
  228. 'customAvatar' => $order->customAvatar ?? '',
  229. 'customMobile' => $order->customMobile ?? '',
  230. ];
  231. $giveInfo = GiveClass::add($giveData, true);
  232. $stockInfo = ProductClass::decreaseStock($productId, $num, 0, true);
  233. $oldStock = $stockInfo['oldStock'];
  234. $newStock = $stockInfo['newStock'];
  235. $stockItem = [[
  236. 'productId' => $productId,
  237. 'itemId' => $ptItemId,
  238. 'itemNum' => $num,
  239. 'oldStock' => $oldStock,
  240. 'itemStock' => $oldStock,
  241. 'newStock' => $newStock,
  242. 'bigNum' => $num,
  243. 'smallNum' => 0,
  244. ]];
  245. $stockData = [];
  246. $stockData['shopId'] = $data['shopId'];
  247. $stockData['relateName'] = $data['staffName'] ?? '';
  248. $stockData['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  249. $stockData['orderSn'] = $orderSn;
  250. $stockData['sjId'] = $data['sjId'] ?? 0;
  251. $stockData['itemInfo'] = $stockItem;
  252. $stockData['relateName'] = $order->customName ?? '';
  253. StockRecordClass::addRecordByOrder($stockData, StockRecordClass::STOCK_RECORD_TYPE_GIVE);
  254. return $giveInfo;
  255. }
  256. //获取订单的花材 ssh 2021.3.2
  257. public static function getOrderItem($orderSn)
  258. {
  259. $list = self::getAllByCondition(['orderSn' => $orderSn], 'id ASC', '*');
  260. return self::groupInfo($list);
  261. }
  262. //组合信息 ssh 2021.3.2
  263. public static function groupInfo($list)
  264. {
  265. if (empty($list)) {
  266. return [];
  267. }
  268. $productIds = array_unique(array_filter(array_column($list, 'productId')));
  269. $productData = ProductClass::getProductByIds($productIds);
  270. $productData = array_column($productData, NULL, 'id');
  271. foreach ($list as $key => $val) {
  272. $shortCover = $val['cover'] ?? '';
  273. $list[$key]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  274. $list[$key]['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  275. if (!$val['ratio']) {
  276. $ratio = $productData[$val['productId']]['ratio'] ?? 1;
  277. $list[$key]['ratio'] = $ratio;
  278. }
  279. //保存实时成本,预订单到货时使用
  280. $list[$key]['currentCost'] = $productData[$val['productId']]['cost'] ?? 0;
  281. }
  282. return $list;
  283. }
  284. /**
  285. * 替换订单(orderSn)下所有商品项为指定的 product 列表,并根据参数处理附加商详(如每支鲜花 xj)、校验及扣减库存、更新限购等。
  286. *
  287. * 步骤说明:
  288. * 1. 根据 customId 获取客户等级和属性,格式化 products 信息;
  289. * 2. 先删除该订单下历史商品项,再批量插入新 products 项;
  290. * 3. 若包含 xj(每支鲜花)信息,批量关联并校验单支库存、同步写入;
  291. * 4. 处理每项商品的限购、本次扣减库存(如 stockMayChange 为 true),并记录出库流水。
  292. * 5. 返回本次批量插入及处理后的汇总结果(带总重量)。
  293. *
  294. * 用于订单商品整体替换的核心业务方法。
  295. * @param $orderSn
  296. * @param $products
  297. * @param null $post
  298. * @param bool $stockMayChange
  299. * @param array $moreParams
  300. * @return array|void
  301. * @throws \Exception
  302. */
  303. public static function replaceItem($orderSn, $products, $post = null, $stockMayChange = false, $moreParams = [])
  304. {
  305. $customId = intval($post['customId']);
  306. $custom = CustomClass::getById($customId, true);
  307. if (empty($custom)) {
  308. return util::fail('没有找到客户');
  309. }
  310. $level = $custom->level ?? 0;
  311. $live = isset($custom->live) ? $custom->live : 1;
  312. $respond = ProductClass::formatProductInfo($products, $level, $live, $moreParams);
  313. $products = $respond['product'];
  314. $weight = 0;
  315. $mainId = $post['mainId'] ?? 0;
  316. self::deleteByCondition(['orderSn' => $orderSn]);
  317. foreach ($products as $key => $p) {
  318. $p['orderSn'] = $orderSn;
  319. $p['mainId'] = $mainId;
  320. $item = self::add($p, true);
  321. $currentPtItemId = $item->itemId;
  322. $unitPrice = $p['unitPrice'];
  323. if (isset($post['xj'][$currentPtItemId]) && !empty($post['xj'][$currentPtItemId])) {
  324. $xjArr = $post['xj'][$currentPtItemId];
  325. if (is_array($xjArr)) {
  326. $ids = array_column($xjArr, 'id');
  327. $sjInfo = XjClass::getByIds($ids, null, 'id');
  328. $xjData = [];
  329. foreach ($xjArr as $xjItem) {
  330. $id = $xjItem['id'] ?? 0;
  331. $num = $xjItem['num'] ?? 0;
  332. $name = $sjInfo[$id]['name'] ?? '';
  333. $cover = $sjInfo[$id]['cover'] ?? '';
  334. $stock = $sjInfo[$id]['stock'] ?? -1;
  335. if ($stock == -1) {
  336. } else {
  337. if ($stock < $num) {
  338. util::fail($name . ' 库存不足 ' . $num);
  339. } else {
  340. $newStock = bcsub($stock, $num);
  341. $status = $newStock == 0 ? 2 : 1;
  342. XjClass::updateById($id, ['stock' => $newStock, 'status' => $status]);
  343. }
  344. }
  345. $xjData[] = ['xjId' => $id, 'name' => $name, 'ptItemId' => $currentPtItemId,
  346. 'num' => $num, 'price' => $unitPrice, 'itemId' => $item->id, 'cover' => $cover];
  347. }
  348. OrderXjClass::batchAdd($xjData);
  349. $item->variety = 1;
  350. $item->save();
  351. }
  352. }
  353. $productId = $p['productId'] ?? 0;
  354. if (!empty($post['treeData'][$currentPtItemId])) {
  355. $treeData = $post['treeData'][$currentPtItemId];
  356. if (is_array($treeData)) {
  357. foreach ($treeData as $treeItem) {
  358. $treeNum = $treeItem['num'] ?? 0;
  359. $treeParam = [
  360. 'orderSn' => $orderSn,
  361. 'productId' => $productId,
  362. 'num' => $treeNum,
  363. ];
  364. OrderTreeClass::add($treeParam);
  365. }
  366. $dishNum = count($treeData);
  367. $item->dishNum = $dishNum;
  368. $item->save();
  369. }
  370. }
  371. $ratio = $p['ratio'] ?? 0;
  372. $bigNum = $p['bigNum'] ?? 0;
  373. $smallNum = $p['smallNum'] ?? 0;
  374. $itemNum = ProductClass::mergeItemNum($bigNum, $smallNum, $ratio);
  375. $w = bcmul($itemNum, $p['weight'], 2);
  376. $weight = bcadd($w, $weight, 2);
  377. $limitBuy = $p['limitBuy'];
  378. if ($limitBuy > 0) {
  379. ProductClass::handleLimitBuy($p, $customId, floatval($itemNum));
  380. }
  381. if ($stockMayChange == true) {
  382. if ($itemNum > 0) {
  383. $productId = $p['productId'];
  384. $checkStock = true;
  385. //如果是虚拟客户,说明自己也是虚拟批发店,虚拟批发店不用考虑库存
  386. if ($live == 0) {
  387. $checkStock = false;
  388. }
  389. $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum, $checkStock);
  390. $recordData = [];
  391. $recordData['sjId'] = $post['sjId'] ?? 0;
  392. $recordData['shopId'] = $post['shopId'] ?? 0;
  393. $recordData['mainId'] = $post['mainId'] ?? 0;
  394. $recordData['itemId'] = $p['itemId'] ?? 0;
  395. $recordData['itemNum'] = $itemNum;
  396. $recordData['oldStock'] = $stockInfo['oldStock'];
  397. $recordData['newStock'] = $stockInfo['newStock'];
  398. $recordData['productId'] = $productId;
  399. $recordData['orderSn'] = $orderSn;
  400. $recordData['relateName'] = $post['customName'] ?? '';
  401. $recordData['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  402. StockRecordClass::addSellStockOrderRecord($recordData);
  403. }
  404. }
  405. }
  406. $respond['weight'] = $weight;
  407. return $respond;
  408. }
  409. public static function getOrderInfoList($where)
  410. {
  411. $respond = self::getList('orderSn,id', $where, 'id DESC');
  412. if (isset($respond['list']) && !empty($respond['list'])) {
  413. $orderSnData = array_unique(array_filter(array_column($respond['list'], 'orderSn')));
  414. $orderInfoList = OrderClass::getOrderInfoBySnList($orderSnData);
  415. foreach ($respond['list'] as $key => $val) {
  416. $orderSn = $val['orderSn'] ?? '';
  417. $orderInfo = $orderInfoList[$orderSn] ?? [];
  418. $respond['list'][$key]['orderInfo'] = $orderInfo;
  419. }
  420. }
  421. return $respond;
  422. }
  423. public static function refreshBelongCost()
  424. {
  425. $customerCachedKey = 'change_belong_cost_item_list';
  426. $belongList = [];
  427. while ($count = Yii::$app->redis->executeCommand('LLEN', [$customerCachedKey])) {
  428. $string = Yii::$app->redis->executeCommand('RPOP', [$customerCachedKey]);
  429. $arr = explode('_', $string);
  430. if (count($arr) == 2) {
  431. $belongList[] = ['id' => $arr[0], 'belongCost' => $arr[1]];
  432. }
  433. }
  434. if (empty($belongList)) {
  435. return false;
  436. }
  437. foreach ($belongList as $info) {
  438. $id = $info['id'];
  439. $belongCost = $info['belongCost'];
  440. noticeUtil::push('变更单独统计' . $id . ' ' . $belongCost, '15280215347');
  441. self::updateByCondition(['productId' => $id], ['belongCost' => $belongCost]);
  442. PurchaseOrderItemClass::updateByCondition(['productId' => $id], ['belongCost' => $belongCost]);
  443. \bizHd\order\classes\OrderItemClass::updateByCondition(['itemId' => $id], ['belongCost' => $belongCost]);
  444. }
  445. }
  446. //导出excel ssh 20241127
  447. public static function exportExcel($order, $orderList, $mainId)
  448. {
  449. $customName = $order->customName ?? '';
  450. $orderSn = $order->orderSn ?? '';
  451. $fileTitle = $customName . '_' . $orderSn;
  452. if (empty($orderList)) {
  453. util::fail('没有数据需要导出');
  454. }
  455. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  456. require_once($phpExcelFile . 'Classes/PHPExcel.php');
  457. $objPHPExcel = new \PHPExcel();
  458. $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
  459. ->setLastModifiedBy("Maarten Balliauw")
  460. ->setTitle("Office 2007 XLSX Document")
  461. ->setSubject("Office 2007 XLSX Document")
  462. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  463. ->setKeywords("office 2007 openxml php")
  464. ->setCategory("file");
  465. $ghsTitle = '花材列表';
  466. $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
  467. $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
  468. $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
  469. $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
  470. $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
  471. $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
  472. $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
  473. //设置宽度
  474. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
  475. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
  476. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
  477. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
  478. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
  479. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(16);
  480. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(16);
  481. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(16);
  482. //加粗
  483. $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(13)->setBold(true);
  484. $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(13)->setBold(true);
  485. $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(13)->setBold(true);
  486. $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(13)->setBold(true);
  487. $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setSize(13)->setBold(true);
  488. $objPHPExcel->getActiveSheet()->getStyle('F1')->getFont()->setSize(13)->setBold(true);
  489. $objPHPExcel->getActiveSheet()->getStyle('G1')->getFont()->setSize(13)->setBold(true);
  490. $objPHPExcel->getActiveSheet()->getStyle('H1')->getFont()->setSize(13)->setBold(true);
  491. $objPHPExcel->getActiveSheet()->getStyle('I1')->getFont()->setSize(13)->setBold(true);
  492. $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  493. $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  494. $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  495. $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  496. $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  497. $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  498. $objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  499. $objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  500. $objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  501. $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  502. $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  503. $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  504. $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  505. $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  506. $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  507. $objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  508. $objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  509. $objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  510. $objPHPExcel->getActiveSheet()->setCellValue('A1', '花材ID');
  511. $objPHPExcel->getActiveSheet()->setCellValue('B1', '花材名称');
  512. $objPHPExcel->getActiveSheet()->setCellValue('C1', '数量');
  513. $objPHPExcel->getActiveSheet()->setCellValue('D1', '单价');
  514. $objPHPExcel->getActiveSheet()->setCellValue('E1', '总价');
  515. $objPHPExcel->getActiveSheet()->setCellValue('F1', '备注');
  516. $objPHPExcel->getActiveSheet()->setCellValue('G1', '预留1');
  517. $objPHPExcel->getActiveSheet()->setCellValue('H1', '预留2');
  518. $objPHPExcel->getActiveSheet()->setCellValue('I1', '预留3');
  519. $baseRow = 2;
  520. foreach ($orderList as $key => $order) {
  521. $i = $baseRow + $key;
  522. $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $order['productId']);
  523. $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $order['name']);
  524. $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $order['xhNum']);
  525. $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $order['xhUnitPrice']);
  526. $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $order['xhPrice']);
  527. $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $order['remark']);
  528. $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, '');
  529. $objPHPExcel->getActiveSheet()->setCellValue('H' . $i, '');
  530. $objPHPExcel->getActiveSheet()->setCellValue('I' . $i, '');
  531. //居中
  532. $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  533. $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  534. $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  535. $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  536. $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  537. $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  538. $objPHPExcel->getActiveSheet()->getStyle('G' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  539. $objPHPExcel->getActiveSheet()->getStyle('H' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  540. $objPHPExcel->getActiveSheet()->getStyle('I' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  541. $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getFont()->setSize(13);
  542. $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getFont()->setSize(13);
  543. $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getFont()->setSize(13);
  544. $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getFont()->setSize(13);
  545. $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getFont()->setSize(13);
  546. $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getFont()->setSize(13);
  547. $objPHPExcel->getActiveSheet()->getStyle('G' . $i)->getFont()->setSize(13);
  548. $objPHPExcel->getActiveSheet()->getStyle('H' . $i)->getFont()->setSize(13);
  549. $objPHPExcel->getActiveSheet()->getStyle('I' . $i)->getFont()->setSize(13);
  550. }
  551. $fileName = $fileTitle;
  552. $objPHPExcel->getActiveSheet()->setTitle($fileName);
  553. $objPHPExcel->setActiveSheetIndex(0);
  554. $dir = './orderItemExcel/' . $mainId;
  555. if (file_exists($dir) == false) {
  556. mkdir($dir, 0777, true);
  557. }
  558. $date = $fileName;
  559. $file = $date . '.xls';
  560. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  561. if (file_exists($dir . '/' . $file)) {
  562. unlink($dir . '/' . $file);
  563. }
  564. $objWriter->save($dir . '/' . $file);
  565. $fileUrl = Yii::$app->params['ghsHost'] . '/orderItemExcel/' . $mainId . '/' . $file;
  566. util::success(['file' => $fileUrl, 'shortFile' => $file]);
  567. }
  568. }