OrderController.php 158 KB

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