OrderClass.php 123 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750
  1. <?php
  2. namespace bizGhs\order\classes;
  3. use bizGhs\item\classes\ItemClassClass;
  4. use wkhtmltox\Image\Converter;
  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\sj\classes\SjClass;
  11. use biz\stat\classes\StatItemClass;
  12. use biz\stat\classes\StatKdClass;
  13. use biz\stat\classes\StatKhCgClass;
  14. use biz\stat\classes\StatOrderCountClass;
  15. use biz\stat\classes\StatOutClass;
  16. use biz\stat\classes\StatRefundClass;
  17. use biz\stat\classes\StatSaleClass;
  18. use biz\stock\classes\StockClass;
  19. use bizGhs\custom\models\Custom;
  20. use bizGhs\express\services\DadaExpressServices;
  21. use bizGhs\order\models\Order;
  22. use bizGhs\order\traits\OrderTrait;
  23. use bizGhs\product\classes\ProductClass;
  24. use bizGhs\admin\classes\AdminClass;
  25. use bizGhs\custom\classes\CustomClass;
  26. use bizGhs\shop\classes\MainClass;
  27. use bizGhs\stat\classes\StatYjClass;
  28. use bizGhs\stock\classes\StockRecordClass;
  29. use bizGhs\stock\services\StockRecordService;
  30. use bizHd\purchase\classes\PurchaseClass;
  31. use bizHd\stat\classes\StatIncomeClass;
  32. use bizHd\stat\classes\StatOrderClass;
  33. use common\components\dict;
  34. use common\components\httpUtil;
  35. use common\components\imgUtil;
  36. use common\components\noticeUtil;
  37. use common\components\orderSn;
  38. use common\components\printUtil;
  39. use common\components\stringUtil;
  40. use common\components\util;
  41. use bizGhs\base\classes\BaseClass;
  42. use Yii;
  43. class OrderClass extends BaseClass
  44. {
  45. use OrderTrait;
  46. public static $baseFile = '\bizGhs\order\models\Order';
  47. //已取消
  48. const ORDER_STATUS_CANCEL = 5;
  49. //已完成
  50. const ORDER_STATUS_COMPLETE = 4;
  51. //配送中
  52. const ORDER_STATUS_SENDING = 3;
  53. //待配送
  54. const ORDER_STATUS_UN_SEND = 2;
  55. //待付款,待确认
  56. const ORDER_STATUS_UN_PAY = 1;
  57. //出车
  58. const SEND_TYPE_CAR_GET = 0;
  59. //到店自取
  60. const SEND_TYPE_SHOP_GET = 1;
  61. //发快递
  62. const SEND_TYPE_THIRD_SEND = 2;
  63. //未确认
  64. const SEND_TYPE_UNKNOWN = 1;
  65. //自取
  66. const SEND_TYPE_NO = 2;
  67. //自己送
  68. const SEND_TYPE_MYSELF = 3;
  69. //快递送
  70. const SEND_TYPE_THIRD = 4;
  71. public static $sendTypeMap = [
  72. self::SEND_TYPE_UNKNOWN => '未确认',
  73. self::SEND_TYPE_NO => '自取',
  74. self::SEND_TYPE_MYSELF => '商家配送',
  75. self::SEND_TYPE_THIRD => '快递配送',
  76. ];
  77. //待付款
  78. const PAY_STATUS_UN_PAY = 0;
  79. //已付款
  80. const PAY_STATUS_HAS_PAY = 1;
  81. //待配送
  82. const SEND_STATUS_UN_SEND = 1;
  83. //配送中
  84. const SEND_STATUS_SENDING = 2;
  85. //配送完成
  86. const SEND_STATUS_COMPLETE = 3;
  87. //订单总流程数
  88. const TOTAL_FLOW = 3;
  89. //清算方式
  90. //欠款
  91. const CLEAR_DEBT = 1;
  92. //已付款
  93. const CLEAR_HAS_GATHERING = 2;
  94. //没有欠款
  95. const DEBT_NO = 0;
  96. //欠款
  97. const DEBT_YES = 1;
  98. //正常订单
  99. const REFUND_NO = 1;
  100. //已退款订单
  101. const REFUND_YES = 2;
  102. public static $refundMap = [
  103. self::REFUND_NO => '',
  104. self::REFUND_YES => '有退款',
  105. ];
  106. public static function exportOrderData($respond, $mainId)
  107. {
  108. $orderList = $respond['list'] ?? [];
  109. if (empty($orderList)) {
  110. util::fail('没有数据需要导出');
  111. }
  112. $orderSnList = array_column($orderList, 'orderSn');
  113. $orderItemData = OrderItemClass::getAllByCondition(['orderSn' => ['in', $orderSnList]], null, '*');
  114. $orderItemList = [];
  115. if (!empty($orderItemData)) {
  116. foreach ($orderItemData as $itemInfo) {
  117. $orderSn = $itemInfo['orderSn'] ?? '';
  118. $orderItemList[$orderSn][] = $itemInfo;
  119. }
  120. }
  121. foreach ($orderList as $key => $orderInfo) {
  122. $book = $orderInfo['book'] ?? 0;
  123. $actPrice = $orderInfo['actPrice'] ?? 0;
  124. $status = $orderInfo['status'] ?? 0;
  125. if ($book == 1 && $status == 2) {
  126. //预订单待发货的不算收入
  127. unset($orderList[$key]);
  128. continue;
  129. }
  130. if ($status == 1 || $status == 5) {
  131. unset($orderList[$key]);
  132. continue;
  133. }
  134. if ($actPrice <= 0) {
  135. unset($orderList[$key]);
  136. continue;
  137. }
  138. $orderSn = $orderInfo['orderSn'] ?? '';
  139. $itemList = $orderItemList[$orderSn] ?? [];
  140. $orderList[$key]['itemList'] = $itemList;
  141. }
  142. $classList = ItemClassClass::getAllByCondition(['mainId' => $mainId], null, '*', 'id');
  143. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  144. require_once($phpExcelFile . 'Classes/PHPExcel.php');
  145. $objPHPExcel = new \PHPExcel();
  146. $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
  147. ->setLastModifiedBy("Maarten Balliauw")
  148. ->setTitle("Office 2007 XLSX Document")
  149. ->setSubject("Office 2007 XLSX Document")
  150. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  151. ->setKeywords("office 2007 openxml php")
  152. ->setCategory("file");
  153. $ghsTitle = '供货商';
  154. $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
  155. $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
  156. $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
  157. $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
  158. $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
  159. $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
  160. $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
  161. $objPHPExcel->getActiveSheet()->setCellValue('A1', '订单号');
  162. $objPHPExcel->getActiveSheet()->setCellValue('B1', '创建时间');
  163. $objPHPExcel->getActiveSheet()->setCellValue('C1', '账单日期');
  164. $objPHPExcel->getActiveSheet()->setCellValue('D1', '订单金额');
  165. $objPHPExcel->getActiveSheet()->setCellValue('E1', '退款金额');
  166. $objPHPExcel->getActiveSheet()->setCellValue('F1', '实际金额');
  167. $objPHPExcel->getActiveSheet()->setCellValue('G1', '客户');
  168. $objPHPExcel->getActiveSheet()->setCellValue('H1', '客户手机号');
  169. $objPHPExcel->getActiveSheet()->setCellValue('I1', '在线支付');
  170. $objPHPExcel->getActiveSheet()->setCellValue('J1', '结清状态');
  171. $objPHPExcel->getActiveSheet()->setCellValue('K1', '已优惠');
  172. $objPHPExcel->getActiveSheet()->setCellValue('L1', '备注');
  173. $objPHPExcel->getActiveSheet()->setCellValue('M1', '开单人');
  174. $objPHPExcel->getActiveSheet()->setCellValue('N1', '花材Id');
  175. $objPHPExcel->getActiveSheet()->setCellValue('O1', '花材名称');
  176. $objPHPExcel->getActiveSheet()->setCellValue('P1', '单价');
  177. $objPHPExcel->getActiveSheet()->setCellValue('Q1', '数量');
  178. $objPHPExcel->getActiveSheet()->setCellValue('R1', '已退数量');
  179. $objPHPExcel->getActiveSheet()->setCellValue('S1', '金额');
  180. $objPHPExcel->getActiveSheet()->setCellValue('T1', '分类');
  181. $objPHPExcel->getActiveSheet()->setCellValue('U1', '备注');
  182. //设置宽度
  183. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
  184. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
  185. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
  186. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(16);
  187. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
  188. $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(20);
  189. $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(20);
  190. $objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(18);
  191. $objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth(18);
  192. //加粗
  193. $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
  194. $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
  195. $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
  196. $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
  197. $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setSize(9)->setBold(true);
  198. $objPHPExcel->getActiveSheet()->getStyle('F1')->getFont()->setSize(9)->setBold(true);
  199. $objPHPExcel->getActiveSheet()->getStyle('G1')->getFont()->setSize(9)->setBold(true);
  200. $objPHPExcel->getActiveSheet()->getStyle('H1')->getFont()->setSize(9)->setBold(true);
  201. $objPHPExcel->getActiveSheet()->getStyle('I1')->getFont()->setSize(9)->setBold(true);
  202. $objPHPExcel->getActiveSheet()->getStyle('J1')->getFont()->setSize(9)->setBold(true);
  203. $objPHPExcel->getActiveSheet()->getStyle('K1')->getFont()->setSize(9)->setBold(true);
  204. $objPHPExcel->getActiveSheet()->getStyle('L1')->getFont()->setSize(9)->setBold(true);
  205. $objPHPExcel->getActiveSheet()->getStyle('M1')->getFont()->setSize(9)->setBold(true);
  206. $objPHPExcel->getActiveSheet()->getStyle('N1')->getFont()->setSize(9)->setBold(true);
  207. $objPHPExcel->getActiveSheet()->getStyle('O1')->getFont()->setSize(9)->setBold(true);
  208. $objPHPExcel->getActiveSheet()->getStyle('P1')->getFont()->setSize(9)->setBold(true);
  209. $objPHPExcel->getActiveSheet()->getStyle('Q1')->getFont()->setSize(9)->setBold(true);
  210. $objPHPExcel->getActiveSheet()->getStyle('R1')->getFont()->setSize(9)->setBold(true);
  211. $objPHPExcel->getActiveSheet()->getStyle('S1')->getFont()->setSize(9)->setBold(true);
  212. $objPHPExcel->getActiveSheet()->getStyle('T1')->getFont()->setSize(9)->setBold(true);
  213. $objPHPExcel->getActiveSheet()->getStyle('U1')->getFont()->setSize(9)->setBold(true);
  214. $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  215. $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  216. $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  217. $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  218. $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  219. $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  220. $objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  221. $objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  222. $objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  223. $objPHPExcel->getActiveSheet()->getStyle('J1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  224. $objPHPExcel->getActiveSheet()->getStyle('K1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  225. $objPHPExcel->getActiveSheet()->getStyle('L1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  226. $objPHPExcel->getActiveSheet()->getStyle('M1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  227. $objPHPExcel->getActiveSheet()->getStyle('N1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  228. $objPHPExcel->getActiveSheet()->getStyle('O1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  229. $objPHPExcel->getActiveSheet()->getStyle('P1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  230. $objPHPExcel->getActiveSheet()->getStyle('Q1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  231. $objPHPExcel->getActiveSheet()->getStyle('R1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  232. $objPHPExcel->getActiveSheet()->getStyle('S1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  233. $objPHPExcel->getActiveSheet()->getStyle('T1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  234. $objPHPExcel->getActiveSheet()->getStyle('U1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  235. $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  236. $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  237. $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  238. $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  239. $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  240. $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  241. $objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  242. $objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  243. $objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  244. $objPHPExcel->getActiveSheet()->getStyle('J1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  245. $objPHPExcel->getActiveSheet()->getStyle('K1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  246. $objPHPExcel->getActiveSheet()->getStyle('L1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  247. $objPHPExcel->getActiveSheet()->getStyle('M1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  248. $objPHPExcel->getActiveSheet()->getStyle('N1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  249. $objPHPExcel->getActiveSheet()->getStyle('O1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  250. $objPHPExcel->getActiveSheet()->getStyle('P1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  251. $objPHPExcel->getActiveSheet()->getStyle('Q1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  252. $objPHPExcel->getActiveSheet()->getStyle('R1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  253. $objPHPExcel->getActiveSheet()->getStyle('S1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  254. $objPHPExcel->getActiveSheet()->getStyle('T1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  255. $objPHPExcel->getActiveSheet()->getStyle('U1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  256. $baseRow = 2;
  257. $x = 0;
  258. foreach ($orderList as $key => $orderData) {
  259. $currentList = $orderData['itemList'] ?? [];
  260. if (!empty($currentList)) {
  261. foreach ($currentList as $k => $orderInfo) {
  262. $i = $baseRow + $x;
  263. $x++;
  264. $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $orderData['orderSn']);
  265. $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $orderData['addTime']);
  266. $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $orderData['payTime']);
  267. $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $orderData['orderPrice']);
  268. $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $orderData['tkPrice']);
  269. $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $orderData['actPrice']);
  270. $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, $orderData['customName']);
  271. $objPHPExcel->getActiveSheet()->setCellValue('H' . $i, $orderData['customMobile']);
  272. $objPHPExcel->getActiveSheet()->setCellValue('I' . $i, $orderData['onlinePay'] == 1 ? '否' : '是');
  273. $objPHPExcel->getActiveSheet()->setCellValue('J' . $i, $orderData['debt'] == 1 ? '未结清' : '已结清');
  274. $objPHPExcel->getActiveSheet()->setCellValue('K' . $i, $orderData['discountAmount']);
  275. $objPHPExcel->getActiveSheet()->setCellValue('L' . $i, $orderData['remark']);
  276. $objPHPExcel->getActiveSheet()->setCellValue('M' . $i, $orderData['shopAdminName']);
  277. $objPHPExcel->getActiveSheet()->setCellValue('N' . $i, $orderInfo['productId']);
  278. $objPHPExcel->getActiveSheet()->setCellValue('O' . $i, $orderInfo['name']);
  279. $objPHPExcel->getActiveSheet()->setCellValue('P' . $i, $orderInfo['xhUnitPrice']);
  280. $remainNum = bcsub($orderInfo['xhNum'], $orderInfo['refundNum']);
  281. $price = bcmul($remainNum, $orderInfo['xhUnitPrice'], 2);
  282. $objPHPExcel->getActiveSheet()->setCellValue('Q' . $i, $remainNum);
  283. $objPHPExcel->getActiveSheet()->setCellValue('R' . $i, $orderInfo['refundNum']);
  284. $objPHPExcel->getActiveSheet()->setCellValue('S' . $i, $price);
  285. $classId = $orderInfo['classId'] ?? 0;
  286. $className = isset($classList[$classId]) && isset($classList[$classId]['name']) ? $classList[$classId]['name'] : '';
  287. $objPHPExcel->getActiveSheet()->setCellValue('T' . $i, $className);
  288. $objPHPExcel->getActiveSheet()->setCellValue('U' . $i, $orderInfo['remark']);
  289. //居左
  290. $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  291. $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  292. $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  293. $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  294. $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  295. $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  296. $objPHPExcel->getActiveSheet()->getStyle('G' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  297. $objPHPExcel->getActiveSheet()->getStyle('H' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  298. $objPHPExcel->getActiveSheet()->getStyle('I' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  299. $objPHPExcel->getActiveSheet()->getStyle('J' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  300. $objPHPExcel->getActiveSheet()->getStyle('K' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  301. $objPHPExcel->getActiveSheet()->getStyle('L' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  302. $objPHPExcel->getActiveSheet()->getStyle('M' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  303. $objPHPExcel->getActiveSheet()->getStyle('N' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  304. $objPHPExcel->getActiveSheet()->getStyle('O' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  305. $objPHPExcel->getActiveSheet()->getStyle('P' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  306. $objPHPExcel->getActiveSheet()->getStyle('Q' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  307. $objPHPExcel->getActiveSheet()->getStyle('R' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  308. $objPHPExcel->getActiveSheet()->getStyle('S' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  309. $objPHPExcel->getActiveSheet()->getStyle('T' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  310. }
  311. }
  312. }
  313. $fileName = '订单明细-' . time();
  314. $objPHPExcel->getActiveSheet()->setTitle($fileName);
  315. $objPHPExcel->setActiveSheetIndex(0);
  316. $dir = './priceTable/' . $mainId;
  317. if (file_exists($dir) == false) {
  318. mkdir($dir, 0777, true);
  319. }
  320. $date = $fileName;
  321. $file = $date . '.xls';
  322. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  323. if (file_exists($dir . '/' . $file)) {
  324. unlink($dir . '/' . $file);
  325. }
  326. $objWriter->save($dir . '/' . $file);
  327. $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
  328. util::success(['file' => $fileUrl, 'shortFile' => $file]);
  329. }
  330. public static function confirmReach($order, $params = [])
  331. {
  332. $cgId = $order->purchaseId ?? 0;
  333. $cg = PurchaseClass::getById($cgId, true);
  334. if (empty($cg)) {
  335. util::fail('没有找到采购信息');
  336. }
  337. $customId = $order->customId ?? 0;
  338. $custom = CustomClass::getById($customId, true);
  339. if (empty($custom)) {
  340. util::fail('没有找到客户信息');
  341. }
  342. $shopId = $custom->shopId ?? 0;
  343. $customShop = ShopClass::getById($shopId, true);
  344. if (empty($customShop)) {
  345. util::fail('没有找到客户的门店');
  346. }
  347. if (isset($customShop->pfShopId) && !empty($customShop->pfShopId)) {
  348. //如果客户是勇记花卉 森润 国恋 珊瑚 中华 寻花季 还是要直接完成,请搜索关键词 has_pf_direct_finish
  349. if (getenv('YII_ENV') == 'production') {
  350. $particularIds = [7779, 7832, 10610, 7779, 16780, 716, 8394];
  351. } else {
  352. $particularIds = [36750];
  353. }
  354. if (!in_array($customShop->id, $particularIds)) {
  355. util::fail('客户有批发店,请通知对方确认');
  356. }
  357. }
  358. //订单如果没有发货则先发货
  359. if ($order->status == 2) {
  360. $staffId = $params['staffId'] ?? 0;
  361. $staffName = $params['staffName'] ?? '';
  362. $element = ['staffId' => $staffId, 'staffName' => $staffName];
  363. self::orderSend($order, $element, true);
  364. $cg = PurchaseClass::getById($cgId, true);
  365. }
  366. PurchaseClass::takeToPutIn($cg);
  367. }
  368. //订单发货主方法 ssh 20231119
  369. public static function orderSend($order, $params, $allowRepeat = false)
  370. {
  371. self::orderFh($order, $params, $allowRepeat);
  372. $cgId = $order->purchaseId ?? 0;
  373. $cgInfo = PurchaseClass::getById($cgId, true);
  374. if (empty($cgInfo)) {
  375. util::fail('没有找到采购信息');
  376. }
  377. PurchaseClass::orderFh($cgInfo, $params, $allowRepeat, true);
  378. }
  379. //订单发货子方法 ssh 20231119
  380. public static function orderFh($order, $params, $allowRepeat = false)
  381. {
  382. if ($order->status == 3) {
  383. if ($allowRepeat == false) {
  384. util::fail('订单已发货');
  385. } else {
  386. return true;
  387. }
  388. }
  389. $fhType = $params['fhType'] ?? 0;
  390. if (is_numeric($fhType) == false) {
  391. util::fail('请选择发货类型');
  392. }
  393. if ($fhType == 1) {
  394. $fhWl = $params['fhWl'] ?? '';
  395. $fhWlNo = $params['fhWlNo'] ?? '';
  396. if (empty($fhWl)) {
  397. util::fail('请填写物流名称');
  398. }
  399. if (empty($fhWlNo)) {
  400. util::fail('请填写物流编号');
  401. }
  402. $order->fhWl = $fhWl;
  403. $order->fhWlNo = $fhWlNo;
  404. }
  405. $order->fhType = $fhType;
  406. $order->status = 3;
  407. $order->fhTime = date("Y-m-d H:i:s");
  408. $staffId = $params['staffId'] ?? 0;
  409. $staffName = $params['staffName'] ?? '';
  410. $order->sendStaffId = $staffId;
  411. $order->sendStaffName = $staffName;
  412. $order->save();
  413. }
  414. public static function arrival($order, $data)
  415. {
  416. if ($order->stockChange == 1) {
  417. util::fail('您已操作过了');
  418. }
  419. $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
  420. $packCost = isset($data['packCost']) && is_numeric($data['packCost']) ? $data['packCost'] : 0;
  421. $order->sendCost = $sendCost;
  422. $order->packCost = $packCost;
  423. $order->save();
  424. $sjId = $order->sjId ?? 0;
  425. $shopId = $order->shopId ?? 0;
  426. $mainId = $order->mainId ?? 0;
  427. //product [{"productId":"3674","num":0,"price":1}]
  428. $product = $data['product'] ?? '';
  429. if (empty($product)) {
  430. util::fail('没有花材?');
  431. }
  432. $ids = [];
  433. $format = [];
  434. foreach ($product as $val) {
  435. $productId = $val['productId'] ?? 0;
  436. $ids[] = $productId;
  437. $format[$productId] = $val;
  438. }
  439. $info = ProductClass::getByIds($ids, null, 'id');
  440. $orderSn = $order->orderSn ?? '';
  441. $customName = $order->customName ?? '';
  442. $list = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  443. if (empty($list)) {
  444. util::fail('没有找到订单的花材');
  445. }
  446. $itemPrice = 0;
  447. $weight = 0;
  448. foreach ($list as $key => $val) {
  449. $productId = $val->productId ?? 0;
  450. $num = $format[$productId]['num'] ?? 0;
  451. $unitPrice = $format[$productId]['price'] ?? 0;
  452. $price = bcmul($unitPrice, $num, 2);
  453. $name = $val->name ?? '';
  454. $xhUnitName = $val->xhUnitName ?? '';
  455. $xhPreNum = $val->xhPreNum ?? 0;
  456. if ($unitPrice <= 0) {
  457. util::fail('花材金额需要大于0');
  458. }
  459. if ($num > $xhPreNum) {
  460. //util::fail($name . "数量不能超过{$xhPreNum}{$xhUnitName}");
  461. }
  462. $val->cost = $unitPrice;
  463. $val->unitPrice = $unitPrice;
  464. $val->price = $price;
  465. $val->bigNum = $num;
  466. $val->num = $num;
  467. $val->xhNum = $num;
  468. $val->xhUnitPrice = $unitPrice;
  469. $val->xhPrice = $price;
  470. $val->save();
  471. if ($val->xhPreNum > $num) {
  472. //客户下单退货数增加
  473. $subNum = bcsub($val->xhPreNum, $num);
  474. StatKhCgClass::ghsBookOrderRefundNum($order, $subNum);
  475. //花材销量榜减少
  476. StatItemClass::ghsBookOrderRefundNum($order, $val, $subNum);
  477. }
  478. $itemPrice = bcadd($itemPrice, $price, 2);
  479. $productWeight = $info[$productId]['weight'] ?? 0;
  480. $currentWeight = bcmul($productWeight, $num, 2);
  481. $weight = bcadd($currentWeight, $weight, 2);
  482. //减少库存
  483. $unitType = $val->xhUnitType ?? 0;
  484. $bigNum = 0;
  485. $smallNum = 0;
  486. if ($unitType == dict::getDict('unitType', 'big')) {
  487. $bigNum = $num;
  488. $itemNum = $num;
  489. } else {
  490. $smallNum = $num;
  491. $itemNum = bcdiv($num, $val->ratio, 2);
  492. }
  493. $checkStock = true;
  494. $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum, $checkStock);
  495. $recordData = [];
  496. $recordData['sjId'] = $sjId;
  497. $recordData['shopId'] = $shopId;
  498. $recordData['mainId'] = $mainId;
  499. $recordData['itemId'] = $val->itemId;
  500. $recordData['itemNum'] = $itemNum;
  501. $recordData['oldStock'] = $stockInfo['oldStock'];
  502. $recordData['newStock'] = $stockInfo['newStock'];
  503. $recordData['productId'] = $productId;
  504. $recordData['orderSn'] = $orderSn;
  505. $recordData['relateName'] = $customName;
  506. $recordData['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  507. StockRecordClass::addSellStockOrderRecord($recordData);
  508. }
  509. $order->itemPrice = $itemPrice;
  510. $sendCost = $order->sendCost ?? 0;
  511. $currentPrice = bcadd($itemPrice, $sendCost, 2);
  512. $packCost = $order->packCost ?? 0;
  513. $currentPrice = bcadd($currentPrice, $packCost, 2);
  514. $shopId = $order->shopId ?? 0;
  515. $shop = ShopClass::getLockById($shopId);
  516. if (empty($shop)) {
  517. util::fail('没有找到门店6');
  518. }
  519. $mainId = $shop->mainId ?? 0;
  520. $main = MainClass::getLockById($mainId);
  521. if (empty($main)) {
  522. util::fail('没有main信息4');
  523. }
  524. $main->unSendOrder -= 1;
  525. $main->finishOrder += 1;
  526. $main->save();
  527. $kiloFee = $shop->kiloFee ?? 0;
  528. $miniKilo = $shop->miniKilo ?? 0;
  529. $calcWeight = $weight > $miniKilo ? $weight : $miniKilo;
  530. $allKiloFee = bcmul($calcWeight, $kiloFee, 2);
  531. $currentPrice = bcadd($currentPrice, $allKiloFee, 2);
  532. $order->prePrice = $currentPrice;
  533. $order->orderPrice = $currentPrice;
  534. $order->actPrice = $currentPrice;
  535. $order->realPrice = $currentPrice;
  536. $order->stockChange = 1;
  537. $order->save();
  538. $bookPrice = $order->bookPrice ?? 0;
  539. $mainId = $shop->mainId ?? 0;
  540. $sjId = $shop->sjId ?? 0;
  541. $customId = $order->customId ?? 0;
  542. $relateOrderSn = $order->orderSn ?? '';
  543. $shopAdminId = $data['shopAdminId'] ?? 0;
  544. $shopAdminName = $data['shopAdminName'] ?? '';
  545. $refund = null;
  546. if ($bookPrice != $currentPrice) {
  547. if ($bookPrice > $currentPrice) {
  548. $refundPrice = bcsub($bookPrice, $currentPrice, 2);
  549. $order->refundPrice = $refundPrice;
  550. $order->tkPrice = bcadd($order->tkPrice, $refundPrice, 2);
  551. $order->refund = self::REFUND_YES;
  552. $order->refundLog = 1;
  553. $order->save();
  554. $orderSn = orderSn::getGhsRefundSn();
  555. $book = 1;
  556. $refundData = [
  557. 'mainId' => $mainId,
  558. 'shopId' => $shopId,
  559. 'sjId' => $sjId,
  560. 'customId' => $customId,
  561. 'orderSn' => $orderSn,
  562. 'relateOrderSn' => $relateOrderSn,
  563. 'book' => $book,
  564. 'status' => RefundOrderClass::STATUS_COMPLETE,
  565. 'shopAdminId' => $shopAdminId,
  566. 'shopAdminName' => $shopAdminName,
  567. 'refundPrice' => $refundPrice,
  568. 'refundType' => RefundOrderClass::REFUND_TYPE_MONEY,
  569. ];
  570. //退款
  571. $refund = RefundOrderClass::add($refundData, true);
  572. //余额减少
  573. ShopClass::ghsBookOrderRefundReduceBalance($main, $shop, $refund, $refundPrice);
  574. //总支出增加
  575. $currentTotalExpend = bcadd($main->totalExpend, $refundPrice, 2);
  576. $main->totalExpend = $currentTotalExpend;
  577. $totalRefund = bcadd($main->totalRefund, $refundPrice, 2);
  578. $main->totalRefund = $totalRefund;
  579. $main->save();
  580. //支出流水
  581. $thisType = dict::getDict('capitalType', 'ghsBookRefund', 'id');
  582. $sjId = $order->sjId ?? 0;
  583. $event = "预订单多付退给{$customName}";
  584. $capitalData = [
  585. 'capitalType' => $thisType,
  586. 'io' => 0,
  587. 'totalExpend' => $currentTotalExpend,
  588. 'payWay' => 0,
  589. 'amount' => $refundPrice,
  590. 'sjId' => $sjId,
  591. 'shopId' => $shopId,
  592. 'event' => $event,
  593. 'mainId' => $mainId,
  594. ];
  595. ShopCapitalClass::addCapital($capitalData);
  596. //支出统计
  597. StatOutClass::updateOrInsert($main, $shop, $refundPrice);
  598. //退款统计
  599. $payWay = $order->payWay ?? 0;
  600. StatRefundClass::replace($main, $shop, $payWay, $refundPrice);
  601. //供货商预订单退款给客户,客户采购金额减少
  602. StatKhCgClass::ghsBookOrderChange(false, $order, $refundPrice);
  603. } else {
  604. //欠款
  605. $currentDebt = bcsub($currentPrice, $bookPrice, 2);
  606. $order->debtPrice = $currentDebt;
  607. $order->remainDebtPrice = $currentDebt;
  608. $order->debt = OrderClass::DEBT_YES;
  609. $order->save();
  610. $currentTotalIncome = bcadd($main->totalIncome, $currentDebt, 2);
  611. $main->totalIncome = $currentTotalIncome;
  612. $main->save();
  613. $payWay = dict::getDict('payWay', 'debtPay');
  614. $custom = CustomClass::getLockById($customId);
  615. if (empty($custom)) {
  616. util::fail('没有找到客户');
  617. }
  618. CustomClass::cgDebtAmountAdd($custom, $order, true);
  619. //收入增加
  620. StatIncomeClass::updateOrInsert($main, $shop, $currentDebt);
  621. //收入流水增加
  622. $orderId = $order->id;
  623. $capitalType = dict::getDict('capitalType', 'ghsBookOrderGetBack', 'id');
  624. $shopAdminId = $order->shopAdminId ?? 0;
  625. $shopAdminName = $order->shopAdminName ?? '';
  626. $event = "预订单 {$orderSn} 差价补款";
  627. $mainId = $shop->mainId ?? 0;
  628. $sjId = $order->sjId ?? 0;
  629. $shopId = $order->shopId ?? 0;
  630. $capital = [
  631. 'capitalType' => $capitalType,
  632. 'relateId' => $orderId,
  633. 'io' => 1,
  634. 'amount' => $currentDebt,
  635. 'totalIncome' => $currentTotalIncome,
  636. 'payWay' => $payWay,
  637. 'event' => $event,
  638. 'mainId' => $mainId,
  639. 'sjId' => $sjId,
  640. 'shopId' => $shopId,
  641. 'shopAdminId' => $shopAdminId,
  642. 'shopAdminName' => $shopAdminName,
  643. ];
  644. ShopCapitalClass::addCapital($capital);
  645. //各渠道收入金额统计
  646. StatKdClass::replace($shop, $currentDebt, $payWay);
  647. //每天销售收入统计
  648. StatSaleClass::replace($main, $shop, $currentDebt);
  649. //预订单,客户补款给供货商,客户采购金额增加
  650. StatKhCgClass::ghsBookOrderChange(true, $order, $currentDebt);
  651. }
  652. }
  653. return ['kiloFee' => $kiloFee, 'refund' => $refund, 'miniKilo' => $miniKilo];
  654. }
  655. //添加订单 ssh 2019.12.5
  656. public static function addOrder($data)
  657. {
  658. $orderSn = orderSn::getGhsOrderSn();
  659. $data['orderSn'] = $orderSn;
  660. $data['payStatus'] = self::PAY_STATUS_UN_PAY;
  661. $data['customId'] = isset($data['customId']) && !empty($data['customId']) ? $data['customId'] : 0;
  662. $live = isset($data['live']) ? $data['live'] : 1;
  663. $currentShopId = $data['shopId'] ?? 0;
  664. $shop = ShopClass::getLockById($currentShopId);
  665. if (empty($shop)) {
  666. util::fail('没有找到门店7');
  667. }
  668. $mainId = $shop->mainId ?? 0;
  669. $main = MainClass::getLockById($mainId);
  670. if (empty($main)) {
  671. util::fail('没有main信息5');
  672. }
  673. //花材
  674. $product = $data['product'];
  675. $book = $data['book'] ?? 0;
  676. $stockMayChange = true;
  677. $data['stockChange'] = 1;
  678. if ($book == 1) {
  679. $stockMayChange = false;
  680. $data['stockChange'] = 0;
  681. }
  682. //花店向虚拟批发店采购的,批发店没有的花材需要补充
  683. if ($live == 0) {
  684. $product = \bizHd\product\classes\ProductClass::hdToggleGhs($product, $shop);
  685. }
  686. $customShopAdminId = $data['customShopAdminId'] ?? 0;
  687. $moreParams = ['book' => $book, 'customShopAdminId' => $customShopAdminId];
  688. $respond = OrderItemClass::replaceItem($orderSn, $product, $data, $stockMayChange, $moreParams);
  689. $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
  690. $data['sendCost'] = $sendCost;
  691. $data['bigNum'] = $respond['bigNum'] ?? 0;
  692. $data['smallNum'] = $respond['smallNum'] ?? 0;
  693. $data['itemNum'] = $respond['totalItemNum'] ?? 0;
  694. $data['reachDiscountPrice'] = $respond['totalReachDiscount'] ?? 0;
  695. //默认订单要打单
  696. $data['needPrint'] = $data['needPrint'] ?? dict::getDict('needPrint', 'need');
  697. $weight = $respond['weight'] ?? 0;
  698. $data['weight'] = $weight;
  699. $itemPrice = $respond['price'] ?? 0;
  700. $data['itemPrice'] = $itemPrice;
  701. $currentPrice = bcadd($itemPrice, $sendCost, 2);
  702. $packCost = isset($data['packCost']) && $data['packCost'] > 0 ? $data['packCost'] : 0;
  703. $currentPrice = bcadd($currentPrice, $packCost, 2);
  704. //预订单需要增加服务费
  705. if ($book == 1) {
  706. $kiloFee = $shop->kiloFee ?? 0;
  707. $miniKilo = $shop->miniKilo ?? 0;
  708. $calcWeight = $weight > $miniKilo ? $weight : $miniKilo;
  709. $allKiloFee = bcmul($calcWeight, $kiloFee, 2);
  710. $currentPrice = bcadd($currentPrice, $allKiloFee, 2);
  711. $data['allKiloFee'] = $allKiloFee;
  712. $data['kiloFee'] = $kiloFee;
  713. $data['miniKilo'] = $miniKilo;
  714. }
  715. $data['prePrice'] = $currentPrice;
  716. $actPrice = $currentPrice;
  717. //商家自己开单时
  718. if (isset($data['modifyPrice'])) {
  719. $modifyPrice = $data['modifyPrice'] ?? 0;
  720. if ($modifyPrice <= 0) {
  721. util::fail('收款金额必须大于0');
  722. }
  723. if ($modifyPrice > $currentPrice) {
  724. //人工和资材费用
  725. $data['labourCost'] = bcsub($modifyPrice, $currentPrice, 2);
  726. }
  727. if ($modifyPrice < $currentPrice) {
  728. //优惠金额
  729. $data['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2);
  730. $data['discountType'] = dict::getDict('discountType', 'discount');
  731. }
  732. $actPrice = $modifyPrice;
  733. if ($book == 1) {
  734. $actPrice = 0;
  735. }
  736. } else {
  737. //整单满减
  738. if ($book == 0) {
  739. $meetNum = $shop->meetNum ?? 0;
  740. $meetAmount = $shop->meetAmount ?? 0;
  741. $cutOption = $shop->cutAmount ?? 0;
  742. $cutStyle = $shop->cutStyle ?? 0;
  743. if ($cutStyle == 0) {
  744. $cutAmount = $cutOption;
  745. } else {
  746. $miniOption = bcsub(1, $cutOption, 2);
  747. $cutAmount = bcmul($actPrice, $miniOption, 2);
  748. }
  749. if ($cutOption > 0) {
  750. if ($meetNum > 0 && isset($data['bigNum']) && $data['bigNum'] >= $meetNum) {
  751. if ($cutAmount > $actPrice) {
  752. util::fail('整单满减为负');
  753. }
  754. $actPrice = bcsub($actPrice, $cutAmount, 2);
  755. $data['orderReachDiscountPrice'] = $cutAmount;
  756. } else {
  757. if ($meetAmount > 0 && isset($data['itemPrice']) && $data['itemPrice'] >= $meetAmount) {
  758. if ($cutAmount > $actPrice) {
  759. util::fail('整单满减为负');
  760. }
  761. $actPrice = bcsub($actPrice, $cutAmount, 2);
  762. $data['orderReachDiscountPrice'] = $cutAmount;
  763. }
  764. }
  765. }
  766. }
  767. }
  768. //客户采购时使用红包时
  769. if (isset($data['discountType']) && $data['discountType'] == dict::getDict('discountType', 'hb')) {
  770. $discountAmount = $data['discountAmount'] ?? 0;
  771. $currentDiscountPrice = bcsub($currentPrice, $discountAmount, 2);
  772. $actPrice = $currentDiscountPrice;
  773. }
  774. $data['actPrice'] = $actPrice;
  775. $data['bookPrice'] = $actPrice;
  776. $data['orderPrice'] = $actPrice;
  777. $data['realPrice'] = $actPrice;
  778. $data['sendTimeWant'] = isset($data['sendTimeWant']) && !empty($data['sendTimeWant']) ? $data['sendTimeWant'] : date("Y-m-d");
  779. //订单有效期
  780. $validTime = dict::getDict('order_pay_has_time');
  781. $current = time() + $validTime;
  782. $data['deadline'] = $data['deadline'] ?? date("Y-m-d H:i:s", $current);
  783. $data['status'] = self::ORDER_STATUS_UN_PAY;
  784. $main->totalOrder += 1;
  785. $main->unPayOrder += 1;
  786. $main->save();
  787. //将当天日期+花店每天的总订单数作为编号
  788. $data['sendNum'] = date("j") . StatOrderCountClass::addOrder($shop, $main);
  789. //订单有效期
  790. $currentTime = time();
  791. $validTime = dict::getDict('order_pay_has_time');
  792. $current = $currentTime + $validTime;
  793. $data['deadline'] = isset($data['deadline']) ? $data['deadline'] : date("Y-m-d H:i:s", $current);
  794. if ($book == 1) {
  795. $fiveTime = bcmul(86400, 5);
  796. $bookDeadline = bcadd($currentTime, $fiveTime);
  797. $data['deadline'] = date("Y-m-d H:i:s", $bookDeadline);
  798. }
  799. //订单自动记为欠款单时间
  800. $localConfirmTime = dict::getDict('local_gys_kd_auto_set_debt_time');
  801. $currentSet = $currentTime + $localConfirmTime;
  802. $data['autoSetTime'] = $data['autoSetTime'] ?? date("Y-m-d H:i:s", $currentSet);
  803. $return = self::add($data, true);
  804. return $return;
  805. }
  806. //修改订单 ssh 2019.12.5
  807. public static function updateOrder($order, $data)
  808. {
  809. $sjId = $order->sjId ?? 0;
  810. $orderSn = $order->orderSn ?? 0;
  811. $currentShopId = $order->shopId ?? 0;
  812. $data['payStatus'] = self::PAY_STATUS_UN_PAY;
  813. //花材列表
  814. $product = $data['product'];
  815. //删除花材再添加
  816. OrderItemClass::deleteByCondition(['orderSn' => $orderSn]);
  817. $respond = OrderItemClass::replaceItem($orderSn, $product, $data);
  818. $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
  819. $data['sendCost'] = $sendCost;
  820. $data['bigNum'] = $respond['bigNum'] ?? 0;
  821. $data['smallNum'] = $respond['smallNum'] ?? 0;
  822. $price = $respond['price'] ?? 0;
  823. $currentPrice = bcadd($price, $sendCost, 2);
  824. $data['prePrice'] = $currentPrice;
  825. if (isset($data['modifyPrice'])) {
  826. //商家打折,修改金额
  827. $modifyPrice = $data['modifyPrice'] ?? 0;
  828. if ($modifyPrice > $currentPrice) {
  829. util::fail('实收金额大于订单总金额');
  830. }
  831. if ($modifyPrice < $currentPrice) {
  832. $data['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2);
  833. $data['discountType'] = dict::getDict('discountType', 'discount');
  834. $currentPrice = $modifyPrice;
  835. }
  836. }
  837. $data['actPrice'] = $currentPrice;
  838. $data['realPrice'] = $currentPrice;
  839. //如果有平台补贴
  840. if (isset($data['discountType']) && $data['discountType'] == dict::getDict('discountType', 'usePtCoupon')) {
  841. $discountAmount = $data['discountAmount'] ?? 0;
  842. $data['realPrice'] = bcsub($currentPrice, $discountAmount, 2);
  843. }
  844. $data['sendTime'] = isset($data['sendTime']) && !empty($data['sendTime']) ? $data['sendTime'] : '0000-00-00 00:00:00';
  845. //订单有效期
  846. $validTime = dict::getDict('order_pay_has_time');
  847. $current = time() + $validTime;
  848. $data['deadline'] = $data['deadline'] ?? date("Y-m-d H:i:s", $current);
  849. $data['status'] = self::ORDER_STATUS_UN_PAY;
  850. //计算总重量(kg)
  851. $weight = 0;
  852. $productMapData = ProductClass::getProductMapData($product);
  853. foreach ($product as $key => $val) {
  854. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  855. $productId = $val['productId'];
  856. $weight = bcadd($w, $weight, 2);
  857. $checkStock = true;
  858. $stockInfo = ProductClass::decreaseStock($val['productId'], $val['bigNum'], $val['smallNum'], $checkStock);
  859. //记录库存流水
  860. $recordData = [];
  861. $recordData['sjId'] = $sjId;
  862. $recordData['shopId'] = $currentShopId;
  863. $recordData['itemId'] = $productMapData[$productId]['itemId'] ?? 0;
  864. $ratio = $productMapData[$productId]['ratio'] ?? 0;
  865. $recordData['itemNum'] = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  866. $recordData['oldStock'] = $stockInfo['oldStock'];
  867. $recordData['newStock'] = $stockInfo['newStock'];
  868. $recordData['productId'] = $productId;
  869. $recordData['orderSn'] = $orderSn;
  870. StockRecordClass::addSellStockOrderRecord($recordData);
  871. }
  872. $data['weight'] = $weight;
  873. $current = time() + 300;
  874. $data['deadline'] = isset($data['deadline']) ? $data['deadline'] : date("Y-m-d H:i:s", $current);
  875. //修改订单暂时不打印
  876. $data['needPrint'] = $data['needPrint'] ?? dict::getDict('needPrint', 'need');
  877. $orderId = $order->id ?? 0;
  878. self::updateById($orderId, $data);
  879. $return = self::getLockById($orderId);
  880. //门店总订单数+1
  881. $shop = ShopClass::getLockById($currentShopId);
  882. if (empty($shop)) {
  883. util::fail('没有找到门店8');
  884. }
  885. $shop->unPayOrder += 1;
  886. $shop->cancelOrder -= 1;
  887. $shop->save();
  888. return $return;
  889. }
  890. //根据订单编号查询 ssh 2021.19
  891. public static function getByOrderSn($orderSn, $returnObj = false)
  892. {
  893. return self::getByCondition(['orderSn' => $orderSn], $returnObj);
  894. }
  895. //根据编号列表查订单
  896. public static function getOrderInfoBySnList($snList)
  897. {
  898. $list = self::getAllByCondition(['orderSn' => ['in', $snList]], null, '*', 'orderSn');
  899. $list = self::groupOrder($list, true, false, false, true);
  900. return $list;
  901. }
  902. //显示操作按钮
  903. public static function getShowButton($showButton, $isList, $order)
  904. {
  905. if ($showButton == false) {
  906. return [];
  907. }
  908. $print = ['type' => 'print', 'show' => 1, 'disable' => 0, 'name' => '打印'];
  909. $modifyProduct = ['type' => 'modifyProduct', 'show' => 0, 'disable' => 0, 'name' => '修改花材'];
  910. $confirm = ['type' => 'confirm', 'show' => 0, 'disable' => 1, 'name' => '确认'];
  911. $cancel = ['type' => 'cancel', 'show' => 0, 'disable' => 0, 'name' => '取消'];
  912. $arrival = ['type' => 'arrival', 'show' => 0, 'disable' => 0, 'name' => '确认发货'];
  913. if ($isList) {
  914. //订单列表页显示的按钮
  915. $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货'];
  916. $selfGet = ['type' => 'selfGet', 'show' => 0, 'disable' => 1, 'name' => '自取'];
  917. if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
  918. //待确认订单,打印和修改花材按钮可以使用
  919. $send['disable'] = 1;
  920. $selfGet['disable'] = 1;
  921. $print['disable'] = 0;
  922. $confirm['disable'] = 0;
  923. }
  924. if ($order['status'] == self::ORDER_STATUS_UN_SEND) {
  925. //待配送订单,改花材按钮不可点,自取可点
  926. $selfGet['disable'] = 0;
  927. }
  928. //自取订单发货按钮置灰
  929. if ($order['sendType'] == self::SEND_TYPE_NO) {
  930. $send['disable'] = 1;
  931. }
  932. //取消订单置灰
  933. if ($order['status'] == self::ORDER_STATUS_CANCEL) {
  934. $send['disable'] = 1;
  935. $selfGet['disable'] = 1;
  936. $print['disable'] = 1;
  937. }
  938. if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
  939. $send['name'] = '发货记录';
  940. }
  941. return [$send, $selfGet, $print, $confirm];
  942. } else {
  943. //订单详情页显示的按钮
  944. if (isset($order['book']) && $order['book'] == 1 && isset($order['stockChange']) && $order['stockChange'] == 0) {
  945. if ($order['status'] == self::ORDER_STATUS_UN_SEND) {
  946. $arrival['show'] = 1;
  947. }
  948. }
  949. //待确认订单显示延期付和已付款
  950. if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
  951. $debtPay = ['type' => 'debtPay', 'show' => 0, 'disable' => 0, 'name' => '延期收款'];
  952. $hasPay = ['type' => 'hasPay', 'show' => 0, 'disable' => 0, 'name' => '欠款'];
  953. $confirm['disable'] = 0;
  954. return [$print, $debtPay, $hasPay, $confirm, $cancel, $arrival];
  955. }
  956. //待配送订单显示打印、发货和自取
  957. if ($order['status'] == self::ORDER_STATUS_UN_SEND) {
  958. $selfGet = ['type' => 'selfGet', 'show' => 0, 'disable' => 1, 'name' => '自取'];
  959. $send = ['type' => 'send', 'show' => 0, 'disable' => 1, 'name' => '发货'];
  960. if ($order['hasItem'] == 2) {
  961. return [$print, $selfGet, $send, $arrival];
  962. }
  963. $selfGet['disable'] = 0;
  964. $send['disable'] = 0;
  965. return [$print, $selfGet, $send, $arrival];
  966. }
  967. //配送中显示按钮
  968. if ($order['status'] == self::ORDER_STATUS_SENDING) {
  969. $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货'];
  970. return [$print, $send, $arrival];
  971. }
  972. //完成
  973. if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
  974. $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货记录'];
  975. //自取订单不显示发货按钮
  976. if ($order['sendType'] == self::SEND_TYPE_NO) {
  977. $send['show'] = 0;
  978. }
  979. return [$print, $send, $arrival];
  980. }
  981. //取消订单置灰
  982. if ($order['status'] == self::ORDER_STATUS_CANCEL) {
  983. $selfGet['disable'] = 1;
  984. $send['disable'] = 1;
  985. $print['disable'] = 1;
  986. return [$modifyProduct, $arrival];
  987. }
  988. return [];
  989. }
  990. }
  991. //显示进度 ssh 2021.3.1
  992. public static function getShowProgress($showProgress, $order)
  993. {
  994. if ($showProgress == false) {
  995. return [];
  996. }
  997. $create = ['name' => '创建', 'complete' => 1];
  998. $unConfirm = ['name' => '待确认', 'complete' => 0];
  999. if ($order['status'] > 0) {
  1000. $unConfirm['complete'] = 1;
  1001. }
  1002. $out = ['name' => '出库', 'complete' => 0];
  1003. if ($order['status'] > 1) {
  1004. $out['complete'] = 1;
  1005. }
  1006. return [$create, $unConfirm, $out];
  1007. }
  1008. //退款等需要使用原来的订单花材结构
  1009. public static function getOriginalShowItem($showItem, $order)
  1010. {
  1011. if ($showItem == false) {
  1012. return ['list' => [], 'itemStat' => []];
  1013. }
  1014. $orderSn = $order['orderSn'];
  1015. $list = OrderItemClass::getOrderItem($orderSn);
  1016. $totalPrice = 0;
  1017. $totalBigNum = 0;
  1018. $totalSmallNum = 0;
  1019. $kind = 0;
  1020. $itemStat = [];
  1021. if (!empty($list)) {
  1022. $ids = array_column($list, 'productId');
  1023. $ids = array_filter(array_unique($ids));
  1024. $productInfo = ProductClass::getByIds($ids, null, 'id');
  1025. foreach ($list as $key => $val) {
  1026. $productId = $val['productId'] ?? 0;
  1027. $currentInfo = $productInfo[$productId];
  1028. $currentPrice = $productInfo[$productId]['price'] ?? 0;
  1029. $unitPrice = isset($val['xhUnitPrice']) ? floatval($val['xhUnitPrice']) : 0;
  1030. $list[$key]['currentHdPrice'] = $unitPrice;
  1031. //原有售价
  1032. $list[$key]['itemSalePrice'] = floatval($currentPrice);
  1033. //自己填的价格
  1034. $list[$key]['itemModifyPrice'] = $unitPrice;
  1035. $list[$key]['property'] = '';
  1036. $list[$key]['cost'] = $currentInfo['cost'] ?? 0;
  1037. $list[$key]['stock'] = $currentInfo['stock'] ? floatval($currentInfo['stock']) : 0;
  1038. $price = $val['price'];
  1039. $totalPrice = stringUtil::calcAdd($totalPrice, $price);
  1040. $kind++;
  1041. $currentBigNum = $val['bigNum'] ?? 0;
  1042. $currentSmallNum = $val['smallNum'] ?? 0;
  1043. $currentGiveNum = $val['giveNum'] ?? 0;
  1044. $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
  1045. $totalBigNum = bcadd($totalBigNum, $currentGiveNum);
  1046. $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
  1047. }
  1048. $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
  1049. }
  1050. return ['list' => $list, 'itemStat' => $itemStat];
  1051. }
  1052. public static function getShowItem($showItem, $order)
  1053. {
  1054. if ($showItem == false) {
  1055. return ['list' => [], 'itemStat' => []];
  1056. }
  1057. $orderSn = $order['orderSn'];
  1058. $list = OrderItemClass::getOrderItem($orderSn);
  1059. $totalPrice = 0;
  1060. $totalBigNum = 0;
  1061. $totalSmallNum = 0;
  1062. $kind = 0;
  1063. $itemStat = [];
  1064. //小菊增加部分
  1065. $xjAddList = [];
  1066. if (!empty($list)) {
  1067. foreach ($list as $key => $val) {
  1068. $price = $val['price'];
  1069. $totalPrice = stringUtil::calcAdd($totalPrice, $price);
  1070. $kind++;
  1071. $currentBigNum = $val['bigNum'];
  1072. $currentSmallNum = $val['smallNum'];
  1073. $unitType = $val['xhUnitType'] ?? 0;
  1074. $refundNum = $val['refundNum'] ?? 0;
  1075. if ($unitType == 0) {
  1076. $currentBigNum = bcsub($currentBigNum, $refundNum);
  1077. } else {
  1078. $currentSmallNum = bcsub($currentSmallNum, $refundNum);
  1079. }
  1080. $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
  1081. $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
  1082. //赠送数量
  1083. $giveNum = $val['giveNum'] ?? 0;
  1084. $totalBigNum = bcadd($totalBigNum, $giveNum);
  1085. $list[$key]['property'] = '';
  1086. //小菊
  1087. if (isset($val['variety']) && $val['variety'] == 1) {
  1088. $currentItemId = $val['id'] ?? 0;
  1089. $xjList = OrderXjClass::getAllByCondition(['itemId' => $currentItemId], null, '*');
  1090. if (!empty($xjList)) {
  1091. //选了有颜色的小菊才把原小菊删除不显示出来
  1092. unset($list[$key]);
  1093. foreach ($xjList as $xjKey => $xj) {
  1094. $xjBase = $val;
  1095. $num = $xj['num'] ?? 0;
  1096. $price = $xj['price'] ?? 0;
  1097. $name = $xj['name'] ?? '';
  1098. $cover = $xj['cover'] ?? '';
  1099. if ($num > 0) {
  1100. $bigTotalPrice = bcmul($price, $num, 2);
  1101. $xjBase['cover'] = imgUtil::groupImg($cover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  1102. $xjBase['bigCover'] = imgUtil::groupImg($cover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  1103. $xjBase['unitPrice'] = $price;
  1104. $xjBase['price'] = floatval($bigTotalPrice);
  1105. $xjBase['num'] = floatval($num);
  1106. $xjBase['bigNum'] = floatval($num);
  1107. $xjBase['name'] = $name;
  1108. $xjBase['property'] = '';
  1109. $xjBase['userPrice'] = $bigTotalPrice;
  1110. $xjBase['xhNum'] = floatval($num);
  1111. $xjBase['xhPreNum'] = floatval($num);
  1112. $xjBase['xhPrice'] = floatval($bigTotalPrice);
  1113. $xjAddList[] = $xjBase;
  1114. }
  1115. }
  1116. }
  1117. }
  1118. }
  1119. if (!empty($xjAddList)) {
  1120. $list = array_merge($list, $xjAddList);
  1121. }
  1122. $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
  1123. }
  1124. return ['list' => $list, 'itemStat' => $itemStat];
  1125. }
  1126. //订单列表 ssh 2021.1.19
  1127. public static function getOrderList($where)
  1128. {
  1129. $data = self::getList('*', $where, 'addTime DESC');
  1130. $data['totalActPrice'] = 0;
  1131. $data['totalTkPrice'] = 0;
  1132. if (isset($data['list']) && !empty($data['list'])) {
  1133. foreach ($data['list'] as $key => $val) {
  1134. //同个人同地址当天订单数
  1135. $sameTimeIds = $val['sameTimeIds'] ?? '';
  1136. $sameNum = 0;
  1137. if (!empty($sameTimeIds)) {
  1138. $sameIds = explode(',', $sameTimeIds);
  1139. $sameNum = count($sameIds);
  1140. }
  1141. $data['list'][$key]['sameTimeIdsNum'] = $sameNum;
  1142. $data['list'][$key]['customAvatarUrl'] = imgUtil::groupImg('');
  1143. }
  1144. }
  1145. return $data;
  1146. }
  1147. //整合订单员工和供货商等信息 ssh 2021.1.19
  1148. //$isList 是否列表页
  1149. public static function groupOrder($list, $showButton = false, $showItem = false, $showExpress = false, $isList = false)
  1150. {
  1151. if (empty($list)) {
  1152. return $list;
  1153. }
  1154. $adminIds = array_unique(array_filter(array_column($list, 'adminId')));
  1155. $adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id');
  1156. $customIds = array_column($list, 'customId');
  1157. $customIds = array_unique(array_filter($customIds));
  1158. $customInfoList = CustomClass::getByIds($customIds, null, 'id');
  1159. foreach ($list as $key => $val) {
  1160. $adminId = $val['adminId'] ?? 0;
  1161. $list[$key]['adminName'] = $adminInfo[$adminId]['name'] ?? '';
  1162. $list[$key]['customAddress'] = $val['fullAddress'] ?? '';
  1163. //显示列表页的操作按钮
  1164. $list[$key]['buttonList'] = self::getShowButton($showButton, $isList, $val);
  1165. //为了列表页的打印按钮能用,列表也强制显示花材
  1166. $showItem = true;
  1167. //退款需要显示原有的花材结构,不显示小菊的多颜色
  1168. $getOriginalItem = Yii::$app->request->get('getOriginalItem', 0);
  1169. $getOriginalItem2 = Yii::$app->request->post('getOriginalItem', 0);
  1170. if ($getOriginalItem == 1 || $getOriginalItem2 == 1) {
  1171. $showItemData = self::getOriginalShowItem($showItem, $val);
  1172. } else {
  1173. $showItemData = self::getShowItem($showItem, $val);
  1174. }
  1175. $list[$key]['product'] = $showItemData['list'];
  1176. $list[$key]['productStat'] = $showItemData['itemStat'];
  1177. $showResetItem = 0;
  1178. //待付款订单显示改花材按钮
  1179. if ($val['status'] == self::PAY_STATUS_UN_PAY) {
  1180. $showResetItem = 1;
  1181. }
  1182. $list[$key]['showResetItem'] = $showResetItem;
  1183. //获取配送进展
  1184. $expressProgress = '';
  1185. if ($val['sendType'] == 4) {
  1186. $expressInfo = OrderExpressClass::getByCondition(['orderSn' => $val['orderSn']]);
  1187. if ($expressInfo) {
  1188. $expressProgress = ['progressName' => OrderExpressClass::$statusMap[$expressInfo['status']] ?? ''];
  1189. }
  1190. }
  1191. $list[$key]['sendTypeName'] = self::$sendTypeMap[$val['sendType']] ?? '未知';
  1192. $list[$key]['expressProgress'] = $expressProgress;
  1193. $list[$key]['customAvatarUrl'] = imgUtil::groupImg($val['customAvatar']);
  1194. $list[$key]['customName'] = isset($val['customId']) && !empty($val['customId']) ? $val['customName'] : '散客';
  1195. $customId = $val['customId'] ?? '';
  1196. $debtAmount = $customInfoList[$customId]['debtAmount'] ?? 0.00;
  1197. //打印数据组合
  1198. $printData = self::getPrintData($val, $debtAmount, $showItemData);
  1199. $list[$key]['printData'] = json_encode($printData);
  1200. $list[$key]['debtAmount'] = $debtAmount;
  1201. $list[$key]['customShopId'] = $customInfoList[$customId]['shopId'] ?? 0;
  1202. }
  1203. return $list;
  1204. }
  1205. public static function printGroup($current, $content, $showPrice = 1, $fontSizeType = 0)
  1206. {
  1207. //58mm的机器,一行打印16个汉字,32个字母
  1208. $productPrice = $current['price'] ?? '';
  1209. $name = $current['name'] ?? '';
  1210. if (floatval($productPrice) == 0.01) {
  1211. $name = $name . '(送)';
  1212. }
  1213. $productNum = $current['num'] ?? '';
  1214. $itemNum = $current['itemNum'] ?? 0;
  1215. $refundNum = $current['refundNum'] ?? 0;
  1216. $unitName = $current['unitName'] ?? '扎';
  1217. $remark = $current['remark'] ?? '';
  1218. $lastNum = bcsub($itemNum, $refundNum);
  1219. if (!empty($remark)) {
  1220. $show = $name . ' ' . $lastNum . $unitName . "【" . $remark . "】";
  1221. } else {
  1222. $show = $name . ' ' . $lastNum . $unitName;
  1223. }
  1224. $content .= '<B>' . $show . '</B><BR>';
  1225. if ($refundNum > 0) {
  1226. $content .= '(买' . $itemNum . $unitName . ' 退' . $refundNum . $unitName . ')<BR>';
  1227. }
  1228. if ($showPrice == 1) {
  1229. $content .= $productNum . ' = ' . $productPrice . '元<BR>';
  1230. }
  1231. $content .= '--------------------------------<BR>';
  1232. return $content;
  1233. }
  1234. //合并打印订单 ssh 20230929
  1235. public static function mergePrintOrder($ids, $mainId)
  1236. {
  1237. $all = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1238. if (empty($all)) {
  1239. util::fail('没有找到订单');
  1240. }
  1241. $snList = [];
  1242. $sendNumList = [];
  1243. $remarkList = [];
  1244. foreach ($all as $info) {
  1245. if ($info->mainId != $mainId) {
  1246. util::fail('不是你的订单');
  1247. }
  1248. $orderSn = $info->orderSn;
  1249. if ($info->payStatus == 1) {
  1250. $snList[] = $orderSn;
  1251. $orderInfo = $info;
  1252. $sendNumList[] = $info->sendNum;
  1253. if (!empty($info->remark)) {
  1254. $remarkList[] = $info->remark;
  1255. }
  1256. }
  1257. }
  1258. $sendNumString = '';
  1259. if (!empty($sendNumList)) {
  1260. $sendNumString = implode(',', $sendNumList);
  1261. }
  1262. $remarkString = '';
  1263. if (!empty($remarkList)) {
  1264. $remarkString = implode(',', $remarkList);
  1265. }
  1266. $allItem = OrderItemClass::getAllByCondition(['orderSn' => ['in', $snList]], null, '*');
  1267. if (empty($allItem)) {
  1268. util::fail('没有花材信息');
  1269. }
  1270. $new = [];
  1271. foreach ($allItem as $currentItem) {
  1272. $unitType = $currentItem['xhPreUnitType'] ?? 1;
  1273. $productId = $currentItem['productId'] ?? 0;
  1274. if ($unitType == 0 && $productId > 0) {
  1275. if (isset($new[$productId])) {
  1276. $xhNum = $currentItem['xhNum'] ?? 0;
  1277. $refundNum = $currentItem['refundNum'] ?? 0;
  1278. $giveNum = $currentItem['giveNum'] ?? 0;
  1279. $new[$productId]['xhNum'] = bcadd($new[$productId]['xhNum'], $xhNum);
  1280. $new[$productId]['refundNum'] = bcadd($new[$productId]['refundNum'], $refundNum);
  1281. $new[$productId]['giveNum'] = bcadd($new[$productId]['giveNum'], $giveNum);
  1282. } else {
  1283. $new[$productId] = $currentItem;
  1284. }
  1285. }
  1286. }
  1287. $showPrice = 1;
  1288. $customId = $orderInfo->customId ?? 0;
  1289. $c = CustomClass::getById($customId);
  1290. $debtAmount = $c['debtAmount'] ?? 0.00;
  1291. $shopId = $orderInfo->shopId ?? 0;
  1292. $shop = ShopClass::getById($shopId, true);
  1293. if (empty($shop)) {
  1294. util::fail('打印失败,没有找到门店9');
  1295. }
  1296. $sjId = $shop->sjId ?? 0;
  1297. $fontSizeType = $shop->fontSize ?? 0;
  1298. $telephone = $shop->telephone ?? '';
  1299. $sj = SjClass::getById($sjId, true);
  1300. $sjName = $sj->name ?? '';
  1301. $shopName = $shop->shopName ?? '';
  1302. $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1303. $fromType = $orderInfo->fromType ?? dict::getDict('fromType', 'shop');
  1304. $fromTypeMap = dict::getDict('fromTypeMap');
  1305. $fromTypeName = $fromTypeMap[$fromType] ?? '门店';
  1306. $content = "<CB>" . $currentName . "</CB>";
  1307. $content .= "<CB>销售单</CB><BR><BR>";
  1308. $content .= '<B>' . $sendNumString . ' ' . $fromTypeName . '</B><BR>';
  1309. $content .= '--------------------------------<BR>';
  1310. //快捷开单不需要打印买家信息
  1311. if ($customId != $shop->skCustomId) {
  1312. $content .= '<B>买家信息:</B><BR><BR>';
  1313. $content .= '<B>' . $orderInfo->customName . '</B><BR>';
  1314. $content .= '<B>' . $orderInfo->customMobile . '</B><BR>';
  1315. if (isset($orderInfo->address) && !empty($orderInfo->address)) {
  1316. $content .= $orderInfo->fullAddress;
  1317. if (isset($orderInfo->showAddress) && !empty($orderInfo->showAddress)) {
  1318. $content .= '(' . $orderInfo->showAddress . ')<BR>';
  1319. } else {
  1320. $content .= '<BR>';
  1321. }
  1322. }
  1323. }
  1324. if (isset($orderInfo->book) && $orderInfo->book == 1) {
  1325. $content .= '<B>预订单</B><BR>';
  1326. }
  1327. if (isset($orderInfo->presell) && $orderInfo->presell == 1) {
  1328. $content .= '<B>预售单</B><BR>';
  1329. }
  1330. if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
  1331. if (isset($orderInfo->transType)) {
  1332. $sendName = '同城配送';
  1333. if ($orderInfo->transType == 0) {
  1334. $sendName = '德邦物流';
  1335. }
  1336. if ($orderInfo->transType == 1) {
  1337. $sendName = '顺丰物流';
  1338. }
  1339. if ($orderInfo->transType == 2) {
  1340. $sendName = '冷链物流';
  1341. }
  1342. if ($orderInfo->transType == 3) {
  1343. $sendName = '航空物流';
  1344. }
  1345. if ($orderInfo->transType == 4) {
  1346. $sendName = '同城配送';
  1347. }
  1348. if ($orderInfo->transType == 5) {
  1349. $sendName = '到店自取';
  1350. }
  1351. $content .= '<BR><B>' . $sendName . '</B><BR>';
  1352. }
  1353. } else {
  1354. if (isset($orderInfo->sendType)) {
  1355. $sendName = '送货上门';
  1356. if ($orderInfo->sendType == 1) {
  1357. $sendName = '到店自取';
  1358. }
  1359. if ($orderInfo->sendType == 2) {
  1360. $sendName = '代叫配送';
  1361. }
  1362. if ($orderInfo->sendType == 3) {
  1363. $wlName = $orderInfo['wlName'] ?? '未填物流';
  1364. $sendName = $wlName;
  1365. }
  1366. if ($orderInfo->sendType == 4) {
  1367. $sendName = '发快递';
  1368. }
  1369. $content .= '<BR><B>' . $sendName . '</B><BR>';
  1370. }
  1371. }
  1372. if (!empty($remarkString)) {
  1373. $content .= '<BR>';
  1374. $content .= '备注:<BR>';
  1375. $content .= '<B>' . $remarkString . '</B><BR>';
  1376. }
  1377. $content .= '<BR>';
  1378. $content .= '商品 数量/单价 金额 <BR>';
  1379. $content .= '--------------------------------<BR>';
  1380. $totalNum = 0;
  1381. $refundTotalNum = 0;
  1382. foreach ($new as $current) {
  1383. //58mm的机器,一行打印16个汉字,32个字母
  1384. $productPrice = $current['xhUnitPrice'] ?? '';
  1385. $name = $current['name'] ?? '';
  1386. if (floatval($productPrice) == 0.01) {
  1387. $name = $name . '(送)';
  1388. }
  1389. $giveNum = $current['giveNum'] ?? 0;
  1390. $refundNum = $current['refundNum'] ?? 0;
  1391. $productNum = $current['xhNum'] ?? '';
  1392. $unitName = $current['xhUnitName'] ?? '扎';
  1393. $totalNum = bcadd($totalNum, $giveNum);
  1394. $refundTotalNum = bcadd($refundTotalNum, $refundNum);
  1395. $lastNum = bcadd($productNum, $giveNum);
  1396. $lastNum = bcsub($lastNum, $refundNum);
  1397. $show = $name . ' ' . $lastNum . $unitName;
  1398. $hint = '';
  1399. if ($refundNum > 0 || $giveNum > 0) {
  1400. $hint .= '(买' . $productNum . $unitName;
  1401. }
  1402. if ($refundNum > 0) {
  1403. $hint .= ' 退' . $refundNum . $unitName;
  1404. if ($giveNum <= 0) {
  1405. $hint .= ')';
  1406. }
  1407. }
  1408. if ($giveNum > 0) {
  1409. $hint .= ' 送' . $giveNum . $unitName . ')';
  1410. }
  1411. $content .= '<B>' . $show . '</B><BR>';
  1412. if (!empty($hint)) {
  1413. $content .= $hint . '<BR>';
  1414. }
  1415. $content .= '--------------------------------<BR>';
  1416. $totalNum = bcadd($totalNum, $productNum);
  1417. }
  1418. $content .= '********************************<BR>';
  1419. $kindNum = count($new);
  1420. $remainNum = bcsub($totalNum, $refundTotalNum);
  1421. $content .= "<CB>共{$kindNum}种";
  1422. $content .= ",{$remainNum}扎";
  1423. $content .= "</CB>";
  1424. $content .= '********************************<BR><BR>';
  1425. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  1426. $printSn = $ext['printSn'] ?? '';
  1427. if (!empty($printSn)) {
  1428. $p = new printUtil($printSn);
  1429. $p->printMsg($content, $shop);
  1430. }
  1431. foreach ($all as $info) {
  1432. if ($info->payStatus == 1) {
  1433. $info->printNum += 1;
  1434. $info->printStatus = 2;
  1435. $info->save();
  1436. }
  1437. }
  1438. }
  1439. //超出数量的打印 sssh 20240605
  1440. public static function onlinePrintOver($showItem, $orderInfo, $currentName, $shop)
  1441. {
  1442. $itemList = $showItem['list'];
  1443. $orderSn = $orderInfo->orderSn ?? '';
  1444. $arr = array_chunk($itemList, 40);
  1445. $totalPage = count($arr);
  1446. foreach ($arr as $key => $itemList) {
  1447. $content = '';
  1448. $content .= "<CB>{$currentName}</CB><BR>";
  1449. $content .= "<CB>销售单</CB><BR><BR>";
  1450. $content .= '<CB>' . $orderSn . '</CB><BR><BR>';
  1451. //快捷开单不需要打印买家信息
  1452. if ($orderInfo->customId != $shop->skCustomId) {
  1453. $content .= '<B>买家信息:</B><BR><BR>';
  1454. $content .= '<B>' . $orderInfo->customName . '</B><BR>';
  1455. $content .= '<B>' . $orderInfo->customMobile . '</B><BR>';
  1456. if (isset($orderInfo['address']) && !empty($orderInfo['address'])) {
  1457. $content .= $orderInfo->fullAddress;
  1458. if (isset($orderInfo['showAddress']) && !empty($orderInfo['showAddress']) && $orderInfo->fullAddress != $orderInfo['showAddress']) {
  1459. $content .= '(' . $orderInfo['showAddress'] . ')<BR><BR>';
  1460. } else {
  1461. $content .= '<BR><BR>';
  1462. }
  1463. }
  1464. }
  1465. if ($totalPage > 1) {
  1466. $currentPage = bcadd($key, 1);
  1467. $content .= "<CB>第{$currentPage}页,共{$totalPage}页</CB><BR>";
  1468. }
  1469. $content .= '<BR>';
  1470. $content .= '商品 数量 <BR>';
  1471. $content .= '--------------------------------<BR>';
  1472. if (isset($itemList) && !empty($itemList)) {
  1473. foreach ($itemList as $info) {
  1474. $name = $info['name'] ?? '';
  1475. $num = $info['xhNum'] ?? 0;
  1476. $refundNum = $info['refundNum'] ?? 0;
  1477. $lastNum = bcsub($num, $refundNum);
  1478. $unitName = $info['xhUnitName'] ?? '';
  1479. $show = $name . ' ' . $lastNum . $unitName;
  1480. $content .= '<B>' . $show . '</B><BR>';
  1481. $content .= '--------------------------------<BR>';
  1482. }
  1483. }
  1484. $kindNum = $showItem['itemStat']['kind'] ?? 0;
  1485. $bigNum = $showItem['itemStat']['bigNum'] ?? 0;
  1486. $smallNun = $showItem['itemStat']['smallNun'] ?? 0;
  1487. $content .= '********************************<BR>';
  1488. $content .= "<CB>共{$kindNum}种";
  1489. $content .= " 数量:";
  1490. if ($bigNum > 0) {
  1491. $content .= "{$bigNum}";
  1492. }
  1493. if ($smallNun > 0) {
  1494. $content .= "{$smallNun}";
  1495. }
  1496. $content .= "</CB>";
  1497. $content .= '********************************<BR><BR>';
  1498. $content .= '<BR>';
  1499. $content .= '<BR>';
  1500. $shopId = $shop->id;
  1501. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  1502. $printSn = $ext['printSn'] ?? '';
  1503. if (!empty($printSn)) {
  1504. $p = new printUtil($printSn);
  1505. $p->printMsg($content, $shop);
  1506. }
  1507. }
  1508. }
  1509. //云打印 ssh 20210709
  1510. public static function onlinePrint($orderInfo, $showPrice = 1)
  1511. {
  1512. if (getenv('YII_ENV') == 'production') {
  1513. //丽子鲜花,客户线上下单,小票上不显示价格
  1514. if (isset($orderInfo->shopId) && $orderInfo->shopId == 1527) {
  1515. if (isset($orderInfo->customShopAdminId) && !empty($orderInfo->customShopAdminId)) {
  1516. $showPrice = 0;
  1517. }
  1518. }
  1519. //源花汇小票不带价格
  1520. if (isset($orderInfo->mainId) && $orderInfo->mainId == 10536) {
  1521. $showPrice = 0;
  1522. }
  1523. //北京花篮子,线上下单,不显示价格
  1524. if (isset($orderInfo->mainId) && $orderInfo->mainId == 10735) {
  1525. if (isset($orderInfo->customShopAdminId) && !empty($orderInfo->customShopAdminId)) {
  1526. $showPrice = 0;
  1527. }
  1528. }
  1529. //淄博花超鲜花小票不带价格
  1530. if (isset($orderInfo->mainId) && $orderInfo->mainId == 16293) {
  1531. $showPrice = 0;
  1532. }
  1533. //淮北花语集小票不带价格
  1534. if (isset($orderInfo->mainId) && $orderInfo->mainId == 52291) {
  1535. $showPrice = 0;
  1536. }
  1537. } else {
  1538. if (isset($orderInfo->mainId) && $orderInfo->mainId == 644) {
  1539. //$showPrice = 0;
  1540. }
  1541. }
  1542. if (isset($orderInfo['actPrice']) && $orderInfo['actPrice'] == 0 && $orderInfo['book'] == 0) {
  1543. util::fail('已全额退款,不能打小票');
  1544. }
  1545. $showItem = OrderClass::getShowItem(true, $orderInfo);
  1546. $customId = $orderInfo['customId'] ?? 0;
  1547. $c = CustomClass::getById($customId);
  1548. $debtAmount = $c['debtAmount'] ?? 0.00;
  1549. $orderSn = $orderInfo['orderSn'] ?? '';
  1550. $shopId = $orderInfo['shopId'] ?? 0;
  1551. $shop = ShopClass::getById($shopId, true);
  1552. if (empty($shop)) {
  1553. util::fail('打印失败,没有找到门店10');
  1554. }
  1555. $sjId = $shop->sjId ?? 0;
  1556. $fontSizeType = $shop->fontSize ?? 0;
  1557. $telephone = $shop->telephone ?? '';
  1558. $telephone2 = $shop->telephone2 ?? '';
  1559. $sj = SjClass::getById($sjId, true);
  1560. $sjName = $sj->name ?? '';
  1561. $shopName = $shop->shopName ?? '';
  1562. $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1563. $itemList = $showItem['list'] ?? [];
  1564. if (count($itemList) > 40) {
  1565. //超出数量的打印
  1566. self::onlinePrintOver($showItem, $orderInfo, $currentName, $shop);
  1567. return true;
  1568. }
  1569. $fromType = $orderInfo['fromType'] ?? dict::getDict('fromType', 'shop');
  1570. $fromTypeMap = dict::getDict('fromTypeMap');
  1571. $fromTypeName = $fromTypeMap[$fromType] ?? '门店';
  1572. $content = "<CB>" . $currentName . "</CB>";
  1573. $content .= "<CB>销售单</CB><BR><BR>";
  1574. $respond = self::getPrintData($orderInfo, $debtAmount, $showItem);
  1575. $content .= '<B>' . $respond['sendNum'] . ' ' . $fromTypeName . '</B><BR>';
  1576. $content .= '--------------------------------<BR>';
  1577. //快捷开单不需要打印买家信息
  1578. if ($customId != $shop->skCustomId) {
  1579. $content .= '<B>买家信息:</B><BR><BR>';
  1580. $content .= '<B>' . $respond['custom']['customName'] . '</B><BR>';
  1581. $content .= '<B>' . $respond['custom']['customMobile'] . '</B><BR>';
  1582. if (isset($orderInfo['address']) && !empty($orderInfo['address'])) {
  1583. $content .= $respond['custom']['fullAddress'];
  1584. if (isset($orderInfo['showAddress']) && !empty($orderInfo['showAddress']) && $orderInfo['showAddress'] != $respond['custom']['fullAddress']) {
  1585. $content .= '(' . $orderInfo['showAddress'] . ')<BR>';
  1586. } else {
  1587. $content .= '<BR>';
  1588. }
  1589. }
  1590. }
  1591. $payDate = date("Y-m-d", strtotime($orderInfo['payTime']));
  1592. $sendTimWant = $orderInfo['sendTimeWant'] ?? '';
  1593. if ($payDate != $sendTimWant) {
  1594. $content .= '<BR>';
  1595. $content .= '送货时间:<BR>';
  1596. $content .= '<B>' . $orderInfo['sendTimeWant'] . '</B><BR>';
  1597. }
  1598. if (isset($orderInfo['book']) && $orderInfo['book'] == 1) {
  1599. $content .= '<B>预订单</B><BR>';
  1600. }
  1601. if (isset($orderInfo['presell']) && $orderInfo['presell'] == 1) {
  1602. $content .= '<B>预售单</B><BR>';
  1603. }
  1604. if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
  1605. if (isset($orderInfo['transType'])) {
  1606. $sendName = '同城配送';
  1607. if ($orderInfo['transType'] == 0) {
  1608. $sendName = '德邦物流';
  1609. }
  1610. if ($orderInfo['transType'] == 1) {
  1611. $sendName = '顺丰物流';
  1612. }
  1613. if ($orderInfo['transType'] == 2) {
  1614. $sendName = '冷链物流';
  1615. }
  1616. if ($orderInfo['transType'] == 3) {
  1617. $sendName = '航空物流';
  1618. }
  1619. if ($orderInfo['transType'] == 4) {
  1620. $sendName = '同城配送';
  1621. }
  1622. if ($orderInfo['transType'] == 5) {
  1623. $sendName = '到店自取';
  1624. }
  1625. $content .= '<BR><B>' . $sendName . '</B><BR>';
  1626. }
  1627. } else {
  1628. if (isset($orderInfo['sendType'])) {
  1629. $sendName = '送货上门';
  1630. if ($orderInfo['sendType'] == 1) {
  1631. $sendName = '到店自取';
  1632. }
  1633. if ($orderInfo['sendType'] == 2) {
  1634. $sendName = '代叫配送';
  1635. }
  1636. if ($orderInfo['sendType'] == 3) {
  1637. $wlName = $orderInfo['wlName'] ?? '未填物流';
  1638. $sendName = $wlName;
  1639. }
  1640. if ($orderInfo['sendType'] == 4) {
  1641. $sendName = '发快递';
  1642. }
  1643. $content .= '<BR><B>' . $sendName . '</B><BR>';
  1644. }
  1645. }
  1646. if (isset($respond['remark']) && !empty($respond['remark'])) {
  1647. $content .= '<BR>';
  1648. $content .= '备注:<BR>';
  1649. $content .= '<B>' . $respond['remark'] . '</B><BR>';
  1650. }
  1651. $content .= '<BR>';
  1652. $content .= '商品 数量/单价 金额 <BR>';
  1653. $content .= '--------------------------------<BR>';
  1654. if (isset($respond['product']) && !empty($respond['product'])) {
  1655. foreach ($respond['product'] as $current) {
  1656. $content = self::printGroup($current, $content, $showPrice, $fontSizeType);
  1657. }
  1658. }
  1659. if (isset($respond['give']) && !empty($respond['give'])) {
  1660. $content .= '<BR><CB>【赠送】</CB><BR>';
  1661. foreach ($respond['give'] as $current) {
  1662. //58mm的机器,一行打印16个汉字,32个字母
  1663. $name = $current['name'] ?? '';
  1664. $count = $current['count'] ?? '';
  1665. $content .= '<B>' . $name . ' ' . $count . '</B><BR>';
  1666. $content .= '--------------------------------<BR>';
  1667. }
  1668. }
  1669. $kindNum = $showItem['itemStat']['kind'] ?? 0;
  1670. $bigNum = $showItem['itemStat']['bigNum'] ?? 0;
  1671. $smallNun = $showItem['itemStat']['smallNun'] ?? 0;
  1672. $content .= '********************************<BR>';
  1673. $content .= "<CB>共{$kindNum}种 ";
  1674. if ($bigNum > 0) {
  1675. $content .= "{$bigNum}扎";
  1676. }
  1677. if ($smallNun > 0) {
  1678. $content .= "{$smallNun}支";
  1679. }
  1680. $content .= "</CB>";
  1681. $content .= '********************************<BR><BR>';
  1682. if ($showPrice == 1) {
  1683. if (isset($orderInfo['itemPrice']) && $orderInfo['itemPrice'] > 0) {
  1684. $content .= '商品金额:' . floatval($orderInfo['itemPrice']) . '<BR>';
  1685. }
  1686. if (isset($respond['sendCost']) && $respond['sendCost'] > 0) {
  1687. $content .= ' 运费:' . floatval($respond['sendCost']) . '<BR>';
  1688. }
  1689. if (isset($orderInfo['packCost']) && $orderInfo['packCost'] > 0) {
  1690. $content .= ' 打包费:' . floatval($orderInfo['packCost']) . '<BR>';
  1691. }
  1692. $content .= '合计金额:' . floatval($respond['prePrice']) . '<BR>';
  1693. if (isset($respond['discountAmount']) && !empty($respond['discountAmount']) && $respond['discountAmount'] > 0) {
  1694. $content .= '优惠扣除:-' . floatval($respond['discountAmount']) . '<BR>';
  1695. }
  1696. if (isset($orderInfo['book']) && $orderInfo['book'] == 1) {
  1697. $content .= '预付金额:' . floatval($orderInfo['bookPrice']) . '<BR>';
  1698. }
  1699. if (isset($orderInfo['tkPrice']) && $orderInfo['tkPrice'] > 0) {
  1700. $content .= '退款金额:' . floatval($orderInfo['tkPrice']) . '<BR>';
  1701. }
  1702. $content .= '<B>订单金额:' . floatval($respond['realPrice']) . '</B><BR>';
  1703. if (isset($respond['debt']) && $respond['debt'] == 1) {
  1704. $content .= '实付金额:0<BR>';
  1705. } else {
  1706. $content .= '实付金额:' . floatval($respond['realPrice']) . '<BR>';
  1707. }
  1708. if ($debtAmount > 0) {
  1709. $content .= '累计赊账:' . floatval($debtAmount) . '<BR>';
  1710. }
  1711. $content .= '--------------------------------<BR>';
  1712. }
  1713. $getInfo = self::getById($orderInfo['id']);
  1714. if (!empty($telephone)) {
  1715. $content .= '联系电话:' . $telephone . '<BR>';
  1716. }
  1717. if (!empty($telephone2)) {
  1718. $content .= '联系电话2:' . $telephone2 . '<BR>';
  1719. }
  1720. $content .= '订单日期:' . date("Y-m-d H:i", strtotime($getInfo['addTime'])) . '<BR>';
  1721. $content .= '订单编号:' . $respond['orderSn'] . '<BR>';
  1722. if (isset($orderInfo['shopAdminId']) && !empty($orderInfo['shopAdminId'])) {
  1723. $content .= '本单由员工(' . $orderInfo['shopAdminName'] . ')开单<BR>';
  1724. } else {
  1725. $content .= '本单由客户(' . $orderInfo['customShopAdminName'] . ')下单<BR>';
  1726. }
  1727. $content .= "<BR>";
  1728. if (getenv('YII_ENV') == 'production') {
  1729. //丽子鲜花、花样年华、镜中花卉、满天星、世纪花、盛丰、福清辉煌、美阁都不显示扫码买花
  1730. if (!in_array($orderInfo->shopId, [1527, 1585, 1596, 16454, 33668, 38492, 36596, 35389, 38322, 43274, 40312, 44556, 42946, 51758, 8391])) {
  1731. //勇记、国恋、花悠星零售开单不需要打印扫码买花
  1732. if ($customId != 12145 || $customId != 12487 || $customId != 12281) {
  1733. $content .= "<BR>";
  1734. $content .= "<C>扫码买花结账</C>";
  1735. $content .= "<BR>";
  1736. $host = Yii::$app->params['hdHost'];
  1737. $content .= "<QR>" . $host . "/#/admin/home/workbench</QR>";
  1738. }
  1739. }
  1740. }
  1741. $content .= "<BR>";
  1742. $content .= "<BR>";
  1743. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  1744. $printSn = $ext['printSn'] ?? '';
  1745. if (!empty($printSn)) {
  1746. $p = new printUtil($printSn);
  1747. $p->printMsg($content, $shop, $orderSn);
  1748. }
  1749. }
  1750. //打印数据 ssh 20210702
  1751. public static function getPrintData($val, $debtAmount, $showItem)
  1752. {
  1753. $giveList = [];
  1754. $printProduct = [];
  1755. if (isset($showItem['list']) && !empty($showItem['list'])) {
  1756. foreach ($showItem['list'] as $itemKey => $itemVal) {
  1757. $bigNum = $itemVal['bigNum'] ?? 0;
  1758. $bigUnitPrice = $itemVal['unitPrice'] ?? 0;
  1759. $smallUnitPrice = $itemVal['smallUnitPrice'] ?? 0;
  1760. $smallNum = $itemVal['smallNum'] ?? 0;
  1761. $giveNum = $itemVal['giveNum'] ?? 0;
  1762. $xhUnitName = $itemVal['xhUnitName'] ?? '扎';
  1763. $refundNum = $itemVal['refundNum'] ?? 0;
  1764. $remark = $itemVal['remark'] ?? '';
  1765. if ($bigNum > 0) {
  1766. $bigTotalPrice = bcmul($bigUnitPrice, $bigNum, 2);
  1767. $printProduct[] = [
  1768. 'name' => $itemVal['name'] ?? '',
  1769. 'num' => floatval($bigNum) . $xhUnitName . ' * ' . floatval($bigUnitPrice) . '元',
  1770. 'count' => floatval($bigNum) . $xhUnitName,
  1771. 'price' => floatval($bigTotalPrice),
  1772. 'refundNum' => $refundNum,
  1773. 'unitName' => $xhUnitName,
  1774. 'itemNum' => $bigNum,
  1775. 'remark' => $remark,
  1776. ];
  1777. }
  1778. if ($smallNum > 0) {
  1779. $smallTotalPrice = bcmul($smallUnitPrice, $smallNum, 2);
  1780. $printProduct[] = [
  1781. 'name' => $itemVal['name'] ?? '',
  1782. 'num' => floatval($smallNum) . '支 * ' . floatval($smallUnitPrice) . '元',
  1783. 'count' => floatval($smallNum) . '支',
  1784. 'price' => floatval($smallTotalPrice),
  1785. 'refundNum' => $refundNum,
  1786. 'unitName' => '支',
  1787. 'itemNum' => $smallNum,
  1788. 'remark' => $remark,
  1789. ];
  1790. }
  1791. if ($giveNum > 0) {
  1792. $giveList[] = [
  1793. 'name' => $itemVal['name'] ?? '',
  1794. 'num' => floatval($giveNum) . $xhUnitName . ' * 0元',
  1795. 'count' => floatval($giveNum) . $xhUnitName,
  1796. 'price' => 0,
  1797. 'unitName' => $xhUnitName,
  1798. 'itemNum' => $giveNum,
  1799. 'remark' => $remark,
  1800. ];
  1801. }
  1802. }
  1803. }
  1804. $sendNum = $val['sendNum'] ?? '';
  1805. $relateOrderSn = $val['orderSn'] ?? '';
  1806. $refundList = [];
  1807. $refundData = RefundOrderClass::getAllByCondition(['relateOrderSn' => $relateOrderSn], null, '*', null, true);
  1808. if (!empty($refundData)) {
  1809. foreach ($refundData as $refund) {
  1810. $refundOrderSn = $refund->orderSn ?? '';
  1811. $refundProductList = RefundOrderItemClass::getAllByCondition(['orderSn' => $refundOrderSn], null, '*');
  1812. if (!empty($refundProductList)) {
  1813. foreach ($refundProductList as $currentRefund) {
  1814. $num = $currentRefund['xhNum'] ?? 0;
  1815. $unitName = $currentRefund['xhUnitName'] ?? '';
  1816. $unitPrice = $currentRefund['xhUnitPrice'] ?? 0;
  1817. $currentPrice = bcmul($unitPrice, $num, 2);
  1818. $refundList[] = [
  1819. 'name' => $currentRefund['name'] ?? '',
  1820. 'num' => floatval($num) . $unitName . '*' . floatval($unitPrice),
  1821. 'count' => floatval($num) . $unitName,
  1822. 'price' => floatval($currentPrice),
  1823. ];
  1824. }
  1825. }
  1826. }
  1827. }
  1828. $printData = [
  1829. 'address' => '',
  1830. 'sendCost' => $val['sendCost'] ?? '0.00',
  1831. 'prePrice' => $val['prePrice'] ?? '0.00',
  1832. 'discountAmount' => $val['discountAmount'] ?? '0.00',
  1833. 'realPrice' => $val['realPrice'] ?? '0.00',
  1834. 'refundPrice' => $val['refundPrice'] ?? '0.00',
  1835. 'debt' => $val['debt'] ?? 0,
  1836. 'orderSn' => $val['orderSn'] ?? '',
  1837. 'date' => $val['addTime'] ?? '',
  1838. 'remark' => $val['remark'] ?? '',
  1839. 'custom' => [
  1840. 'customName' => $val['customName'] ?? '',
  1841. 'customMobile' => $val['customMobile'] ?? '',
  1842. 'fullAddress' => $val['fullAddress'] ?? '',
  1843. ],
  1844. 'product' => $printProduct,
  1845. 'refund' => $refundList,
  1846. 'sendNum' => $sendNum,
  1847. 'debtAmount' => $debtAmount,
  1848. 'give' => $giveList,
  1849. ];
  1850. return $printData;
  1851. }
  1852. //订单的验证 ssh 2021.3.2
  1853. public static function valid($info, $shopId)
  1854. {
  1855. if (empty($info)) {
  1856. util::fail('没有找到订单');
  1857. }
  1858. if (isset($info['shopId']) && $info['shopId'] == $shopId) {
  1859. return true;
  1860. }
  1861. util::fail('无法操作的订单');
  1862. }
  1863. //快递送 ssh 2021.3.16
  1864. public static function thirdSend($order, $expressInfo)
  1865. {
  1866. if ($order->status == self::ORDER_STATUS_UN_PAY) {
  1867. util::fail('订单未付款');
  1868. }
  1869. if ($order->status != self::ORDER_STATUS_UN_SEND) {
  1870. util::fail('不是待配送状态');
  1871. }
  1872. $id = $order->id;
  1873. $expressId = $expressInfo['expressId'] ?? 1;
  1874. $expressName = $expressInfo['deliveryName'] ?? '达达';
  1875. $expressRemark = $expressInfo['remark'] ?? '';
  1876. $order->status = self::ORDER_STATUS_SENDING;
  1877. $order->sendType = self::SEND_TYPE_THIRD;
  1878. $order->expressId = $expressId;
  1879. $order->save();
  1880. $shopId = $order->shopId;
  1881. $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
  1882. if (empty($shop)) {
  1883. util::fail('没有找到门店11');
  1884. }
  1885. $shop->unSendOrder -= 1;
  1886. $shop->sendingOrder += 1;
  1887. $shop->save();
  1888. $express = OrderExpressClass::getByCondition(['orderId' => $id]);
  1889. if (!empty($express)) {
  1890. util::fail('已经发过了');
  1891. }
  1892. //达达
  1893. $dadaRes = DadaExpressServices::addOrder($order, $expressRemark);
  1894. $orderSn = $order->orderSn;
  1895. $sjId = $order->sjId ?? 0;
  1896. /*
  1897. $getInfo = ExpressClass::getExpressInfo($expressId);
  1898. $hour = $expressInfo['sendTime'] ?? '12:00';
  1899. $sendCost = 12;
  1900. $distance = 5;
  1901. $sendTime = strtotime(date("Y-m-d ") . $hour);
  1902. OrderSendClass::thirdSend($order);
  1903. */
  1904. $sendTime = $order->sendTime;
  1905. if ($sendTime == '0000-00-00 00:00:00') {
  1906. $sendTime = time();
  1907. } else {
  1908. $sendTime = strtotime($order->sendTime);
  1909. }
  1910. $expData = [
  1911. 'orderId' => $id,
  1912. 'orderSn' => $orderSn,
  1913. 'sjId' => $sjId,
  1914. 'expressId' => $expressId,
  1915. 'sendTime' => $sendTime,
  1916. 'cost' => $dadaRes['fee'],
  1917. 'distance' => $dadaRes['distance'],
  1918. 'status' => 1,
  1919. 'expressName' => $expressName,
  1920. 'remark' => $expressRemark,
  1921. ];
  1922. OrderExpressClass::addExpress($expData);
  1923. OrderSendClass::thirdSend($order);
  1924. $respond = [
  1925. 'expressName' => $expressName,
  1926. 'expressId' => $expressId,
  1927. 'distance' => $dadaRes['distance'],
  1928. 'cost' => $dadaRes['fee'],
  1929. 'status' => 2,
  1930. 'tip' => 0,
  1931. ];
  1932. //采购单变成已发货
  1933. $purchaseId = $order->purchaseId ?? 0;
  1934. PurchaseClass::sending($purchaseId);
  1935. return $respond;
  1936. }
  1937. //本店送 ssh 2021.1.24
  1938. public static function selfSend($info)
  1939. {
  1940. if ($info->status == self::ORDER_STATUS_UN_PAY) {
  1941. util::fail('订单未付款');
  1942. }
  1943. if ($info->status != self::ORDER_STATUS_UN_SEND) {
  1944. util::fail('不是待配送状态');
  1945. }
  1946. $info->status = self::ORDER_STATUS_SENDING;
  1947. $info->sendType = self::SEND_TYPE_MYSELF;
  1948. $info->save();
  1949. $shopId = $info->shopId;
  1950. $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
  1951. if (empty($shop)) {
  1952. util::fail('没有找到门店12');
  1953. }
  1954. $shop->unSendOrder -= 1;
  1955. $shop->sendingOrder += 1;
  1956. $shop->save();
  1957. OrderSendClass::selfSend($info);
  1958. //采购单变成已发货
  1959. $purchaseId = $info->purchaseId ?? 0;
  1960. PurchaseClass::sending($purchaseId);
  1961. }
  1962. //订单完成 ssh 2020.3.12
  1963. public static function complete($order, $shop)
  1964. {
  1965. $order->status = OrderClass::ORDER_STATUS_COMPLETE;
  1966. $order->currentFlow = self::TOTAL_FLOW;
  1967. $order->totalFlow = self::TOTAL_FLOW;
  1968. $order->save();
  1969. $shop->finishOrder += 1;
  1970. $shop->sendingOrder -= 1;
  1971. $shop->save();
  1972. return $order;
  1973. }
  1974. //修改订单表的配送信息 lqh 2021.3.28
  1975. public static function updateCustomExpressInfo($id, $expressAddInfo)
  1976. {
  1977. $data = [
  1978. 'province' => $expressAddInfo['province'],
  1979. 'city' => $expressAddInfo['city'],
  1980. 'address' => $expressAddInfo['address'],
  1981. 'floor' => $expressAddInfo['floor'],
  1982. 'fullAddress' => $expressAddInfo['city'] . $expressAddInfo['address'] . $expressAddInfo['floor'],
  1983. 'lat' => $expressAddInfo['lat'],
  1984. 'long' => $expressAddInfo['long'],
  1985. 'sendTime' => $expressAddInfo['sendTime'],
  1986. ];
  1987. return self::updateById($id, $data);
  1988. }
  1989. //最客户最近的订单 ssh 2021.5.4
  1990. public static function getCustomOrder($id, $limit = 10, $order = null, $with = null)
  1991. {
  1992. $where = ['customId' => $id, 'payStatus' => 1];
  1993. return self::getLimitList('*', $where, $limit, $order, $with);
  1994. }
  1995. //销售单取消 ssh 2021.5.14
  1996. public static function cancel($id)
  1997. {
  1998. $order = self::getLockById($id);
  1999. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
  2000. util::fail("销售单{$id}不是待付款状态,无法取消");
  2001. }
  2002. $order->status = self::ORDER_STATUS_CANCEL;
  2003. $order->cancelTime = date("Y-m-d H:i:s");
  2004. $order->save();
  2005. $shopId = $order->shopId;
  2006. $shop = ShopClass::getLockById($shopId);
  2007. if (empty($shop)) {
  2008. util::fail('没有找到门店13');
  2009. }
  2010. $mainId = $shop->mainId ?? 0;
  2011. $main = MainClass::getLockById($mainId);
  2012. if (empty($main)) {
  2013. util::fail('没有main信息6');
  2014. }
  2015. $main->unPayOrder -= 1;
  2016. $main->cancelOrder += 1;
  2017. $main->save();
  2018. if ($order->book != 1) {
  2019. //非预订单库存回滚
  2020. $orderItem = OrderItemClass::getOrderItem($order->orderSn);
  2021. foreach ($orderItem as $v) {
  2022. $stockInfo = ProductClass::addStockByItemNum($v['productId'], $v['num']);
  2023. $recordData = [];
  2024. $recordData['sjId'] = $order->sjId;
  2025. $recordData['shopId'] = $shopId;
  2026. //增加中央ID
  2027. $recordData['mainId'] = ProductClass::getMainIdByProductId($v['productId']);
  2028. $recordData['itemId'] = $v['itemId'] ?? 0;
  2029. $recordData['itemNum'] = $v['num'];
  2030. $recordData['oldStock'] = $stockInfo['oldStock'];
  2031. $recordData['newStock'] = $stockInfo['newStock'];
  2032. $recordData['productId'] = $v['productId'];
  2033. $recordData['orderSn'] = $order->orderSn;
  2034. $recordData['relateName'] = $order->customName ?? '';
  2035. $recordData['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  2036. StockRecordClass::addSellStockOrderCancelRecord($recordData);
  2037. }
  2038. }
  2039. return $order;
  2040. }
  2041. //新订单入队列 ssh 20211012
  2042. public static function newOrderAddQueue($order)
  2043. {
  2044. $shopId = $order->shopId ?? 0;
  2045. if (empty($shopId)) {
  2046. return false;
  2047. }
  2048. $id = $order->id ?? 0;
  2049. if (empty($id)) {
  2050. return false;
  2051. }
  2052. $newOrderKey = 'ghsNewOrder_' . $shopId;
  2053. Yii::$app->redis->executeCommand('LPUSH', [$newOrderKey, $id]);
  2054. }
  2055. public static function createImgOrder($order, $shop, $staff, $all)
  2056. {
  2057. $staffName = $order->shopAdminName ?? '';
  2058. $shopName = $shop->shopName ?? '';
  2059. $sjName = $shop->merchantName ?? '';
  2060. $fullSjName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  2061. $customName = $order->customName ?? '';
  2062. $customId = $order->customId ?? 0;
  2063. $custom = CustomClass::getById($customId, true);
  2064. $debtAmount = $custom->debtAmount ?? 0;
  2065. $mainId = $order->mainId ?? 0;
  2066. $dir = Yii::getAlias('@app/web/html/' . $mainId . '/');
  2067. if (!file_exists($dir)) {
  2068. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  2069. mkdir($dir, 0700, true);
  2070. }
  2071. $payTime = $order->payTime ?? '';
  2072. $currentDate = date("Y-m-d", strtotime($payTime));
  2073. $sameTimeIds = $order->sameTimeIds;
  2074. $sameIds = [];
  2075. if (!empty($sameTimeIds)) {
  2076. $sameIds = explode(',', $sameTimeIds);
  2077. }
  2078. $sameNum = count($sameIds);
  2079. if ($all == 1 && $sameNum > 1) {
  2080. $orderList = OrderClass::getAllByCondition(['id' => ['in', $sameIds]], null, '*');
  2081. if (empty($orderList)) {
  2082. return ['imgFile' => ''];
  2083. }
  2084. $itemList = [];
  2085. $remainDebtPrice = 0;
  2086. $actPrice = 0;
  2087. $tkPrice = 0;
  2088. foreach ($orderList as $currentOrder) {
  2089. $orderSn = $currentOrder['orderSn'] ?? '';
  2090. $remainDebtPrice = bcadd($currentOrder['remainDebtPrice'], $remainDebtPrice, 2);
  2091. $actPrice = bcadd($currentOrder['actPrice'], $actPrice, 2);
  2092. $tkPrice = bcadd($tkPrice, $currentOrder['tkPrice'], 2);
  2093. $itemData = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], 'id asc', '*', null);
  2094. if (!empty($itemData)) {
  2095. foreach ($itemData as $singleItem) {
  2096. $productId = $singleItem['productId'] ?? 0;
  2097. $unitPrice = $singleItem['xhUnitPrice'] ?? 0;
  2098. $unitPrice = floatval($unitPrice);
  2099. $xhNum = $singleItem['xhNum'] ?? 0;
  2100. $refundNum = $singleItem['refundNum'] ?? 0;
  2101. if (isset($itemList[$productId . '_' . $unitPrice])) {
  2102. $currentInfo = $itemList[$productId . '_' . $unitPrice];
  2103. $thisNum = bcadd($currentInfo['xhNum'], $xhNum);
  2104. $thisRefundNum = bcadd($currentInfo['refundNum'], $refundNum);
  2105. $itemList[$productId . '_' . $unitPrice]['xhNum'] = $thisNum;
  2106. $itemList[$productId . '_' . $unitPrice]['refundNum'] = $thisRefundNum;
  2107. } else {
  2108. $itemList[$productId . '_' . $unitPrice] = $singleItem;
  2109. }
  2110. }
  2111. }
  2112. }
  2113. $itemList = array_values($itemList);
  2114. $beforeDebtPrice = bcsub($debtAmount, $remainDebtPrice, 2);
  2115. $tkString = '';
  2116. if ($tkPrice > 0) {
  2117. $tkString = "<span style='margin-right:15px;'>已退款:{$tkPrice}</span>";
  2118. }
  2119. } else {
  2120. $orderSn = $order->orderSn ?? '';
  2121. $remainDebtPrice = $order->remainDebtPrice ?? 0;
  2122. $beforeDebtPrice = bcsub($debtAmount, $remainDebtPrice, 2);
  2123. $actPrice = $order->actPrice ?? 0;
  2124. $tkPrice = $order->tkPrice ?? 0;
  2125. $tkString = '';
  2126. if ($tkPrice > 0) {
  2127. $tkString = "<span style='margin-right:15px;'>已退款:{$tkPrice}</span>";
  2128. }
  2129. $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], 'id asc', '*', null);
  2130. }
  2131. if (empty($itemList)) {
  2132. return ['imgFile' => ''];
  2133. }
  2134. $balance = $custom->balance ?? 0;
  2135. $balanceContent = '';
  2136. if ($balance > 0 && $balance > $debtAmount) {
  2137. if ($debtAmount > 0 && $balance > $debtAmount) {
  2138. $remainBalance = bcsub($balance, $debtAmount, 2);
  2139. $balanceContent = '<span style="margin-right:15px;">余额:' . $balance . ',最终余额:' . $remainBalance . '</span>';
  2140. } else {
  2141. $balanceContent = '<span style="margin-right:15px;">余额:' . $balance . '</span>';
  2142. }
  2143. }
  2144. if ($debtAmount >= $balance) {
  2145. $debtAmount = bcsub($debtAmount, $balance, 2);
  2146. }
  2147. if ($beforeDebtPrice >= $balance) {
  2148. $beforeDebtPrice = bcsub($beforeDebtPrice, $balance, 2);
  2149. }
  2150. $totalNum = 0;
  2151. $totalAmount = 0;
  2152. foreach ($itemList as $item) {
  2153. $xhNum = $item['xhNum'] ?? 0;
  2154. $refundNum = $item['refundNum'] ?? 0;
  2155. $realNum = bcsub($xhNum, $refundNum);
  2156. $unitPrice = $item['xhUnitPrice'] ?? 0;
  2157. $amount = bcmul($realNum, $unitPrice, 2);
  2158. $totalNum = bcadd($totalNum, $realNum);
  2159. $totalAmount = bcadd($totalAmount, $amount, 2);
  2160. }
  2161. $totalAmount = floatval($totalAmount);
  2162. $itemList[] = ['xhNum' => $totalNum, 'totalAmount' => $totalAmount,];
  2163. $content = <<<XL
  2164. <html>
  2165. <head>
  2166. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  2167. </head>
  2168. <body>
  2169. XL;
  2170. $total = count($itemList);
  2171. $pageSize = 14;
  2172. $totalPage = ceil($total / $pageSize);
  2173. for ($page = 1; $page <= $totalPage; $page++) {
  2174. $start = ($page - 1) * $pageSize;
  2175. $currentList = array_slice($itemList, $start, $pageSize);
  2176. if (!empty($currentList)) {
  2177. $tableList = '';
  2178. foreach ($currentList as $key => $item) {
  2179. $index = bcadd($key, $start);
  2180. $index++;
  2181. $name = $item['name'] ?? '';
  2182. $num = $item['xhNum'];
  2183. $refundNum = $item['refundNum'] ?? 0;
  2184. $realNum = bcsub($num, $refundNum);
  2185. $bigUnit = $item['xhUnitName'] ?? '';
  2186. $unitPrice = $item['xhUnitPrice'] ?? 0;
  2187. $unitPrice = floatval($unitPrice);
  2188. $amount = bcmul($realNum, $unitPrice, 2);
  2189. $amount = floatval($amount);
  2190. if ($name == '') {
  2191. $index = '合计';
  2192. $amount = $item['totalAmount'] ?? 0;
  2193. }
  2194. $remark = $item['remark'] ?? '';
  2195. $tableList .= "<tr>";
  2196. $tableList .= "<td>{$index}</td>";
  2197. $tableList .= "<td>{$name}</td>";
  2198. $tableList .= "<td>{$realNum}</td>";
  2199. $tableList .= "<td>{$bigUnit}</td>";
  2200. $tableList .= "<td>{$unitPrice}</td>";
  2201. $tableList .= "<td>{$amount}</td>";
  2202. $tableList .= "<td>{$remark}</td>";
  2203. $tableList .= "</tr>";
  2204. }
  2205. $content .= <<<XL
  2206. <div style="width:760px;height:4px;background-color:black;margin-bottom:10px;"></div>
  2207. <div style="width:750px;text-align:center;font-weight:bold;margin-bottom:20px;font-size:18px;">
  2208. <div>{$fullSjName}</div>
  2209. <div style="margin-top:5px;">销售单</div>
  2210. </div>
  2211. <div style="width:750px;">
  2212. <span>单据日期:{$currentDate}</span>
  2213. <span style="margin-left:80px;">开单:{$staffName}</span>
  2214. <span style="margin-left:80px;">客户:{$customName}</span>
  2215. <span style="float:right;">编号:{$orderSn}</span>
  2216. <div>
  2217. <table border="1" style="border: 1px solid black;border-collapse:collapse;text-align:center;font-size:14px;width:750px;margin-top:5px;">
  2218. <tr style="font-weight:bold;">
  2219. <td style="width:70px;">编号</td>
  2220. <td style="width:200px;">名称</td>
  2221. <td style="width:70px;">数量</td>
  2222. <td style="width:70px;">单位</td>
  2223. <td style="width:70px;">单价</td>
  2224. <td style="width:90px;">金额</td>
  2225. <td style="width:160px;">备注</td>
  2226. </tr>
  2227. {$tableList}
  2228. </table>
  2229. <div style="margin-top:5px;margin-bottom:20px;">
  2230. {$tkString}
  2231. <span style="margin-right:15px;">本单:{$actPrice}</span>
  2232. <span style="margin-right:15px;">上次欠款:{$beforeDebtPrice}</span>
  2233. <span style="margin-right:15px;">待付欠款:{$debtAmount}</span>
  2234. {$balanceContent}
  2235. </div>
  2236. XL;
  2237. }
  2238. }
  2239. $content .= <<<XL
  2240. </body>
  2241. <style>
  2242. body{
  2243. font-size:14px;
  2244. }
  2245. td{
  2246. padding:4px;
  2247. }
  2248. </style>
  2249. </html>
  2250. XL;
  2251. $file = $dir . $orderSn . '.html';
  2252. $imgFile = $dir . $orderSn . '.png';
  2253. if (file_exists($file)) {
  2254. unlink($file);
  2255. }
  2256. if (file_exists($imgFile)) {
  2257. unlink($imgFile);
  2258. }
  2259. file_put_contents($file, $content);
  2260. $con = new Converter(null, [
  2261. "fmt" => "png",
  2262. "in" => $file,
  2263. "out" => $imgFile,
  2264. ]);
  2265. $con->convert();
  2266. return ['imgFile' => $imgFile];
  2267. }
  2268. //应收统计下载 ssh 20240530
  2269. public static function exportAccountList($list, $mainId)
  2270. {
  2271. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  2272. require_once($phpExcelFile . 'Classes/PHPExcel.php');
  2273. $objPHPExcel = new \PHPExcel();
  2274. $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
  2275. ->setLastModifiedBy("Maarten Balliauw")
  2276. ->setTitle("Office 2007 XLSX Document")
  2277. ->setSubject("Office 2007 XLSX Document")
  2278. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  2279. ->setKeywords("office 2007 openxml php")
  2280. ->setCategory("file");
  2281. $ghsTitle = '供货商';
  2282. $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
  2283. $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
  2284. $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
  2285. $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
  2286. $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
  2287. $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
  2288. $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
  2289. $objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
  2290. $objPHPExcel->getActiveSheet()->setCellValue('B1', '名称');
  2291. $objPHPExcel->getActiveSheet()->setCellValue('C1', '金额');
  2292. $objPHPExcel->getActiveSheet()->setCellValue('D1', '订单数');
  2293. //设置宽度
  2294. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
  2295. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
  2296. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
  2297. //加粗
  2298. $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
  2299. $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
  2300. $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
  2301. $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
  2302. $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2303. $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2304. $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2305. $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2306. $baseRow = 2;
  2307. foreach ($list as $key => $custom) {
  2308. $i = $baseRow + $key;
  2309. $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['id']);
  2310. $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['name']);
  2311. $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['amount']);
  2312. $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['num']);
  2313. //居左
  2314. $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2315. $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2316. $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2317. $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2318. }
  2319. $fileName = '应收统计-' . date("m-d");
  2320. $objPHPExcel->getActiveSheet()->setTitle($fileName);
  2321. $objPHPExcel->setActiveSheetIndex(0);
  2322. $dir = './priceTable/' . $mainId;
  2323. if (file_exists($dir) == false) {
  2324. mkdir($dir, 0777, true);
  2325. }
  2326. $date = $fileName;
  2327. $file = $date . '.xls';
  2328. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  2329. if (file_exists($dir . '/' . $file)) {
  2330. unlink($dir . '/' . $file);
  2331. }
  2332. $objWriter->save($dir . '/' . $file);
  2333. $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
  2334. util::success(['file' => $fileUrl, 'shortFile' => $file]);
  2335. }
  2336. //应收统计下载 ssh 20240530
  2337. public static function exportPastList($list, $mainId)
  2338. {
  2339. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  2340. require_once($phpExcelFile . 'Classes/PHPExcel.php');
  2341. $objPHPExcel = new \PHPExcel();
  2342. $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
  2343. ->setLastModifiedBy("Maarten Balliauw")
  2344. ->setTitle("Office 2007 XLSX Document")
  2345. ->setSubject("Office 2007 XLSX Document")
  2346. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  2347. ->setKeywords("office 2007 openxml php")
  2348. ->setCategory("file");
  2349. $ghsTitle = '供货商';
  2350. $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
  2351. $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
  2352. $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
  2353. $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
  2354. $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
  2355. $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
  2356. $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
  2357. $objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
  2358. $objPHPExcel->getActiveSheet()->setCellValue('B1', '客户');
  2359. $objPHPExcel->getActiveSheet()->setCellValue('C1', '手机号');
  2360. $objPHPExcel->getActiveSheet()->setCellValue('D1', '欠款金额');
  2361. //设置宽度
  2362. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
  2363. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
  2364. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
  2365. //加粗
  2366. $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
  2367. $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
  2368. $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
  2369. $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
  2370. $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2371. $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2372. $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2373. $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2374. $baseRow = 2;
  2375. foreach ($list as $key => $custom) {
  2376. $i = $baseRow + $key;
  2377. $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['id']);
  2378. $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['name']);
  2379. $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['mobile']);
  2380. $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['currentDebAmount']);
  2381. //居左
  2382. $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2383. $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2384. $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2385. $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2386. }
  2387. $fileName = '历史应收-' . date("m-d");
  2388. $objPHPExcel->getActiveSheet()->setTitle($fileName);
  2389. $objPHPExcel->setActiveSheetIndex(0);
  2390. $dir = './priceTable/' . $mainId;
  2391. if (file_exists($dir) == false) {
  2392. mkdir($dir, 0777, true);
  2393. }
  2394. $date = $fileName;
  2395. $file = $date . '.xls';
  2396. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  2397. if (file_exists($dir . '/' . $file)) {
  2398. unlink($dir . '/' . $file);
  2399. }
  2400. $objWriter->save($dir . '/' . $file);
  2401. $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
  2402. util::success(['file' => $fileUrl, 'shortFile' => $file]);
  2403. }
  2404. public static function exportYj($list, $mainId)
  2405. {
  2406. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  2407. require_once($phpExcelFile . 'Classes/PHPExcel.php');
  2408. $objPHPExcel = new \PHPExcel();
  2409. $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
  2410. ->setLastModifiedBy("Maarten Balliauw")
  2411. ->setTitle("Office 2007 XLSX Document")
  2412. ->setSubject("Office 2007 XLSX Document")
  2413. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  2414. ->setKeywords("office 2007 openxml php")
  2415. ->setCategory("file");
  2416. $ghsTitle = '供货商';
  2417. $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
  2418. $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
  2419. $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
  2420. $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
  2421. $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
  2422. $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
  2423. $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
  2424. $objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
  2425. $objPHPExcel->getActiveSheet()->setCellValue('B1', '客户');
  2426. $objPHPExcel->getActiveSheet()->setCellValue('C1', '手机号');
  2427. $objPHPExcel->getActiveSheet()->setCellValue('D1', '订单数');
  2428. $objPHPExcel->getActiveSheet()->setCellValue('E1', '订单金额');
  2429. $objPHPExcel->getActiveSheet()->setCellValue('F1', '退款金额');
  2430. $objPHPExcel->getActiveSheet()->setCellValue('G1', '实际金额');
  2431. $objPHPExcel->getActiveSheet()->setCellValue('H1', '纸箱费');
  2432. $objPHPExcel->getActiveSheet()->setCellValue('I1', '打包费');
  2433. $objPHPExcel->getActiveSheet()->setCellValue('J1', '运费');
  2434. //设置宽度
  2435. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
  2436. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
  2437. //加粗
  2438. $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
  2439. $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
  2440. $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
  2441. $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
  2442. $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setSize(9)->setBold(true);
  2443. $objPHPExcel->getActiveSheet()->getStyle('F1')->getFont()->setSize(9)->setBold(true);
  2444. $objPHPExcel->getActiveSheet()->getStyle('G1')->getFont()->setSize(9)->setBold(true);
  2445. $objPHPExcel->getActiveSheet()->getStyle('H1')->getFont()->setSize(9)->setBold(true);
  2446. $objPHPExcel->getActiveSheet()->getStyle('I1')->getFont()->setSize(9)->setBold(true);
  2447. $objPHPExcel->getActiveSheet()->getStyle('J1')->getFont()->setSize(9)->setBold(true);
  2448. $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2449. $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2450. $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2451. $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2452. $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2453. $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2454. $objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2455. $objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2456. $objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2457. $objPHPExcel->getActiveSheet()->getStyle('J1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2458. $baseRow = 2;
  2459. foreach ($list as $key => $custom) {
  2460. $i = $baseRow + $key;
  2461. $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['id']);
  2462. $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['name']);
  2463. $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['mobile']);
  2464. $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['num']);
  2465. $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $custom['orderPrice']);
  2466. $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $custom['tkPrice']);
  2467. $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, $custom['actPrice']);
  2468. $objPHPExcel->getActiveSheet()->setCellValue('H' . $i, $custom['carton']);
  2469. $objPHPExcel->getActiveSheet()->setCellValue('I' . $i, $custom['pack']);
  2470. $objPHPExcel->getActiveSheet()->setCellValue('J' . $i, $custom['freight']);
  2471. //居左
  2472. $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2473. $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2474. $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2475. $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2476. $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2477. $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2478. $objPHPExcel->getActiveSheet()->getStyle('G' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2479. $objPHPExcel->getActiveSheet()->getStyle('H' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2480. $objPHPExcel->getActiveSheet()->getStyle('I' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2481. $objPHPExcel->getActiveSheet()->getStyle('J' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2482. }
  2483. $fileName = '客户业绩-' . date("m-d");
  2484. $objPHPExcel->getActiveSheet()->setTitle($fileName);
  2485. $objPHPExcel->setActiveSheetIndex(0);
  2486. $dir = './priceTable/' . $mainId;
  2487. if (file_exists($dir) == false) {
  2488. mkdir($dir, 0777, true);
  2489. }
  2490. $date = $fileName;
  2491. $file = $date . '.xls';
  2492. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  2493. if (file_exists($dir . '/' . $file)) {
  2494. unlink($dir . '/' . $file);
  2495. }
  2496. $objWriter->save($dir . '/' . $file);
  2497. $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
  2498. util::success(['file' => $fileUrl, 'shortFile' => $file]);
  2499. }
  2500. }