OrderController.php 198 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\common\classes\GhsNotifyClass;
  4. use biz\common\classes\HdNotifyClass;
  5. use biz\shop\classes\ShopExtClass;
  6. use bizGhs\custom\classes\CustomDebtChangeClass;
  7. use bizGhs\express\classes\GhsDeliveryOrderClass;
  8. use bizGhs\express\services\DadaExpressServices;
  9. use bizGhs\ghs\classes\GhsClass;
  10. use bizGhs\order\classes\OrderForwardClass;
  11. use bizGhs\order\classes\OrderItemClass;
  12. use bizGhs\order\classes\RefundOrderClass;
  13. use bizHd\purchase\classes\PurchaseClass;
  14. use bizHd\purchase\classes\PurchaseItemClass;
  15. use bizHd\purchase\services\PurchaseService;
  16. use bizHd\wx\classes\WxOpenClass;
  17. use bizGhs\custom\classes\CustomClass;
  18. use bizGhs\order\classes\OrderClass;
  19. use bizGhs\order\classes\OrderMergeClass;
  20. use bizGhs\order\classes\OrderMergeSnClass;
  21. use bizGhs\order\services\OrderService;
  22. use bizHd\saas\services\RegionService;
  23. use bizGhs\product\classes\ProductClass;
  24. use common\components\baiduAip;
  25. use common\components\feiePrintLogUtil;
  26. use common\components\dateUtil;
  27. use common\components\dirUtil;
  28. use common\components\freight;
  29. use common\components\httpUtil;
  30. use common\components\noticeUtil;
  31. use common\components\orderSn;
  32. use common\components\oss;
  33. use common\components\payUtil;
  34. use common\components\qrCodeUtil;
  35. use common\components\stringUtil;
  36. use Yii;
  37. use common\components\util;
  38. use biz\shop\classes\ShopAdminClass;
  39. use biz\shop\classes\ShopClass;
  40. use common\components\dict;
  41. use common\components\lakala\Lakala;
  42. use ghs\models\order\CreateOrderForm;
  43. class OrderController extends BaseController
  44. {
  45. public $guestAccess = ['create-order', 'order-relate', 'fast-pay', 'info'];
  46. //打印物流列表 ssh 20250712
  47. public function actionPrintWlList()
  48. {
  49. $get = Yii::$app->request->get();
  50. $begin = $get['begin'] ?? 1;
  51. $hour = $get['hour'] ?? 0;
  52. if ($hour > 24 || $hour < 0) {
  53. util::fail('必须0到24点');
  54. }
  55. if ($begin == 0) {
  56. $date = date('Y-m-d', strtotime('-1 day'));
  57. } else {
  58. $date = date('Y-m-d');
  59. }
  60. $beginGroup = $date . " {$hour}:00:00";
  61. $newTime = strtotime($beginGroup);
  62. $beginTime = date('Y-m-d H:i:s', $newTime);
  63. $endTime = date("Y-m-d H:i:s");
  64. $shop = $this->shop;
  65. OrderClass::printMyWlList($shop, $beginTime, $endTime);
  66. util::complete('打印成功');
  67. }
  68. //修改平账标识状态 ssh 20240405
  69. public function actionModifyClearSign()
  70. {
  71. $get = Yii::$app->request->get();
  72. $id = $get['id'] ?? '';
  73. $order = OrderClass::getById($id, true);
  74. if (empty($order)) {
  75. util::fail('没有找到订单');
  76. }
  77. if ($order->mainId != $this->mainId) {
  78. util::fail('不是你的订单');
  79. }
  80. if (!in_array($order->status, [3, 4])) {
  81. util::fail('订单没有发货');
  82. }
  83. if ($order->clearSign == 1) {
  84. util::fail('不需要重复操作');
  85. }
  86. $connection = Yii::$app->db;
  87. $transaction = $connection->beginTransaction();
  88. try {
  89. $order->clearSign = 1;
  90. $order->save();
  91. $cgId = $order->purchaseId;
  92. $cg = PurchaseClass::getById($cgId, true);
  93. if (empty($cg)) {
  94. util::fail('没有找到采购信息');
  95. }
  96. $cg->clearSign = 1;
  97. $cg->save();
  98. $transaction->commit();
  99. util::complete();
  100. } catch (\Exception $e) {
  101. $transaction->rollBack();
  102. Yii::error("操作失败原因:" . $e->getMessage());
  103. util::fail('操作失败');
  104. }
  105. }
  106. //下载图片版订单 ssh 20240321
  107. public function actionDown()
  108. {
  109. $get = Yii::$app->request->get();
  110. $id = $get['id'] ?? '';
  111. $all = $get['all'] ?? 0;
  112. $order = OrderClass::getById($id, true);
  113. if (empty($order)) {
  114. util::fail('没有找到订单');
  115. }
  116. if ($order->mainId != $this->mainId) {
  117. util::fail('不是你的订单');
  118. }
  119. $customName = $order->customName ?? '';
  120. $date = date("Ymd", strtotime($order->addTime));
  121. $orderSn = $order->orderSn ?? '';
  122. $name = $customName . '_' . $date . '_' . $orderSn;
  123. $shop = $this->shop;
  124. $staff = $this->shopAdmin;
  125. $respond = OrderClass::createImgOrder($order, $shop, $staff, $all);
  126. $imgUrl = $respond['imgFile'] ?? '';
  127. $file = fopen($imgUrl, "rb");
  128. Header("Content-type: application/octet-stream ");
  129. Header("Accept-Ranges: bytes ");
  130. Header("Content-Disposition: attachment;filename={$name}.png");
  131. $contents = "";
  132. while (!feof($file)) {
  133. $contents .= fread($file, 8192);
  134. }
  135. echo $contents;
  136. fclose($file);
  137. }
  138. //确认送达
  139. public function actionConfirmReach()
  140. {
  141. $get = Yii::$app->request->get();
  142. $id = $get['id'] ?? '';
  143. $order = OrderClass::getById($id, true);
  144. if (empty($order)) {
  145. util::fail('没有找到订单');
  146. }
  147. if ($order->mainId != $this->mainId) {
  148. util::fail('不是你的订单');
  149. }
  150. if ($order->status == 1) {
  151. util::fail('订单待付款');
  152. }
  153. if ($order->status == 4) {
  154. util::fail('订单已完成');
  155. }
  156. if ($order->status == 5) {
  157. util::fail('订单已取消');
  158. }
  159. if (!in_array($order->sendStatus, [-1, -4, -2])) {
  160. util::fail('已经叫跑腿了');
  161. }
  162. $connection = Yii::$app->db;
  163. $transaction = $connection->beginTransaction();
  164. try {
  165. $staff = $this->shopAdmin;
  166. $staffId = $staff->id ?? 0;
  167. $staffName = $staff->name ?? '';
  168. $params = ['staffId' => $staffId, 'staffName' => $staffName];
  169. OrderClass::confirmReach($order, $params);
  170. $transaction->commit();
  171. util::complete('操作成功');
  172. } catch (\Exception $e) {
  173. $transaction->rollBack();
  174. Yii::error("操作失败原因:" . $e->getMessage());
  175. util::fail('确认失败');
  176. }
  177. }
  178. //发货 ssh 20230613
  179. public function actionFh()
  180. {
  181. $post = Yii::$app->request->post();
  182. $id = $post['id'] ?? '';
  183. $order = OrderClass::getById($id, true);
  184. OrderClass::valid($order, $this->shopId);
  185. $staff = $this->shopAdmin;
  186. $staffId = $staff->id ?? 0;
  187. $staffName = $staff->name ?? '';
  188. $fhWl = $post['fhWl'] ?? '';
  189. $fhWlNo = $post['fhWlNo'] ?? '';
  190. $fhType = $post['fhType'] ?? '';
  191. $params = [
  192. 'fhType' => $fhType,
  193. 'fhWl' => $fhWl,
  194. 'fhWlNo' => $fhWlNo,
  195. 'staffId' => $staffId,
  196. 'staffName' => $staffName,
  197. ];
  198. if ($order->book == 1) {
  199. util::fail('预订单不能直接发货');
  200. }
  201. $connection = Yii::$app->db;
  202. $transaction = $connection->beginTransaction();
  203. try {
  204. //花店会增加路上库存
  205. OrderClass::orderSend($order, $params);
  206. $transaction->commit();
  207. util::complete();
  208. } catch (\Exception $e) {
  209. $transaction->rollBack();
  210. Yii::error("操作失败原因:" . $e->getMessage());
  211. util::fail('操作失败');
  212. }
  213. }
  214. public function actionAllFh()
  215. {
  216. $post = Yii::$app->request->post();
  217. $ids = $post['ids'] ?? '';
  218. $mergeId = $post['mergeId'] ?? 0;
  219. if (empty($ids)) {
  220. if (empty($mergeId)) {
  221. util::fail('请选择要合并发货的订单');
  222. }
  223. $mergeInfo = OrderMergeSnClass::getById($mergeId, true);
  224. if (empty($mergeInfo)) {
  225. util::fail('请选择要合并发货的订单呢');
  226. }
  227. if ($mergeInfo->mainId != $this->mainId) {
  228. util::fail('不是你的订单呢');
  229. }
  230. $mergeRows = OrderMergeClass::getAllByCondition(['mergeId' => $mergeId], null, 'orderId');
  231. $ids = !empty($mergeRows) ? implode(',', array_column($mergeRows, 'orderId')) : '';
  232. if (empty($ids)) {
  233. util::fail('请选择要合并发货的订单哈');
  234. }
  235. }
  236. $arr = explode(',', $ids);
  237. if (empty($arr)) {
  238. util::fail('请选择要合并发货的订单哦');
  239. }
  240. $fhWl = $post['fhWl'] ?? '';
  241. $fhWlNo = $post['fhWlNo'] ?? '';
  242. $fhType = 0;
  243. $params = [
  244. 'fhType' => $fhType,
  245. 'fhWl' => $fhWl,
  246. 'fhWlNo' => $fhWlNo,
  247. ];
  248. $connection = Yii::$app->db;
  249. $transaction = $connection->beginTransaction();
  250. try {
  251. $all = OrderClass::getAllByCondition(['id' => ['in', $arr]], null, '*', null, true);
  252. foreach ($all as $order) {
  253. if ($order->book == 1) {
  254. util::fail('有预订单,不能一起发货');
  255. }
  256. if ($order->mainId != $this->mainId) {
  257. util::fail('不是你的订单哦');
  258. }
  259. OrderClass::orderSend($order, $params, true);
  260. }
  261. $transaction->commit();
  262. util::complete();
  263. } catch (\Exception $e) {
  264. $transaction->rollBack();
  265. Yii::error("操作失败原因:" . $e->getMessage());
  266. util::fail('操作失败');
  267. }
  268. }
  269. //合并打印 ssh 20230929
  270. public function actionMergePrint()
  271. {
  272. $post = Yii::$app->request->post();
  273. $ids = $post['ids'] ?? '';
  274. $mergeId = $post['mergeId'] ?? 0;
  275. if (empty($ids)) {
  276. if (empty($mergeId)) {
  277. util::fail('请选择要合并打印的订单');
  278. }
  279. $mergeInfo = OrderMergeSnClass::getById($mergeId, true);
  280. if (empty($mergeInfo)) {
  281. util::fail('请选择要合并打印的订单呢');
  282. }
  283. if ($mergeInfo->mainId != $this->mainId) {
  284. util::fail('不是你的订单呢');
  285. }
  286. $mergeRows = OrderMergeClass::getAllByCondition(['mergeId' => $mergeId], null, 'orderId');
  287. $ids = !empty($mergeRows) ? implode(',', array_column($mergeRows, 'orderId')) : '';
  288. if (empty($ids)) {
  289. util::fail('请选择要合并打印的订单哈');
  290. }
  291. }
  292. $arr = explode(',', $ids);
  293. if (empty($arr)) {
  294. util::fail('请选择要合并打印的订单哦');
  295. }
  296. if (getenv('YII_ENV') == 'production') {
  297. if ($this->mainId != 10536 && $this->mainId != 50) {
  298. //util::fail('功能开发中');
  299. }
  300. } else {
  301. if ($this->mainId != 11) {
  302. //util::fail('功能开发中');
  303. }
  304. }
  305. OrderClass::mergePrintOrder($arr, $this->mainId);
  306. util::complete('打印成功');
  307. }
  308. //获取合并订单列表 ssh 20260518
  309. public function actionMergeOrderList()
  310. {
  311. //同个人当天订单不可能超过9999
  312. Yii::$app->params['pageSize'] = 9999;
  313. $get = Yii::$app->request->get();
  314. $mergeId = $get['mergeId'] ?? '';
  315. $mergeInfo = OrderMergeSnClass::getById($mergeId, true);
  316. if (empty($mergeInfo)) {
  317. util::fail('请选择订单');
  318. }
  319. if ($mergeInfo->mainId != $this->mainId) {
  320. util::fail('不是你的订单');
  321. }
  322. $mergeRows = OrderMergeClass::getAllByCondition(['mergeId' => $mergeId], null, 'orderId');
  323. $ids = !empty($mergeRows) ? implode(',', array_column($mergeRows, 'orderId')) : '';
  324. if (empty($ids)) {
  325. util::fail('请选择订单哈');
  326. }
  327. $where['mainId'] = $this->mainId;
  328. $newIds = explode(',', $ids);
  329. if (empty($newIds)) {
  330. util::fail('请选订单哈');
  331. }
  332. $where['id'] = ['in', $newIds];
  333. $respond = OrderClass::getOrderList($where);
  334. $respond['shop'] = $this->shop;
  335. $respond['shopExt'] = $this->shopExt;
  336. $totalPrice = 0;
  337. if (!empty($respond['list'])) {
  338. foreach ($respond['list'] as $order) {
  339. $actPrice = $order['actPrice'] ?? 0;
  340. $totalPrice = bcadd($totalPrice, $actPrice, 2);
  341. }
  342. }
  343. $totalPrice = floatval($totalPrice);
  344. $respond['shareInfo'] = [
  345. 'id' => $mergeInfo->cgMergeId ?? 0,
  346. 'mergeId' => $mergeInfo->cgMergeId ?? 0,
  347. 'salt' => $mergeInfo->cgSalt ?? '',
  348. 'totalPrice' => $totalPrice,
  349. ];
  350. util::success($respond);
  351. }
  352. //修改分工 ssh 20221129
  353. public function actionChangeWorker()
  354. {
  355. $post = Yii::$app->request->post();
  356. $id = $post['id'] ?? 0;
  357. $shopAdminId = $post['shopAdminId'] ?? 0;
  358. $shopAdminName = $post['shopAdminName'] ?? '';
  359. $order = OrderClass::getById($id, true);
  360. OrderClass::valid($order, $this->shopId);
  361. $preShopAdminId = $order->shopAdminId ?? 0;
  362. if (!empty($preShopAdminId)) {
  363. $shopAdmin = $this->shopAdmin;
  364. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  365. util::fail('管理员才能操作');
  366. }
  367. }
  368. $order->shopAdminId = $shopAdminId;
  369. $order->shopAdminName = $shopAdminName;
  370. $order->save();
  371. util::complete();
  372. }
  373. //预订单到货 ssh 20220321
  374. public function actionArrival()
  375. {
  376. //避免重复提交
  377. $adminId = $this->adminId;
  378. util::checkRepeatCommit($adminId, 6);
  379. $post = Yii::$app->request->post();
  380. $id = $post['id'] ?? 0;
  381. $todayBill = $post['todayBill'] ?? 1;
  382. $connection = Yii::$app->db;
  383. $transaction = $connection->beginTransaction();
  384. try {
  385. $order = OrderClass::getById($id, true);
  386. OrderClass::valid($order, $this->shopId);
  387. $post['shopAdminId'] = $this->shopAdminId;
  388. $post['shopAdminName'] = $this->shopAdmin ? $this->shopAdmin->name : '';
  389. $shop = $this->shop;
  390. $bookSn = $shop->bookSn ?? 0;
  391. if (!empty($bookSn)) {
  392. if ($order->bookSn == $bookSn) {
  393. util::fail('预订结束了才能确认');
  394. }
  395. }
  396. OrderService::arrival($order, $post);
  397. if ($todayBill == 0) {
  398. $lastTime = time() - 86400;
  399. $payTime = date("Y-m-d H:i:s", $lastTime);
  400. $order->payTime = $payTime;
  401. $order->save();
  402. $purchaseId = $order->purchaseId ?? 0;
  403. $cg = PurchaseClass::getById($purchaseId, true);
  404. if (!empty($cg)) {
  405. $cg->payTime = $payTime;
  406. $cg->save();
  407. }
  408. }
  409. $transaction->commit();
  410. util::success($order);
  411. } catch (\Exception $e) {
  412. $transaction->rollBack();
  413. Yii::error("操作失败原因:" . $e->getMessage());
  414. util::fail('操作失败');
  415. }
  416. }
  417. //到货获取订单详情 ssh 20220323
  418. public function actionArrivalDetail()
  419. {
  420. $get = Yii::$app->request->get();
  421. $id = $get['id'] ?? 0;
  422. $info = OrderClass::getById($id);
  423. OrderClass::valid($info, $this->shopId);
  424. $showItemData = OrderClass::getOriginalShowItem(true, $info);
  425. $itemList = $showItemData['list'] ?? [];
  426. $info['product'] = $itemList;
  427. $kiloFee = $this->shop->kiloFee ?? 0;
  428. $miniKilo = $this->shop->miniKilo ?? 0;
  429. $info['kiloFee'] = $kiloFee;
  430. $info['miniKilo'] = $miniKilo;
  431. util::success($info);
  432. }
  433. //支付宝扫码支付 ssh 20210103
  434. public function actionScanPayCheck()
  435. {
  436. $get = Yii::$app->request->get();
  437. $id = isset($get['id']) ? $get['id'] : 0;
  438. $order = OrderClass::getById($id, true);
  439. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY && $order->status != OrderClass::ORDER_STATUS_CANCEL) {
  440. util::success(['returnStatus' => 'SUCCESS']);
  441. }
  442. $deadline = $order->deadline ?? '';
  443. $deadTime = strtotime($deadline);
  444. $current = time();
  445. $diff = bcsub($deadTime, $current);
  446. if ($diff <= 60) {
  447. util::success(['returnStatus' => 'EXPIRE']);
  448. }
  449. util::success(['returnStatus' => 'FAILURE']);
  450. }
  451. //微信和支付宝扫码支付 ssh 20210103
  452. public function actionScanPay()
  453. {
  454. ini_set('date.timezone', 'Asia/Shanghai');
  455. header("Content-type: text/html; charset=utf-8");
  456. $get = Yii::$app->request->get();
  457. $id = isset($get['id']) ? $get['id'] : 0;
  458. $order = OrderClass::getById($id, true);
  459. if (isset($order->status) == false || $order->status != 1) {
  460. util::success(['returnStatus' => 'FAILURE'], '不是待付款订单');
  461. }
  462. OrderClass::valid($order, $this->shopId);
  463. $cgId = $order->purchaseId ?? 0;
  464. $cg = PurchaseClass::getById($cgId, true);
  465. $orderSn = $cg->orderSn ?? '';
  466. if (empty($orderSn)) {
  467. util::success(['returnStatus' => 'FAILURE'], '没有找到采购单');
  468. }
  469. $deadline = $cg->deadline;
  470. $current = date("Y-m-d H:i:s");
  471. if ((strtotime($deadline) + 20) < strtotime($current)) {
  472. util::success(['returnStatus' => 'FAILURE'], '订单已经失效');
  473. }
  474. $totalFee = $cg->actPrice ?? 0;
  475. $subject = '购买鲜花';
  476. $totalAmount = $totalFee;
  477. $body = "到店订单";
  478. //标记为扫码支付 和 自取订单
  479. $order->codePay = 2;
  480. $order->sendType = OrderClass::SEND_TYPE_NO;
  481. $order->save();
  482. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  483. $cg->codePay = 2;
  484. $cg->save();
  485. $shop = $this->shop;
  486. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  487. $wxPayWay = dict::getDict('payWay', 'wxPay');
  488. $aliPayWay = dict::getDict('payWay', 'alipay');
  489. $payWay = Yii::$app->request->get('payWay', $wxPayWay);
  490. if ($payWay == $wxPayWay) {
  491. if (isset($order->wxPayUrl) && !empty($order->wxPayUrl)) {
  492. $url = $order->wxPayUrl;
  493. } else {
  494. util::fail('暂不支持');
  495. $merchantExtend = WxOpenClass::getWxInfo();
  496. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  497. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  498. $params = [
  499. 'appid' => 'OP00002119',
  500. 'serial_no' => '018b08cfddbd',
  501. 'merchant_no' => $shop->lklSjNo,
  502. 'term_no' => $shop->lklScanTermNo,
  503. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  504. 'lklCertificatePath' => $lklCertificatePath,
  505. ];
  506. $laResource = new Lakala($params);
  507. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  508. $wxParams = [
  509. 'orderSn' => $orderSn,
  510. 'amount' => $totalFee,
  511. 'capitalType' => $currentCapitalType,
  512. 'notifyUrl' => $notifyUrl,
  513. 'subject' => $subject,
  514. 'couponId' => 0,
  515. 'wxAppId' => $merchantExtend['miniAppId'],
  516. ];
  517. $response = $laResource->driveNativeWxPay($wxParams);
  518. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  519. $msg = $response['msg'] ?? '';
  520. noticeUtil::push($msg, '15280215347');
  521. util::fail('二维码生成失败');
  522. }
  523. $url = isset($response['resp_data']['acc_resp_fields']['code']) ? $response['resp_data']['acc_resp_fields']['code'] : '';
  524. if (empty($url)) {
  525. util::fail('二维码生成失败..');
  526. }
  527. $order->wxPayUrl = $url;
  528. $order->save();
  529. }
  530. $suffixUrl = qrCodeUtil::generateShortTimeGatheringQrCode($url, $this->sjId, $this->shopId, $payWay);
  531. $payUrl = Yii::$app->params['ghsImgHost'] . $suffixUrl;
  532. util::success(['url' => $payUrl, 'returnStatus' => 'SUCCESS']);
  533. }
  534. if ($payWay == $aliPayWay) {
  535. if (isset($order->aliPayUrl) && !empty($order->aliPayUrl)) {
  536. $url = $order->aliPayUrl;
  537. } else {
  538. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  539. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  540. $params = [
  541. 'appid' => 'OP00002119',
  542. 'serial_no' => '018b08cfddbd',
  543. 'merchant_no' => $shop->lklSjNo,
  544. 'term_no' => $shop->lklScanTermNo,
  545. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  546. 'lklCertificatePath' => $lklCertificatePath,
  547. ];
  548. $laResource = new Lakala($params);
  549. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  550. $aliParams = [
  551. 'orderSn' => $orderSn,
  552. 'amount' => $totalFee,
  553. 'capitalType' => $currentCapitalType,
  554. 'notifyUrl' => $notifyUrl,
  555. 'subject' => $subject,
  556. ];
  557. $response = $laResource->driveAliPay($aliParams);
  558. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  559. util::fail('二维码生成失败');
  560. }
  561. $url = isset($response['resp_data']['acc_resp_fields']['code']) ? $response['resp_data']['acc_resp_fields']['code'] : '';
  562. if (empty($url)) {
  563. util::fail('二维码生成失败..');
  564. }
  565. $order->aliPayUrl = $url;
  566. $order->save();
  567. }
  568. $suffixUrl = qrCodeUtil::generateShortTimeGatheringQrCode($url, $this->sjId, $this->shopId, $payWay);
  569. $payUrl = Yii::$app->params['ghsImgHost'] . $suffixUrl;
  570. util::success(['url' => $payUrl, 'returnStatus' => 'SUCCESS']);
  571. }
  572. util::success(['returnStatus' => 'FAILURE'], '不支持的收款方式');
  573. }
  574. //微信和支付宝付款码支付复查 ssh 20211231
  575. public function actionCodePayCheck()
  576. {
  577. ini_set('date.timezone', 'Asia/Shanghai');
  578. header("Content-type: text/html; charset=utf-8");
  579. $get = Yii::$app->request->get();
  580. $id = isset($get['id']) ? $get['id'] : 0;
  581. util::checkRepeatCommit($id, 3);
  582. $order = OrderClass::getById($id, true);
  583. OrderClass::valid($order, $this->shopId);
  584. if ($order->payStatus == 1) {
  585. util::success(['returnStatus' => 'SUCCESS']);
  586. }
  587. if ($order->status == 5) {
  588. util::success(['returnStatus' => 'CANCEL']);
  589. }
  590. $cgId = $order->purchaseId ?? 0;
  591. $cg = PurchaseClass::getById($cgId, true);
  592. $orderSn = $cg->orderSn ?? '';
  593. $totalFee = $cg->actPrice ?? 0;
  594. if (empty($orderSn)) {
  595. util::complete('没有找到采购单');
  596. }
  597. $connection = Yii::$app->db;
  598. $transaction = $connection->beginTransaction();
  599. try {
  600. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  601. $shop = $this->shop;
  602. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  603. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  604. $params = [
  605. 'appid' => 'OP00002119',
  606. 'serial_no' => '018b08cfddbd',
  607. 'merchant_no' => $shop->lklSjNo,
  608. 'term_no' => $shop->lklScanTermNo,
  609. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  610. 'lklCertificatePath' => $lklCertificatePath,
  611. ];
  612. $laResource = new Lakala($params);
  613. $scanParams = ['orderSn' => $orderSn,];
  614. $response = $laResource->query($scanParams);
  615. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  616. if (isset($response['resp_data']['trade_state']) && $response['resp_data']['trade_state'] == 'SUCCESS') {
  617. //支付成功
  618. $transactionId = $response['resp_data']['trade_no'] ?? '';
  619. $openId = '';
  620. $aliUserId = '';
  621. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  622. $cg->codePay = 1;
  623. $cg->payOpenId = $openId;
  624. $cg->aliUserId = $aliUserId;
  625. //自取订单
  626. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  627. $cg->save();
  628. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  629. $order->codePay = 1;
  630. //自取订单
  631. $order->sendType = OrderClass::SEND_TYPE_NO;
  632. $order->save();
  633. $payWayType = dict::getDict('payWay', 'wxPay');
  634. $account_type = $response['resp_data']['account_type'] ?? '';
  635. if ($account_type == 'WECHAT') {
  636. $payWayType = dict::getDict('payWay', 'wxPay');
  637. }
  638. if ($account_type == 'ALIPAY') {
  639. $payWayType = dict::getDict('payWay', 'alipay');
  640. }
  641. $order->payWay = $payWayType;
  642. $order->save();
  643. $cg->payWay = $payWayType;
  644. $cg->save();
  645. $attach = '';
  646. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  647. $transaction->commit();
  648. $saleId = $order->id ?? 0;
  649. $order = OrderClass::getById($saleId, true);
  650. if (!empty($order)) {
  651. //解决付款成功后重复通知打印问题
  652. $cacheKey = 'pay_success_notice_' . $orderSn;
  653. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  654. if (!empty($has)) {
  655. return false;
  656. }
  657. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 1, 'has']);
  658. //订单生成时唤起在线打印
  659. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  660. if ($order->status != 1 && $order->status != 5) {
  661. OrderClass::onlinePrint($order);
  662. $ext = $this->shopExt;
  663. if (isset($ext->printSn) && !empty($ext->printSn)) {
  664. $order->printNum += 1;
  665. $order->save();
  666. }
  667. }
  668. }
  669. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  670. GhsDeliveryOrderClass::payAfter($order);
  671. ShopExtClass::ghsGatheringReport($order);
  672. }
  673. util::success(['returnStatus' => 'SUCCESS']);
  674. } else {
  675. util::complete('未知状态..');
  676. }
  677. } else {
  678. util::complete('未知状态....');
  679. }
  680. } catch (\Exception $e) {
  681. $transaction->rollBack();
  682. noticeUtil::push('查询订单状态失败:' . $e->getMessage(), '15280215347');
  683. util::fail('支付失败');
  684. }
  685. }
  686. //微信和支付宝付款码支付复查 ssh 20260716
  687. public function actionCodePayVerify()
  688. {
  689. ini_set('date.timezone', 'Asia/Shanghai');
  690. header("Content-type: text/html; charset=utf-8");
  691. $get = Yii::$app->request->get();
  692. $id = $get['id'] ?? 0;
  693. util::checkRepeatCommit($id, 3);
  694. $order = OrderClass::getById($id, true);
  695. if (empty($order)) {
  696. util::complete('没有找到订单呢');
  697. }
  698. OrderClass::valid($order, $this->shopId);
  699. if ($order->payStatus == 1) {
  700. util::success(['returnStatus' => 'SUCCESS']);
  701. }
  702. if ($order->status == 5) {
  703. util::success(['returnStatus' => 'CANCEL']);
  704. }
  705. $cgId = $order->purchaseId ?? 0;
  706. $cg = PurchaseClass::getById($cgId, true);
  707. $orderSn = $cg->orderSn ?? '';
  708. $totalFee = $cg->actPrice ?? 0;
  709. if (empty($orderSn)) {
  710. util::complete('没有找到采购单');
  711. }
  712. $connection = Yii::$app->db;
  713. $transaction = $connection->beginTransaction();
  714. try {
  715. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  716. $shop = $this->shop;
  717. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  718. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  719. $params = [
  720. 'appid' => 'OP00002119',
  721. 'serial_no' => '018b08cfddbd',
  722. 'merchant_no' => $shop->lklSjNo,
  723. 'term_no' => $shop->lklScanTermNo,
  724. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  725. 'lklCertificatePath' => $lklCertificatePath,
  726. ];
  727. $laResource = new Lakala($params);
  728. $scanParams = ['orderSn' => $orderSn,];
  729. $response = $laResource->query($scanParams);
  730. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  731. if (isset($response['resp_data']['trade_state']) && $response['resp_data']['trade_state'] == 'SUCCESS') {
  732. //支付成功
  733. $transactionId = $response['resp_data']['trade_no'] ?? '';
  734. $openId = '';
  735. $aliUserId = '';
  736. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  737. $cg->codePay = 1;
  738. $cg->payOpenId = $openId;
  739. $cg->aliUserId = $aliUserId;
  740. //自取订单
  741. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  742. $cg->save();
  743. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  744. $order->codePay = 1;
  745. //自取订单
  746. $order->sendType = OrderClass::SEND_TYPE_NO;
  747. $order->save();
  748. $payWayType = dict::getDict('payWay', 'wxPay');
  749. $account_type = $response['resp_data']['account_type'] ?? '';
  750. if ($account_type == 'WECHAT') {
  751. $payWayType = dict::getDict('payWay', 'wxPay');
  752. }
  753. if ($account_type == 'ALIPAY') {
  754. $payWayType = dict::getDict('payWay', 'alipay');
  755. }
  756. $order->payWay = $payWayType;
  757. $order->save();
  758. $cg->payWay = $payWayType;
  759. $cg->save();
  760. $attach = '';
  761. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  762. $transaction->commit();
  763. $saleId = $order->id ?? 0;
  764. $order = OrderClass::getById($saleId, true);
  765. if (!empty($order)) {
  766. //解决付款成功后重复通知打印问题
  767. $cacheKey = 'pay_success_notice_' . $orderSn;
  768. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  769. if (!empty($has)) {
  770. return false;
  771. }
  772. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 1, 'has']);
  773. //订单生成时唤起在线打印
  774. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  775. if ($order->status != 1 && $order->status != 5) {
  776. OrderClass::onlinePrint($order);
  777. $ext = $this->shopExt;
  778. if (isset($ext->printSn) && !empty($ext->printSn)) {
  779. $order->printNum += 1;
  780. $order->save();
  781. }
  782. }
  783. }
  784. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  785. GhsDeliveryOrderClass::payAfter($order);
  786. ShopExtClass::ghsGatheringReport($order);
  787. }
  788. util::success(['returnStatus' => 'SUCCESS']);
  789. } else {
  790. util::success(['returnStatus' => 'PENDING'], '等待支付中...');
  791. }
  792. } else {
  793. util::success(['returnStatus' => 'PENDING'], '等待支付中...');
  794. }
  795. } catch (\Exception $e) {
  796. $transaction->rollBack();
  797. noticeUtil::push('查询订单状态失败:' . $e->getMessage(), '15280215347');
  798. util::fail('支付失败');
  799. }
  800. }
  801. /**
  802. * 微信和支付宝付款码支付
  803. * 职责:处理商户扫描客户付款码(被扫支付)的请求,调用拉卡拉支付接口并更新本地订单状态
  804. * 入参:GET 传参 id (订单ID), authCode (付款码)
  805. * 返回:JSON 格式的支付结果(SUCCESS/FAILURE)
  806. * 副作用:更新订单及采购单的支付状态、支付方式,记录支付日志,触发云打印、跑腿呼叫及语音播报
  807. * 关键边界:
  808. * 1. 验证订单及采购单的有效性与时效性
  809. * 2. 校验付款码格式(微信/支付宝)
  810. * 3. 优化:将拉卡拉外部网络请求移出数据库事务,避免因网络延迟长时间占用数据库连接和行锁
  811. */
  812. public function actionCodePay()
  813. {
  814. ini_set('date.timezone', 'Asia/Shanghai');
  815. header("Content-type: text/html; charset=utf-8");
  816. $get = Yii::$app->request->get();
  817. $id = isset($get['id']) ? $get['id'] : 0;
  818. util::checkRepeatCommit($id, 3);
  819. $order = OrderClass::getById($id, true);
  820. if (empty($order)) {
  821. $msg = '没有找到订单';
  822. util::success(['returnStatus' => 'FAILURE'], $msg);
  823. }
  824. if ($order->status == 5) {
  825. $msg = '订单已取消';
  826. util::success(['returnStatus' => 'FAILURE'], $msg);
  827. }
  828. if ($order->status != 1) {
  829. $msg = '不是待付款订单';
  830. util::success(['returnStatus' => 'FAILURE'], $msg);
  831. }
  832. OrderClass::valid($order, $this->shopId);
  833. $cgId = $order->purchaseId ?? 0;
  834. $cg = PurchaseClass::getById($cgId, true);
  835. $orderSn = $cg->orderSn ?? '';
  836. if (empty($orderSn)) {
  837. $msg = '没有找到采购单';
  838. util::success(['returnStatus' => 'FAILURE'], $msg);
  839. }
  840. $codePayErrorKey = 'code_pay_error_' . $id;
  841. $hasFailPay = Yii::$app->redis->executeCommand('GET', [$codePayErrorKey]);
  842. //前面有付失败过,要重新生成单号
  843. if (!empty($hasFailPay)) {
  844. $oldOrderSn = $orderSn;
  845. $shopId = $cg->shopId ?? 0;
  846. $mainId = $cg->mainId ?? 0;
  847. $ghsId = $cg->ghsId ?? 0;
  848. $customId = $cg->customId ?? 0;
  849. $snData = ['shopId' => $shopId, 'mainId' => $mainId, 'ghsId' => $ghsId, 'customId' => $customId];
  850. $orderSn = orderSn::getPurchaseSn($snData);
  851. $cg->orderSn = $orderSn;
  852. $cg->save();
  853. //noticeUtil::push("重新扫码,成功更换单号 {$oldOrderSn} {$orderSn}", '15280215347');
  854. PurchaseItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $orderSn]);
  855. }
  856. $shop = $this->shop;
  857. $sj = $shop->merchantName;
  858. $shopName = $shop->shopName;
  859. $name = $shopName == '首店' ? $sj : $sj . '-' . $shopName;
  860. //付款码
  861. $authCode = (string)$get['authCode'] ?? '';
  862. $authCode = trim($authCode);
  863. if (empty($authCode)) {
  864. $msg = '没有扫到付款码';
  865. $remind = $msg . "(付款码:{$authCode})" . '(' . $name . ')';
  866. noticeUtil::push($remind . ' 编号001', '15280215347');
  867. util::success(['returnStatus' => 'FAILURE'], $msg);
  868. }
  869. //微信文档说明 https://pay.weixin.qq.com/doc/v2/merchant/4011936234
  870. $wxPattern = '/^(10|11|12|13|14|15)\d{16}$/';
  871. //支付宝文档说明 https://opendocs.alipay.com/open/194/106039/
  872. $aliPattern = '/^(25|26|27|28|29|30)\d{14,22}$/';
  873. if (!preg_match($wxPattern, $authCode) && !preg_match($aliPattern, $authCode)) {
  874. $msg = '付款码错误,请使用微信或支付宝付款码';
  875. $remind = $msg . "(付款码:{$authCode})" . '(' . $name . ')';
  876. //noticeUtil::push($remind . ' 编号002', '15280215347');
  877. util::success(['returnStatus' => 'FAILURE'], $msg);
  878. }
  879. $deadline = $cg->deadline;
  880. $current = date("Y-m-d H:i:s");
  881. if ((strtotime($deadline) + 20) < strtotime($current)) {
  882. $msg = '订单已经失效';
  883. util::success(['returnStatus' => 'FAILURE'], $msg);
  884. }
  885. $totalFee = $cg->actPrice ?? 0;
  886. try {
  887. $subject = '购买花材 ' . $orderSn;
  888. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  889. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  890. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  891. $params = [
  892. 'appid' => 'OP00002119',
  893. 'serial_no' => '018b08cfddbd',
  894. 'merchant_no' => $shop->lklSjNo,
  895. 'term_no' => $shop->lklScanTermNo,
  896. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  897. 'lklCertificatePath' => $lklCertificatePath,
  898. ];
  899. $laResource = new Lakala($params);
  900. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  901. $scanParams = [
  902. 'orderSn' => $orderSn,
  903. 'amount' => $totalFee,
  904. 'capitalType' => $capitalType,
  905. 'notifyUrl' => $notifyUrl,
  906. 'subject' => $subject,
  907. 'authCode' => $authCode,
  908. ];
  909. // 复杂分支/关键逻辑:在调用外部支付接口前不开启事务,防止网络延迟卡死数据库连接
  910. $response = $laResource->scanPay($scanParams);
  911. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  912. // 复杂分支/关键逻辑:支付成功后,开启数据库事务,确保本地订单状态更新的原子性
  913. $connection = Yii::$app->db;
  914. $transaction = $connection->beginTransaction();
  915. try {
  916. $account_type = $response['resp_data']['account_type'] ?? '';
  917. $payWayType = dict::getDict('payWay', 'wxPay');
  918. if ($account_type == 'WECHAT') {
  919. $payWayType = dict::getDict('payWay', 'wxPay');
  920. }
  921. if ($account_type == 'ALIPAY') {
  922. $payWayType = dict::getDict('payWay', 'alipay');
  923. }
  924. $order->payWay = $payWayType;
  925. $order->save();
  926. $cg->payWay = $payWayType;
  927. $cg->save();
  928. $transactionId = $response['resp_data']['trade_no'] ?? '';
  929. $openId = '';
  930. $aliUserId = '';
  931. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  932. $cg->codePay = 1;
  933. $cg->payOpenId = $openId;
  934. $cg->aliUserId = $aliUserId;
  935. $cg->save();
  936. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  937. $order->codePay = 1;
  938. $order->save();
  939. $attach = '';
  940. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  941. $transaction->commit();
  942. } catch (\Exception $e) {
  943. $transaction->rollBack();
  944. throw $e;
  945. }
  946. $saleId = $order->id ?? 0;
  947. $order = OrderClass::getById($saleId, true);
  948. if (!empty($order)) {
  949. //解决付款成功后重复通知打印问题
  950. $cacheKey = 'pay_success_notice_' . $orderSn;
  951. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  952. if (!empty($has)) {
  953. return false;
  954. }
  955. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 1, 'has']);
  956. //订单生成时唤起在线打印
  957. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  958. if ($order->status != 1 && $order->status != 5) {
  959. OrderClass::onlinePrint($order);
  960. $ext = $this->shopExt;
  961. if (isset($ext->printSn) && !empty($ext->printSn)) {
  962. $order->printNum += 1;
  963. $order->save();
  964. }
  965. }
  966. }
  967. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  968. GhsDeliveryOrderClass::payAfter($order);
  969. ShopExtClass::ghsGatheringReport($order);
  970. }
  971. util::success(['returnStatus' => 'SUCCESS']);
  972. } else {
  973. //标记有没付成功的次数,原因有可能是余额不足等
  974. Yii::$app->redis->executeCommand('SETEX', [$codePayErrorKey, 1200, 'hasFail']);
  975. $msg = $response['msg'] ?? '';
  976. $retCode = $response['code'] ?? '';
  977. if ($retCode == 'BBS10000' || $retCode == 'BBS11105') {
  978. $shopId = $order->shopId;
  979. ShopExtClass::remindInputPassword($shopId);
  980. }
  981. $fullMsg = $msg . "(付款码:{$authCode})" . '(' . $name . ')';
  982. //noticeUtil::push($fullMsg . ' ' . $retCode . ' 编号007', '15280215347');
  983. util::success(['returnStatus' => 'FAILURE', 'returnCode' => $retCode], $msg);
  984. }
  985. } catch (\Exception $e) {
  986. Yii::error("支付失败原因:" . $e->getMessage());
  987. util::fail('支付失败');
  988. }
  989. }
  990. //订单列表 ssh 2021.1.20
  991. public function actionList()
  992. {
  993. $get = Yii::$app->request->get();
  994. $export = $get['export'] ?? 0;
  995. $onlySend = $get['onlySend'] ?? 0;
  996. ini_set('memory_limit', '5045M');
  997. set_time_limit(0);
  998. $staff = $this->shopAdmin;
  999. if (isset($staff->identity) && $staff->identity == 2) {
  1000. //如果用于确认发货时要显出订单
  1001. if ($onlySend == 0) {
  1002. util::success(['list' => []]);
  1003. }
  1004. }
  1005. $where['mainId'] = $this->mainId;
  1006. $status = $get['status'] ?? 0;
  1007. if (!empty($status)) {
  1008. $where['status'] = $status;
  1009. }
  1010. $clearSign = $get['clearSign'] ?? -1;
  1011. if ($clearSign > -1) {
  1012. $where['clearSign'] = $clearSign;
  1013. }
  1014. $book = $get['book'] ?? -1;
  1015. if ($book > -1) {
  1016. $where['book'] = $book;
  1017. }
  1018. $searchTime = $get['searchTime'] ?? '';
  1019. //0搜索的addTime 1搜索的payTime
  1020. $searchTimeType = $get['searchTimeType'] ?? 0;
  1021. if (!empty($searchTime)) {
  1022. $startTime = $get['startTime'] ?? '';
  1023. $endTime = $get['endTime'] ?? '';
  1024. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  1025. if ($searchTimeType == 0) {
  1026. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1027. } else {
  1028. $where['payTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1029. }
  1030. }
  1031. if ($export == 1) {
  1032. ini_set('memory_limit', '2045M');
  1033. set_time_limit(0);
  1034. if (!isset($where['payTime'])) {
  1035. util::fail('请选 账单日期 和 时间段');
  1036. }
  1037. $start = $where['payTime'][1][0];
  1038. $end = $where['payTime'][1][1];
  1039. $monthTime = bcmul(31, 86400);
  1040. $startArea = strtotime($start);
  1041. $endArea = strtotime($end);
  1042. $diff = bcsub($endArea, $startArea);
  1043. if ($diff > $monthTime) {
  1044. util::fail('最长可导出一个月');
  1045. }
  1046. }
  1047. $name = $get['name'] ?? '';
  1048. if (!empty($name)) {
  1049. $searchType = $get['searchType'] ?? 0;
  1050. if (empty($searchType)) {
  1051. //订单编号
  1052. if (strpos($name, 'XSD') === 0) {
  1053. $where['orderSn'] = $name;
  1054. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  1055. $where['customNamePy'] = ['like', $name];
  1056. } else {
  1057. $where['customName'] = ['like', $name];
  1058. }
  1059. } elseif ($searchType == 1) {
  1060. $where['sendNum'] = $name;
  1061. } else {
  1062. }
  1063. }
  1064. if (!empty($get['customId'])) {
  1065. $where['customId'] = (int)$get['customId'];
  1066. }
  1067. $customDistId = $get['customDistId'] ?? ($get['distId'] ?? 0);
  1068. if (!empty($customDistId)) {
  1069. $where['customDistId'] = (int)$customDistId;
  1070. }
  1071. $debt = isset($get['debt']) && is_numeric($get['debt']) ? (int)$get['debt'] : -1;
  1072. if ($debt > -1) {
  1073. $where['debt'] = $debt;
  1074. }
  1075. if (!empty($get['ids'])) {
  1076. $stringIds = $get['ids'];
  1077. $newIds = explode(',', $stringIds);
  1078. $where['id'] = ['in', $newIds];
  1079. }
  1080. //选择开单人
  1081. $shopAdminId = $get['shopAdminId'] ?? 0;
  1082. if (!empty($shopAdminId)) {
  1083. $where['shopAdminId'] = (int)$shopAdminId;
  1084. }
  1085. $onlinePay = $get['onlinePay'] ?? -1;
  1086. if ($onlinePay > -1) {
  1087. $where['onlinePay'] = $onlinePay;
  1088. }
  1089. $sendType = $get['sendType'] ?? -1;
  1090. if ($sendType > -1) {
  1091. $where['sendType'] = $sendType;
  1092. }
  1093. $respond = OrderClass::getOrderList($where);
  1094. if ($export == 1) {
  1095. OrderClass::exportOrderData($respond, $this->mainId);
  1096. }
  1097. $respond['shop'] = $this->shop;
  1098. $respond['shopExt'] = $this->shopExt;
  1099. util::success($respond);
  1100. }
  1101. //按片区排列的订单列表
  1102. public function actionListByDist()
  1103. {
  1104. $get = Yii::$app->request->get();
  1105. $where = [];
  1106. $where['o.mainId'] = $this->mainId;
  1107. $searchTime = $get['searchTime'] ?? '';
  1108. if (!empty($searchTime)) {
  1109. $startTime = $get['startTime'] ?? '';
  1110. $endTime = $get['endTime'] ?? '';
  1111. // 时间跨度不能超过7天
  1112. if (strtotime($endTime) - strtotime($startTime) > 7 * 24 * 3600) {
  1113. util::fail('最多查询7天的订单');
  1114. }
  1115. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  1116. $where['payTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1117. }
  1118. $respond = OrderClass::getDistOrderList($where);
  1119. util::success($respond);
  1120. }
  1121. // 新订单列表详情 -- 可能与 actionList 很相似,但为不影响 actionList,重新创建个方法 shizhongqi 2022.06.23
  1122. public function actionNewOrderList()
  1123. {
  1124. $get = Yii::$app->request->get();
  1125. $where['shopId'] = $this->shopId;
  1126. /*$status = $get['status'] ?? 0;
  1127. if (!empty($status)) {
  1128. $where['status'] = $status;
  1129. }*/
  1130. // 按类别生成查询条件:1.今日实收 2.今日欠款 3.总欠款(所有历史欠款)
  1131. if (isset($get['type'])) {
  1132. $type = $get['type'];
  1133. if ($type == 1) { // 今日实收
  1134. $get['searchTime'] = 'today';
  1135. $where['debt'] = 0;
  1136. $where['debtPrice'] = '0.00';
  1137. $where['status'] = ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]];
  1138. } elseif ($type == 2) { // 今日欠款
  1139. $get['searchTime'] = 'today';
  1140. $where['debt'] = 1;
  1141. } elseif ($type == 3) { // 总欠款
  1142. $where['debt'] = 1;
  1143. } else {
  1144. util::fail('查询的订单类别不存在');
  1145. }
  1146. }
  1147. $searchTime = $get['searchTime'] ?? '';
  1148. if (!empty($searchTime)) {
  1149. $startTime = '';
  1150. $endTime = '';
  1151. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  1152. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1153. }
  1154. $name = $get['name'] ?? '';
  1155. if (!empty($name)) {
  1156. $searchType = $get['searchType'] ?? 0;
  1157. if (empty($searchType)) {
  1158. //订单编号
  1159. if (strpos($name, 'XSD') === 0) {
  1160. $where['orderSn'] = $name;
  1161. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  1162. $where['customNamePy'] = ['like', $name];
  1163. } else {
  1164. $where['customName'] = ['like', $name];
  1165. }
  1166. } elseif ($searchType == 1) {
  1167. $where['sendNum'] = $name;
  1168. } else {
  1169. util::fail('搜索的订单类别不存在');
  1170. }
  1171. }
  1172. $respond = OrderClass::getOrderList($where);
  1173. $respond['shop'] = $this->shop;
  1174. $respond['shopExt'] = $this->shopExt;
  1175. $respond['type'] = $type; //把查询类别返回
  1176. util::success($respond);
  1177. }
  1178. //商城下单操作 ssh 2021.1.14
  1179. public function actionCreateOrder()
  1180. {
  1181. $post = Yii::$app->request->post();
  1182. $shopId = $this->shopId;
  1183. $customId = $post['customId'] ?? 0;
  1184. //开单必须选客户
  1185. if (empty($customId)) {
  1186. util::fail('请选择客户');
  1187. }
  1188. $modifyPrice = $post['modifyPrice'] ?? 0;
  1189. $pattern = '/^\d+(\.\d{1,2})?$/';
  1190. if ($modifyPrice > 0) {
  1191. if (!preg_match($pattern, $modifyPrice)) {
  1192. //容错前端
  1193. util::fail('金额不能超2位小数');
  1194. }
  1195. }
  1196. $custom = CustomClass::getCustom($customId);
  1197. if (empty($custom)) {
  1198. util::fail('请选客户哦');
  1199. }
  1200. $shopAdmin = $this->shopAdmin;
  1201. $shopAdminId = $this->shopAdminId;
  1202. $shopAdminName = $shopAdmin->name ?? '';
  1203. //解决开单提交订单时,别人修改价格,造成提交价格不是真实卖价问题!!
  1204. $dealPrice = $post['dealPrice'] ?? 0;
  1205. //解决重复提交:同店铺 + 同操作人 + 同客户 + 同成交价,短时间内只允许一次(防连点 / 双请求)
  1206. util::checkRepeatCommit($shopId . '_' . $this->adminId . '_' . $customId . '_' . $dealPrice, 3);
  1207. CustomClass::valid($custom, $this->shopId);
  1208. if (!empty($custom['mainId']) && $custom['mainId'] == $custom['ownMainId']) {
  1209. util::fail('不能给自己开单');
  1210. }
  1211. $post['ghsId'] = $custom['ghsId'] ?? 0;
  1212. $post['customMobile'] = $custom['mobile'] ?? '';
  1213. $customName = $custom['name'] ?? '';
  1214. $post['customName'] = $customName;
  1215. $post['customNamePy'] = $custom['py'] ?? '';
  1216. $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
  1217. $post['province'] = $custom['province'] ?? '';
  1218. $post['city'] = $custom['city'] ?? '';
  1219. $post['dist'] = $custom['dist'] ?? '';
  1220. $post['address'] = $custom['address'] ?? '';
  1221. $post['floor'] = $custom['floor'] ?? '';
  1222. $post['fullAddress'] = $custom['fullAddress'] ?? '';
  1223. $post['showAddress'] = $custom['showAddress'] ?? '';
  1224. $post['long'] = $custom['long'] ?? '';
  1225. $post['lat'] = $custom['lat'] ?? '';
  1226. if (!empty($post['getStaffId'])) {
  1227. if (getenv('YII_ENV') == 'production') {
  1228. $tbMainId = 44171;
  1229. } else {
  1230. $tbMainId = 0;
  1231. }
  1232. if ($this->mainId == $tbMainId) {
  1233. //平潭花天下,就算选了收款人,也不要给改变开单人,临时解决方案 ssh 2250314
  1234. if (!empty($post['shopAdminId'])) {
  1235. $getStaffName = $post['shopAdminName'] ?? '';
  1236. $shopAdminId = $post['shopAdminId'];
  1237. $shopAdminName = $getStaffName;
  1238. }
  1239. } else {
  1240. $getStaffName = $post['getStaffName'] ?? '';
  1241. $shopAdminId = $post['getStaffId'];
  1242. $shopAdminName = $getStaffName;
  1243. }
  1244. } else {
  1245. if (getenv('YII_ENV') == 'production') {
  1246. //鹏诚需要选择开单人
  1247. if (in_array($this->mainId, [19606])) {
  1248. util::fail('请选择开单人');
  1249. }
  1250. } else {
  1251. if (in_array($this->mainId, [])) {
  1252. util::fail('请选择开单人');
  1253. }
  1254. }
  1255. }
  1256. if (getenv('YII_ENV') == 'production') {
  1257. //小向花卉开单权限
  1258. if ($this->mainId == 23390) {
  1259. if (!in_array($this->adminId, [24043, 24585, 24586, 24654, 24115, 23960, 28456, 31105, 28456, 31105, 52528, 25011, 61449, 77951, 24655])) {
  1260. util::fail('你不能开单哦');
  1261. }
  1262. }
  1263. }
  1264. //开单人和收款人必定是同个人
  1265. $post['shopAdminId'] = $shopAdminId;
  1266. $post['shopAdminName'] = $shopAdminName;
  1267. $post['getStaffId'] = $shopAdminId;
  1268. $post['getStaffName'] = $shopAdminName;
  1269. if (getenv('YII_ENV') == 'production') {
  1270. //南粤选了别的开单人,也只能变成本人开单
  1271. if ($this->mainId == 22388) {
  1272. $post['shopAdminName'] = $shopAdmin->name;
  1273. $post['shopAdminId'] = $shopAdmin->id;
  1274. $post['getStaffId'] = $shopAdmin->id;
  1275. $post['getStaffName'] = $shopAdmin->name;
  1276. }
  1277. } else {
  1278. if ($this->mainId == 644) {
  1279. $post['shopAdminName'] = $shopAdmin->name;
  1280. $post['shopAdminId'] = $shopAdmin->id;
  1281. $post['getStaffId'] = $shopAdmin->id;
  1282. $post['getStaffName'] = $shopAdmin->name;
  1283. }
  1284. }
  1285. $post['sjId'] = $this->sjId;
  1286. $post['shopId'] = $shopId;
  1287. $post['mainId'] = $this->mainId;
  1288. $post['fromType'] = 1;
  1289. $post['expressId'] = $post['expressId'] ?? 0;
  1290. $book = $post['book'] ?? 0;
  1291. $post['book'] = $book;
  1292. $sendType = $post['sendType'] ?? 0;
  1293. $transType = $post['transType'] ?? 0;
  1294. $shop = $this->shop;
  1295. //过期不支持开单
  1296. $deadline = $shop->deadline;
  1297. $deadTime = strtotime($deadline);
  1298. $myCurrentTime = time();
  1299. $myCurrentDeadline = $deadTime;
  1300. if ($myCurrentTime > $myCurrentDeadline) {
  1301. util::fail('系统已到期,请续费哦');
  1302. }
  1303. if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
  1304. //昆明发往全国
  1305. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  1306. $post['sendCost'] = $sendCost;
  1307. $packCost = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  1308. $post['packCost'] = $packCost;
  1309. $post['transType'] = $transType;
  1310. $post['localOrder'] = 1;
  1311. } else {
  1312. //同步配送
  1313. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  1314. if ($sendType != dict::getDict('sendType', 'thirdSend') && $sendCost > 0) {
  1315. util::fail('填了运费,请选择跑腿');
  1316. }
  1317. $post['sendCost'] = $sendCost;
  1318. $post['packCost'] = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  1319. }
  1320. if ($book == 1) {
  1321. $bookSn = $shop->bookSn ?? 0;
  1322. if (empty($bookSn)) {
  1323. util::fail('请开启预订');
  1324. }
  1325. $post['bookSn'] = $bookSn;
  1326. }
  1327. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay'); //收款方式 0:扫码付 1:线下(已付款) 2:赊账(欠款)3:现金 4:余额
  1328. $post['debt'] = OrderClass::DEBT_NO;
  1329. if ($hasPay == dict::getDict('hasPay', 'debt')) {
  1330. $post['debt'] = OrderClass::DEBT_YES;
  1331. }
  1332. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  1333. if ($hasPay == dict::getDict('hasPay', 'payed')) {
  1334. //util::fail('没有权限');
  1335. }
  1336. }
  1337. if (getenv('YII_ENV') == 'production') {
  1338. if ($this->mainId == 1082) {
  1339. //泉城鲜花批发的出车,只能开收现金方式,多处要修改,关键词qc_cash
  1340. if ($hasPay != 0) {
  1341. util::fail('只能使用扫码付款,编号193');
  1342. }
  1343. }
  1344. //小齐鲜花出车,源花汇,不能使用线下收款
  1345. if ($this->mainId == 42680 || $this->mainId == 10536) {
  1346. if ($hasPay == 1) {
  1347. util::fail('线下收款暂时无法使用');
  1348. }
  1349. }
  1350. } else {
  1351. if ($this->mainId == 644) {
  1352. if ($hasPay == 1) {
  1353. //util::fail('线下收款暂时无法使用');
  1354. }
  1355. }
  1356. }
  1357. //多颜色数据整理
  1358. $colorItem = $post['xj'] ?? [];
  1359. $newXj = [];
  1360. if (!empty($colorItem)) {
  1361. $colorData = json_decode($colorItem, true);
  1362. if (!empty($colorData) && is_array($colorData)) {
  1363. foreach ($colorData as $colorInfo) {
  1364. $ptItemId = $colorInfo['ptItemId'] ?? 0;
  1365. $colorList = $colorInfo['list'] ?? [];
  1366. if (!empty($colorList)) {
  1367. foreach ($colorList as $colorItemKey => $colorItem) {
  1368. $newXj[$ptItemId][] = $colorItem;
  1369. }
  1370. }
  1371. }
  1372. }
  1373. }
  1374. $post['xj'] = $newXj;
  1375. $treeData = $post['treeData'] ?? [];
  1376. $newTree = [];
  1377. if (!empty($treeData)) {
  1378. $treeArr = json_decode($treeData, true);
  1379. if (!empty($treeArr) && is_array($treeArr)) {
  1380. foreach ($treeArr as $treeInfo) {
  1381. $ptItemId = $treeInfo['ptItemId'] ?? 0;
  1382. $treeList = $treeInfo['list'] ?? [];
  1383. if (!empty($treeList)) {
  1384. foreach ($treeList as $treeItem) {
  1385. $newTree[$ptItemId][] = $treeItem;
  1386. }
  1387. }
  1388. }
  1389. }
  1390. }
  1391. $post['treeData'] = $newTree;
  1392. $productJson = $post['product'] ?? '';
  1393. if (empty($productJson)) {
  1394. //直接收款
  1395. $zjGathering = $post['zjGathering'] ?? 0;
  1396. if ($zjGathering == 1) {
  1397. $gatheringPrice = $post['gatheringPrice'] ?? 0;
  1398. if (!is_numeric($gatheringPrice) || $gatheringPrice <= 0) {
  1399. util::fail('请填写价格');
  1400. }
  1401. //直接收款不需要打印小票
  1402. $post['needPrint'] = 2;
  1403. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  1404. $zjGatheringItem = !empty($ext) ? $ext->zjGatheringItem : 0;
  1405. if (empty($zjGatheringItem)) {
  1406. util::fail('请设置收款的商品');
  1407. }
  1408. $zjGatheringItemInfo = ProductClass::getById($zjGatheringItem, true);
  1409. if (empty($zjGatheringItemInfo)) {
  1410. util::fail('请设置收款的商品呢');
  1411. }
  1412. $zjPtItemId = $zjGatheringItemInfo->itemId ?? 0;
  1413. $productList = [['productId' => $zjGatheringItem, 'itemId' => $zjPtItemId, 'bigNum' => 1, 'smallNum' => 0, 'classId' => 0, 'price' => $gatheringPrice]];
  1414. }
  1415. } else {
  1416. $productList = json_decode($productJson, true);
  1417. }
  1418. if (empty($productList)) {
  1419. util::fail('请选择花材');
  1420. }
  1421. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  1422. $itemInfo = ProductClass::getByIds($ids, null, 'id');
  1423. if (empty($itemInfo)) {
  1424. util::fail('请选择花材哦');
  1425. }
  1426. //判断花材有效性
  1427. foreach ($itemInfo as $itemData) {
  1428. if (!isset($itemData['mainId']) || $itemData['mainId'] != $this->mainId) {
  1429. util::fail('只能选一家的商品哈,请清空重选');
  1430. }
  1431. }
  1432. $diff = [];
  1433. $priceMap = CustomClass::$levelPriceKeyMap;
  1434. //这个参数应该是要作废的,但下面加的参数是有用的,多处要同步修改,关键词 abandon_add_price_map ,ssh 20260116
  1435. $addPriceMap = CustomClass::$levelAddPriceKeyMap;
  1436. //但这边加的参数是有用的,给指定客户涨价的
  1437. $addPriceMap['risePercent'] = $custom['risePercent'] ?? 0;
  1438. $level = $custom['level'] ?? 1;
  1439. $skipLimitBuy = !empty($shop->skCustomId) && intval($shop->skCustomId) == intval($customId);
  1440. $limitBuyCheckList = [];
  1441. foreach ($productList as $currentProduct) {
  1442. $limitBuyCheckList[] = [
  1443. 'id' => $currentProduct['productId'] ?? 0,
  1444. 'bigCount' => $currentProduct['bigNum'] ?? 0,
  1445. 'smallCount' => $currentProduct['smallNum'] ?? 0,
  1446. ];
  1447. }
  1448. $limitBuyInfoList = ProductClass::getLimitBuyInfoByList($limitBuyCheckList, $customId);
  1449. $limitBuyInfoMap = array_column($limitBuyInfoList, null, 'id');
  1450. foreach ($productList as $ptKey => $currentProduct) {
  1451. $currentPrice = $currentProduct['price'] ?? 0;
  1452. $currentId = $currentProduct['productId'] ?? 0;
  1453. $systemInfo = $itemInfo[$currentId] ?? [];
  1454. $name = $systemInfo['name'] ?? '';
  1455. $limitBuyInfo = $limitBuyInfoMap[$currentId] ?? [];
  1456. $buyNum = $skipLimitBuy ? 0 : ($limitBuyInfo['currentBuyNum'] ?? 0);
  1457. $hasBuyNum = $skipLimitBuy ? 0 : ($limitBuyInfo['hasBuyNum'] ?? 0);
  1458. $totalBuyNum = $skipLimitBuy ? 0 : bcadd($hasBuyNum, $buyNum, 2);
  1459. $systemPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap, 0, $buyNum, $totalBuyNum);
  1460. if (getenv('YII_ENV') == 'production') {
  1461. //苏州小蔡鲜花,几个出车,不能低于原价卖,但可以高于原价卖的
  1462. if (in_array($shopId, [38231, 38143, 29163, 29161])) {
  1463. if ($currentPrice < $systemPrice) {
  1464. util::fail('不能低于原价卖');
  1465. }
  1466. }
  1467. } else {
  1468. if (in_array($shopId, [36544])) {
  1469. if ($currentPrice < $systemPrice) {
  1470. util::fail('不能低于原价卖');
  1471. }
  1472. }
  1473. }
  1474. //后端开单,涉及花材满减,关键词 back_order_reach_discount_price
  1475. $post['reachDiscountPrice'] = 0;
  1476. if (floatval($currentPrice) != floatval($systemPrice)) {
  1477. $diff[] = [
  1478. 'name' => $name,
  1479. 'price' => $systemPrice,
  1480. 'kdPrice' => $currentPrice,
  1481. ];
  1482. } else {
  1483. //后端开单,如果没有改价格,并且数量达到花材满减要求,则自动给减价格,关键词 back_order_reach_discount_price
  1484. $bigNum = $currentProduct['bigNum'] ?? 0;
  1485. $reachNum = $systemInfo['reachNum'] ?? 0;
  1486. if ($reachNum > 0 && $bigNum >= $reachNum) {
  1487. $reachNumDiscount = $systemInfo['reachNumDiscount'] ?? 0;
  1488. $unitPrice = $currentProduct['price'] ?? 0;
  1489. if ($unitPrice > $reachNumDiscount) {
  1490. $newUnitPrice = bcsub($unitPrice, $reachNumDiscount, 2);
  1491. $calcPrice = bcmul($reachNumDiscount, $bigNum, 2);
  1492. if ($calcPrice > 0 && isset($post['modifyPrice']) && $post['modifyPrice'] > $calcPrice) {
  1493. $productList[$ptKey]['price'] = $newUnitPrice;
  1494. //提交给后端的总金额也要减掉,否则会有问题
  1495. $post['modifyPrice'] = bcsub($post['modifyPrice'], $calcPrice, 2);
  1496. $post['reachDiscountPrice'] = bcadd($post['reachDiscountPrice'], $calcPrice, 2);
  1497. }
  1498. }
  1499. }
  1500. }
  1501. }
  1502. //解决开单提交订单时,别人修改价格,造成提交价格不是真实卖价问题!!
  1503. if ($dealPrice == 0) {
  1504. if (!empty($diff)) {
  1505. util::success(['diff' => $diff, 'respondType' => 'priceError']);
  1506. }
  1507. } else {
  1508. if (!empty($diff)) {
  1509. $mainId = $this->mainId;
  1510. //花样年华,除了老板,只能按原价开单,不能改价格
  1511. if (getenv('YII_ENV') == 'production') {
  1512. if (in_array($mainId, [1553, 1563])) {
  1513. if ($this->adminId != 2876) {
  1514. util::fail('请按花材原价格开单');
  1515. }
  1516. }
  1517. } else {
  1518. if (in_array($mainId, [0, 1])) {
  1519. util::fail('请按花材原价格开单');
  1520. }
  1521. }
  1522. }
  1523. }
  1524. if ($book == 1) {
  1525. $post['hasPay'] = 2;
  1526. $post['payWay'] = 0;
  1527. }
  1528. $historyDate = $post['historyDate'] ?? '';
  1529. if (!empty($historyDate)) {
  1530. if ($book == 1) {
  1531. util::fail('预订单不能选订单日期');
  1532. }
  1533. if ($hasPay == 0) {
  1534. util::fail('扫码付不能选订单日期');
  1535. }
  1536. }
  1537. $callErrand = $post['callErrand'] ?? 0;
  1538. if ($callErrand == 1) {
  1539. $shopExt = $this->shopExt;
  1540. if ($shopExt->orderFlow == 0) {
  1541. util::fail('下单后要变待发货,才能直接发跑腿');
  1542. }
  1543. }
  1544. $post['product'] = $productList;
  1545. //商家开单到时间会自动标记为欠款,所以360天内不过期,以保证足够时间标记欠款,具体参数查看dict local_gys_kd_auto_set_debt_time
  1546. $time = time();
  1547. $hasTime = dict::getDict('order_pay_has_time');
  1548. $totalTime = bcadd($time, $hasTime);
  1549. $post['deadline'] = date("Y-m-d H:i:s", $totalTime);
  1550. $connection = Yii::$app->db;
  1551. try {
  1552. // 复杂分支/关键逻辑:优化。去除了并发重试机制 runWithDbConcurrencyRetry,降低锁等待和额外重试带来的性能瓶颈
  1553. // 底层在发货和收货扣减库存时,使用商品 ID 升序排序加锁(SELECT FOR UPDATE)策略,100% 杜绝交叉死锁,因此这里无需再做重试。
  1554. $transaction = $connection->beginTransaction();
  1555. try {
  1556. $return = OrderService::createNewOrder($post, $custom, $hasPay);
  1557. $transaction->commit();
  1558. ProductClass::clearLimitBuyRollbackSnapshot();
  1559. } catch (\Exception $exception) {
  1560. if ($transaction->isActive) {
  1561. $transaction->rollBack();
  1562. }
  1563. throw $exception;
  1564. }
  1565. // 复杂分支/关键逻辑:优化。直接将创建成功的 $return 赋值给 $order,避免重复 SELECT 销售单
  1566. $order = $return;
  1567. if (!empty($order)) {
  1568. //订单发跑腿流程
  1569. GhsDeliveryOrderClass::prepareAskData($post, $order);
  1570. $saleId = $order->id ?? 0;
  1571. $shopId = $order->shopId ?? 0;
  1572. $customId = $order->customId ?? 0;
  1573. $ghsId = $order->ghsId ?? 0;
  1574. $date = date("Y-m-d H:i:s");
  1575. // 复杂分支/关键逻辑:优化。使用 updateByCondition 直接更新最后下单时间,避免先 SELECT 再 UPDATE 的性能开销
  1576. if ($customId > 0) {
  1577. CustomClass::updateByCondition(['id' => $customId], ['recentExpend' => $date]);
  1578. }
  1579. if ($ghsId > 0) {
  1580. GhsClass::updateByCondition(['id' => $ghsId], ['recentExpend' => $date]);
  1581. }
  1582. $shop = ShopClass::getById($shopId, true);
  1583. if (isset($order->payStatus) && $order->payStatus == 1) {
  1584. if (!empty($shop)) {
  1585. GhsNotifyClass::newOrderNotify($saleId);
  1586. HdNotifyClass::newCgNotify($order->purchaseId);
  1587. }
  1588. }
  1589. //订单生成时唤起在线打印
  1590. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1591. //预订单开单不打小票,小向花卉不需要打小票
  1592. $mainId = $order->mainId ?? 0;
  1593. if ($order->book == 0 && !in_array($mainId, [23390])) {
  1594. if ($order->status != 1 && $order->status != 5) {
  1595. OrderClass::onlinePrint($order);
  1596. $ext = $this->shopExt;
  1597. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1598. $order->printNum += 1;
  1599. $order->save();
  1600. }
  1601. //花镜 自己开单要打二次,有多处要修改搜索关键词 tow_print
  1602. if (in_array($mainId, [76796])) {
  1603. OrderClass::onlinePrint($order);
  1604. $ext = $this->shopExt;
  1605. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1606. $order->printNum += 1;
  1607. $order->save();
  1608. }
  1609. }
  1610. }
  1611. }
  1612. }
  1613. //前台提醒出示付款码
  1614. if (isset($order->status) && $order->status == 1) {
  1615. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  1616. ShopExtClass::ghsPleasePayReport($order);
  1617. }
  1618. }
  1619. }
  1620. util::success($return);
  1621. } catch (\Exception $e) {
  1622. ProductClass::rollbackLimitBuySnapshot();
  1623. Yii::error("下单失败原因:" . $e->getMessage());
  1624. noticeUtil::push("批发线下开单失败,原因:" . $e->getMessage(), '15280215347');
  1625. if (util::isDbConcurrencyException($e)) {
  1626. util::fail('系统繁忙中,请稍后再试');
  1627. } else {
  1628. util::fail('下单失败');
  1629. }
  1630. }
  1631. }
  1632. /**
  1633. * 创建冲销单(金额为负的独立订单)ssh 冲销单功能
  1634. * 独立通道,不复用常规开单主链路(actionCreateOrder->createNewOrder),避免误伤现网正常开单流程。
  1635. * 支持两种入口:
  1636. * 1. 从 selectCustom(forward=1) 自由开单:不传 relateOrderId,不关联具体原订单。
  1637. * 2. 从售后 refund.vue 转入(原订单非当天/欠款已结清):传 relateOrderId,做累计冲销上限校验,
  1638. * 并强制按原订单实际支付方式覆盖 payWay(不信任前端传值)。
  1639. * 资金处理方式(originalRefund/returnBalance)也按原单支付渠道在 OrderService::createForwardOrder 内强制/校验,
  1640. * 不完全信任前端传值:挂账/余额支付强制返充余额;线上支付(微信/支付宝)可二选一原路退回或返充余额。
  1641. */
  1642. public function actionCreateForwardOrder()
  1643. {
  1644. $post = Yii::$app->request->post();
  1645. $customId = $post['customId'] ?? 0;
  1646. if (empty($customId)) {
  1647. util::fail('请选择客户');
  1648. }
  1649. $custom = CustomClass::getCustom($customId);
  1650. if (empty($custom)) {
  1651. util::fail('请选客户哦');
  1652. }
  1653. CustomClass::valid($custom, $this->shopId);
  1654. $shopAdmin = $this->shopAdmin;
  1655. $shopAdminId = $this->shopAdminId;
  1656. $shopAdminName = $shopAdmin->name ?? '';
  1657. //售后转冲销单场景(带relateOrderId/refundOrderId)本质是在做"售后退款审批",
  1658. //权限口径与老的 /refund/create-order、/refund/pass 保持一致,只有超管能操作;
  1659. //不带这两个参数的是"直接开冲销单"(selectCustom->index2->affirmForward),维持原有权限不变。ssh 冲销单功能
  1660. if (!empty($post['relateOrderId']) || !empty($post['refundOrderId'])) {
  1661. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1662. util::fail('超管才能操作退款');
  1663. }
  1664. }
  1665. //防止连点/重复提交
  1666. util::checkRepeatCommit('forward_' . $this->shopId . '_' . $this->adminId . '_' . $customId, 3);
  1667. //refundOrderId 场景由 OrderService::createForwardOrder 内部按售后申请明细自动生成商品列表,
  1668. //不需要前端再传product(也不信任前端在这个场景下传的商品,避免和售后申请不一致)
  1669. if (empty($post['refundOrderId'])) {
  1670. $productJson = $post['product'] ?? '';
  1671. $productList = is_string($productJson) ? json_decode($productJson, true) : $productJson;
  1672. if (empty($productList)) {
  1673. util::fail('请选择花材');
  1674. }
  1675. $post['product'] = $productList;
  1676. }
  1677. $post['sjId'] = $this->sjId;
  1678. $post['shopId'] = $this->shopId;
  1679. $post['mainId'] = $this->mainId;
  1680. $post['shopAdminId'] = $shopAdminId;
  1681. $post['shopAdminName'] = $shopAdminName;
  1682. $connection = Yii::$app->db;
  1683. $transaction = $connection->beginTransaction();
  1684. try {
  1685. $result = OrderService::createForwardOrder($post, $custom);
  1686. $transaction->commit();
  1687. } catch (\Exception $exception) {
  1688. if ($transaction->isActive) {
  1689. $transaction->rollBack();
  1690. }
  1691. Yii::error('冲销单创建失败原因:' . $exception->getMessage());
  1692. if (util::isDbConcurrencyException($exception)) {
  1693. util::fail('系统繁忙中,请稍后再试');
  1694. }
  1695. throw $exception;
  1696. }
  1697. $order = $result['order'];
  1698. util::success([
  1699. 'id' => $order->id,
  1700. 'orderSn' => $order->orderSn,
  1701. 'actPrice' => $order->actPrice,
  1702. 'customName' => $order->customName,
  1703. 'customBalance' => $result['customBalance'],
  1704. 'thirdRefundNo' => $result['thirdRefundNo'] ?? '',
  1705. ]);
  1706. }
  1707. //按原销售单查询关联的冲销记录(供售后记录页“冲销记录”展示)ssh 冲销单功能
  1708. public function actionGetForwardListByOrder()
  1709. {
  1710. $get = Yii::$app->request->get();
  1711. $orderSn = $get['orderSn'] ?? '';
  1712. if (empty($orderSn)) {
  1713. util::fail('缺少订单号');
  1714. }
  1715. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  1716. if (empty($order)) {
  1717. util::fail('没有找到订单');
  1718. }
  1719. if ($order->mainId != $this->mainId) {
  1720. util::fail('无权查看');
  1721. }
  1722. $list = OrderForwardClass::getByOrderId($order->id);
  1723. if (empty($list)) {
  1724. util::success(['list' => []]);
  1725. }
  1726. $forwardOrderIds = array_unique(array_filter(array_column($list, 'forwardOrderId')));
  1727. $forwardOrderInfo = empty($forwardOrderIds) ? [] : OrderClass::getByIds($forwardOrderIds, null, 'id');
  1728. $data = [];
  1729. foreach ($list as $row) {
  1730. $forwardOrder = $forwardOrderInfo[$row['forwardOrderId']] ?? [];
  1731. $data[] = [
  1732. 'forwardOrderId' => $row['forwardOrderId'],
  1733. 'forwardOrderSn' => $row['forwardOrderSn'],
  1734. 'forwardPrice' => $row['forwardPrice'],
  1735. 'addTime' => $row['addTime'],
  1736. 'shopAdminName' => $forwardOrder['shopAdminName'] ?? '',
  1737. 'forwardStock' => $forwardOrder['forwardStock'] ?? 1,
  1738. ];
  1739. }
  1740. util::success(['list' => $data]);
  1741. }
  1742. //修改订单 ssh 20210810
  1743. public function actionUpdateOrder()
  1744. {
  1745. $post = Yii::$app->request->post();
  1746. util::fail('订单不可修改');
  1747. //PC端开单
  1748. if (isset($post['clearType'])) {
  1749. $clearType = $post['clearType'];
  1750. if ($clearType == OrderClass::CLEAR_DEBT) {
  1751. $post['debt'] = OrderClass::DEBT_YES;
  1752. $post['payWay'] = dict::getDict('payWay', 'debtPay');
  1753. } else {
  1754. $post['debt'] = OrderClass::DEBT_NO;
  1755. }
  1756. }
  1757. //员工不能开已收款订单
  1758. $debt = $post['debt'] ?? OrderClass::DEBT_YES;
  1759. if ($debt == OrderClass::DEBT_NO) {
  1760. $shopAdmin = $this->shopAdmin;
  1761. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1762. util::fail('不能开已收款订单');
  1763. }
  1764. }
  1765. //PC端开单
  1766. if (isset($post['getType'])) {
  1767. util::fail('暂不支持PC端修改订单');
  1768. $getType = $post['getType'];
  1769. //自取
  1770. if ($getType == 1) {
  1771. $post['sendType'] = OrderClass::SEND_TYPE_NO;
  1772. } else {
  1773. //选择配送时,在发货时让商家自己再确认一下用什么方式
  1774. $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN;
  1775. }
  1776. }
  1777. //商家开非自取订单,默认订单是待收款的,debt字段为非欠款
  1778. if (isset($post['sendType']) && $post['sendType'] != OrderClass::SEND_TYPE_NO) {
  1779. $post['debt'] = OrderClass::DEBT_NO;
  1780. }
  1781. $id = $post['id'] ?? 0;
  1782. $order = OrderClass::getLockById($id);
  1783. if (empty($order)) {
  1784. util::fail('没有找到订单');
  1785. }
  1786. OrderClass::valid($order, $this->shopId);
  1787. unset($post['id']);
  1788. $shopAdmin = $this->shopAdmin;
  1789. $post['shopAdminId'] = $this->shopAdminId;
  1790. $post['shopAdminName'] = $shopAdmin->name ?? '';
  1791. $post['fromType'] = 1;
  1792. $post['sendCost'] = $post['sendCost'] ?? '0.00';
  1793. $productJson = $post['product'] ?? '';
  1794. if (empty($productJson)) {
  1795. util::fail('请选择花材');
  1796. }
  1797. $productList = json_decode($productJson, true);
  1798. if (empty($productList)) {
  1799. util::fail('请选择花材');
  1800. }
  1801. $connection = Yii::$app->db;
  1802. $transaction = $connection->beginTransaction();
  1803. try {
  1804. //判断花材有效性
  1805. ProductClass::valid($productList, $this->mainId);
  1806. $post['product'] = $productList;
  1807. //商家开单订单有效期,到期记欠款
  1808. $validTime = dict::getDict('order_pay_has_time');
  1809. $current = time() + $validTime;
  1810. $post['deadline'] = date("Y-m-d H:i:s", $current);
  1811. $upData = [
  1812. 'payWay' => $post['payWay'],
  1813. 'sendType' => $post['sendType'],
  1814. 'debt' => $post['debt'],
  1815. 'needPrint' => $post['needPrint'],
  1816. 'modifyPrice' => $post['modifyPrice'],
  1817. 'shopAdminId' => $post['shopAdminId'],
  1818. 'shopAdminName' => $post['shopAdminName'],
  1819. 'fromType' => 1,
  1820. 'sendCost' => $post['sendCost'],
  1821. 'product' => $post['product'],
  1822. 'deadline' => $post['deadline'],
  1823. 'debt' => $post['debt'],
  1824. ];
  1825. $return = OrderService::updateOrder($order, $upData);
  1826. $transaction->commit();
  1827. util::success($return);
  1828. } catch (\Exception $e) {
  1829. $transaction->rollBack();
  1830. Yii::error("下单失败原因:" . $e->getMessage());
  1831. util::fail('下单失败');
  1832. }
  1833. }
  1834. //取消预订单 ssh 20240503
  1835. public function actionCancelBookOrder()
  1836. {
  1837. $get = Yii::$app->request->get();
  1838. $id = $get['id'] ?? 0;
  1839. if (empty($id)) {
  1840. util::fail('请选择订单');
  1841. }
  1842. $order = OrderClass::getById($id, true);
  1843. if (empty($order)) {
  1844. util::fail('没有找到订单');
  1845. }
  1846. OrderClass::valid($order, $this->shopId);
  1847. if ($order->book == 0) {
  1848. util::fail('不是预订单');
  1849. }
  1850. if ($order->status != 2) {
  1851. util::fail('当前订单状态不能取消');
  1852. }
  1853. $purchaseId = $order->purchaseId ?? 0;
  1854. $purchase = PurchaseClass::getById($purchaseId, true);
  1855. if (empty($purchase)) {
  1856. util::fail('没有找到采购单');
  1857. }
  1858. $connection = Yii::$app->db;
  1859. $transaction = $connection->beginTransaction();
  1860. try {
  1861. $order->status = 5;
  1862. $order->save();
  1863. $purchase->status = 5;
  1864. $purchase->save();
  1865. $transaction->commit();
  1866. util::complete('取消成功');
  1867. } catch (\Exception $e) {
  1868. $transaction->rollBack();
  1869. $msg = $e->getMessage();
  1870. $orderSn = $order->orderSn ?? '';
  1871. noticeUtil::push("预订单{$orderSn}取消失败:{$msg}", '15280215347');
  1872. }
  1873. }
  1874. //取消订单 shizhongqi 20220619
  1875. public function actionCancelOrder()
  1876. {
  1877. $post = Yii::$app->request->post();
  1878. $id = $post['orderId'] ?? 0;
  1879. if (empty($id)) {
  1880. util::fail('请选择订单');
  1881. }
  1882. $order = OrderClass::getById($id, true);
  1883. if (empty($order)) {
  1884. util::fail('请选择订单...');
  1885. }
  1886. OrderClass::valid($order, $this->shopId);
  1887. if (isset($order->status) == false || $order->status != 1) {
  1888. util::fail('不是待付款状态,无法取消');
  1889. }
  1890. $purchaseId = $order->purchaseId ?? 0;
  1891. $purchase = PurchaseClass::getById($purchaseId);
  1892. if (empty($purchase)) {
  1893. util::fail('没有找到采购单');
  1894. }
  1895. $deadLineTime = strtotime($purchase['deadline']);
  1896. $diff = $deadLineTime - time();
  1897. if ($diff <= 60) {
  1898. util::fail('1分钟后订单将自动取消');
  1899. }
  1900. $connection = Yii::$app->db;
  1901. $transaction = $connection->beginTransaction();
  1902. $orderSn = $purchase['orderSn'];
  1903. try {
  1904. $current = PurchaseClass::getById($purchaseId, true);
  1905. PurchaseService::expire($current);
  1906. $transaction->commit();
  1907. //noticeUtil::push("采购单过期未付款,库存已回滚,单号:{$orderSn}");
  1908. } catch (\Exception $e) {
  1909. $transaction->rollBack();
  1910. $msg = $e->getMessage();
  1911. noticeUtil::push("采购单过期处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
  1912. }
  1913. util::complete();
  1914. }
  1915. //延期支付 ssh 2021.1.19
  1916. public function actionDebt()
  1917. {
  1918. $id = Yii::$app->request->get('id');
  1919. //4秒内不允许重复提交
  1920. $cacheKey = 'ghs_set_order_debt_' . $id;
  1921. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  1922. if (!empty($has)) {
  1923. util::fail('请稍等');
  1924. }
  1925. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
  1926. if (getenv('YII_ENV') == 'production') {
  1927. if ($this->mainId == 1082) {
  1928. //泉城鲜花批发的出车,只能开收现金方式,多处要修改,关键词qc_cash
  1929. util::fail('只能使用扫码付款,编号293');
  1930. }
  1931. } else {
  1932. }
  1933. $order = OrderClass::getById($id, true);
  1934. OrderClass::valid($order, $this->shopId);
  1935. $payWay = dict::getDict('payWay', 'debtPay');
  1936. $cgId = $order->purchaseId ?? 0;
  1937. $cg = PurchaseClass::getById($cgId, true);
  1938. if (empty($cg)) {
  1939. util::fail('没有找到采购单');
  1940. }
  1941. if ($order->book == 1) {
  1942. util::fail('预订单不能记欠款');
  1943. }
  1944. $connection = Yii::$app->db;
  1945. $transaction = $connection->beginTransaction();
  1946. try {
  1947. PurchaseService::payAfter($cg, $payWay);
  1948. OrderService::payAfter($order, $payWay);
  1949. $transaction->commit();
  1950. } catch (\Exception $exception) {
  1951. $transaction->rollBack();
  1952. Yii::info("延期支付报错:" . $exception->getMessage());
  1953. util::fail('操作失败');
  1954. }
  1955. $order = OrderClass::getById($id, true);
  1956. if (!empty($order)) {
  1957. $shopId = $order->shopId ?? 0;
  1958. $shop = ShopClass::getById($shopId, true);
  1959. if (!empty($shop)) {
  1960. //花店采购供货商端微信收到通知
  1961. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  1962. $noticeText = json_encode(['orderId' => $id]);
  1963. $noticeKey = "hdCgNoticeGhs";
  1964. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1965. }
  1966. //订单生成时唤起在线打印
  1967. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1968. if ($order->status != 1 && $order->status != 5) {
  1969. OrderClass::onlinePrint($order);
  1970. $ext = $this->shopExt;
  1971. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1972. $order->printNum += 1;
  1973. $order->save();
  1974. }
  1975. }
  1976. }
  1977. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  1978. GhsDeliveryOrderClass::payAfter($order);
  1979. if ($order->status != 1 && $order->status != 5) {
  1980. //花店采购供货商端APP收到通知
  1981. //NoticeClass::ghsNewOrderNotice($order);
  1982. //向供货商APP发通知
  1983. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  1984. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  1985. // $push->ghsOrderMessage($shop, $cgShop, $order);
  1986. }
  1987. }
  1988. util::complete();
  1989. }
  1990. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  1991. public function actionWxPay()
  1992. {
  1993. ini_set('date.timezone', 'Asia/Shanghai');
  1994. $post = Yii::$app->request->post();
  1995. $couponId = $post['couponId'] ?? 0;
  1996. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  1997. $order = OrderClass::getByOrderSn($orderSn);
  1998. if (empty($order)) {
  1999. util::fail('订单号无效');
  2000. }
  2001. $id = $order['id'];
  2002. //支付前验证订单有效性
  2003. if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
  2004. util::fail('无法操作');
  2005. }
  2006. $name = $order['orderName'] ?? '购买商品';
  2007. $totalFee = $order['actPrice'];
  2008. //强制使用小程序的miniOpenId
  2009. $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
  2010. if (empty($openId)) {
  2011. util::fail('没有找到openId');
  2012. }
  2013. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  2014. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  2015. $wxPayType = 0;
  2016. if (httpUtil::isMiniProgram()) {
  2017. $wxPayType = 1;
  2018. }
  2019. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  2020. //订单30分钟后过期
  2021. $now = time();
  2022. $expireTime = $now + 1800;
  2023. $wx = Yii::getAlias("@vendor/weixin");
  2024. require_once($wx . '/lib/WxPay.Api.php');
  2025. require_once($wx . '/example/WxPay.JsApiPay.php');
  2026. $input = new \WxPayUnifiedOrder();
  2027. $input->SetBody($name);
  2028. $input->SetOut_trade_no($orderSn);
  2029. $input->SetTotal_fee($totalFee * 100);
  2030. $input->SetTime_start(date("YmdHis", $now));
  2031. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  2032. $input->SetTime_expire(date("YmdHis", $expireTime));
  2033. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  2034. $input->SetTrade_type("JSAPI");
  2035. //花卉宝代为申请的微信支付
  2036. //$sjExtend = $this->sjExtend->attributes;
  2037. $sjExtend = WxOpenClass::getGhsWxInfo();
  2038. if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
  2039. $input->SetSub_openid($openId);
  2040. } else {
  2041. $input->SetOpenid($openId);
  2042. }
  2043. //强制使用小程序的miniAppId
  2044. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  2045. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  2046. $tools = new \JsApiPay();
  2047. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  2048. $newParams = json_decode($jsApiParameters, true);
  2049. //微信不能修改价格
  2050. $current = date("Y-m-d H:i:s");
  2051. $updateData = ['deadline' => $current, 'modPrice' => 0];
  2052. OrderClass::updateById($id, $updateData);
  2053. util::success($newParams);
  2054. }
  2055. //获取订单详情 ssh 2021.1.21
  2056. public function actionDetail()
  2057. {
  2058. $get = Yii::$app->request->get();
  2059. $id = $get['id'] ?? 0;
  2060. $info = OrderService::getOrderInfo($id, true, true, true, false);
  2061. OrderClass::valid($info, $this->shopId);
  2062. //A4打印需要用到的数据
  2063. $customId = $info['customId'] ?? 0;
  2064. $remark = $info['remark'] ?? '';
  2065. $sendCost = $info['sendCost'] ?? 0;
  2066. $sendNum = $info['sendNum'] ?? '';
  2067. $packCost = $info['packCost'] ?? 0;
  2068. $staffName = $info['shopAdminName'] ?? '';
  2069. $ysName = '';
  2070. if (isset($info['localOrder']) && $info['localOrder'] == 1) {
  2071. if ($info['transType'] == 0) {
  2072. $ysName = '德邦空运';
  2073. }
  2074. if ($info['transType'] == 1) {
  2075. $ysName = '顺丰空运';
  2076. }
  2077. if ($info['transType'] == 2) {
  2078. $ysName = '冷链物流';
  2079. }
  2080. if ($info['transType'] == 3) {
  2081. $ysName = '航空物流';
  2082. }
  2083. if ($info['transType'] == 4) {
  2084. $ysName = '同城配送';
  2085. }
  2086. if ($info['transType'] == 5) {
  2087. $ysName = '到店自取';
  2088. }
  2089. } else {
  2090. $sendType = $info['sendType'] ?? 0;
  2091. $ysName = '送货上门';
  2092. if ($sendType == 1) {
  2093. $ysName = '到店自取';
  2094. }
  2095. if ($sendType == 2) {
  2096. $ysName = '发跑腿';
  2097. }
  2098. if ($sendType == 3) {
  2099. $wlName = $info['wlName'] ?? '';
  2100. $ysName = '发物流';
  2101. if (!empty($wlName)) {
  2102. $ysName = $ysName . '-' . $wlName;
  2103. }
  2104. }
  2105. }
  2106. $fullAddress = '';
  2107. if (getenv('YII_ENV') == 'production') {
  2108. //老油的要显示地址
  2109. if ($this->mainId == 20528) {
  2110. $fullAddress = $info['fullAddress'] ?? '';
  2111. }
  2112. } else {
  2113. if ($this->mainId == 644) {
  2114. $fullAddress = $info['fullAddress'] ?? '';
  2115. }
  2116. }
  2117. $custom = CustomClass::getById($customId, true);
  2118. if (empty($custom)) {
  2119. util::fail('没有找到客户');
  2120. }
  2121. $customName = $custom->name ?? '';
  2122. $customMobile = $custom->customMobile ?? '';
  2123. if (empty($customMobile)) {
  2124. $customShopId = $custom->shopId ?? 0;
  2125. $customShop = ShopClass::getById($customShopId, true);
  2126. if (!empty($customShop)) {
  2127. $customMobile = $customShop->mobile ?? '';
  2128. }
  2129. }
  2130. if (!empty($customMobile)) {
  2131. $customMobile = substr_replace($customMobile, '****', 3, 4);
  2132. }
  2133. $fullCustom = $customName . ' ' . $customMobile;
  2134. if ($this->mainId == 8164) {
  2135. //花大苪不显示客户名称
  2136. $fullCustom = '';
  2137. }
  2138. $seatSn = isset($custom->seatSn) && !empty($custom->seatSn) ? $custom->seatSn : '无';
  2139. $sendTimeWant = $info['sendTimeWant'] ?? '';
  2140. $shortSendTimeWant = !empty($sendTimeWant) ? substr($sendTimeWant, 5, 5) : '';
  2141. $totalItemNum = 0;
  2142. $totalSmallItemNum = 0;
  2143. $table = [];
  2144. if (isset($info['product']) && !empty($info['product'])) {
  2145. foreach ($info['product'] as $key => $val) {
  2146. $currentName = $val['name'] ?? '';
  2147. $num = $val['xhNum'] ?? 0;
  2148. $refundNum = $val['refundNum'] ?? 0;
  2149. $num = bcsub($num, $refundNum);
  2150. $totalItemNum = bcadd($totalItemNum, $num);
  2151. $ratio = $val['ratio'] ?? 0;
  2152. $currentSmallNum = bcmul($num, $ratio);
  2153. $totalSmallItemNum = bcadd($totalSmallItemNum, $currentSmallNum);
  2154. $itemRemark = $val['remark'] ?? '';
  2155. $unitPrice = $val['xhUnitPrice'] ?? 0;
  2156. $unitPrice = floatval($unitPrice);
  2157. $price = bcmul($unitPrice, $num, 2);
  2158. $price = floatval($price);
  2159. $table[] = [
  2160. 'name' => $currentName,
  2161. 'num' => $num,
  2162. 'confirmNum' => '',
  2163. 'remark' => $itemRemark,
  2164. 'wxNumber' => 'shish3508',
  2165. 'unitPrice' => $unitPrice,
  2166. 'price' => $price,
  2167. ];
  2168. }
  2169. }
  2170. $shop = $this->shop;
  2171. $sjName = $shop->merchantName ?? '';
  2172. $shopName = $shop->shopName ?? '';
  2173. $sjShopName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  2174. $a4Print = [
  2175. 'customName' => $fullCustom,
  2176. 'staffName' => $staffName,
  2177. 'seatSn' => $seatSn,
  2178. 'shortSendTimeWant' => $shortSendTimeWant,
  2179. 'table' => $table,
  2180. 'remark' => $remark,
  2181. 'fullAddress' => $fullAddress,
  2182. 'sendNum' => $sendNum,
  2183. 'sendCost' => $sendCost,
  2184. 'ysName' => $ysName,
  2185. 'packCost' => $packCost,
  2186. 'totalItemNum' => $totalItemNum,
  2187. 'totalSmallItemNum' => $totalSmallItemNum,
  2188. 'shopName' => $sjShopName . ' 销售单',
  2189. ];
  2190. $info['printData'] = $a4Print;
  2191. //常规模板
  2192. //有用的历史备份
  2193. $template = '{"panels":[{"index":0,"name":1,"height":297,"width":210,"paperHeader":49.5,"paperFooter":780,"printElements":[{"options":{"left":30,"top":53,"height":52,"width":538,"field":"table","coordinateSync":false,"widthHeightSync":false,"tableBorder":"border","tableHeaderBorder":"border","tableHeaderCellBorder":"border","tableHeaderFontWeight":"bold","right":567.25,"bottom":110.24609375,"vCenter":298.25,"hCenter":82.24609375,"textAlign":"center","columns":[[{"width":134.33608169277167,"title":"名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center","halign":"center","vAlign":"middle","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":74.77209598393634,"title":"预订数","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":73.30462681205907,"title":"确认数","field":"confirmNum","checked":true,"columnId":"confirmNum","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":71.10877448138285,"title":"单价","field":"unitPrice","checked":true,"columnId":"unitPrice","fixed":false,"rowspan":1,"colspan":1},{"width":84.32601880877743,"title":"金额","field":"price","checked":true,"columnId":"price","fixed":false,"rowspan":1,"colspan":1},{"width":100.15240222107263,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":12,"top":786,"height":49,"width":49},"printElementType":{"title":"html","type":"html"}},{"options":{"left":382.5,"top":785,"height":13,"width":136,"title":"销花宝提供技术支持","textAlign":"center","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":518.74609375,"bottom":801.49609375,"vCenter":450.74609375,"hCenter":794.99609375},"printElementType":{"title":"自定义文本","type":"text"}},{"options":{"left":332.5,"top":35,"height":19,"width":233,"title":"货号","field":"seatSn","testData":"60","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"fontWeight":"bold","textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":567.9921875,"bottom":51.2421875,"vCenter":451.4921875,"hCenter":29.2421875},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":32.5,"height":19,"width":128,"title":"12-16","right":147.75,"bottom":49.49609375,"vCenter":87.75,"hCenter":28.99609375,"field":"shortSendTimeWant","testData":"12-16","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":12,"fontWeight":"bold","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":92.5,"top":32.5,"height":19,"width":411,"title":"文本","right":469,"bottom":52.49609375,"vCenter":282.5,"hCenter":34.99609375,"field":"customName","testData":"纯彩 15280215347","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":11,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":150,"height":45,"width":535,"title":"备注","right":565.75,"bottom":195,"vCenter":298.25,"hCenter":172.5,"field":"remark","testData":"箱子上要写上姓名和电话,到货时要拆箱,检查里面的花材","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"fontWeight":"bold","lineHeight":30,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":107.5,"height":25,"width":536,"title":"地址","field":"fullAddress","testData":"福建省厦门市集美区前山路147号中华人民共和国福建省厦门市集美区前山路147号中华人民共和国","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":561.2421875,"bottom":616.75,"vCenter":293.2421875,"hCenter":581.75,"lineHeight":32.25,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":135,"height":15,"width":52,"title":"编号","field":"sendNum","testData":"39","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":241.99609375,"bottom":182.49609375,"vCenter":215.99609375,"hCenter":174.99609375,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":90,"top":135,"height":15,"width":79,"title":"德邦物流","right":173.9921875,"bottom":150,"vCenter":134.4921875,"hCenter":142.5,"field":"ysName","testData":"德邦物流","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"qrCodeLevel":0,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":174,"top":135,"height":15,"width":120,"title":"开单人","field":"staffName","testData":"石头","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":298.9921875,"bottom":154.74609375,"vCenter":238.9921875,"hCenter":149.87109375,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":297.5,"top":135,"height":15,"width":120,"title":"打包人","field":"packName","testData":"小林","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":417.4921875,"bottom":147.24609375,"vCenter":357.4921875,"hCenter":142.37109375,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":92.5,"top":7.5,"height":25,"width":411,"title":"文本","right":509.74609375,"bottom":35.99609375,"vCenter":309.74609375,"hCenter":24.49609375,"field":"shopName","testData":"小向花卉 销售单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":16,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":552.5,"paperNumberTop":785,"paperNumberContinue":true,"fontFamily":"Microsoft YaHei","watermarkOptions":{"content":"","rotate":25,"timestamp":false,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}';
  2194. //$template = '{"panels":[{"index":0,"name":1,"height":297,"width":210,"paperHeader":49.5,"paperFooter":780,"printElements":[{"options":{"left":30,"top":53,"height":52,"width":538,"field":"table","coordinateSync":false,"widthHeightSync":false,"tableBorder":"border","tableHeaderBorder":"border","tableHeaderCellBorder":"border","tableHeaderFontWeight":"bold","right":567.25,"bottom":110.24609375,"vCenter":298.25,"hCenter":82.24609375,"textAlign":"center","columns":[[{"width":134.33608169277167,"title":"名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center","halign":"center","vAlign":"middle","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":74.77209598393634,"title":"预订数","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":73.30462681205907,"title":"确认数","field":"confirmNum","checked":true,"columnId":"confirmNum","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":71.10877448138285,"title":"单价","field":"unitPrice","checked":true,"columnId":"unitPrice","fixed":false,"rowspan":1,"colspan":1},{"width":84.32601880877743,"title":"金额","field":"price","checked":true,"columnId":"price","fixed":false,"rowspan":1,"colspan":1},{"width":100.15240222107263,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":12,"top":786,"height":49,"width":49},"printElementType":{"title":"html","type":"html"}},{"options":{"left":382.5,"top":785,"height":13,"width":136,"title":"销花宝提供技术支持","textAlign":"center","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":518.74609375,"bottom":801.49609375,"vCenter":450.74609375,"hCenter":794.99609375},"printElementType":{"title":"自定义文本","type":"text"}},{"options":{"left":332.5,"top":35,"height":19,"width":233,"title":"货号","field":"seatSn","testData":"60","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"fontWeight":"bold","textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":567.9921875,"bottom":51.2421875,"vCenter":451.4921875,"hCenter":29.2421875},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":32.5,"height":19,"width":128,"title":"12-16","right":147.75,"bottom":49.49609375,"vCenter":87.75,"hCenter":28.99609375,"field":"shortSendTimeWant","testData":"12-16","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":12,"fontWeight":"bold","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":92.5,"top":32.5,"height":19,"width":411,"title":"文本","right":469,"bottom":52.49609375,"vCenter":282.5,"hCenter":34.99609375,"field":"customName","testData":"纯彩 15280215347","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":11,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":145,"height":45,"width":535,"title":"备注","right":559.24609375,"bottom":207.99609375,"vCenter":291.74609375,"hCenter":185.49609375,"field":"remark","testData":"箱子上要写上姓名和电话,到货时要拆箱,检查里面的花材","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"fontWeight":"bold","lineHeight":30,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":107.5,"height":30,"width":536,"title":"地址","field":"fullAddress","testData":"福建省厦门市集美区前山路147号中华人民共和国福建省厦门市集美区前山路147号中华人民共和国","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":561.2421875,"bottom":616.75,"vCenter":293.2421875,"hCenter":581.75,"lineHeight":32.25},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":135,"height":15,"width":52,"title":"编号","field":"sendNum","testData":"39","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":241.99609375,"bottom":182.49609375,"vCenter":215.99609375,"hCenter":174.99609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":95,"top":135,"height":15,"width":79,"title":"德邦物流","right":174.25,"bottom":159.24609375,"vCenter":134.75,"hCenter":151.74609375,"field":"ysName","testData":"德邦物流","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":177.5,"top":137.5,"height":9.75,"width":120,"title":"开单人","field":"staffName","testData":"石头","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":298.9921875,"bottom":154.74609375,"vCenter":238.9921875,"hCenter":149.87109375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":297.5,"top":137.5,"height":9.75,"width":120,"title":"打包人","field":"packName","testData":"小林","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":417.4921875,"bottom":147.24609375,"vCenter":357.4921875,"hCenter":142.37109375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":92.5,"top":7.5,"height":25,"width":411,"title":"文本","right":509.74609375,"bottom":35.99609375,"vCenter":309.74609375,"hCenter":24.49609375,"field":"shopName","testData":"小向花卉 销售单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":16,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":552.5,"paperNumberTop":785,"paperNumberContinue":true,"fontFamily":"Microsoft YaHei","watermarkOptions":{"content":"","rotate":25,"timestamp":false,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}';
  2195. if (getenv('YII_ENV') == 'production') {
  2196. //花大苪模板
  2197. if (in_array($this->mainId, [8164])) {
  2198. $template = '{"panels":[{"index":0,"name":1,"height":297,"width":210,"paperHeader":49.5,"paperFooter":780,"printElements":[{"options":{"left":30,"top":53,"height":52,"width":538,"field":"table","coordinateSync":false,"widthHeightSync":false,"fontSize":16,"lineHeight":30,"tableBorder":"border","tableHeaderBorder":"border","tableHeaderCellBorder":"border","tableHeaderFontWeight":"bold","right":567.25,"bottom":110.24609375,"vCenter":298.25,"hCenter":82.24609375,"textAlign":"center","columns":[[{"width":188.91632245461145,"title":"名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center","halign":"center","vAlign":"middle","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":105.15171514242958,"title":"预订数","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":103.08801880877742,"title":"确认数","field":"confirmNum","checked":true,"columnId":"confirmNum","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":140.84394359418155,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":93.32065807548679,"title":"日期","field":"shortTime","checked":false,"columnId":"shortTime","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":74.09275968851016,"title":"库存","field":"stock","checked":false,"columnId":"stock","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":276,"title":"金额\n","field":"amount","checked":false,"columnId":"amount","fixed":false,"rowspan":1,"colspan":1,"tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":12,"top":786,"height":49,"width":49},"printElementType":{"title":"html","type":"html"}},{"options":{"left":392.5,"top":785,"height":13,"width":199,"title":"销花宝提供技术支持","textAlign":"center","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":590.74609375,"bottom":801.25,"vCenter":491.24609375,"hCenter":794.75},"printElementType":{"title":"自定义文本","type":"text"}},{"options":{"left":335,"top":12.5,"height":44,"width":233,"title":"货号","field":"seatSn","testData":"60","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"fontWeight":"bold","textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":567.9921875,"bottom":51.2421875,"vCenter":451.4921875,"hCenter":29.2421875},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":12.5,"height":46,"width":128,"title":"12-16","right":147.75,"bottom":49.49609375,"vCenter":87.75,"hCenter":28.99609375,"field":"shortSendTimeWant","testData":"12-16","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":20,"fontWeight":"bold","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":95,"top":17.5,"height":35,"width":373,"title":"文本","right":469,"bottom":52.49609375,"vCenter":282.5,"hCenter":34.99609375,"field":"customName","testData":"纯彩 15280215347","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":14,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":32.5,"top":377.5,"height":200,"width":535,"title":"备注","right":571.4921875,"bottom":550.25,"vCenter":303.9921875,"hCenter":450.25,"field":"remark","testData":"箱子上要写上姓名和电话,到货时要拆箱,检查里面的花材","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"fontWeight":"bold","lineHeight":30,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":32.5,"top":302.5,"height":70,"width":536,"title":"地址","field":"fullAddress","testData":"福建省厦门市集美区前山路147号中华人民共和国福建省厦门市集美区前山路147号中华人民共和国","coordinateSync":false,"widthHeightSync":false,"fontSize":18,"fontWeight":"bold","qrCodeLevel":0,"right":561.2421875,"bottom":616.75,"vCenter":293.2421875,"hCenter":581.75,"lineHeight":32.25},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":200,"height":50,"width":400,"title":"编号","field":"sendNum","testData":"39","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"lineHeight":36,"qrCodeLevel":0,"right":430,"bottom":284.99609375,"vCenter":230,"hCenter":259.99609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":32.5,"top":257.5,"height":39,"width":240,"title":"运费","field":"sendCost","testData":"0","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"lineHeight":28.5,"qrCodeLevel":0,"right":526.7421875,"bottom":415.74609375,"vCenter":276.7421875,"hCenter":400.74609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":295,"top":202.5,"height":43,"width":270,"title":"德邦物流","right":565.74609375,"bottom":280.99609375,"vCenter":430.74609375,"hCenter":259.49609375,"field":"ysName","testData":"德邦物流","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":20,"lineHeight":36,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":297.5,"top":260,"height":41,"width":260,"title":"打包费","field":"packCost","testData":"30","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"lineHeight":24,"qrCodeLevel":0,"right":555.74609375,"bottom":332.99609375,"vCenter":425.74609375,"hCenter":312.49609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":160,"height":36,"width":189,"title":"花材数量","field":"totalItemNum","testData":"20","coordinateSync":false,"widthHeightSync":false,"fontFamily":"cursive","fontSize":24,"fontWeight":"bold","lineHeight":32.25,"qrCodeLevel":0,"right":219,"bottom":158.49609375,"vCenter":124.5,"hCenter":140.49609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":295,"top":160,"height":36,"width":189,"title":"支数","field":"totalSmallItemNum","testData":"600","coordinateSync":false,"widthHeightSync":false,"fontFamily":"cursive","fontSize":24,"fontWeight":"bold","lineHeight":32.25,"qrCodeLevel":0,"right":482.25,"bottom":195.24609375,"vCenter":387.75,"hCenter":177.24609375},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":565.5,"paperNumberTop":819,"paperNumberContinue":true,"watermarkOptions":{"content":"vue-plugin-hiprint","rotate":25,"timestamp":true,"format":"YYYY-MM-DD HH:mm"},"panelLayoutOptions":{}}]}';
  2199. }
  2200. if (in_array($this->mainId, [44282])) {
  2201. //$template = '{"panels":[{"index":0,"name":1,"height":297,"width":210,"paperHeader":73.5,"paperFooter":780,"printElements":[{"options":{"left":30,"top":77,"height":52,"width":538,"field":"table","coordinateSync":false,"widthHeightSync":false,"tableBorder":"border","tableHeaderBorder":"border","tableHeaderCellBorder":"border","tableHeaderFontWeight":"bold","right":567.25,"bottom":110.24609375,"vCenter":298.25,"hCenter":82.24609375,"textAlign":"center","columns":[[{"width":134.33608169277167,"title":"名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center","halign":"center","vAlign":"middle","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":74.77209598393634,"title":"预订数","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":73.30462681205907,"title":"确认数","field":"confirmNum","checked":true,"columnId":"confirmNum","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":71.10877448138285,"title":"单价","field":"unitPrice","checked":true,"columnId":"unitPrice","fixed":false,"rowspan":1,"colspan":1},{"width":84.32601880877743,"title":"金额","field":"price","checked":true,"columnId":"price","fixed":false,"rowspan":1,"colspan":1},{"width":100.15240222107263,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":12,"top":786,"height":49,"width":49},"printElementType":{"title":"html","type":"html"}},{"options":{"left":382.5,"top":785,"height":13,"width":136,"title":"销花宝提供技术支持","textAlign":"center","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":518.74609375,"bottom":801.49609375,"vCenter":450.74609375,"hCenter":794.99609375},"printElementType":{"title":"自定义文本","type":"text"}},{"options":{"left":332.5,"top":53,"height":19,"width":233,"title":"货号","field":"seatSn","testData":"60","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"fontWeight":"bold","textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":567.9921875,"bottom":51.2421875,"vCenter":451.4921875,"hCenter":29.2421875},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":50.5,"height":19,"width":128,"title":"12-16","right":147.75,"bottom":49.49609375,"vCenter":87.75,"hCenter":28.99609375,"field":"shortSendTimeWant","testData":"12-16","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":12,"fontWeight":"bold","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":92.5,"top":50.5,"height":19,"width":411,"title":"文本","right":469,"bottom":52.49609375,"vCenter":282.5,"hCenter":34.99609375,"field":"customName","testData":"纯彩 15280215347","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":11,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":181.5,"height":45,"width":535,"title":"备注","right":565.75,"bottom":195,"vCenter":298.25,"hCenter":172.5,"field":"remark","testData":"箱子上要写上姓名和电话,到货时要拆箱,检查里面的花材","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"fontWeight":"bold","lineHeight":30,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":137.5,"height":25,"width":536,"title":"地址","field":"fullAddress","testData":"福建省厦门市集美区前山路147号中华人民共和国福建省厦门市集美区前山路147号中华人民共和国","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":561.2421875,"bottom":616.75,"vCenter":293.2421875,"hCenter":581.75,"lineHeight":32.25,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":165,"height":15,"width":52,"title":"编号","field":"sendNum","testData":"39","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":241.99609375,"bottom":182.49609375,"vCenter":215.99609375,"hCenter":174.99609375,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":90,"top":165,"height":15,"width":79,"title":"德邦物流","right":173.9921875,"bottom":150,"vCenter":134.4921875,"hCenter":142.5,"field":"ysName","testData":"德邦物流","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"qrCodeLevel":0,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":174,"top":165,"height":15,"width":120,"title":"开单人","field":"staffName","testData":"石头","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":298.9921875,"bottom":154.74609375,"vCenter":238.9921875,"hCenter":149.87109375,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":297.5,"top":165,"height":15,"width":120,"title":"打包人","field":"packName","testData":"小林","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":417.4921875,"bottom":147.24609375,"vCenter":357.4921875,"hCenter":142.37109375,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":92.5,"top":25.5,"height":25,"width":411,"title":"文本","right":509.74609375,"bottom":35.99609375,"vCenter":309.74609375,"hCenter":24.49609375,"field":"shopName","testData":"小向花卉 销售单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":16,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":552.5,"paperNumberTop":785,"paperNumberContinue":true,"fontFamily":"Microsoft YaHei","watermarkOptions":{"content":"","rotate":25,"timestamp":false,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}';
  2202. $template = '{"panels":[{"index":0,"name":1,"height":297,"width":210,"paperHeader":73.5,"paperFooter":780,"printElements":[{"options":{"left":30,"top":77,"height":52,"width":538,"field":"table","coordinateSync":false,"widthHeightSync":false,"tableBorder":"border","tableHeaderBorder":"border","tableHeaderCellBorder":"border","tableHeaderFontWeight":"bold","right":567.25,"bottom":110.24609375,"vCenter":298.25,"hCenter":82.24609375,"textAlign":"center","fontSize":11.25,"columns":[[{"width":134.33608169277167,"title":"名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center","halign":"center","vAlign":"middle","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":74.77209598393634,"title":"预订数","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":73.30462681205907,"title":"确认数","field":"confirmNum","checked":true,"columnId":"confirmNum","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":71.10877448138285,"title":"单价","field":"unitPrice","checked":true,"columnId":"unitPrice","fixed":false,"rowspan":1,"colspan":1},{"width":84.32601880877743,"title":"金额","field":"price","checked":true,"columnId":"price","fixed":false,"rowspan":1,"colspan":1},{"width":100.15240222107263,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":12,"top":786,"height":49,"width":49},"printElementType":{"title":"html","type":"html"}},{"options":{"left":382.5,"top":785,"height":13,"width":136,"title":"销花宝提供技术支持","textAlign":"center","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":518.74609375,"bottom":801.49609375,"vCenter":450.74609375,"hCenter":794.99609375},"printElementType":{"title":"自定义文本","type":"text"}},{"options":{"left":332.5,"top":53,"height":19,"width":233,"title":"货号","field":"seatSn","testData":"60","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"fontWeight":"bold","textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":567.9921875,"bottom":51.2421875,"vCenter":451.4921875,"hCenter":29.2421875},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":50.5,"height":19,"width":128,"title":"12-16","right":147.75,"bottom":49.49609375,"vCenter":87.75,"hCenter":28.99609375,"field":"shortSendTimeWant","testData":"12-16","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":12,"fontWeight":"bold","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":93,"top":51,"height":19,"width":411,"title":"文本","right":503.49609375,"bottom":69.49609375,"vCenter":297.99609375,"hCenter":59.99609375,"field":"customName","testData":"纯彩 15280215347","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":11,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":181.5,"height":45,"width":535,"title":"备注","right":565.75,"bottom":195,"vCenter":298.25,"hCenter":172.5,"field":"remark","testData":"箱子上要写上姓名和电话,到货时要拆箱,检查里面的花材","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"fontWeight":"bold","lineHeight":30,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":137.5,"height":25,"width":536,"title":"地址","field":"fullAddress","testData":"福建省厦门市集美区前山路147号中华人民共和国福建省厦门市集美区前山路147号中华人民共和国","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":561.2421875,"bottom":616.75,"vCenter":293.2421875,"hCenter":581.75,"lineHeight":32.25,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":165,"height":15,"width":52,"title":"编号","field":"sendNum","testData":"39","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":241.99609375,"bottom":182.49609375,"vCenter":215.99609375,"hCenter":174.99609375,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":90,"top":165,"height":15,"width":79,"title":"德邦物流","right":173.9921875,"bottom":150,"vCenter":134.4921875,"hCenter":142.5,"field":"ysName","testData":"德邦物流","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"qrCodeLevel":0,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":174,"top":165,"height":15,"width":120,"title":"开单人","field":"staffName","testData":"石头","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":298.9921875,"bottom":154.74609375,"vCenter":238.9921875,"hCenter":149.87109375,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":297.5,"top":165,"height":15,"width":120,"title":"打包人","field":"packName","testData":"小林","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":417.4921875,"bottom":147.24609375,"vCenter":357.4921875,"hCenter":142.37109375,"textContentVerticalAlign":"middle"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":92.5,"top":25.5,"height":25,"width":411,"title":"文本","right":509.74609375,"bottom":35.99609375,"vCenter":309.74609375,"hCenter":24.49609375,"field":"shopName","testData":"小向花卉 销售单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":16,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":552.5,"paperNumberTop":785,"paperNumberContinue":true,"fontFamily":"Microsoft YaHei","watermarkOptions":{"content":"","rotate":25,"timestamp":false,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}';
  2203. }
  2204. }
  2205. $info['template'] = $template;
  2206. $printType = $get['printType'] ?? 0;
  2207. if ($printType == 1) {
  2208. //打多联的模板
  2209. $table = [];
  2210. if (isset($info['product']) && !empty($info['product'])) {
  2211. foreach ($info['product'] as $key => $val) {
  2212. $currentName = $val['name'] ?? '';
  2213. $num = $val['xhNum'] ?? 0;
  2214. $refundNum = $val['refundNum'] ?? 0;
  2215. $num = bcsub($num, $refundNum);
  2216. $totalItemNum = bcadd($totalItemNum, $num);
  2217. $ratio = $val['ratio'] ?? 0;
  2218. $currentSmallNum = bcmul($num, $ratio);
  2219. $totalSmallItemNum = bcadd($totalSmallItemNum, $currentSmallNum);
  2220. $itemRemark = $val['remark'] ?? '';
  2221. $unitPrice = $val['xhUnitPrice'] ?? 0;
  2222. $unitPrice = floatval($unitPrice);
  2223. $price = bcmul($unitPrice, $num, 2);
  2224. $price = floatval($price);
  2225. $table[] = [
  2226. 'name' => $currentName,
  2227. 'num' => $num,
  2228. 'orderNum' => '',
  2229. 'remark' => $itemRemark,
  2230. 'wxNumber' => 'shish3508',
  2231. 'unitPrice' => '¥' . $unitPrice,
  2232. 'price' => '¥' . $price,
  2233. 'refundNum' => $refundNum == 0 ? '' : 0,
  2234. ];
  2235. }
  2236. }
  2237. $orderSn = $info['orderSn'] ?? '';
  2238. $kind = $info['productStat'] && $info['productStat']['kind'] ?? 0;
  2239. $totalItemNum = $info['productStat'] && $info['productStat']['bigNum'] ?? 0;
  2240. $addTime = $info['addTime'] ?? '';
  2241. $actPrice = $info['actPrice'] ?? 0;
  2242. $tkPrice = $info['tkPrice'] ?? 0;
  2243. $prePrice = $info['prePrice'] ?? 0;
  2244. $customMobile = $info['customMobile'] ?? '';
  2245. $address = '';
  2246. if (isset($info['address']) && !empty($info['address'])) {
  2247. $address .= $info['fullAddress'];
  2248. if (isset($info['showAddress']) && !empty($info['showAddress']) && $info['showAddress'] != $info['fullAddress']) {
  2249. $address .= '(' . $info['showAddress'] . ')<BR>';
  2250. }
  2251. }
  2252. $printData = [
  2253. 'table' => $table,
  2254. 'addTime' => '',
  2255. 'entryTime' => $addTime,
  2256. 'ghsName' => $customName,
  2257. 'clearCode' => '',
  2258. 'staffName' => '',
  2259. 'telephone' => $customMobile,
  2260. 'kind' => $kind,
  2261. 'orderSn' => $orderSn,
  2262. 'sjShopName' => $sjShopName . ' 销售单',
  2263. 'sjShopName2' => $sjShopName,
  2264. 'prePrice' => '¥' . $prePrice,
  2265. 'tkPrice' => '¥' . $tkPrice,
  2266. 'realPrice' => '¥' . $actPrice,
  2267. 'totalItemNum' => $totalItemNum,
  2268. 'numKind' => "共" . $kind . "种,数量:" . $totalItemNum,
  2269. 'address' => $address,
  2270. 'saleName' => '销售单',
  2271. ];
  2272. $info['printData'] = $printData;
  2273. $template = '{"panels":[{"index":0,"name":1,"height":140,"width":210,"paperHeader":49.5,"paperFooter":383.4343434343434,"printElements":[{"options":{"left":115,"top":20,"height":25,"width":374,"title":"文本","right":488.99609375,"bottom":44.9921875,"vCenter":301.99609375,"hCenter":32.4921875,"field":"sjShopName","testData":"小向花卉 采购单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":14,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":22.5,"height":21,"width":145,"title":"单号","field":"orderSn","testData":"PC563961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":148.9921875,"bottom":43.9921875,"vCenter":85.9921875,"hCenter":33.4921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":445,"top":25,"height":22,"width":122,"title":"核销码","field":"clearCode","testData":"3961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":571.25,"bottom":46.75,"vCenter":510.25,"hCenter":35.75,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":22.5,"top":55,"height":36,"width":550,"field":"table","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"center","tableHeaderFontWeight":"bold","right":572.5,"bottom":90.99609375,"vCenter":297.5,"hCenter":72.99609375,"fontFamily":"SimSun","columns":[[{"width":54.223705213537556,"title":"序号","field":"orderNum","checked":true,"columnId":"orderNum","fixed":false,"rowspan":1,"colspan":1},{"width":175.72632876030514,"title":"花材名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1},{"width":69.07232544378695,"title":"单价","field":"unitPrice","checked":true,"columnId":"unitPrice","fixed":false,"rowspan":1,"colspan":1},{"width":72.10486265361865,"title":"数量","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1},{"width":67.11113461538461,"title":"金额","field":"price","checked":true,"columnId":"price","fixed":false,"rowspan":1,"colspan":1},{"width":57.08931639029012,"title":"已退","field":"refundNum","checked":true,"columnId":"refundNum","fixed":false,"rowspan":1,"colspan":1},{"width":54.67232692307692,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":200,"top":120,"height":16,"width":178,"title":"账单日期","field":"addTime","testData":"2024-12-28 11:00","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":359.49609375,"bottom":146.9921875,"vCenter":276.99609375,"hCenter":138.9921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":372,"top":120,"height":16,"width":178,"title":"客户","field":"ghsName","testData":"石头花艺","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":573.49609375,"bottom":145.99609375,"vCenter":484.49609375,"hCenter":137.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":120,"height":16,"width":175,"title":"创建时间","right":141.75,"bottom":139.5,"vCenter":81.75,"hCenter":134.625,"field":"entryTime","testData":"2024-12-29 12:10","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":132.5,"top":145,"height":16,"width":90,"title":"售后","right":262.74609375,"bottom":161.2421875,"vCenter":202.74609375,"hCenter":153.2421875,"field":"tkPrice","testData":"63","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":222.5,"top":145,"height":16,"width":114,"title":"实际金额","field":"realPrice","testData":"23","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":358.9921875,"bottom":160.99609375,"vCenter":301.9921875,"hCenter":152.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":347.5,"top":145,"height":16,"width":120,"title":"电话","field":"telephone","testData":"15280215347","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":467.7421875,"bottom":161.2421875,"vCenter":407.7421875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":425,"top":145,"height":16,"width":148,"title":"录单人","field":"staffName","testData":"小石","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":574.4921875,"bottom":161.2421875,"vCenter":500.4921875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":145,"height":16,"width":105,"title":"合计","field":"prePrice","testData":"693","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":144,"bottom":160.24609375,"vCenter":85.5,"hCenter":152.24609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":169.5,"height":16,"width":120,"field":"numKind","testData":"共3种,数量:9","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"title":"文本","fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":169.5,"top":169.5,"height":16,"width":400,"title":"地址","field":"address","testData":"厦门前山路147号","coordinateSync":false,"widthHeightSync":false,"fontSize":10.5,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":569.5,"bottom":185.5,"vCenter":369.5,"hCenter":177.5},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":565.5,"paperNumberTop":389,"paperNumberDisabled":true,"paperNumberContinue":true,"orient":1,"watermarkOptions":{"content":"","rotate":25,"timestamp":false,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}';
  2274. if (in_array($this->mainId, [91452])) {
  2275. //绿科花卉种苗
  2276. $template = '{"panels":[{"index":0,"name":1,"height":140,"width":210,"paperHeader":76.5,"paperFooter":383.4343434343434,"printElements":[{"options":{"left":115.5,"top":21,"height":25,"width":374,"title":"文本","right":488.99609375,"bottom":44.9921875,"vCenter":301.99609375,"hCenter":32.4921875,"field":"sjShopName2","testData":"小向花卉","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":21,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":18.5,"top":22.5,"height":21,"width":165,"title":"单号","field":"orderSn","testData":"PC563961","coordinateSync":false,"widthHeightSync":false,"fontSize":14.25,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":148.9921875,"bottom":43.9921875,"vCenter":85.9921875,"hCenter":33.4921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":448,"top":25,"height":22,"width":122,"title":"核销码","field":"clearCode","testData":"3961","coordinateSync":false,"widthHeightSync":false,"fontSize":14.25,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":571.25,"bottom":46.75,"vCenter":510.25,"hCenter":35.75,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":22.5,"top":82,"height":36,"width":550,"field":"table","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"center","tableHeaderFontWeight":"bold","right":572.5,"bottom":90.99609375,"vCenter":297.5,"hCenter":72.99609375,"fontFamily":"SimSun","columns":[[{"width":54.696355213537544,"title":"序号","field":"orderNum","checked":true,"columnId":"orderNum","fixed":false,"rowspan":1,"colspan":1},{"width":175.25367876030515,"title":"花材名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1},{"width":69.07232544378695,"title":"单价","field":"unitPrice","checked":true,"columnId":"unitPrice","fixed":false,"rowspan":1,"colspan":1},{"width":72.10486265361865,"title":"数量","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1},{"width":67.11113461538461,"title":"金额","field":"price","checked":true,"columnId":"price","fixed":false,"rowspan":1,"colspan":1},{"width":57.08931639029012,"title":"已退","field":"refundNum","checked":true,"columnId":"refundNum","fixed":false,"rowspan":1,"colspan":1},{"width":54.67232692307692,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":200,"top":150,"height":16,"width":178,"title":"账单日期","field":"addTime","testData":"2024-12-28 11:00","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":359.49609375,"bottom":146.9921875,"vCenter":276.99609375,"hCenter":138.9921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":372,"top":150,"height":16,"width":178,"title":"客户","field":"ghsName","testData":"石头花艺","coordinateSync":false,"widthHeightSync":false,"fontSize":15,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":573.49609375,"bottom":145.99609375,"vCenter":484.49609375,"hCenter":137.99609375,"fontFamily":"SimSun","fontWeight":"bold"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":150,"height":16,"width":175,"title":"创建时间","right":141.75,"bottom":139.5,"vCenter":81.75,"hCenter":134.625,"field":"entryTime","testData":"2024-12-29 12:10","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":132.5,"top":175,"height":16,"width":90,"title":"售后","right":262.74609375,"bottom":161.2421875,"vCenter":202.74609375,"hCenter":153.2421875,"field":"tkPrice","testData":"63","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":222.5,"top":175,"height":16,"width":114,"title":"实际金额","field":"realPrice","testData":"23","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":358.9921875,"bottom":160.99609375,"vCenter":301.9921875,"hCenter":152.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":347.5,"top":175,"height":16,"width":120,"title":"电话","field":"telephone","testData":"15280215347","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":467.7421875,"bottom":161.2421875,"vCenter":407.7421875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":425,"top":175,"height":16,"width":148,"title":"录单人","field":"staffName","testData":"小石","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":574.4921875,"bottom":161.2421875,"vCenter":500.4921875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":175,"height":16,"width":105,"title":"合计","field":"prePrice","testData":"693","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":144,"bottom":160.24609375,"vCenter":85.5,"hCenter":152.24609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":199.5,"height":16,"width":120,"field":"numKind","testData":"共3种,数量:9","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"title":"文本","fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":169.5,"top":199.5,"height":16,"width":400,"title":"地址","field":"address","testData":"厦门前山路147号","coordinateSync":false,"widthHeightSync":false,"fontSize":10.5,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":569.5,"bottom":185.5,"vCenter":369.5,"hCenter":177.5},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":238.5,"top":48,"height":28,"width":120,"title":"自定义文本","field":"saleName","testData":"销售单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":19.5,"textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":372.75,"bottom":69.25,"vCenter":312.75,"hCenter":55.25},"printElementType":{"title":"自定义文本","type":"text"}}],"paperNumberLeft":565.5,"paperNumberTop":389,"paperNumberDisabled":true,"paperNumberContinue":true,"orient":1,"watermarkOptions":{"content":"","rotate":25,"timestamp":false,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}';
  2277. }
  2278. $info['template'] = $template;
  2279. }
  2280. //是否有云打印判断
  2281. $hasCloudPrint = 0;
  2282. $shopExt = $this->shopExt;
  2283. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  2284. $hasCloudPrint = 1;
  2285. }
  2286. $info['hasCloudPrint'] = $hasCloudPrint;
  2287. $purchaseId = $info['purchaseId'] ?? 0;
  2288. $cg = PurchaseClass::getById($purchaseId);
  2289. $info['cgInfo'] = $cg;
  2290. //店长信息
  2291. $mainId = $cg['mainId'] ?? 0;
  2292. $superInfo = ShopAdminClass::getManager($mainId);
  2293. $info['customSuper'] = $superInfo;
  2294. //员工是否有财务权限 ssh 20251117
  2295. $staff = $this->shopAdmin;
  2296. $staffFinance = $staff->finance ?? 0;
  2297. $info['staffFinance'] = $staffFinance;
  2298. $shopBusiness = $shop->business ?? 0;
  2299. $info['shopBusiness'] = $shopBusiness;
  2300. //冲销单详情页展示"原单"入口:如果当前订单本身就是一张冲销单(forward==1),
  2301. //反查 xhGhsOrderForward 关联记录拿到原销售单id/单号,供前端跳转查看原单。ssh 冲销单功能
  2302. $forward = $info['forward'] ?? 0;
  2303. if ($forward == 1) {
  2304. $relate = OrderForwardClass::getByForwardOrderId($id);
  2305. if (!empty($relate)) {
  2306. $info['relateOrderId'] = $relate['orderId'] ?? 0;
  2307. $info['relateOrderSn'] = $relate['orderSn'] ?? '';
  2308. }
  2309. }
  2310. util::success($info);
  2311. }
  2312. //获取订单信息 ssh 20240102
  2313. public function actionGetInfoByOrderSn()
  2314. {
  2315. $get = Yii::$app->request->get();
  2316. $orderSn = $get['orderSn'] ?? '';
  2317. $info = OrderService::getByCondition(['orderSn' => $orderSn], true);
  2318. if (empty($info)) {
  2319. util::fail('没有找到订单');
  2320. }
  2321. if ($info->mainId != $this->mainId) {
  2322. util::fail('不是你的订单哦');
  2323. }
  2324. util::success(['info' => $info]);
  2325. }
  2326. //获取订单详情,不需要登录可以访问,后面要删除此方法 ssh 20220819
  2327. public function actionInfo()
  2328. {
  2329. $get = Yii::$app->request->get();
  2330. $id = $get['id'] ?? 0;
  2331. $info = OrderService::getOrderInfo($id, true, true, true, false);
  2332. if (empty($info)) {
  2333. util::fail('没有找到订单');
  2334. }
  2335. //是否有云打印判断
  2336. $hasCloudPrint = 0;
  2337. $shopExt = $this->shopExt;
  2338. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  2339. $hasCloudPrint = 1;
  2340. }
  2341. $info['hasCloudPrint'] = $hasCloudPrint;
  2342. $purchaseId = $info['purchaseId'] ?? 0;
  2343. $cg = PurchaseClass::getById($purchaseId);
  2344. $info['cgInfo'] = $cg;
  2345. //店长信息
  2346. $mainId = $cg['mainId'] ?? 0;
  2347. $superInfo = ShopAdminClass::getManager($mainId);
  2348. $info['customSuper'] = $superInfo;
  2349. util::success($info);
  2350. }
  2351. //自取免发货流程处理 ssh 2021.1.22
  2352. public function actionWithoutSend()
  2353. {
  2354. util::complete();
  2355. }
  2356. //本店送 ssh 2021.1.24
  2357. public function actionSelfSend()
  2358. {
  2359. $get = Yii::$app->request->get();
  2360. $id = isset($get['id']) ? $get['id'] : 0;
  2361. $info = OrderClass::getById($id, true);
  2362. OrderClass::valid($info->attributes, $this->shopId);
  2363. $connection = Yii::$app->db;
  2364. $transaction = $connection->beginTransaction();
  2365. try {
  2366. OrderClass::selfSend($info);
  2367. $transaction->commit();
  2368. } catch (\Exception $exception) {
  2369. $transaction->rollBack();
  2370. Yii::info("本店送操作报错:" . $exception->getMessage());
  2371. util::fail('操作失败');
  2372. }
  2373. util::complete();
  2374. }
  2375. //运费计算 ssh 2021.1.24
  2376. public function actionFreight()
  2377. {
  2378. //2021.3.28 接入达达
  2379. $get = Yii::$app->request->get();
  2380. $post = Yii::$app->request->post();
  2381. if (empty($get)) {
  2382. $get = $post;
  2383. }
  2384. $orderId = $get['id'] ?? 0; //订单ID
  2385. $customId = $get['customId'] ?? 0;
  2386. if (empty($orderId)) {
  2387. //自定义运费
  2388. //freight::getCost();
  2389. if (empty($customId)) {
  2390. util::fail("请选择客户");
  2391. }
  2392. $customInfo = CustomClass::getById($customId);
  2393. if (empty($customInfo)) {
  2394. util::fail('没有找到客户');
  2395. }
  2396. $shop = $this->shop;
  2397. //花材信息
  2398. $productJson = $get['product'] ?? '';
  2399. // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
  2400. if (empty($productJson)) {
  2401. util::fail('请选择花材');
  2402. }
  2403. $productList = json_decode($productJson, true);
  2404. if (empty($productList)) {
  2405. util::fail('请选择花材');
  2406. }
  2407. $productList = ProductClass::mergeItemInfo($productList);
  2408. $weight = 0;
  2409. $price = 0;
  2410. $productData = ProductClass::getProductMapData($productList);
  2411. $bigNum = 0;
  2412. foreach ($productList as $key => $val) {
  2413. $productId = $val['productId'];
  2414. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  2415. $bigNum += $val['bigNum'];
  2416. $weight = bcadd($w, $weight, 2);
  2417. $ratio = $productData[$productId]['ratio'] ?? 0;
  2418. //大小数量合并多少扎
  2419. $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  2420. //售卖价格
  2421. $itemPrice = $productData[$productId]['price'] ?? 0;
  2422. //合计价格
  2423. $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2);
  2424. }
  2425. //没有经纬度的客户运费直接返回空 ssh 20210612
  2426. if (empty($customInfo['lat']) || empty($customInfo['long'])) {
  2427. util::success(['sedCost' => '']);
  2428. }
  2429. $cost = freight::getCost($shop->lat, $shop->long, $customInfo['lat'], $customInfo['long'], $weight);
  2430. util::success(['sedCost' => $cost]);
  2431. }
  2432. $province = $get['province'] ?? '';
  2433. $city = $get['city'] ?? '';
  2434. $address = $get['address'] ?? '';
  2435. $floor = $get['floor'] ?? '';
  2436. $customName = $get['customName'] ?? '';
  2437. $customMobile = $get['customMobile'] ?? '';
  2438. $fullAddress = $province . $city . $address . $floor;
  2439. $sendTime = $get['sendTime'] ?? '';
  2440. $lat = $get['lat'] ?? '';
  2441. $lng = $get['long'] ?? '';
  2442. if (empty($lat) || empty($lng) || empty($fullAddress)) {
  2443. util::fail('请填写客户地址');
  2444. }
  2445. ini_set('date.timezone', 'Asia/Shanghai');
  2446. if (!empty($sendTime)) {
  2447. //配送时间不为空
  2448. // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
  2449. $sendTimeInt = strtotime($sendTime);
  2450. $now = time();
  2451. $diff = $sendTimeInt - $now;
  2452. //因服务器写入时间,改为至少提前6分钟
  2453. if ($diff <= 360) {
  2454. util::fail('配送时间至少提前6分钟');
  2455. }
  2456. } else {
  2457. //默认立即发送
  2458. $sendTime = 0;
  2459. }
  2460. //更新订单表
  2461. $info = OrderService::getOrderInfo($orderId);
  2462. OrderClass::valid($info, $this->shopId);
  2463. if ($sendTime) {
  2464. $sendTime = date('Y-m-d H:i', strtotime($sendTime));
  2465. } else {
  2466. $sendTime = '0000-00-00 00:00:00';
  2467. }
  2468. $expressAddInfo = [
  2469. 'customName' => $customName,
  2470. 'customMobile' => $customMobile,
  2471. 'province' => $province,
  2472. 'city' => $city,
  2473. 'address' => $address,
  2474. 'floor' => $floor,
  2475. 'lat' => $lat,
  2476. 'long' => $lng,
  2477. 'sendTime' => $sendTime,
  2478. ];
  2479. OrderClass::updateCustomExpressInfo($orderId, $expressAddInfo);
  2480. //计算运费
  2481. $info['province'] = $province;
  2482. $info['city'] = $city;
  2483. $info['address'] = $address;
  2484. $info['floor'] = $floor;
  2485. $info['fullAddress'] = $fullAddress;
  2486. $info['lat'] = $lat;
  2487. $info['long'] = $lng;
  2488. $info['sendTime'] = $expressAddInfo['sendTime'];
  2489. $res = DadaExpressServices::queryDeliverFee($info);
  2490. util::success(['sedCost' => $res['fee']]);
  2491. }
  2492. //发快递和第三方配送 ssh 2021.1.24
  2493. public function actionThirdSend()
  2494. {
  2495. $get = Yii::$app->request->get();
  2496. $id = isset($get['id']) ? $get['id'] : 0;
  2497. $info = OrderService::getById($id, true);
  2498. OrderClass::valid($info->attributes, $this->shopId);
  2499. if (empty($info->lat) || empty($info->long) || empty($info->fullAddress)) {
  2500. util::fail('请填写客户地址');
  2501. }
  2502. $connection = Yii::$app->db;
  2503. $transaction = $connection->beginTransaction();
  2504. try {
  2505. $respond = OrderClass::thirdSend($info, $get);
  2506. $transaction->commit();
  2507. util::success($respond);
  2508. } catch (\Exception $exception) {
  2509. $transaction->rollBack();
  2510. Yii::info("发快递操作报错:" . $exception->getMessage());
  2511. util::fail('操作失败' . $exception->getMessage());
  2512. }
  2513. }
  2514. //确认送达 ssh 2021.1.24
  2515. public function actionReach()
  2516. {
  2517. $get = Yii::$app->request->get();
  2518. $id = isset($get['id']) ? $get['id'] : 0;
  2519. $info = OrderClass::getById($id, true);
  2520. OrderClass::valid($info->attributes, $this->shopId);
  2521. $connection = Yii::$app->db;
  2522. $transaction = $connection->beginTransaction();
  2523. try {
  2524. OrderService::reach($info);
  2525. $transaction->commit();
  2526. } catch (\Exception $exception) {
  2527. $transaction->rollBack();
  2528. Yii::info("送达操作报错:" . $exception->getMessage());
  2529. util::fail('操作失败');
  2530. }
  2531. util::complete();
  2532. }
  2533. //下单要用到的相关信息 ssh 2019.12.6
  2534. public function actionOrderRelate()
  2535. {
  2536. $regionTree = RegionService::tree();
  2537. $shop = $this->shop->attributes;
  2538. $freight = ['first' => 5, 'add' => 2];
  2539. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  2540. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'thirdMapKey' => $mapKey, 'merchant' => $shop];
  2541. util::success($out);
  2542. }
  2543. //客户欠款的订单 ssh 2021.2.4
  2544. public function actionDebtList()
  2545. {
  2546. $get = Yii::$app->request->get();
  2547. $id = $get['id'] ?? 0;
  2548. $info = CustomClass::getCustom($id);
  2549. CustomClass::valid($info, $this->shopId);
  2550. $mainId = $this->mainId;
  2551. $where = ['mainId' => $mainId, 'customId' => $id, 'debt' => 1];
  2552. $searchTime = $get['searchTime'] ?? '';
  2553. if (!empty($searchTime)) {
  2554. $startTime = $get['startTime'] ?? '';
  2555. $endTime = $get['endTime'] ?? '';
  2556. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  2557. $where['payTime'] = ['between', [$period['startTime'], $period['endTime']]];
  2558. } else {
  2559. if ($mainId == 33447 && $id == 51031) {
  2560. util::fail('请选时间');
  2561. }
  2562. }
  2563. $allowedPageSizes = [100, 200, 300];
  2564. $pageSize = isset($get['pageSize']) && in_array((int)$get['pageSize'], $allowedPageSizes, true)
  2565. ? (int)$get['pageSize'] : 100;
  2566. $page = max(1, (int)($get['page'] ?? 1));
  2567. $fields = ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice', 'debtPrice', 'payTime', 'remark'];
  2568. Yii::$app->request->setQueryParams(array_merge($get, ['page' => $page, 'pageSize' => $pageSize]));
  2569. $result = OrderClass::getList($fields, $where, 'addTime DESC');
  2570. if (!empty($result['list'])) {
  2571. foreach ($result['list'] as $key => $value) {
  2572. $debtPrice = $value['debtPrice'] ?? 0;
  2573. $remainDebtPrice = $value['remainDebtPrice'] ?? 0;
  2574. $hasPayDebt = '0.00';
  2575. if (bccomp((string)$debtPrice, (string)$remainDebtPrice, 2) > 0) {
  2576. $hasPayDebt = bcsub((string)$debtPrice, (string)$remainDebtPrice, 2);
  2577. }
  2578. $result['list'][$key]['hasPayDebt'] = floatval($hasPayDebt);
  2579. }
  2580. }
  2581. $result['customInfo'] = $info;
  2582. util::success($result);
  2583. }
  2584. //更新打印次数
  2585. public function actionAddPrintNum()
  2586. {
  2587. $id = Yii::$app->request->get('id', 0);
  2588. $order = OrderClass::getById($id, true);
  2589. OrderClass::valid($order, $this->shopId);
  2590. $order->printNum += 1;
  2591. $order->save();
  2592. util::complete();
  2593. }
  2594. //打印订单 ssh 20210714
  2595. public function actionCloudPrintOrder()
  2596. {
  2597. $get = Yii::$app->request->get();
  2598. $id = $get['id'] ?? 0;
  2599. $showPrice = $get['showPrice'] ?? 1;
  2600. $order = OrderClass::getById($id, true);
  2601. OrderClass::valid($order, $this->shopId);
  2602. if ($order->status == OrderClass::ORDER_STATUS_UN_PAY) {
  2603. util::fail('订单还没有付款');
  2604. }
  2605. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  2606. util::fail('订单已取消');
  2607. }
  2608. $ext = $this->shopExt;
  2609. if (isset($ext->printSn) == false || isset($ext->printKey) == false || empty($ext->printSn) || empty($ext->printKey)) {
  2610. util::success(['hasNoPrint' => 1]);
  2611. }
  2612. util::checkRepeatCommit($this->adminId, 3);
  2613. OrderClass::onlinePrint($order, $showPrice);
  2614. $order->printNum += 1;
  2615. $order->save();
  2616. util::complete();
  2617. }
  2618. /**
  2619. * 飞鹅云打印日志(Redis 缓存)
  2620. */
  2621. public function actionPrintLog()
  2622. {
  2623. $id = intval(Yii::$app->request->get('id', 0));
  2624. if ($id <= 0) {
  2625. util::fail('订单id不对');
  2626. }
  2627. $order = OrderClass::getById($id, true);
  2628. OrderClass::valid($order, $this->shopId);
  2629. $printSn = $this->shopExt->printSn ?? '';
  2630. $list = feiePrintLogUtil::getList($order->mainId, $order->id);
  2631. util::success([
  2632. 'printSn' => (string)$printSn,
  2633. 'orderSn' => (string)($order->orderSn ?? ''),
  2634. 'list' => $list,
  2635. ]);
  2636. }
  2637. //订单确认完成 ssh 20210809
  2638. public function actionConfirmFinish()
  2639. {
  2640. $payWay = Yii::$app->request->get('payWay', -1);
  2641. $id = Yii::$app->request->get('id', 0);
  2642. $clearType = Yii::$app->request->get('clearType', 0);
  2643. $connection = Yii::$app->db;
  2644. $transaction = $connection->beginTransaction();
  2645. try {
  2646. $order = OrderClass::getById($id, true);
  2647. OrderClass::valid($order, $this->shopId);
  2648. $purchaseId = $order->purchaseId ?? 0;
  2649. $purchase = PurchaseClass::getById($purchaseId, true);
  2650. if (empty($purchase)) {
  2651. util::fail('没有采购信息');
  2652. }
  2653. if ($clearType == 1) {
  2654. //欠款
  2655. $payWay = dict::getDict('payWay', 'debtPay');
  2656. } elseif ($clearType == 2) {
  2657. //已收款
  2658. if ($payWay == -1) {
  2659. util::fail('请选择收款方式');
  2660. }
  2661. $shopAdmin = $this->shopAdmin;
  2662. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  2663. util::fail('超管才能发起已收款');
  2664. }
  2665. } else {
  2666. util::fail('请选择结算方式');
  2667. }
  2668. //不需要打印
  2669. $order->needPrint = dict::getDict('needPrint', 'noNeed');
  2670. $order->save();
  2671. //支付
  2672. PurchaseService::payAfter($purchase, $payWay);
  2673. OrderService::payAfter($order, $payWay);
  2674. //自己送
  2675. $info = OrderClass::getById($id, true);
  2676. OrderClass::selfSend($info);
  2677. //确认送达,并且不需要微信通知
  2678. Yii::$app->params['noNeedWxNotice'] = 1;
  2679. $info = OrderClass::getById($id, true);
  2680. OrderService::reach($info);
  2681. $transaction->commit();
  2682. util::complete('操作成功');
  2683. } catch (\Exception $exception) {
  2684. $transaction->rollBack();
  2685. Yii::info("确认完成订单报错:" . $exception->getMessage());
  2686. util::fail('操作失败');
  2687. }
  2688. }
  2689. //取消订单 ssh 20220110
  2690. public function actionCancel()
  2691. {
  2692. $shopAdmin = $this->shopAdmin;
  2693. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  2694. util::fail('超管才能取消订单');
  2695. }
  2696. //避免重复提交
  2697. $adminId = $this->adminId;
  2698. util::checkRepeatCommit($adminId, 3);
  2699. $get = Yii::$app->request->get();
  2700. $cashier = $get['cashier'] ?? 0;
  2701. //是否强制取消订单 0不要强制 1强制,没有关单成功也要取消
  2702. $forceCancel = $get['forceCancel'] ?? 0;
  2703. $id = $get['id'] ?? 0;
  2704. $order = OrderClass::getById($id, true);
  2705. OrderClass::valid($order, $this->shopId);
  2706. if ($order->orderType == 2) {
  2707. util::fail('客户下单,不能主动取消');
  2708. }
  2709. //如果收银台的订单,取消时要关闭拉卡拉的订单
  2710. if ($cashier == 1) {
  2711. //已取消,不需要再走下面的流程
  2712. if ($order->status == 5) {
  2713. util::complete('已取消');
  2714. }
  2715. $cgId = $order->purchaseId ?? 0;
  2716. $cg = PurchaseClass::getById($cgId, true);
  2717. $orderSn = $cg->orderSn ?? '';
  2718. $shop = $this->shop;
  2719. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  2720. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  2721. $params = [
  2722. 'appid' => 'OP00002119',
  2723. 'serial_no' => '018b08cfddbd',
  2724. 'merchant_no' => $shop->lklSjNo,
  2725. 'term_no' => $shop->lklScanTermNo,
  2726. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  2727. 'lklCertificatePath' => $lklCertificatePath,
  2728. ];
  2729. $laResource = new Lakala($params);
  2730. // 1. 先查询拉卡拉侧订单状态
  2731. $queryResponse = $laResource->query(['orderSn' => $orderSn]);
  2732. //响应CODE为BBS00000,仅表示查到了这笔交易。交易本身的成功与否状态,要查看响应报文中的trade_state这个值
  2733. if (isset($queryResponse['code']) && $queryResponse['code'] == 'BBS00000') {
  2734. $tradeState = $queryResponse['resp_data']['trade_state'] ?? '';
  2735. // 订单已支付,拦截取消操作
  2736. if ($tradeState == 'SUCCESS') {
  2737. util::fail('已付款,不能取消');
  2738. }
  2739. // 根据拉卡拉聚合支付文档(id=116)及实际情况,判断是否为非终态
  2740. // INIT:初始化, CREATE:下单成功, DEAL:交易处理中, USERPAYING:支付中, NOTPAY:未支付
  2741. $pendingStates = ['INIT', 'CREATE', 'DEAL', 'USERPAYING', 'NOTPAY'];
  2742. if (in_array($tradeState, $pendingStates)) {
  2743. $closeParams = ['orderSn' => $orderSn];
  2744. $closeResponse = $laResource->close($closeParams);
  2745. if (!isset($closeResponse['code']) || $closeResponse['code'] != 'BBS00000') {
  2746. $msg = $closeResponse['msg'] ?? '关闭失败';
  2747. noticeUtil::push("拉卡拉聚合支付关单失败:{$orderSn},原因:{$msg} 原单状态:{$tradeState}", '15280215347');
  2748. if ($forceCancel == 0) {
  2749. //返回禁止关单
  2750. util::fail('取消失败,如必要请强制取消');
  2751. }
  2752. } else {
  2753. noticeUtil::push("关单成功,订单号:{$orderSn} 原单状态:{$tradeState}", '15280215347');
  2754. }
  2755. }
  2756. // 如果状态是 CLOSED 或 CANCELED,则视为已关单,直接继续本地流程
  2757. }
  2758. }
  2759. $connection = Yii::$app->db;
  2760. $transaction = $connection->beginTransaction();
  2761. try {
  2762. OrderService::expire($order);
  2763. $transaction->commit();
  2764. util::complete('已取消');
  2765. } catch (\Exception $exception) {
  2766. $transaction->rollBack();
  2767. Yii::info("取消原因:" . $exception->getMessage());
  2768. util::fail('取消失败');
  2769. }
  2770. }
  2771. //获取收款语音播报地址 ssh 20211231
  2772. public function actionGetPayVoice()
  2773. {
  2774. $id = Yii::$app->request->get('id');
  2775. $order = OrderClass::getById($id, true);
  2776. $payWay = $order->payWay ?? 0;
  2777. $money = floatval($order->actPrice);
  2778. $payment = $payWay == dict::getDict('payWay', 'alipay') ? '支付宝' : '微信';
  2779. $msg = $payment . '收款' . $money . '元';
  2780. $audio = baiduAip::transfer($msg, 4, 0);
  2781. //上传到oss
  2782. $file = time() . rand(10000, 999999) . '.mp3';
  2783. $filePath = 'tmp/arrival/money/' . $file;
  2784. oss::uploadTmpAudio($filePath, $audio);
  2785. $url = Yii::$app->params['ghsImgHost'] . $filePath;
  2786. util::success(['url' => $url]);
  2787. }
  2788. //修改备注
  2789. public function actionModifyRemark()
  2790. {
  2791. $post = Yii::$app->request->post();
  2792. $id = $post['id'] ?? 0;
  2793. $remark = $post['remark'] ?? '';
  2794. $order = OrderClass::getById($id, true);
  2795. if (empty($order)) {
  2796. util::fail('没有找到订单');
  2797. }
  2798. if ($order->mainId != $this->mainId) {
  2799. util::fail('不是你的订单');
  2800. }
  2801. $cgId = $order->purchaseId ?? 0;
  2802. $cg = PurchaseClass::getById($cgId, true);
  2803. if (empty($cg)) {
  2804. util::fail('采购单没有找到');
  2805. }
  2806. $order->remark = $remark;
  2807. $order->save();
  2808. $cg->remark = $remark;
  2809. $cg->save();
  2810. util::complete('修改成功');
  2811. }
  2812. //修改订单的确认时间 ssh 20240511
  2813. public function actionModifyOrderConfirmTime()
  2814. {
  2815. $get = Yii::$app->request->get();
  2816. $id = $get['id'] ?? 0;
  2817. $date = $get['date'] ?? '';
  2818. if (empty($date)) {
  2819. util::fail('请选择日期');
  2820. }
  2821. $connection = Yii::$app->db;
  2822. $transaction = $connection->beginTransaction();//开启事务
  2823. try {
  2824. $order = OrderClass::getById($id, true);
  2825. if (empty($order)) {
  2826. util::fail('没有找到订单');
  2827. }
  2828. if ($order->mainId != $this->mainId) {
  2829. util::fail('不是你的订单');
  2830. }
  2831. if ($order->payStatus == 0) {
  2832. util::fail('没有确认的订单');
  2833. }
  2834. $mainId = $this->mainId;
  2835. //超管或者约定的人可以修改日期
  2836. if (getenv('YII_ENV') == 'production') {
  2837. if (in_array($mainId, [23390])) {
  2838. if (!in_array($this->adminId, [24586, 23960, 24043])) {
  2839. util::fail('你不能修改哦');
  2840. }
  2841. }
  2842. }
  2843. $payTime = $order->payTime;
  2844. $timeArr = explode(' ', $payTime);
  2845. $dateStr = $timeArr[0];
  2846. if ($dateStr == $date) {
  2847. util::fail('日期没变');
  2848. }
  2849. $after = $timeArr[1];
  2850. $new = $date . ' ' . $after;
  2851. $cgId = $order->purchaseId ?? 0;
  2852. $cg = PurchaseClass::getById($cgId, true);
  2853. if (empty($cg)) {
  2854. util::fail('没有找到订单信息');
  2855. }
  2856. $order->payTime = $new;
  2857. $order->save();
  2858. $cg->payTime = $new;
  2859. $cg->save();
  2860. //有修改账单日期需要更新到欠款变动明细,财务好对账,多个地方要同步修改,关键词 to_change_custom_debt_pay_time
  2861. CustomDebtChangeClass::updateByCondition(['capitalType' => 10, 'relateId' => $id], ['payTime' => $new]);
  2862. //找到当前订单客户的账单日期为 $date 的所有订单,然后更新同天内的所有订单的 sameTimeIds(加此次要改变的订单的订单号$id),有多处调用,关键词 update_same_ids
  2863. OrderClass::updateSameTimeIds($order, $date);
  2864. PurchaseClass::updateMergeCg($cg, 1);
  2865. OrderClass::updateMergeOrder($order, 1);
  2866. $transaction->commit();
  2867. util::complete('修改成功');
  2868. } catch (\Exception $e) {
  2869. $transaction->rollBack();
  2870. util::fail('修改失败');
  2871. }
  2872. }
  2873. //应收款统计 ssh 20240528
  2874. public function actionAccountList()
  2875. {
  2876. $get = Yii::$app->request->get();
  2877. $mainId = $this->mainId;
  2878. $export = $get['export'] ?? 0;
  2879. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : -1;
  2880. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2881. $startTime = $get['startTime'] ?? '';
  2882. $endTime = $get['endTime'] ?? '';
  2883. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2884. $start = $period['startTime'];
  2885. $end = $period['endTime'];
  2886. $customList = CustomClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name', 'id');
  2887. $currentStartDate = date('Y-m-d', strtotime($start));
  2888. $currentEndDate = date('Y-m-d', strtotime($end));
  2889. $currentStartTime = $currentStartDate . ' 00:00:00';
  2890. $currentEndTime = $currentEndDate . ' 23:59:59';
  2891. $where = ['mainId' => $mainId];
  2892. if ($debt > -1) {
  2893. $where['debt'] = $debt;
  2894. }
  2895. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  2896. $orderList = OrderClass::getAllByCondition($where, null, '*');
  2897. $list = [];
  2898. $totalAmount = 0;
  2899. if (!empty($orderList)) {
  2900. foreach ($orderList as $orderInfo) {
  2901. $actPrice = $orderInfo['actPrice'] ?? 0;
  2902. $customId = $orderInfo['customId'] ?? 0;
  2903. $status = $orderInfo['status'] ?? 0;
  2904. $book = $orderInfo['book'] ?? 0;
  2905. if ($status == 1 || $status == 5) {
  2906. continue;
  2907. }
  2908. if ($book == 1 && $status == 2) {
  2909. continue;
  2910. }
  2911. if (isset($list[$customId])) {
  2912. $list[$customId]['amount'] = bcadd($list[$customId]['amount'], $actPrice, 2);
  2913. $list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
  2914. } else {
  2915. $name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
  2916. $list[$customId] = ['id' => $customId, 'name' => $name, 'amount' => $actPrice, 'num' => 1];
  2917. }
  2918. $totalAmount = bcadd($totalAmount, $actPrice, 2);
  2919. }
  2920. $list = array_values($list);
  2921. }
  2922. if ($export == 1) {
  2923. if (empty($list)) {
  2924. util::fail('没有数据需要导出');
  2925. }
  2926. ini_set('memory_limit', '2045M');
  2927. set_time_limit(0);
  2928. OrderClass::exportAccountList($list, $mainId);
  2929. util::stop();
  2930. }
  2931. util::success(['list' => $list, 'totalAmount' => $totalAmount]);
  2932. }
  2933. //应收款统计 ssh 20240528
  2934. public function actionPastList()
  2935. {
  2936. $get = Yii::$app->request->get();
  2937. $export = $get['export'] ?? 0;
  2938. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2939. $startTime = $get['startTime'] ?? '';
  2940. $endTime = $get['endTime'] ?? '';
  2941. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2942. $end = $period['endTime'];
  2943. $customList = CustomClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name,mobile', 'id');
  2944. $currentDate = date('Y-m-d 00:00:00', bcadd(strtotime($end), 86400));
  2945. $totalAmount = 0;
  2946. if (!empty($customList)) {
  2947. foreach ($customList as $key => $custom) {
  2948. $customId = $custom['id'] ?? 0;
  2949. $change = CustomDebtChangeClass::getByCondition(['customId' => $customId, 'addTime<' => $currentDate], true, 'addTime DESC');
  2950. $amount = $change->balance ?? 0;
  2951. $totalAmount = bcadd($totalAmount, $amount, 2);
  2952. $customList[$key]['currentDebAmount'] = $amount;
  2953. }
  2954. $customList = array_values($customList);
  2955. }
  2956. if ($export == 1) {
  2957. $mainId = $this->mainId;
  2958. if (empty($customList)) {
  2959. util::fail('没有数据需要导出');
  2960. }
  2961. ini_set('memory_limit', '2045M');
  2962. set_time_limit(0);
  2963. OrderClass::exportPastList($customList, $mainId);
  2964. util::stop();
  2965. }
  2966. util::success(['list' => $customList, 'totalAmount' => $totalAmount]);
  2967. }
  2968. //客户业绩,有多个地方,需要同步,搜索关键词 customYj ssh 20240628
  2969. public function actionYj()
  2970. {
  2971. $get = Yii::$app->request->get();
  2972. $mainId = $this->mainId;
  2973. $export = $get['export'] ?? 0;
  2974. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : -1;
  2975. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2976. $startTime = $get['startTime'] ?? '';
  2977. $endTime = $get['endTime'] ?? '';
  2978. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2979. $start = $period['startTime'];
  2980. $end = $period['endTime'];
  2981. $customList = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, '*', 'id');
  2982. $currentStartDate = date('Y-m-d', strtotime($start));
  2983. $currentEndDate = date('Y-m-d', strtotime($end));
  2984. $currentStartTime = $currentStartDate . ' 00:00:00';
  2985. $currentEndTime = $currentEndDate . ' 23:59:59';
  2986. $where = ['mainId' => $mainId];
  2987. if ($debt > -1) {
  2988. $where['debt'] = $debt;
  2989. }
  2990. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  2991. $orderList = OrderClass::getAllByCondition($where, null, '*');
  2992. $list = [];
  2993. $totalActPrice = 0;
  2994. $totalOrderPrice = 0;
  2995. $totalCarton = 0;
  2996. $totalCartonNum = 0;
  2997. $totalPack = 0;
  2998. $totalFreight = 0;
  2999. $totalTkPrice = 0;
  3000. //增加项
  3001. $totalOnlyTkPrice = 0;
  3002. $totalNum = 0;
  3003. if (!empty($orderList)) {
  3004. foreach ($orderList as $orderInfo) {
  3005. $actPrice = $orderInfo['actPrice'] ?? 0;
  3006. $orderPrice = $orderInfo['orderPrice'] ?? 0;
  3007. $customId = $orderInfo['customId'] ?? 0;
  3008. $status = $orderInfo['status'] ?? 0;
  3009. $book = $orderInfo['book'] ?? 0;
  3010. $orderSn = $orderInfo['orderSn'] ?? '';
  3011. $tkPrice = $orderInfo['tkPrice'] ?? 0;
  3012. if ($status == 1 || $status == 5) {
  3013. continue;
  3014. }
  3015. if ($book == 1 && $status == 2) {
  3016. continue;
  3017. }
  3018. $carton = 0;
  3019. $cartonNum = 0;
  3020. $pack = 0;
  3021. $freight = 0;
  3022. $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  3023. if ($actPrice > 0) {
  3024. if (!empty($orderItemList)) {
  3025. foreach ($orderItemList as $orderItem) {
  3026. $num = $orderItem['xhNum'] ?? 0;
  3027. $unitPrice = $orderItem['xhUnitPrice'] ?? 0;
  3028. $refundNum = $orderItem['refundNum'] ?? 0;
  3029. $classId = $orderItem['classId'] ?? 0;
  3030. if (getenv('YII_ENV') == 'production') {
  3031. //小向算打包纸箱费用
  3032. if ($mainId == 23390) {
  3033. $remainNum = bcsub($num, $refundNum);
  3034. $amount = bcmul($remainNum, $unitPrice, 2);
  3035. if ($classId == 72106) {
  3036. $carton = bcadd($carton, $amount, 2);
  3037. $cartonNum = bcadd($cartonNum, $remainNum);
  3038. }
  3039. if ($classId == 72108) {
  3040. $pack = bcadd($pack, $amount, 2);
  3041. }
  3042. if ($classId == 73118) {
  3043. $freight = bcadd($freight, $amount, 2);
  3044. }
  3045. }
  3046. //花大苪
  3047. if ($mainId == 8164) {
  3048. $remainNum = bcsub($num, $refundNum);
  3049. $amount = bcmul($remainNum, $unitPrice, 2);
  3050. if ($classId == 90497) {
  3051. $carton = bcadd($carton, $amount, 2);
  3052. $cartonNum = bcadd($cartonNum, $remainNum);
  3053. }
  3054. if ($classId == 90501) {
  3055. $freight = bcadd($freight, $amount, 2);
  3056. }
  3057. }
  3058. //石头花艺
  3059. if ($mainId == 50) {
  3060. $remainNum = bcsub($num, $refundNum);
  3061. $amount = bcmul($remainNum, $unitPrice, 2);
  3062. if ($classId == 71495) {
  3063. $carton = bcadd($carton, $amount, 2);
  3064. $cartonNum = bcadd($cartonNum, $remainNum);
  3065. }
  3066. if ($classId == 91009) {
  3067. $freight = bcadd($freight, $amount, 2);
  3068. }
  3069. }
  3070. }
  3071. }
  3072. }
  3073. }
  3074. //增加项
  3075. if ($tkPrice > 0) {
  3076. $refundList = RefundOrderClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
  3077. if (!empty($refundList)) {
  3078. foreach ($refundList as $refundInfo) {
  3079. if ($refundInfo->status == 1) {
  3080. if ($refundInfo->refundType == 2) {
  3081. $refundPrice = $refundInfo->refundPrice ?? 0;
  3082. $totalOnlyTkPrice = bcadd($totalOnlyTkPrice, $refundPrice, 2);
  3083. }
  3084. }
  3085. }
  3086. }
  3087. }
  3088. $totalCarton = bcadd($totalCarton, $carton, 2);
  3089. $totalCartonNum = bcadd($totalCartonNum, $cartonNum);
  3090. $totalPack = bcadd($totalPack, $pack, 2);
  3091. $totalFreight = bcadd($totalFreight, $freight, 2);
  3092. $totalTkPrice = bcadd($totalTkPrice, $tkPrice, 2);
  3093. $totalActPrice = bcadd($totalActPrice, $actPrice, 2);
  3094. $totalOrderPrice = bcadd($totalOrderPrice, $orderPrice, 2);
  3095. $totalNum++;
  3096. if (isset($list[$customId])) {
  3097. $list[$customId]['actPrice'] = bcadd($list[$customId]['actPrice'], $actPrice, 2);
  3098. $list[$customId]['orderPrice'] = bcadd($list[$customId]['orderPrice'], $orderPrice, 2);
  3099. $list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
  3100. $list[$customId]['carton'] = bcadd($list[$customId]['carton'], $carton, 2);
  3101. $list[$customId]['cartonNum'] = bcadd($list[$customId]['cartonNum'], $cartonNum);
  3102. $list[$customId]['pack'] = bcadd($list[$customId]['pack'], $pack, 2);
  3103. $list[$customId]['freight'] = bcadd($list[$customId]['freight'], $freight, 2);
  3104. $list[$customId]['tkPrice'] = bcadd($list[$customId]['tkPrice'], $tkPrice, 2);
  3105. } else {
  3106. $name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
  3107. $mobile = $customList[$customId] && $customList[$customId]['mobile'] ? $customList[$customId]['mobile'] : '0';
  3108. $list[$customId] = [
  3109. 'id' => $customId,
  3110. 'name' => $name,
  3111. 'mobile' => $mobile,
  3112. 'orderPrice' => $orderPrice,
  3113. 'actPrice' => $actPrice,
  3114. 'num' => 1,
  3115. 'carton' => $carton,
  3116. 'cartonNum' => $cartonNum,
  3117. 'pack' => $pack,
  3118. 'freight' => $freight,
  3119. 'tkPrice' => $tkPrice,
  3120. ];
  3121. }
  3122. }
  3123. foreach ($customList as $key => $custom) {
  3124. $customId = $custom['id'] ?? 0;
  3125. if (isset($list[$customId]) == false) {
  3126. $list[$customId] = [
  3127. 'id' => $customId,
  3128. 'name' => $custom['name'],
  3129. 'mobile' => $custom['mobile'],
  3130. 'actPrice' => 0,
  3131. 'num' => 0,
  3132. 'carton' => 0,
  3133. 'pack' => 0,
  3134. 'freight' => 0,
  3135. 'tkPrice' => 0,
  3136. 'orderPrice' => 0,
  3137. ];
  3138. }
  3139. }
  3140. $list = array_values($list);
  3141. }
  3142. if ($export == 1) {
  3143. if (empty($list)) {
  3144. util::fail('没有数据需要导出');
  3145. }
  3146. ini_set('memory_limit', '2045M');
  3147. set_time_limit(0);
  3148. OrderClass::exportYj($list, $mainId);
  3149. util::stop();
  3150. }
  3151. util::success([
  3152. 'list' => $list,
  3153. 'totalActPrice' => $totalActPrice,
  3154. 'totalOrderPrice' => $totalOrderPrice,
  3155. 'totalCarton' => $totalCarton,
  3156. 'totalCartonNum' => $totalCartonNum,
  3157. 'totalNum' => $totalNum,
  3158. 'totalPack' => $totalPack,
  3159. 'totalFreight' => $totalFreight,
  3160. 'totalTkPrice' => $totalTkPrice,
  3161. //增加项
  3162. 'totalOnlyTkPrice' => $totalOnlyTkPrice,
  3163. ]);
  3164. }
  3165. //修改配送人 ssh 20240824
  3166. public function actionChangeSendStaff()
  3167. {
  3168. $staff = $this->shopAdmin;
  3169. if (isset($staff->finance) == false || $staff->finance == 0) {
  3170. util::fail('请有财务权限的人修改');
  3171. }
  3172. $get = Yii::$app->request->get();
  3173. $staffId = $get['staffId'] ?? 0;
  3174. $orderId = $get['orderId'] ?? 0;
  3175. $order = OrderClass::getById($orderId, true);
  3176. if (empty($order)) {
  3177. util::fail('没有找到订单');
  3178. }
  3179. if ($order->mainId != $this->mainId) {
  3180. util::fail('不是你的');
  3181. }
  3182. $staff = ShopAdminClass::getById($staffId, true);
  3183. if (empty($staff)) {
  3184. util::fail('没有找到员工');
  3185. }
  3186. if ($staff->mainId != $this->mainId) {
  3187. util::fail('不是你的员工');
  3188. }
  3189. $staffName = $staff->name ?? '';
  3190. $order->sendStaffId = $staffId;
  3191. $order->sendStaffName = $staffName;
  3192. $order->save();
  3193. util::complete('修改成功');
  3194. }
  3195. //导入开单 ssh 20241126
  3196. public function actionImportCreate()
  3197. {
  3198. ini_set('memory_limit', '2045M');
  3199. set_time_limit(0);
  3200. $connection = Yii::$app->db;
  3201. try {
  3202. $get = Yii::$app->request->get();
  3203. $customId = $get['id'] ?? '';
  3204. $customRes = CustomClass::getById($customId, true);
  3205. if (empty($customRes)) {
  3206. util::fail('没有找到客户');
  3207. }
  3208. if ($customRes->ownMainId != $this->mainId) {
  3209. util::fail('不是你的客户');
  3210. }
  3211. if (isset($customRes->mainId) && !empty($customRes->mainId) && $customRes->mainId == $customRes->ownMainId) {
  3212. util::fail('不能给自己开单');
  3213. }
  3214. $file = $_FILES['file'];
  3215. if (!is_uploaded_file($file['tmp_name'])) {
  3216. util::fail('please upload img');
  3217. }
  3218. $mainId = $this->mainId;
  3219. $sjId = $this->sjId;
  3220. $shopId = $this->shopId;
  3221. $month = date("Ym");
  3222. $date = date("d");
  3223. $path = dirUtil::getImgUploadDir() . "/{$mainId}/kd/{$shopId}/{$month}/{$date}/";
  3224. if (!file_exists($path)) {
  3225. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  3226. mkdir($path, 0700, true);
  3227. }
  3228. $preFileName = stringUtil::uniqueFileName();
  3229. $newFile = $preFileName . ".xls";
  3230. $fullPathFile = $path . $newFile;
  3231. if (move_uploaded_file($file['tmp_name'], $fullPathFile)) {
  3232. $arr = [];
  3233. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  3234. require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');
  3235. $spreadsheet = \PHPExcel_IOFactory::load($fullPathFile);
  3236. // 获取活动工作表
  3237. $worksheet = $spreadsheet->getActiveSheet();
  3238. // 遍历每一行
  3239. foreach ($worksheet->getRowIterator() as $key => $row) {
  3240. $cellIterator = $row->getCellIterator();
  3241. // 这里设置为迭代所有单元格,包括空单元格
  3242. $cellIterator->setIterateOnlyExistingCells(FALSE);
  3243. // 遍历每列
  3244. $rowData = [];
  3245. foreach ($cellIterator as $cell) {
  3246. $option = $cell->getValue();
  3247. $rowData[] = trim($option);
  3248. }
  3249. $arr[] = $rowData;
  3250. }
  3251. array_shift($arr);
  3252. $productIds = [];
  3253. foreach ($arr as $k => $v) {
  3254. $productId = $v[0] ?? 0;
  3255. $productId = trim($productId);
  3256. if (is_numeric($productId) && $productId > 0) {
  3257. $productIds[] = $productId;
  3258. }
  3259. }
  3260. if (empty($productIds)) {
  3261. util::fail('没有识别出花材');
  3262. }
  3263. $productInfo = ProductClass::getByIds($productIds, null, 'id');
  3264. if (empty($productInfo)) {
  3265. util::fail('没有找到有效花材');
  3266. }
  3267. $mat = [];
  3268. foreach ($arr as $k => $v) {
  3269. $productId = $v[0] ?? 0;
  3270. $productId = trim($productId);
  3271. $num = $v[2] ?? 0;
  3272. $num = trim($num);
  3273. $unitPrice = $v[3] ?? 0;
  3274. $unitPrice = trim($unitPrice);
  3275. $remark = $v['5'] ?? '';
  3276. $remark = trim($remark);
  3277. if (is_numeric($productId) && $productId > 0 && $num > 0 && $unitPrice > 0) {
  3278. $product = $productInfo[$productId] ?? [];
  3279. $ptItemId = $product['itemId'] ?? 0;
  3280. $mat[] = [
  3281. 'productId' => $productId,
  3282. 'bigNum' => $num,
  3283. 'itemId' => $ptItemId,
  3284. 'smallNum' => 0,
  3285. 'price' => $unitPrice,
  3286. 'remark' => $remark,
  3287. ];
  3288. }
  3289. }
  3290. $modifyPrice = 0;
  3291. foreach ($mat as $ma) {
  3292. $cNum = $ma['bigNum'] ?? 0;
  3293. $cPrice = $ma['price'] ?? 0;
  3294. $cTotal = bcmul($cNum, $cPrice, 2);
  3295. $modifyPrice = bcadd($modifyPrice, $cTotal, 2);
  3296. }
  3297. $customName = $customRes->name ?? '';
  3298. $customMobile = $customRes->mobile ?? '';
  3299. $customPy = $customRes->py ?? '';
  3300. $ghsId = $customRes->ghsId ?? 0;
  3301. $hasPay = 2;
  3302. $custom = CustomClass::getCustom($customId);
  3303. $post = [];
  3304. $post['modifyPrice'] = $modifyPrice;
  3305. $post['shopId'] = $shopId;
  3306. $post['sendType'] = 0;
  3307. $post['transType'] = 0;
  3308. $post['sendSide'] = 0;
  3309. $post['sendCost'] = 0;
  3310. $post['packCost'] = 0;
  3311. $post['customId'] = $customId;
  3312. $post['customName'] = $customName;
  3313. $post['payWay'] = 0;
  3314. $post['needPrint'] = 2;
  3315. $post['hasPay'] = 2;
  3316. $post['product'] = $mat;
  3317. $post['deadline'] = date("Y-m-d H:i:s", time() + 86400);
  3318. $post['debt'] = 1;
  3319. $post['mainId'] = $mainId;
  3320. $post['fromType'] = 1;
  3321. $post['expressId'] = 0;
  3322. $post['sjId'] = $sjId;
  3323. $staff = $this->shopAdmin;
  3324. $staffId = $staff->id ?? 0;
  3325. $staffName = $staff->name ?? '';
  3326. $post['shopAdminId'] = $staffId;
  3327. $post['shopAdminName'] = $staffName;
  3328. $post['getStaffId'] = $staffId;
  3329. $post['getStaffName'] = $staffName;
  3330. $post['customMobile'] = $customMobile;
  3331. $post['customNamePy'] = $customPy;
  3332. $post['customAvatar'] = '';
  3333. $post['newVersion'] = 1;
  3334. $post['book'] = 1;
  3335. $post['wlName'] = '';
  3336. $post['dealPrice'] = 1;
  3337. $post['ghsId'] = $ghsId;
  3338. $shop = $this->shop;
  3339. $bookSn = $shop->bookSn ?? 0;
  3340. $post['bookSn'] = $bookSn;
  3341. // 复杂分支/关键逻辑:优化。去除了并发重试机制 runWithDbConcurrencyRetry,降低锁等待和额外重试带来的性能瓶颈
  3342. // 底层在发货和收货扣减库存时,使用商品 ID 升序排序加锁(SELECT FOR UPDATE)策略,100% 杜绝交叉死锁,因此这里无需再做重试。
  3343. $transaction = $connection->beginTransaction();
  3344. try {
  3345. OrderService::createNewOrder($post, $custom, $hasPay);
  3346. $transaction->commit();
  3347. } catch (\Exception $exception) {
  3348. if ($transaction->isActive) {
  3349. $transaction->rollBack();
  3350. }
  3351. throw $exception;
  3352. }
  3353. util::complete('提交成功');
  3354. } else {
  3355. util::fail('上传失败了,出错了哦');
  3356. }
  3357. } catch (\Exception $e) {
  3358. Yii::info("导入失败了," . $e->getMessage());
  3359. noticeUtil::push('导入失败,失败原因:' . $e->getMessage(), '15280215347');
  3360. $msg = $e->getMessage();
  3361. util::fail('导入失败:' . $msg);
  3362. }
  3363. }
  3364. //打印发物流用和标签 ssh 20250312
  3365. public function actionPrintWlLabel()
  3366. {
  3367. $get = Yii::$app->request->get();
  3368. $id = $get['id'] ?? 0;
  3369. $order = OrderClass::getById($id, true);
  3370. if (empty($order)) {
  3371. util::fail('没有找到订单');
  3372. }
  3373. if ($order->payStatus == 0) {
  3374. util::fail('订单没有付款');
  3375. }
  3376. $ext = $this->shopExt;
  3377. $shop = $this->shop;
  3378. OrderClass::printLogisticsLabel($order, $shop, $ext);
  3379. util::complete('打印成功');
  3380. }
  3381. //修改地址 ssh 20251123
  3382. public function actionModifyAddress()
  3383. {
  3384. $post = Yii::$app->request->post();
  3385. $id = $post['id'] ?? 0;
  3386. $order = OrderClass::getById($id, true);
  3387. if (empty($order)) {
  3388. util::fail('没有找到订单');
  3389. }
  3390. if ($order->mainId != $this->mainId) {
  3391. util::fail('不是你的订单,不能修改地址');
  3392. }
  3393. if ($order->status == 3) {
  3394. util::fail('订单已经在配送了,不能修改地址');
  3395. }
  3396. if ($order->status == 4) {
  3397. util::fail('订单已完成,不能修改地址');
  3398. }
  3399. $province = $post['province'] ?? '';
  3400. $city = $post['city'] ?? '';
  3401. $dist = $post['dist'] ?? '';
  3402. $address = $post['address'] ?? '';
  3403. $floor = $post['floor'] ?? '';
  3404. $fullAddress = $city . $dist . $address . $floor;
  3405. $lat = $post['lat'] ?? '';
  3406. $long = $post['long'] ?? '';
  3407. $showAddress = $post['showAddress'] ?? '';
  3408. $order->province = $province;
  3409. $order->city = $city;
  3410. $order->dist = $dist;
  3411. $order->address = $address;
  3412. $order->floor = $floor;
  3413. $order->showAddress = $showAddress;
  3414. $order->fullAddress = $fullAddress;
  3415. $order->lat = $lat;
  3416. $order->long = $long;
  3417. $order->save();
  3418. $syncDefaultAddress = $post['syncDefaultAddress'] ?? 0;
  3419. if ($syncDefaultAddress == 1) {
  3420. $customId = $order->customId ?? 0;
  3421. $custom = CustomClass::getById($customId, true);
  3422. if (!empty($custom)) {
  3423. $custom->province = $province;
  3424. $custom->city = $city;
  3425. $custom->dist = $dist;
  3426. $custom->address = $address;
  3427. $custom->floor = $floor;
  3428. $custom->showAddress = $showAddress;
  3429. $custom->fullAddress = $fullAddress;
  3430. $custom->lat = $lat;
  3431. $custom->long = $long;
  3432. $custom->save();
  3433. }
  3434. }
  3435. util::complete('修改成功');
  3436. }
  3437. }