ServiceOrderLogic.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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. 'work_id' => (int)$order['work_id'],
  160. ];
  161. }
  162. /**
  163. * 获取订单工程师信息
  164. * * @param $params
  165. * * @return array|false
  166. */
  167. public static function getMasterWorker($params)
  168. {
  169. try {
  170. $order_info = \app\common\model\recharge\RechargeOrder::with(['order_goods'=>function ($query) {
  171. $query->visible(['goods_name','goods_image','goods_number','good_unit']);
  172. },'service_work'=>function ($query) {
  173. $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']);
  174. }])
  175. ->visible(['id','sn','payment_type','order_total','order_amount','pay_status','create_time','title','work_id'])
  176. ->where([
  177. 'order_type' => 0,
  178. 'user_id' => $params['user_id'],
  179. 'sn'=>$params['sn']
  180. ])->findOrEmpty()->toArray();
  181. $data = [];
  182. //获取师傅参数
  183. if(!empty($order_info['service_work']['master_worker_id'])){
  184. $worker = MasterWorker::find($order_info['service_work']['master_worker_id']);
  185. $data['avatar'] = $worker['avatar'];
  186. $data['real_name'] = $worker['real_name'];
  187. $data['worker_number'] = $worker['worker_number'];
  188. $data['mobile'] = $worker['mobile'];
  189. $maintain_exp_type = !empty($worker->worker_register->maintain_exp_type)?$worker->worker_register->maintain_exp_type:'';
  190. $data['worker_exp'] = DictData::where(['type_value'=>'worker_exp_type','value'=>$maintain_exp_type])->value('name');
  191. $data['appointment_time'] = $order_info['service_work']['appointment_time'];
  192. }
  193. return $data;
  194. }
  195. catch (\Exception $e) {
  196. self::setError($e->getMessage());
  197. return false;
  198. }
  199. }
  200. /**
  201. * 获取订单详情
  202. * @param $params
  203. * @return array|false
  204. */
  205. public static function detail($params)
  206. {
  207. try {
  208. $order_info = \app\common\model\recharge\RechargeOrder::with(['order_goods'=>function ($query) {
  209. $query->visible(['goods_name','goods_image','goods_number','good_unit']);
  210. },'service_work'=>function ($query) {
  211. $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']);
  212. }])
  213. ->visible(['id','sn','payment_type','order_total','order_amount','paid_amount','pay_status','create_time','title','work_id'])
  214. ->where([
  215. 'order_type' => 0,
  216. 'user_id' => $params['user_id'],
  217. 'sn'=>$params['sn']
  218. ])->findOrEmpty()->toArray();
  219. $order_info['master_worker'] = [
  220. 'avatar' => '',
  221. 'real_name'=>'',
  222. 'worker_number'=>'',
  223. 'mobile'=>'',
  224. 'worker_exp'=>''
  225. ];
  226. if(empty($order_info)){
  227. throw new Exception('订单不存在');
  228. }
  229. //查询总价
  230. $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');
  231. $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');
  232. //获取师傅参数
  233. if(!empty($order_info['service_work']['master_worker_id'])){
  234. $worker = MasterWorker::find($order_info['service_work']['master_worker_id']);
  235. $order_info['master_worker']['avatar'] = $worker['avatar'];
  236. $order_info['master_worker']['real_name'] = $worker['real_name'];
  237. $order_info['master_worker']['worker_number'] = $worker['worker_number'];
  238. $order_info['master_worker']['mobile'] = $worker['mobile'];
  239. $maintain_exp_type = !empty($worker->worker_register->maintain_exp_type)?$worker->worker_register->maintain_exp_type:'';
  240. $order_info['master_worker']['worker_exp'] = DictData::where(['type_value'=>'worker_exp_type','value'=>$maintain_exp_type])->value('name');
  241. }
  242. //搜索当前工单下的所有订单记录
  243. $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();
  244. $pay_status_data = DictData::where('type_value','pay_status')->column('name','value');
  245. $payment_type_data = DictData::where('type_value','payment_type')->column('name','value');
  246. $pay_way_data = DictData::where('type_value','pay_way')->column('name','value');
  247. $coupon_price = 0;
  248. foreach ($order_info['pay_orders'] as $k=>&$v){
  249. $v['pay_status_name'] = $pay_status_data[$v['pay_status']];
  250. $v['payment_type_name'] = $payment_type_data[$v['payment_type']];
  251. $v['pay_way_name'] = $pay_way_data[$v['pay_way']];
  252. $coupon_price += $v['coupon_price'];
  253. }
  254. //汇总优惠卷额度
  255. $order_info['coupon_price'] = $coupon_price;
  256. return $order_info;
  257. }
  258. catch (\Exception $e) {
  259. self::setError($e->getMessage());
  260. return false;
  261. }
  262. }
  263. /**
  264. * 取消订单
  265. * @param $params
  266. * @return false|void
  267. */
  268. public static function cancelOrder($params)
  269. {
  270. Db::startTrans();
  271. try {
  272. $work_id = \app\common\model\recharge\RechargeOrder::where([
  273. 'order_type' => 0,
  274. 'user_id' => $params['user_id'],
  275. 'sn'=>$params['sn']
  276. ])->value('work_id');
  277. if(empty($work_id)){
  278. throw new Exception('订单不存在');
  279. }
  280. $payed_order = \app\common\model\recharge\RechargeOrder::where(['user_id'=>$params['user_id'],'work_id'=>$work_id,'pay_status'=>1])->findOrEmpty();
  281. if(!$payed_order->isEmpty()){
  282. throw new Exception('存在已支付订单,不允许取消订单,请联系客服');
  283. }
  284. //软删除订单
  285. $cancel_order = \app\common\model\recharge\RechargeOrder::where(['user_id'=>$params['user_id'],'work_id'=>$work_id])->findOrEmpty();
  286. $cancel_order->pay_status = 2;
  287. $cancel_order->save();
  288. //更新工单状态为已取消
  289. $service_work = ServiceWork::find($work_id);
  290. $service_work->service_status = 4;
  291. $service_work->save();
  292. //判断如果存在优惠券,返还优惠券
  293. if(!empty($payed_order->coupon_id)){
  294. $user_coupon = UserCoupon::where(['user_id'=>$payed_order->user_id,'id'=>$payed_order->coupon_id])->findOrEmpty();
  295. $user_coupon->voucher_status = 0;
  296. $user_coupon->voucher_count = $user_coupon->voucher_count+1;
  297. $user_coupon->save();
  298. }
  299. Db::commit();
  300. }
  301. catch (\Exception $e) {
  302. self::setError($e->getMessage());
  303. return false;
  304. }
  305. }
  306. /**
  307. * 用户确认尾款报价单
  308. * @param $params
  309. * @return false|void
  310. */
  311. public static function confirmOrder($params)
  312. {
  313. Db::startTrans();
  314. try {
  315. $work_id = \app\common\model\recharge\RechargeOrder::where([
  316. 'order_type' => 0,
  317. 'user_id' => $params['user_id'],
  318. 'sn'=>$params['sn']
  319. ])->value('work_id');
  320. if(empty($work_id)){
  321. throw new Exception('订单不存在');
  322. }
  323. //更新工单状态为已取消
  324. $service_work = ServiceWork::find($work_id);
  325. if($service_work->user_confirm_status==2){
  326. throw new Exception('请勿重复操作');
  327. }
  328. $service_work->work_status = 5;
  329. $service_work->user_confirm_status = 2;
  330. $service_work->save();
  331. $work_log = [
  332. 'work_id'=>$work_id,
  333. 'master_worker_id'=>$service_work->master_worker_id,
  334. 'opera_log'=>'用户'.$params['user_info']['real_name'].'于'.date('y-m-d H:i:s',time()).'于'.date('Y-m-d H:i:s',time()).'确认了报价单',
  335. ];
  336. ServiceWorkLogLogic::add($work_log);
  337. Db::commit();
  338. }
  339. catch (\Exception $e) {
  340. self::setError($e->getMessage());
  341. return false;
  342. }
  343. }
  344. /**
  345. * 用户确认服务完成
  346. * @param $params
  347. * @return false|void
  348. */
  349. public static function confirmServiceFinish($params)
  350. {
  351. Db::startTrans();
  352. try {
  353. $work_id = \app\common\model\recharge\RechargeOrder::where([
  354. 'order_type' => 0,
  355. 'user_id' => $params['user_id'],
  356. 'sn'=>$params['sn']
  357. ])->value('work_id');
  358. if(empty($work_id)){
  359. throw new Exception('订单不存在');
  360. }
  361. $service_work = ServiceWork::find($work_id);
  362. if($service_work->user_confirm_status!=3){
  363. throw new Exception('请勿重复操作');
  364. }
  365. $orders = RechargeOrder::where(['work_id'=>$work_id,'user_id'=>$params['user_id']])->select()->toArray();
  366. //确认所有订单总金额和结算金额
  367. //若订单是全款已支付订单
  368. if(count($orders)==1 and $orders[0]['payment_type']==0 and $orders[0]['pay_status']==1){
  369. $service_work->work_status = 7;
  370. $service_work->user_confirm_status = 5;
  371. $service_work->service_status = 3;
  372. $service_work->work_pay_status = 1;
  373. $service_work->work_total = $orders[0]['order_total'];
  374. $service_work->work_amount = $orders[0]['order_amount'];
  375. }else{
  376. $service_work->work_status = 6;
  377. $service_work->user_confirm_status = 4;
  378. $order_total = 0;
  379. foreach ($orders as $k=>$v){
  380. $order_total += $v['order_total'];
  381. }
  382. $service_work->work_total = $order_total;
  383. }
  384. $service_work->finished_time = time();
  385. $service_work->save();
  386. //更新师傅的进行工单数量
  387. MasterWorker::setWorktotal('dec',$service_work->master_worker_id);
  388. $work_log = [
  389. 'work_id'=>$work_id,
  390. 'master_worker_id'=>$service_work->master_worker_id,
  391. 'opera_log'=>'用户'.$params['user_info']['real_name'].'于'.date('y-m-d H:i:s',time()).'于'.date('Y-m-d H:i:s',time()).'确认服务完成',
  392. ];
  393. ServiceWorkLogLogic::add($work_log);
  394. Db::commit();
  395. }
  396. catch (\Exception $e) {
  397. self::setError($e->getMessage());
  398. return false;
  399. }
  400. }
  401. public static function firmOrderSave($params)
  402. {
  403. Db::startTrans();
  404. try {
  405. $goodIds = array_column($params['order_goods'],'id');
  406. $goodInfo = Goods::whereIn('id',$goodIds)->select();
  407. $ids = $goodInfo->column('id');
  408. if(!empty(array_diff($goodIds,$ids))){
  409. throw new Exception('产品不存在!');
  410. }
  411. if(empty($params['user_info']['mobile'])){
  412. throw new Exception('请先补充您的联系方式后在提交订单');
  413. }
  414. $order_amount = 0;
  415. $order_total = 0;
  416. $orderGoodsData = [];
  417. $goodsPaymentTypeArr = [];
  418. //计算订单总金额和结算金额
  419. foreach($params['order_goods'] as $val){
  420. $goods = $goodInfo->where('id',$val['id'])->toArray()[0];
  421. //根据服务工单计算当前订单应支付金额
  422. $order_total = $goods['service_total'];
  423. if($goods['goods_payment_type'] == GoodsEnum::ISGOODS_PAYMENT_TYPE){
  424. //一口价订单
  425. $order_amount = $goods['service_fee']*$val['goods_number'];
  426. }else{
  427. $order_total = $goods['base_service_fee']*$val['goods_number'];
  428. $order_amount = $goods['service_fee']*$val['goods_number'];
  429. }
  430. $goodsPaymentTypeArr[] = $goods['goods_payment_type'];
  431. $orderGoodsData[] = [
  432. 'goods_id' => $goods['id'],
  433. 'category_type' => $goods['category_type'],
  434. 'goods_category_ids' => $goods['goods_category_ids'],
  435. 'goods_category_id' => $goods['goods_category_id'],
  436. 'goods_name' => $goods['goods_name'],
  437. 'goods_image' => $goods['goods_image'],
  438. 'goods_video' => $goods['goods_video'],
  439. 'goods_number' => $val['goods_number'],
  440. 'good_unit' => $goods['good_unit'],
  441. 'goods_size' => $goods['goods_size'],
  442. 'goods_type' => $goods['goods_type'],
  443. 'goods_brand' => $goods['goods_brand'],
  444. 'install_guide' => $goods['install_guide'],
  445. 'goods_payment_type'=>$goods['goods_payment_type'],
  446. 'base_service_fee' => $goods['base_service_fee'],
  447. 'service_total' => $goods['service_total'],
  448. 'service_fee' => $goods['service_fee'],
  449. 'service_image' => $goods['service_image'],
  450. 'warranty_period'=>$goods['warranty_period'],
  451. 'fee_schedule' => $goods['fee_schedule'],
  452. 'goods_status' => $goods['goods_status'],
  453. ];
  454. }
  455. if(count(array_unique($goodsPaymentTypeArr))>1){
  456. throw new Exception('订单中存在多种支付方式');
  457. }
  458. //生成服务工单
  459. $work_data = [
  460. 'work_sn' => generate_sn(ServiceWork::class, 'work_sn'),
  461. 'real_name' => $params['contact_people'],
  462. 'mobile' => $params['contact_number'],
  463. 'address' => $params['address'],
  464. 'title' => $goods['goods_name'] . '*' .$val['goods_number'].$goods['good_unit'],
  465. 'category_type' => $goods['category_type'],
  466. 'goods_category_ids' => $goods['goods_category_ids'],
  467. 'goods_category_id' => $goods['goods_category_id'],
  468. 'base_service_fee' => $goods['base_service_fee'],
  469. 'service_fee' => $goods['service_fee'],
  470. 'work_pay_status'=>WorkEnum::UN_PAY_STATUS,
  471. 'appointment_time' => strtotime($params['appointment_time']),
  472. 'user_id' => $params['user_id'],
  473. 'work_type' => 1,
  474. ];
  475. $service_work = ServiceWork::create($work_data);
  476. //生成服务订单
  477. $data = [
  478. 'work_id'=> $service_work['id'],
  479. 'sn' => generate_sn(RechargeOrder::class, 'sn'),
  480. 'order_type'=>0,//服务订单
  481. 'order_terminal' => $params['terminal'],
  482. 'payment_type'=>$goods['goods_payment_type']==1?1:0,
  483. 'user_id' => $params['user_id'],
  484. 'pay_status' => PayEnum::UNPAID,
  485. 'coupon_id'=>!empty($params['coupon_id'])?$params['coupon_id']:0,
  486. 'coupon_price'=>!empty($order_coupon_amount)?$order_coupon_amount:0,
  487. 'pay_way' => $params['pay_way'],
  488. 'order_total' => $order_total,
  489. 'order_amount' => $order_amount,
  490. ];
  491. $order = RechargeOrder::create($data);
  492. array_walk($orderGoodsData, function (&$value, $key, $data) {
  493. $value = array_merge($value, ['sn' => $data['sn']]);
  494. },$data);
  495. dd($orderGoodsData);
  496. $orderGoodsModel = new OrderGoods();
  497. $orderGoodsModel->saveAll($orderGoodsData);
  498. Db::commit();
  499. return [
  500. 'order_id' => (int)$order['id'],
  501. ];
  502. } catch (\Exception $e) {
  503. Db::rollback();
  504. self::setError($e->getMessage());
  505. return false;
  506. }
  507. }
  508. }