ServiceOrderLogic.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. <?php
  2. namespace app\api\logic;
  3. use app\common\enum\GoodsEnum;
  4. use app\common\enum\PayEnum;
  5. use app\common\enum\WorkEnum;
  6. use app\common\logic\BaseLogic;
  7. use app\common\model\coupon\UserCoupon;
  8. use app\common\model\dict\DictData;
  9. use app\common\model\goods\Goods;
  10. use app\common\model\master_worker\MasterWorker;
  11. use app\common\model\orders\RechargeOrder;
  12. use app\common\model\recharge\OrderGoods;
  13. use app\common\model\works\ServiceWork;
  14. use app\workerapi\logic\ServiceWorkLogLogic;
  15. use think\Exception;
  16. use think\facade\Db;
  17. /**
  18. * 订单逻辑层
  19. * Class ServiceOrderLogic
  20. * @package app\api\logic
  21. */
  22. class ServiceOrderLogic extends BaseLogic
  23. {
  24. /**
  25. * 提交订单
  26. * @param array $params
  27. * @return array|false
  28. */
  29. public static function submitOrder($params)
  30. {
  31. Db::startTrans();
  32. try {
  33. $goods = Goods::findOrEmpty($params['goods_id']);
  34. if($goods->isEmpty()){
  35. throw new Exception('产品不存在!');
  36. }
  37. if(empty($params['user_info']['mobile'])){
  38. throw new Exception('请先补充您的联系方式后在提交订单');
  39. }
  40. //根据服务工单计算当前订单应支付金额
  41. if($goods['goods_payment_type'] == GoodsEnum::ISGOODS_PAYMENT_TYPE){
  42. //一口价订单
  43. $order_total = $goods['service_fee'];
  44. $order_amount = $goods['service_fee'];
  45. }else{
  46. $order_total = $goods['base_service_fee'];
  47. $order_amount = $goods['service_fee'];
  48. }
  49. //优惠券验证
  50. if(!empty($params['coupon_id'])){
  51. $user_coupon = UserCoupon::where(['id'=>$params['coupon_id'],'user_id'=>$params['user_id'],'voucher_status'=>0])
  52. ->where('voucher_count','>',0)
  53. ->where('expire_time','>=',time())
  54. ->where('begin_use','<',time())
  55. ->findOrEmpty();
  56. if($user_coupon->isEmpty()){
  57. throw new Exception('该优惠券无法使用');
  58. }
  59. if($goods['goods_payment_type'] == GoodsEnum::ISGOODS_PAYMENT_TYPE and $order_amount<$user_coupon['amount_require']){
  60. throw new Exception('该优惠劵不满足满减使用条件');
  61. }
  62. if($goods['goods_payment_type'] != GoodsEnum::ISGOODS_PAYMENT_TYPE){
  63. throw new Exception('请在支付尾款的时候使用该优惠券');
  64. }
  65. //优惠券折扣
  66. if($user_coupon['mold_type'] == 1){
  67. //按比例折扣
  68. if($user_coupon['discount_ratio']>=1){
  69. throw new Exception('优惠券有误,请联系客服');
  70. }
  71. $order_coupon_amount = intval($order_amount*(1-$user_coupon['discount_ratio']));
  72. }else{
  73. $order_coupon_amount = $user_coupon['amount'];
  74. }
  75. if(!empty($user_coupon['max_deductible_price'])){
  76. $order_amount = ($order_coupon_amount>$user_coupon['max_deductible_price'])?($order_amount-$user_coupon['max_deductible_price']):($order_amount-$order_coupon_amount);
  77. }else{
  78. $order_amount = $order_amount-$order_coupon_amount;
  79. }
  80. $user_coupon->voucher_status = 1;
  81. $user_coupon->voucher_count = $user_coupon->voucher_count-1;
  82. $user_coupon->save();
  83. }
  84. //生成服务工单
  85. $work_data = [
  86. 'work_sn' => generate_sn(ServiceWork::class, 'work_sn'),
  87. 'real_name' => $params['contact_people'],
  88. 'mobile' => $params['contact_number'],
  89. 'address' => $params['address'],
  90. 'title' => $goods->goods_name . '*' . $goods->goods_number.$goods->good_unit,
  91. 'category_type' => $goods['category_type'],
  92. 'goods_category_ids' => $goods['goods_category_ids'],
  93. 'goods_category_id' => $goods['goods_category_id'],
  94. 'base_service_fee' => $goods['base_service_fee'],
  95. 'service_fee' => $goods['service_fee'],
  96. 'work_pay_status'=>WorkEnum::UN_PAY_STATUS,
  97. 'appointment_time' => strtotime($params['appointment_time']),
  98. 'user_id'=>$params['user_id'],
  99. 'lon'=>!empty($params['lon'])?$params['lon']:0,
  100. 'lat'=>!empty($params['lat'])?$params['lat']:0,
  101. ];
  102. //判断是否是加单
  103. if(!empty($params['worker'])){
  104. $worker_id = MasterWorker::where('worker_number',$params['worker'])->value('id');
  105. $work_data['master_worker_id'] = $worker_id;
  106. $work_data['work_status'] = 1;
  107. $work_data['dispatch_time'] = time();
  108. $work_data['work_type'] = 2;
  109. }
  110. $service_work = ServiceWork::create($work_data);
  111. //生成服务订单
  112. $data = [
  113. 'work_id'=> $service_work['id'],
  114. 'sn' => generate_sn(RechargeOrder::class, 'sn'),
  115. 'order_type'=>0,//服务订单
  116. 'order_terminal' => $params['terminal'],
  117. 'payment_type'=>$goods['goods_payment_type']==1?1:0,
  118. 'user_id' => $params['user_id'],
  119. 'pay_status' => PayEnum::UNPAID,
  120. 'coupon_id'=>!empty($params['coupon_id'])?$params['coupon_id']:0,
  121. 'coupon_price'=>!empty($order_coupon_amount)?$order_coupon_amount:0,
  122. 'pay_way' => $params['pay_way'],
  123. 'order_total' => $order_total,
  124. 'order_amount' => $order_amount,
  125. ];
  126. $order = RechargeOrder::create($data);
  127. //生成订单服务详情
  128. OrderGoods::create([
  129. 'sn' => $order['sn'],
  130. 'goods_id' => $params['goods_id'],
  131. 'category_type' => $goods['category_type'],
  132. 'goods_category_ids' => $goods['goods_category_ids'],
  133. 'goods_category_id' => $goods['goods_category_id'],
  134. 'goods_name' => $goods['goods_name'],
  135. 'goods_image' => $goods['goods_image'],
  136. 'goods_video' => $goods['goods_video'],
  137. 'goods_number' => $goods['goods_number'],
  138. 'good_unit' => $goods['good_unit'],
  139. 'goods_size' => $goods['goods_size'],
  140. 'goods_type' => $goods['goods_type'],
  141. 'goods_brand' => $goods['goods_brand'],
  142. 'install_guide' => $goods['install_guide'],
  143. 'goods_payment_type'=>$goods['goods_payment_type'],
  144. 'base_service_fee' => $goods['base_service_fee'],
  145. 'service_total' => $goods['service_total'],
  146. 'service_fee' => $goods['service_fee'],
  147. 'service_image' => $goods['service_image'],
  148. 'warranty_period'=>$goods['warranty_period'],
  149. 'fee_schedule' => $goods['fee_schedule'],
  150. 'goods_status' => $goods['goods_status'],
  151. ]);
  152. Db::commit();
  153. } catch (\Exception $e) {
  154. self::setError($e->getMessage());
  155. return false;
  156. }
  157. return [
  158. 'order_id' => (int)$order['id'],
  159. ];
  160. }
  161. /**
  162. * 获取订单工程师信息
  163. * * @param $params
  164. * * @return array|false
  165. */
  166. public static function getMasterWorker($params)
  167. {
  168. try {
  169. $order_info = \app\common\model\recharge\RechargeOrder::with(['order_goods'=>function ($query) {
  170. $query->visible(['goods_name','goods_image','goods_number','good_unit']);
  171. },'service_work'=>function ($query) {
  172. $query->visible(['real_name','mobile','address','service_status','appointment_time','master_worker_id','work_images','finished_images','finished_time'])->append(['service_status_text','user_service_status','user_service_status_text']);
  173. }])
  174. ->visible(['id','sn','payment_type','order_total','order_amount','pay_status','create_time','title','work_id'])
  175. ->where([
  176. 'order_type' => 0,
  177. 'user_id' => $params['user_id'],
  178. 'sn'=>$params['sn']
  179. ])->findOrEmpty()->toArray();
  180. $data = [];
  181. //获取师傅参数
  182. if(!empty($order_info['service_work']['master_worker_id'])){
  183. $worker = MasterWorker::find($order_info['service_work']['master_worker_id']);
  184. $data['avatar'] = $worker['avatar'];
  185. $data['real_name'] = $worker['real_name'];
  186. $data['worker_number'] = $worker['worker_number'];
  187. $data['mobile'] = $worker['mobile'];
  188. $maintain_exp_type = !empty($worker->worker_register->maintain_exp_type)?$worker->worker_register->maintain_exp_type:'';
  189. $data['worker_exp'] = DictData::where(['type_value'=>'worker_exp_type','value'=>$maintain_exp_type])->value('name');
  190. $data['appointment_time'] = $order_info['service_work']['appointment_time'];
  191. }
  192. return $data;
  193. }
  194. catch (\Exception $e) {
  195. self::setError($e->getMessage());
  196. return false;
  197. }
  198. }
  199. /**
  200. * 获取订单详情
  201. * @param $params
  202. * @return array|false
  203. */
  204. public static function detail($params)
  205. {
  206. try {
  207. $order_info = \app\common\model\recharge\RechargeOrder::with(['order_goods'=>function ($query) {
  208. $query->visible(['goods_name','goods_image','goods_number','good_unit']);
  209. },'service_work'=>function ($query) {
  210. $query->visible(['real_name','mobile','address','service_status','appointment_time','master_worker_id','work_images','finished_images','finished_time'])->append(['service_status_text','user_service_status','user_service_status_text']);
  211. }])
  212. ->visible(['id','sn','payment_type','order_total','order_amount','paid_amount','pay_status','create_time','title','work_id'])
  213. ->where([
  214. 'order_type' => 0,
  215. 'user_id' => $params['user_id'],
  216. 'sn'=>$params['sn']
  217. ])->findOrEmpty()->toArray();
  218. $order_info['master_worker'] = [
  219. 'avatar' => '',
  220. 'real_name'=>'',
  221. 'worker_number'=>'',
  222. 'mobile'=>'',
  223. 'worker_exp'=>''
  224. ];
  225. if(empty($order_info)){
  226. throw new Exception('订单不存在');
  227. }
  228. //查询总价
  229. $order_info['order_amount'] = \app\common\model\recharge\RechargeOrder::where(['order_type'=>0,'user_id'=>$params['user_id'],'work_id'=>$order_info['work_id']])->sum('order_amount');
  230. $order_info['paid_amount'] = \app\common\model\recharge\RechargeOrder::where(['order_type'=>0,'user_id'=>$params['user_id'],'work_id'=>$order_info['work_id']])->sum('paid_amount');
  231. //获取师傅参数
  232. if(!empty($order_info['service_work']['master_worker_id'])){
  233. $worker = MasterWorker::find($order_info['service_work']['master_worker_id']);
  234. $order_info['master_worker']['avatar'] = $worker['avatar'];
  235. $order_info['master_worker']['real_name'] = $worker['real_name'];
  236. $order_info['master_worker']['worker_number'] = $worker['worker_number'];
  237. $order_info['master_worker']['mobile'] = $worker['mobile'];
  238. $maintain_exp_type = !empty($worker->worker_register->maintain_exp_type)?$worker->worker_register->maintain_exp_type:'';
  239. $order_info['master_worker']['worker_exp'] = DictData::where(['type_value'=>'worker_exp_type','value'=>$maintain_exp_type])->value('name');
  240. }
  241. //搜索当前工单下的所有订单记录
  242. $order_info['pay_orders'] = \app\common\model\recharge\RechargeOrder::where(['work_id'=>$order_info['work_id']])->field('id as order_id, pay_status,payment_type,pay_way,pay_time,order_amount,coupon_price')->order('id asc')->select()->toArray();
  243. $pay_status_data = DictData::where('type_value','pay_status')->column('name','value');
  244. $payment_type_data = DictData::where('type_value','payment_type')->column('name','value');
  245. $pay_way_data = DictData::where('type_value','pay_way')->column('name','value');
  246. $coupon_price = 0;
  247. foreach ($order_info['pay_orders'] as $k=>&$v){
  248. $v['pay_status_name'] = $pay_status_data[$v['pay_status']];
  249. $v['payment_type_name'] = $payment_type_data[$v['payment_type']];
  250. $v['pay_way_name'] = $pay_way_data[$v['pay_way']];
  251. $coupon_price += $v['coupon_price'];
  252. }
  253. //汇总优惠卷额度
  254. $order_info['coupon_price'] = $coupon_price;
  255. return $order_info;
  256. }
  257. catch (\Exception $e) {
  258. self::setError($e->getMessage());
  259. return false;
  260. }
  261. }
  262. /**
  263. * 取消订单
  264. * @param $params
  265. * @return false|void
  266. */
  267. public static function cancelOrder($params)
  268. {
  269. Db::startTrans();
  270. try {
  271. $work_id = \app\common\model\recharge\RechargeOrder::where([
  272. 'order_type' => 0,
  273. 'user_id' => $params['user_id'],
  274. 'sn'=>$params['sn']
  275. ])->value('work_id');
  276. if(empty($work_id)){
  277. throw new Exception('订单不存在');
  278. }
  279. $payed_order = \app\common\model\recharge\RechargeOrder::where(['user_id'=>$params['user_id'],'work_id'=>$work_id,'pay_status'=>1])->findOrEmpty();
  280. if(!$payed_order->isEmpty()){
  281. throw new Exception('存在已支付订单,不允许取消订单,请联系客服');
  282. }
  283. //软删除订单
  284. $cancel_order = \app\common\model\recharge\RechargeOrder::where(['user_id'=>$params['user_id'],'work_id'=>$work_id])->findOrEmpty();
  285. $cancel_order->pay_status = 2;
  286. $cancel_order->save();
  287. //更新工单状态为已取消
  288. $service_work = ServiceWork::find($work_id);
  289. $service_work->service_status = 4;
  290. $service_work->save();
  291. //判断如果存在优惠券,返还优惠券
  292. if(!empty($payed_order->coupon_id)){
  293. $user_coupon = UserCoupon::where(['user_id'=>$payed_order->user_id,'id'=>$payed_order->coupon_id])->findOrEmpty();
  294. $user_coupon->voucher_status = 0;
  295. $user_coupon->voucher_count = $user_coupon->voucher_count+1;
  296. $user_coupon->save();
  297. }
  298. Db::commit();
  299. }
  300. catch (\Exception $e) {
  301. self::setError($e->getMessage());
  302. return false;
  303. }
  304. }
  305. /**
  306. * 用户确认尾款报价单
  307. * @param $params
  308. * @return false|void
  309. */
  310. public static function confirmOrder($params)
  311. {
  312. Db::startTrans();
  313. try {
  314. $work_id = \app\common\model\recharge\RechargeOrder::where([
  315. 'order_type' => 0,
  316. 'user_id' => $params['user_id'],
  317. 'sn'=>$params['sn']
  318. ])->value('work_id');
  319. if(empty($work_id)){
  320. throw new Exception('订单不存在');
  321. }
  322. //更新工单状态为已取消
  323. $service_work = ServiceWork::find($work_id);
  324. if($service_work->user_confirm_status==2){
  325. throw new Exception('请勿重复操作');
  326. }
  327. $service_work->work_status = 5;
  328. $service_work->user_confirm_status = 2;
  329. $service_work->save();
  330. $work_log = [
  331. 'work_id'=>$work_id,
  332. 'master_worker_id'=>$service_work->master_worker_id,
  333. 'opera_log'=>'用户'.$params['user_info']['real_name'].'于'.date('y-m-d H:i:s',time()).'于'.date('Y-m-d H:i:s',time()).'确认了报价单',
  334. ];
  335. ServiceWorkLogLogic::add($work_log);
  336. Db::commit();
  337. }
  338. catch (\Exception $e) {
  339. self::setError($e->getMessage());
  340. return false;
  341. }
  342. }
  343. /**
  344. * 用户确认服务完成
  345. * @param $params
  346. * @return false|void
  347. */
  348. public static function confirmServiceFinish($params)
  349. {
  350. Db::startTrans();
  351. try {
  352. $work_id = \app\common\model\recharge\RechargeOrder::where([
  353. 'order_type' => 0,
  354. 'user_id' => $params['user_id'],
  355. 'sn'=>$params['sn']
  356. ])->value('work_id');
  357. if(empty($work_id)){
  358. throw new Exception('订单不存在');
  359. }
  360. $service_work = ServiceWork::find($work_id);
  361. if($service_work->user_confirm_status!=3){
  362. throw new Exception('请勿重复操作');
  363. }
  364. $orders = RechargeOrder::where(['work_id'=>$work_id,'user_id'=>$params['user_id']])->select()->toArray();
  365. //确认所有订单总金额和结算金额
  366. //若订单是全款已支付订单
  367. if(count($orders)==1 and $orders[0]['payment_type']==0 and $orders[0]['pay_status']==1){
  368. $service_work->work_status = 7;
  369. $service_work->user_confirm_status = 5;
  370. $service_work->service_status = 3;
  371. $service_work->work_pay_status = 1;
  372. $service_work->work_total = $orders[0]['order_total'];
  373. $service_work->work_amount = $orders[0]['order_amount'];
  374. }else{
  375. $service_work->work_status = 6;
  376. $service_work->user_confirm_status = 4;
  377. $order_total = 0;
  378. foreach ($orders as $k=>$v){
  379. $order_total += $v['order_total'];
  380. }
  381. $service_work->work_total = $order_total;
  382. }
  383. $service_work->finished_time = time();
  384. $service_work->save();
  385. //更新师傅的进行工单数量
  386. MasterWorker::setWorktotal('dec',$service_work->master_worker_id);
  387. $work_log = [
  388. 'work_id'=>$work_id,
  389. 'master_worker_id'=>$service_work->master_worker_id,
  390. 'opera_log'=>'用户'.$params['user_info']['real_name'].'于'.date('y-m-d H:i:s',time()).'于'.date('Y-m-d H:i:s',time()).'确认服务完成',
  391. ];
  392. ServiceWorkLogLogic::add($work_log);
  393. Db::commit();
  394. }
  395. catch (\Exception $e) {
  396. self::setError($e->getMessage());
  397. return false;
  398. }
  399. }
  400. public static function firmOrderSave($params)
  401. {
  402. Db::startTrans();
  403. try {
  404. $goodIds = array_column($params['order_goods'],'id');
  405. $goodInfo = Goods::whereIn('id',$goodIds)->select();
  406. $ids = $goodInfo->column('id');
  407. if(!empty(array_diff($goodIds,$ids))){
  408. throw new Exception('产品不存在!');
  409. }
  410. if(empty($params['user_info']['mobile'])){
  411. throw new Exception('请先补充您的联系方式后在提交订单');
  412. }
  413. $order_amount = 0;
  414. $order_total = 0;
  415. $orderGoodsData = [];
  416. $goodsPaymentTypeArr = [];
  417. //计算订单总金额和结算金额
  418. foreach($params['order_goods'] as $val){
  419. $goods = $goodInfo->where('id',$val['id'])->toArray()[0];
  420. //根据服务工单计算当前订单应支付金额
  421. $order_total = $goods['service_total'];
  422. if($goods['goods_payment_type'] == GoodsEnum::ISGOODS_PAYMENT_TYPE){
  423. //一口价订单
  424. $order_amount = $goods['service_fee']*$val['goods_number'];
  425. }else{
  426. $order_total = $goods['base_service_fee']*$val['goods_number'];
  427. $order_amount = $goods['service_fee']*$val['goods_number'];
  428. }
  429. $goodsPaymentTypeArr[] = $goods['goods_payment_type'];
  430. $orderGoodsData[] = [
  431. 'goods_id' => $goods['id'],
  432. 'category_type' => $goods['category_type'],
  433. 'goods_category_ids' => $goods['goods_category_ids'],
  434. 'goods_category_id' => $goods['goods_category_id'],
  435. 'goods_name' => $goods['goods_name'],
  436. 'goods_image' => $goods['goods_image'],
  437. 'goods_video' => $goods['goods_video'],
  438. 'goods_number' => $val['goods_number'],
  439. 'good_unit' => $goods['good_unit'],
  440. 'goods_size' => $goods['goods_size'],
  441. 'goods_type' => $goods['goods_type'],
  442. 'goods_brand' => $goods['goods_brand'],
  443. 'install_guide' => $goods['install_guide'],
  444. 'goods_payment_type'=>$goods['goods_payment_type'],
  445. 'base_service_fee' => $goods['base_service_fee'],
  446. 'service_total' => $goods['service_total'],
  447. 'service_fee' => $goods['service_fee'],
  448. 'service_image' => $goods['service_image'],
  449. 'warranty_period'=>$goods['warranty_period'],
  450. 'fee_schedule' => $goods['fee_schedule'],
  451. 'goods_status' => $goods['goods_status'],
  452. ];
  453. }
  454. if(count(array_unique($goodsPaymentTypeArr))>1){
  455. throw new Exception('订单中存在多种支付方式');
  456. }
  457. //生成服务工单
  458. $work_data = [
  459. 'work_sn' => generate_sn(ServiceWork::class, 'work_sn'),
  460. 'real_name' => $params['contact_people'],
  461. 'mobile' => $params['contact_number'],
  462. 'address' => $params['address'],
  463. 'title' => $goods['goods_name'] . '*' .$val['goods_number'].$goods['good_unit'],
  464. 'category_type' => $goods['category_type'],
  465. 'goods_category_ids' => $goods['goods_category_ids'],
  466. 'goods_category_id' => $goods['goods_category_id'],
  467. 'base_service_fee' => $goods['base_service_fee'],
  468. 'service_fee' => $goods['service_fee'],
  469. 'work_pay_status'=>WorkEnum::UN_PAY_STATUS,
  470. 'appointment_time' => strtotime($params['appointment_time']),
  471. 'user_id' => $params['user_id'],
  472. 'work_type' => 1,
  473. ];
  474. $service_work = ServiceWork::create($work_data);
  475. //生成服务订单
  476. $data = [
  477. 'work_id'=> $service_work['id'],
  478. 'sn' => generate_sn(RechargeOrder::class, 'sn'),
  479. 'order_type'=>0,//服务订单
  480. 'order_terminal' => $params['terminal'],
  481. 'payment_type'=>$goods['goods_payment_type']==1?1:0,
  482. 'user_id' => $params['user_id'],
  483. 'pay_status' => PayEnum::UNPAID,
  484. 'coupon_id'=>!empty($params['coupon_id'])?$params['coupon_id']:0,
  485. 'coupon_price'=>!empty($order_coupon_amount)?$order_coupon_amount:0,
  486. 'pay_way' => $params['pay_way'],
  487. 'order_total' => $order_total,
  488. 'order_amount' => $order_amount,
  489. ];
  490. $order = RechargeOrder::create($data);
  491. array_walk($orderGoodsData, function (&$value, $key, $data) {
  492. $value = array_merge($value, ['sn' => $data['sn']]);
  493. },$data);
  494. dd($orderGoodsData);
  495. $orderGoodsModel = new OrderGoods();
  496. $orderGoodsModel->saveAll($orderGoodsData);
  497. Db::commit();
  498. return [
  499. 'order_id' => (int)$order['id'],
  500. ];
  501. } catch (\Exception $e) {
  502. Db::rollback();
  503. self::setError($e->getMessage());
  504. return false;
  505. }
  506. }
  507. }