OrderController.php 130 KB

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