OrderController.php 157 KB

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