You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

585 lines
22 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Commons\Log;
  4. use App\Constants\v3\ErrorCode;
  5. use App\Constants\v3\LogLabel;
  6. use App\Constants\v3\OrderState;
  7. use App\Constants\v3\OrderType;
  8. use App\Constants\v3\Payment;
  9. use App\Constants\v3\SsdbKeys;
  10. use App\Exception\ErrorCodeException;
  11. use App\Model\v3\Coupon;
  12. use App\Model\v3\CouponRec;
  13. use App\Model\v3\Goods;
  14. use App\Model\v3\GoodsActivity;
  15. use App\Model\v3\Order;
  16. use App\Model\v3\OrderGoods;
  17. use App\Model\v3\OrderMain;
  18. use App\Model\v3\OrderSalesStatistic;
  19. use App\Model\v3\ShoppingCart;
  20. use App\Model\v3\Store;
  21. use App\Model\v3\UserAddress;
  22. use App\Service\v3\Interfaces\CouponRecServiceInterface;
  23. use App\Service\v3\Interfaces\CouponServiceInterface;
  24. use App\Service\v3\Interfaces\DeliveryMoneyServiceInterface;
  25. use App\Service\v3\Interfaces\GoodsActivityServiceInterface;
  26. use App\Service\v3\Interfaces\GoodsServiceInterface;
  27. use App\Service\v3\Interfaces\PaymentServiceInterface;
  28. use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface;
  29. use App\TaskWorker\SSDBTask;
  30. use Exception;
  31. use Hyperf\Database\Model\Model;
  32. use Hyperf\DbConnection\Db;
  33. use Hyperf\Di\Annotation\Inject;
  34. use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
  35. use Hyperf\Snowflake\IdGeneratorInterface;
  36. use Hyperf\Utils\ApplicationContext;
  37. class OrderOnlineService implements OrderOnlineServiceInterface
  38. {
  39. /**
  40. * @Inject
  41. * @var Log
  42. */
  43. protected $log;
  44. /**
  45. * @Inject
  46. * @var DeliveryMoneyServiceInterface
  47. */
  48. protected $deliveryService;
  49. /**
  50. * @Inject
  51. * @var CouponRecServiceInterface
  52. */
  53. protected $couponRecService;
  54. /**
  55. * @Inject
  56. * @var CouponServiceInterface
  57. */
  58. protected $couponService;
  59. /**
  60. * @Inject
  61. * @var GoodsActivityServiceInterface
  62. */
  63. protected $goodsActivityService;
  64. /**
  65. * @Inject
  66. * @var GoodsServiceInterface
  67. */
  68. protected $goodsService;
  69. /**
  70. * @Inject
  71. * @var PaymentServiceInterface
  72. */
  73. protected $paymentService;
  74. /**
  75. * @Inject
  76. * @var ShopCartUpdateServiceInterface
  77. */
  78. protected $shopCartUpdateService;
  79. /**
  80. * 下单
  81. * @param $marketId
  82. * @param $userId
  83. * @param $userAddrId
  84. * @param $storeList
  85. * @param $totalMoney
  86. * @param string $deliveryTimeNote
  87. * @param int $serviceMoney
  88. * @param null $receiveCouponIds
  89. * @param string $plat
  90. * @return array[]
  91. */
  92. public function do($marketId, $userId, $userAddrId, $storeList, $totalMoney, $deliveryTimeNote='尽快送达', $serviceMoney=0, $receiveCouponIds=null, $plat=''){
  93. Db::beginTransaction();
  94. try {
  95. $currentTime = time();
  96. bcscale(6);
  97. // 用户收货地址
  98. $userAddr = UserAddress::query()->find($userAddrId);
  99. // 获取配送费用
  100. $deliveryAmount = $this->deliveryService->do($userAddr->lat, $userAddr->lng);
  101. // 优惠券数据
  102. $couponRec = CouponRec::query()->lockForUpdate()->whereIn('id', $receiveCouponIds)->get()->toArray();
  103. // 处理购物车数据,计算订单金额、子订单数据处理等
  104. $totalAmount = 0; # 实付金额
  105. $orderAmount = 0; # 订单金额
  106. $dataMain = []; # 主订单
  107. $dataChildren = []; # 子订单
  108. $dataOrderGoods = []; # 订单商品
  109. $storeTypeIds = []; # 订单中的商户类型,用于校验红包
  110. foreach ($storeList as $key => &$storeItem) {
  111. $storeId = $storeItem->store_id;
  112. // 子订单金额
  113. $subAmount = 0;
  114. // 店铺分类
  115. $storeType = Store::query()->where(['id' => $storeId])->value('category_id');
  116. $storeTypeIds[] = (string)$storeType;
  117. // 店铺今天的订单数
  118. $count = Order::query()
  119. ->join('lanzu_order_main as main', 'main.id', '=', 'lanzu_order.order_main_id')
  120. ->where(['lanzu_order.store_id' => $storeId, 'main.type' => OrderType::ONLINE])
  121. ->whereBetween('lanzu_order.created_at', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))])
  122. ->count();
  123. // 用户购物车数据
  124. $cartIds = explode(',', $storeItem->cart_ids);
  125. $carts = ShoppingCart::query()->whereIn('id', $cartIds)->where(['market_id' => $marketId, 'user_id' => $userId])->get();
  126. foreach ($carts as $k => &$cart) {
  127. // 查个商品
  128. $goods = [];
  129. if ($cart->activity_type == 1) {
  130. $goods = Goods::query()->lockForUpdate()->find($cart->goods_id);
  131. $check = $this->goodsService->check($goods, $cart->num);
  132. if (true !== $check) {
  133. throw new ErrorCodeException($check, '[商品失效1]'.$cart->goods_id);
  134. }
  135. } elseif ($cart->activity_type == 2) {
  136. $goods = GoodsActivity::query()->lockForUpdate()->find($cart->goods_id);
  137. $check = $this->goodsActivityService->check($goods, $cart->num, $userId);
  138. if (true !== $check) {
  139. throw new ErrorCodeException($check, '[商品失效2]'.$cart->goods_id);
  140. }
  141. // 活动商品不可用优惠券
  142. if ($goods->can_use_coupon!=1 && $receiveCouponIds) {
  143. throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_CANNOT_USE_COUPON, '[商品失效]'.$cart->goods_id);
  144. }
  145. // 活动商品可用优惠券,再校验这些优惠券是不是可以在当前活动类型可用
  146. // receiveCouponIds中是不是有当前活动不可用的优惠券
  147. $couponIds = array_values(array_column($couponRec, 'coupon_id'));
  148. $couponsActivityAvailable = Coupon::query()
  149. ->select(['id'])
  150. ->whereJsonContains('activity_available', [(string)$goods->type])
  151. ->whereJsonContains('market_ids', [(string)$goods->market_id])
  152. ->whereIn('id', $couponIds)
  153. ->get()->toArray();
  154. $couponsActivityAvailableIds = array_values(array_column($couponsActivityAvailable, 'id'));
  155. if (!empty(array_diff($couponIds, $couponsActivityAvailableIds))) {
  156. throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_CANNOT_USE_COUPON, '[商品失效]'.json_encode($couponsActivityAvailableIds));
  157. }
  158. }
  159. if (empty($goods)) {
  160. throw new ErrorCodeException(ErrorCode::ORDER_GOODS_NOT_AVAILABLE);
  161. }
  162. // 库存判断
  163. if ($goods->is_infinite !=1 && $goods->inventory < $cart->num) {
  164. throw new ErrorCodeException(ErrorCode::ORDER_GOODS_INVENTORY_LIMIT);
  165. }
  166. // 算金额
  167. $goodsAmount = bcmul((string)$goods->price, (string)$cart->num); # 当前商品的金额
  168. $subAmount = bcadd((string)$subAmount, (string)$goodsAmount); # 当前店铺子订单的金额
  169. // 订单商品数据
  170. $dataOrderGoods[$storeId][] = [
  171. 'order_id' => 0,
  172. 'goods_id' => $cart->goods_id,
  173. 'activity_type' => $cart->activity_type,
  174. 'number' => $cart->num,
  175. 'price' => $goods->price,
  176. 'original_price' => $goods->original_price,
  177. 'vip_price' => $goods->vip_price,
  178. 'name' => $goods->name,
  179. 'goods_unit' => $goods->goods_unit,
  180. 'cover_img' => $goods->cover_img,
  181. 'spec' => json_encode($goods->spec),
  182. ];
  183. }
  184. // 子订单数据
  185. $dataChildren[] = [
  186. 'order_main_id' => 0,
  187. 'user_id' => $userId,
  188. 'store_id' => $storeId,
  189. 'money' => bcadd((string)$subAmount, '0', 2),
  190. 'oid' => $count + 1,
  191. 'order_num' => date('YmdHis').mt_rand(1000, 9999),
  192. 'note' => $storeItem->note
  193. ];
  194. // 订单金额
  195. $orderAmount = bcadd((string)$orderAmount, (string)$subAmount);
  196. }
  197. // 优惠券的使用
  198. $couponMoney = 0;
  199. if (!empty($couponRec)) {
  200. $couponsCanUse = $this->couponRecService->allForOrderOlAvailable($totalAmount, $userId, $marketId, 2, $storeTypeIds);
  201. $couponCanUseIds = array_column($couponsCanUse, 'id');
  202. $couponCanUseIds = array_intersect($couponCanUseIds, $receiveCouponIds);
  203. $couponCannotUseIds = array_diff($receiveCouponIds, $couponCanUseIds);
  204. if (empty($couponCanUseIds)||!empty($couponCannotUseIds)) {
  205. throw new ErrorCodeException(ErrorCode::COUPON_NOT_AVAILABLE);
  206. }
  207. // 计算红包折扣金额
  208. foreach ($couponsCanUse as $key => $coupon) {
  209. if (!in_array($coupon->id, $receiveCouponIds)) {
  210. continue;
  211. }
  212. if ($coupon->discount_type == Coupon::DISCOUNT_TYPE_CASH) {
  213. $couponMoney = bcadd($couponMoney, $coupon->discounts, 2);
  214. } elseif ($coupon->discount_type == Coupon::DISCOUNT_TYPE_RATE) {
  215. $discountRate = bcdiv($coupon->discounts,10);
  216. $discountRate = bcsub(1,$discountRate);
  217. $discountMoney = bcmul($orderAmount, $discountRate);
  218. $couponMoney = bcadd($couponMoney, $discountMoney, 2);
  219. }
  220. }
  221. }
  222. // 获取分布式全局ID
  223. $generator = ApplicationContext::getContainer()->get(IdGeneratorInterface::class);
  224. $globalOrderId = $generator->generate();
  225. $orderAmount = bcadd((string)$orderAmount, '0', 2);
  226. $totalAmount = bcadd((string)$totalAmount, (string)$orderAmount);
  227. $totalAmount = bcadd((string)$totalAmount, (string)$deliveryAmount);
  228. $totalAmount = bcadd((string)$totalAmount, (string)$serviceMoney);
  229. $totalAmount = bcsub((string)$totalAmount, (string)$couponMoney, 2);
  230. // 校验订单总金额
  231. if ($totalAmount != $totalMoney) {
  232. throw new ErrorCodeException(ErrorCode::ORDER_TOTAL_AMOUNT_ERROR);
  233. }
  234. $dataMain = [
  235. 'market_id' => $marketId,
  236. 'order_num' => $globalOrderId,
  237. 'global_order_id' => $globalOrderId,
  238. 'user_id' => $userId,
  239. 'type' => OrderType::ONLINE,
  240. 'money' => $totalAmount,
  241. 'total_money' => $orderAmount,
  242. 'services_money' => $serviceMoney,
  243. 'coupon_money' => $couponMoney,
  244. 'delivery_money' => $deliveryAmount,
  245. 'state' => OrderState::UNPAID,
  246. 'tel' => $userAddr->tel,
  247. 'address' => $userAddr->address.$userAddr->doorplate,
  248. 'lat' => $userAddr->lat,
  249. 'lng' => $userAddr->lng,
  250. 'name' => $userAddr->user_name,
  251. 'plat' => $plat,
  252. 'delivery_time_note' => $deliveryTimeNote
  253. ];
  254. // 生成主订单
  255. $orderMain = OrderMain::query()->create($dataMain);
  256. // 处理子订单
  257. foreach ($dataChildren as $key => &$child) {
  258. $child['order_main_id'] = $globalOrderId;
  259. $orderChild = Order::query()->create($child);
  260. $orderChildId = $orderChild->id;
  261. foreach ($dataOrderGoods[$child['store_id']] as $k => &$orderGoods) {
  262. $orderGoods['order_id'] = $orderChildId;
  263. $orderGoods['created_at'] = $currentTime;
  264. $orderGoods['updated_at'] = $currentTime;
  265. }
  266. OrderGoods::query()->insert($dataOrderGoods[$child['store_id']]);
  267. }
  268. // 判断是否有购买多个特价商品
  269. $check = $this->goodsActivityService->checkOrderActivityCount($dataOrderGoods);
  270. if(!$check){
  271. throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT, '[同一订单同种类型活动商品]'.json_encode($dataOrderGoods));
  272. }
  273. // 订单成功,做一些处理
  274. // 活动商品购买记录
  275. foreach ($dataOrderGoods as $key => &$goods) {
  276. foreach ($goods as $k => &$goodsItem)
  277. if ($goodsItem['activity_type'] == 2) {
  278. $this->goodsActivityService->cacheRecord($goodsItem['goods_id'], $goodsItem['number'], $userId);
  279. }
  280. }
  281. // 优惠券红包使用记录
  282. $this->couponService->orderUseCoupons($globalOrderId, $couponRec);
  283. Db::commit();
  284. // 清除购物车
  285. $this->shopCartUpdateService->doClear($userId, $marketId);
  286. // 记录用户中心的badge
  287. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  288. $ssdb->exec('hincr', SsdbKeys::USER_ORDER_BADGE.$userId, 'unpaid', 1);
  289. // 支付
  290. return $this->paymentService->do($globalOrderId, $totalAmount, $userId, config('wechat.notify_url.online'));
  291. } catch (Exception $e) {
  292. Db::rollBack();
  293. $this->log->event(LogLabel::ORDER_ONLINE_LOG, ['exception_msg' => $e->getMessage()]);
  294. throw new ErrorCodeException(ErrorCode::ORDER_ONLINE_FAIL, $e->getMessage());
  295. }
  296. }
  297. public function check($globalOrderId, $userId, $state): Model
  298. {
  299. $builder = OrderMain::query()
  300. ->where(['global_order_id' => $globalOrderId, 'user_id' => $userId]);
  301. if (is_array($state)) {
  302. $builder = $builder->whereIn('state', $state);
  303. } else {
  304. $builder = $builder->where(['state' => $state]);
  305. }
  306. $orderMain = $builder->first();
  307. if (empty($orderMain)) {
  308. throw new ErrorCodeException(ErrorCode::ORDER_NOT_AVAILABLE);
  309. }
  310. return $orderMain;
  311. }
  312. /**
  313. * @inheritDoc
  314. */
  315. public function undo($globalOrderId, $userId)
  316. {
  317. Db::beginTransaction();
  318. try {
  319. // 订单待支付
  320. $orderMain = $this->check($globalOrderId, $userId, OrderState::UNPAID);
  321. $orderMain->state = OrderState::CANCELED;
  322. if (!$orderMain->save()) {
  323. throw new ErrorCodeException(ErrorCode::ORDER_NOT_AVAILABLE);
  324. }
  325. // 退还优惠券
  326. $this->couponService->orderRefundCoupons($globalOrderId);
  327. // 撤销活动商品购买记录
  328. $orders = Order::query()->where(['order_main_id' => $globalOrderId])->get()->toArray();
  329. $orderGoods = OrderGoods::query()
  330. ->where('activity_type', 2)
  331. ->whereIn('order_id', array_values(array_column($orders, 'id')))
  332. ->get();
  333. foreach ($orderGoods as $key => &$goods) {
  334. $this->goodsActivityService->clearCacheRecord($goods->goods_id, $goods->number, $orderMain->user_id);
  335. }
  336. Db::commit();
  337. return true;
  338. } catch (Exception $e) {
  339. Db::rollBack();
  340. throw new ErrorCodeException(ErrorCode::ORDER_CANCEL_FAIL, $e->getMessage());
  341. }
  342. }
  343. public function detailByUser($globalOrderId, $userId)
  344. {
  345. $orderMain = OrderMain::with(['market'])->where(['global_order_id' => $globalOrderId])->first();
  346. $orders = Order::query()
  347. ->where(['order_main_id' => $globalOrderId, 'user_id' => $userId])
  348. ->with([
  349. 'orderGoods',
  350. 'store'
  351. ])
  352. ->get()->toArray();
  353. return ['order_main' => $orderMain, 'orders' => $orders];
  354. }
  355. /**
  356. * @inheritDoc
  357. */
  358. public function doByPaid($globalOrderId)
  359. {
  360. Db::beginTransaction();
  361. try {
  362. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  363. // 查询订单
  364. $orderMain = OrderMain::query()
  365. ->where(['global_order_id' => $globalOrderId,'type' => OrderType::ONLINE])
  366. ->first();
  367. // 修改订单、子订单状态
  368. $currentTime = time();
  369. $orderMain->state = OrderState::PAID;
  370. $orderMain->pay_time = $currentTime;
  371. $orderMain->save();;
  372. // 更新商品库存和销量
  373. $orders = Order::query()
  374. ->where(['order_main_id' => $globalOrderId])
  375. ->get()
  376. ->toArray();
  377. // 更新商户销量
  378. $upStoreScore = Store::query()
  379. ->whereIn('id', array_values(array_column($orders, 'store_id')))
  380. ->update(['sales' => Db::raw('sales+1')]);
  381. $orderGoods = OrderGoods::query()
  382. ->whereIn('order_id', array_values(array_column($orders, 'id')))
  383. ->get()
  384. ->toArray();
  385. foreach ($orderGoods as $key => &$goodsItem) {
  386. if ($goodsItem['activity_type'] == 2) { # 活动商品
  387. $goods = GoodsActivity::find($goodsItem['goods_id']);
  388. } else {
  389. $goods = Goods::find($goodsItem['goods_id']);
  390. }
  391. $goods->inventory = $goods->inventory - $goodsItem['number'];
  392. $goods->sales = $goods->sales + $goodsItem['number'];
  393. $goods->save();
  394. // 商品月销
  395. if (!$ssdb->exec('exists', SsdbKeys::GOODS_MONTH_SALES . date('Ym') . '_' . $goodsItem['activity_type'] . '_'.$goods->id)) {
  396. $ssdb->exec('set', SsdbKeys::GOODS_MONTH_SALES . date('Ym') . '_' . $goodsItem['activity_type'] . '_' . $goods->id, $goodsItem['number']);
  397. } else {
  398. $ssdb->exec('incr', SsdbKeys::GOODS_MONTH_SALES . date('Ym') . '_' . $goodsItem['activity_type'] . '_' . $goods->id, $goodsItem['number']);
  399. }
  400. }
  401. // 月销流水
  402. $statistics = [];
  403. foreach ($orders as $key => &$order) {
  404. $statistics[] = [
  405. 'money' => $order['money'],
  406. 'user_id' => $order['user_id'],
  407. 'store_id' => $order['store_id'],
  408. 'market_id' => $orderMain->market_id,
  409. 'order_id' => $order['id'],
  410. 'createtime' => $orderMain->pay_time,
  411. ];
  412. // 商户月销
  413. if (!$ssdb->exec('exists', SsdbKeys::STORE_MONTH_SALES . date('Ym').'_' . $order['store_id'])) {
  414. $ssdb->exec('set', SsdbKeys::STORE_MONTH_SALES . date('Ym') . '_' . $order['store_id'], 1);
  415. } else {
  416. $ssdb->exec('incr', SsdbKeys::STORE_MONTH_SALES . date('Ym') . '_' . $order['store_id'], 1);
  417. }
  418. }
  419. if (is_array($statistics) && !empty($statistics)) {
  420. $inSalesStatistics = OrderSalesStatistic::query()->insert($statistics);
  421. }
  422. Db::commit();
  423. // 记录用户中心的badge
  424. $ssdb->exec('hincr', SsdbKeys::USER_ORDER_BADGE.$orderMain->user_id, 'receiving', 1);
  425. return true;
  426. } catch (Exception $e) {
  427. $this->log->event(LogLabel::ORDER_ONLINE_PAID_LOG, ['exception' => $e->getMessage()]);
  428. Db::rollBack();
  429. return false;
  430. }
  431. }
  432. /**
  433. * @inheritDoc
  434. */
  435. public function doPay($globalOrderId, $userId)
  436. {
  437. // 订单待支付
  438. $orderMain = $this->check($globalOrderId, $userId, OrderState::UNPAID);
  439. return $this->paymentService->do(
  440. $orderMain->global_order_id,
  441. $orderMain->money,
  442. $orderMain->user_id,
  443. config('wechat.notify_url.online')
  444. );
  445. }
  446. /**
  447. * @inheritDoc
  448. * @throws Exception
  449. */
  450. public function doDel($globalOrderId, $userId)
  451. {
  452. // 订单完成
  453. $orderMain = $this->check($globalOrderId, $userId, OrderState::CAN_DEL);
  454. if (!$orderMain->delete()) {
  455. throw new ErrorCodeException(ErrorCode::ORDER_DELETE_FAIL);
  456. }
  457. return true;
  458. }
  459. /**
  460. * @inheritDoc
  461. */
  462. public function doApplyRefund($globalOrderId, $userId)
  463. {
  464. // 未接单
  465. $orderMain = $this->check($globalOrderId, $userId, OrderState::PAID);
  466. $orderMain->state = OrderState::REFUNDING;
  467. if (!$orderMain->save()) {
  468. throw new ErrorCodeException(ErrorCode::ORDER_APPLY_REFUND_FAIL);
  469. }
  470. // 记录badge
  471. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  472. $ssdb->exec('hincr', SsdbKeys::USER_ORDER_BADGE.$orderMain->user_id, 'refund', 1);
  473. return true;
  474. }
  475. /**
  476. * @inheritDoc
  477. */
  478. public function doComplete($globalOrderId, $userId)
  479. {
  480. $orderMain = $this->check($globalOrderId, $userId, OrderState::RECEIVING);
  481. $orderMain->state = OrderState::COMPLETED;
  482. if (!$orderMain->save()) {
  483. throw new ErrorCodeException(ErrorCode::ORDER_COMPLETE_FAIL);
  484. }
  485. // 记录badge
  486. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  487. $ssdb->exec('hincr', SsdbKeys::USER_ORDER_BADGE.$orderMain->user_id, 'completed', 1);
  488. return true;
  489. }
  490. /**
  491. * @inheritDoc
  492. */
  493. public function doRefund($globalOrderId, $userId)
  494. {
  495. $orderMain = $this->check($globalOrderId, $userId, OrderState::REFUNDING);
  496. $orderMain->state = OrderState::REFUNDED;
  497. if (!$orderMain->save()) {
  498. throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL);
  499. }
  500. // 微信退款
  501. if ($orderMain->pay_type == Payment::WECHAT) {
  502. return $this->paymentService->undo($orderMain->global_order_id, $userId);
  503. }
  504. }
  505. }