OrderController.php 158 KB

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