OrderClass.php 143 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162
  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. $currentShopId = $data['shopId'] ?? 0;
  766. $shop = ShopClass::getLockById($currentShopId);
  767. if (empty($shop)) {
  768. util::fail('没有找到门店7');
  769. }
  770. $mainId = $shop->mainId ?? 0;
  771. $main = MainClass::getLockById($mainId);
  772. if (empty($main)) {
  773. util::fail('没有main信息5');
  774. }
  775. //花材
  776. $product = $data['product'];
  777. $book = $data['book'] ?? 0;
  778. $stockMayChange = true;
  779. $data['stockChange'] = 1;
  780. if ($book == 1) {
  781. $stockMayChange = false;
  782. $data['stockChange'] = 0;
  783. }
  784. //花店向虚拟批发店采购的,批发店没有的花材需要补充
  785. if ($live == 0) {
  786. $product = \bizHd\product\classes\ProductClass::hdToggleGhs($product, $shop);
  787. }
  788. $customShopAdminId = $data['customShopAdminId'] ?? 0;
  789. $moreParams = ['book' => $book, 'customShopAdminId' => $customShopAdminId, 'custom' => $custom];
  790. $respond = OrderItemClass::replaceItem($orderSn, $product, $data, $stockMayChange, $moreParams);
  791. $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
  792. $data['sendCost'] = $sendCost;
  793. $data['bigNum'] = $respond['bigNum'] ?? 0;
  794. $data['smallNum'] = $respond['smallNum'] ?? 0;
  795. $data['itemNum'] = $respond['totalItemNum'] ?? 0;
  796. //这个字段记录每个花材满多少扎减掉的金额,并汇总金额,区别于整单满减的 $cutAmount。保存起来应该是在哪里有用,$totalReachDiscount在这边不影响actPrice,估计因为取花材的价格里::getFinalPrice()已经使用了优惠后的价格,有多处,关键词 reachDiscountPrice_explain ssh 20260116
  797. $data['reachDiscountPrice'] = $respond['totalReachDiscount'] ?? 0;
  798. //记录订单的总成本
  799. $totalCost = $respond['totalCost'] ?? 0;
  800. $packCost = $data['packCost'] ?? 0;
  801. $totalCost = bcadd($totalCost, $packCost, 2);
  802. $totalCost = bcadd($totalCost, $sendCost, 2);
  803. $data['totalCost'] = $totalCost;
  804. $data['remainCost'] = $totalCost;
  805. //默认订单要打单
  806. $data['needPrint'] = $data['needPrint'] ?? dict::getDict('needPrint', 'need');
  807. $weight = $respond['weight'] ?? 0;
  808. $data['weight'] = $weight;
  809. $itemPrice = $respond['price'] ?? 0;
  810. $data['itemPrice'] = $itemPrice;
  811. $currentPrice = bcadd($itemPrice, $sendCost, 2);
  812. $packCost = isset($data['packCost']) && $data['packCost'] > 0 ? $data['packCost'] : 0;
  813. $currentPrice = bcadd($currentPrice, $packCost, 2);
  814. //预订单需要增加服务费
  815. if ($book == 1) {
  816. $kiloFee = $shop->kiloFee ?? 0;
  817. $miniKilo = $shop->miniKilo ?? 0;
  818. $calcWeight = max($weight, $miniKilo);
  819. $allKiloFee = bcmul($calcWeight, $kiloFee, 2);
  820. $currentPrice = bcadd($currentPrice, $allKiloFee, 2);
  821. $data['allKiloFee'] = $allKiloFee;
  822. $data['kiloFee'] = $kiloFee;
  823. $data['miniKilo'] = $miniKilo;
  824. }
  825. $data['prePrice'] = $currentPrice;
  826. $actPrice = $currentPrice;
  827. //商家自己开单时
  828. if (isset($data['modifyPrice'])) {
  829. $modifyPrice = $data['modifyPrice'] ?? 0;
  830. if ($modifyPrice <= 0) {
  831. util::fail('收款金额必须大于0');
  832. }
  833. if ($modifyPrice > $currentPrice) {
  834. //人工和资材费用
  835. $data['labourCost'] = bcsub($modifyPrice, $currentPrice, 2);
  836. }
  837. if ($modifyPrice < $currentPrice) {
  838. //优惠金额
  839. $data['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2);
  840. $data['discountType'] = dict::getDict('discountType', 'discount');
  841. }
  842. $actPrice = $modifyPrice;
  843. if ($book == 1) {
  844. $actPrice = 0;
  845. }
  846. } else {
  847. //客户自己下单才有整单满减,门店帮忙开单没有,,多个地方要同步修改,关键词 meet_amount_num_reduce
  848. if ($book == 0) {
  849. $meetNum = $shop->meetNum ?? 0;
  850. $meetAmount = $shop->meetAmount ?? 0;
  851. $cutOption = $shop->cutAmount ?? 0;
  852. $cutStyle = $shop->cutStyle ?? 0;
  853. if ($cutStyle == 0) {
  854. $cutAmount = $cutOption;
  855. } else {
  856. $miniOption = bcsub(1, $cutOption, 2);
  857. $cutAmount = bcmul($actPrice, $miniOption, 2);
  858. }
  859. if ($cutAmount > 0 && $meetNum > 0 && $meetAmount > 0) {
  860. if (isset($data['bigNum']) && $data['bigNum'] >= $meetNum && isset($data['itemPrice']) && $data['itemPrice'] >= $meetAmount) {
  861. if ($cutAmount < $actPrice) {
  862. $actPrice = bcsub($actPrice, $cutAmount, 2);
  863. $data['orderReachDiscountPrice'] = $cutAmount;
  864. } else {
  865. noticeUtil::push('订单金额不足满减金额,customId:' . $customId, '15280215347');
  866. }
  867. }
  868. }
  869. }
  870. }
  871. //如果有设置指定客户涨价百分之几,然后又设置了涨价的幅度。【这个功能主要用于客户不收他运费,门店不赚钱,收他运费客户不乐意,所以把运费加到花材里】,多处同步修改,关键词 rise_percent_rang
  872. if (isset($data['itemPrice'])) {
  873. if (isset($data['orderReachDiscountPrice'])) {
  874. $originActPrice = bcadd($actPrice, $data['orderReachDiscountPrice'], 2);
  875. } else {
  876. $originActPrice = $actPrice;
  877. }
  878. if ($originActPrice >= $data['itemPrice']) {
  879. if (isset($custom['risePercent']) && $custom['risePercent'] > 0) {
  880. if (isset($custom['riseRange']) && $custom['riseRange'] > 0) {
  881. $risePercent = $custom['risePercent'];
  882. $riseRange = $custom['riseRange'];
  883. // 计算涨价金额:涨价后金额 * (涨价百分比 / (100 + 涨价百分比))
  884. $riseAmount = bcmul($data['itemPrice'], bcdiv($risePercent, bcadd(100, $risePercent, 0), 4), 2);
  885. if ($riseAmount > $riseRange) {
  886. //应该退回的金额
  887. $backAmount = bcsub($riseAmount, $riseRange, 2);
  888. $actPrice = bcsub($actPrice, $backAmount, 2);
  889. if (isset($data['orderReachDiscountPrice'])) {
  890. if ($data['orderReachDiscountPrice'] < $backAmount) {
  891. //前面整单满减的,就不减了,所以这里面加回来
  892. $actPrice = bcadd($actPrice, $data['orderReachDiscountPrice'], 2);
  893. //改成减多加钱里面的
  894. $data['orderReachDiscountPrice'] = $backAmount;
  895. }
  896. } else {
  897. $data['orderReachDiscountPrice'] = $backAmount;
  898. }
  899. }
  900. }
  901. }
  902. }
  903. }
  904. //客户采购时使用红包时
  905. if (isset($data['discountType']) && $data['discountType'] == dict::getDict('discountType', 'hb')) {
  906. $discountAmount = $data['discountAmount'] ?? 0;
  907. $currentDiscountPrice = bcsub($currentPrice, $discountAmount, 2);
  908. $actPrice = $currentDiscountPrice;
  909. }
  910. $data['actPrice'] = $actPrice;
  911. $data['bookPrice'] = $actPrice;
  912. $data['orderPrice'] = $actPrice;
  913. $data['realPrice'] = $actPrice;
  914. $data['sendTimeWant'] = isset($data['sendTimeWant']) && !empty($data['sendTimeWant']) ? $data['sendTimeWant'] : date("Y-m-d");
  915. //订单有效期
  916. $validTime = dict::getDict('order_pay_has_time');
  917. $current = time() + $validTime;
  918. $data['deadline'] = $data['deadline'] ?? date("Y-m-d H:i:s", $current);
  919. $data['status'] = self::ORDER_STATUS_UN_PAY;
  920. $main->totalOrder += 1;
  921. $main->unPayOrder += 1;
  922. $main->save();
  923. //将当天日期+花店每天的总订单数作为编号,批发的加个0作为前缀,跟零售的编号这样来区分
  924. $data['sendNum'] = '0' . date("j") . StatOrderCountClass::addOrder($shop, $main);
  925. //订单有效期
  926. $currentTime = time();
  927. $validTime = dict::getDict('order_pay_has_time');
  928. $current = $currentTime + $validTime;
  929. $data['deadline'] = $data['deadline'] ?? date("Y-m-d H:i:s", $current);
  930. if ($book == 1) {
  931. $fiveTime = bcmul(86400, 5);
  932. $bookDeadline = bcadd($currentTime, $fiveTime);
  933. $data['deadline'] = date("Y-m-d H:i:s", $bookDeadline);
  934. }
  935. //订单自动记为欠款单时间
  936. $localConfirmTime = dict::getDict('local_gys_kd_auto_set_debt_time');
  937. $currentSet = $currentTime + $localConfirmTime;
  938. $data['autoSetTime'] = $data['autoSetTime'] ?? date("Y-m-d H:i:s", $currentSet);
  939. $return = self::add($data, true);
  940. return $return;
  941. }
  942. //修改订单 ssh 2019.12.5
  943. public static function updateOrder($order, $data)
  944. {
  945. $sjId = $order->sjId ?? 0;
  946. $orderSn = $order->orderSn ?? 0;
  947. $currentShopId = $order->shopId ?? 0;
  948. $data['payStatus'] = self::PAY_STATUS_UN_PAY;
  949. //花材列表
  950. $product = $data['product'];
  951. //删除花材再添加
  952. OrderItemClass::deleteByCondition(['orderSn' => $orderSn]);
  953. $respond = OrderItemClass::replaceItem($orderSn, $product, $data);
  954. $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0;
  955. $data['sendCost'] = $sendCost;
  956. $data['bigNum'] = $respond['bigNum'] ?? 0;
  957. $data['smallNum'] = $respond['smallNum'] ?? 0;
  958. $price = $respond['price'] ?? 0;
  959. $currentPrice = bcadd($price, $sendCost, 2);
  960. $data['prePrice'] = $currentPrice;
  961. if (isset($data['modifyPrice'])) {
  962. //商家打折,修改金额
  963. $modifyPrice = $data['modifyPrice'] ?? 0;
  964. if ($modifyPrice > $currentPrice) {
  965. util::fail('实收金额大于订单总金额');
  966. }
  967. if ($modifyPrice < $currentPrice) {
  968. $data['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2);
  969. $data['discountType'] = dict::getDict('discountType', 'discount');
  970. $currentPrice = $modifyPrice;
  971. }
  972. }
  973. $data['actPrice'] = $currentPrice;
  974. $data['realPrice'] = $currentPrice;
  975. //如果有平台补贴
  976. if (isset($data['discountType']) && $data['discountType'] == dict::getDict('discountType', 'usePtCoupon')) {
  977. $discountAmount = $data['discountAmount'] ?? 0;
  978. $data['realPrice'] = bcsub($currentPrice, $discountAmount, 2);
  979. }
  980. $data['sendTime'] = isset($data['sendTime']) && !empty($data['sendTime']) ? $data['sendTime'] : '0000-00-00 00:00:00';
  981. //订单有效期
  982. $validTime = dict::getDict('order_pay_has_time');
  983. $current = time() + $validTime;
  984. $data['deadline'] = $data['deadline'] ?? date("Y-m-d H:i:s", $current);
  985. $data['status'] = self::ORDER_STATUS_UN_PAY;
  986. //计算总重量(kg)
  987. $weight = 0;
  988. $productMapData = ProductClass::getProductMapData($product);
  989. foreach ($product as $key => $val) {
  990. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  991. $productId = $val['productId'];
  992. $weight = bcadd($w, $weight, 2);
  993. $checkStock = true;
  994. $stockInfo = ProductClass::decreaseStock($val['productId'], $val['bigNum'], $val['smallNum'], $checkStock);
  995. //记录库存流水
  996. $recordData = [];
  997. $recordData['sjId'] = $sjId;
  998. $recordData['shopId'] = $currentShopId;
  999. $recordData['itemId'] = $productMapData[$productId]['itemId'] ?? 0;
  1000. $ratio = $productMapData[$productId]['ratio'] ?? 0;
  1001. $recordData['itemNum'] = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  1002. $recordData['oldStock'] = $stockInfo['oldStock'];
  1003. $recordData['newStock'] = $stockInfo['newStock'];
  1004. $recordData['productId'] = $productId;
  1005. $recordData['orderSn'] = $orderSn;
  1006. StockRecordClass::addSellStockOrderRecord($recordData);
  1007. }
  1008. $data['weight'] = $weight;
  1009. $current = time() + 300;
  1010. $data['deadline'] = isset($data['deadline']) ? $data['deadline'] : date("Y-m-d H:i:s", $current);
  1011. //修改订单暂时不打印
  1012. $data['needPrint'] = $data['needPrint'] ?? dict::getDict('needPrint', 'need');
  1013. $orderId = $order->id ?? 0;
  1014. self::updateById($orderId, $data);
  1015. $return = self::getLockById($orderId);
  1016. //门店总订单数+1
  1017. $shop = ShopClass::getLockById($currentShopId);
  1018. if (empty($shop)) {
  1019. util::fail('没有找到门店8');
  1020. }
  1021. $shop->unPayOrder += 1;
  1022. $shop->cancelOrder -= 1;
  1023. $shop->save();
  1024. return $return;
  1025. }
  1026. //根据订单编号查询 ssh 2021.19
  1027. public static function getByOrderSn($orderSn, $returnObj = false)
  1028. {
  1029. return self::getByCondition(['orderSn' => $orderSn], $returnObj);
  1030. }
  1031. //根据编号列表查订单
  1032. public static function getOrderInfoBySnList($snList)
  1033. {
  1034. $list = self::getAllByCondition(['orderSn' => ['in', $snList]], null, '*', 'orderSn');
  1035. $list = self::groupOrder($list, true, false, false, true);
  1036. return $list;
  1037. }
  1038. //显示操作按钮
  1039. public static function getShowButton($showButton, $isList, $order)
  1040. {
  1041. if ($showButton == false) {
  1042. return [];
  1043. }
  1044. $print = ['type' => 'print', 'show' => 1, 'disable' => 0, 'name' => '打印'];
  1045. $modifyProduct = ['type' => 'modifyProduct', 'show' => 0, 'disable' => 0, 'name' => '修改花材'];
  1046. $confirm = ['type' => 'confirm', 'show' => 0, 'disable' => 1, 'name' => '确认'];
  1047. $cancel = ['type' => 'cancel', 'show' => 0, 'disable' => 0, 'name' => '取消'];
  1048. $arrival = ['type' => 'arrival', 'show' => 0, 'disable' => 0, 'name' => '确认发货'];
  1049. if ($isList) {
  1050. //订单列表页显示的按钮
  1051. $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货'];
  1052. $selfGet = ['type' => 'selfGet', 'show' => 0, 'disable' => 1, 'name' => '自取'];
  1053. if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
  1054. //待确认订单,打印和修改花材按钮可以使用
  1055. $send['disable'] = 1;
  1056. $selfGet['disable'] = 1;
  1057. $print['disable'] = 0;
  1058. $confirm['disable'] = 0;
  1059. }
  1060. if ($order['status'] == self::ORDER_STATUS_UN_SEND) {
  1061. //待配送订单,改花材按钮不可点,自取可点
  1062. $selfGet['disable'] = 0;
  1063. }
  1064. //自取订单发货按钮置灰
  1065. if ($order['sendType'] == self::SEND_TYPE_NO) {
  1066. $send['disable'] = 1;
  1067. }
  1068. //取消订单置灰
  1069. if ($order['status'] == self::ORDER_STATUS_CANCEL) {
  1070. $send['disable'] = 1;
  1071. $selfGet['disable'] = 1;
  1072. $print['disable'] = 1;
  1073. }
  1074. if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
  1075. $send['name'] = '发货记录';
  1076. }
  1077. return [$send, $selfGet, $print, $confirm];
  1078. } else {
  1079. //订单详情页显示的按钮
  1080. if (isset($order['book']) && $order['book'] == 1 && isset($order['stockChange']) && $order['stockChange'] == 0) {
  1081. if ($order['status'] == self::ORDER_STATUS_UN_SEND) {
  1082. $arrival['show'] = 1;
  1083. }
  1084. }
  1085. //待确认订单显示延期付和已付款
  1086. if ($order['status'] == self::ORDER_STATUS_UN_PAY) {
  1087. $debtPay = ['type' => 'debtPay', 'show' => 0, 'disable' => 0, 'name' => '延期收款'];
  1088. $hasPay = ['type' => 'hasPay', 'show' => 0, 'disable' => 0, 'name' => '欠款'];
  1089. $confirm['disable'] = 0;
  1090. return [$print, $debtPay, $hasPay, $confirm, $cancel, $arrival];
  1091. }
  1092. //待配送订单显示打印、发货和自取
  1093. if ($order['status'] == self::ORDER_STATUS_UN_SEND) {
  1094. $selfGet = ['type' => 'selfGet', 'show' => 0, 'disable' => 1, 'name' => '自取'];
  1095. $send = ['type' => 'send', 'show' => 0, 'disable' => 1, 'name' => '发货'];
  1096. if ($order['hasItem'] == 2) {
  1097. return [$print, $selfGet, $send, $arrival];
  1098. }
  1099. $selfGet['disable'] = 0;
  1100. $send['disable'] = 0;
  1101. return [$print, $selfGet, $send, $arrival];
  1102. }
  1103. //配送中显示按钮
  1104. if ($order['status'] == self::ORDER_STATUS_SENDING) {
  1105. $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货'];
  1106. return [$print, $send, $arrival];
  1107. }
  1108. //完成
  1109. if ($order['status'] == self::ORDER_STATUS_COMPLETE) {
  1110. $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货记录'];
  1111. //自取订单不显示发货按钮
  1112. if ($order['sendType'] == self::SEND_TYPE_NO) {
  1113. $send['show'] = 0;
  1114. }
  1115. return [$print, $send, $arrival];
  1116. }
  1117. //取消订单置灰
  1118. if ($order['status'] == self::ORDER_STATUS_CANCEL) {
  1119. $selfGet['disable'] = 1;
  1120. $send['disable'] = 1;
  1121. $print['disable'] = 1;
  1122. return [$modifyProduct, $arrival];
  1123. }
  1124. return [];
  1125. }
  1126. }
  1127. //显示进度 ssh 2021.3.1
  1128. public static function getShowProgress($showProgress, $order)
  1129. {
  1130. if ($showProgress == false) {
  1131. return [];
  1132. }
  1133. $create = ['name' => '创建', 'complete' => 1];
  1134. $unConfirm = ['name' => '待确认', 'complete' => 0];
  1135. if ($order['status'] > 0) {
  1136. $unConfirm['complete'] = 1;
  1137. }
  1138. $out = ['name' => '出库', 'complete' => 0];
  1139. if ($order['status'] > 1) {
  1140. $out['complete'] = 1;
  1141. }
  1142. return [$create, $unConfirm, $out];
  1143. }
  1144. //退款等需要使用原来的订单花材结构
  1145. public static function getOriginalShowItem($showItem, $order)
  1146. {
  1147. if ($showItem == false) {
  1148. return ['list' => [], 'itemStat' => []];
  1149. }
  1150. $orderSn = $order['orderSn'];
  1151. $list = OrderItemClass::getOrderItem($orderSn);
  1152. $totalPrice = 0;
  1153. $totalBigNum = 0;
  1154. $totalSmallNum = 0;
  1155. $kind = 0;
  1156. $itemStat = [];
  1157. if (!empty($list)) {
  1158. $ids = array_column($list, 'productId');
  1159. $ids = array_filter(array_unique($ids));
  1160. $productInfo = ProductClass::getByIds($ids, null, 'id');
  1161. foreach ($list as $key => $val) {
  1162. $productId = $val['productId'] ?? 0;
  1163. $currentInfo = $productInfo[$productId];
  1164. $currentPrice = $productInfo[$productId]['price'] ?? 0;
  1165. $unitPrice = isset($val['xhUnitPrice']) ? floatval($val['xhUnitPrice']) : 0;
  1166. $list[$key]['currentHdPrice'] = $unitPrice;
  1167. //原有售价
  1168. $list[$key]['itemSalePrice'] = floatval($currentPrice);
  1169. //自己填的价格
  1170. $list[$key]['itemModifyPrice'] = $unitPrice;
  1171. $list[$key]['property'] = '';
  1172. $list[$key]['cost'] = $currentInfo['cost'] ?? 0;
  1173. $list[$key]['stock'] = $currentInfo['stock'] ? floatval($currentInfo['stock']) : 0;
  1174. $price = $val['price'];
  1175. $totalPrice = stringUtil::calcAdd($totalPrice, $price);
  1176. $kind++;
  1177. $currentBigNum = $val['bigNum'] ?? 0;
  1178. $currentSmallNum = $val['smallNum'] ?? 0;
  1179. $currentGiveNum = $val['giveNum'] ?? 0;
  1180. $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
  1181. $totalBigNum = bcadd($totalBigNum, $currentGiveNum);
  1182. $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
  1183. }
  1184. $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
  1185. }
  1186. return ['list' => $list, 'itemStat' => $itemStat];
  1187. }
  1188. public static function getShowItem($showItem, $order)
  1189. {
  1190. if ($showItem == false) {
  1191. return ['list' => [], 'itemStat' => []];
  1192. }
  1193. $orderSn = $order['orderSn'];
  1194. $list = OrderItemClass::getOrderItem($orderSn);
  1195. $totalPrice = 0;
  1196. $totalBigNum = 0;
  1197. $totalSmallNum = 0;
  1198. $kind = 0;
  1199. $itemStat = [];
  1200. //小菊增加部分
  1201. $xjAddList = [];
  1202. if (!empty($list)) {
  1203. foreach ($list as $key => $val) {
  1204. $price = $val['price'];
  1205. $totalPrice = stringUtil::calcAdd($totalPrice, $price);
  1206. $kind++;
  1207. $currentBigNum = $val['bigNum'];
  1208. $currentSmallNum = $val['smallNum'];
  1209. $unitType = $val['xhUnitType'] ?? 0;
  1210. $refundNum = $val['refundNum'] ?? 0;
  1211. if ($unitType == 0) {
  1212. $currentBigNum = bcsub($currentBigNum, $refundNum);
  1213. } else {
  1214. $currentSmallNum = bcsub($currentSmallNum, $refundNum);
  1215. }
  1216. $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum);
  1217. $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum);
  1218. //赠送数量
  1219. $giveNum = $val['giveNum'] ?? 0;
  1220. $totalBigNum = bcadd($totalBigNum, $giveNum);
  1221. $list[$key]['property'] = '';
  1222. //小菊
  1223. if (isset($val['variety']) && $val['variety'] == 1) {
  1224. $currentItemId = $val['id'] ?? 0;
  1225. $xjList = OrderXjClass::getAllByCondition(['itemId' => $currentItemId], null, '*');
  1226. if (!empty($xjList)) {
  1227. //选了有颜色的小菊才把原小菊删除不显示出来!!!
  1228. unset($list[$key]);
  1229. foreach ($xjList as $xjKey => $xj) {
  1230. $xjBase = $val;
  1231. $num = $xj['num'] ?? 0;
  1232. $price = $xj['price'] ?? 0;
  1233. $name = $xj['name'] ?? '';
  1234. $cover = $xj['cover'] ?? '';
  1235. if ($num > 0) {
  1236. $bigTotalPrice = bcmul($price, $num, 2);
  1237. $xjBase['cover'] = imgUtil::groupImg($cover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  1238. $xjBase['bigCover'] = imgUtil::groupImg($cover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  1239. $xjBase['unitPrice'] = $price;
  1240. $xjBase['price'] = floatval($bigTotalPrice);
  1241. $xjBase['num'] = floatval($num);
  1242. $xjBase['bigNum'] = floatval($num);
  1243. $xjBase['name'] = $name;
  1244. $xjBase['property'] = '';
  1245. $xjBase['userPrice'] = $bigTotalPrice;
  1246. $xjBase['xhNum'] = floatval($num);
  1247. $xjBase['xhPreNum'] = floatval($num);
  1248. $xjBase['xhPrice'] = floatval($bigTotalPrice);
  1249. $xjAddList[] = $xjBase;
  1250. }
  1251. }
  1252. }
  1253. }
  1254. }
  1255. if (!empty($xjAddList)) {
  1256. $list = array_merge($list, $xjAddList);
  1257. }
  1258. $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice];
  1259. }
  1260. return ['list' => $list, 'itemStat' => $itemStat];
  1261. }
  1262. //订单列表 ssh 2021.1.19
  1263. public static function getOrderList($where)
  1264. {
  1265. $data = self::getList('*', $where, 'addTime DESC');
  1266. $data['totalActPrice'] = 0;
  1267. $data['totalTkPrice'] = 0;
  1268. if (isset($data['list']) && !empty($data['list'])) {
  1269. foreach ($data['list'] as $key => $val) {
  1270. //同个人同地址当天订单数
  1271. $sameTimeIds = $val['sameTimeIds'] ?? '';
  1272. $sameNum = 0;
  1273. if (!empty($sameTimeIds)) {
  1274. $sameIds = explode(',', $sameTimeIds);
  1275. $sameNum = count($sameIds);
  1276. }
  1277. $data['list'][$key]['sameTimeIdsNum'] = $sameNum;
  1278. $data['list'][$key]['customAvatarUrl'] = imgUtil::groupImg('');
  1279. }
  1280. }
  1281. return $data;
  1282. }
  1283. //按片区排列的订单列表
  1284. public static function getDistOrderList($where)
  1285. {
  1286. /** @var Order $model */
  1287. $model = self::getActiveRecord();
  1288. $query = $model->conditionQuery($where)
  1289. ->alias('o')
  1290. ->leftJoin(['c' => Custom::tableName()], 'c.id = o.customId')
  1291. ->select(['o.id', 'o.mainId', 'o.customId', 'o.customName', 'o.customAvatar', 'o.fullAddress', 'o.remark', 'c.name', 'c.mobile', 'c.distId', 'distId' => 'c.distId']);
  1292. // $clone = clone $query;
  1293. // $count = intval($clone->count('o.id'));
  1294. $orderList = $query
  1295. ->orderBy(['c.distId' => SORT_ASC, 'o.addTime' => SORT_DESC]) // ->offset($offset)->limit($pageSize)
  1296. ->asArray()
  1297. ->all();
  1298. $distIds = array_unique(array_filter(array_column($orderList, 'distId')));
  1299. $distMap = [];
  1300. if (!empty($distIds)) {
  1301. $distMap = DistClass::getByIds($distIds, null, 'id');
  1302. }
  1303. $grouped = [];
  1304. foreach ($orderList as $orderInfo) {
  1305. $distId = intval($orderInfo['distId']);
  1306. if (!isset($grouped[$distId]) && isset($distMap[$distId])) {
  1307. $grouped[$distId] = [
  1308. 'distId' => $distId,
  1309. 'distName' => $distMap[$distId]['name'],
  1310. 'list' => [],
  1311. ];
  1312. }
  1313. $grouped[$distId]['list'][$orderInfo['customId']][] = $orderInfo;
  1314. }
  1315. return [
  1316. 'list' => array_values($grouped),
  1317. ];
  1318. }
  1319. //整合订单员工和供货商等信息 ssh 2021.1.19
  1320. //$isList 是否列表页
  1321. public static function groupOrder($list, $showButton = false, $showItem = false, $showExpress = false, $isList = false)
  1322. {
  1323. if (empty($list)) {
  1324. return $list;
  1325. }
  1326. $adminIds = array_unique(array_filter(array_column($list, 'adminId')));
  1327. $adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id');
  1328. //退款需要显示原有的花材结构,不显示小菊的多颜色
  1329. $getOriginalItem = Yii::$app->request->get('getOriginalItem', 0);
  1330. $getOriginalItem2 = Yii::$app->request->post('getOriginalItem', 0);
  1331. $customIds = array_column($list, 'customId');
  1332. $customIds = array_unique(array_filter($customIds));
  1333. $customInfoList = CustomClass::getByIds($customIds, null, 'id');
  1334. foreach ($list as $key => $val) {
  1335. $adminId = $val['adminId'] ?? 0;
  1336. $list[$key]['adminName'] = $adminInfo[$adminId]['name'] ?? '';
  1337. $list[$key]['customAddress'] = $val['fullAddress'] ?? '';
  1338. //显示列表页的操作按钮
  1339. $list[$key]['buttonList'] = self::getShowButton($showButton, $isList, $val);
  1340. //为了列表页的打印按钮能用,列表也强制显示花材
  1341. $showItem = true;
  1342. if ($getOriginalItem == 1 || $getOriginalItem2 == 1) {
  1343. $showItemData = self::getOriginalShowItem($showItem, $val);
  1344. } else {
  1345. $showItemData = self::getShowItem($showItem, $val);
  1346. }
  1347. $list[$key]['product'] = $showItemData['list'];
  1348. $list[$key]['productStat'] = $showItemData['itemStat'];
  1349. $showResetItem = 0;
  1350. //待付款订单显示改花材按钮
  1351. if ($val['status'] == self::PAY_STATUS_UN_PAY) {
  1352. $showResetItem = 1;
  1353. }
  1354. $list[$key]['showResetItem'] = $showResetItem;
  1355. //获取配送进展
  1356. $expressProgress = '';
  1357. if ($val['sendType'] == 4) {
  1358. $expressInfo = OrderExpressClass::getByCondition(['orderSn' => $val['orderSn']]);
  1359. if ($expressInfo) {
  1360. $expressProgress = ['progressName' => OrderExpressClass::$statusMap[$expressInfo['status']] ?? ''];
  1361. }
  1362. }
  1363. $list[$key]['sendTypeName'] = self::$sendTypeMap[$val['sendType']] ?? '未知';
  1364. $list[$key]['expressProgress'] = $expressProgress;
  1365. $list[$key]['customAvatarUrl'] = imgUtil::groupImg($val['customAvatar']);
  1366. $list[$key]['customName'] = !empty($val['customId']) ? $val['customName'] : '散客';
  1367. $customId = $val['customId'] ?? '';
  1368. $debtAmount = $customInfoList[$customId]['debtAmount'] ?? 0.00;
  1369. //打印数据组合
  1370. $printData = self::getPrintData($val, $debtAmount, $showItemData);
  1371. $list[$key]['printData'] = json_encode($printData);
  1372. $list[$key]['debtAmount'] = $debtAmount;
  1373. $list[$key]['customShopId'] = $customInfoList[$customId]['shopId'] ?? 0;
  1374. //计算利润
  1375. $actPrice = $val['actPrice'] ?? 0;
  1376. $remainCost = $val['remainCost'] ?? 0;
  1377. $profit = bcsub($actPrice, $remainCost, 2);
  1378. $profit = floatval($profit);
  1379. $list[$key]['profit'] = $profit;
  1380. }
  1381. return $list;
  1382. }
  1383. public static function printGroup($current, $content, $showPrice = 1, $fontSizeType = 0)
  1384. {
  1385. //58mm的机器,一行打印16个汉字,32个字母
  1386. $productPrice = $current['price'] ?? '';
  1387. $unitPrice = $current['unitPrice'] ?? '';
  1388. $name = $current['name'] ?? '';
  1389. if (floatval($unitPrice) == 0.01) {
  1390. $name = $name . '(送)';
  1391. }
  1392. $productNum = $current['num'] ?? '';
  1393. $itemNum = $current['itemNum'] ?? 0;
  1394. $refundNum = $current['refundNum'] ?? 0;
  1395. $unitName = $current['unitName'] ?? '扎';
  1396. $remark = $current['remark'] ?? '';
  1397. $ratioType = $current['ratioType'] === null ? -1 : intval($current['ratioType']);
  1398. $ratio = $current['ratio'];
  1399. $lastNum = bcsub($itemNum, $refundNum);
  1400. if (!empty($remark)) {
  1401. $show = $name . ' ' . $lastNum . $unitName . "【" . $remark . "】";
  1402. } else {
  1403. $show = $name . ' ' . $lastNum . $unitName;
  1404. }
  1405. $content .= '<B>' . $show . '</B><BR>';
  1406. if ($refundNum > 0) {
  1407. $content .= '(买' . $itemNum . $unitName . ' 退' . $refundNum . $unitName . ')<BR>';
  1408. }
  1409. if ($showPrice == 1) {
  1410. if (floatval($unitPrice) == 0.01) {
  1411. $content .= $productNum . ' = ' . $productPrice . '元 赠送价<BR>';
  1412. } else {
  1413. $content .= $productNum . ' = ' . $productPrice . '元 ' . ($ratioType == 0 ? $ratio . '支装' : ($ratioType == 1 ? '若干支装' : '')) . '<BR>';
  1414. }
  1415. } else {
  1416. $content .= ' ' . ($ratioType == 0 ? $ratio . '支装' : ($ratioType == 1 ? '若干支装' : '')) . '<BR>';
  1417. }
  1418. $content .= '--------------------------------<BR>';
  1419. return $content;
  1420. }
  1421. //合并打印订单 ssh 20230929
  1422. public static function mergePrintOrder($ids, $mainId)
  1423. {
  1424. $all = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1425. if (empty($all)) {
  1426. util::fail('没有找到订单');
  1427. }
  1428. $snList = [];
  1429. $sendNumList = [];
  1430. $remarkList = [];
  1431. foreach ($all as $info) {
  1432. if ($info->mainId != $mainId) {
  1433. util::fail('不是你的订单');
  1434. }
  1435. $orderSn = $info->orderSn;
  1436. if ($info->payStatus == 1) {
  1437. $snList[] = $orderSn;
  1438. $orderInfo = $info;
  1439. $sendNumList[] = $info->sendNum;
  1440. if (!empty($info->remark)) {
  1441. $remarkList[] = $info->remark;
  1442. }
  1443. }
  1444. }
  1445. $sendNumString = '';
  1446. if (!empty($sendNumList)) {
  1447. $sendNumString = implode(',', $sendNumList);
  1448. }
  1449. $remarkString = '';
  1450. if (!empty($remarkList)) {
  1451. $remarkString = implode(',', $remarkList);
  1452. }
  1453. $allItem = OrderItemClass::getAllByCondition(['orderSn' => ['in', $snList]], null, '*');
  1454. if (empty($allItem)) {
  1455. util::fail('没有花材信息');
  1456. }
  1457. $new = [];
  1458. foreach ($allItem as $currentItem) {
  1459. $unitType = $currentItem['xhPreUnitType'] ?? 1;
  1460. $productId = $currentItem['productId'] ?? 0;
  1461. if ($unitType == 0 && $productId > 0) {
  1462. if (isset($new[$productId])) {
  1463. $xhNum = $currentItem['xhNum'] ?? 0;
  1464. $refundNum = $currentItem['refundNum'] ?? 0;
  1465. $giveNum = $currentItem['giveNum'] ?? 0;
  1466. $new[$productId]['xhNum'] = bcadd($new[$productId]['xhNum'], $xhNum);
  1467. $new[$productId]['refundNum'] = bcadd($new[$productId]['refundNum'], $refundNum);
  1468. $new[$productId]['giveNum'] = bcadd($new[$productId]['giveNum'], $giveNum);
  1469. $remark = $currentItem['remark'] ?? '';
  1470. if (!empty($remark)) {
  1471. $new[$productId]['remark'] = $remark;
  1472. }
  1473. } else {
  1474. $new[$productId] = $currentItem;
  1475. }
  1476. }
  1477. }
  1478. $showPrice = 1;
  1479. $customId = $orderInfo->customId ?? 0;
  1480. $c = CustomClass::getById($customId);
  1481. $debtAmount = $c['debtAmount'] ?? 0.00;
  1482. $shopId = $orderInfo->shopId ?? 0;
  1483. $shop = ShopClass::getById($shopId, true);
  1484. if (empty($shop)) {
  1485. util::fail('打印失败,没有找到门店9');
  1486. }
  1487. $sjId = $shop->sjId ?? 0;
  1488. $fontSizeType = $shop->fontSize ?? 0;
  1489. $telephone = $shop->telephone ?? '';
  1490. $sj = SjClass::getById($sjId, true);
  1491. $sjName = $sj->name ?? '';
  1492. $shopName = $shop->shopName ?? '';
  1493. $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1494. $fromType = $orderInfo->fromType ?? dict::getDict('fromType', 'shop');
  1495. $fromTypeMap = dict::getDict('fromTypeMap');
  1496. $fromTypeName = $fromTypeMap[$fromType] ?? '门店';
  1497. $content = "<CB>" . $currentName . "</CB>";
  1498. $content .= "<CB>销售单</CB><BR><BR>";
  1499. $content .= '<B>' . $sendNumString . ' ' . $fromTypeName . '</B><BR>';
  1500. $content .= '--------------------------------<BR>';
  1501. //快捷开单不需要打印买家信息
  1502. if ($customId != $shop->skCustomId) {
  1503. $content .= '<B>买家信息:</B><BR><BR>';
  1504. $content .= '<B>' . $orderInfo->customName . '</B><BR>';
  1505. $content .= '<B>' . $orderInfo->customMobile . '</B><BR>';
  1506. if (isset($orderInfo->address) && !empty($orderInfo->address)) {
  1507. $content .= $orderInfo->fullAddress;
  1508. if (isset($orderInfo->showAddress) && !empty($orderInfo->showAddress)) {
  1509. $content .= '(' . $orderInfo->showAddress . ')<BR>';
  1510. } else {
  1511. $content .= '<BR>';
  1512. }
  1513. }
  1514. }
  1515. if (isset($orderInfo->book) && $orderInfo->book == 1) {
  1516. $content .= '<B>预订单</B><BR>';
  1517. }
  1518. if (isset($orderInfo->presell) && $orderInfo->presell == 1) {
  1519. $content .= '<B>预售单</B><BR>';
  1520. }
  1521. if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
  1522. if (isset($orderInfo->transType)) {
  1523. $sendName = '同城配送';
  1524. if ($orderInfo->transType == 0) {
  1525. $sendName = '德邦物流';
  1526. }
  1527. if ($orderInfo->transType == 1) {
  1528. $sendName = '顺丰物流';
  1529. }
  1530. if ($orderInfo->transType == 2) {
  1531. $sendName = '冷链物流';
  1532. }
  1533. if ($orderInfo->transType == 3) {
  1534. $sendName = '航空物流';
  1535. }
  1536. if ($orderInfo->transType == 4) {
  1537. $sendName = '同城配送';
  1538. }
  1539. if ($orderInfo->transType == 5) {
  1540. $sendName = '到店自取';
  1541. }
  1542. $content .= '<BR><B>' . $sendName . '</B><BR>';
  1543. }
  1544. } else {
  1545. if (isset($orderInfo->sendType)) {
  1546. $sendName = '送货上门';
  1547. if ($orderInfo->sendType == 1) {
  1548. $sendName = '到店自取';
  1549. }
  1550. if ($orderInfo->sendType == 2) {
  1551. $sendName = '跑腿送';
  1552. }
  1553. if ($orderInfo->sendType == 3) {
  1554. $wlName = $orderInfo['wlName'] ?? '未填物流';
  1555. $sendName = $wlName;
  1556. }
  1557. if ($orderInfo->sendType == 4) {
  1558. $sendName = '发快递';
  1559. }
  1560. $content .= '<BR><B>' . $sendName . '</B><BR>';
  1561. }
  1562. }
  1563. if (!empty($remarkString)) {
  1564. $content .= '<BR>';
  1565. $content .= '备注:<BR>';
  1566. $content .= '<B>' . $remarkString . '</B><BR>';
  1567. }
  1568. $content .= '<BR>';
  1569. $content .= '商品 数量/单价 金额 <BR>';
  1570. $content .= '--------------------------------<BR>';
  1571. $totalNum = 0;
  1572. $refundTotalNum = 0;
  1573. foreach ($new as $current) {
  1574. //58mm的机器,一行打印16个汉字,32个字母
  1575. $productPrice = $current['xhUnitPrice'] ?? '';
  1576. $name = $current['name'] ?? '';
  1577. if (floatval($productPrice) == 0.01) {
  1578. $name = $name . '(送)';
  1579. }
  1580. $giveNum = $current['giveNum'] ?? 0;
  1581. $refundNum = $current['refundNum'] ?? 0;
  1582. $productNum = $current['xhNum'] ?? '';
  1583. $unitName = $current['xhUnitName'] ?? '扎';
  1584. $remark = $current['remark'] ?? '';
  1585. $totalNum = bcadd($totalNum, $giveNum);
  1586. $refundTotalNum = bcadd($refundTotalNum, $refundNum);
  1587. $lastNum = bcadd($productNum, $giveNum);
  1588. $lastNum = bcsub($lastNum, $refundNum);
  1589. $show = $name . ' ' . $lastNum . $unitName;
  1590. if (!empty($remark)) {
  1591. $show .= "【{$remark}】";
  1592. }
  1593. $hint = '';
  1594. if ($refundNum > 0 || $giveNum > 0) {
  1595. $hint .= '(买' . $productNum . $unitName;
  1596. }
  1597. if ($refundNum > 0) {
  1598. $hint .= ' 退' . $refundNum . $unitName;
  1599. if ($giveNum <= 0) {
  1600. $hint .= ')';
  1601. }
  1602. }
  1603. if ($giveNum > 0) {
  1604. $hint .= ' 送' . $giveNum . $unitName . ')';
  1605. }
  1606. $content .= '<B>' . $show . '</B><BR>';
  1607. if (!empty($hint)) {
  1608. $content .= $hint . '<BR>';
  1609. }
  1610. $content .= '--------------------------------<BR>';
  1611. $totalNum = bcadd($totalNum, $productNum);
  1612. }
  1613. $content .= '********************************<BR>';
  1614. $kindNum = count($new);
  1615. $remainNum = bcsub($totalNum, $refundTotalNum);
  1616. $content .= "<CB>共{$kindNum}种";
  1617. $content .= ",{$remainNum}扎";
  1618. $content .= "</CB>";
  1619. $content .= '********************************<BR><BR>';
  1620. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  1621. $printSn = $ext['printSn'] ?? '';
  1622. if (!empty($printSn)) {
  1623. $p = new printUtil($printSn);
  1624. $p->printMsg($content, $shop);
  1625. }
  1626. foreach ($all as $info) {
  1627. if ($info->payStatus == 1) {
  1628. $info->printNum += 1;
  1629. $info->printStatus = 2;
  1630. $info->save();
  1631. }
  1632. }
  1633. }
  1634. //超出数量的打印 sssh 20240605
  1635. public static function onlinePrintOver($showItem, $orderInfo, $currentName, $shop)
  1636. {
  1637. $itemList = $showItem['list'];
  1638. $orderSn = $orderInfo->orderSn ?? '';
  1639. $arr = array_chunk($itemList, 40);
  1640. $totalPage = count($arr);
  1641. foreach ($arr as $key => $itemList) {
  1642. $content = '';
  1643. $content .= "<CB>{$currentName}</CB><BR>";
  1644. $content .= "<CB>销售单</CB><BR><BR>";
  1645. $content .= '<CB>' . $orderSn . '</CB><BR><BR>';
  1646. //快捷开单不需要打印买家信息
  1647. if ($orderInfo->customId != $shop->skCustomId) {
  1648. $content .= '<B>买家信息:</B><BR><BR>';
  1649. $content .= '<B>' . $orderInfo->customName . '</B><BR>';
  1650. $content .= '<B>' . $orderInfo->customMobile . '</B><BR>';
  1651. if (isset($orderInfo['address']) && !empty($orderInfo['address'])) {
  1652. $content .= $orderInfo->fullAddress;
  1653. if (isset($orderInfo['showAddress']) && !empty($orderInfo['showAddress']) && $orderInfo->fullAddress != $orderInfo['showAddress']) {
  1654. $content .= '(' . $orderInfo['showAddress'] . ')<BR><BR>';
  1655. } else {
  1656. $content .= '<BR><BR>';
  1657. }
  1658. }
  1659. }
  1660. if ($totalPage > 1) {
  1661. $currentPage = bcadd($key, 1);
  1662. $content .= "<CB>第{$currentPage}页,共{$totalPage}页</CB><BR>";
  1663. }
  1664. $content .= '<BR>';
  1665. $content .= '商品 数量 <BR>';
  1666. $content .= '--------------------------------<BR>';
  1667. if (isset($itemList) && !empty($itemList)) {
  1668. foreach ($itemList as $info) {
  1669. $name = $info['name'] ?? '';
  1670. $num = $info['xhNum'] ?? 0;
  1671. $refundNum = $info['refundNum'] ?? 0;
  1672. $lastNum = bcsub($num, $refundNum);
  1673. $unitName = $info['xhUnitName'] ?? '';
  1674. $show = $name . ' ' . $lastNum . $unitName;
  1675. $content .= '<B>' . $show . '</B><BR>';
  1676. $content .= '--------------------------------<BR>';
  1677. }
  1678. }
  1679. $kindNum = $showItem['itemStat']['kind'] ?? 0;
  1680. $bigNum = $showItem['itemStat']['bigNum'] ?? 0;
  1681. $smallNun = $showItem['itemStat']['smallNun'] ?? 0;
  1682. $content .= '********************************<BR>';
  1683. $content .= "<CB>共{$kindNum}种";
  1684. $content .= " 数量:";
  1685. if ($bigNum > 0) {
  1686. $content .= "{$bigNum}";
  1687. }
  1688. if ($smallNun > 0) {
  1689. $content .= "{$smallNun}";
  1690. }
  1691. $content .= "</CB>";
  1692. $content .= '********************************<BR><BR>';
  1693. $content .= '<BR>';
  1694. $content .= '<BR>';
  1695. $shopId = $shop->id;
  1696. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  1697. $printSn = $ext['printSn'] ?? '';
  1698. if (!empty($printSn)) {
  1699. $p = new printUtil($printSn);
  1700. $p->printMsg($content, $shop);
  1701. }
  1702. }
  1703. }
  1704. //云打印 ssh 20210709
  1705. public static function onlinePrint($orderInfo, $showPrice = 1)
  1706. {
  1707. if (getenv('YII_ENV') == 'production') {
  1708. //淮北花语集、丽子鲜花,客户线上下单不显示价格,门店开单显示价格
  1709. if ($orderInfo->shopId == 1527 || $orderInfo->mainId == 52291) {
  1710. if (!empty($orderInfo->customShopAdminId)) {
  1711. $showPrice = 0;
  1712. }
  1713. }
  1714. //源花汇小票不带价格
  1715. if (isset($orderInfo->mainId) && $orderInfo->mainId == 62382) {
  1716. $showPrice = 0;
  1717. }
  1718. //三明易批花非洲菊 不带价格
  1719. if (isset($orderInfo->mainId) && $orderInfo->mainId == 10536) {
  1720. $showPrice = 0;
  1721. }
  1722. //北京花篮子,线上下单,不显示价格
  1723. if (isset($orderInfo->mainId) && $orderInfo->mainId == 10735) {
  1724. if (!empty($orderInfo->customShopAdminId)) {
  1725. $showPrice = 0;
  1726. }
  1727. }
  1728. //美婷鲜花批发,线上下单,不显示价格
  1729. if (isset($orderInfo->mainId) && $orderInfo->mainId == 73125) {
  1730. if (!empty($orderInfo->customShopAdminId)) {
  1731. $showPrice = 0;
  1732. }
  1733. }
  1734. //淄博花超鲜花小票不带价格
  1735. if (isset($orderInfo->mainId) && $orderInfo->mainId == 16293) {
  1736. $showPrice = 0;
  1737. }
  1738. } else {
  1739. if (isset($orderInfo->mainId) && $orderInfo->mainId == 644) {
  1740. //$showPrice = 0;
  1741. }
  1742. }
  1743. if (isset($orderInfo['actPrice']) && $orderInfo['actPrice'] == 0 && $orderInfo['book'] == 0) {
  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. ProductClass::baseClearLimitBuy($v['productId'], $customId, $num);
  2265. }
  2266. }
  2267. return $order;
  2268. }
  2269. //新订单入队列 ssh 20211012
  2270. public static function newOrderAddQueue($order)
  2271. {
  2272. $shopId = $order->shopId ?? 0;
  2273. if (empty($shopId)) {
  2274. return false;
  2275. }
  2276. $id = $order->id ?? 0;
  2277. if (empty($id)) {
  2278. return false;
  2279. }
  2280. $newOrderKey = 'ghsNewOrder_' . $shopId;
  2281. Yii::$app->redis->executeCommand('LPUSH', [$newOrderKey, $id]);
  2282. }
  2283. public static function createImgOrder($order, $shop, $staff, $all)
  2284. {
  2285. $staffName = $order->shopAdminName ?? '';
  2286. $shopName = $shop->shopName ?? '';
  2287. $sjName = $shop->merchantName ?? '';
  2288. $fullSjName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  2289. $customName = $order->customName ?? '';
  2290. $customId = $order->customId ?? 0;
  2291. $custom = CustomClass::getById($customId, true);
  2292. $debtAmount = $custom->debtAmount ?? 0;
  2293. $mainId = $order->mainId ?? 0;
  2294. $dir = Yii::getAlias('@app/web/html/' . $mainId . '/');
  2295. if (!file_exists($dir)) {
  2296. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  2297. mkdir($dir, 0700, true);
  2298. }
  2299. $payTime = $order->payTime ?? '';
  2300. $currentDate = date("Y-m-d", strtotime($payTime));
  2301. $sameTimeIds = $order->sameTimeIds;
  2302. $sameIds = [];
  2303. if (!empty($sameTimeIds)) {
  2304. $sameIds = explode(',', $sameTimeIds);
  2305. }
  2306. $sameNum = count($sameIds);
  2307. if ($all == 1 && $sameNum > 1) {
  2308. $orderList = OrderClass::getAllByCondition(['id' => ['in', $sameIds]], null, '*');
  2309. if (empty($orderList)) {
  2310. return ['imgFile' => ''];
  2311. }
  2312. $itemList = [];
  2313. $remainDebtPrice = 0;
  2314. $actPrice = 0;
  2315. $tkPrice = 0;
  2316. foreach ($orderList as $currentOrder) {
  2317. $orderSn = $currentOrder['orderSn'] ?? '';
  2318. $remainDebtPrice = bcadd($currentOrder['remainDebtPrice'], $remainDebtPrice, 2);
  2319. $actPrice = bcadd($currentOrder['actPrice'], $actPrice, 2);
  2320. $tkPrice = bcadd($tkPrice, $currentOrder['tkPrice'], 2);
  2321. $itemData = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], 'id asc', '*', null);
  2322. if (!empty($itemData)) {
  2323. foreach ($itemData as $singleItem) {
  2324. $productId = $singleItem['productId'] ?? 0;
  2325. $unitPrice = $singleItem['xhUnitPrice'] ?? 0;
  2326. $unitPrice = floatval($unitPrice);
  2327. $xhNum = $singleItem['xhNum'] ?? 0;
  2328. $refundNum = $singleItem['refundNum'] ?? 0;
  2329. if (isset($itemList[$productId . '_' . $unitPrice])) {
  2330. $currentInfo = $itemList[$productId . '_' . $unitPrice];
  2331. $thisNum = bcadd($currentInfo['xhNum'], $xhNum);
  2332. $thisRefundNum = bcadd($currentInfo['refundNum'], $refundNum);
  2333. $itemList[$productId . '_' . $unitPrice]['xhNum'] = $thisNum;
  2334. $itemList[$productId . '_' . $unitPrice]['refundNum'] = $thisRefundNum;
  2335. } else {
  2336. $itemList[$productId . '_' . $unitPrice] = $singleItem;
  2337. }
  2338. }
  2339. }
  2340. }
  2341. $itemList = array_values($itemList);
  2342. $beforeDebtPrice = bcsub($debtAmount, $remainDebtPrice, 2);
  2343. $tkString = '';
  2344. if ($tkPrice > 0) {
  2345. $tkString = "<span style='margin-right:15px;'>已退款:{$tkPrice}</span>";
  2346. }
  2347. } else {
  2348. $orderSn = $order->orderSn ?? '';
  2349. $remainDebtPrice = $order->remainDebtPrice ?? 0;
  2350. $beforeDebtPrice = bcsub($debtAmount, $remainDebtPrice, 2);
  2351. $actPrice = $order->actPrice ?? 0;
  2352. $tkPrice = $order->tkPrice ?? 0;
  2353. $tkString = '';
  2354. if ($tkPrice > 0) {
  2355. $tkString = "<span style='margin-right:15px;'>已退款:{$tkPrice}</span>";
  2356. }
  2357. $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], 'id asc', '*', null);
  2358. }
  2359. if (empty($itemList)) {
  2360. return ['imgFile' => ''];
  2361. }
  2362. $balance = $custom->balance ?? 0;
  2363. $balanceContent = '';
  2364. if ($balance > 0 && $balance > $debtAmount) {
  2365. if ($debtAmount > 0 && $balance > $debtAmount) {
  2366. $remainBalance = bcsub($balance, $debtAmount, 2);
  2367. $balanceContent = '<span style="margin-right:15px;">余额:' . $balance . ',最终余额:' . $remainBalance . '</span>';
  2368. } else {
  2369. $balanceContent = '<span style="margin-right:15px;">余额:' . $balance . '</span>';
  2370. }
  2371. }
  2372. if ($debtAmount >= $balance) {
  2373. $debtAmount = bcsub($debtAmount, $balance, 2);
  2374. }
  2375. if ($beforeDebtPrice >= $balance) {
  2376. $beforeDebtPrice = bcsub($beforeDebtPrice, $balance, 2);
  2377. }
  2378. $totalNum = 0;
  2379. $totalAmount = 0;
  2380. foreach ($itemList as $item) {
  2381. $xhNum = $item['xhNum'] ?? 0;
  2382. $refundNum = $item['refundNum'] ?? 0;
  2383. $realNum = bcsub($xhNum, $refundNum);
  2384. $unitPrice = $item['xhUnitPrice'] ?? 0;
  2385. $amount = bcmul($realNum, $unitPrice, 2);
  2386. $totalNum = bcadd($totalNum, $realNum);
  2387. $totalAmount = bcadd($totalAmount, $amount, 2);
  2388. }
  2389. $totalAmount = floatval($totalAmount);
  2390. $itemList[] = ['xhNum' => $totalNum, 'totalAmount' => $totalAmount,];
  2391. $content = <<<XL
  2392. <html>
  2393. <head>
  2394. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  2395. </head>
  2396. <body>
  2397. XL;
  2398. $total = count($itemList);
  2399. $pageSize = 14;
  2400. $totalPage = ceil($total / $pageSize);
  2401. for ($page = 1; $page <= $totalPage; $page++) {
  2402. $start = ($page - 1) * $pageSize;
  2403. $currentList = array_slice($itemList, $start, $pageSize);
  2404. if (!empty($currentList)) {
  2405. $tableList = '';
  2406. foreach ($currentList as $key => $item) {
  2407. $index = bcadd($key, $start);
  2408. $index++;
  2409. $name = $item['name'] ?? '';
  2410. $num = $item['xhNum'];
  2411. $refundNum = $item['refundNum'] ?? 0;
  2412. $realNum = bcsub($num, $refundNum);
  2413. $bigUnit = $item['xhUnitName'] ?? '';
  2414. $unitPrice = $item['xhUnitPrice'] ?? 0;
  2415. $unitPrice = floatval($unitPrice);
  2416. $amount = bcmul($realNum, $unitPrice, 2);
  2417. $amount = floatval($amount);
  2418. if ($name == '') {
  2419. $index = '合计';
  2420. $amount = $item['totalAmount'] ?? 0;
  2421. }
  2422. $remark = $item['remark'] ?? '';
  2423. $tableList .= "<tr>";
  2424. $tableList .= "<td>{$index}</td>";
  2425. $tableList .= "<td>{$name}</td>";
  2426. $tableList .= "<td>{$realNum}</td>";
  2427. $tableList .= "<td>{$bigUnit}</td>";
  2428. $tableList .= "<td>{$unitPrice}</td>";
  2429. $tableList .= "<td>{$amount}</td>";
  2430. $tableList .= "<td>{$remark}</td>";
  2431. $tableList .= "</tr>";
  2432. }
  2433. $content .= <<<XL
  2434. <div style="width:760px;height:4px;background-color:black;margin-bottom:10px;"></div>
  2435. <div style="width:750px;text-align:center;font-weight:bold;margin-bottom:20px;font-size:18px;">
  2436. <div>{$fullSjName}</div>
  2437. <div style="margin-top:5px;">销售单</div>
  2438. </div>
  2439. <div style="width:750px;">
  2440. <span>单据日期:{$currentDate}</span>
  2441. <span style="margin-left:80px;">开单:{$staffName}</span>
  2442. <span style="margin-left:80px;">客户:{$customName}</span>
  2443. <span style="float:right;">编号:{$orderSn}</span>
  2444. <div>
  2445. <table border="1" style="border: 1px solid black;border-collapse:collapse;text-align:center;font-size:14px;width:750px;margin-top:5px;">
  2446. <tr style="font-weight:bold;">
  2447. <td style="width:70px;">编号</td>
  2448. <td style="width:200px;">名称</td>
  2449. <td style="width:70px;">数量</td>
  2450. <td style="width:70px;">单位</td>
  2451. <td style="width:70px;">单价</td>
  2452. <td style="width:90px;">金额</td>
  2453. <td style="width:160px;">备注</td>
  2454. </tr>
  2455. {$tableList}
  2456. </table>
  2457. <div style="margin-top:5px;margin-bottom:20px;">
  2458. {$tkString}
  2459. <span style="margin-right:15px;">本单:{$actPrice}</span>
  2460. <span style="margin-right:15px;">上次欠款:{$beforeDebtPrice}</span>
  2461. <span style="margin-right:15px;">待付欠款:{$debtAmount}</span>
  2462. {$balanceContent}
  2463. </div>
  2464. <div style="margin-top:5px;margin-bottom:20px;">
  2465. <span style="margin-right:15px;color:red;font-weight:bold;font-size:20px;">请在收到货后12小时以内验货,超12小时概不负责!</span>
  2466. </div>
  2467. XL;
  2468. }
  2469. }
  2470. $content .= <<<XL
  2471. </body>
  2472. <style>
  2473. body{
  2474. font-size:14px;
  2475. }
  2476. td{
  2477. padding:4px;
  2478. }
  2479. </style>
  2480. </html>
  2481. XL;
  2482. $file = $dir . $orderSn . '.html';
  2483. $imgFile = $dir . $orderSn . '.png';
  2484. if (file_exists($file)) {
  2485. unlink($file);
  2486. }
  2487. if (file_exists($imgFile)) {
  2488. unlink($imgFile);
  2489. }
  2490. file_put_contents($file, $content);
  2491. $con = new Converter(null, [
  2492. "fmt" => "png",
  2493. "in" => $file,
  2494. "out" => $imgFile,
  2495. ]);
  2496. $con->convert();
  2497. return ['imgFile' => $imgFile];
  2498. }
  2499. //应收统计下载 ssh 20240530
  2500. public static function exportAccountList($list, $mainId)
  2501. {
  2502. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  2503. require_once($phpExcelFile . 'Classes/PHPExcel.php');
  2504. $objPHPExcel = new \PHPExcel();
  2505. $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
  2506. ->setLastModifiedBy("Maarten Balliauw")
  2507. ->setTitle("Office 2007 XLSX Document")
  2508. ->setSubject("Office 2007 XLSX Document")
  2509. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  2510. ->setKeywords("office 2007 openxml php")
  2511. ->setCategory("file");
  2512. $ghsTitle = '供货商';
  2513. $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
  2514. $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
  2515. $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
  2516. $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
  2517. $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
  2518. $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
  2519. $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
  2520. $objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
  2521. $objPHPExcel->getActiveSheet()->setCellValue('B1', '名称');
  2522. $objPHPExcel->getActiveSheet()->setCellValue('C1', '金额');
  2523. $objPHPExcel->getActiveSheet()->setCellValue('D1', '订单数');
  2524. //设置宽度
  2525. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
  2526. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
  2527. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
  2528. //加粗
  2529. $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
  2530. $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
  2531. $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
  2532. $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
  2533. $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2534. $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2535. $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2536. $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2537. $baseRow = 2;
  2538. foreach ($list as $key => $custom) {
  2539. $i = $baseRow + $key;
  2540. $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['id']);
  2541. $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['name']);
  2542. $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['amount']);
  2543. $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['num']);
  2544. //居左
  2545. $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2546. $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2547. $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2548. $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2549. }
  2550. $fileName = '应收统计-' . date("m-d");
  2551. $objPHPExcel->getActiveSheet()->setTitle($fileName);
  2552. $objPHPExcel->setActiveSheetIndex(0);
  2553. $dir = './priceTable/' . $mainId;
  2554. if (file_exists($dir) == false) {
  2555. mkdir($dir, 0777, true);
  2556. }
  2557. $date = $fileName;
  2558. $file = $date . '.xls';
  2559. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  2560. if (file_exists($dir . '/' . $file)) {
  2561. unlink($dir . '/' . $file);
  2562. }
  2563. $objWriter->save($dir . '/' . $file);
  2564. $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
  2565. util::success(['file' => $fileUrl, 'shortFile' => $file]);
  2566. }
  2567. //应收统计下载 ssh 20240530
  2568. public static function exportPastList($list, $mainId)
  2569. {
  2570. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  2571. require_once($phpExcelFile . 'Classes/PHPExcel.php');
  2572. $objPHPExcel = new \PHPExcel();
  2573. $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
  2574. ->setLastModifiedBy("Maarten Balliauw")
  2575. ->setTitle("Office 2007 XLSX Document")
  2576. ->setSubject("Office 2007 XLSX Document")
  2577. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  2578. ->setKeywords("office 2007 openxml php")
  2579. ->setCategory("file");
  2580. $ghsTitle = '供货商';
  2581. $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
  2582. $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
  2583. $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
  2584. $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
  2585. $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
  2586. $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
  2587. $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
  2588. $objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
  2589. $objPHPExcel->getActiveSheet()->setCellValue('B1', '客户');
  2590. $objPHPExcel->getActiveSheet()->setCellValue('C1', '手机号');
  2591. $objPHPExcel->getActiveSheet()->setCellValue('D1', '欠款金额');
  2592. //设置宽度
  2593. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
  2594. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
  2595. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
  2596. //加粗
  2597. $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
  2598. $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
  2599. $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
  2600. $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
  2601. $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2602. $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2603. $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2604. $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2605. $baseRow = 2;
  2606. foreach ($list as $key => $custom) {
  2607. $i = $baseRow + $key;
  2608. $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['id']);
  2609. $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['name']);
  2610. $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['mobile']);
  2611. $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['currentDebAmount']);
  2612. //居左
  2613. $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2614. $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2615. $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2616. $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2617. }
  2618. $fileName = '历史应收-' . date("m-d");
  2619. $objPHPExcel->getActiveSheet()->setTitle($fileName);
  2620. $objPHPExcel->setActiveSheetIndex(0);
  2621. $dir = './priceTable/' . $mainId;
  2622. if (file_exists($dir) == false) {
  2623. mkdir($dir, 0777, true);
  2624. }
  2625. $date = $fileName;
  2626. $file = $date . '.xls';
  2627. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  2628. if (file_exists($dir . '/' . $file)) {
  2629. unlink($dir . '/' . $file);
  2630. }
  2631. $objWriter->save($dir . '/' . $file);
  2632. $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
  2633. util::success(['file' => $fileUrl, 'shortFile' => $file]);
  2634. }
  2635. public static function exportYj($list, $mainId)
  2636. {
  2637. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  2638. require_once($phpExcelFile . 'Classes/PHPExcel.php');
  2639. $objPHPExcel = new \PHPExcel();
  2640. $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
  2641. ->setLastModifiedBy("Maarten Balliauw")
  2642. ->setTitle("Office 2007 XLSX Document")
  2643. ->setSubject("Office 2007 XLSX Document")
  2644. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  2645. ->setKeywords("office 2007 openxml php")
  2646. ->setCategory("file");
  2647. $ghsTitle = '供货商';
  2648. $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle);
  2649. $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7);
  2650. $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1);
  2651. $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5);
  2652. $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0);
  2653. $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1);
  2654. $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0);
  2655. $objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
  2656. $objPHPExcel->getActiveSheet()->setCellValue('B1', '客户');
  2657. $objPHPExcel->getActiveSheet()->setCellValue('C1', '手机号');
  2658. $objPHPExcel->getActiveSheet()->setCellValue('D1', '订单数');
  2659. $objPHPExcel->getActiveSheet()->setCellValue('E1', '订单金额');
  2660. $objPHPExcel->getActiveSheet()->setCellValue('F1', '退款金额');
  2661. $objPHPExcel->getActiveSheet()->setCellValue('G1', '实际金额');
  2662. $objPHPExcel->getActiveSheet()->setCellValue('H1', '纸箱费');
  2663. $objPHPExcel->getActiveSheet()->setCellValue('I1', '打包费');
  2664. $objPHPExcel->getActiveSheet()->setCellValue('J1', '运费');
  2665. //设置宽度
  2666. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
  2667. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
  2668. //加粗
  2669. $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true);
  2670. $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true);
  2671. $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true);
  2672. $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true);
  2673. $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setSize(9)->setBold(true);
  2674. $objPHPExcel->getActiveSheet()->getStyle('F1')->getFont()->setSize(9)->setBold(true);
  2675. $objPHPExcel->getActiveSheet()->getStyle('G1')->getFont()->setSize(9)->setBold(true);
  2676. $objPHPExcel->getActiveSheet()->getStyle('H1')->getFont()->setSize(9)->setBold(true);
  2677. $objPHPExcel->getActiveSheet()->getStyle('I1')->getFont()->setSize(9)->setBold(true);
  2678. $objPHPExcel->getActiveSheet()->getStyle('J1')->getFont()->setSize(9)->setBold(true);
  2679. $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2680. $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2681. $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2682. $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2683. $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2684. $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2685. $objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2686. $objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2687. $objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2688. $objPHPExcel->getActiveSheet()->getStyle('J1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2689. $baseRow = 2;
  2690. foreach ($list as $key => $custom) {
  2691. $i = $baseRow + $key;
  2692. $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['id']);
  2693. $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['name']);
  2694. $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['mobile']);
  2695. $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['num']);
  2696. $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $custom['orderPrice']);
  2697. $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $custom['tkPrice']);
  2698. $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, $custom['actPrice']);
  2699. $objPHPExcel->getActiveSheet()->setCellValue('H' . $i, $custom['carton']);
  2700. $objPHPExcel->getActiveSheet()->setCellValue('I' . $i, $custom['pack']);
  2701. $objPHPExcel->getActiveSheet()->setCellValue('J' . $i, $custom['freight']);
  2702. //居左
  2703. $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2704. $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2705. $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2706. $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2707. $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2708. $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2709. $objPHPExcel->getActiveSheet()->getStyle('G' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2710. $objPHPExcel->getActiveSheet()->getStyle('H' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2711. $objPHPExcel->getActiveSheet()->getStyle('I' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2712. $objPHPExcel->getActiveSheet()->getStyle('J' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  2713. }
  2714. $fileName = '客户业绩-' . date("m-d");
  2715. $objPHPExcel->getActiveSheet()->setTitle($fileName);
  2716. $objPHPExcel->setActiveSheetIndex(0);
  2717. $dir = './priceTable/' . $mainId;
  2718. if (file_exists($dir) == false) {
  2719. mkdir($dir, 0777, true);
  2720. }
  2721. $date = $fileName;
  2722. $file = $date . '.xls';
  2723. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  2724. if (file_exists($dir . '/' . $file)) {
  2725. unlink($dir . '/' . $file);
  2726. }
  2727. $objWriter->save($dir . '/' . $file);
  2728. $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file;
  2729. util::success(['file' => $fileUrl, 'shortFile' => $file]);
  2730. }
  2731. public static function printLogisticsLabel($order, $shop, $ext)
  2732. {
  2733. /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/
  2734. $orderMainId = $order->mainId;
  2735. if (getenv('YII_ENV') == 'production') {
  2736. $map = [65726, 58, 25119, 28500, 1294,12925];
  2737. } else {
  2738. $map = [828];
  2739. }
  2740. /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/
  2741. $customId = $order->customId ?? 0;
  2742. $custom = CustomClass::getById($customId, true);
  2743. if (empty($custom)) {
  2744. if (!in_array($orderMainId, $map)) {
  2745. util::fail('没有找到客户');
  2746. } else {
  2747. return false;
  2748. }
  2749. }
  2750. $shortName = $custom->shortName ?? '未命名';
  2751. $shortName = stringUtil::subStringUtf8($shortName, 5);
  2752. $customMobile = $order->customMobile ?? '';
  2753. if (empty($customMobile)) {
  2754. if (!in_array($orderMainId, $map)) {
  2755. util::fail('客户手机号无效');
  2756. } else {
  2757. return false;
  2758. }
  2759. }
  2760. $customName = $order->customName ?? '';
  2761. $shortMobile = substr($customMobile, -4);
  2762. $remark = $order->remark ?? '';
  2763. $shortRemark = stringUtil::subStringUtf8($remark, 8);
  2764. $wlName = $custom->wlName ?? '';
  2765. if (empty($wlName)) {
  2766. $wlName = $shortRemark;
  2767. }
  2768. $distId = $custom->distId ?? '';
  2769. $dist = DistClass::getById($distId, true);
  2770. $distName = $dist->name ?? '未分区';
  2771. $address = $order->address ?? '';
  2772. $floor = $order->floor ?? '';
  2773. $fullAddress = $address . $floor;
  2774. $shopName = $shop->shopName ?? '';
  2775. $sjName = $shop->merchantName;
  2776. $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  2777. $telephone = $shop->telephone ?? '';
  2778. $wlLabelSn = $ext->wlLabelSn ?? '';
  2779. if (empty($wlLabelSn)) {
  2780. if (!in_array($orderMainId, $map)) {
  2781. util::fail('请绑定物流标签机');
  2782. } else {
  2783. return false;
  2784. }
  2785. }
  2786. $p = new printUtil($wlLabelSn);
  2787. if (!in_array($orderMainId, $map)) {
  2788. $p->times = 1;
  2789. //安庆三叶鲜花批发,比较特殊
  2790. if ($orderMainId == 2071) {
  2791. $content = '<TEXT x="386" y="120" font="12" w="4" h="4" r="90">' . $shortName . '</TEXT>';
  2792. $content .= '<TEXT x="363" y="10" font="12" w="2" h="2" r="90">地址</TEXT>';
  2793. $content .= '<TEXT x="270" y="120" font="12" w="3" h="3" r="90">' . $customMobile . '</TEXT>';
  2794. $content .= '<TEXT x="256" y="10" font="12" w="2" h="2" r="90">号码</TEXT>';
  2795. $content .= '<TEXT x="182" y="120" font="12" w="4" h="4" r="90">' . $wlName . '</TEXT>';
  2796. $content .= '<TEXT x="158" y="10" font="12" w="2" h="2" r="90">物流</TEXT>';
  2797. $content .= '<TEXT x="65" y="35" font="12" w="2" h="2" r="90">' . $currentName . ' ' . $telephone . '</TEXT>';
  2798. } else {
  2799. $content = '<TEXT x="420" y="130" font="12" w="4" h="4" r="90">' . $shortName . '</TEXT>';
  2800. $content .= '<TEXT x="395" y="10" font="12" w="2" h="2" r="90">地址</TEXT>';
  2801. $content .= '<TEXT x="290" y="130" font="12" w="3" h="3" r="90">' . $customMobile . '</TEXT>';
  2802. $content .= '<TEXT x="265" y="10" font="12" w="2" h="2" r="90">号码</TEXT>';
  2803. $content .= '<TEXT x="170" y="130" font="12" w="4" h="4" r="90">' . $wlName . '</TEXT>';
  2804. $content .= '<TEXT x="150" y="10" font="12" w="2" h="2" r="90">物流</TEXT>';
  2805. $content .= '<TEXT x="45" y="70" font="12" w="2" h="2" r="90">' . $currentName . ' ' . $telephone . '</TEXT>';
  2806. }
  2807. } else {
  2808. /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/
  2809. $sameTimeIds = $order->sameTimeIds;
  2810. $num = 1;
  2811. if (!empty($sameTimeIds)) {
  2812. $ids = explode(',', $sameTimeIds);
  2813. if (!empty($ids)) {
  2814. $num = count($ids);
  2815. }
  2816. }
  2817. if ($num > 1) {
  2818. $customName = $customName . ' ' . $num . '单';
  2819. }
  2820. $itemNum = $order->itemNum ?? 0;
  2821. $itemNum = floatval($itemNum);
  2822. $payTime = $order->payTime ?? '';
  2823. $payDate = date('m-d H:i', strtotime($payTime));
  2824. $content = '<TEXT x="400" y="30" font="12" w="3" h="3" r="90">' . $customName . '</TEXT>';
  2825. $content .= '<TEXT x="280" y="30" font="12" w="2" h="2" r="90">' . $fullAddress . '</TEXT>';
  2826. $content .= '<TEXT x="180" y="30" font="12" w="2" h="2" r="90">' . $customMobile . ' ' . $itemNum . '扎</TEXT>';
  2827. $content .= '<TEXT x="86" y="30" font="12" w="2" h="2" r="90">' . $distName . ' ' . $payDate . '</TEXT>';
  2828. /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/
  2829. }
  2830. $p->printLabelMsg($content);
  2831. return true;
  2832. }
  2833. // 更新同天内的所有订单的 sameTimeIds
  2834. public static function updateSameTimeIds($order, $date)
  2835. {
  2836. $id = $order->id ?? 0;
  2837. $customId = $order->customId ?? 0;
  2838. $mainId = $order->mainId ?? 0;
  2839. $oldSameTimeIds = $order->sameTimeIds ?? '';
  2840. //找到当前订单客户的账单日期为 $date 的所有订单,然后更新同天内的所有订单的 sameTimeIds(加此次要改变的订单的订单号$id)
  2841. $startTime = $date . ' 00:00:00';
  2842. $endTime = $date . ' 23:59:59';
  2843. $dayOrders = self::getAllByCondition([
  2844. 'mainId' => $mainId,
  2845. 'customId' => $customId,
  2846. 'payTime' => ['between', [$startTime, $endTime]]
  2847. ], 'id ASC', 'id, sameTimeIds');
  2848. $ids = [];
  2849. if (!empty($dayOrders)) {
  2850. $ids = array_column($dayOrders, 'id');
  2851. }
  2852. // 确保当前订单ID在列表中
  2853. if (!in_array($id, $ids)) {
  2854. $ids[] = $id;
  2855. }
  2856. // 排序并去重
  2857. sort($ids);
  2858. $ids = array_unique($ids);
  2859. // 限制最多 90 单,避免 someTimeIds 过长(兼容原先业务逻辑限制)
  2860. if (count($ids) > 90) {
  2861. $ids = array_slice($ids, 0, 90);
  2862. }
  2863. $sameTimeIdsStr = implode(',', $ids);
  2864. // 更新所有相关订单
  2865. if (!empty($ids) && in_array($id, $ids)) {
  2866. self::updateByIds($ids, ['sameTimeIds' => $sameTimeIdsStr]);
  2867. }
  2868. //从原先同天内的订单中删除此次要改变的订单的订单号$id
  2869. if (!empty($oldSameTimeIds) && $oldSameTimeIds != $sameTimeIdsStr) {
  2870. $oldSameTimeIdsArr = explode(',', $oldSameTimeIds);
  2871. if (in_array($id, $oldSameTimeIdsArr)) {
  2872. $oldSameTimeIdsArr = array_diff($oldSameTimeIdsArr, [$id]);
  2873. $oldSameTimeIdsStr = implode(',', $oldSameTimeIdsArr);
  2874. if (!empty($oldSameTimeIdsArr)) {
  2875. self::updateByIds($oldSameTimeIdsArr, ['sameTimeIds' => $oldSameTimeIdsStr]);
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }