OrderController.php 178 KB

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