OrderController.php 155 KB

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