OrderController.php 159 KB

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