OrderController.php 197 KB

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