OrderController.php 200 KB

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