OrderController.php 161 KB

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