OrderController.php 158 KB

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