OrderController.php 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\hb\classes\HbClass;
  4. use Yii;
  5. use biz\shop\classes\ShopExtClass;
  6. use biz\sj\services\MerchantExtendService;
  7. use biz\sj\services\MerchantService;
  8. use bizHd\custom\classes\CustomClass;
  9. use bizHd\custom\classes\HdClass;
  10. use bizHd\goods\classes\GoodsClass;
  11. use bizHd\merchant\services\ShopService;
  12. use bizHd\order\classes\OrderClass;
  13. use bizHd\order\classes\OrderForwardClass;
  14. use bizHd\order\classes\OrderItemClass;
  15. use bizHd\order\classes\OrderSendClass;
  16. use hd\models\order\CreateOrderForm;
  17. use bizHd\express\classes\HdDeliveryOrderClass;
  18. use bizHd\order\services\OrderService;
  19. use bizHd\product\classes\ProductClass;
  20. use bizHd\saas\services\RegionService;
  21. use bizHd\shop\classes\ShopClass;
  22. use bizHd\user\services\UserService;
  23. use bizHd\work\classes\WorkClass;
  24. use common\components\dict;
  25. use common\components\dateUtil;
  26. use common\components\noticeUtil;
  27. use common\components\orderSn;
  28. use common\components\payUtil;
  29. use common\services\xhPayToolService;
  30. use common\components\util;
  31. use common\components\stringUtil;
  32. use bizHd\promote\services\CouponService;
  33. use common\components\httpUtil;
  34. use biz\wx\classes\WxMessageClass;
  35. use common\components\lakala\Lakala;
  36. use yii\helpers\ArrayHelper;
  37. class OrderController extends BaseController
  38. {
  39. public $guestAccess = ['order-relate', 'fast-pay', 'create-order', 'list', 'info'];
  40. public function actionDebt()
  41. {
  42. $get = Yii::$app->request->get();
  43. $id = $get['id'] ?? 0;
  44. $info = OrderClass::getById($id, true);
  45. if (empty($info)) {
  46. util::fail('没有找到订单');
  47. }
  48. if ($info->mainId != $this->mainId) {
  49. util::fail('不是你的订单');
  50. }
  51. //4秒内不允许重复提交
  52. util::checkRepeatCommit($id, 4);
  53. if ($info->status != 1) {
  54. util::fail('订单已付款或取消');
  55. }
  56. $payWay = dict::getDict('payWay', 'debtPay');
  57. $connection = Yii::$app->db;
  58. $transaction = $connection->beginTransaction();
  59. try {
  60. $actPrice = $info->actPrice ?? 0;
  61. $info->debtPrice = $actPrice;
  62. $info->remainDebtPrice = $actPrice;
  63. $info->debt = 1;
  64. $info->save();
  65. OrderClass::payAfter($info, $payWay);
  66. //到店自取订单,并且是待取货状态,则自动完成取货,多处要同步修改,关键词 reach_shop_fetch_goods
  67. if ($info->getGoods == 1 && $info->sendType == 1 && $info->status == 2) {
  68. $info->status = 4;
  69. $info->save();
  70. }
  71. $transaction->commit();
  72. //付款成功了,通知发跑腿功能,关键词 hd_pay_after_call_pt,多处要同步修改
  73. HdDeliveryOrderClass::payAfter($info);
  74. util::complete('赊账成功');
  75. } catch (\Exception $exception) {
  76. $transaction->rollBack();
  77. Yii::info("赊账失败原因:" . $exception->getMessage());
  78. util::fail('操作失败');
  79. }
  80. }
  81. //取消订单 ssh 20221231
  82. public function actionCancel()
  83. {
  84. //避免重复提交
  85. $adminId = $this->adminId;
  86. util::checkRepeatCommit($adminId, 8);
  87. $get = Yii::$app->request->get();
  88. $id = $get['id'] ?? 0;
  89. $order = OrderClass::getById($id, true);
  90. if ($order->mainId != $this->mainId) {
  91. util::fail('不是你的订单');
  92. }
  93. $staff = $this->shopAdmin;
  94. $connection = Yii::$app->db;
  95. $transaction = $connection->beginTransaction();
  96. try {
  97. OrderClass::setExpire($order, true, $staff);
  98. $transaction->commit();
  99. util::complete();
  100. } catch (\Exception $exception) {
  101. $transaction->rollBack();
  102. Yii::info("取消原因:" . $exception->getMessage());
  103. util::fail('取消失败');
  104. }
  105. }
  106. //修改订单 ssh 20220926
  107. public function actionUpdate()
  108. {
  109. $post = Yii::$app->request->post();
  110. $id = $post['id'] ?? 0;
  111. $order = OrderClass::getById($id, true);
  112. OrderClass::valid($order, $this->mainId);
  113. unset($post['id']);
  114. if ($order->status == 3) {
  115. util::fail('订单已配送');
  116. }
  117. if ($order->status == 4) {
  118. util::fail('订单已完成');
  119. }
  120. if ($order->status == 5) {
  121. util::fail('订单已取消');
  122. }
  123. if ($order->fromType == 4) {
  124. util::fail('请在美团APP上修改');
  125. }
  126. $address = $post['address'] ?? '';
  127. $floor = $post['floor'] ?? '';
  128. $post['fullAddress'] = $address . $floor;
  129. OrderClass::updateById($id, $post);
  130. $workList = WorkClass::getAllByCondition(['orderId' => $id], null, '*', null, true);
  131. $remark = $post['remark'] ?? '';
  132. $reachDate = $post['reachDate'] ?? '';
  133. $reachPeriod = $post['reachPeriod'] ?? '';
  134. $cardInfo = $post['cardInfo'] ?? '';
  135. $anonymity = $post['anonymity'] ?? 0;
  136. $bookName = $post['bookName'] ?? '';
  137. if (!empty($workList)) {
  138. foreach ($workList as $work) {
  139. $work->remark = $remark;
  140. $work->reachDate = $reachDate;
  141. $work->reachPeriod = $reachPeriod;
  142. $work->cardInfo = $cardInfo;
  143. $work->anonymity = $anonymity;
  144. $work->bookName = $bookName;
  145. $work->save();
  146. }
  147. }
  148. $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shopId], true);
  149. ShopExtClass::orderUpdateRemind($shopExt, $order);
  150. util::complete();
  151. }
  152. //客户欠款的订单 ssh 2021.2.4
  153. public function actionDebtList()
  154. {
  155. $get = Yii::$app->request->get();
  156. $id = $get['id'] ?? 0;
  157. $info = CustomClass::getById($id, true);
  158. CustomClass::valid($info, $this->shopId);
  159. $where = ['customId' => $id, 'debt' => 1];
  160. $searchTime = $get['searchTime'] ?? '';
  161. if (!empty($searchTime)) {
  162. $startTime = $get['startTime'] ?? '';
  163. $endTime = $get['endTime'] ?? '';
  164. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  165. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  166. }
  167. $allowedPageSizes = [100, 200, 300];
  168. $pageSize = isset($get['pageSize']) && in_array((int)$get['pageSize'], $allowedPageSizes, true)
  169. ? (int)$get['pageSize'] : 100;
  170. $page = max(1, (int)($get['page'] ?? 1));
  171. $fields = ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice', 'debtPrice'];
  172. Yii::$app->request->setQueryParams(array_merge($get, ['page' => $page, 'pageSize' => $pageSize]));
  173. $result = OrderClass::getList($fields, $where, 'addTime DESC');
  174. if (!empty($result['list'])) {
  175. foreach ($result['list'] as $key => $value) {
  176. $debtPrice = $value['debtPrice'] ?? 0;
  177. $remainDebtPrice = $value['remainDebtPrice'] ?? 0;
  178. $hasPayDebt = 0;
  179. if ($debtPrice > $remainDebtPrice) {
  180. $hasPayDebt = bcsub($debtPrice, $remainDebtPrice, 2);
  181. }
  182. $result['list'][$key]['hasPayDebt'] = floatval($hasPayDebt);
  183. }
  184. }
  185. $result['customInfo'] = $info;
  186. util::success($result);
  187. }
  188. //确认送达 ssh 20250902
  189. public function actionReach()
  190. {
  191. //解决重复提交
  192. util::checkRepeatCommit($this->adminId, 5);
  193. $get = Yii::$app->request->get();
  194. $id = $get['id'] ?? 0;
  195. $order = OrderClass::getById($id, true);
  196. if (empty($order)) {
  197. util::fail('没有找到订单');
  198. }
  199. OrderClass::valid($order, $this->mainId);
  200. if ($order->status == 5) {
  201. util::fail('订单已取消');
  202. }
  203. if ($order->status == 1) {
  204. util::fail('订单待付款');
  205. }
  206. if ($order->status == 2) {
  207. util::fail('订单未发货');
  208. }
  209. if ($order->status == 4) {
  210. util::fail('订单已经送到了');
  211. }
  212. if (!in_array($order->sendStatus, [-1, -4])) {
  213. util::fail('由跑腿送货,无需确认');
  214. }
  215. $order->status = 4;
  216. $order->save();
  217. util::complete('操作成功');
  218. }
  219. //确认取货
  220. public function actionFetch()
  221. {
  222. $get = Yii::$app->request->get();
  223. $id = $get['id'] ?? 0;
  224. //解决重复提交
  225. util::checkRepeatCommit($id . '_' . $this->adminId, 5);
  226. $order = OrderClass::getById($id, true);
  227. if (empty($order)) {
  228. util::fail('没有找到订单');
  229. }
  230. OrderClass::valid($order, $this->mainId);
  231. if ($order->status == 5) {
  232. util::fail('订单已取消');
  233. }
  234. if ($order->status == 1) {
  235. util::fail('订单待付款');
  236. }
  237. if ($order->status == 4) {
  238. util::fail('订单已取过了');
  239. }
  240. if (in_array($order->sendStatus, [-1, 0, 1, 2, 4, 5])) {
  241. util::fail('由跑腿送货,无需确认');
  242. }
  243. $order->status = 4;
  244. $order->save();
  245. util::complete('操作成功');
  246. }
  247. //批量确认取货 待发货的自取订单 每次500个
  248. public function actionBatchFetch()
  249. {
  250. $where = ["status" => 2, "sendType" => 1, "shopId" => $this->shopId];
  251. $orderList = OrderService::getLimitList("id", $where, 500, "id desc");
  252. $ids = ArrayHelper::getColumn($orderList, "id");
  253. OrderService::updateByIds($ids, ["status" => 4]);
  254. util::complete($ids);
  255. }
  256. //确认发货
  257. public function actionSend()
  258. {
  259. //解决重复提交
  260. util::checkRepeatCommit($this->adminId, 5);
  261. $get = Yii::$app->request->get();
  262. $id = $get['id'] ?? 0;
  263. $order = OrderClass::getById($id, true);
  264. if (empty($order)) {
  265. util::fail('没有找到订单');
  266. }
  267. OrderClass::valid($order, $this->mainId);
  268. if ($order->status != 2) {
  269. util::fail('订单不是待发货状态');
  270. }
  271. // $workList = WorkClass::getAllByCondition(['orderId' => $id], null, '*', null, true);
  272. // if (!empty($workList)) {
  273. // $unComplete = false;
  274. // foreach ($workList as $work) {
  275. // if ($work->status != 1) {
  276. // $unComplete = true;
  277. // }
  278. // }
  279. // if ($unComplete == true) {
  280. // util::fail('还有制作单没有完成');
  281. // }
  282. // }
  283. $order->status = 3;
  284. $order->save();
  285. util::complete('已发货');
  286. }
  287. //打印订单 ssh 20220601
  288. public function actionPrintOrder()
  289. {
  290. $get = Yii::$app->request->get();
  291. $id = isset($get['id']) ? $get['id'] : 0;
  292. $order = OrderClass::getById($id, true);
  293. if (empty($order)) {
  294. util::fail('没有找到订单');
  295. }
  296. if ($order->forward == 1) {
  297. util::fail('红冲订单不能打印');
  298. }
  299. OrderClass::valid($order, $this->mainId);
  300. OrderClass::onlinePrint($order, true);
  301. util::complete();
  302. }
  303. //微信和支付宝付款码支付复查 ssh 20220422
  304. public function actionCodePayCheck()
  305. {
  306. ini_set('date.timezone', 'Asia/Shanghai');
  307. header("Content-type: text/html; charset=utf-8");
  308. $get = Yii::$app->request->get();
  309. $id = isset($get['id']) ? $get['id'] : 0;
  310. util::checkRepeatCommit($id, 3);
  311. $order = OrderClass::getById($id, true);
  312. OrderClass::valid($order, $this->mainId);
  313. $orderSn = $order->orderSn ?? '';
  314. $totalFee = $order->mainPay ?? 0;
  315. if ($order->payStatus == 1) {
  316. util::success(['returnStatus' => 'SUCCESS']);
  317. }
  318. if ($order->status == OrderClass::ORDER_STATUS_COMPLETE) {
  319. util::success(['returnStatus' => 'SUCCESS']);
  320. }
  321. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  322. util::complete('订单已取消');
  323. }
  324. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
  325. util::complete('订单不是待付款状态');
  326. }
  327. $connection = Yii::$app->db;
  328. $transaction = $connection->beginTransaction();
  329. try {
  330. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  331. $shop = $this->shop;
  332. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  333. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  334. $params = [
  335. 'appid' => 'OP00002119',
  336. 'serial_no' => '018b08cfddbd',
  337. 'merchant_no' => $shop->lklSjNo,
  338. 'term_no' => $shop->lklScanTermNo,
  339. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  340. 'lklCertificatePath' => $lklCertificatePath,
  341. ];
  342. $laResource = new Lakala($params);
  343. $scanParams = ['orderSn' => $orderSn,];
  344. $response = $laResource->query($scanParams);
  345. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  346. if (isset($response['resp_data']['trade_state']) && $response['resp_data']['trade_state'] == 'SUCCESS') {
  347. $payWayType = dict::getDict('payWay', 'wxPay');
  348. $account_type = $response['resp_data']['account_type'] ?? '';
  349. if ($account_type == 'WECHAT') {
  350. $payWayType = dict::getDict('payWay', 'wxPay');
  351. }
  352. if ($account_type == 'ALIPAY') {
  353. $payWayType = dict::getDict('payWay', 'alipay');
  354. }
  355. $transactionId = $response['resp_data']['trade_no'] ?? '';
  356. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  357. $order->save();
  358. $attach = '';
  359. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  360. $transaction->commit();
  361. //解决重复通知
  362. $cacheKey = 'hd_shop_order_pay_check_' . $orderSn;
  363. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  364. if (empty($has)) {
  365. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
  366. //打印小票和语音播报
  367. $newOrder = OrderClass::getById($id, true);
  368. OrderClass::onlinePrint($newOrder);
  369. ShopExtClass::hdGatheringReport($newOrder);
  370. //到店自取订单,并且是待取货状态,则自动完成取货,多处要同步修改,关键词 reach_shop_fetch_goods
  371. if ($newOrder->getGoods == 1 && $newOrder->sendType == 1 && $newOrder->status == 2) {
  372. $newOrder->status = 4;
  373. $newOrder->save();
  374. }
  375. HdDeliveryOrderClass::payAfter($newOrder);
  376. $shopId = $newOrder->shopId ?? 0;
  377. $shop = ShopClass::getById($shopId, true);
  378. WxMessageClass::gatheringIncomeInform($shop, $newOrder);
  379. }
  380. util::success(['returnStatus' => 'SUCCESS']);
  381. } else {
  382. util::complete('未知状态..');
  383. }
  384. }
  385. util::complete('未知状态..');
  386. } catch (\Exception $e) {
  387. $transaction->rollBack();
  388. util::complete('支付失败');
  389. }
  390. }
  391. //微信和支付宝付款码支付复查 ssh 20260716
  392. public function actionCodePayVerify()
  393. {
  394. ini_set('date.timezone', 'Asia/Shanghai');
  395. header("Content-type: text/html; charset=utf-8");
  396. $get = Yii::$app->request->get();
  397. $id = $get['id'] ?? 0;
  398. util::checkRepeatCommit($id, 3);
  399. $order = OrderClass::getById($id, true);
  400. OrderClass::valid($order, $this->mainId);
  401. $orderSn = $order->orderSn ?? '';
  402. $totalFee = $order->mainPay ?? 0;
  403. if ($order->payStatus == 1) {
  404. util::success(['returnStatus' => 'SUCCESS']);
  405. }
  406. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  407. util::complete('订单已取消');
  408. }
  409. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
  410. util::complete('订单不是待付款状态');
  411. }
  412. $connection = Yii::$app->db;
  413. $transaction = $connection->beginTransaction();
  414. try {
  415. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  416. $shop = $this->shop;
  417. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  418. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  419. $params = [
  420. 'appid' => 'OP00002119',
  421. 'serial_no' => '018b08cfddbd',
  422. 'merchant_no' => $shop->lklSjNo,
  423. 'term_no' => $shop->lklScanTermNo,
  424. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  425. 'lklCertificatePath' => $lklCertificatePath,
  426. ];
  427. $laResource = new Lakala($params);
  428. $scanParams = ['orderSn' => $orderSn,];
  429. $response = $laResource->query($scanParams);
  430. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  431. if (isset($response['resp_data']['trade_state']) && $response['resp_data']['trade_state'] == 'SUCCESS') {
  432. $payWayType = dict::getDict('payWay', 'wxPay');
  433. $account_type = $response['resp_data']['account_type'] ?? '';
  434. if ($account_type == 'WECHAT') {
  435. $payWayType = dict::getDict('payWay', 'wxPay');
  436. }
  437. if ($account_type == 'ALIPAY') {
  438. $payWayType = dict::getDict('payWay', 'alipay');
  439. }
  440. $transactionId = $response['resp_data']['trade_no'] ?? '';
  441. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  442. $order->save();
  443. $attach = '';
  444. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  445. $transaction->commit();
  446. //解决重复通知
  447. $cacheKey = 'hd_shop_order_pay_check_' . $orderSn;
  448. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  449. if (empty($has)) {
  450. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
  451. //打印小票和语音播报
  452. $newOrder = OrderClass::getById($id, true);
  453. OrderClass::onlinePrint($newOrder);
  454. ShopExtClass::hdGatheringReport($newOrder);
  455. //到店自取订单,并且是待取货状态,则自动完成取货,多处要同步修改,关键词 reach_shop_fetch_goods
  456. if ($newOrder->getGoods == 1 && $newOrder->sendType == 1 && $newOrder->status == 2) {
  457. $newOrder->status = 4;
  458. $newOrder->save();
  459. }
  460. HdDeliveryOrderClass::payAfter($newOrder);
  461. $shopId = $newOrder->shopId ?? 0;
  462. $shop = ShopClass::getById($shopId, true);
  463. WxMessageClass::gatheringIncomeInform($shop, $newOrder);
  464. }
  465. util::success(['returnStatus' => 'SUCCESS']);
  466. } else {
  467. util::success(['returnStatus' => 'PENDING'], '等待支付中...');
  468. }
  469. }
  470. util::success(['returnStatus' => 'PENDING'], '等待支付中...');
  471. } catch (\Exception $e) {
  472. $transaction->rollBack();
  473. util::complete('支付失败');
  474. }
  475. }
  476. /**
  477. * 微信和支付宝付款码支付
  478. * 职责:处理商户扫描客户付款码(被扫支付)的请求,调用拉卡拉支付接口并更新本地订单状态(零售端)
  479. * 入参:GET 传参 id (订单ID), authCode (付款码), version (版本号)
  480. * 返回:JSON 格式的支付结果(SUCCESS/FAILURE)
  481. * 副作用:更新订单支付状态、支付方式,记录支付日志,触发云打印、跑腿呼叫及语音播报
  482. * 关键边界:
  483. * 1. 验证订单有效性与待付款状态
  484. * 2. 校验付款码格式(微信/支付宝)
  485. * 3. 优化:将拉卡拉外部网络请求移出数据库事务,避免因网络延迟长时间占用数据库连接和行锁
  486. */
  487. public function actionCodePay()
  488. {
  489. ini_set('date.timezone', 'Asia/Shanghai');
  490. header("Content-type: text/html; charset=utf-8");
  491. $get = Yii::$app->request->get();
  492. $id = isset($get['id']) ? $get['id'] : 0;
  493. util::checkRepeatCommit($id, 3);
  494. $version = $get['version'] ?? 0;
  495. $order = OrderClass::getById($id, true);
  496. OrderClass::valid($order, $this->mainId);
  497. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  498. $msg = '订单已取消';
  499. util::success(['returnStatus' => 'FAILURE'], $msg);
  500. }
  501. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
  502. $msg = '订单不是待付款状态';
  503. util::success(['returnStatus' => 'FAILURE'], $msg);
  504. }
  505. $shop = $this->shop;
  506. $sj = $shop->merchantName;
  507. $shopName = $shop->shopName;
  508. $name = $shopName == '首店' ? $sj : $sj . '-' . $shopName;
  509. $authCode = (string)$get['authCode'] ?? '';
  510. if ($version > 0) {
  511. if (empty($authCode)) {
  512. $msg = '没有扫到付款码';
  513. $remind = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
  514. noticeUtil::push($remind . ' 编号005', '15280215347');
  515. util::success(['returnStatus' => 'FAILURE'], $msg);
  516. }
  517. //微信文档说明 https://pay.weixin.qq.com/doc/v2/merchant/4011936234
  518. $wxPattern = '/^(10|11|12|13|14|15)\d{16}$/';
  519. //支付宝文档说明 https://opendocs.alipay.com/open/194/106039/
  520. $aliPattern = '/^(25|26|27|28|29|30)\d{14,22}$/';
  521. if (!preg_match($wxPattern, $authCode) && !preg_match($aliPattern, $authCode)) {
  522. $msg = '付款码错误,请使用微信或支付宝付款码';
  523. $remind = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
  524. //noticeUtil::push($remind . ' 编号009', '15280215347');
  525. util::success(['returnStatus' => 'FAILURE'], $msg);
  526. }
  527. } else {
  528. if (empty($authCode)) {
  529. util::fail('没有获取到支付码');
  530. }
  531. }
  532. $orderSn = $order->orderSn ?? '';
  533. $lsCodePayErrorKey = 'ls_code_pay_error_' . $id;
  534. $hasFailPay = Yii::$app->redis->executeCommand('GET', [$lsCodePayErrorKey]);
  535. //前面有付失败过,要重新生成单号
  536. if (!empty($hasFailPay)) {
  537. $oldOrderSn = $order->orderSn;
  538. $orderSn = orderSn::getOrderSn();
  539. $order->orderSn = $orderSn;
  540. $order->save();
  541. OrderItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $orderSn]);
  542. }
  543. $subject = '购买花材 ' . $orderSn;
  544. $totalFee = $order->mainPay ?? 0;
  545. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  546. try {
  547. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  548. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  549. $params = [
  550. 'appid' => 'OP00002119',
  551. 'serial_no' => '018b08cfddbd',
  552. 'merchant_no' => $shop->lklSjNo,
  553. 'term_no' => $shop->lklScanTermNo,
  554. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  555. 'lklCertificatePath' => $lklCertificatePath,
  556. ];
  557. $laResource = new Lakala($params);
  558. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  559. $scanParams = [
  560. 'orderSn' => $orderSn,
  561. 'amount' => $totalFee,
  562. 'capitalType' => $capitalType,
  563. 'notifyUrl' => $notifyUrl,
  564. 'subject' => $subject,
  565. 'authCode' => $authCode,
  566. ];
  567. // 复杂分支/关键逻辑:在调用外部支付接口前不开启事务,防止网络延迟卡死数据库连接
  568. $response = $laResource->scanPay($scanParams);
  569. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  570. // 复杂分支/关键逻辑:支付成功后,开启数据库事务,确保本地订单状态更新的原子性
  571. $connection = Yii::$app->db;
  572. $transaction = $connection->beginTransaction();
  573. try {
  574. $account_type = $response['resp_data']['account_type'] ?? '';
  575. $payWayType = dict::getDict('payWay', 'wxPay');
  576. if ($account_type == 'WECHAT') {
  577. $payWayType = dict::getDict('payWay', 'wxPay');
  578. }
  579. if ($account_type == 'ALIPAY') {
  580. $payWayType = dict::getDict('payWay', 'alipay');
  581. }
  582. $order->payWay = $payWayType;
  583. $transactionId = $response['resp_data']['trade_no'] ?? '';
  584. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  585. $order->save();
  586. $attach = '';
  587. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  588. $transaction->commit();
  589. } catch (\Exception $e) {
  590. $transaction->rollBack();
  591. throw $e;
  592. }
  593. //解决重复通知
  594. $cacheKey = 'hd_shop_order_pay_' . $orderSn;
  595. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  596. if (empty($has)) {
  597. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
  598. $newOrder = OrderClass::getById($id, true);
  599. //到店自取订单,并且是待取货状态,则自动完成取货,多处要同步修改,关键词 reach_shop_fetch_goods
  600. if ($newOrder->getGoods == 1 && $newOrder->sendType == 1 && $newOrder->status == 2) {
  601. $newOrder->status = 4;
  602. $newOrder->save();
  603. }
  604. //打印小票
  605. OrderClass::onlinePrint($newOrder);
  606. HdDeliveryOrderClass::payAfter($newOrder);
  607. //语音播报
  608. ShopExtClass::hdGatheringReport($newOrder);
  609. $shopId = $newOrder->shopId ?? 0;
  610. $shop = ShopClass::getById($shopId, true);
  611. WxMessageClass::gatheringIncomeInform($shop, $newOrder);
  612. }
  613. util::success(['returnStatus' => 'SUCCESS']);
  614. } else {
  615. //标记有没付成功的次数,原因有可能是余额不足等
  616. Yii::$app->redis->executeCommand('SETEX', [$lsCodePayErrorKey, 1200, 'hasFail']);
  617. $msg = $response['msg'] ?? '';
  618. $retCode = $response['code'] ?? '';
  619. $fullMsg = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
  620. if ($retCode == 'BBS10000' || $retCode == 'BBS11105') {
  621. $shopId = $order->shopId;
  622. ShopExtClass::remindInputPassword($shopId);
  623. }
  624. //noticeUtil::push($fullMsg . ' ' . $retCode . ' 编号008', '15280215347');
  625. util::success(['returnStatus' => 'FAILURE', 'returnCode' => $retCode], $msg);
  626. }
  627. } catch (\Exception $e) {
  628. Yii::error("零售端支付失败原因:" . $e->getMessage());
  629. util::fail('支付失败');
  630. }
  631. }
  632. //开单操作 ssh 20220316
  633. public function actionCreateOrder()
  634. {
  635. $post = Yii::$app->request->post();
  636. $post['sjId'] = $this->sjId;
  637. $post['shopId'] = $this->shopId;
  638. $post['mainId'] = $this->mainId ?? 0;
  639. $shop = $this->shop;
  640. if ($shop->memberLevelSet == 0) {
  641. //util::fail('请先设置会员等级');
  642. }
  643. $now = time();
  644. $orderValidTime = 600;
  645. $expireTime = $now + $orderValidTime;
  646. $post['deadline'] = $expireTime;
  647. $post['staffId'] = $this->shopAdminId ?? 0;
  648. $post['staffName'] = $this->shopAdmin->name ?? '';
  649. $post['flowerNum'] = isset($post['flowerNum']) && $post['flowerNum'] > 0 ? $post['flowerNum'] : 0;
  650. $version = $post['version'] ?? 0; //验证已移至 CreateOrderForm
  651. if ($version < 3) {
  652. util::fail('请升级版本,或用小程序');
  653. }
  654. //默认情况开单员工和收款员工是同个人
  655. $staffId = $this->shopAdminId ?? 0;
  656. $staffName = $this->shopAdmin->name ?? '';
  657. if (empty($post['shopAdminId'])) {
  658. $post['shopAdminId'] = $staffId;
  659. $post['shopAdminName'] = $staffName;
  660. }
  661. if (empty($post['getStaffId'])) {
  662. $post['getStaffId'] = $staffId;
  663. $post['getStaffName'] = $this->shopAdmin->name ?? '';
  664. }
  665. $groupId = !empty($post['groupId']) ? $post['groupId'] : 0;
  666. $post['fromType'] = $post['fromType'] ?? 1;
  667. if ($post['fromType'] == dict::getDict('fromType', 'friend')) {
  668. if (empty($post['bookName'])) {
  669. util::fail('请填写订花人姓名');
  670. }
  671. }
  672. $customId = $post['customId'] ?? 0;
  673. $custom = CustomClass::getById($customId, true);
  674. if (empty($custom)) {
  675. util::fail('没有找到客户哦');
  676. }
  677. $hdId = $custom->hdId ?? 0;
  678. $hd = HdClass::getById($hdId, true);
  679. if (empty($hd)) {
  680. util::fail('客户对应的花店信息缺失,编号869');
  681. }
  682. $hdName = $hd->name ?? '';
  683. $post['hdId'] = $hdId;
  684. $post['hdName'] = $hdName;
  685. $customName = $custom->name ?? '';
  686. $post['customName'] = $customName;
  687. $post['customNamePy'] = stringUtil::py($customName);
  688. if (!empty($post['receiveMobile'])) {
  689. if (!stringUtil::isMobile($post['receiveMobile'])) {
  690. util::fail('请填写正确的收花人手机号');
  691. }
  692. }
  693. if (!empty($post['bookMobile'])) {
  694. if (!stringUtil::isMobile($post['bookMobile'])) {
  695. util::fail('请填写正确的订花人手机号');
  696. }
  697. }
  698. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  699. $post['sendType'] = $post['sendType'] ?? 1;
  700. $forward = $post['forward'] ?? 0;
  701. if ($forward == 1) {
  702. if ($hasPay != 1) {
  703. util::fail('红冲订单只能走线下转账');
  704. }
  705. $historyDate = $post['historyDate'] ?? '';
  706. if (!empty($historyDate)) {
  707. if ($historyDate != date("Y-m-d")) {
  708. util::fail('红冲订单不能修改账单日期,只能今天');
  709. }
  710. }
  711. }
  712. $productJson = $post['product'] ?? '';
  713. $productList = [];
  714. if (!empty($productJson)) {
  715. $productList = json_decode($productJson, true);
  716. }
  717. if (empty($productList) && empty($groupId)) {
  718. //商家手机上开单并生成制作单
  719. if (!empty($post['unitGoodsPrice'])) {
  720. util::fail('此功能停用,有需要请联系管理员');
  721. $unitGoodsPrice = $post['unitGoodsPrice'];
  722. if (!is_numeric($unitGoodsPrice)) {
  723. util::fail('请输入正确的单价');
  724. }
  725. $productList = GoodsClass::orderCreateGoods($post);
  726. }
  727. }
  728. //直接收款
  729. $zjGathering = $post['zjGathering'] ?? 0;
  730. if ($zjGathering == 1) {
  731. $lsGoodsPrice = $post['lsGoodsPrice'] ?? 0;
  732. if (!is_numeric($lsGoodsPrice) || $lsGoodsPrice <= 0) {
  733. util::fail('请填写价格');
  734. }
  735. //直接收款不需要打印小票
  736. $post['needPrint'] = dict::getDict('needPrint', 'noNeed');
  737. $shopId = $this->shopId;
  738. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  739. $zjGatheringItem = !empty($ext) ? $ext->zjGatheringItem : 0;
  740. if (empty($zjGatheringItem)) {
  741. util::fail('请设置直接收款的商品');
  742. }
  743. $zjGatheringItemInfo = ProductClass::getById($zjGatheringItem, true);
  744. if (empty($zjGatheringItemInfo)) {
  745. util::fail('请设置直接收款的商品哈');
  746. }
  747. $productList = [['productId' => $zjGatheringItem, 'unitType' => 0, 'num' => 1, 'property' => '1', 'unitPrice' => $lsGoodsPrice]];
  748. }
  749. $callErrand = $post['callErrand'] ?? 0;
  750. if ($callErrand == 1) {
  751. $shopId = $this->shopId;
  752. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  753. if (!empty($shopExt) && $shopExt->orderFlow == 0) {
  754. util::fail('下单后要变待发货,才能直接发跑腿');
  755. }
  756. }
  757. $connection = Yii::$app->db;
  758. $transaction = $connection->beginTransaction();
  759. try {
  760. $post['product'] = $productList;
  761. $reduceStock = $post['reduceStock'] ?? 0;
  762. if ($reduceStock == 1) {
  763. //如果扣除库,则走另外一条路
  764. $return = OrderClass::reduceMyStock($post, $this->shop, $custom);
  765. $transaction->commit();
  766. util::success($return);
  767. }
  768. //解决开单提交订单时,别人修改价格,造成提交价格不是真实卖价问题!!
  769. $dealPrice = $post['dealPrice'] ?? 0;
  770. //解决重复提交
  771. util::checkRepeatCommit($this->adminId . '_' . $dealPrice, 3);
  772. $totalNum = 0;
  773. if ($dealPrice == 0) {
  774. $productIds = [];
  775. $hsIds = [];
  776. foreach ($productList as $pv) {
  777. $property = $pv['property'] ?? 0;
  778. $puId = $pv['productId'] ?? 0;
  779. if ($property == 0) {
  780. $hsIds[] = $puId;
  781. } else {
  782. $productIds[] = $puId;
  783. }
  784. }
  785. $itemInfo = [];
  786. if (!empty($productIds)) {
  787. $itemInfo = ProductClass::getByIds($productIds, null, 'id');
  788. }
  789. $hsInfo = [];
  790. if (!empty($hsIds)) {
  791. $hsInfo = GoodsClass::getByIds($hsIds, null, 'id');
  792. }
  793. $diff = [];
  794. $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
  795. $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
  796. $level = 0;
  797. foreach ($productList as $currentProduct) {
  798. $property = $currentProduct['property'] ?? 0;
  799. $currentPrice = $currentProduct['unitPrice'] ?? 0;
  800. $currentId = $currentProduct['productId'] ?? 0;
  801. if ($property == 1) {
  802. $systemInfo = $itemInfo[$currentId] ?? [];
  803. if (!empty($systemInfo)) {
  804. $name = $systemInfo['name'] ?? '';
  805. $systemPrice = \bizGhs\product\classes\ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
  806. if (floatval($currentPrice) != floatval($systemPrice)) {
  807. $diff[] = [
  808. 'name' => $name,
  809. 'price' => $systemPrice,
  810. 'kdPrice' => $currentPrice,
  811. ];
  812. }
  813. }
  814. } else {
  815. $systemInfo = $hsInfo[$currentId] ?? [];
  816. if (!empty($systemInfo)) {
  817. $params = [];
  818. $name = $systemInfo['name'] ?? '';
  819. $hsData = GoodsClass::getFinalPrice($systemInfo, $shop, $custom, $params);
  820. $systemPrice = $hsData['price'] ?? 0;
  821. if ($systemInfo['priceType'] == 1) {
  822. if (floatval($currentPrice) != floatval($systemPrice)) {
  823. $diff[] = [
  824. 'name' => $name,
  825. 'price' => $systemPrice,
  826. 'kdPrice' => $currentPrice,
  827. ];
  828. }
  829. }
  830. }
  831. }
  832. $num = $currentProduct['num'];
  833. $totalNum = bcadd($totalNum, $num);
  834. }
  835. if (!empty($diff)) {
  836. util::success(['diff' => $diff, 'respondType' => 'priceError']);
  837. }
  838. }
  839. //红包使用,多有处,关键词 use_hb_action
  840. $hbId = $post['hbId'] ?? 0;
  841. $hb = null;
  842. if ($hbId > 0) { // 不使用 $hbId =! 0,因为要用负数来表示红包已取消
  843. $hb = HbClass::getById($hbId, true);
  844. if (!empty($hb)) {
  845. if ($hb->customId != $customId) {
  846. util::fail('不是这个客户的红包');
  847. }
  848. if ($hb->amount != $post['hbAmount']) {
  849. util::fail('红包错误'); //红包数据可能被串改
  850. }
  851. if ($hb->status == 1) {
  852. util::fail('红包已使用');
  853. }
  854. if ($hb->status == -1) {
  855. util::fail('红包已作废');
  856. }
  857. if ($hb->endTime < time()) {
  858. $hb->status = -1;
  859. $hb->save();
  860. util::fail('红包已失效');
  861. }
  862. if ($hb->beginTime > time()) {
  863. util::fail('红包可使用期未到');
  864. }
  865. if ($this->shop->rechargeWeal == 3) {
  866. // 判断支付方式是否是余额支付
  867. if ($hasPay != dict::getDict('hasPay', 'balance')) {
  868. util::fail('用红包要用余额支付');
  869. } else {
  870. if ($custom->balance < $post['modifyPrice']) {
  871. util::fail('用红包要用余额支付(您的余额不足)');
  872. }
  873. }
  874. }
  875. } else {
  876. Yii::error('没有找到红包,hbId: ', $hbId . ' ' . __METHOD__);
  877. util::fail('红包无效');
  878. }
  879. }
  880. $post['bigNum'] = $totalNum;
  881. //多处调用这个方法,注意同步修改,搜索关键词 createHdNewOrder
  882. $return = OrderService::createHdOrder($post, $custom, $hasPay);
  883. if (!empty($hb)) {
  884. $hb->status = 1;
  885. $hb->orderId = $return->id;
  886. $hb->save();
  887. }
  888. $staff = $this->shopAdmin;
  889. //售后开付款单,库存要变化,关系要建立,多处需要同步修改 sh_pay_change ssh
  890. OrderClass::shPayChange($return, $shop, $staff);
  891. //打印小票和语音播报等使用
  892. $id = $return->id ?? 0;
  893. $order = OrderClass::getById($id, true);
  894. //如果需要生成制作单
  895. $needWork = $post['needWork'] ?? 0;
  896. if ($needWork == 1) {
  897. $main = $this->main;
  898. WorkClass::needWork($order, $main);
  899. $has = WorkClass::getByCondition(['orderId' => $id], true);
  900. if (!empty($has)) {
  901. $return->hasWork = 1;
  902. $return->save();
  903. }
  904. }
  905. //到店自取订单,并且是待取货状态,则自动完成取货,多处要同步修改,关键词 reach_shop_fetch_goods
  906. if ($order->getGoods == 1 && $order->sendType == 1 && $order->status == 2) {
  907. $order->status = 4;
  908. $order->save();
  909. }
  910. $transaction->commit();
  911. if ($order->fromType == 3 || $order->fromType == 4) {
  912. //除了客服号下单和美团下单,其它情况允许打小票
  913. } else {
  914. //前台打小票
  915. OrderClass::onlinePrint($order);
  916. }
  917. //订单发跑腿流程
  918. HdDeliveryOrderClass::prepareAskData($post, $order);
  919. //前台提示收款多少钱
  920. ShopExtClass::hdGatheringReport($order);
  921. //前台提醒出示付款码
  922. if (isset($order->status) && $order->status == 1) {
  923. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  924. ShopExtClass::pleasePayReport($order);
  925. }
  926. }
  927. $shopId = $order->shopId ?? 0;
  928. $shop = ShopClass::getById($shopId, true);
  929. WxMessageClass::gatheringIncomeInform($shop, $order);
  930. if ($needWork == 1) {
  931. //新制作单提示
  932. $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shopId], true);
  933. ShopExtClass::newWorkRemind($shopExt, $order);
  934. }
  935. util::success($return);
  936. } catch (\Exception $e) {
  937. $transaction->rollBack();
  938. Yii::error("下单失败原因:" . $e->getMessage());
  939. util::fail('下单失败');
  940. }
  941. }
  942. //下单要用到的相关信息 ssh 2019.12.6
  943. public function actionOrderRelate()
  944. {
  945. $regionTree = RegionService::tree();
  946. $shop = $this->shop->attributes;
  947. $freight = MerchantExtendService::getFreight($this->sjExtend);
  948. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  949. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'thirdMapKey' => $mapKey, 'merchant' => $shop];
  950. util::success($out);
  951. }
  952. //余额支付 ssh 2019.12.6
  953. public function actionBalancePay()
  954. {
  955. $post = Yii::$app->request->post();
  956. $orderSn = $post['orderSn'] ?? 0;
  957. $payPassword = $post['payPassword'] ?? 0;
  958. $couponId = $post['couponId'] ?? 0;
  959. $order = OrderService::getByOrderSn($orderSn);
  960. $userId = $this->adminId;
  961. $user = UserService::getUserInfo($userId);
  962. //验证支付密码是否正确
  963. UserService::validPayPassword($payPassword, $user);
  964. //支付前验证订单有效性
  965. OrderService::checkBeforePay($order);
  966. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  967. $totalFee = $order['prePrice'];
  968. $sourceType = 0;
  969. $discountData = OrderService::getDiscountPrice(['price' => $totalFee, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  970. $actPrice = $discountData['price'];
  971. $callbackParams = [];
  972. $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
  973. $balance = $respond['balance'] ?? 0;
  974. util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'balance' => $balance]);
  975. }
  976. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  977. public function actionWxPay()
  978. {
  979. ini_set('date.timezone', 'Asia/Shanghai');
  980. $post = Yii::$app->request->post();
  981. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  982. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  983. $order = OrderService::getByOrderSn($orderSn);
  984. $orderId = $order['id'];
  985. //验证优惠券是否还有效
  986. if (!empty($couponId)) {
  987. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  988. }
  989. //支付前验证订单有效性
  990. OrderService::checkBeforePay($order);
  991. $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
  992. $totalFee = $order['realPrice'];
  993. //小程序使用miniOpenId
  994. if (httpUtil::isMiniProgram()) {
  995. $openId = $this->user['miniOpenId'];
  996. } else {
  997. $openId = $this->user['openId'];
  998. }
  999. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  1000. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  1001. $wxPayType = 0;
  1002. if (httpUtil::isMiniProgram()) {
  1003. $wxPayType = 1;
  1004. }
  1005. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  1006. //订单30分钟后过期
  1007. $now = time();
  1008. $expireTime = $now + 1800;
  1009. $wx = Yii::getAlias("@vendor/weixin");
  1010. require_once($wx . '/lib/WxPay.Api.php');
  1011. require_once($wx . '/example/WxPay.JsApiPay.php');
  1012. $input = new \WxPayUnifiedOrder();
  1013. $input->SetBody($name);
  1014. $input->SetOut_trade_no($orderSn);
  1015. $input->SetTotal_fee($totalFee * 100);
  1016. $input->SetTime_start(date("YmdHis", $now));
  1017. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  1018. $input->SetTime_expire(date("YmdHis", $expireTime));
  1019. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  1020. $input->SetTrade_type("JSAPI");
  1021. //花卉宝代为申请的微信支付
  1022. $merchantExtend = $this->sjExtend->attributes;
  1023. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  1024. $input->SetSub_openid($openId);
  1025. } else {
  1026. $input->SetOpenid($openId);
  1027. }
  1028. //小程序使用miniAppId
  1029. if (httpUtil::isMiniProgram()) {
  1030. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  1031. }
  1032. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  1033. $tools = new \JsApiPay();
  1034. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  1035. $newParams = json_decode($jsApiParameters, true);
  1036. //已请求微信不能修改价格
  1037. $updateData = [];
  1038. $updateData['modPrice'] = 0;
  1039. if (empty($order['deadline'])) {
  1040. $updateData['deadline'] = $expireTime;
  1041. }
  1042. OrderService::updateById($orderId, $updateData);
  1043. util::success($newParams);
  1044. }
  1045. //快捷付款订单
  1046. public function actionFastPay()
  1047. {
  1048. ini_set('date.timezone', 'Asia/Shanghai');
  1049. $post = Yii::$app->request->post();
  1050. $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
  1051. $shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->sj);
  1052. //验证门店是否有效
  1053. $shopInfo = ShopService::getById($shopId);
  1054. ShopService::valid($shopInfo, $this->sjId);
  1055. $post['shopId'] = $shopId;
  1056. //默认门店订单
  1057. $store = isset($post['store']) ? $post['store'] : 1;
  1058. $post['store'] = $store;
  1059. //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
  1060. $sourceType = $this->isWx ? 0 : 1;
  1061. if (httpUtil::isMiniProgram()) {
  1062. $sourceType = 2;
  1063. }
  1064. $sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
  1065. //兼容旧系统sourceType=3表示朋友圈来源
  1066. $fromType = $sourceType == 3 ? 2 : 0;
  1067. $fromType = isset($post['fromType']) && !empty($post['fromType']) ? $post['fromType'] : $fromType;
  1068. $post['userId'] = $this->adminId;
  1069. $custom = $this->custom;
  1070. $post['bookName'] = $custom['userName'] ?? '';
  1071. $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  1072. $bookMobile = empty($bookMobile) && isset($custom['mobile']) && !empty($custom['mobile']) ? $custom['mobile'] : $bookMobile;
  1073. $post['bookMobile'] = $bookMobile;
  1074. $prePrice = round($post['prePrice'], 2);
  1075. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  1076. $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  1077. $actPrice = $discountData['price'];
  1078. $post['discountType'] = $discountData['discountType'];
  1079. $post['discountAmount'] = $discountData['discountAmount'];
  1080. $post['actPrice'] = $actPrice;
  1081. $post['realPrice'] = $actPrice;
  1082. $post['payStyle'] = 0;
  1083. $post['sjId'] = $this->sjId;
  1084. $now = time();
  1085. $expireTime = $now + 300;//订单5分钟后过期
  1086. $post['createTime'] = date("Y-m-d H:i:s", $now);
  1087. $post['deadline'] = $expireTime;
  1088. if ($actPrice <= 0) {
  1089. util::fail('请填写正确的金额');
  1090. }
  1091. //微信支付订单提交不能修改价格
  1092. $post['modPrice'] = $this->isWx ? 0 : 1;
  1093. $post['sourceType'] = $sourceType;
  1094. $post['goodsNum'] = 1;
  1095. $post['fromType'] = $fromType;
  1096. $order = OrderService::addOrder($post);
  1097. $orderId = $order['id'];
  1098. $orderSn = $order['orderSn'];
  1099. $sjId = $this->sjId;
  1100. if ($payWay == 0) {
  1101. $orderId = $order['id'];
  1102. $name = '购买商品';
  1103. $totalFee = $actPrice;
  1104. $user = UserService::getById($this->adminId);
  1105. $openId = isset($user['openId']) ? $user['openId'] : 0;
  1106. if (httpUtil::isMiniProgram()) {
  1107. //小程序使用miniOpenId
  1108. $openId = $user['miniOpenId'];
  1109. }
  1110. if (empty($openId)) {
  1111. util::fail('没有找到客户的openId');
  1112. }
  1113. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  1114. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  1115. $wxPayType = 0;
  1116. if (httpUtil::isMiniProgram()) {
  1117. $wxPayType = 1;
  1118. }
  1119. $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&wxPayType=' . $wxPayType;
  1120. $wx = Yii::getAlias("@vendor/weixin");
  1121. require_once($wx . '/lib/WxPay.Api.php');
  1122. require_once($wx . '/example/WxPay.JsApiPay.php');
  1123. $input = new \WxPayUnifiedOrder();
  1124. $input->SetBody($name);
  1125. $input->SetOut_trade_no($orderSn);
  1126. $input->SetTotal_fee($totalFee * 100);
  1127. $input->SetTime_start(date("YmdHis", $now));
  1128. $input->SetAttach($attach);
  1129. //设置订单有效期5分钟
  1130. $input->SetTime_expire(date("YmdHis", $expireTime));
  1131. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  1132. $input->SetTrade_type("JSAPI");
  1133. //花卉宝代为申请的微信支付
  1134. $merchantExtend = $this->sjExtend->attributes;
  1135. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  1136. $input->SetSub_openid($openId);
  1137. } else {
  1138. $input->SetOpenid($openId);
  1139. }
  1140. //小程序使用miniAppId
  1141. if (httpUtil::isMiniProgram()) {
  1142. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  1143. }
  1144. Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
  1145. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  1146. $tools = new \JsApiPay();
  1147. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  1148. $newParams = json_decode($jsApiParameters, true);
  1149. $newParams['orderId'] = $orderId;
  1150. util::success($newParams);
  1151. } elseif ($payWay == 1) {
  1152. $extend = MerchantExtendService::getBySjId($sjId);
  1153. if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
  1154. util::fail('支付宝付款即将开通...');
  1155. }
  1156. $config = [
  1157. //应用ID,您的APPID。
  1158. 'app_id' => $extend['alipayPId'],
  1159. //商户私钥,您的原始格式RSA私钥
  1160. 'merchant_private_key' => $extend['alipayKey'],
  1161. //异步通知地址
  1162. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-callback",
  1163. //同步跳转
  1164. 'return_url' => "",
  1165. //编码格式
  1166. 'charset' => "UTF-8",
  1167. //签名方式
  1168. 'sign_type' => "RSA2",
  1169. //支付宝网关
  1170. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  1171. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  1172. 'alipay_public_key' => $extend['alipayPublicKey'],
  1173. ];
  1174. Yii::info(json_encode($config) . ' aplipay config');
  1175. $alipayWap = Yii::getAlias("@vendor/alipayWap");
  1176. require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
  1177. require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
  1178. $totalFee = $order['realPrice'];
  1179. $out_trade_no = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
  1180. $subject = '购买商品';//订单名称,必填
  1181. $total_amount = $totalFee;//付款金额,必填
  1182. $body = '';//商品描述,可空
  1183. $timeout_express = "1m";//超时时间
  1184. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  1185. $passBackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&sjId=' . $sjId;//将流水类型、优惠卷传过去
  1186. $passBackParams = urlencode($passBackParams);
  1187. $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
  1188. $payRequestBuilder->setBody($body);
  1189. $payRequestBuilder->setSubject($subject);
  1190. $payRequestBuilder->setOutTradeNo($out_trade_no);
  1191. $payRequestBuilder->setTotalAmount($total_amount);
  1192. $payRequestBuilder->setTimeExpress($timeout_express);
  1193. //在异步通知时将该参数原样返回
  1194. $payRequestBuilder->setPassbackParams($passBackParams);
  1195. //同步通知
  1196. $returnUrl = Yii::$app->params['mallDomain'] . "/#/pages/callback/success?account={$sjId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
  1197. //异步通知
  1198. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/ali-callback";
  1199. $payResponse = new \AlipayTradeService($config);
  1200. $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
  1201. //直接将支付宝的html返回给前端
  1202. echo $result;
  1203. } elseif ($payWay == 2) {
  1204. //余额支付
  1205. util::fail('暂不支持');
  1206. } else {
  1207. util::fail('无效的支付方式');
  1208. }
  1209. }
  1210. //订单评价
  1211. public function actionComment()
  1212. {
  1213. $post = Yii::$app->request->post();
  1214. $id = $post['id'];
  1215. $order = OrderService::getById($id);
  1216. OrderService::valid($order, $this->mainId);
  1217. if ($order['grade'] > 0) {
  1218. util::fail('您已经评过了');
  1219. }
  1220. OrderService::comment($post);
  1221. util::complete('提交成功');
  1222. }
  1223. //订单详情,不需要登陆可以查看,要有盐,给跑腿上查看订单信息用的
  1224. public function actionInfo()
  1225. {
  1226. $get = Yii::$app->request->get();
  1227. $id = $get['id'] ?? 0;
  1228. $salt = $get['salt'] ?? '';
  1229. $detail = OrderClass::getFullInfo($id);
  1230. if (empty($detail)) {
  1231. util::fail('没有找到订单');
  1232. }
  1233. if (empty($detail['salt'])) {
  1234. util::fail('没有找到订单信息');
  1235. }
  1236. if (empty($salt)) {
  1237. util::fail('请求参数错误呢');
  1238. }
  1239. if ($detail['salt'] != $salt) {
  1240. util::fail('不是你的订单');
  1241. }
  1242. util::success($detail);
  1243. }
  1244. //订单详情
  1245. public function actionDetail()
  1246. {
  1247. $id = Yii::$app->request->get('id', 0);
  1248. $detail = OrderClass::getFullInfo($id);
  1249. OrderService::valid($detail, $this->mainId);
  1250. $forwardMap = [];
  1251. if ($detail['forward'] == 1) {
  1252. //当前单如果已经是红冲订单,则取出其对应的原单
  1253. $map = OrderForwardClass::getByCondition(['shOrderId' => $id], true);
  1254. if (!empty($map)) {
  1255. $originOrderId = $map->orderId ?? 0;
  1256. $forwardMap['orderId'] = $originOrderId;
  1257. }
  1258. }
  1259. $detail['forwardMap'] = $forwardMap;
  1260. $shOrderMap = [];
  1261. if ($detail['hasForward'] == 1) {
  1262. $shOrderMap = OrderForwardClass::getAllByCondition(['orderId' => $id], null, '*');
  1263. }
  1264. $detail['shOrderMap'] = $shOrderMap;
  1265. $main = $this->main;
  1266. //是否走红冲订单模式判断 ssh
  1267. $ret = OrderClass::ifShPay($detail, $main, 0);
  1268. $shAddPay = $ret['shAddPay'];
  1269. $shAddPayReason = $ret['shAddPayReason'];
  1270. $detail['shAddPay'] = $shAddPay;
  1271. $detail['shAddPayReason'] = $shAddPayReason;
  1272. util::success($detail);
  1273. }
  1274. public function actionList()
  1275. {
  1276. $get = Yii::$app->request->get();
  1277. $searchText = $get['searchText'] ?? '';
  1278. $shopId = $this->shopId ?? 0;
  1279. if (empty($shopId)) {
  1280. //没有登录不显示数据
  1281. util::success(['list' => [], 'moreData' => 0, 'shop' => [], 'totalNum' => 0, 'totalPage' => 0]);
  1282. }
  1283. $where = [];
  1284. $where['shopId'] = $shopId;
  1285. if (!empty($get['customId'])) {
  1286. $where['customId'] = $get['customId'];
  1287. }
  1288. if (!empty($get['ids'])) {
  1289. $stringIds = $get['ids'];
  1290. $newIds = explode(',', $stringIds);
  1291. $where['id'] = ['in', $newIds];
  1292. }
  1293. $status = $get['status'] ?? 0;
  1294. if (!empty($status)) {
  1295. $where['status'] = $get['status'];
  1296. }
  1297. $debt = $get['debt'] ?? -1;
  1298. if ($debt > -1) {
  1299. $where['debt'] = $debt;
  1300. }
  1301. if (!empty($get['shopAdminId'])) {
  1302. $where['shopAdminId'] = $get['shopAdminId'];
  1303. }
  1304. // 按搜索词自动识别:纯数字查货号,否则查姓名
  1305. if (!empty($searchText)) {
  1306. $this->appendOrderListSearchWhere($where, $searchText);
  1307. }
  1308. if (isset($get['repeat']) && $get['repeat'] > -1) {
  1309. $where['repeat'] = $get['repeat'];
  1310. }
  1311. if (!empty($get['searchTime'])) {
  1312. $startTime = $get['startTime'] ?? '';
  1313. $endTime = $get['endTime'] ?? '';
  1314. $period = dateUtil::formatTime($get['searchTime'], $startTime, $endTime);
  1315. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1316. }
  1317. $list = OrderService::getOrderList($where);
  1318. $list['shop'] = $this->shop->attributes ?? [];
  1319. util::success($list);
  1320. }
  1321. //订单归类 ssh 2019.12.17
  1322. public function actionClassify()
  1323. {
  1324. $post = Yii::$app->request->post();
  1325. $id = $post['id'] ?? 0;
  1326. $order = OrderService::getById($id);
  1327. OrderService::valid($order, $this->mainId);
  1328. $categoryId = $post['categoryId'];
  1329. $usageId = $post['usageId'];
  1330. OrderService::classify($id, $categoryId, $usageId);
  1331. util::complete();
  1332. }
  1333. //更新配送单 ssh 2019.12.17
  1334. public function actionUpdateSheet()
  1335. {
  1336. $post = Yii::$app->request->post();
  1337. $id = $post['id'] ?? 0;
  1338. unset($post['id']);
  1339. $order = OrderService::getById($id);
  1340. OrderService::valid($order, $this->mainId);
  1341. OrderService::updateSheet($order, $post);
  1342. util::complete('提交成功');
  1343. }
  1344. //商家收款与发货 ssh 2019.12.18
  1345. public function actionGathering()
  1346. {
  1347. $post = Yii::$app->request->post();
  1348. $price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
  1349. $payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
  1350. $userId = $post['userId'] ?? 0;
  1351. $userInfo = UserService::getById($userId);
  1352. if (empty($userInfo) || $userInfo['sjId'] != $this->sjId) {
  1353. util::fail('您选择的客户无效');
  1354. }
  1355. if ($price <= 0) {
  1356. util::fail('请输入金额');
  1357. }
  1358. $post['prePrice'] = $price;
  1359. $post['actPrice'] = $price;
  1360. $post['payWay'] = $payWay;
  1361. $post['sourceType'] = 1;
  1362. $post['userId'] = $userId;
  1363. $post['goodsNum'] = 1;
  1364. $post['orderName'] = '商品';
  1365. $shopId = MerchantService::getDefaultShopId($this->sj);
  1366. $post['shopId'] = $shopId;
  1367. $order = OrderService::addOrder($post);
  1368. $id = $order['id'];
  1369. $orderSn = $order['orderSn'];
  1370. //流水类型列表
  1371. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  1372. $callbackParams = [];
  1373. switch ($payWay) {
  1374. case 0:
  1375. xhPayToolService::wxPay($callbackParams, $orderSn, $price, $capitalType, 0);
  1376. break;
  1377. case 1:
  1378. xhPayToolService::alipay($callbackParams, $orderSn, $price, $capitalType, 0, []);
  1379. break;
  1380. case 2:
  1381. xhPayToolService::balancePay($callbackParams, $orderSn, $price, $capitalType, 0);
  1382. break;
  1383. default:
  1384. util::fail('无效支付方式');
  1385. }
  1386. util::success($order);
  1387. }
  1388. //免发货管理 ssh 2020.1.6
  1389. public function actionWithoutSend()
  1390. {
  1391. $id = Yii::$app->request->get('id');
  1392. $order = OrderService::getById($id);
  1393. OrderService::valid($order, $this->mainId);
  1394. //配送流程变更
  1395. $currentFlow = OrderSendClass::withoutSend($order);
  1396. util::success(['currentFlow' => $currentFlow]);
  1397. }
  1398. //修改价格 ssh 2020.1.6
  1399. public function actionUpdatePrice()
  1400. {
  1401. $id = Yii::$app->request->get('id');
  1402. $price = Yii::$app->request->get('price', 1);
  1403. $order = OrderService::getById($id);
  1404. OrderService::valid($order, $this->mainId);
  1405. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  1406. util::fail('已发起支付,不能修改价格');
  1407. }
  1408. OrderService::updateById($id, ['actPrice' => $price]);
  1409. util::complete('修改成功');
  1410. }
  1411. //配送单 ssh 2020.2.29
  1412. public function actionGetDeliverDetail()
  1413. {
  1414. $id = Yii::$app->request->get('id', 0);
  1415. $order = OrderService::getById($id);
  1416. OrderService::valid($order, $this->mainId);
  1417. $reachDate = isset($order['reachDate']) && !empty($order['reachDate']) ? $order['reachDate'] : '';
  1418. $reachPeriodId = $order['reachPeriod'];
  1419. $reachPeriodArr = [0 => '上午', 1 => '下午', 2 => '晚上'];
  1420. $reachPeriod = isset($reachPeriodArr[$reachPeriodId]) ? $reachPeriodArr[$reachPeriodId] : '';
  1421. $bookName = isset($order['bookName']) ? $order['bookName'] : '';
  1422. $bookMobile = isset($order['bookMobile']) ? $order['bookMobile'] : '';
  1423. if (isset($order['anonymity']) && $order['anonymity'] == 1) {
  1424. $bookName = '--';
  1425. $bookMobile = '--';
  1426. }
  1427. $data = [
  1428. 'reachDate' => $reachDate . ' ' . $reachPeriod,
  1429. 'orderSn' => $order['orderSn'],
  1430. 'receiveUserName' => $order['receiveUserName'],
  1431. 'receiveMobile' => $order['receiveMobile'],
  1432. 'fullAddress' => $order['fullAddress'] . "(" . $order['showAddress'] . ")",
  1433. 'cardInfo' => $order['cardInfo'],
  1434. 'bookMobile' => $bookMobile,
  1435. 'bookName' => $bookName,
  1436. 'remark' => $order['remark'],
  1437. 'sendNum' => $order['sendNum'],
  1438. 'telephone' => 18030142050,
  1439. 'printTime' => '',
  1440. 'img' => '',
  1441. ];
  1442. util::success($data);
  1443. }
  1444. //运费计算 lqh 2021.4.12 暂反回固定
  1445. public function actionFreight()
  1446. {
  1447. util::success(['sedCost' => 10]);
  1448. }
  1449. /**
  1450. * 订单列表搜索条件:纯数字按货号精确匹配,否则按客户姓名模糊匹配
  1451. * @param array $where 查询条件(引用传递)
  1452. * @param string $searchText 搜索关键词
  1453. */
  1454. private function appendOrderListSearchWhere(&$where, $searchText)
  1455. {
  1456. $searchText = trim((string)$searchText);
  1457. if ($searchText === '') {
  1458. return;
  1459. }
  1460. if (preg_match('/^\d+$/', $searchText)) {
  1461. $where['sendNum'] = $searchText;
  1462. return;
  1463. }
  1464. $where['customName'] = ['like', $searchText];
  1465. }
  1466. }