OrderController.php 157 KB

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