OrderController.php 112 KB

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