OwnerPriceOperationService.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. <?php
  2. namespace App\Services;
  3. use App\Feature;
  4. use App\Jobs\HandlePastBill;
  5. use App\Owner;
  6. use App\OwnerFeeDetail;
  7. use App\OwnerPriceOperation;
  8. use App\OwnerPriceOperationItem;
  9. use App\Services\common\QueryService;
  10. use Illuminate\Database\Eloquent\Builder;
  11. use Illuminate\Database\Eloquent\Collection;
  12. use Illuminate\Database\Eloquent\Model;
  13. use Illuminate\Support\Facades\Cache;
  14. use Illuminate\Support\Facades\DB;
  15. use App\Traits\ServiceAppAop;
  16. class OwnerPriceOperationService
  17. {
  18. use ServiceAppAop;
  19. protected $modelClass=OwnerPriceOperation::class;
  20. /**
  21. * @param Builder $builder
  22. * @param array $params
  23. * @return Builder
  24. */
  25. private function query(Builder $builder, array $params)
  26. {
  27. if ($params["owner_id"] ?? false){
  28. $ids = $this->ownerGetIds($params["owner_id"]);
  29. if ($ids)$builder->whereIn("id",$ids);
  30. unset($params["owner_id"]);
  31. }
  32. $columnQueryRules = [
  33. "name" => ["like"=>""]
  34. ];
  35. return app(QueryService::class)->query($params, $builder, $columnQueryRules);
  36. }
  37. public function paginate(array $params, array $withs = [])
  38. {
  39. return $this->query(OwnerPriceOperation::query()->orderByDesc('id')->with($withs),$params)
  40. ->paginate($params["paginate"] ?? 50);
  41. }
  42. private function ownerGetIds(string $ownerId)
  43. {
  44. if (!$ownerId)return [];
  45. $arr = DB::select(DB::raw("SELECT owner_price_operation_id AS id FROM owner_price_operation_owner WHERE owner_id in (".$ownerId.")"));
  46. return array_column($arr,"id");
  47. }
  48. /**
  49. * 拷贝目标数据
  50. *
  51. * @param object|int $model
  52. * @param array $values
  53. * @param array $items
  54. * @param array|null $owners
  55. * @param bool $isLoadItem
  56. *
  57. * @return object|null
  58. */
  59. public function copy($model, $values = [], $owners = null, $items = [], $isLoadItem = true)
  60. {
  61. if (is_integer($model))$model = OwnerPriceOperation::query()->find($model);
  62. if (!$model)return null;
  63. $values["operation"] = "U";
  64. $values["target_id"] = $model->id;
  65. foreach ($model->getFillable() as $column){
  66. if (!array_key_exists($column,$values))$values[$column] = $model[$column];
  67. }
  68. if ($owners === null){
  69. $query = DB::raw("SELECT * FROM owner_price_operation_owner WHERE owner_price_operation_id = {$model->id}");
  70. $owners = array_column(DB::select($query),"owner_id");
  71. }
  72. /** @var OwnerPriceOperation $copyModel */
  73. $copyModel = OwnerPriceOperation::query()->create($values);
  74. $copyModel->owners()->sync($owners);
  75. $insert = [];
  76. if ($isLoadItem){
  77. $model->load("items");
  78. /** @var \stdClass $model */
  79. foreach ($model->items as $item){
  80. $columns = ["strategy","amount","unit_id","unit_price","feature","priority","discount_price","odd_price"];
  81. if ($items[$item->id] ?? false){
  82. foreach ($columns as $column){
  83. if (!array_key_exists($column,$items[$item->id]))$items[$item->id][$column] = $item[$column];
  84. }
  85. $obj = $items[$item->id];
  86. unset($items[$item->id]);
  87. }else{
  88. /** @var OwnerPriceOperationItem $item */
  89. $obj = $item->toArray();
  90. unset($obj["id"]);
  91. }
  92. $obj["owner_price_operation_id"] = $copyModel->id;
  93. $insert[] = $obj;
  94. }
  95. }else{
  96. foreach ($items as $item){
  97. $arr = [];
  98. $arr["owner_price_operation_id"] = $copyModel->id;
  99. $arr["strategy"] = $item["strategy"];
  100. $arr["amount"] = $item["amount"] ?? null;
  101. $arr["unit_id"] = $item["unit_id"];
  102. $arr["unit_price"] = $item["unit_price"];
  103. $arr["feature"] = $item["feature"] ?? null;
  104. $arr["odd_price"] = $item["odd_price"] ?? null;
  105. $arr["priority"] = $item["priority"] ?? 0;
  106. $arr["discount_price"] = isset($item["discount_price"]) ? (is_array($item["discount_price"]) ? implode(",",$item["discount_price"]) : $item["discount_price"]) : null;
  107. $insert[] = $arr;
  108. }
  109. }
  110. if ($insert)OwnerPriceOperationItem::query()->insert($insert);
  111. return $copyModel;
  112. }
  113. /**
  114. * 审核或恢复目标集
  115. *
  116. * @param bool $isAudit
  117. * @param integer|null|array $ownerId
  118. * @param integer|null|array $ids
  119. */
  120. public function auditOrRecover($isAudit = true, $ownerId = null, $ids = null)
  121. {
  122. if (!$ownerId && !$ids)return;
  123. $result = app(QueryService::class)->priceModelAuditOrRecoverQuery($isAudit,OwnerPriceOperation::query(),$ownerId,$ids);
  124. if ($result["delete"])$this->destroy($result["delete"]);
  125. if ($result["update"])OwnerPriceOperation::query()->whereIn("id",$result["update"])->update(["operation"=>null,"target_id"=>null]);
  126. if (!is_array($ownerId))$ownerId = [$ownerId];
  127. foreach ($ownerId as $ow)Cache::tags("operationFeeOwner:".$ow)->flush();
  128. }
  129. public function destroy($id)
  130. {
  131. if (!is_array($id))$id = [$id];
  132. OwnerPriceOperationItem::query()->whereIn("owner_price_operation_id",$id)->delete();
  133. $query = "IN (";
  134. for ($i=0;$i<count($id)-1;$i++)$query .= "{$id[$i]},";
  135. $query .= "{$id[count($id)-1]})";
  136. $sql = "SELECT * FROM owner_price_operation_owner WHERE owner_price_operation_id {$query}";
  137. $owners = array_column(DB::select(DB::raw($sql)),"owner_id");
  138. DB::table("owner_price_operation_owner")->whereIn("owner_price_operation_id",$id)->delete();
  139. app("OwnerService")->refreshRelevance($owners,1,true);
  140. return OwnerPriceOperation::destroy($id);
  141. }
  142. /**
  143. * @param array $params
  144. * @return Model
  145. */
  146. public function create(array $params)
  147. {
  148. $params["operation"] = "C";
  149. return OwnerPriceOperation::query()->create($params);
  150. }
  151. public function insertItem(array $params)
  152. {
  153. OwnerPriceOperationItem::query()->insert($params);
  154. }
  155. public function find($id, $withs = [])
  156. {
  157. $query = OwnerPriceOperation::query()->with($withs)->find($id);
  158. return $query;
  159. }
  160. public function update(array $params, array $values)
  161. {
  162. $query = OwnerPriceOperation::query();
  163. foreach ($params as $column => $value){
  164. $query->where($column,$value);
  165. }
  166. return $query->update($values);
  167. }
  168. public function destroyItem($id)
  169. {
  170. return OwnerPriceOperationItem::query()->where("owner_price_operation_id",$id)->delete();
  171. }
  172. public function findUpdate(OwnerPriceOperation $model, array $params)
  173. {
  174. return $model->update($params);
  175. }
  176. /**
  177. * 获取计费模型缓存
  178. *
  179. * @param integer $owner
  180. * @param string $type
  181. * @param int|null $typeMark
  182. *
  183. * @return array|Collection
  184. *
  185. */
  186. public function getOwnerPriceOperation($owner, $type, $typeMark)
  187. {
  188. return Cache::tags("operationFeeOwner:".$owner)->remember("operationFee:".$owner.$type.$typeMark,config("cache.expirations.rarelyChange"),
  189. function ()use($owner,$type,$typeMark){
  190. $query = OwnerPriceOperation::query()->with(["items"=>function($query){
  191. /** @var Builder $query */
  192. $query->orderByRaw("CASE strategy WHEN '起步' THEN 1 WHEN '默认' THEN 2 WHEN '特征' THEN 3 END DESC,priority");
  193. }])->where("operation_type",$type)->whereHas("owners",function ($query)use($owner){
  194. /** @var Builder $query */
  195. $query->where("id",$owner);
  196. })->where(function(Builder $query){
  197. $query->whereNull("operation")->orWhere("operation","");
  198. })->orderByRaw("strategy desc,priority desc");
  199. if ($typeMark!==null)$query->where("type_mark",$typeMark);
  200. else $query->whereNull("type_mark");
  201. return $query->get();
  202. });
  203. }
  204. /**
  205. * 获取满减信息
  206. *
  207. * @param null|string $discount
  208. * @param integer $total
  209. *
  210. * @return bool|array
  211. */
  212. public function getDiscount($discount, $total)
  213. {
  214. if ($discount){
  215. foreach (array_reverse(explode(",",$discount),true) as $index=>$discount){
  216. if ($total >= $discount)return [$index=>$discount];
  217. }
  218. }
  219. return false;
  220. }
  221. /**
  222. * 处理折扣单
  223. *
  224. * @param object $rule
  225. * @param integer $owner
  226. * @param bool|array $result
  227. */
  228. public function handleDiscount($rule, $owner, $result)
  229. {
  230. $sign = false;
  231. //入口仅在此处存在 缓存1000s
  232. $key = "owner_price_operation_owner_".$rule->id."_".$owner;
  233. $discountIndex = key($result);
  234. $targetValue = $result[$discountIndex];
  235. $pivot = null;
  236. try{
  237. DB::beginTransaction();
  238. //此处暂时未使用cache的互斥锁 使用sql行锁代替下 防止缓存击穿
  239. $pivot = app(CacheService::class)->getOrExecute($key,function ()use($key,$targetValue,&$sign,$rule,$owner){
  240. return DB::selectOne(DB::raw("SELECT * FROM owner_price_operation_owner WHERE owner_price_operation_id = ? AND owner_id = ? for update"),[$rule->id,$owner]);
  241. },1000);
  242. if ($pivot && (!$pivot->discount_date || substr($pivot->discount_date,0,7)!=date("Y-m") || $pivot->target_value < $targetValue)){
  243. //未被标记过处理时间或处理时间不为本月,或上次处理值过期,处理历史即时账单
  244. $sign = true;
  245. }
  246. if ($sign){
  247. //先标记成功 这将在后续推进历史单处理流程,防止程序在此堵塞
  248. DB::update(DB::raw("UPDATE owner_price_operation_owner SET discount_date = ?,target_value = ? WHERE owner_price_operation_id = ? AND owner_id = ?"),
  249. [date("Y-m-d"),$targetValue,$rule->id,$owner]);
  250. $pivot->discount_date = date("Y-m-d");
  251. $pivot->target_value = $targetValue;
  252. Cache::put($key,$pivot,1000);
  253. }
  254. DB::commit();
  255. }catch (\Exception $exception){
  256. DB::rollBack();
  257. LogService::log(__CLASS__,"即时账单满减处理失败",$exception->getMessage());
  258. }
  259. //进入历史单处理
  260. if ($pivot && $sign)dispatch(new HandlePastBill(array($rule,$owner,$discountIndex,$pivot)));
  261. }
  262. /** 参数顺序: 数量 匹配对象 列映射 货主ID 单位ID 类型 SKU .
  263. * 匹配顺序: 类型 货主 策略 单位 特征 ..多对多匹配规则废弃,1对1,设单位必定为件,对应规则必然只有一项存在
  264. * 单位匹配: 件,箱 由小到大,依次换算匹配 .
  265. *
  266. * 2:没有总数量存在,都为子项内数量
  267. *
  268. * @param array|object|Model $matchObject key-val
  269. * @param array $columnMapping key-val
  270. * @param string $ownerId
  271. * @param string $type
  272. * @param int|null $typeMark
  273. *
  274. * @return double|array
  275. * 错误代码: -1:无匹配对象 -2:无计费模型 -3:未知单位 -4:sku为空 -5:货主未找到 -6:无箱规 -7:未匹配到计费模型
  276. *
  277. * 一. 2020-10-10 zzd
  278. * 二. 2021-01-08 zzd
  279. * 三. 2021-01-28 zzd
  280. * 增加满减策略:子策略匹配时不再考虑单,仅件箱换算,满减满足后标记模型修改历史对账单
  281. * 增加按订单计价策略:主匹配模型增加字段量价,该字段存在时视为按单计价,价格为该值
  282. * 四. 2021-02-18 zzd
  283. * 满减多阶段匹配 满减字段由单值改为字符串多值 匹配时转数组寻找最相近
  284. * 五. 2021-03-18 zzd
  285. * 区分单据类型,增加字段
  286. * 六. 2021-03-23 zzd
  287. * 不严格区分入库出库差异 统一模型
  288. * 七. 2021-03-30 zzd
  289. * 增加一级二级特征,零头价,满减按总件,附加费用等
  290. * 八. 2021-04-19 zzd
  291. * 增加税率计算,改变返回值数据结构,增加封顶费
  292. * 九. 2021-04-21 zzd
  293. * 排除掉order不存在包裹情况,预设输出值为null防止返回0,历史账单处理推进队列防止超时
  294. */
  295. public function matching($matchObject, $columnMapping, $ownerId, $type = '出库', $typeMark = null)
  296. {
  297. $units = app("UnitService")->getUnitMapping(["件","箱"]); //获取单位映射集
  298. $rules = $this->getOwnerPriceOperation($ownerId,$type,$typeMark);//货主下的全部规则
  299. if (!$rules)return -2; //规则不存在跳出
  300. //建立一组返回变量
  301. $id = null;
  302. $money = null;
  303. $taxFee = null;
  304. if ($type == '出库')$total = app("OrderService")->getOrderQuantity($ownerId)+1;//获取该货主本月C端单量
  305. else {
  306. $total = 0;
  307. if ($matchObject->storeItems)foreach ($matchObject->storeItems as $item)$total += $item->amount;
  308. $total += app("StoreService")->getStoreAmount($ownerId);//获取该货主本月入库件数
  309. }
  310. foreach ($rules as $rule){
  311. if (!$rule->items)continue; //不存在子规则跳出
  312. $result = $this->getDiscount($rule->discount_count,$total); //满减信息
  313. if ($result)$this->handleDiscount($rule,$ownerId,$result);//满减存在
  314. if ($rule->strategy == '特征'){
  315. if (app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject)){
  316. if (!$rule->total_price)$money = $this->matchItem($rule,$columnMapping,$matchObject,$units,$ownerId,$result);
  317. $id = $rule->id;
  318. };
  319. }else{
  320. if (!$rule->total_price)$money = $this->matchItem($rule,$columnMapping,$matchObject,$units,$ownerId,$result);
  321. $id = $rule->id;
  322. };
  323. if ($id){
  324. if ($rule->total_price)$money = $result ? explode(",",$rule->total_discount_price)[key($result)] : $rule->total_price;//按单计价存在,直接返回单总价或减免总价
  325. $money = $rule->max_fee&&$money>$rule->max_fee ? $rule->max_fee : $money;//封顶费
  326. if ($money<=0)$money=null;//计算失误
  327. if ($rule->tax_rate_id && $rule->taxRate)$taxFee = $money*($rule->taxRate->value/100);
  328. else{
  329. /** @var Owner|\stdClass $owner */
  330. $owner = Owner::query()->with("taxRate")
  331. ->whereHas("taxRate")->find($ownerId);
  332. if ($owner)$taxFee = $money*($owner->taxRate->value/100);
  333. }
  334. break;
  335. }
  336. }
  337. return array($id,$money,$taxFee);
  338. }
  339. /**
  340. * 根据货主 sku寻找箱规并将指定数量切换为箱 返回箱规
  341. *
  342. * @param integer $ownerId
  343. * @param null|object $commodity
  344. *
  345. * @return int
  346. */
  347. private function changeUnit($ownerId,$commodity)
  348. {
  349. if (!$commodity)return -4;
  350. if ($commodity["pack_spec"])return $commodity["pack_spec"];
  351. $pack = app("CommodityService")->getPack($ownerId,$commodity["sku"]);
  352. if (!$pack)return -6;
  353. return $pack;
  354. }
  355. /**
  356. * 重置子节点的映射对象 将无限极数组扁平化为二维 以Feature中定义的8:商品数量 key为基准
  357. *
  358. * @param object|array $matchObject
  359. * @param array $columnMapping
  360. *
  361. * @return array
  362. */
  363. private function resetChildNodeMapping($matchObject,&$columnMapping)
  364. {
  365. $need = "";
  366. foreach (Feature::TYPE_NODE as $index){
  367. if (!$need)$need=strstr($columnMapping[$index],".",true);
  368. $columnMapping[$index] = ltrim(strstr($columnMapping[$index],"."),".");
  369. }
  370. $nextObj = strstr($columnMapping[8],".",true);
  371. $first = $matchObject[$need] ?? false;
  372. if ($first===false)return $matchObject;
  373. if (!$first)return $first;
  374. if (is_array($first))$first = reset($first);
  375. if ($nextObj && is_array($first[$nextObj])){
  376. $result = [];
  377. foreach ($matchObject[$need] as $arr)$result = array_merge($result,$arr[$nextObj]);
  378. return $this->resetChildNodeMapping($result,$columnMapping);
  379. }
  380. return $matchObject[$need];
  381. }
  382. /**
  383. * 匹配子策略
  384. *
  385. * @param Model|\stdClass $obj 策略对象
  386. * @param array $columnMapping 映射对象
  387. * @param Model $matchObject 被匹配对象
  388. * @param array $units 单位集
  389. * @param integer $ownerId 货主ID
  390. * @param bool|array $result 满减信息
  391. *
  392. * @return double
  393. */
  394. private function matchItem($obj, $columnMapping, $matchObject, $units, $ownerId, $result)
  395. {
  396. $matchObject = $this->resetChildNodeMapping($matchObject->toArray(),$columnMapping);
  397. if (!$matchObject)return -1;
  398. $total = 0; //商品总数
  399. foreach ($matchObject as $commodity)$total += $commodity[$columnMapping[8]]; //取对象内商品数量总数将其当作子属性插入原对象
  400. $surcharge = 0;
  401. $unitName = "";
  402. if ($obj->surcharge_unit_id && $obj->surcharge && isset($units[$rule->surcharge_unit_id])){
  403. if ($units[$obj->surcharge_unit_id] == '件')$surcharge += $obj->surcharge*$total;
  404. else $surcharge += $obj->surcharge;
  405. }//耗材附加费
  406. foreach ($obj->items as $rule){
  407. if ($result)$rule->unit_price = explode(",",$rule->discount_price)[key($result)]; //满足满减条件,单价调整为满减单价
  408. if ($rule->strategy=='起步'){
  409. $money = $rule->unit_price;
  410. $startNumber = $rule->amount;
  411. if ($unitName && $startNumber && $unitName != $units[$rule->unit_id])return -3; //校验单位是否一致
  412. if ($startNumber)$matchObject=$this->settingCount($matchObject,$columnMapping[8],$startNumber);
  413. if ($matchObject)foreach ($matchObject as $package)$money += $package[$columnMapping[8]] * $package["price"];
  414. if (!$startNumber && $money<$rule->unit_price)$money = $rule->unit_price;
  415. return $money+$surcharge;
  416. }
  417. foreach ($matchObject as &$package){
  418. if ($package["price"] ?? false)continue;
  419. if (!isset($units[$rule->unit_id]))return -3;
  420. if (!$unitName)$unitName = $units[$rule->unit_id];
  421. else if ($unitName != $units[$rule->unit_id]) return -3;
  422. if ($rule->strategy=='特征'){
  423. $package[$columnMapping[10]] = $total; //设置一个不存在的总数进入原对象
  424. if (!app("FeatureService")->matchFeature($rule->feature,$columnMapping,$package)) continue;
  425. }
  426. $package["price"] = $rule->unit_price;
  427. }
  428. if ($units[$rule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
  429. $amount = 0;
  430. foreach ($matchObject as $commodity){
  431. $pack = $this->changeUnit($ownerId,$commodity[$columnMapping[9]]);
  432. if ($rule->odd_price){
  433. $amount += floor($amount/$pack);
  434. $surcharge += $rule->odd_price * ($amount%$pack); //零头附加费
  435. }else$amount += ceil($amount/$pack);
  436. }
  437. if ($amount<0)return $amount;
  438. $package[$columnMapping[8]] = $amount;
  439. }
  440. }
  441. if ($matchObject){
  442. $money = $surcharge;
  443. foreach ($matchObject as $package)if ($package["price"])$money += $package[$columnMapping[8]] * $package["price"];
  444. }
  445. return $money ?? -7;
  446. }
  447. //递归式重新设置数量
  448. private function settingCount($packages,$amountColumn,$startNumber)
  449. {
  450. if (!$packages) return null;
  451. $maxPrice = 0;
  452. $index = null;
  453. foreach ($packages as $i => $package){
  454. if ($package[$amountColumn] <= 0){
  455. unset($packages[$i]);continue;
  456. }
  457. if ($package["price"] > $maxPrice || ($package["price"]==0 && $maxPrice==0)){
  458. $maxPrice = $package["price"];
  459. $index = $i;
  460. }
  461. }
  462. if ($packages[$index][$amountColumn] >= $startNumber){
  463. $packages[$index][$amountColumn] -= $startNumber;
  464. return $packages;
  465. }else{
  466. $startNumber -= $packages[$index][$amountColumn];
  467. unset($packages[$index]);
  468. $this->settingCount($packages,$amountColumn,$startNumber);
  469. }
  470. }
  471. /**
  472. * 处理历史账单
  473. *
  474. * @param object $rule
  475. * @param int $owner
  476. * @param int $discountIndex
  477. * @param object $pivot
  478. */
  479. public function handlePastBill($rule, $owner, $discountIndex, $pivot)
  480. {
  481. try{
  482. DB::beginTransaction();
  483. $month = date("Y-m");
  484. $day = date("t",strtotime($month));
  485. $units = app("UnitService")->getUnitMapping(["件","箱"]); //获取单位映射集
  486. foreach (OwnerFeeDetail::query()->with(["order.logistic","order.shop","order.packages.commodities.commodity","order.batch"])
  487. ->where("owner_id",$owner)
  488. ->whereBetween("worked_at",[$month."-01",$month."-".$day])->get() as $detail){
  489. $order = $detail->order;
  490. $logistic_fee = 0;
  491. if ($logistic_fee!==null && $logistic_fee<0)$logistic_fee = null;
  492. $money = $this->matchItem($rule,Feature::MAPPING["order"],$order,$units,$owner,[$discountIndex=>true]);
  493. if ($money>0)$detail->update(["work_fee"=>$money]);
  494. else LogService::log(__CLASS__,"处理历史即时账单时发生匹配错误","账单主键:".$detail->id."; 错误代码".$money);
  495. };
  496. DB::commit();
  497. }catch (\Exception $e){
  498. DB::rollBack();
  499. //处理失败回退标记
  500. DB::update(DB::raw("UPDATE owner_price_operation_owner SET discount_date = ?,target_value = ? WHERE owner_price_operation_id = ? AND owner_id = ?"),
  501. [$pivot->discount_date,$pivot->target_value,$rule->id,$owner]);
  502. LogService::log(__CLASS__,"处理历史即时账单时发生系统错误","计费模型主键:".$rule->id."; 错误信息".$e->getMessage());
  503. }
  504. }
  505. }