OrderClass.php 132 KB

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