OrderController.php 155 KB

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