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