OrderController.php 159 KB

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