OrderController.php 160 KB

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