OrderController.php 157 KB

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