OrderController.php 157 KB

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