OrderController.php 154 KB

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