OrderController.php 158 KB

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