OrderClass.php 146 KB

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