OrderController.php 155 KB

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