OrderController.php 126 KB

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