OrderController.php 187 KB

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