OrderController.php 156 KB

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