OrderController.php 128 KB

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