OrderController.php 191 KB

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