OrderController.php 182 KB

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