OrderController.php 157 KB

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