OrderController.php 155 KB

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