OrderController.php 180 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337
  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. $customDistId = $get['customDistId'] ?? ($get['distId'] ?? 0);
  935. if (!empty($customDistId)) {
  936. $where['customDistId'] = (int)$customDistId;
  937. }
  938. $debt = isset($get['debt']) && is_numeric($get['debt']) ? (int)$get['debt'] : -1;
  939. if ($debt > -1) {
  940. $where['debt'] = $debt;
  941. }
  942. if (isset($get['ids']) && !empty($get['ids'])) {
  943. $stringIds = $get['ids'];
  944. $newIds = explode(',', $stringIds);
  945. $where['id'] = ['in', $newIds];
  946. }
  947. //选择开单人
  948. $shopAdminId = $get['shopAdminId'] ?? 0;
  949. if (!empty($shopAdminId)) {
  950. $where['shopAdminId'] = $shopAdminId;
  951. }
  952. $onlinePay = $get['onlinePay'] ?? -1;
  953. if ($onlinePay > -1) {
  954. $where['onlinePay'] = $onlinePay;
  955. }
  956. $sendType = $get['sendType'] ?? -1;
  957. if ($sendType > -1) {
  958. $where['sendType'] = $sendType;
  959. }
  960. $respond = OrderClass::getOrderList($where);
  961. if ($export == 1) {
  962. OrderClass::exportOrderData($respond, $this->mainId);
  963. }
  964. $respond['shop'] = $this->shop;
  965. $respond['shopExt'] = $this->shopExt;
  966. util::success($respond);
  967. }
  968. //按片区排列的订单列表
  969. public function actionListByDist()
  970. {
  971. $get = Yii::$app->request->get();
  972. $where = [];
  973. $where['o.mainId'] = $this->mainId;
  974. $searchTime = $get['searchTime'] ?? '';
  975. if (!empty($searchTime)) {
  976. $startTime = $get['startTime'] ?? '';
  977. $endTime = $get['endTime'] ?? '';
  978. // 时间跨度不能超过7天
  979. if (strtotime($endTime) - strtotime($startTime) > 7 * 24 * 3600) {
  980. util::fail('最多查询7天的订单');
  981. }
  982. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  983. $where['payTime'] = ['between', [$period['startTime'], $period['endTime']]];
  984. }
  985. $respond = OrderClass::getDistOrderList($where);
  986. util::success($respond);
  987. }
  988. // 新订单列表详情 -- 可能与 actionList 很相似,但为不影响 actionList,重新创建个方法 shizhongqi 2022.06.23
  989. public function actionNewOrderList()
  990. {
  991. $get = Yii::$app->request->get();
  992. $where['shopId'] = $this->shopId;
  993. /*$status = $get['status'] ?? 0;
  994. if (!empty($status)) {
  995. $where['status'] = $status;
  996. }*/
  997. // 按类别生成查询条件:1.今日实收 2.今日欠款 3.总欠款(所有历史欠款)
  998. if (isset($get['type'])) {
  999. $type = $get['type'];
  1000. if ($type == 1) { // 今日实收
  1001. $get['searchTime'] = 'today';
  1002. $where['debt'] = 0;
  1003. $where['debtPrice'] = '0.00';
  1004. $where['status'] = ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]];
  1005. } elseif ($type == 2) { // 今日欠款
  1006. $get['searchTime'] = 'today';
  1007. $where['debt'] = 1;
  1008. } elseif ($type == 3) { // 总欠款
  1009. $where['debt'] = 1;
  1010. } else {
  1011. util::fail('查询的订单类别不存在');
  1012. }
  1013. }
  1014. $searchTime = $get['searchTime'] ?? '';
  1015. if (!empty($searchTime)) {
  1016. $startTime = '';
  1017. $endTime = '';
  1018. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  1019. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1020. }
  1021. $name = $get['name'] ?? '';
  1022. if (!empty($name)) {
  1023. $searchType = $get['searchType'] ?? 0;
  1024. if (empty($searchType)) {
  1025. //订单编号
  1026. if (strpos($name, 'XSD') === 0) {
  1027. $where['orderSn'] = $name;
  1028. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  1029. $where['customNamePy'] = ['like', $name];
  1030. } else {
  1031. $where['customName'] = ['like', $name];
  1032. }
  1033. } elseif ($searchType == 1) {
  1034. $where['sendNum'] = $name;
  1035. } else {
  1036. util::fail('搜索的订单类别不存在');
  1037. }
  1038. }
  1039. $respond = OrderClass::getOrderList($where);
  1040. $respond['shop'] = $this->shop;
  1041. $respond['shopExt'] = $this->shopExt;
  1042. $respond['type'] = $type; //把查询类别返回
  1043. util::success($respond);
  1044. }
  1045. //商城下单操作 ssh 2021.1.14
  1046. public function actionCreateOrder()
  1047. {
  1048. $post = Yii::$app->request->post();
  1049. $shopId = $this->shopId;
  1050. $customId = $post['customId'] ?? 0;
  1051. $post['customId'] = $customId;
  1052. //开单必须选客户
  1053. if (empty($customId)) {
  1054. util::fail('请选择客户');
  1055. }
  1056. $modifyPrice = $post['modifyPrice'] ?? 0;
  1057. $pattern = '/^\d+(\.\d{1,2})?$/';
  1058. if ($modifyPrice > 0) {
  1059. if (!preg_match($pattern, $modifyPrice)) {
  1060. //容错前端
  1061. util::fail('金额不能超2位小数');
  1062. }
  1063. }
  1064. $custom = CustomClass::getCustom($customId);
  1065. if (empty($custom)) {
  1066. util::fail('请选客户哦');
  1067. }
  1068. $shopAdmin = $this->shopAdmin;
  1069. $shopAdminId = $this->shopAdminId;
  1070. $shopAdminName = $shopAdmin->name ?? '';
  1071. //解决开单提交订单时,别人修改价格,造成提交价格不是真实卖价问题!!
  1072. $dealPrice = $post['dealPrice'] ?? 0;
  1073. //解决重复提交:同店铺 + 同操作人 + 同客户 + 同成交价,短时间内只允许一次(防连点 / 双请求)
  1074. util::checkRepeatCommit($shopId . '_' . $this->adminId . '_' . $customId . '_' . $dealPrice, 3);
  1075. CustomClass::valid($custom, $this->shopId);
  1076. if (!empty($custom['mainId']) && $custom['mainId'] == $custom['ownMainId']) {
  1077. util::fail('不能给自己开单');
  1078. }
  1079. $post['ghsId'] = $custom['ghsId'] ?? 0;
  1080. $post['customMobile'] = $custom['mobile'] ?? '';
  1081. $customName = $custom['name'] ?? '';
  1082. $post['customName'] = $customName;
  1083. $post['customNamePy'] = $custom['py'] ?? '';
  1084. $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
  1085. $post['province'] = $custom['province'] ?? '';
  1086. $post['city'] = $custom['city'] ?? '';
  1087. $post['dist'] = $custom['dist'] ?? '';
  1088. $post['address'] = $custom['address'] ?? '';
  1089. $post['floor'] = $custom['floor'] ?? '';
  1090. $post['fullAddress'] = $custom['fullAddress'] ?? '';
  1091. $post['showAddress'] = $custom['showAddress'] ?? '';
  1092. $post['long'] = $custom['long'] ?? '';
  1093. $post['lat'] = $custom['lat'] ?? '';
  1094. if (!empty($post['getStaffId'])) {
  1095. if (getenv('YII_ENV') == 'production') {
  1096. $tbMainId = 44171;
  1097. } else {
  1098. $tbMainId = 0;
  1099. }
  1100. if ($this->mainId == $tbMainId) {
  1101. //平潭花天下,就算选了收款人,也不要给改变开单人,临时解决方案 ssh 2250314
  1102. if (!empty($post['shopAdminId'])) {
  1103. $getStaffName = $post['shopAdminName'] ?? '';
  1104. $shopAdminId = $post['shopAdminId'];
  1105. $shopAdminName = $getStaffName;
  1106. }
  1107. } else {
  1108. $getStaffName = $post['getStaffName'] ?? '';
  1109. $shopAdminId = $post['getStaffId'];
  1110. $shopAdminName = $getStaffName;
  1111. }
  1112. } else {
  1113. if (getenv('YII_ENV') == 'production') {
  1114. //鹏诚需要选择开单人
  1115. if (in_array($this->mainId, [19606])) {
  1116. util::fail('请选择开单人');
  1117. }
  1118. } else {
  1119. if (in_array($this->mainId, [])) {
  1120. util::fail('请选择开单人');
  1121. }
  1122. }
  1123. }
  1124. if (getenv('YII_ENV') == 'production') {
  1125. //小向花卉开单权限
  1126. if ($this->mainId == 23390) {
  1127. if (!in_array($this->adminId, [24043, 24585, 24586, 24654, 24115, 23960, 28456, 31105, 28456, 31105, 52528, 25011, 61449, 77951, 24655])) {
  1128. util::fail('你不能开单哦');
  1129. }
  1130. }
  1131. }
  1132. //开单人和收款人必定是同个人
  1133. $post['shopAdminId'] = $shopAdminId;
  1134. $post['shopAdminName'] = $shopAdminName;
  1135. $post['getStaffId'] = $shopAdminId;
  1136. $post['getStaffName'] = $shopAdminName;
  1137. if (getenv('YII_ENV') == 'production') {
  1138. //南粤选了别的开单人,也只能变成本人开单
  1139. if ($this->mainId == 22388) {
  1140. $post['shopAdminName'] = $shopAdmin->name;
  1141. $post['shopAdminId'] = $shopAdmin->id;
  1142. $post['getStaffId'] = $shopAdmin->id;
  1143. $post['getStaffName'] = $shopAdmin->name;
  1144. }
  1145. } else {
  1146. if ($this->mainId == 644) {
  1147. $post['shopAdminName'] = $shopAdmin->name;
  1148. $post['shopAdminId'] = $shopAdmin->id;
  1149. $post['getStaffId'] = $shopAdmin->id;
  1150. $post['getStaffName'] = $shopAdmin->name;
  1151. }
  1152. }
  1153. $post['sjId'] = $this->sjId;
  1154. $post['shopId'] = $shopId;
  1155. $post['mainId'] = $this->mainId;
  1156. $post['fromType'] = 1;
  1157. $post['expressId'] = $post['expressId'] ?? 0;
  1158. $book = $post['book'] ?? 0;
  1159. $post['book'] = $book;
  1160. $sendType = $post['sendType'] ?? 0;
  1161. $transType = $post['transType'] ?? 0;
  1162. $shop = $this->shop;
  1163. //过期不支持开单
  1164. $deadline = $shop->deadline;
  1165. $deadTime = strtotime($deadline);
  1166. $myCurrentTime = time();
  1167. $myCurrentDeadline = $deadTime;
  1168. if ($myCurrentTime > $myCurrentDeadline) {
  1169. util::fail('系统已到期,请续费哦');
  1170. }
  1171. if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
  1172. //昆明发往全国
  1173. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  1174. $post['sendCost'] = $sendCost;
  1175. $packCost = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  1176. $post['packCost'] = $packCost;
  1177. $post['transType'] = $transType;
  1178. $post['localOrder'] = 1;
  1179. } else {
  1180. //同步配送
  1181. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  1182. if ($sendType != dict::getDict('sendType', 'thirdSend') && $sendCost > 0) {
  1183. util::fail('填了运费,请选择跑腿');
  1184. }
  1185. $post['sendCost'] = $sendCost;
  1186. $post['packCost'] = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  1187. }
  1188. if ($book == 1) {
  1189. $bookSn = $shop->bookSn ?? 0;
  1190. if (empty($bookSn)) {
  1191. util::fail('请开启预订');
  1192. }
  1193. $post['bookSn'] = $bookSn;
  1194. }
  1195. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay'); //收款方式 0:扫码付 1:线下(已付款) 2:赊账(欠款)3:现金 4:余额
  1196. $post['debt'] = OrderClass::DEBT_NO;
  1197. if ($hasPay == dict::getDict('hasPay', 'debt')) {
  1198. $post['debt'] = OrderClass::DEBT_YES;
  1199. }
  1200. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  1201. if ($hasPay == dict::getDict('hasPay', 'payed')) {
  1202. //util::fail('没有权限');
  1203. }
  1204. }
  1205. if (getenv('YII_ENV') == 'production') {
  1206. if ($this->mainId == 1082) {
  1207. //泉城鲜花批发的出车,只能开收现金方式,多处要修改,关键词qc_cash
  1208. if ($hasPay != 0) {
  1209. util::fail('只能使用扫码付款,编号193');
  1210. }
  1211. }
  1212. //小齐鲜花出车,源花汇,不能使用线下收款
  1213. if ($this->mainId == 42680 || $this->mainId == 10536) {
  1214. if ($hasPay == 1) {
  1215. util::fail('线下收款暂时无法使用');
  1216. }
  1217. }
  1218. } else {
  1219. if ($this->mainId == 644) {
  1220. if ($hasPay == 1) {
  1221. //util::fail('线下收款暂时无法使用');
  1222. }
  1223. }
  1224. }
  1225. //多颜色数据整理
  1226. $colorItem = $post['xj'] ?? [];
  1227. $newXj = [];
  1228. if (!empty($colorItem)) {
  1229. $colorData = json_decode($colorItem, true);
  1230. if (!empty($colorData) && is_array($colorData)) {
  1231. foreach ($colorData as $colorInfo) {
  1232. $ptItemId = $colorInfo['ptItemId'] ?? 0;
  1233. $colorList = $colorInfo['list'] ?? [];
  1234. if (!empty($colorList)) {
  1235. foreach ($colorList as $colorItemKey => $colorItem) {
  1236. $newXj[$ptItemId][] = $colorItem;
  1237. }
  1238. }
  1239. }
  1240. }
  1241. }
  1242. $post['xj'] = $newXj;
  1243. $treeData = $post['treeData'] ?? [];
  1244. $newTree = [];
  1245. if (!empty($treeData)) {
  1246. $treeArr = json_decode($treeData, true);
  1247. if (!empty($treeArr) && is_array($treeArr)) {
  1248. foreach ($treeArr as $treeInfo) {
  1249. $ptItemId = $treeInfo['ptItemId'] ?? 0;
  1250. $treeList = $treeInfo['list'] ?? [];
  1251. if (!empty($treeList)) {
  1252. foreach ($treeList as $treeItem) {
  1253. $newTree[$ptItemId][] = $treeItem;
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. $post['treeData'] = $newTree;
  1260. $productJson = $post['product'] ?? '';
  1261. if (empty($productJson)) {
  1262. //直接收款
  1263. $zjGathering = $post['zjGathering'] ?? 0;
  1264. if ($zjGathering == 1) {
  1265. $gatheringPrice = $post['gatheringPrice'] ?? 0;
  1266. if (!is_numeric($gatheringPrice) || $gatheringPrice <= 0) {
  1267. util::fail('请填写价格');
  1268. }
  1269. //直接收款不需要打印小票
  1270. $post['needPrint'] = 2;
  1271. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  1272. $zjGatheringItem = !empty($ext) ? $ext->zjGatheringItem : 0;
  1273. if (empty($zjGatheringItem)) {
  1274. util::fail('请设置收款的商品');
  1275. }
  1276. $zjGatheringItemInfo = ProductClass::getById($zjGatheringItem, true);
  1277. if (empty($zjGatheringItemInfo)) {
  1278. util::fail('请设置收款的商品呢');
  1279. }
  1280. $zjPtItemId = $zjGatheringItemInfo->itemId ?? 0;
  1281. $productList = [['productId' => $zjGatheringItem, 'itemId' => $zjPtItemId, 'bigNum' => 1, 'smallNum' => 0, 'classId' => 0, 'price' => $gatheringPrice]];
  1282. }
  1283. } else {
  1284. $productList = json_decode($productJson, true);
  1285. }
  1286. if (empty($productList)) {
  1287. util::fail('请选择花材');
  1288. }
  1289. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  1290. $itemInfo = ProductClass::getByIds($ids, null, 'id');
  1291. if (empty($itemInfo)) {
  1292. util::fail('请选择花材哦');
  1293. }
  1294. //判断花材有效性
  1295. foreach ($itemInfo as $itemData) {
  1296. if (!isset($itemData['mainId']) || $itemData['mainId'] != $this->mainId) {
  1297. util::fail('只能选择同一家的商品哈');
  1298. }
  1299. }
  1300. $diff = [];
  1301. $priceMap = CustomClass::$levelPriceKeyMap;
  1302. //这个参数应该是要作废的,但下面加的参数是有用的,多处要同步修改,关键词 abandon_add_price_map ,ssh 20260116
  1303. $addPriceMap = CustomClass::$levelAddPriceKeyMap;
  1304. //但这边加的参数是有用的,给指定客户涨价的
  1305. $addPriceMap['risePercent'] = $custom['risePercent'] ?? 0;
  1306. $level = $custom['level'] ?? 1;
  1307. foreach ($productList as $ptKey => $currentProduct) {
  1308. $currentPrice = $currentProduct['price'] ?? 0;
  1309. $currentId = $currentProduct['productId'] ?? 0;
  1310. $systemInfo = $itemInfo[$currentId] ?? [];
  1311. $name = $systemInfo['name'] ?? '';
  1312. $systemPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
  1313. if (getenv('YII_ENV') == 'production') {
  1314. //苏州小蔡鲜花,几个出车,不能低于原价卖,但可以高于原价卖的
  1315. if (in_array($shopId, [38231, 38143, 29163, 29161])) {
  1316. if ($currentPrice < $systemPrice) {
  1317. util::fail('不能低于原价卖');
  1318. }
  1319. }
  1320. } else {
  1321. if (in_array($shopId, [36544])) {
  1322. if ($currentPrice < $systemPrice) {
  1323. util::fail('不能低于原价卖');
  1324. }
  1325. }
  1326. }
  1327. //后端开单,涉及花材满减,关键词 back_order_reach_discount_price
  1328. $post['reachDiscountPrice'] = 0;
  1329. if (floatval($currentPrice) != floatval($systemPrice)) {
  1330. $diff[] = [
  1331. 'name' => $name,
  1332. 'price' => $systemPrice,
  1333. 'kdPrice' => $currentPrice,
  1334. ];
  1335. } else {
  1336. //后端开单,如果没有改价格,并且数量达到花材满减要求,则自动给减价格,关键词 back_order_reach_discount_price
  1337. $bigNum = $currentProduct['bigNum'] ?? 0;
  1338. $reachNum = $systemInfo['reachNum'] ?? 0;
  1339. if ($reachNum > 0 && $bigNum >= $reachNum) {
  1340. $reachNumDiscount = $systemInfo['reachNumDiscount'] ?? 0;
  1341. $unitPrice = $currentProduct['price'] ?? 0;
  1342. if ($unitPrice > $reachNumDiscount) {
  1343. $newUnitPrice = bcsub($unitPrice, $reachNumDiscount, 2);
  1344. $calcPrice = bcmul($reachNumDiscount, $bigNum, 2);
  1345. if ($calcPrice > 0 && isset($post['modifyPrice']) && $post['modifyPrice'] > $calcPrice) {
  1346. $productList[$ptKey]['price'] = $newUnitPrice;
  1347. //提交给后端的总金额也要减掉,否则会有问题
  1348. $post['modifyPrice'] = bcsub($post['modifyPrice'], $calcPrice, 2);
  1349. $post['reachDiscountPrice'] = bcadd($post['reachDiscountPrice'], $calcPrice, 2);
  1350. }
  1351. }
  1352. }
  1353. }
  1354. }
  1355. //解决开单提交订单时,别人修改价格,造成提交价格不是真实卖价问题!!
  1356. if ($dealPrice == 0) {
  1357. if (!empty($diff)) {
  1358. util::success(['diff' => $diff, 'respondType' => 'priceError']);
  1359. }
  1360. } else {
  1361. if (!empty($diff)) {
  1362. $mainId = $this->mainId;
  1363. //花样年华,除了老板,只能按原价开单,不能改价格
  1364. if (getenv('YII_ENV') == 'production') {
  1365. if (in_array($mainId, [1553, 1563])) {
  1366. if ($this->adminId != 2876) {
  1367. util::fail('请按花材原价格开单');
  1368. }
  1369. }
  1370. } else {
  1371. if (in_array($mainId, [0, 1])) {
  1372. util::fail('请按花材原价格开单');
  1373. }
  1374. }
  1375. }
  1376. }
  1377. if ($book == 1) {
  1378. $post['hasPay'] = 2;
  1379. $post['payWay'] = 0;
  1380. }
  1381. $historyDate = $post['historyDate'] ?? '';
  1382. if (!empty($historyDate)) {
  1383. if ($book == 1) {
  1384. util::fail('预订单不能选订单日期');
  1385. }
  1386. if ($hasPay == 0) {
  1387. util::fail('扫码付不能选订单日期');
  1388. }
  1389. }
  1390. $callErrand = $post['callErrand'] ?? 0;
  1391. if ($callErrand == 1) {
  1392. $shopExt = $this->shopExt;
  1393. if ($shopExt->orderFlow == 0) {
  1394. util::fail('下单后要变待发货,才能直接发跑腿');
  1395. }
  1396. }
  1397. $post['product'] = $productList;
  1398. //商家开单到时间会自动标记为欠款,所以360天内不过期,以保证足够时间标记欠款,具体参数查看dict local_gys_kd_auto_set_debt_time
  1399. $time = time();
  1400. $hasTime = dict::getDict('order_pay_has_time');
  1401. $totalTime = bcadd($time, $hasTime);
  1402. $post['deadline'] = date("Y-m-d H:i:s", $totalTime);
  1403. $connection = Yii::$app->db;
  1404. try {
  1405. //多处有用到此方法,需要同步修改,搜索关键词create_new_order
  1406. $return = util::runWithDbConcurrencyRetry(function () use ($connection, $post, $custom, $hasPay) {
  1407. $transaction = $connection->beginTransaction();
  1408. try {
  1409. $return = OrderService::createNewOrder($post, $custom, $hasPay);
  1410. $transaction->commit();
  1411. return $return;
  1412. } catch (\Exception $exception) {
  1413. if ($transaction->isActive) {
  1414. $transaction->rollBack();
  1415. }
  1416. throw $exception;
  1417. }
  1418. });
  1419. $saleId = $return->id ?? 0;
  1420. $order = OrderClass::getById($saleId, true);
  1421. if (!empty($order)) {
  1422. //订单发跑腿流程
  1423. GhsDeliveryOrderClass::prepareAskData($post, $order);
  1424. $shopId = $order->shopId ?? 0;
  1425. $customId = $order->customId ?? 0;
  1426. $ghsId = $order->ghsId ?? 0;
  1427. $custom = CustomClass::getById($customId, true);
  1428. $date = date("Y-m-d H:i:s");
  1429. if (!empty($custom)) {
  1430. $custom->recentExpend = $date;
  1431. $custom->save();
  1432. }
  1433. $ghs = GhsClass::getById($ghsId, true);
  1434. if (!empty($ghs)) {
  1435. $ghs->recentExpend = $date;
  1436. $ghs->save();
  1437. }
  1438. $shop = ShopClass::getById($shopId, true);
  1439. if (isset($order->payStatus) && $order->payStatus == 1) {
  1440. if (!empty($shop)) {
  1441. GhsNotifyClass::newOrderNotify($saleId);
  1442. HdNotifyClass::newCgNotify($order->purchaseId);
  1443. }
  1444. }
  1445. //订单生成时唤起在线打印
  1446. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1447. //预订单开单不打小票,小向花卉不需要打小票
  1448. $mainId = $order->mainId ?? 0;
  1449. if ($order->book == 0 && !in_array($mainId, [23390])) {
  1450. if ($order->status != 1 && $order->status != 5) {
  1451. OrderClass::onlinePrint($order);
  1452. $ext = $this->shopExt;
  1453. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1454. $order->printNum += 1;
  1455. $order->save();
  1456. }
  1457. //花镜 自己开单要打二次,有多处要修改搜索关键词 tow_print
  1458. if (in_array($mainId, [76796])) {
  1459. OrderClass::onlinePrint($order);
  1460. $ext = $this->shopExt;
  1461. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1462. $order->printNum += 1;
  1463. $order->save();
  1464. }
  1465. }
  1466. }
  1467. }
  1468. }
  1469. //前台提醒出示付款码
  1470. if (isset($order->status) && $order->status == 1) {
  1471. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  1472. ShopExtClass::ghsPleasePayReport($order);
  1473. }
  1474. }
  1475. }
  1476. util::success($return);
  1477. } catch (\Exception $e) {
  1478. Yii::error("下单失败原因:" . $e->getMessage());
  1479. noticeUtil::push("批发线下开单失败,原因:" . $e->getMessage(), '15280215347');
  1480. if (util::isDbConcurrencyException($e)) {
  1481. util::fail('系统繁忙中,请稍后再试');
  1482. } else {
  1483. util::fail('下单失败');
  1484. }
  1485. }
  1486. }
  1487. //修改订单 ssh 20210810
  1488. public function actionUpdateOrder()
  1489. {
  1490. $post = Yii::$app->request->post();
  1491. util::fail('订单不可修改');
  1492. //PC端开单
  1493. if (isset($post['clearType'])) {
  1494. $clearType = $post['clearType'];
  1495. if ($clearType == OrderClass::CLEAR_DEBT) {
  1496. $post['debt'] = OrderClass::DEBT_YES;
  1497. $post['payWay'] = dict::getDict('payWay', 'debtPay');
  1498. } else {
  1499. $post['debt'] = OrderClass::DEBT_NO;
  1500. }
  1501. }
  1502. //员工不能开已收款订单
  1503. $debt = $post['debt'] ?? OrderClass::DEBT_YES;
  1504. if ($debt == OrderClass::DEBT_NO) {
  1505. $shopAdmin = $this->shopAdmin;
  1506. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1507. util::fail('不能开已收款订单');
  1508. }
  1509. }
  1510. //PC端开单
  1511. if (isset($post['getType'])) {
  1512. util::fail('暂不支持PC端修改订单');
  1513. $getType = $post['getType'];
  1514. //自取
  1515. if ($getType == 1) {
  1516. $post['sendType'] = OrderClass::SEND_TYPE_NO;
  1517. } else {
  1518. //选择配送时,在发货时让商家自己再确认一下用什么方式
  1519. $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN;
  1520. }
  1521. }
  1522. //商家开非自取订单,默认订单是待收款的,debt字段为非欠款
  1523. if (isset($post['sendType']) && $post['sendType'] != OrderClass::SEND_TYPE_NO) {
  1524. $post['debt'] = OrderClass::DEBT_NO;
  1525. }
  1526. $id = $post['id'] ?? 0;
  1527. $order = OrderClass::getLockById($id);
  1528. if (empty($order)) {
  1529. util::fail('没有找到订单');
  1530. }
  1531. OrderClass::valid($order, $this->shopId);
  1532. unset($post['id']);
  1533. $shopAdmin = $this->shopAdmin;
  1534. $post['shopAdminId'] = $this->shopAdminId;
  1535. $post['shopAdminName'] = $shopAdmin->name ?? '';
  1536. $post['fromType'] = 1;
  1537. $post['sendCost'] = $post['sendCost'] ?? '0.00';
  1538. $productJson = $post['product'] ?? '';
  1539. if (empty($productJson)) {
  1540. util::fail('请选择花材');
  1541. }
  1542. $productList = json_decode($productJson, true);
  1543. if (empty($productList)) {
  1544. util::fail('请选择花材');
  1545. }
  1546. $connection = Yii::$app->db;
  1547. $transaction = $connection->beginTransaction();
  1548. try {
  1549. //判断花材有效性
  1550. ProductClass::valid($productList, $this->mainId);
  1551. $post['product'] = $productList;
  1552. //商家开单订单有效期,到期记欠款
  1553. $validTime = dict::getDict('order_pay_has_time');
  1554. $current = time() + $validTime;
  1555. $post['deadline'] = date("Y-m-d H:i:s", $current);
  1556. $upData = [
  1557. 'payWay' => $post['payWay'],
  1558. 'sendType' => $post['sendType'],
  1559. 'debt' => $post['debt'],
  1560. 'needPrint' => $post['needPrint'],
  1561. 'modifyPrice' => $post['modifyPrice'],
  1562. 'shopAdminId' => $post['shopAdminId'],
  1563. 'shopAdminName' => $post['shopAdminName'],
  1564. 'fromType' => 1,
  1565. 'sendCost' => $post['sendCost'],
  1566. 'product' => $post['product'],
  1567. 'deadline' => $post['deadline'],
  1568. 'debt' => $post['debt'],
  1569. ];
  1570. $return = OrderService::updateOrder($order, $upData);
  1571. $transaction->commit();
  1572. util::success($return);
  1573. } catch (\Exception $e) {
  1574. $transaction->rollBack();
  1575. Yii::error("下单失败原因:" . $e->getMessage());
  1576. util::fail('下单失败');
  1577. }
  1578. }
  1579. //取消预订单 ssh 20240503
  1580. public function actionCancelBookOrder()
  1581. {
  1582. $get = Yii::$app->request->get();
  1583. $id = $get['id'] ?? 0;
  1584. if (empty($id)) {
  1585. util::fail('请选择订单');
  1586. }
  1587. $order = OrderClass::getById($id, true);
  1588. if (empty($order)) {
  1589. util::fail('没有找到订单');
  1590. }
  1591. OrderClass::valid($order, $this->shopId);
  1592. if ($order->book == 0) {
  1593. util::fail('不是预订单');
  1594. }
  1595. if ($order->status != 2) {
  1596. util::fail('当前订单状态不能取消');
  1597. }
  1598. $purchaseId = $order->purchaseId ?? 0;
  1599. $purchase = PurchaseClass::getById($purchaseId, true);
  1600. if (empty($purchase)) {
  1601. util::fail('没有找到采购单');
  1602. }
  1603. $connection = Yii::$app->db;
  1604. $transaction = $connection->beginTransaction();
  1605. try {
  1606. $order->status = 5;
  1607. $order->save();
  1608. $purchase->status = 5;
  1609. $purchase->save();
  1610. $transaction->commit();
  1611. util::complete('取消成功');
  1612. } catch (\Exception $e) {
  1613. $transaction->rollBack();
  1614. $msg = $e->getMessage();
  1615. $orderSn = $order->orderSn ?? '';
  1616. noticeUtil::push("预订单{$orderSn}取消失败:{$msg}", '15280215347');
  1617. }
  1618. }
  1619. //取消订单 shizhongqi 20220619
  1620. public function actionCancelOrder()
  1621. {
  1622. $post = Yii::$app->request->post();
  1623. $id = $post['orderId'] ?? 0;
  1624. if (empty($id)) {
  1625. util::fail('请选择订单');
  1626. }
  1627. $order = OrderClass::getById($id, true);
  1628. if (empty($order)) {
  1629. util::fail('请选择订单...');
  1630. }
  1631. OrderClass::valid($order, $this->shopId);
  1632. if (isset($order->status) == false || $order->status != 1) {
  1633. util::fail('不是待付款状态,无法取消');
  1634. }
  1635. $purchaseId = $order->purchaseId ?? 0;
  1636. $purchase = PurchaseClass::getById($purchaseId);
  1637. if (empty($purchase)) {
  1638. util::fail('没有找到采购单');
  1639. }
  1640. $deadLineTime = strtotime($purchase['deadline']);
  1641. $diff = $deadLineTime - time();
  1642. if ($diff <= 60) {
  1643. util::fail('1分钟后订单将自动取消');
  1644. }
  1645. $connection = Yii::$app->db;
  1646. $transaction = $connection->beginTransaction();
  1647. $orderSn = $purchase['orderSn'];
  1648. try {
  1649. $current = PurchaseClass::getById($purchaseId, true);
  1650. PurchaseService::expire($current);
  1651. $transaction->commit();
  1652. //noticeUtil::push("采购单过期未付款,库存已回滚,单号:{$orderSn}");
  1653. } catch (\Exception $e) {
  1654. $transaction->rollBack();
  1655. $msg = $e->getMessage();
  1656. noticeUtil::push("采购单过期处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
  1657. }
  1658. util::complete();
  1659. }
  1660. //延期支付 ssh 2021.1.19
  1661. public function actionDebt()
  1662. {
  1663. $id = Yii::$app->request->get('id');
  1664. //4秒内不允许重复提交
  1665. $cacheKey = 'ghs_set_order_debt_' . $id;
  1666. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  1667. if (!empty($has)) {
  1668. util::fail('请稍等');
  1669. }
  1670. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
  1671. if (getenv('YII_ENV') == 'production') {
  1672. if ($this->mainId == 1082) {
  1673. //泉城鲜花批发的出车,只能开收现金方式,多处要修改,关键词qc_cash
  1674. util::fail('只能使用扫码付款,编号293');
  1675. }
  1676. } else {
  1677. }
  1678. $order = OrderClass::getById($id, true);
  1679. OrderClass::valid($order, $this->shopId);
  1680. $payWay = dict::getDict('payWay', 'debtPay');
  1681. $cgId = $order->purchaseId ?? 0;
  1682. $cg = PurchaseClass::getById($cgId, true);
  1683. if (empty($cg)) {
  1684. util::fail('没有找到采购单');
  1685. }
  1686. if ($order->book == 1) {
  1687. util::fail('预订单不能记欠款');
  1688. }
  1689. $connection = Yii::$app->db;
  1690. $transaction = $connection->beginTransaction();
  1691. try {
  1692. PurchaseService::payAfter($cg, $payWay);
  1693. OrderService::payAfter($order, $payWay);
  1694. $transaction->commit();
  1695. } catch (\Exception $exception) {
  1696. $transaction->rollBack();
  1697. Yii::info("延期支付报错:" . $exception->getMessage());
  1698. util::fail('操作失败');
  1699. }
  1700. $order = OrderClass::getById($id, true);
  1701. if (!empty($order)) {
  1702. $shopId = $order->shopId ?? 0;
  1703. $shop = ShopClass::getById($shopId, true);
  1704. if (!empty($shop)) {
  1705. //花店采购供货商端微信收到通知
  1706. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  1707. $noticeText = json_encode(['orderId' => $id]);
  1708. $noticeKey = "hdCgNoticeGhs";
  1709. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1710. }
  1711. //订单生成时唤起在线打印
  1712. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1713. if ($order->status != 1 && $order->status != 5) {
  1714. OrderClass::onlinePrint($order);
  1715. $ext = $this->shopExt;
  1716. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1717. $order->printNum += 1;
  1718. $order->save();
  1719. }
  1720. }
  1721. }
  1722. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  1723. GhsDeliveryOrderClass::payAfter($order);
  1724. if ($order->status != 1 && $order->status != 5) {
  1725. //花店采购供货商端APP收到通知
  1726. //NoticeClass::ghsNewOrderNotice($order);
  1727. //向供货商APP发通知
  1728. // $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
  1729. // $push = new push('ghs', push::MSG_TYPE_ORDER);
  1730. // $push->ghsOrderMessage($shop, $cgShop, $order);
  1731. }
  1732. }
  1733. util::complete();
  1734. }
  1735. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  1736. public function actionWxPay()
  1737. {
  1738. ini_set('date.timezone', 'Asia/Shanghai');
  1739. $post = Yii::$app->request->post();
  1740. $couponId = $post['couponId'] ?? 0;
  1741. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  1742. $order = OrderClass::getByOrderSn($orderSn);
  1743. if (empty($order)) {
  1744. util::fail('订单号无效');
  1745. }
  1746. $id = $order['id'];
  1747. //支付前验证订单有效性
  1748. if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
  1749. util::fail('无法操作');
  1750. }
  1751. $name = $order['orderName'] ?? '购买商品';
  1752. $totalFee = $order['actPrice'];
  1753. //强制使用小程序的miniOpenId
  1754. $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
  1755. if (empty($openId)) {
  1756. util::fail('没有找到openId');
  1757. }
  1758. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  1759. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  1760. $wxPayType = 0;
  1761. if (httpUtil::isMiniProgram()) {
  1762. $wxPayType = 1;
  1763. }
  1764. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  1765. //订单30分钟后过期
  1766. $now = time();
  1767. $expireTime = $now + 1800;
  1768. $wx = Yii::getAlias("@vendor/weixin");
  1769. require_once($wx . '/lib/WxPay.Api.php');
  1770. require_once($wx . '/example/WxPay.JsApiPay.php');
  1771. $input = new \WxPayUnifiedOrder();
  1772. $input->SetBody($name);
  1773. $input->SetOut_trade_no($orderSn);
  1774. $input->SetTotal_fee($totalFee * 100);
  1775. $input->SetTime_start(date("YmdHis", $now));
  1776. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  1777. $input->SetTime_expire(date("YmdHis", $expireTime));
  1778. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  1779. $input->SetTrade_type("JSAPI");
  1780. //花卉宝代为申请的微信支付
  1781. //$sjExtend = $this->sjExtend->attributes;
  1782. $sjExtend = WxOpenClass::getGhsWxInfo();
  1783. if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
  1784. $input->SetSub_openid($openId);
  1785. } else {
  1786. $input->SetOpenid($openId);
  1787. }
  1788. //强制使用小程序的miniAppId
  1789. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  1790. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  1791. $tools = new \JsApiPay();
  1792. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  1793. $newParams = json_decode($jsApiParameters, true);
  1794. //微信不能修改价格
  1795. $current = date("Y-m-d H:i:s");
  1796. $updateData = ['deadline' => $current, 'modPrice' => 0];
  1797. OrderClass::updateById($id, $updateData);
  1798. util::success($newParams);
  1799. }
  1800. //获取订单详情 ssh 2021.1.21
  1801. public function actionDetail()
  1802. {
  1803. $get = Yii::$app->request->get();
  1804. $id = $get['id'] ?? 0;
  1805. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1806. OrderClass::valid($info, $this->shopId);
  1807. //A4打印需要用到的数据
  1808. $customId = $info['customId'] ?? 0;
  1809. $remark = $info['remark'] ?? '';
  1810. $sendCost = $info['sendCost'] ?? 0;
  1811. $sendNum = $info['sendNum'] ?? '';
  1812. $packCost = $info['packCost'] ?? 0;
  1813. $staffName = $info['shopAdminName'] ?? '';
  1814. $ysName = '';
  1815. if (isset($info['localOrder']) && $info['localOrder'] == 1) {
  1816. if ($info['transType'] == 0) {
  1817. $ysName = '德邦空运';
  1818. }
  1819. if ($info['transType'] == 1) {
  1820. $ysName = '顺丰空运';
  1821. }
  1822. if ($info['transType'] == 2) {
  1823. $ysName = '冷链物流';
  1824. }
  1825. if ($info['transType'] == 3) {
  1826. $ysName = '航空物流';
  1827. }
  1828. if ($info['transType'] == 4) {
  1829. $ysName = '同城配送';
  1830. }
  1831. if ($info['transType'] == 5) {
  1832. $ysName = '到店自取';
  1833. }
  1834. } else {
  1835. $sendType = $info['sendType'] ?? 0;
  1836. $ysName = '送货上门';
  1837. if ($sendType == 1) {
  1838. $ysName = '到店自取';
  1839. }
  1840. if ($sendType == 2) {
  1841. $ysName = '发跑腿';
  1842. }
  1843. if ($sendType == 3) {
  1844. $wlName = $info['wlName'] ?? '';
  1845. $ysName = '发物流';
  1846. if (!empty($wlName)) {
  1847. $ysName = $ysName . '-' . $wlName;
  1848. }
  1849. }
  1850. }
  1851. $fullAddress = '';
  1852. if (getenv('YII_ENV') == 'production') {
  1853. //老油的要显示地址
  1854. if ($this->mainId == 20528) {
  1855. $fullAddress = $info['fullAddress'] ?? '';
  1856. }
  1857. } else {
  1858. if ($this->mainId == 644) {
  1859. $fullAddress = $info['fullAddress'] ?? '';
  1860. }
  1861. }
  1862. $custom = CustomClass::getById($customId, true);
  1863. if (empty($custom)) {
  1864. util::fail('没有找到客户');
  1865. }
  1866. $customName = $custom->name ?? '';
  1867. $customMobile = $custom->customMobile ?? '';
  1868. if (empty($customMobile)) {
  1869. $customShopId = $custom->shopId ?? 0;
  1870. $customShop = ShopClass::getById($customShopId, true);
  1871. if (!empty($customShop)) {
  1872. $customMobile = $customShop->mobile ?? '';
  1873. }
  1874. }
  1875. if (!empty($customMobile)) {
  1876. $customMobile = substr_replace($customMobile, '****', 3, 4);
  1877. }
  1878. $fullCustom = $customName . ' ' . $customMobile;
  1879. if ($this->mainId == 8164) {
  1880. //花大苪不显示客户名称
  1881. $fullCustom = '';
  1882. }
  1883. $seatSn = isset($custom->seatSn) && !empty($custom->seatSn) ? $custom->seatSn : '无';
  1884. $sendTimeWant = $info['sendTimeWant'] ?? '';
  1885. $shortSendTimeWant = !empty($sendTimeWant) ? substr($sendTimeWant, 5, 5) : '';
  1886. $totalItemNum = 0;
  1887. $totalSmallItemNum = 0;
  1888. $table = [];
  1889. if (isset($info['product']) && !empty($info['product'])) {
  1890. foreach ($info['product'] as $key => $val) {
  1891. $currentName = $val['name'] ?? '';
  1892. $num = $val['xhNum'] ?? 0;
  1893. $refundNum = $val['refundNum'] ?? 0;
  1894. $num = bcsub($num, $refundNum);
  1895. $totalItemNum = bcadd($totalItemNum, $num);
  1896. $ratio = $val['ratio'] ?? 0;
  1897. $currentSmallNum = bcmul($num, $ratio);
  1898. $totalSmallItemNum = bcadd($totalSmallItemNum, $currentSmallNum);
  1899. $itemRemark = $val['remark'] ?? '';
  1900. $unitPrice = $val['xhUnitPrice'] ?? 0;
  1901. $unitPrice = floatval($unitPrice);
  1902. $price = bcmul($unitPrice, $num, 2);
  1903. $price = floatval($price);
  1904. $table[] = [
  1905. 'name' => $currentName,
  1906. 'num' => $num,
  1907. 'confirmNum' => '',
  1908. 'remark' => $itemRemark,
  1909. 'wxNumber' => 'shish3508',
  1910. 'unitPrice' => $unitPrice,
  1911. 'price' => $price,
  1912. ];
  1913. }
  1914. }
  1915. $shop = $this->shop;
  1916. $sjName = $shop->merchantName ?? '';
  1917. $shopName = $shop->shopName ?? '';
  1918. $sjShopName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1919. $a4Print = [
  1920. 'customName' => $fullCustom,
  1921. 'staffName' => $staffName,
  1922. 'seatSn' => $seatSn,
  1923. 'shortSendTimeWant' => $shortSendTimeWant,
  1924. 'table' => $table,
  1925. 'remark' => $remark,
  1926. 'fullAddress' => $fullAddress,
  1927. 'sendNum' => $sendNum,
  1928. 'sendCost' => $sendCost,
  1929. 'ysName' => $ysName,
  1930. 'packCost' => $packCost,
  1931. 'totalItemNum' => $totalItemNum,
  1932. 'totalSmallItemNum' => $totalSmallItemNum,
  1933. 'shopName' => $sjShopName . ' 销售单',
  1934. ];
  1935. $info['printData'] = $a4Print;
  1936. //常规模板
  1937. //有用的历史备份
  1938. $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}}]}';
  1939. //$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}}]}';
  1940. if (getenv('YII_ENV') == 'production') {
  1941. //花大苪模板
  1942. if (in_array($this->mainId, [8164])) {
  1943. $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":{}}]}';
  1944. }
  1945. if (in_array($this->mainId, [44282])) {
  1946. //$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}}]}';
  1947. $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}}]}';
  1948. }
  1949. }
  1950. $info['template'] = $template;
  1951. $printType = $get['printType'] ?? 0;
  1952. if ($printType == 1) {
  1953. //打多联的模板
  1954. $table = [];
  1955. if (isset($info['product']) && !empty($info['product'])) {
  1956. foreach ($info['product'] as $key => $val) {
  1957. $currentName = $val['name'] ?? '';
  1958. $num = $val['xhNum'] ?? 0;
  1959. $refundNum = $val['refundNum'] ?? 0;
  1960. $num = bcsub($num, $refundNum);
  1961. $totalItemNum = bcadd($totalItemNum, $num);
  1962. $ratio = $val['ratio'] ?? 0;
  1963. $currentSmallNum = bcmul($num, $ratio);
  1964. $totalSmallItemNum = bcadd($totalSmallItemNum, $currentSmallNum);
  1965. $itemRemark = $val['remark'] ?? '';
  1966. $unitPrice = $val['xhUnitPrice'] ?? 0;
  1967. $unitPrice = floatval($unitPrice);
  1968. $price = bcmul($unitPrice, $num, 2);
  1969. $price = floatval($price);
  1970. $table[] = [
  1971. 'name' => $currentName,
  1972. 'num' => $num,
  1973. 'orderNum' => '',
  1974. 'remark' => $itemRemark,
  1975. 'wxNumber' => 'shish3508',
  1976. 'unitPrice' => '¥' . $unitPrice,
  1977. 'price' => '¥' . $price,
  1978. 'refundNum' => $refundNum == 0 ? '' : 0,
  1979. ];
  1980. }
  1981. }
  1982. $orderSn = $info['orderSn'] ?? '';
  1983. $kind = $info['productStat'] && $info['productStat']['kind'] ?? 0;
  1984. $totalItemNum = $info['productStat'] && $info['productStat']['bigNum'] ?? 0;
  1985. $addTime = $info['addTime'] ?? '';
  1986. $actPrice = $info['actPrice'] ?? 0;
  1987. $tkPrice = $info['tkPrice'] ?? 0;
  1988. $prePrice = $info['prePrice'] ?? 0;
  1989. $customMobile = $info['customMobile'] ?? '';
  1990. $address = '';
  1991. if (isset($info['address']) && !empty($info['address'])) {
  1992. $address .= $info['fullAddress'];
  1993. if (isset($info['showAddress']) && !empty($info['showAddress']) && $info['showAddress'] != $info['fullAddress']) {
  1994. $address .= '(' . $info['showAddress'] . ')<BR>';
  1995. }
  1996. }
  1997. $printData = [
  1998. 'table' => $table,
  1999. 'addTime' => '',
  2000. 'entryTime' => $addTime,
  2001. 'ghsName' => $customName,
  2002. 'clearCode' => '',
  2003. 'staffName' => '',
  2004. 'telephone' => $customMobile,
  2005. 'kind' => $kind,
  2006. 'orderSn' => $orderSn,
  2007. 'sjShopName' => $sjShopName . ' 销售单',
  2008. 'sjShopName2' => $sjShopName,
  2009. 'prePrice' => '¥' . $prePrice,
  2010. 'tkPrice' => '¥' . $tkPrice,
  2011. 'realPrice' => '¥' . $actPrice,
  2012. 'totalItemNum' => $totalItemNum,
  2013. 'numKind' => "共" . $kind . "种,数量:" . $totalItemNum,
  2014. 'address' => $address,
  2015. 'saleName'=>'销售单',
  2016. ];
  2017. $info['printData'] = $printData;
  2018. $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}}]}';
  2019. if (in_array($this->mainId, [91452])) {
  2020. //绿科花卉种苗
  2021. $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}}]}';
  2022. }
  2023. $info['template'] = $template;
  2024. }
  2025. //是否有云打印判断
  2026. $hasCloudPrint = 0;
  2027. $shopExt = $this->shopExt;
  2028. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  2029. $hasCloudPrint = 1;
  2030. }
  2031. $info['hasCloudPrint'] = $hasCloudPrint;
  2032. $purchaseId = $info['purchaseId'] ?? 0;
  2033. $cg = PurchaseClass::getById($purchaseId);
  2034. $info['cgInfo'] = $cg;
  2035. //店长信息
  2036. $mainId = $cg['mainId'] ?? 0;
  2037. $superInfo = ShopAdminClass::getManager($mainId);
  2038. $info['customSuper'] = $superInfo;
  2039. //员工是否有财务权限 ssh 20251117
  2040. $staff = $this->shopAdmin;
  2041. $staffFinance = $staff->finance ?? 0;
  2042. $info['staffFinance'] = $staffFinance;
  2043. $shopBusiness = $shop->business ?? 0;
  2044. $info['shopBusiness'] = $shopBusiness;
  2045. util::success($info);
  2046. }
  2047. //获取订单信息 ssh 20240102
  2048. public function actionGetInfoByOrderSn()
  2049. {
  2050. $get = Yii::$app->request->get();
  2051. $orderSn = $get['orderSn'] ?? '';
  2052. $info = OrderService::getByCondition(['orderSn' => $orderSn], true);
  2053. if (empty($info)) {
  2054. util::fail('没有找到订单');
  2055. }
  2056. if ($info->mainId != $this->mainId) {
  2057. util::fail('不是你的订单哦');
  2058. }
  2059. util::success(['info' => $info]);
  2060. }
  2061. //获取订单详情,不需要登录可以访问,后面要删除此方法 ssh 20220819
  2062. public function actionInfo()
  2063. {
  2064. $get = Yii::$app->request->get();
  2065. $id = $get['id'] ?? 0;
  2066. $info = OrderService::getOrderInfo($id, true, true, true, false);
  2067. if (empty($info)) {
  2068. util::fail('没有找到订单');
  2069. }
  2070. //是否有云打印判断
  2071. $hasCloudPrint = 0;
  2072. $shopExt = $this->shopExt;
  2073. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  2074. $hasCloudPrint = 1;
  2075. }
  2076. $info['hasCloudPrint'] = $hasCloudPrint;
  2077. $purchaseId = $info['purchaseId'] ?? 0;
  2078. $cg = PurchaseClass::getById($purchaseId);
  2079. $info['cgInfo'] = $cg;
  2080. //店长信息
  2081. $mainId = $cg['mainId'] ?? 0;
  2082. $superInfo = ShopAdminClass::getManager($mainId);
  2083. $info['customSuper'] = $superInfo;
  2084. util::success($info);
  2085. }
  2086. //自取免发货流程处理 ssh 2021.1.22
  2087. public function actionWithoutSend()
  2088. {
  2089. util::complete();
  2090. }
  2091. //本店送 ssh 2021.1.24
  2092. public function actionSelfSend()
  2093. {
  2094. $get = Yii::$app->request->get();
  2095. $id = isset($get['id']) ? $get['id'] : 0;
  2096. $info = OrderClass::getById($id, true);
  2097. OrderClass::valid($info->attributes, $this->shopId);
  2098. $connection = Yii::$app->db;
  2099. $transaction = $connection->beginTransaction();
  2100. try {
  2101. OrderClass::selfSend($info);
  2102. $transaction->commit();
  2103. } catch (\Exception $exception) {
  2104. $transaction->rollBack();
  2105. Yii::info("本店送操作报错:" . $exception->getMessage());
  2106. util::fail('操作失败');
  2107. }
  2108. util::complete();
  2109. }
  2110. //运费计算 ssh 2021.1.24
  2111. public function actionFreight()
  2112. {
  2113. //2021.3.28 接入达达
  2114. $get = Yii::$app->request->get();
  2115. $post = Yii::$app->request->post();
  2116. if (empty($get)) {
  2117. $get = $post;
  2118. }
  2119. $orderId = $get['id'] ?? 0; //订单ID
  2120. $customId = $get['customId'] ?? 0;
  2121. if (empty($orderId)) {
  2122. //自定义运费
  2123. //freight::getCost();
  2124. if (empty($customId)) {
  2125. util::fail("请选择客户");
  2126. }
  2127. $customInfo = CustomClass::getById($customId);
  2128. if (empty($customInfo)) {
  2129. util::fail('没有找到客户');
  2130. }
  2131. $shop = $this->shop;
  2132. //花材信息
  2133. $productJson = $get['product'] ?? '';
  2134. // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
  2135. if (empty($productJson)) {
  2136. util::fail('请选择花材');
  2137. }
  2138. $productList = json_decode($productJson, true);
  2139. if (empty($productList)) {
  2140. util::fail('请选择花材');
  2141. }
  2142. $productList = ProductClass::mergeItemInfo($productList);
  2143. $weight = 0;
  2144. $price = 0;
  2145. $productData = ProductClass::getProductMapData($productList);
  2146. $bigNum = 0;
  2147. foreach ($productList as $key => $val) {
  2148. $productId = $val['productId'];
  2149. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  2150. $bigNum += $val['bigNum'];
  2151. $weight = bcadd($w, $weight, 2);
  2152. $ratio = $productData[$productId]['ratio'] ?? 0;
  2153. //大小数量合并多少扎
  2154. $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  2155. //售卖价格
  2156. $itemPrice = $productData[$productId]['price'] ?? 0;
  2157. //合计价格
  2158. $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2);
  2159. }
  2160. //没有经纬度的客户运费直接返回空 ssh 20210612
  2161. if (empty($customInfo['lat']) || empty($customInfo['long'])) {
  2162. util::success(['sedCost' => '']);
  2163. }
  2164. $cost = freight::getCost($shop->lat, $shop->long, $customInfo['lat'], $customInfo['long'], $weight);
  2165. util::success(['sedCost' => $cost]);
  2166. }
  2167. $province = $get['province'] ?? '';
  2168. $city = $get['city'] ?? '';
  2169. $address = $get['address'] ?? '';
  2170. $floor = $get['floor'] ?? '';
  2171. $customName = $get['customName'] ?? '';
  2172. $customMobile = $get['customMobile'] ?? '';
  2173. $fullAddress = $province . $city . $address . $floor;
  2174. $sendTime = $get['sendTime'] ?? '';
  2175. $lat = $get['lat'] ?? '';
  2176. $lng = $get['long'] ?? '';
  2177. if (empty($lat) || empty($lng) || empty($fullAddress)) {
  2178. util::fail('请填写客户地址');
  2179. }
  2180. ini_set('date.timezone', 'Asia/Shanghai');
  2181. if (!empty($sendTime)) {
  2182. //配送时间不为空
  2183. // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
  2184. $sendTimeInt = strtotime($sendTime);
  2185. $now = time();
  2186. $diff = $sendTimeInt - $now;
  2187. //因服务器写入时间,改为至少提前6分钟
  2188. if ($diff <= 360) {
  2189. util::fail('配送时间至少提前6分钟');
  2190. }
  2191. } else {
  2192. //默认立即发送
  2193. $sendTime = 0;
  2194. }
  2195. //更新订单表
  2196. $info = OrderService::getOrderInfo($orderId);
  2197. OrderClass::valid($info, $this->shopId);
  2198. if ($sendTime) {
  2199. $sendTime = date('Y-m-d H:i', strtotime($sendTime));
  2200. } else {
  2201. $sendTime = '0000-00-00 00:00:00';
  2202. }
  2203. $expressAddInfo = [
  2204. 'customName' => $customName,
  2205. 'customMobile' => $customMobile,
  2206. 'province' => $province,
  2207. 'city' => $city,
  2208. 'address' => $address,
  2209. 'floor' => $floor,
  2210. 'lat' => $lat,
  2211. 'long' => $lng,
  2212. 'sendTime' => $sendTime,
  2213. ];
  2214. OrderClass::updateCustomExpressInfo($orderId, $expressAddInfo);
  2215. //计算运费
  2216. $info['province'] = $province;
  2217. $info['city'] = $city;
  2218. $info['address'] = $address;
  2219. $info['floor'] = $floor;
  2220. $info['fullAddress'] = $fullAddress;
  2221. $info['lat'] = $lat;
  2222. $info['long'] = $lng;
  2223. $info['sendTime'] = $expressAddInfo['sendTime'];
  2224. $res = DadaExpressServices::queryDeliverFee($info);
  2225. util::success(['sedCost' => $res['fee']]);
  2226. }
  2227. //发快递和第三方配送 ssh 2021.1.24
  2228. public function actionThirdSend()
  2229. {
  2230. $get = Yii::$app->request->get();
  2231. $id = isset($get['id']) ? $get['id'] : 0;
  2232. $info = OrderService::getById($id, true);
  2233. OrderClass::valid($info->attributes, $this->shopId);
  2234. if (empty($info->lat) || empty($info->long) || empty($info->fullAddress)) {
  2235. util::fail('请填写客户地址');
  2236. }
  2237. $connection = Yii::$app->db;
  2238. $transaction = $connection->beginTransaction();
  2239. try {
  2240. $respond = OrderClass::thirdSend($info, $get);
  2241. $transaction->commit();
  2242. util::success($respond);
  2243. } catch (\Exception $exception) {
  2244. $transaction->rollBack();
  2245. Yii::info("发快递操作报错:" . $exception->getMessage());
  2246. util::fail('操作失败' . $exception->getMessage());
  2247. }
  2248. }
  2249. //确认送达 ssh 2021.1.24
  2250. public function actionReach()
  2251. {
  2252. $get = Yii::$app->request->get();
  2253. $id = isset($get['id']) ? $get['id'] : 0;
  2254. $info = OrderClass::getById($id, true);
  2255. OrderClass::valid($info->attributes, $this->shopId);
  2256. $connection = Yii::$app->db;
  2257. $transaction = $connection->beginTransaction();
  2258. try {
  2259. OrderService::reach($info);
  2260. $transaction->commit();
  2261. } catch (\Exception $exception) {
  2262. $transaction->rollBack();
  2263. Yii::info("送达操作报错:" . $exception->getMessage());
  2264. util::fail('操作失败');
  2265. }
  2266. util::complete();
  2267. }
  2268. //下单要用到的相关信息 ssh 2019.12.6
  2269. public function actionOrderRelate()
  2270. {
  2271. $regionTree = RegionService::tree();
  2272. $shop = $this->shop->attributes;
  2273. $freight = ['first' => 5, 'add' => 2];
  2274. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  2275. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'thirdMapKey' => $mapKey, 'merchant' => $shop];
  2276. util::success($out);
  2277. }
  2278. //客户欠款的订单 ssh 2021.2.4
  2279. public function actionDebtList()
  2280. {
  2281. $get = Yii::$app->request->get();
  2282. $id = $get['id'] ?? 0;
  2283. $info = CustomClass::getCustom($id);
  2284. CustomClass::valid($info, $this->shopId);
  2285. $mainId = $this->mainId;
  2286. $where = ['mainId' => $mainId, 'customId' => $id, 'debt' => 1];
  2287. $searchTime = $get['searchTime'] ?? '';
  2288. if (!empty($searchTime)) {
  2289. $startTime = $get['startTime'] ?? '';
  2290. $endTime = $get['endTime'] ?? '';
  2291. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  2292. $where['payTime'] = ['between', [$period['startTime'], $period['endTime']]];
  2293. } else {
  2294. if ($mainId == 33447 && $id == 51031) {
  2295. util::fail('请选时间');
  2296. }
  2297. }
  2298. $allowedPageSizes = [100, 200, 300];
  2299. $pageSize = isset($get['pageSize']) && in_array((int)$get['pageSize'], $allowedPageSizes, true)
  2300. ? (int)$get['pageSize'] : 100;
  2301. $page = max(1, (int)($get['page'] ?? 1));
  2302. $fields = ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice', 'debtPrice', 'payTime'];
  2303. Yii::$app->request->setQueryParams(array_merge($get, ['page' => $page, 'pageSize' => $pageSize]));
  2304. $result = OrderClass::getList($fields, $where, 'addTime DESC');
  2305. if (!empty($result['list'])) {
  2306. foreach ($result['list'] as $key => $value) {
  2307. $debtPrice = $value['debtPrice'] ?? 0;
  2308. $remainDebtPrice = $value['remainDebtPrice'] ?? 0;
  2309. $hasPayDebt = '0.00';
  2310. if (bccomp((string)$debtPrice, (string)$remainDebtPrice, 2) > 0) {
  2311. $hasPayDebt = bcsub((string)$debtPrice, (string)$remainDebtPrice, 2);
  2312. }
  2313. $result['list'][$key]['hasPayDebt'] = floatval($hasPayDebt);
  2314. }
  2315. }
  2316. $result['customInfo'] = $info;
  2317. util::success($result);
  2318. }
  2319. //更新打印次数
  2320. public function actionAddPrintNum()
  2321. {
  2322. $id = Yii::$app->request->get('id', 0);
  2323. $order = OrderClass::getById($id, true);
  2324. OrderClass::valid($order, $this->shopId);
  2325. $order->printNum += 1;
  2326. $order->save();
  2327. util::complete();
  2328. }
  2329. //打印订单 ssh 20210714
  2330. public function actionCloudPrintOrder()
  2331. {
  2332. $get = Yii::$app->request->get();
  2333. $id = $get['id'] ?? 0;
  2334. $showPrice = $get['showPrice'] ?? 1;
  2335. $order = OrderClass::getById($id, true);
  2336. OrderClass::valid($order, $this->shopId);
  2337. if ($order->status == OrderClass::ORDER_STATUS_UN_PAY) {
  2338. util::fail('订单还没有付款');
  2339. }
  2340. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  2341. util::fail('订单已取消');
  2342. }
  2343. $ext = $this->shopExt;
  2344. if (isset($ext->printSn) == false || isset($ext->printKey) == false || empty($ext->printSn) || empty($ext->printKey)) {
  2345. util::success(['hasNoPrint' => 1]);
  2346. }
  2347. OrderClass::onlinePrint($order, $showPrice);
  2348. $order->printNum += 1;
  2349. $order->save();
  2350. util::complete();
  2351. }
  2352. //订单确认完成 ssh 20210809
  2353. public function actionConfirmFinish()
  2354. {
  2355. $payWay = Yii::$app->request->get('payWay', -1);
  2356. $id = Yii::$app->request->get('id', 0);
  2357. $clearType = Yii::$app->request->get('clearType', 0);
  2358. $connection = Yii::$app->db;
  2359. $transaction = $connection->beginTransaction();
  2360. try {
  2361. $order = OrderClass::getById($id, true);
  2362. OrderClass::valid($order, $this->shopId);
  2363. $purchaseId = $order->purchaseId ?? 0;
  2364. $purchase = PurchaseClass::getById($purchaseId, true);
  2365. if (empty($purchase)) {
  2366. util::fail('没有采购信息');
  2367. }
  2368. if ($clearType == 1) {
  2369. //欠款
  2370. $payWay = dict::getDict('payWay', 'debtPay');
  2371. } elseif ($clearType == 2) {
  2372. //已收款
  2373. if ($payWay == -1) {
  2374. util::fail('请选择收款方式');
  2375. }
  2376. $shopAdmin = $this->shopAdmin;
  2377. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  2378. util::fail('超管才能发起已收款');
  2379. }
  2380. } else {
  2381. util::fail('请选择结算方式');
  2382. }
  2383. //不需要打印
  2384. $order->needPrint = dict::getDict('needPrint', 'noNeed');
  2385. $order->save();
  2386. //支付
  2387. PurchaseService::payAfter($purchase, $payWay);
  2388. OrderService::payAfter($order, $payWay);
  2389. //自己送
  2390. $info = OrderClass::getById($id, true);
  2391. OrderClass::selfSend($info);
  2392. //确认送达,并且不需要微信通知
  2393. Yii::$app->params['noNeedWxNotice'] = 1;
  2394. $info = OrderClass::getById($id, true);
  2395. OrderService::reach($info);
  2396. $transaction->commit();
  2397. util::complete('操作成功');
  2398. } catch (\Exception $exception) {
  2399. $transaction->rollBack();
  2400. Yii::info("确认完成订单报错:" . $exception->getMessage());
  2401. util::fail('操作失败');
  2402. }
  2403. }
  2404. //取消订单 ssh 20220110
  2405. public function actionCancel()
  2406. {
  2407. $shopAdmin = $this->shopAdmin;
  2408. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  2409. util::fail('超管才能取消订单');
  2410. }
  2411. $id = Yii::$app->request->get('id');
  2412. $order = OrderClass::getById($id, true);
  2413. if ($order->orderType == 2) {
  2414. util::fail('客户下单,不能主动取消');
  2415. }
  2416. OrderClass::valid($order, $this->shopId);
  2417. OrderService::expire($order, true);
  2418. util::complete('已取消');
  2419. }
  2420. //获取收款语音播报地址 ssh 20211231
  2421. public function actionGetPayVoice()
  2422. {
  2423. $id = Yii::$app->request->get('id');
  2424. $order = OrderClass::getById($id, true);
  2425. $payWay = $order->payWay ?? 0;
  2426. $money = floatval($order->actPrice);
  2427. $payment = $payWay == dict::getDict('payWay', 'alipay') ? '支付宝' : '微信';
  2428. $msg = $payment . '收款' . $money . '元';
  2429. $audio = baiduAip::transfer($msg, 4, 0);
  2430. //上传到oss
  2431. $file = time() . rand(10000, 999999) . '.mp3';
  2432. $filePath = 'tmp/arrival/money/' . $file;
  2433. oss::uploadTmpAudio($filePath, $audio);
  2434. $url = Yii::$app->params['ghsImgHost'] . $filePath;
  2435. util::success(['url' => $url]);
  2436. }
  2437. //修改备注
  2438. public function actionModifyRemark()
  2439. {
  2440. $post = Yii::$app->request->post();
  2441. $id = $post['id'] ?? 0;
  2442. $remark = $post['remark'] ?? '';
  2443. $order = OrderClass::getById($id, true);
  2444. if (empty($order)) {
  2445. util::fail('没有找到订单');
  2446. }
  2447. if ($order->mainId != $this->mainId) {
  2448. util::fail('不是你的订单');
  2449. }
  2450. $cgId = $order->purchaseId ?? 0;
  2451. $cg = PurchaseClass::getById($cgId, true);
  2452. if (empty($cg)) {
  2453. util::fail('采购单没有找到');
  2454. }
  2455. $order->remark = $remark;
  2456. $order->save();
  2457. $cg->remark = $remark;
  2458. $cg->save();
  2459. util::complete('修改成功');
  2460. }
  2461. //修改订单的确认时间 ssh 20240511
  2462. public function actionModifyOrderConfirmTime()
  2463. {
  2464. $get = Yii::$app->request->get();
  2465. $id = $get['id'] ?? 0;
  2466. $date = $get['date'] ?? '';
  2467. if (empty($date)) {
  2468. util::fail('请选择日期');
  2469. }
  2470. $connection = Yii::$app->db;
  2471. $transaction = $connection->beginTransaction();//开启事务
  2472. try {
  2473. $order = OrderClass::getById($id, true);
  2474. if (empty($order)) {
  2475. util::fail('没有找到订单');
  2476. }
  2477. if ($order->mainId != $this->mainId) {
  2478. util::fail('不是你的订单');
  2479. }
  2480. if ($order->payStatus == 0) {
  2481. util::fail('没有确认的订单');
  2482. }
  2483. $mainId = $this->mainId;
  2484. //超管或者约定的人可以修改日期
  2485. if (getenv('YII_ENV') == 'production') {
  2486. if (in_array($mainId, [23390])) {
  2487. if (!in_array($this->adminId, [24586, 23960, 24043])) {
  2488. util::fail('你不能修改哦');
  2489. }
  2490. }
  2491. }
  2492. $payTime = $order->payTime;
  2493. $timeArr = explode(' ', $payTime);
  2494. $dateStr = $timeArr[0];
  2495. if ($dateStr == $date) {
  2496. util::fail('日期没变');
  2497. }
  2498. $after = $timeArr[1];
  2499. $new = $date . ' ' . $after;
  2500. $cgId = $order->purchaseId ?? 0;
  2501. $cg = PurchaseClass::getById($cgId, true);
  2502. if (empty($cg)) {
  2503. util::fail('没有找到订单信息');
  2504. }
  2505. $order->payTime = $new;
  2506. $order->save();
  2507. $cg->payTime = $new;
  2508. $cg->save();
  2509. //有修改账单日期需要更新到欠款变动明细,财务好对账,多个地方要同步修改,关键词 to_change_custom_debt_pay_time
  2510. CustomDebtChangeClass::updateByCondition(['capitalType' => 10, 'relateId' => $id], ['payTime' => $new]);
  2511. //找到当前订单客户的账单日期为 $date 的所有订单,然后更新同天内的所有订单的 sameTimeIds(加此次要改变的订单的订单号$id),有多处调用,关键词 update_same_ids
  2512. OrderClass::updateSameTimeIds($order, $date);
  2513. PurchaseClass::updateMergeCg($cg, 1);
  2514. OrderClass::updateMergeOrder($order, 1);
  2515. $transaction->commit();
  2516. util::complete('修改成功');
  2517. } catch (\Exception $e) {
  2518. $transaction->rollBack();
  2519. util::fail('修改失败');
  2520. }
  2521. }
  2522. //应收款统计 ssh 20240528
  2523. public function actionAccountList()
  2524. {
  2525. $get = Yii::$app->request->get();
  2526. $mainId = $this->mainId;
  2527. $export = $get['export'] ?? 0;
  2528. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : -1;
  2529. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2530. $startTime = $get['startTime'] ?? '';
  2531. $endTime = $get['endTime'] ?? '';
  2532. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2533. $start = $period['startTime'];
  2534. $end = $period['endTime'];
  2535. $customList = CustomClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name', 'id');
  2536. $currentStartDate = date('Y-m-d', strtotime($start));
  2537. $currentEndDate = date('Y-m-d', strtotime($end));
  2538. $currentStartTime = $currentStartDate . ' 00:00:00';
  2539. $currentEndTime = $currentEndDate . ' 23:59:59';
  2540. $where = ['mainId' => $mainId];
  2541. if ($debt > -1) {
  2542. $where['debt'] = $debt;
  2543. }
  2544. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  2545. $orderList = OrderClass::getAllByCondition($where, null, '*');
  2546. $list = [];
  2547. $totalAmount = 0;
  2548. if (!empty($orderList)) {
  2549. foreach ($orderList as $orderInfo) {
  2550. $actPrice = $orderInfo['actPrice'] ?? 0;
  2551. $customId = $orderInfo['customId'] ?? 0;
  2552. $status = $orderInfo['status'] ?? 0;
  2553. $book = $orderInfo['book'] ?? 0;
  2554. if ($status == 1 || $status == 5) {
  2555. continue;
  2556. }
  2557. if ($book == 1 && $status == 2) {
  2558. continue;
  2559. }
  2560. if (isset($list[$customId])) {
  2561. $list[$customId]['amount'] = bcadd($list[$customId]['amount'], $actPrice, 2);
  2562. $list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
  2563. } else {
  2564. $name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
  2565. $list[$customId] = ['id' => $customId, 'name' => $name, 'amount' => $actPrice, 'num' => 1];
  2566. }
  2567. $totalAmount = bcadd($totalAmount, $actPrice, 2);
  2568. }
  2569. $list = array_values($list);
  2570. }
  2571. if ($export == 1) {
  2572. if (empty($list)) {
  2573. util::fail('没有数据需要导出');
  2574. }
  2575. ini_set('memory_limit', '2045M');
  2576. set_time_limit(0);
  2577. OrderClass::exportAccountList($list, $mainId);
  2578. util::stop();
  2579. }
  2580. util::success(['list' => $list, 'totalAmount' => $totalAmount]);
  2581. }
  2582. //应收款统计 ssh 20240528
  2583. public function actionPastList()
  2584. {
  2585. $get = Yii::$app->request->get();
  2586. $export = $get['export'] ?? 0;
  2587. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2588. $startTime = $get['startTime'] ?? '';
  2589. $endTime = $get['endTime'] ?? '';
  2590. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2591. $end = $period['endTime'];
  2592. $customList = CustomClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name,mobile', 'id');
  2593. $currentDate = date('Y-m-d 00:00:00', bcadd(strtotime($end), 86400));
  2594. $totalAmount = 0;
  2595. if (!empty($customList)) {
  2596. foreach ($customList as $key => $custom) {
  2597. $customId = $custom['id'] ?? 0;
  2598. $change = CustomDebtChangeClass::getByCondition(['customId' => $customId, 'addTime<' => $currentDate], true, 'addTime DESC');
  2599. $amount = $change->balance ?? 0;
  2600. $totalAmount = bcadd($totalAmount, $amount, 2);
  2601. $customList[$key]['currentDebAmount'] = $amount;
  2602. }
  2603. $customList = array_values($customList);
  2604. }
  2605. if ($export == 1) {
  2606. $mainId = $this->mainId;
  2607. if (empty($customList)) {
  2608. util::fail('没有数据需要导出');
  2609. }
  2610. ini_set('memory_limit', '2045M');
  2611. set_time_limit(0);
  2612. OrderClass::exportPastList($customList, $mainId);
  2613. util::stop();
  2614. }
  2615. util::success(['list' => $customList, 'totalAmount' => $totalAmount]);
  2616. }
  2617. //客户业绩,有多个地方,需要同步,搜索关键词 customYj ssh 20240628
  2618. public function actionYj()
  2619. {
  2620. $get = Yii::$app->request->get();
  2621. $mainId = $this->mainId;
  2622. $export = $get['export'] ?? 0;
  2623. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : -1;
  2624. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2625. $startTime = $get['startTime'] ?? '';
  2626. $endTime = $get['endTime'] ?? '';
  2627. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2628. $start = $period['startTime'];
  2629. $end = $period['endTime'];
  2630. $customList = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, '*', 'id');
  2631. $currentStartDate = date('Y-m-d', strtotime($start));
  2632. $currentEndDate = date('Y-m-d', strtotime($end));
  2633. $currentStartTime = $currentStartDate . ' 00:00:00';
  2634. $currentEndTime = $currentEndDate . ' 23:59:59';
  2635. $where = ['mainId' => $mainId];
  2636. if ($debt > -1) {
  2637. $where['debt'] = $debt;
  2638. }
  2639. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  2640. $orderList = OrderClass::getAllByCondition($where, null, '*');
  2641. $list = [];
  2642. $totalActPrice = 0;
  2643. $totalOrderPrice = 0;
  2644. $totalCarton = 0;
  2645. $totalCartonNum = 0;
  2646. $totalPack = 0;
  2647. $totalFreight = 0;
  2648. $totalTkPrice = 0;
  2649. //增加项
  2650. $totalOnlyTkPrice = 0;
  2651. $totalNum = 0;
  2652. if (!empty($orderList)) {
  2653. foreach ($orderList as $orderInfo) {
  2654. $actPrice = $orderInfo['actPrice'] ?? 0;
  2655. $orderPrice = $orderInfo['orderPrice'] ?? 0;
  2656. $customId = $orderInfo['customId'] ?? 0;
  2657. $status = $orderInfo['status'] ?? 0;
  2658. $book = $orderInfo['book'] ?? 0;
  2659. $orderSn = $orderInfo['orderSn'] ?? '';
  2660. $tkPrice = $orderInfo['tkPrice'] ?? 0;
  2661. if ($status == 1 || $status == 5) {
  2662. continue;
  2663. }
  2664. if ($book == 1 && $status == 2) {
  2665. continue;
  2666. }
  2667. $carton = 0;
  2668. $cartonNum = 0;
  2669. $pack = 0;
  2670. $freight = 0;
  2671. $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  2672. if ($actPrice > 0) {
  2673. if (!empty($orderItemList)) {
  2674. foreach ($orderItemList as $orderItem) {
  2675. $num = $orderItem['xhNum'] ?? 0;
  2676. $unitPrice = $orderItem['xhUnitPrice'] ?? 0;
  2677. $refundNum = $orderItem['refundNum'] ?? 0;
  2678. $classId = $orderItem['classId'] ?? 0;
  2679. if (getenv('YII_ENV') == 'production') {
  2680. //小向算打包纸箱费用
  2681. if ($mainId == 23390) {
  2682. $remainNum = bcsub($num, $refundNum);
  2683. $amount = bcmul($remainNum, $unitPrice, 2);
  2684. if ($classId == 72106) {
  2685. $carton = bcadd($carton, $amount, 2);
  2686. $cartonNum = bcadd($cartonNum, $remainNum);
  2687. }
  2688. if ($classId == 72108) {
  2689. $pack = bcadd($pack, $amount, 2);
  2690. }
  2691. if ($classId == 73118) {
  2692. $freight = bcadd($freight, $amount, 2);
  2693. }
  2694. }
  2695. //花大苪
  2696. if ($mainId == 8164) {
  2697. $remainNum = bcsub($num, $refundNum);
  2698. $amount = bcmul($remainNum, $unitPrice, 2);
  2699. if ($classId == 90497) {
  2700. $carton = bcadd($carton, $amount, 2);
  2701. $cartonNum = bcadd($cartonNum, $remainNum);
  2702. }
  2703. if ($classId == 90501) {
  2704. $freight = bcadd($freight, $amount, 2);
  2705. }
  2706. }
  2707. //石头花艺
  2708. if ($mainId == 50) {
  2709. $remainNum = bcsub($num, $refundNum);
  2710. $amount = bcmul($remainNum, $unitPrice, 2);
  2711. if ($classId == 71495) {
  2712. $carton = bcadd($carton, $amount, 2);
  2713. $cartonNum = bcadd($cartonNum, $remainNum);
  2714. }
  2715. if ($classId == 91009) {
  2716. $freight = bcadd($freight, $amount, 2);
  2717. }
  2718. }
  2719. }
  2720. }
  2721. }
  2722. }
  2723. //增加项
  2724. if ($tkPrice > 0) {
  2725. $refundList = RefundOrderClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
  2726. if (!empty($refundList)) {
  2727. foreach ($refundList as $refundInfo) {
  2728. if ($refundInfo->status == 1) {
  2729. if ($refundInfo->refundType == 2) {
  2730. $refundPrice = $refundInfo->refundPrice ?? 0;
  2731. $totalOnlyTkPrice = bcadd($totalOnlyTkPrice, $refundPrice, 2);
  2732. }
  2733. }
  2734. }
  2735. }
  2736. }
  2737. $totalCarton = bcadd($totalCarton, $carton, 2);
  2738. $totalCartonNum = bcadd($totalCartonNum, $cartonNum);
  2739. $totalPack = bcadd($totalPack, $pack, 2);
  2740. $totalFreight = bcadd($totalFreight, $freight, 2);
  2741. $totalTkPrice = bcadd($totalTkPrice, $tkPrice, 2);
  2742. $totalActPrice = bcadd($totalActPrice, $actPrice, 2);
  2743. $totalOrderPrice = bcadd($totalOrderPrice, $orderPrice, 2);
  2744. $totalNum++;
  2745. if (isset($list[$customId])) {
  2746. $list[$customId]['actPrice'] = bcadd($list[$customId]['actPrice'], $actPrice, 2);
  2747. $list[$customId]['orderPrice'] = bcadd($list[$customId]['orderPrice'], $orderPrice, 2);
  2748. $list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
  2749. $list[$customId]['carton'] = bcadd($list[$customId]['carton'], $carton, 2);
  2750. $list[$customId]['cartonNum'] = bcadd($list[$customId]['cartonNum'], $cartonNum);
  2751. $list[$customId]['pack'] = bcadd($list[$customId]['pack'], $pack, 2);
  2752. $list[$customId]['freight'] = bcadd($list[$customId]['freight'], $freight, 2);
  2753. $list[$customId]['tkPrice'] = bcadd($list[$customId]['tkPrice'], $tkPrice, 2);
  2754. } else {
  2755. $name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
  2756. $mobile = $customList[$customId] && $customList[$customId]['mobile'] ? $customList[$customId]['mobile'] : '0';
  2757. $list[$customId] = [
  2758. 'id' => $customId,
  2759. 'name' => $name,
  2760. 'mobile' => $mobile,
  2761. 'orderPrice' => $orderPrice,
  2762. 'actPrice' => $actPrice,
  2763. 'num' => 1,
  2764. 'carton' => $carton,
  2765. 'cartonNum' => $cartonNum,
  2766. 'pack' => $pack,
  2767. 'freight' => $freight,
  2768. 'tkPrice' => $tkPrice,
  2769. ];
  2770. }
  2771. }
  2772. foreach ($customList as $key => $custom) {
  2773. $customId = $custom['id'] ?? 0;
  2774. if (isset($list[$customId]) == false) {
  2775. $list[$customId] = [
  2776. 'id' => $customId,
  2777. 'name' => $custom['name'],
  2778. 'mobile' => $custom['mobile'],
  2779. 'actPrice' => 0,
  2780. 'num' => 0,
  2781. 'carton' => 0,
  2782. 'pack' => 0,
  2783. 'freight' => 0,
  2784. 'tkPrice' => 0,
  2785. 'orderPrice' => 0,
  2786. ];
  2787. }
  2788. }
  2789. $list = array_values($list);
  2790. }
  2791. if ($export == 1) {
  2792. if (empty($list)) {
  2793. util::fail('没有数据需要导出');
  2794. }
  2795. ini_set('memory_limit', '2045M');
  2796. set_time_limit(0);
  2797. OrderClass::exportYj($list, $mainId);
  2798. util::stop();
  2799. }
  2800. util::success([
  2801. 'list' => $list,
  2802. 'totalActPrice' => $totalActPrice,
  2803. 'totalOrderPrice' => $totalOrderPrice,
  2804. 'totalCarton' => $totalCarton,
  2805. 'totalCartonNum' => $totalCartonNum,
  2806. 'totalNum' => $totalNum,
  2807. 'totalPack' => $totalPack,
  2808. 'totalFreight' => $totalFreight,
  2809. 'totalTkPrice' => $totalTkPrice,
  2810. //增加项
  2811. 'totalOnlyTkPrice' => $totalOnlyTkPrice,
  2812. ]);
  2813. }
  2814. //修改配送人 ssh 20240824
  2815. public function actionChangeSendStaff()
  2816. {
  2817. $staff = $this->shopAdmin;
  2818. if (isset($staff->finance) == false || $staff->finance == 0) {
  2819. util::fail('请有财务权限的人修改');
  2820. }
  2821. $get = Yii::$app->request->get();
  2822. $staffId = $get['staffId'] ?? 0;
  2823. $orderId = $get['orderId'] ?? 0;
  2824. $order = OrderClass::getById($orderId, true);
  2825. if (empty($order)) {
  2826. util::fail('没有找到订单');
  2827. }
  2828. if ($order->mainId != $this->mainId) {
  2829. util::fail('不是你的');
  2830. }
  2831. $staff = ShopAdminClass::getById($staffId, true);
  2832. if (empty($staff)) {
  2833. util::fail('没有找到员工');
  2834. }
  2835. if ($staff->mainId != $this->mainId) {
  2836. util::fail('不是你的员工');
  2837. }
  2838. $staffName = $staff->name ?? '';
  2839. $order->sendStaffId = $staffId;
  2840. $order->sendStaffName = $staffName;
  2841. $order->save();
  2842. util::complete('修改成功');
  2843. }
  2844. //导入开单 ssh 20241126
  2845. public function actionImportCreate()
  2846. {
  2847. ini_set('memory_limit', '2045M');
  2848. set_time_limit(0);
  2849. $connection = Yii::$app->db;
  2850. try {
  2851. $get = Yii::$app->request->get();
  2852. $customId = $get['id'] ?? '';
  2853. $customRes = CustomClass::getById($customId, true);
  2854. if (empty($customRes)) {
  2855. util::fail('没有找到客户');
  2856. }
  2857. if ($customRes->ownMainId != $this->mainId) {
  2858. util::fail('不是你的客户');
  2859. }
  2860. if (isset($customRes->mainId) && !empty($customRes->mainId) && $customRes->mainId == $customRes->ownMainId) {
  2861. util::fail('不能给自己开单');
  2862. }
  2863. $file = $_FILES['file'];
  2864. if (!is_uploaded_file($file['tmp_name'])) {
  2865. util::fail('please upload img');
  2866. }
  2867. $mainId = $this->mainId;
  2868. $sjId = $this->sjId;
  2869. $shopId = $this->shopId;
  2870. $month = date("Ym");
  2871. $date = date("d");
  2872. $path = dirUtil::getImgUploadDir() . "/{$mainId}/kd/{$shopId}/{$month}/{$date}/";
  2873. if (!file_exists($path)) {
  2874. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  2875. mkdir($path, 0700, true);
  2876. }
  2877. $preFileName = stringUtil::uniqueFileName();
  2878. $newFile = $preFileName . ".xls";
  2879. $fullPathFile = $path . $newFile;
  2880. if (move_uploaded_file($file['tmp_name'], $fullPathFile)) {
  2881. $arr = [];
  2882. $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/");
  2883. require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');
  2884. $spreadsheet = \PHPExcel_IOFactory::load($fullPathFile);
  2885. // 获取活动工作表
  2886. $worksheet = $spreadsheet->getActiveSheet();
  2887. // 遍历每一行
  2888. foreach ($worksheet->getRowIterator() as $key => $row) {
  2889. $cellIterator = $row->getCellIterator();
  2890. // 这里设置为迭代所有单元格,包括空单元格
  2891. $cellIterator->setIterateOnlyExistingCells(FALSE);
  2892. // 遍历每列
  2893. $rowData = [];
  2894. foreach ($cellIterator as $cell) {
  2895. $option = $cell->getValue();
  2896. $rowData[] = trim($option);
  2897. }
  2898. $arr[] = $rowData;
  2899. }
  2900. array_shift($arr);
  2901. $productIds = [];
  2902. foreach ($arr as $k => $v) {
  2903. $productId = $v[0] ?? 0;
  2904. $productId = trim($productId);
  2905. if (is_numeric($productId) && $productId > 0) {
  2906. $productIds[] = $productId;
  2907. }
  2908. }
  2909. if (empty($productIds)) {
  2910. util::fail('没有识别出花材');
  2911. }
  2912. $productInfo = ProductClass::getByIds($productIds, null, 'id');
  2913. if (empty($productInfo)) {
  2914. util::fail('没有找到有效花材');
  2915. }
  2916. $mat = [];
  2917. foreach ($arr as $k => $v) {
  2918. $productId = $v[0] ?? 0;
  2919. $productId = trim($productId);
  2920. $num = $v[2] ?? 0;
  2921. $num = trim($num);
  2922. $unitPrice = $v[3] ?? 0;
  2923. $unitPrice = trim($unitPrice);
  2924. $remark = $v['5'] ?? '';
  2925. $remark = trim($remark);
  2926. if (is_numeric($productId) && $productId > 0 && $num > 0 && $unitPrice > 0) {
  2927. $product = $productInfo[$productId] ?? [];
  2928. $ptItemId = $product['itemId'] ?? 0;
  2929. $mat[] = [
  2930. 'productId' => $productId,
  2931. 'bigNum' => $num,
  2932. 'itemId' => $ptItemId,
  2933. 'smallNum' => 0,
  2934. 'price' => $unitPrice,
  2935. 'remark' => $remark,
  2936. ];
  2937. }
  2938. }
  2939. $modifyPrice = 0;
  2940. foreach ($mat as $ma) {
  2941. $cNum = $ma['bigNum'] ?? 0;
  2942. $cPrice = $ma['price'] ?? 0;
  2943. $cTotal = bcmul($cNum, $cPrice, 2);
  2944. $modifyPrice = bcadd($modifyPrice, $cTotal, 2);
  2945. }
  2946. $customName = $customRes->name ?? '';
  2947. $customMobile = $customRes->mobile ?? '';
  2948. $customPy = $customRes->py ?? '';
  2949. $ghsId = $customRes->ghsId ?? 0;
  2950. $hasPay = 2;
  2951. $custom = CustomClass::getCustom($customId);
  2952. $post = [];
  2953. $post['modifyPrice'] = $modifyPrice;
  2954. $post['shopId'] = $shopId;
  2955. $post['sendType'] = 0;
  2956. $post['transType'] = 0;
  2957. $post['sendSide'] = 0;
  2958. $post['sendCost'] = 0;
  2959. $post['packCost'] = 0;
  2960. $post['customId'] = $customId;
  2961. $post['customName'] = $customName;
  2962. $post['payWay'] = 0;
  2963. $post['needPrint'] = 2;
  2964. $post['hasPay'] = 2;
  2965. $post['product'] = $mat;
  2966. $post['deadline'] = date("Y-m-d H:i:s", time() + 86400);
  2967. $post['debt'] = 1;
  2968. $post['mainId'] = $mainId;
  2969. $post['fromType'] = 1;
  2970. $post['expressId'] = 0;
  2971. $post['sjId'] = $sjId;
  2972. $staff = $this->shopAdmin;
  2973. $staffId = $staff->id ?? 0;
  2974. $staffName = $staff->name ?? '';
  2975. $post['shopAdminId'] = $staffId;
  2976. $post['shopAdminName'] = $staffName;
  2977. $post['getStaffId'] = $staffId;
  2978. $post['getStaffName'] = $staffName;
  2979. $post['customMobile'] = $customMobile;
  2980. $post['customNamePy'] = $customPy;
  2981. $post['customAvatar'] = '';
  2982. $post['newVersion'] = 1;
  2983. $post['book'] = 1;
  2984. $post['wlName'] = '';
  2985. $post['dealPrice'] = 1;
  2986. $post['ghsId'] = $ghsId;
  2987. $shop = $this->shop;
  2988. $bookSn = $shop->bookSn ?? 0;
  2989. $post['bookSn'] = $bookSn;
  2990. //多处有用到此方法,需要同步修改,搜索关键词create_new_order
  2991. util::runWithDbConcurrencyRetry(function () use ($connection, $post, $custom, $hasPay) {
  2992. $transaction = $connection->beginTransaction();
  2993. try {
  2994. OrderService::createNewOrder($post, $custom, $hasPay);
  2995. $transaction->commit();
  2996. } catch (\Exception $exception) {
  2997. if ($transaction->isActive) {
  2998. $transaction->rollBack();
  2999. }
  3000. throw $exception;
  3001. }
  3002. });
  3003. util::complete('提交成功');
  3004. } else {
  3005. util::fail('上传失败了,出错了哦');
  3006. }
  3007. } catch (\Exception $e) {
  3008. Yii::info("导入失败了," . $e->getMessage());
  3009. noticeUtil::push('导入失败,失败原因:' . $e->getMessage(), '15280215347');
  3010. $msg = $e->getMessage();
  3011. util::fail('导入失败:' . $msg);
  3012. }
  3013. }
  3014. //打印发物流用和标签 ssh 20250312
  3015. public function actionPrintWlLabel()
  3016. {
  3017. $get = Yii::$app->request->get();
  3018. $id = $get['id'] ?? 0;
  3019. $order = OrderClass::getById($id, true);
  3020. if (empty($order)) {
  3021. util::fail('没有找到订单');
  3022. }
  3023. if ($order->payStatus == 0) {
  3024. util::fail('订单没有付款');
  3025. }
  3026. $ext = $this->shopExt;
  3027. $shop = $this->shop;
  3028. OrderClass::printLogisticsLabel($order, $shop, $ext);
  3029. util::complete('打印成功');
  3030. }
  3031. //修改地址 ssh 20251123
  3032. public function actionModifyAddress()
  3033. {
  3034. $post = Yii::$app->request->post();
  3035. $id = $post['id'] ?? 0;
  3036. $order = OrderClass::getById($id, true);
  3037. if (empty($order)) {
  3038. util::fail('没有找到订单');
  3039. }
  3040. if ($order->mainId != $this->mainId) {
  3041. util::fail('不是你的订单,不能修改地址');
  3042. }
  3043. if ($order->status == 3) {
  3044. util::fail('订单已经在配送了,不能修改地址');
  3045. }
  3046. if ($order->status == 4) {
  3047. util::fail('订单已完成,不能修改地址');
  3048. }
  3049. $province = $post['province'] ?? '';
  3050. $city = $post['city'] ?? '';
  3051. $dist = $post['dist'] ?? '';
  3052. $address = $post['address'] ?? '';
  3053. $floor = $post['floor'] ?? '';
  3054. $fullAddress = $city . $dist . $address . $floor;
  3055. $lat = $post['lat'] ?? '';
  3056. $long = $post['long'] ?? '';
  3057. $showAddress = $post['showAddress'] ?? '';
  3058. $order->province = $province;
  3059. $order->city = $city;
  3060. $order->dist = $dist;
  3061. $order->address = $address;
  3062. $order->floor = $floor;
  3063. $order->showAddress = $showAddress;
  3064. $order->fullAddress = $fullAddress;
  3065. $order->lat = $lat;
  3066. $order->long = $long;
  3067. $order->save();
  3068. $syncDefaultAddress = $post['syncDefaultAddress'] ?? 0;
  3069. if ($syncDefaultAddress == 1) {
  3070. $customId = $order->customId ?? 0;
  3071. $custom = CustomClass::getById($customId, true);
  3072. if (!empty($custom)) {
  3073. $custom->province = $province;
  3074. $custom->city = $city;
  3075. $custom->dist = $dist;
  3076. $custom->address = $address;
  3077. $custom->floor = $floor;
  3078. $custom->showAddress = $showAddress;
  3079. $custom->fullAddress = $fullAddress;
  3080. $custom->lat = $lat;
  3081. $custom->long = $long;
  3082. $custom->save();
  3083. }
  3084. }
  3085. util::complete('修改成功');
  3086. }
  3087. }