OrderController.php 155 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933
  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. noticeUtil::push($msg.' '.$retCode.' 编号145539', '15280215347');
  730. util::success(['returnStatus' => 'FAILURE'], $msg);
  731. }
  732. } catch (\Exception $e) {
  733. $transaction->rollBack();
  734. Yii::error("支付失败原因:" . $e->getMessage());
  735. util::fail('支付失败');
  736. }
  737. }
  738. //订单列表 ssh 2021.1.20
  739. public function actionList()
  740. {
  741. $get = Yii::$app->request->get();
  742. $export = $get['export'] ?? 0;
  743. $onlySend = $get['onlySend'] ?? 0;
  744. ini_set('memory_limit', '5045M');
  745. set_time_limit(0);
  746. $staff = $this->shopAdmin;
  747. if (isset($staff->identity) && $staff->identity == 2) {
  748. //如果用于确认发货时要显出订单
  749. if ($onlySend == 0) {
  750. util::success(['list' => []]);
  751. }
  752. }
  753. $where['mainId'] = $this->mainId;
  754. $status = $get['status'] ?? 0;
  755. if (!empty($status)) {
  756. $where['status'] = $status;
  757. }
  758. $clearSign = $get['clearSign'] ?? -1;
  759. if ($clearSign > -1) {
  760. $where['clearSign'] = $clearSign;
  761. }
  762. $book = $get['book'] ?? -1;
  763. if ($book > -1) {
  764. $where['book'] = $book;
  765. }
  766. $searchTime = $get['searchTime'] ?? '';
  767. if (!empty($searchTime)) {
  768. $startTime = $get['startTime'] ?? '';
  769. $endTime = $get['endTime'] ?? '';
  770. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  771. $where['payTime'] = ['between', [$period['startTime'], $period['endTime']]];
  772. }
  773. if ($export == 1) {
  774. ini_set('memory_limit', '2045M');
  775. set_time_limit(0);
  776. if (isset($where['payTime']) == false) {
  777. util::fail('请选时间段');
  778. }
  779. $start = $where['payTime'][1][0];
  780. $end = $where['payTime'][1][1];
  781. $monthTime = bcmul(31, 86400);
  782. $startArea = strtotime($start);
  783. $endArea = strtotime($end);
  784. $diff = bcsub($endArea, $startArea);
  785. if ($diff > $monthTime) {
  786. util::fail('最长可导出一个月');
  787. }
  788. }
  789. $name = $get['name'] ?? '';
  790. if (!empty($name)) {
  791. $searchType = $get['searchType'] ?? 0;
  792. if (empty($searchType)) {
  793. //订单编号
  794. if (strpos($name, 'XSD') === 0) {
  795. $where['orderSn'] = $name;
  796. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  797. $where['customNamePy'] = ['like', $name];
  798. } else {
  799. $where['customName'] = ['like', $name];
  800. }
  801. } elseif ($searchType == 1) {
  802. $where['sendNum'] = $name;
  803. } else {
  804. }
  805. }
  806. if (isset($get['customId']) && !empty($get['customId'])) {
  807. $where['customId'] = $get['customId'];
  808. }
  809. if (isset($get['ids']) && !empty($get['ids'])) {
  810. $stringIds = $get['ids'];
  811. $newIds = explode(',', $stringIds);
  812. $where['id'] = ['in', $newIds];
  813. }
  814. //选择开单人
  815. $shopAdminId = $get['shopAdminId'] ?? 0;
  816. if (!empty($shopAdminId)) {
  817. $where['shopAdminId'] = $shopAdminId;
  818. }
  819. $respond = OrderClass::getOrderList($where);
  820. if ($export == 1) {
  821. OrderClass::exportOrderData($respond, $this->mainId);
  822. }
  823. $respond['shop'] = $this->shop;
  824. $respond['shopExt'] = $this->shopExt;
  825. util::success($respond);
  826. }
  827. // 新订单列表详情 -- 可能与 actionList 很相似,但为不影响 actionList,重新创建个方法 shizhongqi 2022.06.23
  828. public function actionNewOrderList()
  829. {
  830. $get = Yii::$app->request->get();
  831. $where['shopId'] = $this->shopId;
  832. /*$status = $get['status'] ?? 0;
  833. if (!empty($status)) {
  834. $where['status'] = $status;
  835. }*/
  836. // 按类别生成查询条件:1.今日实收 2.今日欠款 3.总欠款(所有历史欠款)
  837. if (isset($get['type'])) {
  838. $type = $get['type'];
  839. if ($type == 1) { // 今日实收
  840. $get['searchTime'] = 'today';
  841. $where['debt'] = 0;
  842. $where['debtPrice'] = '0.00';
  843. $where['status'] = ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]];
  844. } elseif ($type == 2) { // 今日欠款
  845. $get['searchTime'] = 'today';
  846. $where['debt'] = 1;
  847. } elseif ($type == 3) { // 总欠款
  848. $where['debt'] = 1;
  849. } else {
  850. util::fail('查询的订单类别不存在');
  851. }
  852. }
  853. $searchTime = $get['searchTime'] ?? '';
  854. if (!empty($searchTime)) {
  855. $startTime = '';
  856. $endTime = '';
  857. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  858. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  859. }
  860. $name = $get['name'] ?? '';
  861. if (!empty($name)) {
  862. $searchType = $get['searchType'] ?? 0;
  863. if (empty($searchType)) {
  864. //订单编号
  865. if (strpos($name, 'XSD') === 0) {
  866. $where['orderSn'] = $name;
  867. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  868. $where['customNamePy'] = ['like', $name];
  869. } else {
  870. $where['customName'] = ['like', $name];
  871. }
  872. } elseif ($searchType == 1) {
  873. $where['sendNum'] = $name;
  874. } else {
  875. util::fail('搜索的订单类别不存在');
  876. }
  877. }
  878. $respond = OrderClass::getOrderList($where);
  879. $respond['shop'] = $this->shop;
  880. $respond['shopExt'] = $this->shopExt;
  881. $respond['type'] = $type; //把查询类别返回
  882. util::success($respond);
  883. }
  884. //商城下单操作 ssh 2021.1.14
  885. public function actionCreateOrder()
  886. {
  887. $post = Yii::$app->request->post();
  888. $shopId = $this->shopId;
  889. $customId = $post['customId'] ?? 0;
  890. $post['customId'] = $customId;
  891. //开单必须选客户
  892. if (empty($customId)) {
  893. util::fail('请选择客户');
  894. }
  895. $modifyPrice = $post['modifyPrice'] ?? 0;
  896. $pattern = '/^\d+(\.\d{1,2})?$/';
  897. if ($modifyPrice > 0) {
  898. if (preg_match($pattern, $modifyPrice) == false) {
  899. //容错前端
  900. util::fail('金额不能超2位小数');
  901. }
  902. }
  903. $custom = CustomClass::getCustom($customId);
  904. if (empty($custom)) {
  905. util::fail('请选客户哦');
  906. }
  907. $shopAdmin = $this->shopAdmin;
  908. $shopAdminId = $this->shopAdminId;
  909. $shopAdminName = $shopAdmin->name ?? '';
  910. //n秒内不允许重复提交,有多个地方要同步修改,关键词ghs_custom_create_order_redis
  911. $createOrderCacheKey = 'ghs_custom_create_order_' . $customId . '_' . $shopAdminId;
  912. $has = Yii::$app->redis->executeCommand('GET', [$createOrderCacheKey]);
  913. if (!empty($has)) {
  914. util::fail('已提交过,5秒后再试');
  915. }
  916. Yii::$app->redis->executeCommand('SETEX', [$createOrderCacheKey, 5, 'has']);
  917. CustomClass::valid($custom, $this->shopId);
  918. if (!empty($custom['mainId']) && $custom['mainId'] == $custom['ownMainId']) {
  919. util::fail('不能给自己开单');
  920. }
  921. $post['ghsId'] = $custom['ghsId'] ?? 0;
  922. $post['customMobile'] = $custom['mobile'] ?? '';
  923. $customName = $custom['name'] ?? '';
  924. $post['customName'] = $customName;
  925. $post['customNamePy'] = $custom['py'] ?? '';
  926. $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
  927. $post['province'] = $custom['province'] ?? '';
  928. $post['city'] = $custom['city'] ?? '';
  929. $post['dist'] = $custom['dist'] ?? '';
  930. $post['address'] = $custom['address'] ?? '';
  931. $post['floor'] = $custom['floor'] ?? '';
  932. $post['fullAddress'] = $custom['fullAddress'] ?? '';
  933. $post['showAddress'] = $custom['showAddress'] ?? '';
  934. $post['long'] = $custom['long'] ?? '';
  935. $post['lat'] = $custom['lat'] ?? '';
  936. if (!empty($post['getStaffId'])) {
  937. if (getenv('YII_ENV') == 'production') {
  938. $tbMainId = 44171;
  939. } else {
  940. $tbMainId = 644;
  941. }
  942. if ($this->mainId == $tbMainId) {
  943. //平潭花天下,就算选了收款人,也不要给改变开单人,临时解决方案 ssh 2250314
  944. if (!empty($post['shopAdminId'])) {
  945. $getStaffName = $post['shopAdminName'] ?? '';
  946. $shopAdminId = $post['shopAdminId'];
  947. $shopAdminName = $getStaffName;
  948. }
  949. } else {
  950. $getStaffName = $post['getStaffName'] ?? '';
  951. $shopAdminId = $post['getStaffId'];
  952. $shopAdminName = $getStaffName;
  953. }
  954. } else {
  955. if (getenv('YII_ENV') == 'production') {
  956. //鹏诚需要选择开单人
  957. if (in_array($this->mainId, [19606])) {
  958. util::fail('请选择开单人');
  959. }
  960. } else {
  961. if (in_array($this->mainId, [])) {
  962. util::fail('请选择开单人');
  963. }
  964. }
  965. }
  966. if (getenv('YII_ENV') == 'production') {
  967. //小向花卉开单售后控制
  968. if ($this->mainId == 23390) {
  969. if (!in_array($this->adminId, [24043, 24585, 24586, 24654, 24115, 23960, 28456, 31105, 28456, 31105,52528])) {
  970. util::fail('你不能开单哦');
  971. }
  972. }
  973. }
  974. //开单人和收款人必定是同个人
  975. $post['shopAdminId'] = $shopAdminId;
  976. $post['shopAdminName'] = $shopAdminName;
  977. $post['getStaffId'] = $shopAdminId;
  978. $post['getStaffName'] = $shopAdminName;
  979. $post['sjId'] = $this->sjId;
  980. $post['shopId'] = $shopId;
  981. $post['mainId'] = $this->mainId;
  982. $post['fromType'] = 1;
  983. $post['expressId'] = $post['expressId'] ?? 0;
  984. $book = $post['book'] ?? 0;
  985. $post['book'] = $book;
  986. $sendType = $post['sendType'] ?? 0;
  987. $transType = $post['transType'] ?? 0;
  988. $shop = $this->shop;
  989. if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
  990. //昆明发往全国
  991. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  992. $post['sendCost'] = $sendCost;
  993. $packCost = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  994. $post['packCost'] = $packCost;
  995. $post['transType'] = $transType;
  996. $post['localOrder'] = 1;
  997. } else {
  998. //同步配送
  999. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  1000. if ($sendType != dict::getDict('sendType', 'thirdSend') && $sendCost > 0) {
  1001. util::fail('填了运费,请选择代叫跑腿');
  1002. }
  1003. $post['sendCost'] = $sendCost;
  1004. $post['packCost'] = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  1005. }
  1006. if ($book == 1) {
  1007. $bookSn = $shop->bookSn ?? 0;
  1008. if (empty($bookSn)) {
  1009. util::fail('请开启预订');
  1010. }
  1011. $post['bookSn'] = $bookSn;
  1012. }
  1013. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  1014. $post['debt'] = OrderClass::DEBT_NO;
  1015. if ($hasPay == dict::getDict('hasPay', 'debt')) {
  1016. $post['debt'] = OrderClass::DEBT_YES;
  1017. }
  1018. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1019. if ($hasPay == dict::getDict('hasPay', 'payed')) {
  1020. //util::fail('没有权限');
  1021. }
  1022. }
  1023. if (getenv('YII_ENV') == 'production') {
  1024. if ($this->mainId == 1082) {
  1025. //泉城鲜花批发的出车,只能开收现金方式,多处要修改,关键词qc_cash
  1026. if ($hasPay != 0) {
  1027. util::fail('只能使用扫码付款,编号193');
  1028. }
  1029. }
  1030. } else {
  1031. if ($this->mainId == 644) {
  1032. if ($hasPay != 0) {
  1033. //util::fail('只能使用扫码付款,编号190');
  1034. }
  1035. }
  1036. }
  1037. //多颜色数据整理
  1038. $colorItem = $post['xj'] ?? [];
  1039. $newXj = [];
  1040. if (!empty($colorItem)) {
  1041. $colorData = json_decode($colorItem, true);
  1042. if (!empty($colorData) && is_array($colorData)) {
  1043. foreach ($colorData as $colorInfo) {
  1044. $ptItemId = $colorInfo['ptItemId'] ?? 0;
  1045. $colorList = $colorInfo['list'] ?? [];
  1046. if (!empty($colorList)) {
  1047. foreach ($colorList as $colorItemKey => $colorItem) {
  1048. $newXj[$ptItemId][] = $colorItem;
  1049. }
  1050. }
  1051. }
  1052. }
  1053. }
  1054. $post['xj'] = $newXj;
  1055. $productJson = $post['product'] ?? '';
  1056. if (empty($productJson)) {
  1057. util::fail('请选择花材');
  1058. }
  1059. $productList = json_decode($productJson, true);
  1060. if (empty($productList)) {
  1061. util::fail('请选择花材');
  1062. }
  1063. $dealPrice = $post['dealPrice'] ?? 0;
  1064. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  1065. $itemInfo = ProductClass::getByIds($ids, null, 'id');
  1066. if (empty($itemInfo)) {
  1067. util::fail('请选择花材哦');
  1068. }
  1069. //判断花材有效性
  1070. foreach ($itemInfo as $itemData) {
  1071. if (isset($itemData['mainId']) == false || $itemData['mainId'] != $this->mainId) {
  1072. util::fail('只能选择同一家的商品哈');
  1073. }
  1074. }
  1075. //解决开单提交订单时,别人修改价格,造成提交价格不是真实卖价问题!!
  1076. if ($dealPrice == 0) {
  1077. $diff = [];
  1078. $priceMap = CustomClass::$levelPriceKeyMap;
  1079. $addPriceMap = CustomClass::$levelAddPriceKeyMap;
  1080. $level = $custom['level'] ?? 1;
  1081. foreach ($productList as $currentKey => $currentProduct) {
  1082. $currentPrice = $currentProduct['price'] ?? 0;
  1083. $currentId = $currentProduct['productId'] ?? 0;
  1084. $systemInfo = $itemInfo[$currentId] ?? [];
  1085. $name = $systemInfo['name'] ?? '';
  1086. $systemPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
  1087. if (floatval($currentPrice) != floatval($systemPrice)) {
  1088. $diff[] = [
  1089. 'name' => $name,
  1090. 'price' => $systemPrice,
  1091. 'kdPrice' => $currentPrice,
  1092. ];
  1093. }
  1094. }
  1095. if (!empty($diff)) {
  1096. //n秒内不允许重复提交,有多个地方要同步修改,关键词ghs_custom_create_order_redis
  1097. Yii::$app->redis->executeCommand('DEL', [$createOrderCacheKey]);
  1098. util::success(['diff' => $diff, 'respondType' => 'priceError']);
  1099. }
  1100. }
  1101. if ($book == 1) {
  1102. $post['hasPay'] = 2;
  1103. $post['payWay'] = 0;
  1104. }
  1105. $historyDate = $post['historyDate'] ?? '';
  1106. if (!empty($historyDate)) {
  1107. if ($book == 1) {
  1108. util::fail('预订单不能选订单日期');
  1109. }
  1110. if ($hasPay == 0) {
  1111. util::fail('扫码付不能选订单日期');
  1112. }
  1113. if (strtotime($historyDate) > strtotime(date("Y-m-d"))) {
  1114. util::fail('订单日期只能选历史时间');
  1115. }
  1116. }
  1117. $connection = Yii::$app->db;
  1118. $transaction = $connection->beginTransaction();
  1119. try {
  1120. $post['product'] = $productList;
  1121. //商家开单到时间会自动标记为欠款,所以360天内不过期,以保证足够时间标记欠款,具体参数查看dict local_gys_kd_auto_set_debt_time
  1122. $time = time();
  1123. $hasTime = dict::getDict('order_pay_has_time');
  1124. $totalTime = bcadd($time, $hasTime);
  1125. $post['deadline'] = date("Y-m-d H:i:s", $totalTime);
  1126. //多处有用到此方法,需要同步修改,搜索关键词create_new_order
  1127. $return = OrderService::createNewOrder($post, $custom, $hasPay);
  1128. $transaction->commit();
  1129. $saleId = $return->id ?? 0;
  1130. $order = OrderClass::getById($saleId, true);
  1131. if (!empty($order)) {
  1132. $shopId = $order->shopId ?? 0;
  1133. $customId = $order->customId ?? 0;
  1134. $ghsId = $order->ghsId ?? 0;
  1135. $custom = CustomClass::getById($customId, true);
  1136. $date = date("Y-m-d H:i:s");
  1137. if (!empty($custom)) {
  1138. $custom->recentExpend = $date;
  1139. $custom->save();
  1140. }
  1141. $ghs = GhsClass::getById($ghsId, true);
  1142. if (!empty($ghs)) {
  1143. $ghs->recentExpend = $date;
  1144. $ghs->save();
  1145. }
  1146. $shop = ShopClass::getById($shopId, true);
  1147. if (isset($order->payStatus) && $order->payStatus == 1) {
  1148. if (!empty($shop)) {
  1149. //通知员工
  1150. $noticeText = json_encode(['orderId' => $saleId]);
  1151. $noticeKey = "hdCgNoticeGhs";
  1152. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1153. //通知花店
  1154. // $noticeText = json_encode(['id' => $order->purchaseId]);
  1155. // $noticeKey = "ghsKdNoticeHd";
  1156. // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1157. }
  1158. }
  1159. //订单生成时唤起在线打印
  1160. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1161. //预订单开单不打小票,小向花卉不需要打小票
  1162. $mainId = $order->mainId ?? 0;
  1163. if ($order->book == 0 && !in_array($mainId, [23390])) {
  1164. if ($order->status != 1 && $order->status != 5) {
  1165. OrderClass::onlinePrint($order);
  1166. $ext = $this->shopExt;
  1167. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1168. $order->printNum += 1;
  1169. $order->save();
  1170. }
  1171. //xxx自己开单要打二次,有多处要修改搜索关键词 tow_print
  1172. if (in_array($mainId, [0])) {
  1173. OrderClass::onlinePrint($order);
  1174. $ext = $this->shopExt;
  1175. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1176. $order->printNum += 1;
  1177. $order->save();
  1178. }
  1179. }
  1180. }
  1181. }
  1182. }
  1183. //前台提醒出示付款码
  1184. if (isset($order->status) && $order->status == 1) {
  1185. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  1186. ShopExtClass::ghsPleasePayReport($order);
  1187. }
  1188. }
  1189. }
  1190. util::success($return);
  1191. } catch (\Exception $e) {
  1192. $transaction->rollBack();
  1193. Yii::error("下单失败原因:" . $e->getMessage());
  1194. noticeUtil::push("零售下单失败原因:" . $e->getMessage(), '15280215347');
  1195. util::fail('下单失败');
  1196. }
  1197. }
  1198. //修改订单 ssh 20210810
  1199. public function actionUpdateOrder()
  1200. {
  1201. $post = Yii::$app->request->post();
  1202. util::fail('订单不可修改');
  1203. //PC端开单
  1204. if (isset($post['clearType'])) {
  1205. $clearType = $post['clearType'];
  1206. if ($clearType == OrderClass::CLEAR_DEBT) {
  1207. $post['debt'] = OrderClass::DEBT_YES;
  1208. $post['payWay'] = dict::getDict('payWay', 'debtPay');
  1209. } else {
  1210. $post['debt'] = OrderClass::DEBT_NO;
  1211. }
  1212. }
  1213. //员工不能开已收款订单
  1214. $debt = $post['debt'] ?? OrderClass::DEBT_YES;
  1215. if ($debt == OrderClass::DEBT_NO) {
  1216. $shopAdmin = $this->shopAdmin;
  1217. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1218. util::fail('不能开已收款订单');
  1219. }
  1220. }
  1221. //PC端开单
  1222. if (isset($post['getType'])) {
  1223. util::fail('暂不支持PC端修改订单');
  1224. $getType = $post['getType'];
  1225. //自取
  1226. if ($getType == 1) {
  1227. $post['sendType'] = OrderClass::SEND_TYPE_NO;
  1228. } else {
  1229. //选择配送时,在发货时让商家自己再确认一下用什么方式
  1230. $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN;
  1231. }
  1232. }
  1233. //商家开非自取订单,默认订单是待收款的,debt字段为非欠款
  1234. if (isset($post['sendType']) && $post['sendType'] != OrderClass::SEND_TYPE_NO) {
  1235. $post['debt'] = OrderClass::DEBT_NO;
  1236. }
  1237. $id = $post['id'] ?? 0;
  1238. $order = OrderClass::getLockById($id);
  1239. if (empty($order)) {
  1240. util::fail('没有找到订单');
  1241. }
  1242. OrderClass::valid($order, $this->shopId);
  1243. unset($post['id']);
  1244. $shopAdmin = $this->shopAdmin;
  1245. $post['shopAdminId'] = $this->shopAdminId;
  1246. $post['shopAdminName'] = $shopAdmin->name ?? '';
  1247. $post['fromType'] = 1;
  1248. $post['sendCost'] = $post['sendCost'] ?? '0.00';
  1249. $productJson = $post['product'] ?? '';
  1250. if (empty($productJson)) {
  1251. util::fail('请选择花材');
  1252. }
  1253. $productList = json_decode($productJson, true);
  1254. if (empty($productList)) {
  1255. util::fail('请选择花材');
  1256. }
  1257. $connection = Yii::$app->db;
  1258. $transaction = $connection->beginTransaction();
  1259. try {
  1260. //判断花材有效性
  1261. ProductClass::valid($productList, $this->mainId);
  1262. $post['product'] = $productList;
  1263. //商家开单订单有效期,到期记欠款
  1264. $validTime = dict::getDict('order_pay_has_time');
  1265. $current = time() + $validTime;
  1266. $post['deadline'] = date("Y-m-d H:i:s", $current);
  1267. $upData = [
  1268. 'payWay' => $post['payWay'],
  1269. 'sendType' => $post['sendType'],
  1270. 'debt' => $post['debt'],
  1271. 'needPrint' => $post['needPrint'],
  1272. 'modifyPrice' => $post['modifyPrice'],
  1273. 'shopAdminId' => $post['shopAdminId'],
  1274. 'shopAdminName' => $post['shopAdminName'],
  1275. 'fromType' => 1,
  1276. 'sendCost' => $post['sendCost'],
  1277. 'product' => $post['product'],
  1278. 'deadline' => $post['deadline'],
  1279. 'debt' => $post['debt'],
  1280. ];
  1281. $return = OrderService::updateOrder($order, $upData);
  1282. $transaction->commit();
  1283. util::success($return);
  1284. } catch (\Exception $e) {
  1285. $transaction->rollBack();
  1286. Yii::error("下单失败原因:" . $e->getMessage());
  1287. util::fail('下单失败');
  1288. }
  1289. }
  1290. //取消预订单 ssh 20240503
  1291. public function actionCancelBookOrder()
  1292. {
  1293. $get = Yii::$app->request->get();
  1294. $id = $get['id'] ?? 0;
  1295. if (empty($id)) {
  1296. util::fail('请选择订单');
  1297. }
  1298. $order = OrderClass::getById($id, true);
  1299. if (empty($order)) {
  1300. util::fail('没有找到订单');
  1301. }
  1302. OrderClass::valid($order, $this->shopId);
  1303. if ($order->book == 0) {
  1304. util::fail('不是预订单');
  1305. }
  1306. if ($order->status != 2) {
  1307. util::fail('当前订单状态不能取消');
  1308. }
  1309. $purchaseId = $order->purchaseId ?? 0;
  1310. $purchase = PurchaseClass::getById($purchaseId, true);
  1311. if (empty($purchase)) {
  1312. util::fail('没有找到采购单');
  1313. }
  1314. $connection = Yii::$app->db;
  1315. $transaction = $connection->beginTransaction();
  1316. try {
  1317. $order->status = 5;
  1318. $order->save();
  1319. $purchase->status = 5;
  1320. $purchase->save();
  1321. $transaction->commit();
  1322. util::complete('取消成功');
  1323. } catch (\Exception $e) {
  1324. $transaction->rollBack();
  1325. $msg = $e->getMessage();
  1326. $orderSn = $order->orderSn ?? '';
  1327. noticeUtil::push("预订单{$orderSn}取消失败:{$msg}", '15280215347');
  1328. }
  1329. }
  1330. //取消订单 shizhongqi 20220619
  1331. public function actionCancelOrder()
  1332. {
  1333. $post = Yii::$app->request->post();
  1334. $id = $post['orderId'] ?? 0;
  1335. if (empty($id)) {
  1336. util::fail('请选择订单');
  1337. }
  1338. $order = OrderClass::getById($id, true);
  1339. if (empty($order)) {
  1340. util::fail('请选择订单...');
  1341. }
  1342. OrderClass::valid($order, $this->shopId);
  1343. if (isset($order->status) == false || $order->status != 1) {
  1344. util::fail('不是待付款状态,无法取消');
  1345. }
  1346. $purchaseId = $order->purchaseId ?? 0;
  1347. $purchase = PurchaseClass::getById($purchaseId);
  1348. if (empty($purchase)) {
  1349. util::fail('没有找到采购单');
  1350. }
  1351. $deadLineTime = strtotime($purchase['deadline']);
  1352. $diff = $deadLineTime - time();
  1353. if ($diff <= 60) {
  1354. util::fail('1分钟后订单将自动取消');
  1355. }
  1356. $connection = Yii::$app->db;
  1357. $transaction = $connection->beginTransaction();
  1358. $orderSn = $purchase['orderSn'];
  1359. try {
  1360. $current = PurchaseClass::getById($purchaseId, true);
  1361. PurchaseService::expire($current);
  1362. $transaction->commit();
  1363. //noticeUtil::push("采购单过期未付款,库存已回滚,单号:{$orderSn}");
  1364. } catch (\Exception $e) {
  1365. $transaction->rollBack();
  1366. $msg = $e->getMessage();
  1367. noticeUtil::push("采购单过期处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
  1368. }
  1369. util::complete();
  1370. }
  1371. //延期支付 ssh 2021.1.19
  1372. public function actionDebt()
  1373. {
  1374. $id = Yii::$app->request->get('id');
  1375. //4秒内不允许重复提交
  1376. $cacheKey = 'ghs_set_order_debt_' . $id;
  1377. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  1378. if (!empty($has)) {
  1379. util::fail('请稍等');
  1380. }
  1381. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
  1382. if (getenv('YII_ENV') == 'production') {
  1383. if ($this->mainId == 1082) {
  1384. //泉城鲜花批发的出车,只能开收现金方式,多处要修改,关键词qc_cash
  1385. util::fail('只能使用扫码付款,编号293');
  1386. }
  1387. } else {
  1388. }
  1389. $order = OrderClass::getById($id, true);
  1390. OrderClass::valid($order, $this->shopId);
  1391. $payWay = dict::getDict('payWay', 'debtPay');
  1392. $cgId = $order->purchaseId ?? 0;
  1393. $cg = PurchaseClass::getById($cgId, true);
  1394. if (empty($cg)) {
  1395. util::fail('没有找到采购单');
  1396. }
  1397. if ($order->book == 1) {
  1398. util::fail('预订单不能记欠款');
  1399. }
  1400. $connection = Yii::$app->db;
  1401. $transaction = $connection->beginTransaction();
  1402. try {
  1403. PurchaseService::payAfter($cg, $payWay);
  1404. OrderService::payAfter($order, $payWay);
  1405. $transaction->commit();
  1406. } catch (\Exception $exception) {
  1407. $transaction->rollBack();
  1408. Yii::info("延期支付报错:" . $exception->getMessage());
  1409. util::fail('操作失败');
  1410. }
  1411. $order = OrderClass::getById($id, true);
  1412. if (!empty($order)) {
  1413. $shopId = $order->shopId ?? 0;
  1414. $shop = ShopClass::getById($shopId, true);
  1415. if (!empty($shop)) {
  1416. //花店采购供货商端微信收到通知
  1417. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  1418. $noticeText = json_encode(['orderId' => $id]);
  1419. $noticeKey = "hdCgNoticeGhs";
  1420. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1421. }
  1422. //订单生成时唤起在线打印
  1423. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1424. if ($order->status != 1 && $order->status != 5) {
  1425. OrderClass::onlinePrint($order);
  1426. $ext = $this->shopExt;
  1427. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1428. $order->printNum += 1;
  1429. $order->save();
  1430. }
  1431. }
  1432. }
  1433. if ($order->status != 1 && $order->status != 5) {
  1434. //花店采购供货商端APP收到通知
  1435. //NoticeClass::ghsNewOrderNotice($order);
  1436. }
  1437. }
  1438. util::complete();
  1439. }
  1440. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  1441. public function actionWxPay()
  1442. {
  1443. ini_set('date.timezone', 'Asia/Shanghai');
  1444. $post = Yii::$app->request->post();
  1445. $couponId = $post['couponId'] ?? 0;
  1446. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  1447. $order = OrderClass::getByOrderSn($orderSn);
  1448. if (empty($order)) {
  1449. util::fail('订单号无效');
  1450. }
  1451. $id = $order['id'];
  1452. //支付前验证订单有效性
  1453. if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
  1454. util::fail('无法操作');
  1455. }
  1456. $name = $order['orderName'] ?? '购买商品';
  1457. $totalFee = $order['actPrice'];
  1458. //强制使用小程序的miniOpenId
  1459. $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
  1460. if (empty($openId)) {
  1461. util::fail('没有找到openId');
  1462. }
  1463. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  1464. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  1465. $wxPayType = 0;
  1466. if (httpUtil::isMiniProgram()) {
  1467. $wxPayType = 1;
  1468. }
  1469. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  1470. //订单30分钟后过期
  1471. $now = time();
  1472. $expireTime = $now + 1800;
  1473. $wx = Yii::getAlias("@vendor/weixin");
  1474. require_once($wx . '/lib/WxPay.Api.php');
  1475. require_once($wx . '/example/WxPay.JsApiPay.php');
  1476. $input = new \WxPayUnifiedOrder();
  1477. $input->SetBody($name);
  1478. $input->SetOut_trade_no($orderSn);
  1479. $input->SetTotal_fee($totalFee * 100);
  1480. $input->SetTime_start(date("YmdHis", $now));
  1481. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  1482. $input->SetTime_expire(date("YmdHis", $expireTime));
  1483. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  1484. $input->SetTrade_type("JSAPI");
  1485. //花卉宝代为申请的微信支付
  1486. //$sjExtend = $this->sjExtend->attributes;
  1487. $sjExtend = WxOpenClass::getGhsWxInfo();
  1488. if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
  1489. $input->SetSub_openid($openId);
  1490. } else {
  1491. $input->SetOpenid($openId);
  1492. }
  1493. //强制使用小程序的miniAppId
  1494. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  1495. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  1496. $tools = new \JsApiPay();
  1497. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  1498. $newParams = json_decode($jsApiParameters, true);
  1499. //微信不能修改价格
  1500. $current = date("Y-m-d H:i:s");
  1501. $updateData = ['deadline' => $current, 'modPrice' => 0];
  1502. OrderClass::updateById($id, $updateData);
  1503. util::success($newParams);
  1504. }
  1505. //获取订单详情 ssh 2021.1.21
  1506. public function actionDetail()
  1507. {
  1508. $get = Yii::$app->request->get();
  1509. $id = $get['id'] ?? 0;
  1510. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1511. OrderClass::valid($info, $this->shopId);
  1512. //A4打印需要用到的数据
  1513. $customId = $info['customId'] ?? 0;
  1514. $remark = $info['remark'] ?? '';
  1515. $sendCost = $info['sendCost'] ?? 0;
  1516. $sendNum = $info['sendNum'] ?? '';
  1517. $packCost = $info['packCost'] ?? 0;
  1518. $staffName = $info['shopAdminName'] ?? '';
  1519. $ysName = '';
  1520. if (isset($info['localOrder']) && $info['localOrder'] == 1) {
  1521. if ($info['transType'] == 0) {
  1522. $ysName = '德邦空运';
  1523. }
  1524. if ($info['transType'] == 1) {
  1525. $ysName = '顺丰空运';
  1526. }
  1527. if ($info['transType'] == 2) {
  1528. $ysName = '冷链物流';
  1529. }
  1530. if ($info['transType'] == 3) {
  1531. $ysName = '航空物流';
  1532. }
  1533. if ($info['transType'] == 4) {
  1534. $ysName = '同城配送';
  1535. }
  1536. if ($info['transType'] == 5) {
  1537. $ysName = '到店自取';
  1538. }
  1539. } else {
  1540. $sendType = $info['sendType'] ?? 0;
  1541. $ysName = '送货上门';
  1542. if ($sendType == 1) {
  1543. $ysName = '到店自取';
  1544. }
  1545. if ($sendType == 2) {
  1546. $ysName = '发跑腿';
  1547. }
  1548. if ($sendType == 3) {
  1549. $wlName = $info['wlName'] ?? '';
  1550. $ysName = '发物流';
  1551. if (!empty($wlName)) {
  1552. $ysName = $ysName . '-' . $wlName;
  1553. }
  1554. }
  1555. }
  1556. $fullAddress = '';
  1557. if (getenv('YII_ENV') == 'production') {
  1558. //老油的要显示地址
  1559. if ($this->mainId == 20528) {
  1560. $fullAddress = $info['fullAddress'] ?? '';
  1561. }
  1562. } else {
  1563. if ($this->mainId == 644) {
  1564. $fullAddress = $info['fullAddress'] ?? '';
  1565. }
  1566. }
  1567. $custom = CustomClass::getById($customId, true);
  1568. if (empty($custom)) {
  1569. util::fail('没有找到客户');
  1570. }
  1571. $customName = $custom->name ?? '';
  1572. $customMobile = $custom->customMobile ?? '';
  1573. if (empty($customMobile)) {
  1574. $customShopId = $custom->shopId ?? 0;
  1575. $customShop = ShopClass::getById($customShopId, true);
  1576. if (!empty($customShop)) {
  1577. $customMobile = $customShop->mobile ?? '';
  1578. }
  1579. }
  1580. if (!empty($customMobile)) {
  1581. $customMobile = substr_replace($customMobile, '****', 3, 4);
  1582. }
  1583. $fullCustom = $customName . ' ' . $customMobile;
  1584. if ($this->mainId == 8164) {
  1585. //花大苪不显示客户名称
  1586. $fullCustom = '';
  1587. }
  1588. $seatSn = isset($custom->seatSn) && !empty($custom->seatSn) ? $custom->seatSn : '无';
  1589. $sendTimeWant = $info['sendTimeWant'] ?? '';
  1590. $shortSendTimeWant = !empty($sendTimeWant) ? substr($sendTimeWant, 5, 5) : '';
  1591. $totalItemNum = 0;
  1592. $totalSmallItemNum = 0;
  1593. $table = [];
  1594. if (isset($info['product']) && !empty($info['product'])) {
  1595. foreach ($info['product'] as $key => $val) {
  1596. $currentName = $val['name'] ?? '';
  1597. $num = $val['xhNum'] ?? 0;
  1598. $refundNum = $val['refundNum'] ?? 0;
  1599. $num = bcsub($num, $refundNum);
  1600. $totalItemNum = bcadd($totalItemNum, $num);
  1601. $ratio = $val['ratio'] ?? 0;
  1602. $currentSmallNum = bcmul($num, $ratio);
  1603. $totalSmallItemNum = bcadd($totalSmallItemNum, $currentSmallNum);
  1604. $itemRemark = $val['remark'] ?? '';
  1605. $unitPrice = $val['xhUnitPrice'] ?? 0;
  1606. $unitPrice = floatval($unitPrice);
  1607. $price = bcmul($unitPrice, $num, 2);
  1608. $price = floatval($price);
  1609. $table[] = [
  1610. 'name' => $currentName,
  1611. 'num' => $num,
  1612. 'confirmNum' => '',
  1613. 'remark' => $itemRemark,
  1614. 'wxNumber' => 'shish3508',
  1615. 'unitPrice' => $unitPrice,
  1616. 'price' => $price,
  1617. ];
  1618. }
  1619. }
  1620. $shop = $this->shop;
  1621. $sjName = $shop->merchantName ?? '';
  1622. $shopName = $shop->shopName ?? '';
  1623. $sjShopName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1624. $a4Print = [
  1625. 'customName' => $fullCustom,
  1626. 'staffName' => $staffName,
  1627. 'seatSn' => $seatSn,
  1628. 'shortSendTimeWant' => $shortSendTimeWant,
  1629. 'table' => $table,
  1630. 'remark' => $remark,
  1631. 'fullAddress' => $fullAddress,
  1632. 'sendNum' => $sendNum,
  1633. 'sendCost' => $sendCost,
  1634. 'ysName' => $ysName,
  1635. 'packCost' => $packCost,
  1636. 'totalItemNum' => $totalItemNum,
  1637. 'totalSmallItemNum' => $totalSmallItemNum,
  1638. 'shopName' => $sjShopName . ' 销售单',
  1639. ];
  1640. $info['printData'] = $a4Print;
  1641. //常规模板
  1642. //有用的历史备份
  1643. $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}}]}';
  1644. //$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}}]}';
  1645. if (getenv('YII_ENV') == 'production') {
  1646. //花大苪模板
  1647. if (in_array($this->mainId, [8164])) {
  1648. $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":{}}]}';
  1649. }
  1650. if (in_array($this->mainId, [44282])) {
  1651. //$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}}]}';
  1652. $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}}]}';
  1653. }
  1654. }
  1655. $info['template'] = $template;
  1656. $printType = $get['printType'] ?? 0;
  1657. if ($printType == 1) {
  1658. //打多联的模板
  1659. $table = [];
  1660. if (isset($info['product']) && !empty($info['product'])) {
  1661. foreach ($info['product'] as $key => $val) {
  1662. $currentName = $val['name'] ?? '';
  1663. $num = $val['xhNum'] ?? 0;
  1664. $refundNum = $val['refundNum'] ?? 0;
  1665. $num = bcsub($num, $refundNum);
  1666. $totalItemNum = bcadd($totalItemNum, $num);
  1667. $ratio = $val['ratio'] ?? 0;
  1668. $currentSmallNum = bcmul($num, $ratio);
  1669. $totalSmallItemNum = bcadd($totalSmallItemNum, $currentSmallNum);
  1670. $itemRemark = $val['remark'] ?? '';
  1671. $unitPrice = $val['xhUnitPrice'] ?? 0;
  1672. $unitPrice = floatval($unitPrice);
  1673. $price = bcmul($unitPrice, $num, 2);
  1674. $price = floatval($price);
  1675. $table[] = [
  1676. 'name' => $currentName,
  1677. 'num' => $num,
  1678. 'orderNum' => '',
  1679. 'remark' => $itemRemark,
  1680. 'wxNumber' => 'shish3508',
  1681. 'unitPrice' => '¥' . $unitPrice,
  1682. 'price' => '¥' . $price,
  1683. 'refundNum' => $refundNum == 0 ? '' : 0,
  1684. ];
  1685. }
  1686. }
  1687. $orderSn = $info['orderSn'] ?? '';
  1688. $kind = $info['productStat'] && $info['productStat']['kind'] ?? 0;
  1689. $totalItemNum = $info['productStat'] && $info['productStat']['bigNum'] ?? 0;
  1690. $addTime = $info['addTime'] ?? '';
  1691. $actPrice = $info['actPrice'] ?? 0;
  1692. $tkPrice = $info['tkPrice'] ?? 0;
  1693. $prePrice = $info['prePrice'] ?? 0;
  1694. $customMobile = $info['customMobile'] ?? '';
  1695. $address = '';
  1696. if (isset($info['address']) && !empty($info['address'])) {
  1697. $address .= $info['fullAddress'];
  1698. if (isset($info['showAddress']) && !empty($info['showAddress']) && $info['showAddress'] != $info['fullAddress']) {
  1699. $address .= '(' . $info['showAddress'] . ')<BR>';
  1700. }
  1701. }
  1702. $printData = [
  1703. 'table' => $table,
  1704. 'addTime' => '',
  1705. 'entryTime' => $addTime,
  1706. 'ghsName' => $customName,
  1707. 'clearCode' => '',
  1708. 'staffName' => '',
  1709. 'telephone' => $customMobile,
  1710. 'kind' => $kind,
  1711. 'orderSn' => $orderSn,
  1712. 'sjShopName' => $sjShopName . ' 销售单',
  1713. 'prePrice' => '¥' . $prePrice,
  1714. 'tkPrice' => '¥' . $tkPrice,
  1715. 'realPrice' => '¥' . $actPrice,
  1716. 'totalItemNum' => $totalItemNum,
  1717. 'numKind' => "共" . $kind . "种,数量:" . $totalItemNum,
  1718. 'address' => $address,
  1719. ];
  1720. $info['printData'] = $printData;
  1721. $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}}]}';
  1722. $info['template'] = $template;
  1723. }
  1724. //是否有云打印判断
  1725. $hasCloudPrint = 0;
  1726. $shopExt = $this->shopExt;
  1727. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  1728. $hasCloudPrint = 1;
  1729. }
  1730. $info['hasCloudPrint'] = $hasCloudPrint;
  1731. $purchaseId = $info['purchaseId'] ?? 0;
  1732. $cg = PurchaseClass::getById($purchaseId);
  1733. $info['cgInfo'] = $cg;
  1734. //店长信息
  1735. $mainId = $cg['mainId'] ?? 0;
  1736. $superInfo = ShopAdminClass::getManager($mainId);
  1737. $info['customSuper'] = $superInfo;
  1738. util::success($info);
  1739. }
  1740. //获取订单信息 ssh 20240102
  1741. public function actionGetInfoByOrderSn()
  1742. {
  1743. $get = Yii::$app->request->get();
  1744. $orderSn = $get['orderSn'] ?? '';
  1745. $info = OrderService::getByCondition(['orderSn' => $orderSn], true);
  1746. if (empty($info)) {
  1747. util::fail('没有找到订单');
  1748. }
  1749. if ($info->mainId != $this->mainId) {
  1750. util::fail('不是你的订单哦');
  1751. }
  1752. util::success(['info' => $info]);
  1753. }
  1754. //获取订单详情,不需要登录可以访问,后面要删除此方法 ssh 20220819
  1755. public function actionInfo()
  1756. {
  1757. $get = Yii::$app->request->get();
  1758. $id = $get['id'] ?? 0;
  1759. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1760. if (empty($info)) {
  1761. util::fail('没有找到订单');
  1762. }
  1763. //是否有云打印判断
  1764. $hasCloudPrint = 0;
  1765. $shopExt = $this->shopExt;
  1766. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  1767. $hasCloudPrint = 1;
  1768. }
  1769. $info['hasCloudPrint'] = $hasCloudPrint;
  1770. $purchaseId = $info['purchaseId'] ?? 0;
  1771. $cg = PurchaseClass::getById($purchaseId);
  1772. $info['cgInfo'] = $cg;
  1773. //店长信息
  1774. $mainId = $cg['mainId'] ?? 0;
  1775. $superInfo = ShopAdminClass::getManager($mainId);
  1776. $info['customSuper'] = $superInfo;
  1777. util::success($info);
  1778. }
  1779. //自取免发货流程处理 ssh 2021.1.22
  1780. public function actionWithoutSend()
  1781. {
  1782. util::complete();
  1783. }
  1784. //本店送 ssh 2021.1.24
  1785. public function actionSelfSend()
  1786. {
  1787. $get = Yii::$app->request->get();
  1788. $id = isset($get['id']) ? $get['id'] : 0;
  1789. $info = OrderClass::getById($id, true);
  1790. OrderClass::valid($info->attributes, $this->shopId);
  1791. $connection = Yii::$app->db;
  1792. $transaction = $connection->beginTransaction();
  1793. try {
  1794. OrderClass::selfSend($info);
  1795. $transaction->commit();
  1796. } catch (\Exception $exception) {
  1797. $transaction->rollBack();
  1798. Yii::info("本店送操作报错:" . $exception->getMessage());
  1799. util::fail('操作失败');
  1800. }
  1801. util::complete();
  1802. }
  1803. //运费计算 ssh 2021.1.24
  1804. public function actionFreight()
  1805. {
  1806. //2021.3.28 接入达达
  1807. $get = Yii::$app->request->get();
  1808. $post = Yii::$app->request->post();
  1809. if (empty($get)) {
  1810. $get = $post;
  1811. }
  1812. $orderId = $get['id'] ?? 0; //订单ID
  1813. $customId = $get['customId'] ?? 0;
  1814. if (empty($orderId)) {
  1815. //自定义运费
  1816. //freight::getCost();
  1817. if (empty($customId)) {
  1818. util::fail("请选择客户");
  1819. }
  1820. $customInfo = CustomClass::getById($customId);
  1821. if (empty($customInfo)) {
  1822. util::fail('没有找到客户');
  1823. }
  1824. $shop = $this->shop;
  1825. //花材信息
  1826. $productJson = $get['product'] ?? '';
  1827. // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
  1828. if (empty($productJson)) {
  1829. util::fail('请选择花材');
  1830. }
  1831. $productList = json_decode($productJson, true);
  1832. if (empty($productList)) {
  1833. util::fail('请选择花材');
  1834. }
  1835. $productList = ProductClass::mergeItemInfo($productList);
  1836. $weight = 0;
  1837. $price = 0;
  1838. $productData = ProductClass::getProductMapData($productList);
  1839. $bigNum = 0;
  1840. foreach ($productList as $key => $val) {
  1841. $productId = $val['productId'];
  1842. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  1843. $bigNum += $val['bigNum'];
  1844. $weight = bcadd($w, $weight, 2);
  1845. $ratio = $productData[$productId]['ratio'] ?? 0;
  1846. //大小数量合并多少扎
  1847. $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  1848. //售卖价格
  1849. $itemPrice = $productData[$productId]['price'] ?? 0;
  1850. //合计价格
  1851. $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2);
  1852. }
  1853. //没有经纬度的客户运费直接返回空 ssh 20210612
  1854. if (empty($customInfo['lat']) || empty($customInfo['long'])) {
  1855. util::success(['sedCost' => '']);
  1856. }
  1857. $cost = freight::getCost($shop->lat, $shop->long, $customInfo['lat'], $customInfo['long'], $weight);
  1858. util::success(['sedCost' => $cost]);
  1859. }
  1860. $province = $get['province'] ?? '';
  1861. $city = $get['city'] ?? '';
  1862. $address = $get['address'] ?? '';
  1863. $floor = $get['floor'] ?? '';
  1864. $customName = $get['customName'] ?? '';
  1865. $customMobile = $get['customMobile'] ?? '';
  1866. $fullAddress = $province . $city . $address . $floor;
  1867. $sendTime = $get['sendTime'] ?? '';
  1868. $lat = $get['lat'] ?? '';
  1869. $lng = $get['long'] ?? '';
  1870. if (empty($lat) || empty($lng) || empty($fullAddress)) {
  1871. util::fail('请填写客户地址');
  1872. }
  1873. ini_set('date.timezone', 'Asia/Shanghai');
  1874. if (!empty($sendTime)) {
  1875. //配送时间不为空
  1876. // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
  1877. $sendTimeInt = strtotime($sendTime);
  1878. $now = time();
  1879. $diff = $sendTimeInt - $now;
  1880. //因服务器写入时间,改为至少提前6分钟
  1881. if ($diff <= 360) {
  1882. util::fail('配送时间至少提前6分钟');
  1883. }
  1884. } else {
  1885. //默认立即发送
  1886. $sendTime = 0;
  1887. }
  1888. //更新订单表
  1889. $info = OrderService::getOrderInfo($orderId);
  1890. OrderClass::valid($info, $this->shopId);
  1891. if ($sendTime) {
  1892. $sendTime = date('Y-m-d H:i', strtotime($sendTime));
  1893. } else {
  1894. $sendTime = '0000-00-00 00:00:00';
  1895. }
  1896. $expressAddInfo = [
  1897. 'customName' => $customName,
  1898. 'customMobile' => $customMobile,
  1899. 'province' => $province,
  1900. 'city' => $city,
  1901. 'address' => $address,
  1902. 'floor' => $floor,
  1903. 'lat' => $lat,
  1904. 'long' => $lng,
  1905. 'sendTime' => $sendTime,
  1906. ];
  1907. OrderClass::updateCustomExpressInfo($orderId, $expressAddInfo);
  1908. //计算运费
  1909. $info['province'] = $province;
  1910. $info['city'] = $city;
  1911. $info['address'] = $address;
  1912. $info['floor'] = $floor;
  1913. $info['fullAddress'] = $fullAddress;
  1914. $info['lat'] = $lat;
  1915. $info['long'] = $lng;
  1916. $info['sendTime'] = $expressAddInfo['sendTime'];
  1917. $res = DadaExpressServices::queryDeliverFee($info);
  1918. util::success(['sedCost' => $res['fee']]);
  1919. }
  1920. //发快递和第三方配送 ssh 2021.1.24
  1921. public function actionThirdSend()
  1922. {
  1923. $get = Yii::$app->request->get();
  1924. $id = isset($get['id']) ? $get['id'] : 0;
  1925. $info = OrderService::getById($id, true);
  1926. OrderClass::valid($info->attributes, $this->shopId);
  1927. if (empty($info->lat) || empty($info->long) || empty($info->fullAddress)) {
  1928. util::fail('请填写客户地址');
  1929. }
  1930. $connection = Yii::$app->db;
  1931. $transaction = $connection->beginTransaction();
  1932. try {
  1933. $respond = OrderClass::thirdSend($info, $get);
  1934. $transaction->commit();
  1935. util::success($respond);
  1936. } catch (\Exception $exception) {
  1937. $transaction->rollBack();
  1938. Yii::info("发快递操作报错:" . $exception->getMessage());
  1939. util::fail('操作失败' . $exception->getMessage());
  1940. }
  1941. }
  1942. //确认送达 ssh 2021.1.24
  1943. public function actionReach()
  1944. {
  1945. $get = Yii::$app->request->get();
  1946. $id = isset($get['id']) ? $get['id'] : 0;
  1947. $info = OrderClass::getById($id, true);
  1948. OrderClass::valid($info->attributes, $this->shopId);
  1949. $connection = Yii::$app->db;
  1950. $transaction = $connection->beginTransaction();
  1951. try {
  1952. OrderService::reach($info);
  1953. $transaction->commit();
  1954. } catch (\Exception $exception) {
  1955. $transaction->rollBack();
  1956. Yii::info("送达操作报错:" . $exception->getMessage());
  1957. util::fail('操作失败');
  1958. }
  1959. util::complete();
  1960. }
  1961. //下单要用到的相关信息 ssh 2019.12.6
  1962. public function actionOrderRelate()
  1963. {
  1964. $regionTree = RegionService::tree();
  1965. $shop = $this->shop->attributes;
  1966. $freight = ['first' => 5, 'add' => 2];
  1967. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  1968. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
  1969. util::success($out);
  1970. }
  1971. //客户欠款的订单 ssh 2021.2.4
  1972. public function actionDebtList()
  1973. {
  1974. $get = Yii::$app->request->get();
  1975. $id = $get['id'] ?? 0;
  1976. $info = CustomClass::getCustom($id);
  1977. CustomClass::valid($info, $this->shopId);
  1978. $mainId = $this->mainId;
  1979. $where = ['mainId' => $mainId, 'customId' => $id, 'debt' => 1];
  1980. $searchTime = $get['searchTime'] ?? '';
  1981. if (!empty($searchTime)) {
  1982. $startTime = $get['startTime'] ?? '';
  1983. $endTime = $get['endTime'] ?? '';
  1984. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  1985. $where['payTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1986. }
  1987. $list = OrderClass::getAllByCondition($where, 'addTime DESC', ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice', 'payTime']);
  1988. $result = ['customInfo' => $info, 'list' => $list];
  1989. util::success($result);
  1990. }
  1991. //更新打印次数
  1992. public function actionAddPrintNum()
  1993. {
  1994. $id = Yii::$app->request->get('id', 0);
  1995. $order = OrderClass::getById($id, true);
  1996. OrderClass::valid($order, $this->shopId);
  1997. $order->printNum += 1;
  1998. $order->save();
  1999. util::complete();
  2000. }
  2001. //打印订单 ssh 20210714
  2002. public function actionCloudPrintOrder()
  2003. {
  2004. $get = Yii::$app->request->get();
  2005. $id = $get['id'] ?? 0;
  2006. $showPrice = $get['showPrice'] ?? 1;
  2007. $order = OrderClass::getById($id, true);
  2008. OrderClass::valid($order, $this->shopId);
  2009. if ($order->status == OrderClass::ORDER_STATUS_UN_PAY) {
  2010. util::fail('订单还没有付款');
  2011. }
  2012. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  2013. util::fail('订单已取消');
  2014. }
  2015. $ext = $this->shopExt;
  2016. if (isset($ext->printSn) == false || isset($ext->printKey) == false || empty($ext->printSn) || empty($ext->printKey)) {
  2017. util::success(['hasNoPrint' => 1]);
  2018. }
  2019. OrderClass::onlinePrint($order, $showPrice);
  2020. $order->printNum += 1;
  2021. $order->save();
  2022. util::complete();
  2023. }
  2024. //订单确认完成 ssh 20210809
  2025. public function actionConfirmFinish()
  2026. {
  2027. $payWay = Yii::$app->request->get('payWay', -1);
  2028. $id = Yii::$app->request->get('id', 0);
  2029. $clearType = Yii::$app->request->get('clearType', 0);
  2030. $connection = Yii::$app->db;
  2031. $transaction = $connection->beginTransaction();
  2032. try {
  2033. $order = OrderClass::getById($id, true);
  2034. OrderClass::valid($order, $this->shopId);
  2035. $purchaseId = $order->purchaseId ?? 0;
  2036. $purchase = PurchaseClass::getById($purchaseId, true);
  2037. if (empty($purchase)) {
  2038. util::fail('没有采购信息');
  2039. }
  2040. if ($clearType == 1) {
  2041. //欠款
  2042. $payWay = dict::getDict('payWay', 'debtPay');
  2043. } elseif ($clearType == 2) {
  2044. //已收款
  2045. if ($payWay == -1) {
  2046. util::fail('请选择收款方式');
  2047. }
  2048. $shopAdmin = $this->shopAdmin;
  2049. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  2050. util::fail('超管才能发起已收款');
  2051. }
  2052. } else {
  2053. util::fail('请选择结算方式');
  2054. }
  2055. //不需要打印
  2056. $order->needPrint = dict::getDict('needPrint', 'noNeed');
  2057. $order->save();
  2058. //支付
  2059. PurchaseService::payAfter($purchase, $payWay);
  2060. OrderService::payAfter($order, $payWay);
  2061. //自己送
  2062. $info = OrderClass::getById($id, true);
  2063. OrderClass::selfSend($info);
  2064. //确认送达,并且不需要微信通知
  2065. Yii::$app->params['noNeedWxNotice'] = 1;
  2066. $info = OrderClass::getById($id, true);
  2067. OrderService::reach($info);
  2068. $transaction->commit();
  2069. util::complete('操作成功');
  2070. } catch (\Exception $exception) {
  2071. $transaction->rollBack();
  2072. Yii::info("确认完成订单报错:" . $exception->getMessage());
  2073. util::fail('操作失败');
  2074. }
  2075. }
  2076. //取消订单 ssh 20220110
  2077. public function actionCancel()
  2078. {
  2079. $shopAdmin = $this->shopAdmin;
  2080. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  2081. util::fail('超管才能取消订单');
  2082. }
  2083. $id = Yii::$app->request->get('id');
  2084. $order = OrderClass::getById($id, true);
  2085. if ($order->orderType == 2) {
  2086. util::fail('客户下单,不能主动取消');
  2087. }
  2088. OrderClass::valid($order, $this->shopId);
  2089. OrderService::expire($order, true);
  2090. util::complete('已取消');
  2091. }
  2092. //获取收款语音播报地址 ssh 20211231
  2093. public function actionGetPayVoice()
  2094. {
  2095. $id = Yii::$app->request->get('id');
  2096. $order = OrderClass::getById($id, true);
  2097. $payWay = $order->payWay ?? 0;
  2098. $money = floatval($order->actPrice);
  2099. $payment = $payWay == dict::getDict('payWay', 'alipay') ? '支付宝' : '微信';
  2100. $msg = $payment . '收款' . $money . '元';
  2101. $audio = baiduAip::transfer($msg, 4, 0);
  2102. //上传到oss
  2103. $file = time() . rand(10000, 999999) . '.mp3';
  2104. $filePath = 'tmp/arrival/money/' . $file;
  2105. oss::uploadTmpAudio($filePath, $audio);
  2106. $url = Yii::$app->params['ghsImgHost'] . $filePath;
  2107. util::success(['url' => $url]);
  2108. }
  2109. //修改备注
  2110. public function actionModifyRemark()
  2111. {
  2112. $post = Yii::$app->request->post();
  2113. $id = $post['id'] ?? 0;
  2114. $remark = $post['remark'] ?? '';
  2115. $order = OrderClass::getById($id, true);
  2116. if (empty($order)) {
  2117. util::fail('没有找到订单');
  2118. }
  2119. if ($order->mainId != $this->mainId) {
  2120. util::fail('不是你的订单');
  2121. }
  2122. $cgId = $order->purchaseId ?? 0;
  2123. $cg = PurchaseClass::getById($cgId, true);
  2124. if (empty($cg)) {
  2125. util::fail('采购单没有找到');
  2126. }
  2127. $order->remark = $remark;
  2128. $order->save();
  2129. $cg->remark = $remark;
  2130. $cg->save();
  2131. util::complete('修改成功');
  2132. }
  2133. //修改订单的确认时间 ssh 20240511
  2134. public function actionModifyOrderConfirmTime()
  2135. {
  2136. $get = Yii::$app->request->get();
  2137. $id = $get['id'] ?? 0;
  2138. $date = $get['date'] ?? '';
  2139. if (empty($date)) {
  2140. util::fail('请选择日期');
  2141. }
  2142. $order = OrderClass::getById($id, true);
  2143. if (empty($order)) {
  2144. util::fail('没有找到订单');
  2145. }
  2146. if ($order->mainId != $this->mainId) {
  2147. util::fail('不是你的订单');
  2148. }
  2149. if ($order->payStatus == 0) {
  2150. util::fail('没有确认的订单');
  2151. }
  2152. $mainId = $this->mainId;
  2153. //超管或者约定的人可以修改日期
  2154. if (getenv('YII_ENV') == 'production') {
  2155. if (in_array($mainId, [23390])) {
  2156. if (!in_array($this->adminId, [24586, 23960])) {
  2157. util::fail('你不能修改哦');
  2158. }
  2159. }
  2160. } else {
  2161. if (in_array($mainId, [644])) {
  2162. if (!in_array($this->adminId, [919])) {
  2163. }
  2164. }
  2165. }
  2166. $payTime = $order->payTime;
  2167. $time = strtotime($payTime);
  2168. $after = date("H:i:s", $time);
  2169. $new = $date . ' ' . $after;
  2170. $cgId = $order->purchaseId ?? 0;
  2171. $cg = PurchaseClass::getById($cgId, true);
  2172. if (empty($cg)) {
  2173. util::fail('没有找到订单信息');
  2174. }
  2175. if (strtotime($new) > time()) {
  2176. util::fail('不能修改成未来时间');
  2177. }
  2178. $order->payTime = $new;
  2179. $order->save();
  2180. $cg->payTime = $new;
  2181. $cg->save();
  2182. //有修改账单日期需要更新到欠款变动明细,财务好对账,多个地方要同步修改,关键词to_change_custom_debt_pay_time
  2183. CustomDebtChangeClass::updateByCondition(['capitalType' => 10, 'relateId' => $id], ['payTime' => $new]);
  2184. util::complete('修改成功');
  2185. }
  2186. //应收款统计 ssh 20240528
  2187. public function actionAccountList()
  2188. {
  2189. $get = Yii::$app->request->get();
  2190. $mainId = $this->mainId;
  2191. $export = $get['export'] ?? 0;
  2192. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : -1;
  2193. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2194. $startTime = $get['startTime'] ?? '';
  2195. $endTime = $get['endTime'] ?? '';
  2196. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2197. $start = $period['startTime'];
  2198. $end = $period['endTime'];
  2199. $customList = CustomClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name', 'id');
  2200. $currentStartDate = date('Y-m-d', strtotime($start));
  2201. $currentEndDate = date('Y-m-d', strtotime($end));
  2202. $currentStartTime = $currentStartDate . ' 00:00:00';
  2203. $currentEndTime = $currentEndDate . ' 23:59:59';
  2204. $where = ['mainId' => $mainId];
  2205. if ($debt > -1) {
  2206. $where['debt'] = $debt;
  2207. }
  2208. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  2209. $orderList = OrderClass::getAllByCondition($where, null, '*');
  2210. $list = [];
  2211. $totalAmount = 0;
  2212. if (!empty($orderList)) {
  2213. foreach ($orderList as $orderInfo) {
  2214. $actPrice = $orderInfo['actPrice'] ?? 0;
  2215. $customId = $orderInfo['customId'] ?? 0;
  2216. $status = $orderInfo['status'] ?? 0;
  2217. $book = $orderInfo['book'] ?? 0;
  2218. if ($status == 1 || $status == 5) {
  2219. continue;
  2220. }
  2221. if ($book == 1 && $status == 2) {
  2222. continue;
  2223. }
  2224. if (isset($list[$customId])) {
  2225. $list[$customId]['amount'] = bcadd($list[$customId]['amount'], $actPrice, 2);
  2226. $list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
  2227. } else {
  2228. $name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
  2229. $list[$customId] = ['id' => $customId, 'name' => $name, 'amount' => $actPrice, 'num' => 1];
  2230. }
  2231. $totalAmount = bcadd($totalAmount, $actPrice, 2);
  2232. }
  2233. $list = array_values($list);
  2234. }
  2235. if ($export == 1) {
  2236. if (empty($list)) {
  2237. util::fail('没有数据需要导出');
  2238. }
  2239. ini_set('memory_limit', '2045M');
  2240. set_time_limit(0);
  2241. OrderClass::exportAccountList($list, $mainId);
  2242. util::stop();
  2243. }
  2244. util::success(['list' => $list, 'totalAmount' => $totalAmount]);
  2245. }
  2246. //应收款统计 ssh 20240528
  2247. public function actionPastList()
  2248. {
  2249. $get = Yii::$app->request->get();
  2250. $export = $get['export'] ?? 0;
  2251. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2252. $startTime = $get['startTime'] ?? '';
  2253. $endTime = $get['endTime'] ?? '';
  2254. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2255. $end = $period['endTime'];
  2256. $customList = CustomClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name,mobile', 'id');
  2257. $currentDate = date('Y-m-d 00:00:00', bcadd(strtotime($end), 86400));
  2258. $totalAmount = 0;
  2259. if (!empty($customList)) {
  2260. foreach ($customList as $key => $custom) {
  2261. $customId = $custom['id'] ?? 0;
  2262. $change = CustomDebtChangeClass::getByCondition(['customId' => $customId, 'addTime<' => $currentDate], true, 'addTime DESC');
  2263. $amount = $change->balance ?? 0;
  2264. $totalAmount = bcadd($totalAmount, $amount, 2);
  2265. $customList[$key]['currentDebAmount'] = $amount;
  2266. }
  2267. $customList = array_values($customList);
  2268. }
  2269. if ($export == 1) {
  2270. $mainId = $this->mainId;
  2271. if (empty($customList)) {
  2272. util::fail('没有数据需要导出');
  2273. }
  2274. ini_set('memory_limit', '2045M');
  2275. set_time_limit(0);
  2276. OrderClass::exportPastList($customList, $mainId);
  2277. util::stop();
  2278. }
  2279. util::success(['list' => $customList, 'totalAmount' => $totalAmount]);
  2280. }
  2281. //客户业绩,有多个地方,需要同步,搜索关键词 customYj ssh 20240628
  2282. public function actionYj()
  2283. {
  2284. $get = Yii::$app->request->get();
  2285. $mainId = $this->mainId;
  2286. $export = $get['export'] ?? 0;
  2287. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : -1;
  2288. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2289. $startTime = $get['startTime'] ?? '';
  2290. $endTime = $get['endTime'] ?? '';
  2291. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2292. $start = $period['startTime'];
  2293. $end = $period['endTime'];
  2294. $customList = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, '*', 'id');
  2295. $currentStartDate = date('Y-m-d', strtotime($start));
  2296. $currentEndDate = date('Y-m-d', strtotime($end));
  2297. $currentStartTime = $currentStartDate . ' 00:00:00';
  2298. $currentEndTime = $currentEndDate . ' 23:59:59';
  2299. $where = ['mainId' => $mainId];
  2300. if ($debt > -1) {
  2301. $where['debt'] = $debt;
  2302. }
  2303. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  2304. $orderList = OrderClass::getAllByCondition($where, null, '*');
  2305. $list = [];
  2306. $totalActPrice = 0;
  2307. $totalOrderPrice = 0;
  2308. $totalCarton = 0;
  2309. $totalCartonNum = 0;
  2310. $totalPack = 0;
  2311. $totalFreight = 0;
  2312. $totalTkPrice = 0;
  2313. //增加项
  2314. $totalOnlyTkPrice = 0;
  2315. $totalNum = 0;
  2316. if (!empty($orderList)) {
  2317. foreach ($orderList as $orderInfo) {
  2318. $actPrice = $orderInfo['actPrice'] ?? 0;
  2319. $orderPrice = $orderInfo['orderPrice'] ?? 0;
  2320. $customId = $orderInfo['customId'] ?? 0;
  2321. $status = $orderInfo['status'] ?? 0;
  2322. $book = $orderInfo['book'] ?? 0;
  2323. $orderSn = $orderInfo['orderSn'] ?? '';
  2324. $tkPrice = $orderInfo['tkPrice'] ?? 0;
  2325. if ($status == 1 || $status == 5) {
  2326. continue;
  2327. }
  2328. if ($book == 1 && $status == 2) {
  2329. continue;
  2330. }
  2331. $carton = 0;
  2332. $cartonNum = 0;
  2333. $pack = 0;
  2334. $freight = 0;
  2335. $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  2336. if ($actPrice > 0) {
  2337. if (!empty($orderItemList)) {
  2338. foreach ($orderItemList as $orderItem) {
  2339. $num = $orderItem['xhNum'] ?? 0;
  2340. $unitPrice = $orderItem['xhUnitPrice'] ?? 0;
  2341. $refundNum = $orderItem['refundNum'] ?? 0;
  2342. $classId = $orderItem['classId'] ?? 0;
  2343. if (getenv('YII_ENV') == 'production') {
  2344. //小向算打包纸箱费用
  2345. if ($mainId == 23390) {
  2346. $remainNum = bcsub($num, $refundNum);
  2347. $amount = bcmul($remainNum, $unitPrice, 2);
  2348. if ($classId == 72106) {
  2349. $carton = bcadd($carton, $amount, 2);
  2350. $cartonNum = bcadd($cartonNum, $remainNum);
  2351. }
  2352. if ($classId == 72108) {
  2353. $pack = bcadd($pack, $amount, 2);
  2354. }
  2355. if ($classId == 73118) {
  2356. $freight = bcadd($freight, $amount, 2);
  2357. }
  2358. }
  2359. //花大苪
  2360. if ($mainId == 8164) {
  2361. $remainNum = bcsub($num, $refundNum);
  2362. $amount = bcmul($remainNum, $unitPrice, 2);
  2363. if ($classId == 90497) {
  2364. $carton = bcadd($carton, $amount, 2);
  2365. $cartonNum = bcadd($cartonNum, $remainNum);
  2366. }
  2367. if ($classId == 90501) {
  2368. $freight = bcadd($freight, $amount, 2);
  2369. }
  2370. }
  2371. //石头花艺
  2372. if ($mainId == 50) {
  2373. $remainNum = bcsub($num, $refundNum);
  2374. $amount = bcmul($remainNum, $unitPrice, 2);
  2375. if ($classId == 71495) {
  2376. $carton = bcadd($carton, $amount, 2);
  2377. $cartonNum = bcadd($cartonNum, $remainNum);
  2378. }
  2379. if ($classId == 91009) {
  2380. $freight = bcadd($freight, $amount, 2);
  2381. }
  2382. }
  2383. }
  2384. }
  2385. }
  2386. }
  2387. //增加项
  2388. if ($tkPrice > 0) {
  2389. $refundList = RefundOrderClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
  2390. if (!empty($refundList)) {
  2391. foreach ($refundList as $refundInfo) {
  2392. if ($refundInfo->status == 1) {
  2393. if ($refundInfo->refundType == 2) {
  2394. $refundPrice = $refundInfo->refundPrice ?? 0;
  2395. $totalOnlyTkPrice = bcadd($totalOnlyTkPrice, $refundPrice, 2);
  2396. }
  2397. }
  2398. }
  2399. }
  2400. }
  2401. $totalCarton = bcadd($totalCarton, $carton, 2);
  2402. $totalCartonNum = bcadd($totalCartonNum, $cartonNum);
  2403. $totalPack = bcadd($totalPack, $pack, 2);
  2404. $totalFreight = bcadd($totalFreight, $freight, 2);
  2405. $totalTkPrice = bcadd($totalTkPrice, $tkPrice, 2);
  2406. $totalActPrice = bcadd($totalActPrice, $actPrice, 2);
  2407. $totalOrderPrice = bcadd($totalOrderPrice, $orderPrice, 2);
  2408. $totalNum++;
  2409. if (isset($list[$customId])) {
  2410. $list[$customId]['actPrice'] = bcadd($list[$customId]['actPrice'], $actPrice, 2);
  2411. $list[$customId]['orderPrice'] = bcadd($list[$customId]['orderPrice'], $orderPrice, 2);
  2412. $list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
  2413. $list[$customId]['carton'] = bcadd($list[$customId]['carton'], $carton, 2);
  2414. $list[$customId]['cartonNum'] = bcadd($list[$customId]['cartonNum'], $cartonNum);
  2415. $list[$customId]['pack'] = bcadd($list[$customId]['pack'], $pack, 2);
  2416. $list[$customId]['freight'] = bcadd($list[$customId]['freight'], $freight, 2);
  2417. $list[$customId]['tkPrice'] = bcadd($list[$customId]['tkPrice'], $tkPrice, 2);
  2418. } else {
  2419. $name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
  2420. $mobile = $customList[$customId] && $customList[$customId]['mobile'] ? $customList[$customId]['mobile'] : '0';
  2421. $list[$customId] = [
  2422. 'id' => $customId,
  2423. 'name' => $name,
  2424. 'mobile' => $mobile,
  2425. 'orderPrice' => $orderPrice,
  2426. 'actPrice' => $actPrice,
  2427. 'num' => 1,
  2428. 'carton' => $carton,
  2429. 'cartonNum' => $cartonNum,
  2430. 'pack' => $pack,
  2431. 'freight' => $freight,
  2432. 'tkPrice' => $tkPrice,
  2433. ];
  2434. }
  2435. }
  2436. foreach ($customList as $key => $custom) {
  2437. $customId = $custom['id'] ?? 0;
  2438. if (isset($list[$customId]) == false) {
  2439. $list[$customId] = [
  2440. 'id' => $customId,
  2441. 'name' => $custom['name'],
  2442. 'mobile' => $custom['mobile'],
  2443. 'actPrice' => 0,
  2444. 'num' => 0,
  2445. 'carton' => 0,
  2446. 'pack' => 0,
  2447. 'freight' => 0,
  2448. 'tkPrice' => 0,
  2449. 'orderPrice' => 0,
  2450. ];
  2451. }
  2452. }
  2453. $list = array_values($list);
  2454. }
  2455. if ($export == 1) {
  2456. if (empty($list)) {
  2457. util::fail('没有数据需要导出');
  2458. }
  2459. ini_set('memory_limit', '2045M');
  2460. set_time_limit(0);
  2461. OrderClass::exportYj($list, $mainId);
  2462. util::stop();
  2463. }
  2464. util::success([
  2465. 'list' => $list,
  2466. 'totalActPrice' => $totalActPrice,
  2467. 'totalOrderPrice' => $totalOrderPrice,
  2468. 'totalCarton' => $totalCarton,
  2469. 'totalCartonNum' => $totalCartonNum,
  2470. 'totalNum' => $totalNum,
  2471. 'totalPack' => $totalPack,
  2472. 'totalFreight' => $totalFreight,
  2473. 'totalTkPrice' => $totalTkPrice,
  2474. //增加项
  2475. 'totalOnlyTkPrice' => $totalOnlyTkPrice,
  2476. ]);
  2477. }
  2478. //修改配送人 ssh 20240824
  2479. public function actionChangeSendStaff()
  2480. {
  2481. $staff = $this->shopAdmin;
  2482. if (isset($staff->finance) == false || $staff->finance == 0) {
  2483. util::fail('请有财务权限的人修改');
  2484. }
  2485. $get = Yii::$app->request->get();
  2486. $staffId = $get['staffId'] ?? 0;
  2487. $orderId = $get['orderId'] ?? 0;
  2488. $order = OrderClass::getById($orderId, true);
  2489. if (empty($order)) {
  2490. util::fail('没有找到订单');
  2491. }
  2492. if ($order->mainId != $this->mainId) {
  2493. util::fail('不是你的');
  2494. }
  2495. $staff = ShopAdminClass::getById($staffId, true);
  2496. if (empty($staff)) {
  2497. util::fail('没有找到员工');
  2498. }
  2499. if ($staff->mainId != $this->mainId) {
  2500. util::fail('不是你的员工');
  2501. }
  2502. $staffName = $staff->name ?? '';
  2503. $order->sendStaffId = $staffId;
  2504. $order->sendStaffName = $staffName;
  2505. $order->save();
  2506. util::complete('修改成功');
  2507. }
  2508. //导入开单 ssh 20241126
  2509. public function actionImportCreate()
  2510. {
  2511. ini_set('memory_limit', '2045M');
  2512. set_time_limit(0);
  2513. $connection = Yii::$app->db;
  2514. $transaction = $connection->beginTransaction();
  2515. try {
  2516. $get = Yii::$app->request->get();
  2517. $customId = $get['id'] ?? '';
  2518. $customRes = CustomClass::getById($customId, true);
  2519. if (empty($customRes)) {
  2520. util::fail('没有找到客户');
  2521. }
  2522. if ($customRes->ownMainId != $this->mainId) {
  2523. util::fail('不是你的客户');
  2524. }
  2525. if (isset($customRes->mainId) && !empty($customRes->mainId) && $customRes->mainId == $customRes->ownMainId) {
  2526. util::fail('不能给自己开单');
  2527. }
  2528. $file = $_FILES['file'];
  2529. if (!is_uploaded_file($file['tmp_name'])) {
  2530. util::fail('please upload img');
  2531. }
  2532. $mainId = $this->mainId;
  2533. $sjId = $this->sjId;
  2534. $shopId = $this->shopId;
  2535. $month = date("Ym");
  2536. $date = date("d");
  2537. $path = dirUtil::getImgUploadDir() . "/{$mainId}/kd/{$shopId}/{$month}/{$date}/";
  2538. if (!file_exists($path)) {
  2539. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  2540. mkdir($path, 0700, true);
  2541. }
  2542. $preFileName = stringUtil::uniqueFileName();
  2543. $newFile = $preFileName . ".xls";
  2544. $fullPathFile = $path . $newFile;
  2545. if (move_uploaded_file($file['tmp_name'], $fullPathFile)) {
  2546. $arr = [];
  2547. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  2548. require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');
  2549. $spreadsheet = \PHPExcel_IOFactory::load($fullPathFile);
  2550. // 获取活动工作表
  2551. $worksheet = $spreadsheet->getActiveSheet();
  2552. // 遍历每一行
  2553. foreach ($worksheet->getRowIterator() as $key => $row) {
  2554. $cellIterator = $row->getCellIterator();
  2555. // 这里设置为迭代所有单元格,包括空单元格
  2556. $cellIterator->setIterateOnlyExistingCells(FALSE);
  2557. // 遍历每列
  2558. $rowData = [];
  2559. foreach ($cellIterator as $cell) {
  2560. $option = $cell->getValue();
  2561. $rowData[] = trim($option);
  2562. }
  2563. $arr[] = $rowData;
  2564. }
  2565. array_shift($arr);
  2566. $productIds = [];
  2567. foreach ($arr as $k => $v) {
  2568. $productId = $v[0] ?? 0;
  2569. $productId = trim($productId);
  2570. if (is_numeric($productId) && $productId > 0) {
  2571. $productIds[] = $productId;
  2572. }
  2573. }
  2574. if (empty($productIds)) {
  2575. util::fail('没有识别出花材');
  2576. }
  2577. $productInfo = ProductClass::getByIds($productIds, null, 'id');
  2578. if (empty($productInfo)) {
  2579. util::fail('没有找到有效花材');
  2580. }
  2581. $mat = [];
  2582. foreach ($arr as $k => $v) {
  2583. $productId = $v[0] ?? 0;
  2584. $productId = trim($productId);
  2585. $num = $v[2] ?? 0;
  2586. $num = trim($num);
  2587. $unitPrice = $v[3] ?? 0;
  2588. $unitPrice = trim($unitPrice);
  2589. $remark = $v['5'] ?? '';
  2590. $remark = trim($remark);
  2591. if (is_numeric($productId) && $productId > 0 && $num > 0 && $unitPrice > 0) {
  2592. $product = $productInfo[$productId] ?? [];
  2593. $ptItemId = $product['itemId'] ?? 0;
  2594. $mat[] = [
  2595. 'productId' => $productId,
  2596. 'bigNum' => $num,
  2597. 'itemId' => $ptItemId,
  2598. 'smallNum' => 0,
  2599. 'price' => $unitPrice,
  2600. 'remark' => $remark,
  2601. ];
  2602. }
  2603. }
  2604. $modifyPrice = 0;
  2605. foreach ($mat as $ma) {
  2606. $cNum = $ma['bigNum'] ?? 0;
  2607. $cPrice = $ma['price'] ?? 0;
  2608. $cTotal = bcmul($cNum, $cPrice, 2);
  2609. $modifyPrice = bcadd($modifyPrice, $cTotal, 2);
  2610. }
  2611. $customName = $customRes->name ?? '';
  2612. $customMobile = $customRes->mobile ?? '';
  2613. $customPy = $customRes->py ?? '';
  2614. $ghsId = $customRes->ghsId ?? 0;
  2615. $hasPay = 2;
  2616. $custom = CustomClass::getCustom($customId);
  2617. $post = [];
  2618. $post['modifyPrice'] = $modifyPrice;
  2619. $post['shopId'] = $shopId;
  2620. $post['sendType'] = 0;
  2621. $post['transType'] = 0;
  2622. $post['sendSide'] = 0;
  2623. $post['sendCost'] = 0;
  2624. $post['packCost'] = 0;
  2625. $post['customId'] = $customId;
  2626. $post['customName'] = $customName;
  2627. $post['payWay'] = 0;
  2628. $post['needPrint'] = 2;
  2629. $post['hasPay'] = 2;
  2630. $post['product'] = $mat;
  2631. $post['deadline'] = date("Y-m-d H:i:s", time() + 86400);
  2632. $post['debt'] = 1;
  2633. $post['mainId'] = $mainId;
  2634. $post['fromType'] = 1;
  2635. $post['expressId'] = 0;
  2636. $post['sjId'] = $sjId;
  2637. $staff = $this->shopAdmin;
  2638. $staffId = $staff->id ?? 0;
  2639. $staffName = $staff->name ?? '';
  2640. $post['shopAdminId'] = $staffId;
  2641. $post['shopAdminName'] = $staffName;
  2642. $post['getStaffId'] = $staffId;
  2643. $post['getStaffName'] = $staffName;
  2644. $post['customMobile'] = $customMobile;
  2645. $post['customNamePy'] = $customPy;
  2646. $post['customAvatar'] = '';
  2647. $post['newVersion'] = 1;
  2648. $post['book'] = 1;
  2649. $post['wlName'] = '';
  2650. $post['dealPrice'] = 1;
  2651. $post['ghsId'] = $ghsId;
  2652. $shop = $this->shop;
  2653. $bookSn = $shop->bookSn ?? 0;
  2654. $post['bookSn'] = $bookSn;
  2655. //多处有用到此方法,需要同步修改,搜索关键词create_new_order
  2656. OrderService::createNewOrder($post, $custom, $hasPay);
  2657. $transaction->commit();
  2658. util::complete('提交成功');
  2659. } else {
  2660. util::fail('上传失败了,出错了哦');
  2661. }
  2662. } catch (\Exception $e) {
  2663. $transaction->rollBack();
  2664. Yii::info("导入失败了," . $e->getMessage());
  2665. noticeUtil::push('导入失败,失败原因:' . $e->getMessage(), '15280215347');
  2666. $msg = $e->getMessage();
  2667. util::fail('导入失败:' . $msg);
  2668. }
  2669. }
  2670. //打印发物流用和标签 ssh 20250312
  2671. public function actionPrintWlLabel()
  2672. {
  2673. $get = Yii::$app->request->get();
  2674. $id = $get['id'] ?? 0;
  2675. $order = OrderClass::getById($id, true);
  2676. if (empty($order)) {
  2677. util::fail('没有找到订单');
  2678. }
  2679. $customId = $order->customId ?? 0;
  2680. $custom = CustomClass::getById($customId, true);
  2681. if (empty($custom)) {
  2682. util::fail('没有找到客户');
  2683. }
  2684. $shortName = $custom->shortName ?? '';
  2685. if (empty($shortName)) {
  2686. util::fail('客户的短名没有设置');
  2687. }
  2688. $shortName = stringUtil::subStringUtf8($shortName, 5);
  2689. $customMobile = $order->customMobile ?? '';
  2690. if (empty($customMobile)) {
  2691. util::fail('客户手机号无效');
  2692. }
  2693. $shortMobile = substr($customMobile, -4);
  2694. $remark = $order->remark ?? '';
  2695. $shortRemark = stringUtil::subStringUtf8($remark, 8);
  2696. $shop = $this->shop;
  2697. $shopName = $shop->shopName ?? '';
  2698. $sjName = $shop->merchantName;
  2699. $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  2700. $telephone = $shop->telephone ?? '';
  2701. $ext = $this->shopExt;
  2702. $wlLabelSn = $ext->wlLabelSn ?? '';
  2703. if (empty($wlLabelSn)) {
  2704. util::fail('请绑定物流标签机');
  2705. }
  2706. $p = new printUtil($wlLabelSn);
  2707. $p->times = 2;
  2708. $content = '<TEXT x="420" y="130" font="12" w="4" h="4" r="90">' . $shortName . '</TEXT>';
  2709. $content .= '<TEXT x="395" y="10" font="12" w="2" h="2" r="90">地址</TEXT>';
  2710. $content .= '<TEXT x="290" y="130" font="12" w="4" h="4" r="90">' . $shortMobile . '</TEXT>';
  2711. $content .= '<TEXT x="265" y="10" font="12" w="2" h="2" r="90">代码</TEXT>';
  2712. $content .= '<TEXT x="170" y="130" font="12" w="4" h="4" r="90">' . $shortRemark . '</TEXT>';
  2713. $content .= '<TEXT x="150" y="10" font="12" w="2" h="2" r="90">物流</TEXT>';
  2714. $content .= '<TEXT x="45" y="70" font="12" w="2" h="2" r="90">' . $currentName . ' ' . $telephone . '</TEXT>';
  2715. $p->printLabelMsg($content);
  2716. util::complete('打印成功');
  2717. }
  2718. }