| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928 |
- <?php
- namespace bizGhs\order\classes;
- use bizGhs\item\classes\ItemClassClass;
- use bizHd\purchase\classes\PurchaseItemClass;
- use common\components\arrayUtil;
- use wkhtmltox\Image\Converter;
- 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 bizGhs\express\services\DadaExpressServices;
- 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\stock\classes\StockRecordClass;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\stat\classes\StatIncomeClass;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\orderSn;
- use common\components\printUtil;
- use common\components\stringUtil;
- use common\components\util;
- use bizGhs\base\classes\BaseClass;
- use Yii;
- use yii\helpers\ArrayHelper;
- 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;
- //未确认,这里的数值是错的,请参考dict.php的数值
- const SEND_TYPE_UNKNOWN = 1;
- //自取,这里的数值是错的,请参考dict.php的数值
- const SEND_TYPE_NO = 2;
- //自己送,这里的数值是错的,请参考dict.php的数值
- const SEND_TYPE_MYSELF = 3;
- //快递送,这里的数值是错的,请参考dict.php的数值
- 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_UNSEND = 0; //未发货
- const SEND_STATUS_SENDING = 1; //已发货(配送中)
- const SEND_STATUS_COMPLETED = 2; //已送达
- const SEND_STATUS_CANCEL = 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 printMyWlList($shop, $beginTime, $endTime)
- {
- $end = strtotime($endTime);
- $begin = strtotime($beginTime);
- $different = $end - $begin;
- if ($different > 172800) {
- util::fail('最多可打印2天订单');
- }
- $mainId = $shop->mainId;
- $orderList = OrderClass::getAllByCondition(['mainId' => $mainId, 'payTime' => ['between', [$beginTime, $endTime]], 'payStatus' => 1], 'id asc', '*', null, true);
- if (empty($orderList)) {
- util::fail('没有订单需要打印');
- }
- $ids = [];
- foreach ($orderList as $order) {
- $customId = $order->customId;
- $ids[] = $customId;
- }
- $ids = array_unique(array_filter($ids));
- $customList = CustomClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,mainId,shortName,mobile,wlName', 'id');
- $myList = [];
- foreach ($orderList as $order) {
- $customId = $order->customId;
- $custom = $customList[$customId] ?? [];
- $sendNum = $order->sendNum;
- $customMobile = $order->customMobile;
- $shortName = $custom['shortName'] ?? '';
- $wlName = $custom['wlName'] ?? '';
- $myList[] = ['sendNum' => $sendNum, 'customMobile' => $customMobile, 'shortName' => $shortName, 'wlName' => $wlName];
- }
- $myList = arrayUtil::arraySort($myList, 'customMobile');
- $size = 50;
- $arr = array_chunk($myList, $size);
- $totalPage = count($arr);
- foreach ($arr as $key => $sonList) {
- $content = '';
- if ($totalPage > 1) {
- $currentPage = bcadd($key, 1);
- $content .= "<CB>第{$currentPage}页,共{$totalPage}页</CB><BR>";
- }
- $content .= '<BR>';
- $content .= '--------------------------------<BR>';
- if (!empty($sonList)) {
- foreach ($sonList as $info) {
- $sendNum = $info['sendNum'];
- $customMobile = $info['customMobile'];
- $shortName = $info['shortName'];
- $wlName = $info['wlName'];
- $content .= '<B>' . $sendNum . ' ' . $shortName . '</B><BR>';
- $content .= '<BR>';
- $content .= '<B>' . $customMobile . ' ' . $wlName . '</B><BR>';
- $content .= '--------------------------------<BR>';
- }
- }
- $content .= '<BR>';
- $shopId = $shop->id;
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
- $printSn = $ext['printSn'] ?? '';
- if (empty($printSn)) {
- util::fail('没有设置打印机');
- }
- $p = new printUtil($printSn);
- $p->printMsg($content, $shop);
- }
- }
- 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 ($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);
- }
- // 构建“冲销”函数的参数 -- 变动前的花材存库数据
- $purchaseItems = PurchaseItemClass::getAllByCondition(['orderSn' => $cg->orderSn], null, "productId");
- $productIds = ArrayHelper::getColumn($purchaseItems, 'productId'); //$productIds 是本次入库涉及的花材ID数组
- $oldStocks = [];
- foreach ($productIds as $productId) {
- $product = ProductClass::getById($productId, true);
- $oldStocks[$productId] = $product;
- }
- PurchaseClass::takeToPutIn($cg);
- $shop = ShopClass::getLockById($shopId);
- if (empty($shop)) {
- util::fail('没有找到门店14');
- }
- $adminId = $shop->adminId;
- $mainId = $shop->mainId;
- PurchaseClass::rollbackProductStock($oldStocks, $shop, $adminId, $mainId, '系统');
- }
- //订单发货主方法 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)
- {
- $shopId = $data['shopId'] ?? 0;
- $mainId = $data['mainId'] ?? 0;
- $ghsId = $data['ghsId'] ?? 0;
- $customId = $data['customId'] ?? 0;
- $snData = ['shopId' => $shopId, 'mainId' => $mainId, 'ghsId' => $ghsId, 'customId' => $customId];
- $orderSn = orderSn::getGhsOrderSn($snData);
- $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 ($orderInfo->shopId == 1527 || $orderInfo->mainId == 52291) {
- if (!empty($orderInfo->customShopAdminId)) {
- $showPrice = 0;
- }
- }
- //源花汇小票不带价格
- if (isset($orderInfo->mainId) && $orderInfo->mainId == 10536) {
- $showPrice = 0;
- }
- //北京花篮子,线上下单,不显示价格
- if (isset($orderInfo->mainId) && $orderInfo->mainId == 10735) {
- if (!empty($orderInfo->customShopAdminId)) {
- $showPrice = 0;
- }
- }
- //淄博花超鲜花小票不带价格
- if (isset($orderInfo->mainId) && $orderInfo->mainId == 16293) {
- $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;
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- $printSn = $ext->printSn ?? '';
- /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/
- $orderMainId = $orderInfo['mainId'] ?? 0;
- if (getenv('YII_ENV') == 'production') {
- $map = [65726, 58];
- } else {
- $map = [828, 0];
- }
- if (in_array($orderMainId, $map)) {
- self::printLogisticsLabel($orderInfo, $shop, $ext);
- }
- /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/
- $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><BR>';
- $content .= '********************************<BR>';
- $content .= '<CB>送货时间</CB><BR>';
- $content .= '<CB><BOLD>【' . $orderInfo['sendTimeWant'] . '】</BOLD></CB>';
- $content .= '********************************<BR><BR><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, 65591])) {
- //勇记、国恋、花悠星零售开单不需要打印扫码买花
- 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>";
- 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);
- //如果有限购数量占用,也需要清除
- $customId = $order->customId ?? 0;
- $num = floor($v['num']);
- ProductClass::baseClearLimitBuy($v['productId'], $customId, $num);
- }
- }
- 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]);
- }
- public static function printLogisticsLabel($order, $shop, $ext)
- {
- /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/
- $orderMainId = $order->mainId;
- if (getenv('YII_ENV') == 'production') {
- $map = [65726, 58];
- } else {
- $map = [828, 0];
- }
- /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/
- $customId = $order->customId ?? 0;
- $custom = CustomClass::getById($customId, true);
- if (empty($custom)) {
- if (!in_array($orderMainId, $map)) {
- util::fail('没有找到客户');
- } else {
- return false;
- }
- }
- $shortName = $custom->shortName ?? '';
- $shortName = stringUtil::subStringUtf8($shortName, 5);
- $customMobile = $order->customMobile ?? '';
- if (empty($customMobile)) {
- if (!in_array($orderMainId, $map)) {
- util::fail('客户手机号无效');
- } else {
- return false;
- }
- }
- $customName = $order->customName ?? '';
- $shortMobile = substr($customMobile, -4);
- $remark = $order->remark ?? '';
- $shortRemark = stringUtil::subStringUtf8($remark, 8);
- $address = $order->address ?? '';
- $floor = $order->floor ?? '';
- $fullAddress = $address . $floor;
- $shopName = $shop->shopName ?? '';
- $sjName = $shop->merchantName;
- $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
- $telephone = $shop->telephone ?? '';
- $wlLabelSn = $ext->wlLabelSn ?? '';
- if (empty($wlLabelSn)) {
- if (!in_array($orderMainId, $map)) {
- util::fail('请绑定物流标签机');
- } else {
- return false;
- }
- }
- $p = new printUtil($wlLabelSn);
- if (!in_array($orderMainId, $map)) {
- if (empty($shortName)) {
- util::fail('客户短名没有设置');
- }
- $p->times = 2;
- $content = '<TEXT x="420" y="130" font="12" w="4" h="4" r="90">' . $shortName . '</TEXT>';
- $content .= '<TEXT x="395" y="10" font="12" w="2" h="2" r="90">地址</TEXT>';
- $content .= '<TEXT x="290" y="130" font="12" w="4" h="4" r="90">' . $shortMobile . '</TEXT>';
- $content .= '<TEXT x="265" y="10" font="12" w="2" h="2" r="90">代码</TEXT>';
- $content .= '<TEXT x="170" y="130" font="12" w="4" h="4" r="90">' . $shortRemark . '</TEXT>';
- $content .= '<TEXT x="150" y="10" font="12" w="2" h="2" r="90">物流</TEXT>';
- $content .= '<TEXT x="45" y="70" font="12" w="2" h="2" r="90">' . $currentName . ' ' . $telephone . '</TEXT>';
- } else {
- /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/
- $sameTimeIds = $order->sameTimeIds;
- $num = 1;
- if (!empty($sameTimeIds)) {
- $ids = explode(',', $sameTimeIds);
- if (!empty($ids)) {
- $num = count($ids);
- }
- }
- if ($num > 1) {
- $customName = $customName . ' ' . $num . '单';
- }
- $content = '<TEXT x="405" y="30" font="12" w="4" h="4" r="90">' . $shortName . '</TEXT>';
- $content .= '<TEXT x="285" y="30" font="12" w="2" h="3" r="90">' . $customName . '</TEXT>';
- $content .= '<TEXT x="190" y="30" font="12" w="1" h="2" r="90">' . $fullAddress . '</TEXT>';
- $content .= '<TEXT x="120" y="30" font="12" w="2" h="2" r="90">' . $customMobile . '</TEXT>';
- /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/
- }
- $p->printLabelMsg($content);
- return true;
- }
- }
|