OrderController.php 190 KB

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