OrderClass.php 137 KB

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