| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750 |
- <?php
- namespace bizGhs\order\classes;
- use bizGhs\item\classes\ItemClassClass;
- use wkhtmltox\Image\Converter;
- use biz\shop\classes\ShopAdminClass;
- use biz\shop\classes\ShopCapitalClass;
- use biz\shop\classes\ShopClass;
- use biz\shop\classes\ShopExtClass;
- use biz\shop\models\Shop;
- use biz\sj\classes\SjClass;
- use biz\stat\classes\StatItemClass;
- use biz\stat\classes\StatKdClass;
- use biz\stat\classes\StatKhCgClass;
- use biz\stat\classes\StatOrderCountClass;
- use biz\stat\classes\StatOutClass;
- use biz\stat\classes\StatRefundClass;
- use biz\stat\classes\StatSaleClass;
- use biz\stock\classes\StockClass;
- use bizGhs\custom\models\Custom;
- use bizGhs\express\services\DadaExpressServices;
- use bizGhs\order\models\Order;
- use bizGhs\order\traits\OrderTrait;
- use bizGhs\product\classes\ProductClass;
- use bizGhs\admin\classes\AdminClass;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\shop\classes\MainClass;
- use bizGhs\stat\classes\StatYjClass;
- use bizGhs\stock\classes\StockRecordClass;
- use bizGhs\stock\services\StockRecordService;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\stat\classes\StatIncomeClass;
- use bizHd\stat\classes\StatOrderClass;
- use common\components\dict;
- use common\components\httpUtil;
- use common\components\imgUtil;
- use common\components\noticeUtil;
- use common\components\orderSn;
- use common\components\printUtil;
- use common\components\stringUtil;
- use common\components\util;
- use bizGhs\base\classes\BaseClass;
- use Yii;
- class OrderClass extends BaseClass
- {
- use OrderTrait;
- public static $baseFile = '\bizGhs\order\models\Order';
- //已取消
- const ORDER_STATUS_CANCEL = 5;
- //已完成
- const ORDER_STATUS_COMPLETE = 4;
- //配送中
- const ORDER_STATUS_SENDING = 3;
- //待配送
- const ORDER_STATUS_UN_SEND = 2;
- //待付款,待确认
- const ORDER_STATUS_UN_PAY = 1;
- //出车
- const SEND_TYPE_CAR_GET = 0;
- //到店自取
- const SEND_TYPE_SHOP_GET = 1;
- //发快递
- const SEND_TYPE_THIRD_SEND = 2;
- //未确认
- const SEND_TYPE_UNKNOWN = 1;
- //自取
- const SEND_TYPE_NO = 2;
- //自己送
- const SEND_TYPE_MYSELF = 3;
- //快递送
- const SEND_TYPE_THIRD = 4;
- public static $sendTypeMap = [
- self::SEND_TYPE_UNKNOWN => '未确认',
- self::SEND_TYPE_NO => '自取',
- self::SEND_TYPE_MYSELF => '商家配送',
- self::SEND_TYPE_THIRD => '快递配送',
- ];
- //待付款
- const PAY_STATUS_UN_PAY = 0;
- //已付款
- const PAY_STATUS_HAS_PAY = 1;
- //待配送
- const SEND_STATUS_UN_SEND = 1;
- //配送中
- const SEND_STATUS_SENDING = 2;
- //配送完成
- const SEND_STATUS_COMPLETE = 3;
- //订单总流程数
- const TOTAL_FLOW = 3;
- //清算方式
- //欠款
- const CLEAR_DEBT = 1;
- //已付款
- const CLEAR_HAS_GATHERING = 2;
- //没有欠款
- const DEBT_NO = 0;
- //欠款
- const DEBT_YES = 1;
- //正常订单
- const REFUND_NO = 1;
- //已退款订单
- const REFUND_YES = 2;
- public static $refundMap = [
- self::REFUND_NO => '',
- self::REFUND_YES => '有退款',
- ];
- public static function exportOrderData($respond, $mainId)
- {
- $orderList = $respond['list'] ?? [];
- if (empty($orderList)) {
- util::fail('没有数据需要导出');
- }
- $orderSnList = array_column($orderList, 'orderSn');
- $orderItemData = OrderItemClass::getAllByCondition(['orderSn' => ['in', $orderSnList]], null, '*');
- $orderItemList = [];
- if (!empty($orderItemData)) {
- foreach ($orderItemData as $itemInfo) {
- $orderSn = $itemInfo['orderSn'] ?? '';
- $orderItemList[$orderSn][] = $itemInfo;
- }
- }
- foreach ($orderList as $key => $orderInfo) {
- $book = $orderInfo['book'] ?? 0;
- $actPrice = $orderInfo['actPrice'] ?? 0;
- $status = $orderInfo['status'] ?? 0;
- if ($book == 1 && $status == 2) {
- //预订单待发货的不算收入
- unset($orderList[$key]);
- continue;
- }
- if ($status == 1 || $status == 5) {
- unset($orderList[$key]);
- continue;
- }
- if ($actPrice <= 0) {
- unset($orderList[$key]);
- continue;
- }
- $orderSn = $orderInfo['orderSn'] ?? '';
- $itemList = $orderItemList[$orderSn] ?? [];
- $orderList[$key]['itemList'] = $itemList;
- }
- $classList = ItemClassClass::getAllByCondition(['mainId' => $mainId], null, '*', 'id');
- $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
- require_once($phpExcelFile . 'Classes/PHPExcel.php');
- $objPHPExcel = new \PHPExcel();
- $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
- ->setLastModifiedBy("Maarten Balliauw")
- ->setTitle("Office 2007 XLSX Document")
- ->setSubject("Office 2007 XLSX Document")
- ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
- ->setKeywords("office 2007 openxml php")
- ->setCategory("file");
- $ghsTitle = '供货商';
- $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
- $objPHPExcel->getActiveSheet()->setCellValue('A1', '订单号');
- $objPHPExcel->getActiveSheet()->setCellValue('B1', '创建时间');
- $objPHPExcel->getActiveSheet()->setCellValue('C1', '账单日期');
- $objPHPExcel->getActiveSheet()->setCellValue('D1', '订单金额');
- $objPHPExcel->getActiveSheet()->setCellValue('E1', '退款金额');
- $objPHPExcel->getActiveSheet()->setCellValue('F1', '实际金额');
- $objPHPExcel->getActiveSheet()->setCellValue('G1', '客户');
- $objPHPExcel->getActiveSheet()->setCellValue('H1', '客户手机号');
- $objPHPExcel->getActiveSheet()->setCellValue('I1', '在线支付');
- $objPHPExcel->getActiveSheet()->setCellValue('J1', '结清状态');
- $objPHPExcel->getActiveSheet()->setCellValue('K1', '已优惠');
- $objPHPExcel->getActiveSheet()->setCellValue('L1', '备注');
- $objPHPExcel->getActiveSheet()->setCellValue('M1', '开单人');
- $objPHPExcel->getActiveSheet()->setCellValue('N1', '花材Id');
- $objPHPExcel->getActiveSheet()->setCellValue('O1', '花材名称');
- $objPHPExcel->getActiveSheet()->setCellValue('P1', '单价');
- $objPHPExcel->getActiveSheet()->setCellValue('Q1', '数量');
- $objPHPExcel->getActiveSheet()->setCellValue('R1', '已退数量');
- $objPHPExcel->getActiveSheet()->setCellValue('S1', '金额');
- $objPHPExcel->getActiveSheet()->setCellValue('T1', '分类');
- $objPHPExcel->getActiveSheet()->setCellValue('U1', '备注');
- //设置宽度
- $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(16);
- $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(18);
- $objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth(18);
- //加粗
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('F1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('G1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('H1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('I1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('J1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('K1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('L1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('M1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('N1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('O1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('P1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('Q1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('R1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('S1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('T1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('U1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('J1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('K1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('L1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('M1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('N1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('O1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('P1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('Q1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('R1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('S1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('T1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('U1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('J1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('K1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('L1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('M1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('N1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('O1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('P1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('Q1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('R1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('S1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('T1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('U1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $baseRow = 2;
- $x = 0;
- foreach ($orderList as $key => $orderData) {
- $currentList = $orderData['itemList'] ?? [];
- if (!empty($currentList)) {
- foreach ($currentList as $k => $orderInfo) {
- $i = $baseRow + $x;
- $x++;
- $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $orderData['orderSn']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $orderData['addTime']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $orderData['payTime']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $orderData['orderPrice']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $orderData['tkPrice']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $orderData['actPrice']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, $orderData['customName']);
- $objPHPExcel->getActiveSheet()->setCellValue('H' . $i, $orderData['customMobile']);
- $objPHPExcel->getActiveSheet()->setCellValue('I' . $i, $orderData['onlinePay'] == 1 ? '否' : '是');
- $objPHPExcel->getActiveSheet()->setCellValue('J' . $i, $orderData['debt'] == 1 ? '未结清' : '已结清');
- $objPHPExcel->getActiveSheet()->setCellValue('K' . $i, $orderData['discountAmount']);
- $objPHPExcel->getActiveSheet()->setCellValue('L' . $i, $orderData['remark']);
- $objPHPExcel->getActiveSheet()->setCellValue('M' . $i, $orderData['shopAdminName']);
- $objPHPExcel->getActiveSheet()->setCellValue('N' . $i, $orderInfo['productId']);
- $objPHPExcel->getActiveSheet()->setCellValue('O' . $i, $orderInfo['name']);
- $objPHPExcel->getActiveSheet()->setCellValue('P' . $i, $orderInfo['xhUnitPrice']);
- $remainNum = bcsub($orderInfo['xhNum'], $orderInfo['refundNum']);
- $price = bcmul($remainNum, $orderInfo['xhUnitPrice'], 2);
- $objPHPExcel->getActiveSheet()->setCellValue('Q' . $i, $remainNum);
- $objPHPExcel->getActiveSheet()->setCellValue('R' . $i, $orderInfo['refundNum']);
- $objPHPExcel->getActiveSheet()->setCellValue('S' . $i, $price);
- $classId = $orderInfo['classId'] ?? 0;
- $className = isset($classList[$classId]) && isset($classList[$classId]['name']) ? $classList[$classId]['name'] : '';
- $objPHPExcel->getActiveSheet()->setCellValue('T' . $i, $className);
- $objPHPExcel->getActiveSheet()->setCellValue('U' . $i, $orderInfo['remark']);
- //居左
- $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('G' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('H' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('I' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('J' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('K' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('L' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('M' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('N' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('O' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('P' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('Q' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('R' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('S' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('T' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- }
- }
- }
- $fileName = '订单明细-' . time();
- $objPHPExcel->getActiveSheet()->setTitle($fileName);
- $objPHPExcel->setActiveSheetIndex(0);
- $dir = './priceTable/' . $mainId;
- if (file_exists($dir) == false) {
- mkdir($dir, 0777, true);
- }
- $date = $fileName;
- $file = $date . '.xls';
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- if (file_exists($dir . '/' . $file)) {
- unlink($dir . '/' . $file);
- }
- $objWriter->save($dir . '/' . $file);
- $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
- util::success(['file' => $fileUrl, 'shortFile' => $file]);
- }
- public static function confirmReach($order, $params = [])
- {
- $cgId = $order->purchaseId ?? 0;
- $cg = PurchaseClass::getById($cgId, true);
- if (empty($cg)) {
- util::fail('没有找到采购信息');
- }
- $customId = $order->customId ?? 0;
- $custom = CustomClass::getById($customId, true);
- if (empty($custom)) {
- util::fail('没有找到客户信息');
- }
- $shopId = $custom->shopId ?? 0;
- $customShop = ShopClass::getById($shopId, true);
- if (empty($customShop)) {
- util::fail('没有找到客户的门店');
- }
- if (isset($customShop->pfShopId) && !empty($customShop->pfShopId)) {
- //如果客户是勇记花卉 森润 国恋 珊瑚 中华 寻花季 还是要直接完成,请搜索关键词 has_pf_direct_finish
- if (getenv('YII_ENV') == 'production') {
- $particularIds = [7779, 7832, 10610, 7779, 16780, 716, 8394];
- } else {
- $particularIds = [36750];
- }
- if (!in_array($customShop->id, $particularIds)) {
- util::fail('客户有批发店,请通知对方确认');
- }
- }
- //订单如果没有发货则先发货
- if ($order->status == 2) {
- $staffId = $params['staffId'] ?? 0;
- $staffName = $params['staffName'] ?? '';
- $element = ['staffId' => $staffId, 'staffName' => $staffName];
- self::orderSend($order, $element, true);
- $cg = PurchaseClass::getById($cgId, true);
- }
- PurchaseClass::takeToPutIn($cg);
- }
- //订单发货主方法 ssh 20231119
- public static function orderSend($order, $params, $allowRepeat = false)
- {
- self::orderFh($order, $params, $allowRepeat);
- $cgId = $order->purchaseId ?? 0;
- $cgInfo = PurchaseClass::getById($cgId, true);
- if (empty($cgInfo)) {
- util::fail('没有找到采购信息');
- }
- PurchaseClass::orderFh($cgInfo, $params, $allowRepeat, true);
- }
- //订单发货子方法 ssh 20231119
- public static function orderFh($order, $params, $allowRepeat = false)
- {
- if ($order->status == 3) {
- if ($allowRepeat == false) {
- util::fail('订单已发货');
- } else {
- return true;
- }
- }
- $fhType = $params['fhType'] ?? 0;
- if (is_numeric($fhType) == false) {
- util::fail('请选择发货类型');
- }
- if ($fhType == 1) {
- $fhWl = $params['fhWl'] ?? '';
- $fhWlNo = $params['fhWlNo'] ?? '';
- if (empty($fhWl)) {
- util::fail('请填写物流名称');
- }
- if (empty($fhWlNo)) {
- util::fail('请填写物流编号');
- }
- $order->fhWl = $fhWl;
- $order->fhWlNo = $fhWlNo;
- }
- $order->fhType = $fhType;
- $order->status = 3;
- $order->fhTime = date("Y-m-d H:i:s");
- $staffId = $params['staffId'] ?? 0;
- $staffName = $params['staffName'] ?? '';
- $order->sendStaffId = $staffId;
- $order->sendStaffName = $staffName;
- $order->save();
- }
- public static function arrival($order, $data)
- {
- if ($order->stockChange == 1) {
- util::fail('您已操作过了');
- }
- $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
- $packCost = isset($data['packCost']) && is_numeric($data['packCost']) ? $data['packCost'] : 0;
- $order->sendCost = $sendCost;
- $order->packCost = $packCost;
- $order->save();
- $sjId = $order->sjId ?? 0;
- $shopId = $order->shopId ?? 0;
- $mainId = $order->mainId ?? 0;
- //product [{"productId":"3674","num":0,"price":1}]
- $product = $data['product'] ?? '';
- if (empty($product)) {
- util::fail('没有花材?');
- }
- $ids = [];
- $format = [];
- foreach ($product as $val) {
- $productId = $val['productId'] ?? 0;
- $ids[] = $productId;
- $format[$productId] = $val;
- }
- $info = ProductClass::getByIds($ids, null, 'id');
- $orderSn = $order->orderSn ?? '';
- $customName = $order->customName ?? '';
- $list = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
- if (empty($list)) {
- util::fail('没有找到订单的花材');
- }
- $itemPrice = 0;
- $weight = 0;
- foreach ($list as $key => $val) {
- $productId = $val->productId ?? 0;
- $num = $format[$productId]['num'] ?? 0;
- $unitPrice = $format[$productId]['price'] ?? 0;
- $price = bcmul($unitPrice, $num, 2);
- $name = $val->name ?? '';
- $xhUnitName = $val->xhUnitName ?? '';
- $xhPreNum = $val->xhPreNum ?? 0;
- if ($unitPrice <= 0) {
- util::fail('花材金额需要大于0');
- }
- if ($num > $xhPreNum) {
- //util::fail($name . "数量不能超过{$xhPreNum}{$xhUnitName}");
- }
- $val->cost = $unitPrice;
- $val->unitPrice = $unitPrice;
- $val->price = $price;
- $val->bigNum = $num;
- $val->num = $num;
- $val->xhNum = $num;
- $val->xhUnitPrice = $unitPrice;
- $val->xhPrice = $price;
- $val->save();
- if ($val->xhPreNum > $num) {
- //客户下单退货数增加
- $subNum = bcsub($val->xhPreNum, $num);
- StatKhCgClass::ghsBookOrderRefundNum($order, $subNum);
- //花材销量榜减少
- StatItemClass::ghsBookOrderRefundNum($order, $val, $subNum);
- }
- $itemPrice = bcadd($itemPrice, $price, 2);
- $productWeight = $info[$productId]['weight'] ?? 0;
- $currentWeight = bcmul($productWeight, $num, 2);
- $weight = bcadd($currentWeight, $weight, 2);
- //减少库存
- $unitType = $val->xhUnitType ?? 0;
- $bigNum = 0;
- $smallNum = 0;
- if ($unitType == dict::getDict('unitType', 'big')) {
- $bigNum = $num;
- $itemNum = $num;
- } else {
- $smallNum = $num;
- $itemNum = bcdiv($num, $val->ratio, 2);
- }
- $checkStock = true;
- $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum, $checkStock);
- $recordData = [];
- $recordData['sjId'] = $sjId;
- $recordData['shopId'] = $shopId;
- $recordData['mainId'] = $mainId;
- $recordData['itemId'] = $val->itemId;
- $recordData['itemNum'] = $itemNum;
- $recordData['oldStock'] = $stockInfo['oldStock'];
- $recordData['newStock'] = $stockInfo['newStock'];
- $recordData['productId'] = $productId;
- $recordData['orderSn'] = $orderSn;
- $recordData['relateName'] = $customName;
- $recordData['ptStyle'] = dict::getDict('ptStyle', 'ghs');
- StockRecordClass::addSellStockOrderRecord($recordData);
- }
- $order->itemPrice = $itemPrice;
- $sendCost = $order->sendCost ?? 0;
- $currentPrice = bcadd($itemPrice, $sendCost, 2);
- $packCost = $order->packCost ?? 0;
- $currentPrice = bcadd($currentPrice, $packCost, 2);
- $shopId = $order->shopId ?? 0;
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- util::fail('没有找到门店6');
- }
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息4');
- }
- $main->unSendOrder -= 1;
- $main->finishOrder += 1;
- $main->save();
- $kiloFee = $shop->kiloFee ?? 0;
- $miniKilo = $shop->miniKilo ?? 0;
- $calcWeight = $weight > $miniKilo ? $weight : $miniKilo;
- $allKiloFee = bcmul($calcWeight, $kiloFee, 2);
- $currentPrice = bcadd($currentPrice, $allKiloFee, 2);
- $order->prePrice = $currentPrice;
- $order->orderPrice = $currentPrice;
- $order->actPrice = $currentPrice;
- $order->realPrice = $currentPrice;
- $order->stockChange = 1;
- $order->save();
- $bookPrice = $order->bookPrice ?? 0;
- $mainId = $shop->mainId ?? 0;
- $sjId = $shop->sjId ?? 0;
- $customId = $order->customId ?? 0;
- $relateOrderSn = $order->orderSn ?? '';
- $shopAdminId = $data['shopAdminId'] ?? 0;
- $shopAdminName = $data['shopAdminName'] ?? '';
- $refund = null;
- if ($bookPrice != $currentPrice) {
- if ($bookPrice > $currentPrice) {
- $refundPrice = bcsub($bookPrice, $currentPrice, 2);
- $order->refundPrice = $refundPrice;
- $order->tkPrice = bcadd($order->tkPrice, $refundPrice, 2);
- $order->refund = self::REFUND_YES;
- $order->refundLog = 1;
- $order->save();
- $orderSn = orderSn::getGhsRefundSn();
- $book = 1;
- $refundData = [
- 'mainId' => $mainId,
- 'shopId' => $shopId,
- 'sjId' => $sjId,
- 'customId' => $customId,
- 'orderSn' => $orderSn,
- 'relateOrderSn' => $relateOrderSn,
- 'book' => $book,
- 'status' => RefundOrderClass::STATUS_COMPLETE,
- 'shopAdminId' => $shopAdminId,
- 'shopAdminName' => $shopAdminName,
- 'refundPrice' => $refundPrice,
- 'refundType' => RefundOrderClass::REFUND_TYPE_MONEY,
- ];
- //退款
- $refund = RefundOrderClass::add($refundData, true);
- //余额减少
- ShopClass::ghsBookOrderRefundReduceBalance($main, $shop, $refund, $refundPrice);
- //总支出增加
- $currentTotalExpend = bcadd($main->totalExpend, $refundPrice, 2);
- $main->totalExpend = $currentTotalExpend;
- $totalRefund = bcadd($main->totalRefund, $refundPrice, 2);
- $main->totalRefund = $totalRefund;
- $main->save();
- //支出流水
- $thisType = dict::getDict('capitalType', 'ghsBookRefund', 'id');
- $sjId = $order->sjId ?? 0;
- $event = "预订单多付退给{$customName}";
- $capitalData = [
- 'capitalType' => $thisType,
- 'io' => 0,
- 'totalExpend' => $currentTotalExpend,
- 'payWay' => 0,
- 'amount' => $refundPrice,
- 'sjId' => $sjId,
- 'shopId' => $shopId,
- 'event' => $event,
- 'mainId' => $mainId,
- ];
- ShopCapitalClass::addCapital($capitalData);
- //支出统计
- StatOutClass::updateOrInsert($main, $shop, $refundPrice);
- //退款统计
- $payWay = $order->payWay ?? 0;
- StatRefundClass::replace($main, $shop, $payWay, $refundPrice);
- //供货商预订单退款给客户,客户采购金额减少
- StatKhCgClass::ghsBookOrderChange(false, $order, $refundPrice);
- } else {
- //欠款
- $currentDebt = bcsub($currentPrice, $bookPrice, 2);
- $order->debtPrice = $currentDebt;
- $order->remainDebtPrice = $currentDebt;
- $order->debt = OrderClass::DEBT_YES;
- $order->save();
- $currentTotalIncome = bcadd($main->totalIncome, $currentDebt, 2);
- $main->totalIncome = $currentTotalIncome;
- $main->save();
- $payWay = dict::getDict('payWay', 'debtPay');
- $custom = CustomClass::getLockById($customId);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- CustomClass::cgDebtAmountAdd($custom, $order, true);
- //收入增加
- StatIncomeClass::updateOrInsert($main, $shop, $currentDebt);
- //收入流水增加
- $orderId = $order->id;
- $capitalType = dict::getDict('capitalType', 'ghsBookOrderGetBack', 'id');
- $shopAdminId = $order->shopAdminId ?? 0;
- $shopAdminName = $order->shopAdminName ?? '';
- $event = "预订单 {$orderSn} 差价补款";
- $mainId = $shop->mainId ?? 0;
- $sjId = $order->sjId ?? 0;
- $shopId = $order->shopId ?? 0;
- $capital = [
- 'capitalType' => $capitalType,
- 'relateId' => $orderId,
- 'io' => 1,
- 'amount' => $currentDebt,
- 'totalIncome' => $currentTotalIncome,
- 'payWay' => $payWay,
- 'event' => $event,
- 'mainId' => $mainId,
- 'sjId' => $sjId,
- 'shopId' => $shopId,
- 'shopAdminId' => $shopAdminId,
- 'shopAdminName' => $shopAdminName,
- ];
- ShopCapitalClass::addCapital($capital);
- //各渠道收入金额统计
- StatKdClass::replace($shop, $currentDebt, $payWay);
- //每天销售收入统计
- StatSaleClass::replace($main, $shop, $currentDebt);
- //预订单,客户补款给供货商,客户采购金额增加
- StatKhCgClass::ghsBookOrderChange(true, $order, $currentDebt);
- }
- }
- return ['kiloFee' => $kiloFee, 'refund' => $refund, 'miniKilo' => $miniKilo];
- }
- //添加订单 ssh 2019.12.5
- public static function addOrder($data)
- {
- $orderSn = orderSn::getGhsOrderSn();
- $data['orderSn'] = $orderSn;
- $data['payStatus'] = self::PAY_STATUS_UN_PAY;
- $data['customId'] = isset($data['customId']) && !empty($data['customId']) ? $data['customId'] : 0;
- $live = isset($data['live']) ? $data['live'] : 1;
- $currentShopId = $data['shopId'] ?? 0;
- $shop = ShopClass::getLockById($currentShopId);
- if (empty($shop)) {
- util::fail('没有找到门店7');
- }
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息5');
- }
- //花材
- $product = $data['product'];
- $book = $data['book'] ?? 0;
- $stockMayChange = true;
- $data['stockChange'] = 1;
- if ($book == 1) {
- $stockMayChange = false;
- $data['stockChange'] = 0;
- }
- //花店向虚拟批发店采购的,批发店没有的花材需要补充
- if ($live == 0) {
- $product = \bizHd\product\classes\ProductClass::hdToggleGhs($product, $shop);
- }
- $customShopAdminId = $data['customShopAdminId'] ?? 0;
- $moreParams = ['book' => $book, 'customShopAdminId' => $customShopAdminId];
- $respond = OrderItemClass::replaceItem($orderSn, $product, $data, $stockMayChange, $moreParams);
- $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
- $data['sendCost'] = $sendCost;
- $data['bigNum'] = $respond['bigNum'] ?? 0;
- $data['smallNum'] = $respond['smallNum'] ?? 0;
- $data['itemNum'] = $respond['totalItemNum'] ?? 0;
- $data['reachDiscountPrice'] = $respond['totalReachDiscount'] ?? 0;
- //默认订单要打单
- $data['needPrint'] = $data['needPrint'] ?? dict::getDict('needPrint', 'need');
- $weight = $respond['weight'] ?? 0;
- $data['weight'] = $weight;
- $itemPrice = $respond['price'] ?? 0;
- $data['itemPrice'] = $itemPrice;
- $currentPrice = bcadd($itemPrice, $sendCost, 2);
- $packCost = isset($data['packCost']) && $data['packCost'] > 0 ? $data['packCost'] : 0;
- $currentPrice = bcadd($currentPrice, $packCost, 2);
- //预订单需要增加服务费
- if ($book == 1) {
- $kiloFee = $shop->kiloFee ?? 0;
- $miniKilo = $shop->miniKilo ?? 0;
- $calcWeight = $weight > $miniKilo ? $weight : $miniKilo;
- $allKiloFee = bcmul($calcWeight, $kiloFee, 2);
- $currentPrice = bcadd($currentPrice, $allKiloFee, 2);
- $data['allKiloFee'] = $allKiloFee;
- $data['kiloFee'] = $kiloFee;
- $data['miniKilo'] = $miniKilo;
- }
- $data['prePrice'] = $currentPrice;
- $actPrice = $currentPrice;
- //商家自己开单时
- if (isset($data['modifyPrice'])) {
- $modifyPrice = $data['modifyPrice'] ?? 0;
- if ($modifyPrice <= 0) {
- util::fail('收款金额必须大于0');
- }
- if ($modifyPrice > $currentPrice) {
- //人工和资材费用
- $data['labourCost'] = bcsub($modifyPrice, $currentPrice, 2);
- }
- if ($modifyPrice < $currentPrice) {
- //优惠金额
- $data['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2);
- $data['discountType'] = dict::getDict('discountType', 'discount');
- }
- $actPrice = $modifyPrice;
- if ($book == 1) {
- $actPrice = 0;
- }
- } else {
- //整单满减
- if ($book == 0) {
- $meetNum = $shop->meetNum ?? 0;
- $meetAmount = $shop->meetAmount ?? 0;
- $cutOption = $shop->cutAmount ?? 0;
- $cutStyle = $shop->cutStyle ?? 0;
- if ($cutStyle == 0) {
- $cutAmount = $cutOption;
- } else {
- $miniOption = bcsub(1, $cutOption, 2);
- $cutAmount = bcmul($actPrice, $miniOption, 2);
- }
- if ($cutOption > 0) {
- if ($meetNum > 0 && isset($data['bigNum']) && $data['bigNum'] >= $meetNum) {
- if ($cutAmount > $actPrice) {
- util::fail('整单满减为负');
- }
- $actPrice = bcsub($actPrice, $cutAmount, 2);
- $data['orderReachDiscountPrice'] = $cutAmount;
- } else {
- if ($meetAmount > 0 && isset($data['itemPrice']) && $data['itemPrice'] >= $meetAmount) {
- if ($cutAmount > $actPrice) {
- util::fail('整单满减为负');
- }
- $actPrice = bcsub($actPrice, $cutAmount, 2);
- $data['orderReachDiscountPrice'] = $cutAmount;
- }
- }
- }
- }
- }
- //客户采购时使用红包时
- if (isset($data['discountType']) && $data['discountType'] == dict::getDict('discountType', 'hb')) {
- $discountAmount = $data['discountAmount'] ?? 0;
- $currentDiscountPrice = bcsub($currentPrice, $discountAmount, 2);
- $actPrice = $currentDiscountPrice;
- }
- $data['actPrice'] = $actPrice;
- $data['bookPrice'] = $actPrice;
- $data['orderPrice'] = $actPrice;
- $data['realPrice'] = $actPrice;
- $data['sendTimeWant'] = isset($data['sendTimeWant']) && !empty($data['sendTimeWant']) ? $data['sendTimeWant'] : date("Y-m-d");
- //订单有效期
- $validTime = dict::getDict('order_pay_has_time');
- $current = time() + $validTime;
- $data['deadline'] = $data['deadline'] ?? date("Y-m-d H:i:s", $current);
- $data['status'] = self::ORDER_STATUS_UN_PAY;
- $main->totalOrder += 1;
- $main->unPayOrder += 1;
- $main->save();
- //将当天日期+花店每天的总订单数作为编号
- $data['sendNum'] = date("j") . StatOrderCountClass::addOrder($shop, $main);
- //订单有效期
- $currentTime = time();
- $validTime = dict::getDict('order_pay_has_time');
- $current = $currentTime + $validTime;
- $data['deadline'] = isset($data['deadline']) ? $data['deadline'] : date("Y-m-d H:i:s", $current);
- if ($book == 1) {
- $fiveTime = bcmul(86400, 5);
- $bookDeadline = bcadd($currentTime, $fiveTime);
- $data['deadline'] = date("Y-m-d H:i:s", $bookDeadline);
- }
- //订单自动记为欠款单时间
- $localConfirmTime = dict::getDict('local_gys_kd_auto_set_debt_time');
- $currentSet = $currentTime + $localConfirmTime;
- $data['autoSetTime'] = $data['autoSetTime'] ?? date("Y-m-d H:i:s", $currentSet);
- $return = self::add($data, true);
- return $return;
- }
- //修改订单 ssh 2019.12.5
- public static function updateOrder($order, $data)
- {
- $sjId = $order->sjId ?? 0;
- $orderSn = $order->orderSn ?? 0;
- $currentShopId = $order->shopId ?? 0;
- $data['payStatus'] = self::PAY_STATUS_UN_PAY;
- //花材列表
- $product = $data['product'];
- //删除花材再添加
- OrderItemClass::deleteByCondition(['orderSn' => $orderSn]);
- $respond = OrderItemClass::replaceItem($orderSn, $product, $data);
- $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
- $data['sendCost'] = $sendCost;
- $data['bigNum'] = $respond['bigNum'] ?? 0;
- $data['smallNum'] = $respond['smallNum'] ?? 0;
- $price = $respond['price'] ?? 0;
- $currentPrice = bcadd($price, $sendCost, 2);
- $data['prePrice'] = $currentPrice;
- if (isset($data['modifyPrice'])) {
- //商家打折,修改金额
- $modifyPrice = $data['modifyPrice'] ?? 0;
- if ($modifyPrice > $currentPrice) {
- util::fail('实收金额大于订单总金额');
- }
- if ($modifyPrice < $currentPrice) {
- $data['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2);
- $data['discountType'] = dict::getDict('discountType', 'discount');
- $currentPrice = $modifyPrice;
- }
- }
- $data['actPrice'] = $currentPrice;
- $data['realPrice'] = $currentPrice;
- //如果有平台补贴
- if (isset($data['discountType']) && $data['discountType'] == dict::getDict('discountType', 'usePtCoupon')) {
- $discountAmount = $data['discountAmount'] ?? 0;
- $data['realPrice'] = bcsub($currentPrice, $discountAmount, 2);
- }
- $data['sendTime'] = isset($data['sendTime']) && !empty($data['sendTime']) ? $data['sendTime'] : '0000-00-00 00:00:00';
- //订单有效期
- $validTime = dict::getDict('order_pay_has_time');
- $current = time() + $validTime;
- $data['deadline'] = $data['deadline'] ?? date("Y-m-d H:i:s", $current);
- $data['status'] = self::ORDER_STATUS_UN_PAY;
- //计算总重量(kg)
- $weight = 0;
- $productMapData = ProductClass::getProductMapData($product);
- foreach ($product as $key => $val) {
- $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
- $productId = $val['productId'];
- $weight = bcadd($w, $weight, 2);
- $checkStock = true;
- $stockInfo = ProductClass::decreaseStock($val['productId'], $val['bigNum'], $val['smallNum'], $checkStock);
- //记录库存流水
- $recordData = [];
- $recordData['sjId'] = $sjId;
- $recordData['shopId'] = $currentShopId;
- $recordData['itemId'] = $productMapData[$productId]['itemId'] ?? 0;
- $ratio = $productMapData[$productId]['ratio'] ?? 0;
- $recordData['itemNum'] = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
- $recordData['oldStock'] = $stockInfo['oldStock'];
- $recordData['newStock'] = $stockInfo['newStock'];
- $recordData['productId'] = $productId;
- $recordData['orderSn'] = $orderSn;
- StockRecordClass::addSellStockOrderRecord($recordData);
- }
- $data['weight'] = $weight;
- $current = time() + 300;
- $data['deadline'] = isset($data['deadline']) ? $data['deadline'] : date("Y-m-d H:i:s", $current);
- //修改订单暂时不打印
- $data['needPrint'] = $data['needPrint'] ?? dict::getDict('needPrint', 'need');
- $orderId = $order->id ?? 0;
- self::updateById($orderId, $data);
- $return = self::getLockById($orderId);
- //门店总订单数+1
- $shop = ShopClass::getLockById($currentShopId);
- if (empty($shop)) {
- util::fail('没有找到门店8');
- }
- $shop->unPayOrder += 1;
- $shop->cancelOrder -= 1;
- $shop->save();
- return $return;
- }
- //根据订单编号查询 ssh 2021.19
- public static function getByOrderSn($orderSn, $returnObj = false)
- {
- return self::getByCondition(['orderSn' => $orderSn], $returnObj);
- }
- //根据编号列表查订单
- public static function getOrderInfoBySnList($snList)
- {
- $list = self::getAllByCondition(['orderSn' => ['in', $snList]], null, '*', 'orderSn');
- $list = self::groupOrder($list, true, false, false, true);
- return $list;
- }
- //显示操作按钮
- public static function getShowButton($showButton, $isList, $order)
- {
- if ($showButton == false) {
- return [];
- }
- $print = ['type' => 'print', 'show' => 1, 'disable' => 0, 'name' => '打印'];
- $modifyProduct = ['type' => 'modifyProduct', 'show' => 0, 'disable' => 0, 'name' => '修改花材'];
- $confirm = ['type' => 'confirm', 'show' => 0, 'disable' => 1, 'name' => '确认'];
- $cancel = ['type' => 'cancel', 'show' => 0, 'disable' => 0, 'name' => '取消'];
- $arrival = ['type' => 'arrival', 'show' => 0, 'disable' => 0, 'name' => '确认发货'];
- if ($isList) {
- //订单列表页显示的按钮
- $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货'];
- $selfGet = ['type' => 'selfGet', 'show' => 0, 'disable' => 1, 'name' => '自取'];
- if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
- //待确认订单,打印和修改花材按钮可以使用
- $send['disable'] = 1;
- $selfGet['disable'] = 1;
- $print['disable'] = 0;
- $confirm['disable'] = 0;
- }
- if ($order['status'] == self::ORDER_STATUS_UN_SEND) {
- //待配送订单,改花材按钮不可点,自取可点
- $selfGet['disable'] = 0;
- }
- //自取订单发货按钮置灰
- if ($order['sendType'] == self::SEND_TYPE_NO) {
- $send['disable'] = 1;
- }
- //取消订单置灰
- if ($order['status'] == self::ORDER_STATUS_CANCEL) {
- $send['disable'] = 1;
- $selfGet['disable'] = 1;
- $print['disable'] = 1;
- }
- if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
- $send['name'] = '发货记录';
- }
- return [$send, $selfGet, $print, $confirm];
- } else {
- //订单详情页显示的按钮
- if (isset($order['book']) && $order['book'] == 1 && isset($order['stockChange']) && $order['stockChange'] == 0) {
- if ($order['status'] == self::ORDER_STATUS_UN_SEND) {
- $arrival['show'] = 1;
- }
- }
- //待确认订单显示延期付和已付款
- if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
- $debtPay = ['type' => 'debtPay', 'show' => 0, 'disable' => 0, 'name' => '延期收款'];
- $hasPay = ['type' => 'hasPay', 'show' => 0, 'disable' => 0, 'name' => '欠款'];
- $confirm['disable'] = 0;
- return [$print, $debtPay, $hasPay, $confirm, $cancel, $arrival];
- }
- //待配送订单显示打印、发货和自取
- if ($order['status'] == self::ORDER_STATUS_UN_SEND) {
- $selfGet = ['type' => 'selfGet', 'show' => 0, 'disable' => 1, 'name' => '自取'];
- $send = ['type' => 'send', 'show' => 0, 'disable' => 1, 'name' => '发货'];
- if ($order['hasItem'] == 2) {
- return [$print, $selfGet, $send, $arrival];
- }
- $selfGet['disable'] = 0;
- $send['disable'] = 0;
- return [$print, $selfGet, $send, $arrival];
- }
- //配送中显示按钮
- if ($order['status'] == self::ORDER_STATUS_SENDING) {
- $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货'];
- return [$print, $send, $arrival];
- }
- //完成
- if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
- $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货记录'];
- //自取订单不显示发货按钮
- if ($order['sendType'] == self::SEND_TYPE_NO) {
- $send['show'] = 0;
- }
- return [$print, $send, $arrival];
- }
- //取消订单置灰
- if ($order['status'] == self::ORDER_STATUS_CANCEL) {
- $selfGet['disable'] = 1;
- $send['disable'] = 1;
- $print['disable'] = 1;
- return [$modifyProduct, $arrival];
- }
- return [];
- }
- }
- //显示进度 ssh 2021.3.1
- public static function getShowProgress($showProgress, $order)
- {
- if ($showProgress == false) {
- return [];
- }
- $create = ['name' => '创建', 'complete' => 1];
- $unConfirm = ['name' => '待确认', 'complete' => 0];
- if ($order['status'] > 0) {
- $unConfirm['complete'] = 1;
- }
- $out = ['name' => '出库', 'complete' => 0];
- if ($order['status'] > 1) {
- $out['complete'] = 1;
- }
- return [$create, $unConfirm, $out];
- }
- //退款等需要使用原来的订单花材结构
- public static function getOriginalShowItem($showItem, $order)
- {
- if ($showItem == false) {
- return ['list' => [], 'itemStat' => []];
- }
- $orderSn = $order['orderSn'];
- $list = OrderItemClass::getOrderItem($orderSn);
- $totalPrice = 0;
- $totalBigNum = 0;
- $totalSmallNum = 0;
- $kind = 0;
- $itemStat = [];
- if (!empty($list)) {
- $ids = array_column($list, 'productId');
- $ids = array_filter(array_unique($ids));
- $productInfo = ProductClass::getByIds($ids, null, 'id');
- foreach ($list as $key => $val) {
- $productId = $val['productId'] ?? 0;
- $currentInfo = $productInfo[$productId];
- $currentPrice = $productInfo[$productId]['price'] ?? 0;
- $unitPrice = isset($val['xhUnitPrice']) ? floatval($val['xhUnitPrice']) : 0;
- $list[$key]['currentHdPrice'] = $unitPrice;
- //原有售价
- $list[$key]['itemSalePrice'] = floatval($currentPrice);
- //自己填的价格
- $list[$key]['itemModifyPrice'] = $unitPrice;
- $list[$key]['property'] = '';
- $list[$key]['cost'] = $currentInfo['cost'] ?? 0;
- $list[$key]['stock'] = $currentInfo['stock'] ? floatval($currentInfo['stock']) : 0;
- $price = $val['price'];
- $totalPrice = stringUtil::calcAdd($totalPrice, $price);
- $kind++;
- $currentBigNum = $val['bigNum'] ?? 0;
- $currentSmallNum = $val['smallNum'] ?? 0;
- $currentGiveNum = $val['giveNum'] ?? 0;
- $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
- $totalBigNum = bcadd($totalBigNum, $currentGiveNum);
- $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
- }
- $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
- }
- return ['list' => $list, 'itemStat' => $itemStat];
- }
- public static function getShowItem($showItem, $order)
- {
- if ($showItem == false) {
- return ['list' => [], 'itemStat' => []];
- }
- $orderSn = $order['orderSn'];
- $list = OrderItemClass::getOrderItem($orderSn);
- $totalPrice = 0;
- $totalBigNum = 0;
- $totalSmallNum = 0;
- $kind = 0;
- $itemStat = [];
- //小菊增加部分
- $xjAddList = [];
- if (!empty($list)) {
- foreach ($list as $key => $val) {
- $price = $val['price'];
- $totalPrice = stringUtil::calcAdd($totalPrice, $price);
- $kind++;
- $currentBigNum = $val['bigNum'];
- $currentSmallNum = $val['smallNum'];
- $unitType = $val['xhUnitType'] ?? 0;
- $refundNum = $val['refundNum'] ?? 0;
- if ($unitType == 0) {
- $currentBigNum = bcsub($currentBigNum, $refundNum);
- } else {
- $currentSmallNum = bcsub($currentSmallNum, $refundNum);
- }
- $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
- $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
- //赠送数量
- $giveNum = $val['giveNum'] ?? 0;
- $totalBigNum = bcadd($totalBigNum, $giveNum);
- $list[$key]['property'] = '';
- //小菊
- if (isset($val['variety']) && $val['variety'] == 1) {
- $currentItemId = $val['id'] ?? 0;
- $xjList = OrderXjClass::getAllByCondition(['itemId' => $currentItemId], null, '*');
- if (!empty($xjList)) {
- //选了有颜色的小菊才把原小菊删除不显示出来
- unset($list[$key]);
- foreach ($xjList as $xjKey => $xj) {
- $xjBase = $val;
- $num = $xj['num'] ?? 0;
- $price = $xj['price'] ?? 0;
- $name = $xj['name'] ?? '';
- $cover = $xj['cover'] ?? '';
- if ($num > 0) {
- $bigTotalPrice = bcmul($price, $num, 2);
- $xjBase['cover'] = imgUtil::groupImg($cover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- $xjBase['bigCover'] = imgUtil::groupImg($cover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
- $xjBase['unitPrice'] = $price;
- $xjBase['price'] = floatval($bigTotalPrice);
- $xjBase['num'] = floatval($num);
- $xjBase['bigNum'] = floatval($num);
- $xjBase['name'] = $name;
- $xjBase['property'] = '';
- $xjBase['userPrice'] = $bigTotalPrice;
- $xjBase['xhNum'] = floatval($num);
- $xjBase['xhPreNum'] = floatval($num);
- $xjBase['xhPrice'] = floatval($bigTotalPrice);
- $xjAddList[] = $xjBase;
- }
- }
- }
- }
- }
- if (!empty($xjAddList)) {
- $list = array_merge($list, $xjAddList);
- }
- $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
- }
- return ['list' => $list, 'itemStat' => $itemStat];
- }
- //订单列表 ssh 2021.1.19
- public static function getOrderList($where)
- {
- $data = self::getList('*', $where, 'addTime DESC');
- $data['totalActPrice'] = 0;
- $data['totalTkPrice'] = 0;
- if (isset($data['list']) && !empty($data['list'])) {
- foreach ($data['list'] as $key => $val) {
- //同个人同地址当天订单数
- $sameTimeIds = $val['sameTimeIds'] ?? '';
- $sameNum = 0;
- if (!empty($sameTimeIds)) {
- $sameIds = explode(',', $sameTimeIds);
- $sameNum = count($sameIds);
- }
- $data['list'][$key]['sameTimeIdsNum'] = $sameNum;
- $data['list'][$key]['customAvatarUrl'] = imgUtil::groupImg('');
- }
- }
- return $data;
- }
- //整合订单员工和供货商等信息 ssh 2021.1.19
- //$isList 是否列表页
- public static function groupOrder($list, $showButton = false, $showItem = false, $showExpress = false, $isList = false)
- {
- if (empty($list)) {
- return $list;
- }
- $adminIds = array_unique(array_filter(array_column($list, 'adminId')));
- $adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id');
- $customIds = array_column($list, 'customId');
- $customIds = array_unique(array_filter($customIds));
- $customInfoList = CustomClass::getByIds($customIds, null, 'id');
- foreach ($list as $key => $val) {
- $adminId = $val['adminId'] ?? 0;
- $list[$key]['adminName'] = $adminInfo[$adminId]['name'] ?? '';
- $list[$key]['customAddress'] = $val['fullAddress'] ?? '';
- //显示列表页的操作按钮
- $list[$key]['buttonList'] = self::getShowButton($showButton, $isList, $val);
- //为了列表页的打印按钮能用,列表也强制显示花材
- $showItem = true;
- //退款需要显示原有的花材结构,不显示小菊的多颜色
- $getOriginalItem = Yii::$app->request->get('getOriginalItem', 0);
- $getOriginalItem2 = Yii::$app->request->post('getOriginalItem', 0);
- if ($getOriginalItem == 1 || $getOriginalItem2 == 1) {
- $showItemData = self::getOriginalShowItem($showItem, $val);
- } else {
- $showItemData = self::getShowItem($showItem, $val);
- }
- $list[$key]['product'] = $showItemData['list'];
- $list[$key]['productStat'] = $showItemData['itemStat'];
- $showResetItem = 0;
- //待付款订单显示改花材按钮
- if ($val['status'] == self::PAY_STATUS_UN_PAY) {
- $showResetItem = 1;
- }
- $list[$key]['showResetItem'] = $showResetItem;
- //获取配送进展
- $expressProgress = '';
- if ($val['sendType'] == 4) {
- $expressInfo = OrderExpressClass::getByCondition(['orderSn' => $val['orderSn']]);
- if ($expressInfo) {
- $expressProgress = ['progressName' => OrderExpressClass::$statusMap[$expressInfo['status']] ?? ''];
- }
- }
- $list[$key]['sendTypeName'] = self::$sendTypeMap[$val['sendType']] ?? '未知';
- $list[$key]['expressProgress'] = $expressProgress;
- $list[$key]['customAvatarUrl'] = imgUtil::groupImg($val['customAvatar']);
- $list[$key]['customName'] = isset($val['customId']) && !empty($val['customId']) ? $val['customName'] : '散客';
- $customId = $val['customId'] ?? '';
- $debtAmount = $customInfoList[$customId]['debtAmount'] ?? 0.00;
- //打印数据组合
- $printData = self::getPrintData($val, $debtAmount, $showItemData);
- $list[$key]['printData'] = json_encode($printData);
- $list[$key]['debtAmount'] = $debtAmount;
- $list[$key]['customShopId'] = $customInfoList[$customId]['shopId'] ?? 0;
- }
- return $list;
- }
- public static function printGroup($current, $content, $showPrice = 1, $fontSizeType = 0)
- {
- //58mm的机器,一行打印16个汉字,32个字母
- $productPrice = $current['price'] ?? '';
- $name = $current['name'] ?? '';
- if (floatval($productPrice) == 0.01) {
- $name = $name . '(送)';
- }
- $productNum = $current['num'] ?? '';
- $itemNum = $current['itemNum'] ?? 0;
- $refundNum = $current['refundNum'] ?? 0;
- $unitName = $current['unitName'] ?? '扎';
- $remark = $current['remark'] ?? '';
- $lastNum = bcsub($itemNum, $refundNum);
- if (!empty($remark)) {
- $show = $name . ' ' . $lastNum . $unitName . "【" . $remark . "】";
- } else {
- $show = $name . ' ' . $lastNum . $unitName;
- }
- $content .= '<B>' . $show . '</B><BR>';
- if ($refundNum > 0) {
- $content .= '(买' . $itemNum . $unitName . ' 退' . $refundNum . $unitName . ')<BR>';
- }
- if ($showPrice == 1) {
- $content .= $productNum . ' = ' . $productPrice . '元<BR>';
- }
- $content .= '--------------------------------<BR>';
- return $content;
- }
- //合并打印订单 ssh 20230929
- public static function mergePrintOrder($ids, $mainId)
- {
- $all = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
- if (empty($all)) {
- util::fail('没有找到订单');
- }
- $snList = [];
- $sendNumList = [];
- $remarkList = [];
- foreach ($all as $info) {
- if ($info->mainId != $mainId) {
- util::fail('不是你的订单');
- }
- $orderSn = $info->orderSn;
- if ($info->payStatus == 1) {
- $snList[] = $orderSn;
- $orderInfo = $info;
- $sendNumList[] = $info->sendNum;
- if (!empty($info->remark)) {
- $remarkList[] = $info->remark;
- }
- }
- }
- $sendNumString = '';
- if (!empty($sendNumList)) {
- $sendNumString = implode(',', $sendNumList);
- }
- $remarkString = '';
- if (!empty($remarkList)) {
- $remarkString = implode(',', $remarkList);
- }
- $allItem = OrderItemClass::getAllByCondition(['orderSn' => ['in', $snList]], null, '*');
- if (empty($allItem)) {
- util::fail('没有花材信息');
- }
- $new = [];
- foreach ($allItem as $currentItem) {
- $unitType = $currentItem['xhPreUnitType'] ?? 1;
- $productId = $currentItem['productId'] ?? 0;
- if ($unitType == 0 && $productId > 0) {
- if (isset($new[$productId])) {
- $xhNum = $currentItem['xhNum'] ?? 0;
- $refundNum = $currentItem['refundNum'] ?? 0;
- $giveNum = $currentItem['giveNum'] ?? 0;
- $new[$productId]['xhNum'] = bcadd($new[$productId]['xhNum'], $xhNum);
- $new[$productId]['refundNum'] = bcadd($new[$productId]['refundNum'], $refundNum);
- $new[$productId]['giveNum'] = bcadd($new[$productId]['giveNum'], $giveNum);
- } else {
- $new[$productId] = $currentItem;
- }
- }
- }
- $showPrice = 1;
- $customId = $orderInfo->customId ?? 0;
- $c = CustomClass::getById($customId);
- $debtAmount = $c['debtAmount'] ?? 0.00;
- $shopId = $orderInfo->shopId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- util::fail('打印失败,没有找到门店9');
- }
- $sjId = $shop->sjId ?? 0;
- $fontSizeType = $shop->fontSize ?? 0;
- $telephone = $shop->telephone ?? '';
- $sj = SjClass::getById($sjId, true);
- $sjName = $sj->name ?? '';
- $shopName = $shop->shopName ?? '';
- $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
- $fromType = $orderInfo->fromType ?? dict::getDict('fromType', 'shop');
- $fromTypeMap = dict::getDict('fromTypeMap');
- $fromTypeName = $fromTypeMap[$fromType] ?? '门店';
- $content = "<CB>" . $currentName . "</CB>";
- $content .= "<CB>销售单</CB><BR><BR>";
- $content .= '<B>' . $sendNumString . ' ' . $fromTypeName . '</B><BR>';
- $content .= '--------------------------------<BR>';
- //快捷开单不需要打印买家信息
- if ($customId != $shop->skCustomId) {
- $content .= '<B>买家信息:</B><BR><BR>';
- $content .= '<B>' . $orderInfo->customName . '</B><BR>';
- $content .= '<B>' . $orderInfo->customMobile . '</B><BR>';
- if (isset($orderInfo->address) && !empty($orderInfo->address)) {
- $content .= $orderInfo->fullAddress;
- if (isset($orderInfo->showAddress) && !empty($orderInfo->showAddress)) {
- $content .= '(' . $orderInfo->showAddress . ')<BR>';
- } else {
- $content .= '<BR>';
- }
- }
- }
- if (isset($orderInfo->book) && $orderInfo->book == 1) {
- $content .= '<B>预订单</B><BR>';
- }
- if (isset($orderInfo->presell) && $orderInfo->presell == 1) {
- $content .= '<B>预售单</B><BR>';
- }
- if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
- if (isset($orderInfo->transType)) {
- $sendName = '同城配送';
- if ($orderInfo->transType == 0) {
- $sendName = '德邦物流';
- }
- if ($orderInfo->transType == 1) {
- $sendName = '顺丰物流';
- }
- if ($orderInfo->transType == 2) {
- $sendName = '冷链物流';
- }
- if ($orderInfo->transType == 3) {
- $sendName = '航空物流';
- }
- if ($orderInfo->transType == 4) {
- $sendName = '同城配送';
- }
- if ($orderInfo->transType == 5) {
- $sendName = '到店自取';
- }
- $content .= '<BR><B>' . $sendName . '</B><BR>';
- }
- } else {
- if (isset($orderInfo->sendType)) {
- $sendName = '送货上门';
- if ($orderInfo->sendType == 1) {
- $sendName = '到店自取';
- }
- if ($orderInfo->sendType == 2) {
- $sendName = '代叫配送';
- }
- if ($orderInfo->sendType == 3) {
- $wlName = $orderInfo['wlName'] ?? '未填物流';
- $sendName = $wlName;
- }
- if ($orderInfo->sendType == 4) {
- $sendName = '发快递';
- }
- $content .= '<BR><B>' . $sendName . '</B><BR>';
- }
- }
- if (!empty($remarkString)) {
- $content .= '<BR>';
- $content .= '备注:<BR>';
- $content .= '<B>' . $remarkString . '</B><BR>';
- }
- $content .= '<BR>';
- $content .= '商品 数量/单价 金额 <BR>';
- $content .= '--------------------------------<BR>';
- $totalNum = 0;
- $refundTotalNum = 0;
- foreach ($new as $current) {
- //58mm的机器,一行打印16个汉字,32个字母
- $productPrice = $current['xhUnitPrice'] ?? '';
- $name = $current['name'] ?? '';
- if (floatval($productPrice) == 0.01) {
- $name = $name . '(送)';
- }
- $giveNum = $current['giveNum'] ?? 0;
- $refundNum = $current['refundNum'] ?? 0;
- $productNum = $current['xhNum'] ?? '';
- $unitName = $current['xhUnitName'] ?? '扎';
- $totalNum = bcadd($totalNum, $giveNum);
- $refundTotalNum = bcadd($refundTotalNum, $refundNum);
- $lastNum = bcadd($productNum, $giveNum);
- $lastNum = bcsub($lastNum, $refundNum);
- $show = $name . ' ' . $lastNum . $unitName;
- $hint = '';
- if ($refundNum > 0 || $giveNum > 0) {
- $hint .= '(买' . $productNum . $unitName;
- }
- if ($refundNum > 0) {
- $hint .= ' 退' . $refundNum . $unitName;
- if ($giveNum <= 0) {
- $hint .= ')';
- }
- }
- if ($giveNum > 0) {
- $hint .= ' 送' . $giveNum . $unitName . ')';
- }
- $content .= '<B>' . $show . '</B><BR>';
- if (!empty($hint)) {
- $content .= $hint . '<BR>';
- }
- $content .= '--------------------------------<BR>';
- $totalNum = bcadd($totalNum, $productNum);
- }
- $content .= '********************************<BR>';
- $kindNum = count($new);
- $remainNum = bcsub($totalNum, $refundTotalNum);
- $content .= "<CB>共{$kindNum}种";
- $content .= ",{$remainNum}扎";
- $content .= "</CB>";
- $content .= '********************************<BR><BR>';
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
- $printSn = $ext['printSn'] ?? '';
- if (!empty($printSn)) {
- $p = new printUtil($printSn);
- $p->printMsg($content, $shop);
- }
- foreach ($all as $info) {
- if ($info->payStatus == 1) {
- $info->printNum += 1;
- $info->printStatus = 2;
- $info->save();
- }
- }
- }
- //超出数量的打印 sssh 20240605
- public static function onlinePrintOver($showItem, $orderInfo, $currentName, $shop)
- {
- $itemList = $showItem['list'];
- $orderSn = $orderInfo->orderSn ?? '';
- $arr = array_chunk($itemList, 40);
- $totalPage = count($arr);
- foreach ($arr as $key => $itemList) {
- $content = '';
- $content .= "<CB>{$currentName}</CB><BR>";
- $content .= "<CB>销售单</CB><BR><BR>";
- $content .= '<CB>' . $orderSn . '</CB><BR><BR>';
- //快捷开单不需要打印买家信息
- if ($orderInfo->customId != $shop->skCustomId) {
- $content .= '<B>买家信息:</B><BR><BR>';
- $content .= '<B>' . $orderInfo->customName . '</B><BR>';
- $content .= '<B>' . $orderInfo->customMobile . '</B><BR>';
- if (isset($orderInfo['address']) && !empty($orderInfo['address'])) {
- $content .= $orderInfo->fullAddress;
- if (isset($orderInfo['showAddress']) && !empty($orderInfo['showAddress']) && $orderInfo->fullAddress != $orderInfo['showAddress']) {
- $content .= '(' . $orderInfo['showAddress'] . ')<BR><BR>';
- } else {
- $content .= '<BR><BR>';
- }
- }
- }
- if ($totalPage > 1) {
- $currentPage = bcadd($key, 1);
- $content .= "<CB>第{$currentPage}页,共{$totalPage}页</CB><BR>";
- }
- $content .= '<BR>';
- $content .= '商品 数量 <BR>';
- $content .= '--------------------------------<BR>';
- if (isset($itemList) && !empty($itemList)) {
- foreach ($itemList as $info) {
- $name = $info['name'] ?? '';
- $num = $info['xhNum'] ?? 0;
- $refundNum = $info['refundNum'] ?? 0;
- $lastNum = bcsub($num, $refundNum);
- $unitName = $info['xhUnitName'] ?? '';
- $show = $name . ' ' . $lastNum . $unitName;
- $content .= '<B>' . $show . '</B><BR>';
- $content .= '--------------------------------<BR>';
- }
- }
- $kindNum = $showItem['itemStat']['kind'] ?? 0;
- $bigNum = $showItem['itemStat']['bigNum'] ?? 0;
- $smallNun = $showItem['itemStat']['smallNun'] ?? 0;
- $content .= '********************************<BR>';
- $content .= "<CB>共{$kindNum}种";
- $content .= " 数量:";
- if ($bigNum > 0) {
- $content .= "{$bigNum}";
- }
- if ($smallNun > 0) {
- $content .= "{$smallNun}";
- }
- $content .= "</CB>";
- $content .= '********************************<BR><BR>';
- $content .= '<BR>';
- $content .= '<BR>';
- $shopId = $shop->id;
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
- $printSn = $ext['printSn'] ?? '';
- if (!empty($printSn)) {
- $p = new printUtil($printSn);
- $p->printMsg($content, $shop);
- }
- }
- }
- //云打印 ssh 20210709
- public static function onlinePrint($orderInfo, $showPrice = 1)
- {
- if (getenv('YII_ENV') == 'production') {
- //丽子鲜花,客户线上下单,小票上不显示价格
- if (isset($orderInfo->shopId) && $orderInfo->shopId == 1527) {
- if (isset($orderInfo->customShopAdminId) && !empty($orderInfo->customShopAdminId)) {
- $showPrice = 0;
- }
- }
- //源花汇小票不带价格
- if (isset($orderInfo->mainId) && $orderInfo->mainId == 10536) {
- $showPrice = 0;
- }
- //北京花篮子,线上下单,不显示价格
- if (isset($orderInfo->mainId) && $orderInfo->mainId == 10735) {
- if (isset($orderInfo->customShopAdminId) && !empty($orderInfo->customShopAdminId)) {
- $showPrice = 0;
- }
- }
- //淄博花超鲜花小票不带价格
- if (isset($orderInfo->mainId) && $orderInfo->mainId == 16293) {
- $showPrice = 0;
- }
- //淮北花语集小票不带价格
- if (isset($orderInfo->mainId) && $orderInfo->mainId == 52291) {
- $showPrice = 0;
- }
- } else {
- if (isset($orderInfo->mainId) && $orderInfo->mainId == 644) {
- //$showPrice = 0;
- }
- }
- if (isset($orderInfo['actPrice']) && $orderInfo['actPrice'] == 0 && $orderInfo['book'] == 0) {
- util::fail('已全额退款,不能打小票');
- }
- $showItem = OrderClass::getShowItem(true, $orderInfo);
- $customId = $orderInfo['customId'] ?? 0;
- $c = CustomClass::getById($customId);
- $debtAmount = $c['debtAmount'] ?? 0.00;
- $orderSn = $orderInfo['orderSn'] ?? '';
- $shopId = $orderInfo['shopId'] ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if (empty($shop)) {
- util::fail('打印失败,没有找到门店10');
- }
- $sjId = $shop->sjId ?? 0;
- $fontSizeType = $shop->fontSize ?? 0;
- $telephone = $shop->telephone ?? '';
- $telephone2 = $shop->telephone2 ?? '';
- $sj = SjClass::getById($sjId, true);
- $sjName = $sj->name ?? '';
- $shopName = $shop->shopName ?? '';
- $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
- $itemList = $showItem['list'] ?? [];
- if (count($itemList) > 40) {
- //超出数量的打印
- self::onlinePrintOver($showItem, $orderInfo, $currentName, $shop);
- return true;
- }
- $fromType = $orderInfo['fromType'] ?? dict::getDict('fromType', 'shop');
- $fromTypeMap = dict::getDict('fromTypeMap');
- $fromTypeName = $fromTypeMap[$fromType] ?? '门店';
- $content = "<CB>" . $currentName . "</CB>";
- $content .= "<CB>销售单</CB><BR><BR>";
- $respond = self::getPrintData($orderInfo, $debtAmount, $showItem);
- $content .= '<B>' . $respond['sendNum'] . ' ' . $fromTypeName . '</B><BR>';
- $content .= '--------------------------------<BR>';
- //快捷开单不需要打印买家信息
- if ($customId != $shop->skCustomId) {
- $content .= '<B>买家信息:</B><BR><BR>';
- $content .= '<B>' . $respond['custom']['customName'] . '</B><BR>';
- $content .= '<B>' . $respond['custom']['customMobile'] . '</B><BR>';
- if (isset($orderInfo['address']) && !empty($orderInfo['address'])) {
- $content .= $respond['custom']['fullAddress'];
- if (isset($orderInfo['showAddress']) && !empty($orderInfo['showAddress']) && $orderInfo['showAddress'] != $respond['custom']['fullAddress']) {
- $content .= '(' . $orderInfo['showAddress'] . ')<BR>';
- } else {
- $content .= '<BR>';
- }
- }
- }
- $payDate = date("Y-m-d", strtotime($orderInfo['payTime']));
- $sendTimWant = $orderInfo['sendTimeWant'] ?? '';
- if ($payDate != $sendTimWant) {
- $content .= '<BR>';
- $content .= '送货时间:<BR>';
- $content .= '<B>' . $orderInfo['sendTimeWant'] . '</B><BR>';
- }
- if (isset($orderInfo['book']) && $orderInfo['book'] == 1) {
- $content .= '<B>预订单</B><BR>';
- }
- if (isset($orderInfo['presell']) && $orderInfo['presell'] == 1) {
- $content .= '<B>预售单</B><BR>';
- }
- if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
- if (isset($orderInfo['transType'])) {
- $sendName = '同城配送';
- if ($orderInfo['transType'] == 0) {
- $sendName = '德邦物流';
- }
- if ($orderInfo['transType'] == 1) {
- $sendName = '顺丰物流';
- }
- if ($orderInfo['transType'] == 2) {
- $sendName = '冷链物流';
- }
- if ($orderInfo['transType'] == 3) {
- $sendName = '航空物流';
- }
- if ($orderInfo['transType'] == 4) {
- $sendName = '同城配送';
- }
- if ($orderInfo['transType'] == 5) {
- $sendName = '到店自取';
- }
- $content .= '<BR><B>' . $sendName . '</B><BR>';
- }
- } else {
- if (isset($orderInfo['sendType'])) {
- $sendName = '送货上门';
- if ($orderInfo['sendType'] == 1) {
- $sendName = '到店自取';
- }
- if ($orderInfo['sendType'] == 2) {
- $sendName = '代叫配送';
- }
- if ($orderInfo['sendType'] == 3) {
- $wlName = $orderInfo['wlName'] ?? '未填物流';
- $sendName = $wlName;
- }
- if ($orderInfo['sendType'] == 4) {
- $sendName = '发快递';
- }
- $content .= '<BR><B>' . $sendName . '</B><BR>';
- }
- }
- if (isset($respond['remark']) && !empty($respond['remark'])) {
- $content .= '<BR>';
- $content .= '备注:<BR>';
- $content .= '<B>' . $respond['remark'] . '</B><BR>';
- }
- $content .= '<BR>';
- $content .= '商品 数量/单价 金额 <BR>';
- $content .= '--------------------------------<BR>';
- if (isset($respond['product']) && !empty($respond['product'])) {
- foreach ($respond['product'] as $current) {
- $content = self::printGroup($current, $content, $showPrice, $fontSizeType);
- }
- }
- if (isset($respond['give']) && !empty($respond['give'])) {
- $content .= '<BR><CB>【赠送】</CB><BR>';
- foreach ($respond['give'] as $current) {
- //58mm的机器,一行打印16个汉字,32个字母
- $name = $current['name'] ?? '';
- $count = $current['count'] ?? '';
- $content .= '<B>' . $name . ' ' . $count . '</B><BR>';
- $content .= '--------------------------------<BR>';
- }
- }
- $kindNum = $showItem['itemStat']['kind'] ?? 0;
- $bigNum = $showItem['itemStat']['bigNum'] ?? 0;
- $smallNun = $showItem['itemStat']['smallNun'] ?? 0;
- $content .= '********************************<BR>';
- $content .= "<CB>共{$kindNum}种 ";
- if ($bigNum > 0) {
- $content .= "{$bigNum}扎";
- }
- if ($smallNun > 0) {
- $content .= "{$smallNun}支";
- }
- $content .= "</CB>";
- $content .= '********************************<BR><BR>';
- if ($showPrice == 1) {
- if (isset($orderInfo['itemPrice']) && $orderInfo['itemPrice'] > 0) {
- $content .= '商品金额:' . floatval($orderInfo['itemPrice']) . '<BR>';
- }
- if (isset($respond['sendCost']) && $respond['sendCost'] > 0) {
- $content .= ' 运费:' . floatval($respond['sendCost']) . '<BR>';
- }
- if (isset($orderInfo['packCost']) && $orderInfo['packCost'] > 0) {
- $content .= ' 打包费:' . floatval($orderInfo['packCost']) . '<BR>';
- }
- $content .= '合计金额:' . floatval($respond['prePrice']) . '<BR>';
- if (isset($respond['discountAmount']) && !empty($respond['discountAmount']) && $respond['discountAmount'] > 0) {
- $content .= '优惠扣除:-' . floatval($respond['discountAmount']) . '<BR>';
- }
- if (isset($orderInfo['book']) && $orderInfo['book'] == 1) {
- $content .= '预付金额:' . floatval($orderInfo['bookPrice']) . '<BR>';
- }
- if (isset($orderInfo['tkPrice']) && $orderInfo['tkPrice'] > 0) {
- $content .= '退款金额:' . floatval($orderInfo['tkPrice']) . '<BR>';
- }
- $content .= '<B>订单金额:' . floatval($respond['realPrice']) . '</B><BR>';
- if (isset($respond['debt']) && $respond['debt'] == 1) {
- $content .= '实付金额:0<BR>';
- } else {
- $content .= '实付金额:' . floatval($respond['realPrice']) . '<BR>';
- }
- if ($debtAmount > 0) {
- $content .= '累计赊账:' . floatval($debtAmount) . '<BR>';
- }
- $content .= '--------------------------------<BR>';
- }
- $getInfo = self::getById($orderInfo['id']);
- if (!empty($telephone)) {
- $content .= '联系电话:' . $telephone . '<BR>';
- }
- if (!empty($telephone2)) {
- $content .= '联系电话2:' . $telephone2 . '<BR>';
- }
- $content .= '订单日期:' . date("Y-m-d H:i", strtotime($getInfo['addTime'])) . '<BR>';
- $content .= '订单编号:' . $respond['orderSn'] . '<BR>';
- if (isset($orderInfo['shopAdminId']) && !empty($orderInfo['shopAdminId'])) {
- $content .= '本单由员工(' . $orderInfo['shopAdminName'] . ')开单<BR>';
- } else {
- $content .= '本单由客户(' . $orderInfo['customShopAdminName'] . ')下单<BR>';
- }
- $content .= "<BR>";
- if (getenv('YII_ENV') == 'production') {
- //丽子鲜花、花样年华、镜中花卉、满天星、世纪花、盛丰、福清辉煌、美阁都不显示扫码买花
- if (!in_array($orderInfo->shopId, [1527, 1585, 1596, 16454, 33668, 38492, 36596, 35389, 38322, 43274, 40312, 44556, 42946, 51758, 8391])) {
- //勇记、国恋、花悠星零售开单不需要打印扫码买花
- if ($customId != 12145 || $customId != 12487 || $customId != 12281) {
- $content .= "<BR>";
- $content .= "<C>扫码买花结账</C>";
- $content .= "<BR>";
- $host = Yii::$app->params['hdHost'];
- $content .= "<QR>" . $host . "/#/admin/home/workbench</QR>";
- }
- }
- }
- $content .= "<BR>";
- $content .= "<BR>";
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
- $printSn = $ext['printSn'] ?? '';
- if (!empty($printSn)) {
- $p = new printUtil($printSn);
- $p->printMsg($content, $shop, $orderSn);
- }
- }
- //打印数据 ssh 20210702
- public static function getPrintData($val, $debtAmount, $showItem)
- {
- $giveList = [];
- $printProduct = [];
- if (isset($showItem['list']) && !empty($showItem['list'])) {
- foreach ($showItem['list'] as $itemKey => $itemVal) {
- $bigNum = $itemVal['bigNum'] ?? 0;
- $bigUnitPrice = $itemVal['unitPrice'] ?? 0;
- $smallUnitPrice = $itemVal['smallUnitPrice'] ?? 0;
- $smallNum = $itemVal['smallNum'] ?? 0;
- $giveNum = $itemVal['giveNum'] ?? 0;
- $xhUnitName = $itemVal['xhUnitName'] ?? '扎';
- $refundNum = $itemVal['refundNum'] ?? 0;
- $remark = $itemVal['remark'] ?? '';
- if ($bigNum > 0) {
- $bigTotalPrice = bcmul($bigUnitPrice, $bigNum, 2);
- $printProduct[] = [
- 'name' => $itemVal['name'] ?? '',
- 'num' => floatval($bigNum) . $xhUnitName . ' * ' . floatval($bigUnitPrice) . '元',
- 'count' => floatval($bigNum) . $xhUnitName,
- 'price' => floatval($bigTotalPrice),
- 'refundNum' => $refundNum,
- 'unitName' => $xhUnitName,
- 'itemNum' => $bigNum,
- 'remark' => $remark,
- ];
- }
- if ($smallNum > 0) {
- $smallTotalPrice = bcmul($smallUnitPrice, $smallNum, 2);
- $printProduct[] = [
- 'name' => $itemVal['name'] ?? '',
- 'num' => floatval($smallNum) . '支 * ' . floatval($smallUnitPrice) . '元',
- 'count' => floatval($smallNum) . '支',
- 'price' => floatval($smallTotalPrice),
- 'refundNum' => $refundNum,
- 'unitName' => '支',
- 'itemNum' => $smallNum,
- 'remark' => $remark,
- ];
- }
- if ($giveNum > 0) {
- $giveList[] = [
- 'name' => $itemVal['name'] ?? '',
- 'num' => floatval($giveNum) . $xhUnitName . ' * 0元',
- 'count' => floatval($giveNum) . $xhUnitName,
- 'price' => 0,
- 'unitName' => $xhUnitName,
- 'itemNum' => $giveNum,
- 'remark' => $remark,
- ];
- }
- }
- }
- $sendNum = $val['sendNum'] ?? '';
- $relateOrderSn = $val['orderSn'] ?? '';
- $refundList = [];
- $refundData = RefundOrderClass::getAllByCondition(['relateOrderSn' => $relateOrderSn], null, '*', null, true);
- if (!empty($refundData)) {
- foreach ($refundData as $refund) {
- $refundOrderSn = $refund->orderSn ?? '';
- $refundProductList = RefundOrderItemClass::getAllByCondition(['orderSn' => $refundOrderSn], null, '*');
- if (!empty($refundProductList)) {
- foreach ($refundProductList as $currentRefund) {
- $num = $currentRefund['xhNum'] ?? 0;
- $unitName = $currentRefund['xhUnitName'] ?? '';
- $unitPrice = $currentRefund['xhUnitPrice'] ?? 0;
- $currentPrice = bcmul($unitPrice, $num, 2);
- $refundList[] = [
- 'name' => $currentRefund['name'] ?? '',
- 'num' => floatval($num) . $unitName . '*' . floatval($unitPrice),
- 'count' => floatval($num) . $unitName,
- 'price' => floatval($currentPrice),
- ];
- }
- }
- }
- }
- $printData = [
- 'address' => '',
- 'sendCost' => $val['sendCost'] ?? '0.00',
- 'prePrice' => $val['prePrice'] ?? '0.00',
- 'discountAmount' => $val['discountAmount'] ?? '0.00',
- 'realPrice' => $val['realPrice'] ?? '0.00',
- 'refundPrice' => $val['refundPrice'] ?? '0.00',
- 'debt' => $val['debt'] ?? 0,
- 'orderSn' => $val['orderSn'] ?? '',
- 'date' => $val['addTime'] ?? '',
- 'remark' => $val['remark'] ?? '',
- 'custom' => [
- 'customName' => $val['customName'] ?? '',
- 'customMobile' => $val['customMobile'] ?? '',
- 'fullAddress' => $val['fullAddress'] ?? '',
- ],
- 'product' => $printProduct,
- 'refund' => $refundList,
- 'sendNum' => $sendNum,
- 'debtAmount' => $debtAmount,
- 'give' => $giveList,
- ];
- return $printData;
- }
- //订单的验证 ssh 2021.3.2
- public static function valid($info, $shopId)
- {
- if (empty($info)) {
- util::fail('没有找到订单');
- }
- if (isset($info['shopId']) && $info['shopId'] == $shopId) {
- return true;
- }
- util::fail('无法操作的订单');
- }
- //快递送 ssh 2021.3.16
- public static function thirdSend($order, $expressInfo)
- {
- if ($order->status == self::ORDER_STATUS_UN_PAY) {
- util::fail('订单未付款');
- }
- if ($order->status != self::ORDER_STATUS_UN_SEND) {
- util::fail('不是待配送状态');
- }
- $id = $order->id;
- $expressId = $expressInfo['expressId'] ?? 1;
- $expressName = $expressInfo['deliveryName'] ?? '达达';
- $expressRemark = $expressInfo['remark'] ?? '';
- $order->status = self::ORDER_STATUS_SENDING;
- $order->sendType = self::SEND_TYPE_THIRD;
- $order->expressId = $expressId;
- $order->save();
- $shopId = $order->shopId;
- $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
- if (empty($shop)) {
- util::fail('没有找到门店11');
- }
- $shop->unSendOrder -= 1;
- $shop->sendingOrder += 1;
- $shop->save();
- $express = OrderExpressClass::getByCondition(['orderId' => $id]);
- if (!empty($express)) {
- util::fail('已经发过了');
- }
- //达达
- $dadaRes = DadaExpressServices::addOrder($order, $expressRemark);
- $orderSn = $order->orderSn;
- $sjId = $order->sjId ?? 0;
- /*
- $getInfo = ExpressClass::getExpressInfo($expressId);
- $hour = $expressInfo['sendTime'] ?? '12:00';
- $sendCost = 12;
- $distance = 5;
- $sendTime = strtotime(date("Y-m-d ") . $hour);
- OrderSendClass::thirdSend($order);
- */
- $sendTime = $order->sendTime;
- if ($sendTime == '0000-00-00 00:00:00') {
- $sendTime = time();
- } else {
- $sendTime = strtotime($order->sendTime);
- }
- $expData = [
- 'orderId' => $id,
- 'orderSn' => $orderSn,
- 'sjId' => $sjId,
- 'expressId' => $expressId,
- 'sendTime' => $sendTime,
- 'cost' => $dadaRes['fee'],
- 'distance' => $dadaRes['distance'],
- 'status' => 1,
- 'expressName' => $expressName,
- 'remark' => $expressRemark,
- ];
- OrderExpressClass::addExpress($expData);
- OrderSendClass::thirdSend($order);
- $respond = [
- 'expressName' => $expressName,
- 'expressId' => $expressId,
- 'distance' => $dadaRes['distance'],
- 'cost' => $dadaRes['fee'],
- 'status' => 2,
- 'tip' => 0,
- ];
- //采购单变成已发货
- $purchaseId = $order->purchaseId ?? 0;
- PurchaseClass::sending($purchaseId);
- return $respond;
- }
- //本店送 ssh 2021.1.24
- public static function selfSend($info)
- {
- if ($info->status == self::ORDER_STATUS_UN_PAY) {
- util::fail('订单未付款');
- }
- if ($info->status != self::ORDER_STATUS_UN_SEND) {
- util::fail('不是待配送状态');
- }
- $info->status = self::ORDER_STATUS_SENDING;
- $info->sendType = self::SEND_TYPE_MYSELF;
- $info->save();
- $shopId = $info->shopId;
- $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one();
- if (empty($shop)) {
- util::fail('没有找到门店12');
- }
- $shop->unSendOrder -= 1;
- $shop->sendingOrder += 1;
- $shop->save();
- OrderSendClass::selfSend($info);
- //采购单变成已发货
- $purchaseId = $info->purchaseId ?? 0;
- PurchaseClass::sending($purchaseId);
- }
- //订单完成 ssh 2020.3.12
- public static function complete($order, $shop)
- {
- $order->status = OrderClass::ORDER_STATUS_COMPLETE;
- $order->currentFlow = self::TOTAL_FLOW;
- $order->totalFlow = self::TOTAL_FLOW;
- $order->save();
- $shop->finishOrder += 1;
- $shop->sendingOrder -= 1;
- $shop->save();
- return $order;
- }
- //修改订单表的配送信息 lqh 2021.3.28
- public static function updateCustomExpressInfo($id, $expressAddInfo)
- {
- $data = [
- 'province' => $expressAddInfo['province'],
- 'city' => $expressAddInfo['city'],
- 'address' => $expressAddInfo['address'],
- 'floor' => $expressAddInfo['floor'],
- 'fullAddress' => $expressAddInfo['city'] . $expressAddInfo['address'] . $expressAddInfo['floor'],
- 'lat' => $expressAddInfo['lat'],
- 'long' => $expressAddInfo['long'],
- 'sendTime' => $expressAddInfo['sendTime'],
- ];
- return self::updateById($id, $data);
- }
- //最客户最近的订单 ssh 2021.5.4
- public static function getCustomOrder($id, $limit = 10, $order = null, $with = null)
- {
- $where = ['customId' => $id, 'payStatus' => 1];
- return self::getLimitList('*', $where, $limit, $order, $with);
- }
- //销售单取消 ssh 2021.5.14
- public static function cancel($id)
- {
- $order = self::getLockById($id);
- if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
- util::fail("销售单{$id}不是待付款状态,无法取消");
- }
- $order->status = self::ORDER_STATUS_CANCEL;
- $order->cancelTime = date("Y-m-d H:i:s");
- $order->save();
- $shopId = $order->shopId;
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- util::fail('没有找到门店13');
- }
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getLockById($mainId);
- if (empty($main)) {
- util::fail('没有main信息6');
- }
- $main->unPayOrder -= 1;
- $main->cancelOrder += 1;
- $main->save();
- if ($order->book != 1) {
- //非预订单库存回滚
- $orderItem = OrderItemClass::getOrderItem($order->orderSn);
- foreach ($orderItem as $v) {
- $stockInfo = ProductClass::addStockByItemNum($v['productId'], $v['num']);
- $recordData = [];
- $recordData['sjId'] = $order->sjId;
- $recordData['shopId'] = $shopId;
- //增加中央ID
- $recordData['mainId'] = ProductClass::getMainIdByProductId($v['productId']);
- $recordData['itemId'] = $v['itemId'] ?? 0;
- $recordData['itemNum'] = $v['num'];
- $recordData['oldStock'] = $stockInfo['oldStock'];
- $recordData['newStock'] = $stockInfo['newStock'];
- $recordData['productId'] = $v['productId'];
- $recordData['orderSn'] = $order->orderSn;
- $recordData['relateName'] = $order->customName ?? '';
- $recordData['ptStyle'] = dict::getDict('ptStyle', 'ghs');
- StockRecordClass::addSellStockOrderCancelRecord($recordData);
- }
- }
- return $order;
- }
- //新订单入队列 ssh 20211012
- public static function newOrderAddQueue($order)
- {
- $shopId = $order->shopId ?? 0;
- if (empty($shopId)) {
- return false;
- }
- $id = $order->id ?? 0;
- if (empty($id)) {
- return false;
- }
- $newOrderKey = 'ghsNewOrder_' . $shopId;
- Yii::$app->redis->executeCommand('LPUSH', [$newOrderKey, $id]);
- }
- public static function createImgOrder($order, $shop, $staff, $all)
- {
- $staffName = $order->shopAdminName ?? '';
- $shopName = $shop->shopName ?? '';
- $sjName = $shop->merchantName ?? '';
- $fullSjName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
- $customName = $order->customName ?? '';
- $customId = $order->customId ?? 0;
- $custom = CustomClass::getById($customId, true);
- $debtAmount = $custom->debtAmount ?? 0;
- $mainId = $order->mainId ?? 0;
- $dir = Yii::getAlias('@app/web/html/' . $mainId . '/');
- if (!file_exists($dir)) {
- //检查是否有该文件夹,如果没有就创建,并给予最高权限
- mkdir($dir, 0700, true);
- }
- $payTime = $order->payTime ?? '';
- $currentDate = date("Y-m-d", strtotime($payTime));
- $sameTimeIds = $order->sameTimeIds;
- $sameIds = [];
- if (!empty($sameTimeIds)) {
- $sameIds = explode(',', $sameTimeIds);
- }
- $sameNum = count($sameIds);
- if ($all == 1 && $sameNum > 1) {
- $orderList = OrderClass::getAllByCondition(['id' => ['in', $sameIds]], null, '*');
- if (empty($orderList)) {
- return ['imgFile' => ''];
- }
- $itemList = [];
- $remainDebtPrice = 0;
- $actPrice = 0;
- $tkPrice = 0;
- foreach ($orderList as $currentOrder) {
- $orderSn = $currentOrder['orderSn'] ?? '';
- $remainDebtPrice = bcadd($currentOrder['remainDebtPrice'], $remainDebtPrice, 2);
- $actPrice = bcadd($currentOrder['actPrice'], $actPrice, 2);
- $tkPrice = bcadd($tkPrice, $currentOrder['tkPrice'], 2);
- $itemData = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], 'id asc', '*', null);
- if (!empty($itemData)) {
- foreach ($itemData as $singleItem) {
- $productId = $singleItem['productId'] ?? 0;
- $unitPrice = $singleItem['xhUnitPrice'] ?? 0;
- $unitPrice = floatval($unitPrice);
- $xhNum = $singleItem['xhNum'] ?? 0;
- $refundNum = $singleItem['refundNum'] ?? 0;
- if (isset($itemList[$productId . '_' . $unitPrice])) {
- $currentInfo = $itemList[$productId . '_' . $unitPrice];
- $thisNum = bcadd($currentInfo['xhNum'], $xhNum);
- $thisRefundNum = bcadd($currentInfo['refundNum'], $refundNum);
- $itemList[$productId . '_' . $unitPrice]['xhNum'] = $thisNum;
- $itemList[$productId . '_' . $unitPrice]['refundNum'] = $thisRefundNum;
- } else {
- $itemList[$productId . '_' . $unitPrice] = $singleItem;
- }
- }
- }
- }
- $itemList = array_values($itemList);
- $beforeDebtPrice = bcsub($debtAmount, $remainDebtPrice, 2);
- $tkString = '';
- if ($tkPrice > 0) {
- $tkString = "<span style='margin-right:15px;'>已退款:{$tkPrice}</span>";
- }
- } else {
- $orderSn = $order->orderSn ?? '';
- $remainDebtPrice = $order->remainDebtPrice ?? 0;
- $beforeDebtPrice = bcsub($debtAmount, $remainDebtPrice, 2);
- $actPrice = $order->actPrice ?? 0;
- $tkPrice = $order->tkPrice ?? 0;
- $tkString = '';
- if ($tkPrice > 0) {
- $tkString = "<span style='margin-right:15px;'>已退款:{$tkPrice}</span>";
- }
- $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], 'id asc', '*', null);
- }
- if (empty($itemList)) {
- return ['imgFile' => ''];
- }
- $balance = $custom->balance ?? 0;
- $balanceContent = '';
- if ($balance > 0 && $balance > $debtAmount) {
- if ($debtAmount > 0 && $balance > $debtAmount) {
- $remainBalance = bcsub($balance, $debtAmount, 2);
- $balanceContent = '<span style="margin-right:15px;">余额:' . $balance . ',最终余额:' . $remainBalance . '</span>';
- } else {
- $balanceContent = '<span style="margin-right:15px;">余额:' . $balance . '</span>';
- }
- }
- if ($debtAmount >= $balance) {
- $debtAmount = bcsub($debtAmount, $balance, 2);
- }
- if ($beforeDebtPrice >= $balance) {
- $beforeDebtPrice = bcsub($beforeDebtPrice, $balance, 2);
- }
- $totalNum = 0;
- $totalAmount = 0;
- foreach ($itemList as $item) {
- $xhNum = $item['xhNum'] ?? 0;
- $refundNum = $item['refundNum'] ?? 0;
- $realNum = bcsub($xhNum, $refundNum);
- $unitPrice = $item['xhUnitPrice'] ?? 0;
- $amount = bcmul($realNum, $unitPrice, 2);
- $totalNum = bcadd($totalNum, $realNum);
- $totalAmount = bcadd($totalAmount, $amount, 2);
- }
- $totalAmount = floatval($totalAmount);
- $itemList[] = ['xhNum' => $totalNum, 'totalAmount' => $totalAmount,];
- $content = <<<XL
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- </head>
- <body>
- XL;
- $total = count($itemList);
- $pageSize = 14;
- $totalPage = ceil($total / $pageSize);
- for ($page = 1; $page <= $totalPage; $page++) {
- $start = ($page - 1) * $pageSize;
- $currentList = array_slice($itemList, $start, $pageSize);
- if (!empty($currentList)) {
- $tableList = '';
- foreach ($currentList as $key => $item) {
- $index = bcadd($key, $start);
- $index++;
- $name = $item['name'] ?? '';
- $num = $item['xhNum'];
- $refundNum = $item['refundNum'] ?? 0;
- $realNum = bcsub($num, $refundNum);
- $bigUnit = $item['xhUnitName'] ?? '';
- $unitPrice = $item['xhUnitPrice'] ?? 0;
- $unitPrice = floatval($unitPrice);
- $amount = bcmul($realNum, $unitPrice, 2);
- $amount = floatval($amount);
- if ($name == '') {
- $index = '合计';
- $amount = $item['totalAmount'] ?? 0;
- }
- $remark = $item['remark'] ?? '';
- $tableList .= "<tr>";
- $tableList .= "<td>{$index}</td>";
- $tableList .= "<td>{$name}</td>";
- $tableList .= "<td>{$realNum}</td>";
- $tableList .= "<td>{$bigUnit}</td>";
- $tableList .= "<td>{$unitPrice}</td>";
- $tableList .= "<td>{$amount}</td>";
- $tableList .= "<td>{$remark}</td>";
- $tableList .= "</tr>";
- }
- $content .= <<<XL
- <div style="width:760px;height:4px;background-color:black;margin-bottom:10px;"></div>
- <div style="width:750px;text-align:center;font-weight:bold;margin-bottom:20px;font-size:18px;">
- <div>{$fullSjName}</div>
- <div style="margin-top:5px;">销售单</div>
- </div>
- <div style="width:750px;">
- <span>单据日期:{$currentDate}</span>
- <span style="margin-left:80px;">开单:{$staffName}</span>
- <span style="margin-left:80px;">客户:{$customName}</span>
- <span style="float:right;">编号:{$orderSn}</span>
- <div>
- <table border="1" style="border: 1px solid black;border-collapse:collapse;text-align:center;font-size:14px;width:750px;margin-top:5px;">
- <tr style="font-weight:bold;">
- <td style="width:70px;">编号</td>
- <td style="width:200px;">名称</td>
- <td style="width:70px;">数量</td>
- <td style="width:70px;">单位</td>
- <td style="width:70px;">单价</td>
- <td style="width:90px;">金额</td>
- <td style="width:160px;">备注</td>
- </tr>
- {$tableList}
- </table>
- <div style="margin-top:5px;margin-bottom:20px;">
- {$tkString}
- <span style="margin-right:15px;">本单:{$actPrice}</span>
- <span style="margin-right:15px;">上次欠款:{$beforeDebtPrice}</span>
- <span style="margin-right:15px;">待付欠款:{$debtAmount}</span>
- {$balanceContent}
- </div>
- XL;
- }
- }
- $content .= <<<XL
- </body>
- <style>
- body{
- font-size:14px;
- }
- td{
- padding:4px;
- }
- </style>
- </html>
- XL;
- $file = $dir . $orderSn . '.html';
- $imgFile = $dir . $orderSn . '.png';
- if (file_exists($file)) {
- unlink($file);
- }
- if (file_exists($imgFile)) {
- unlink($imgFile);
- }
- file_put_contents($file, $content);
- $con = new Converter(null, [
- "fmt" => "png",
- "in" => $file,
- "out" => $imgFile,
- ]);
- $con->convert();
- return ['imgFile' => $imgFile];
- }
- //应收统计下载 ssh 20240530
- public static function exportAccountList($list, $mainId)
- {
- $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
- require_once($phpExcelFile . 'Classes/PHPExcel.php');
- $objPHPExcel = new \PHPExcel();
- $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
- ->setLastModifiedBy("Maarten Balliauw")
- ->setTitle("Office 2007 XLSX Document")
- ->setSubject("Office 2007 XLSX Document")
- ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
- ->setKeywords("office 2007 openxml php")
- ->setCategory("file");
- $ghsTitle = '供货商';
- $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
- $objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
- $objPHPExcel->getActiveSheet()->setCellValue('B1', '名称');
- $objPHPExcel->getActiveSheet()->setCellValue('C1', '金额');
- $objPHPExcel->getActiveSheet()->setCellValue('D1', '订单数');
- //设置宽度
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
- //加粗
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $baseRow = 2;
- foreach ($list as $key => $custom) {
- $i = $baseRow + $key;
- $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['id']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['name']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['amount']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['num']);
- //居左
- $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- }
- $fileName = '应收统计-' . date("m-d");
- $objPHPExcel->getActiveSheet()->setTitle($fileName);
- $objPHPExcel->setActiveSheetIndex(0);
- $dir = './priceTable/' . $mainId;
- if (file_exists($dir) == false) {
- mkdir($dir, 0777, true);
- }
- $date = $fileName;
- $file = $date . '.xls';
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- if (file_exists($dir . '/' . $file)) {
- unlink($dir . '/' . $file);
- }
- $objWriter->save($dir . '/' . $file);
- $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
- util::success(['file' => $fileUrl, 'shortFile' => $file]);
- }
- //应收统计下载 ssh 20240530
- public static function exportPastList($list, $mainId)
- {
- $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
- require_once($phpExcelFile . 'Classes/PHPExcel.php');
- $objPHPExcel = new \PHPExcel();
- $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
- ->setLastModifiedBy("Maarten Balliauw")
- ->setTitle("Office 2007 XLSX Document")
- ->setSubject("Office 2007 XLSX Document")
- ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
- ->setKeywords("office 2007 openxml php")
- ->setCategory("file");
- $ghsTitle = '供货商';
- $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
- $objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
- $objPHPExcel->getActiveSheet()->setCellValue('B1', '客户');
- $objPHPExcel->getActiveSheet()->setCellValue('C1', '手机号');
- $objPHPExcel->getActiveSheet()->setCellValue('D1', '欠款金额');
- //设置宽度
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
- //加粗
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $baseRow = 2;
- foreach ($list as $key => $custom) {
- $i = $baseRow + $key;
- $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['id']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['name']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['mobile']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['currentDebAmount']);
- //居左
- $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- }
- $fileName = '历史应收-' . date("m-d");
- $objPHPExcel->getActiveSheet()->setTitle($fileName);
- $objPHPExcel->setActiveSheetIndex(0);
- $dir = './priceTable/' . $mainId;
- if (file_exists($dir) == false) {
- mkdir($dir, 0777, true);
- }
- $date = $fileName;
- $file = $date . '.xls';
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- if (file_exists($dir . '/' . $file)) {
- unlink($dir . '/' . $file);
- }
- $objWriter->save($dir . '/' . $file);
- $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
- util::success(['file' => $fileUrl, 'shortFile' => $file]);
- }
- public static function exportYj($list, $mainId)
- {
- $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
- require_once($phpExcelFile . 'Classes/PHPExcel.php');
- $objPHPExcel = new \PHPExcel();
- $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
- ->setLastModifiedBy("Maarten Balliauw")
- ->setTitle("Office 2007 XLSX Document")
- ->setSubject("Office 2007 XLSX Document")
- ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
- ->setKeywords("office 2007 openxml php")
- ->setCategory("file");
- $ghsTitle = '供货商';
- $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
- $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
- $objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
- $objPHPExcel->getActiveSheet()->setCellValue('B1', '客户');
- $objPHPExcel->getActiveSheet()->setCellValue('C1', '手机号');
- $objPHPExcel->getActiveSheet()->setCellValue('D1', '订单数');
- $objPHPExcel->getActiveSheet()->setCellValue('E1', '订单金额');
- $objPHPExcel->getActiveSheet()->setCellValue('F1', '退款金额');
- $objPHPExcel->getActiveSheet()->setCellValue('G1', '实际金额');
- $objPHPExcel->getActiveSheet()->setCellValue('H1', '纸箱费');
- $objPHPExcel->getActiveSheet()->setCellValue('I1', '打包费');
- $objPHPExcel->getActiveSheet()->setCellValue('J1', '运费');
- //设置宽度
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
- //加粗
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('F1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('G1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('H1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('I1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('J1')->getFont()->setSize(9)->setBold(true);
- $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('J1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $baseRow = 2;
- foreach ($list as $key => $custom) {
- $i = $baseRow + $key;
- $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['id']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['name']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['mobile']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['num']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $custom['orderPrice']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $custom['tkPrice']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, $custom['actPrice']);
- $objPHPExcel->getActiveSheet()->setCellValue('H' . $i, $custom['carton']);
- $objPHPExcel->getActiveSheet()->setCellValue('I' . $i, $custom['pack']);
- $objPHPExcel->getActiveSheet()->setCellValue('J' . $i, $custom['freight']);
- //居左
- $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('G' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('H' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('I' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getActiveSheet()->getStyle('J' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- }
- $fileName = '客户业绩-' . date("m-d");
- $objPHPExcel->getActiveSheet()->setTitle($fileName);
- $objPHPExcel->setActiveSheetIndex(0);
- $dir = './priceTable/' . $mainId;
- if (file_exists($dir) == false) {
- mkdir($dir, 0777, true);
- }
- $date = $fileName;
- $file = $date . '.xls';
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- if (file_exists($dir . '/' . $file)) {
- unlink($dir . '/' . $file);
- }
- $objWriter->save($dir . '/' . $file);
- $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
- util::success(['file' => $fileUrl, 'shortFile' => $file]);
- }
- }
|