Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zhengmingwei
  5. * Date: 2019/11/9
  6. * Time: 10:00 下午
  7. */
  8. namespace addons\unishop\controller;
  9. use addons\nzf\AliPay;
  10. use addons\nzf\PayService;
  11. use addons\unishop\extend\Hashids;
  12. use addons\unishop\model\Area;
  13. use addons\unishop\model\Config;
  14. use addons\unishop\model\Evaluate;
  15. use addons\unishop\model\Product;
  16. use app\admin\model\unishop\Coupon as CouponModel;
  17. use addons\unishop\model\DeliveryRule as DeliveryRuleModel;
  18. use addons\unishop\model\OrderRefund;
  19. use app\admin\model\unishop\OrderRefundProduct;
  20. use think\Db;
  21. use think\Exception;
  22. use addons\unishop\model\Address as AddressModel;
  23. use think\Hook;
  24. use think\Loader;
  25. /**
  26. * 订单相关接口
  27. * Class Order
  28. * @package addons\unishop\controller
  29. */
  30. class Order extends Base
  31. {
  32. /**
  33. * 允许频繁访问的接口
  34. * @var array
  35. */
  36. protected $frequently = ['getorders'];
  37. protected $noNeedLogin = [];
  38. /**
  39. * 创建订单
  40. */
  41. public function create()
  42. {
  43. $productId = $this->request->post('id', 0);
  44. try {
  45. $user_id = $this->auth->id;
  46. // 单个商品
  47. if ($productId) {
  48. $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
  49. $product = (new Product)->where(['id' => $productId, 'switch' => Product::SWITCH_ON, 'deletetime' => null])->find();
  50. /** 产品基础数据 **/
  51. $spec = $this->request->post('spec', '');
  52. $productData[0] = $product->getDataOnCreateOrder($spec);
  53. } else {
  54. // 多个商品
  55. $cart = $this->request->post('cart');
  56. $carts = (new \addons\unishop\model\Cart)
  57. ->whereIn('id', $cart)
  58. ->with(['product'])
  59. ->order(['id' => 'desc'])
  60. ->select();
  61. foreach ($carts as $cart) {
  62. if ($cart->product instanceof Product) {
  63. $productData[] = $cart->product->getDataOnCreateOrder($cart->spec ? $cart->spec : '', $cart->number);
  64. }
  65. }
  66. }
  67. if (empty($productData) || !$productData) {
  68. $this->error(__('Product not exist'));
  69. }
  70. /** 默认地址 **/
  71. // $address = (new AddressModel)->where(['user_id' => $user_id, 'is_default' => AddressModel::IS_DEFAULT_YES])->find();
  72. // if ($address) {
  73. // $area = (new Area)->whereIn('id', [$address->province_id, $address->city_id, $address->area_id])->column('name', 'id');
  74. // $address = $address->toArray();
  75. // $address['province']['name'] = $area[$address['province_id']];
  76. // $address['city']['name'] = $area[$address['city_id']];
  77. // $address['area']['name'] = $area[$address['area_id']];
  78. // }
  79. /** 可用优惠券 **/
  80. $coupon = CouponModel::all(function ($query) {
  81. $time = time();
  82. $query
  83. ->where(['switch' => CouponModel::SWITCH_ON])
  84. ->where('starttime', '<', $time)
  85. ->where('endtime', '>', $time);
  86. });
  87. if ($coupon) {
  88. $coupon = collection($coupon)->toArray();
  89. }
  90. /** 运费数据 **/
  91. // $cityId = $address['city_id'] ? $address['city_id'] : 0;
  92. // $delivery = (new DeliveryRuleModel())->getDelivetyByArea($cityId);
  93. foreach ($productData as &$product) {
  94. $product['image'] = Config::getImagesFullUrl($product['image']);
  95. $product['sales_price'] = number_format($product['sales_price'], 2);
  96. $product['market_price'] = number_format($product['market_price'], 2);
  97. }
  98. $this->success('', [
  99. 'product' => $productData,
  100. // 'address' => $address,
  101. 'coupon' => $coupon,
  102. // 'delivery' => $delivery['list']
  103. ]);
  104. } catch (Exception $e) {
  105. $this->error($e->getMessage(), false);
  106. }
  107. }
  108. /**
  109. * 提交订单
  110. */
  111. public function submit()
  112. {
  113. $data = $this->request->post();
  114. try {
  115. $validate = Loader::validate('\\addons\\unishop\\validate\\Order');
  116. if (!$validate->check($data, [], 'submit')) {
  117. throw new Exception($validate->getError());
  118. }
  119. Db::startTrans();
  120. // 判断创建订单的条件
  121. if (empty(Hook::get('create_order_before'))) {
  122. Hook::add('create_order_before', 'addons\\unishop\\behavior\\Order');
  123. }
  124. // 减少商品库存,增加"已下单未支付数量"
  125. if (empty(Hook::get('create_order_after'))) {
  126. Hook::add('create_order_after', 'addons\\unishop\\behavior\\Order');
  127. }
  128. $orderModel = new \addons\unishop\model\Order();
  129. $result = $orderModel->createOrder($this->auth->id, $data);
  130. Db::commit();
  131. $this->success('', $result);
  132. } catch (Exception $e) {
  133. Db::rollback();
  134. $this->error($e->getMessage(), false);
  135. }
  136. }
  137. /**
  138. * 获取运费模板
  139. */
  140. public function getDelivery()
  141. {
  142. $cityId = $this->request->get('city_id', 0);
  143. $delivery = (new DeliveryRuleModel())->getDelivetyByArea($cityId);
  144. $this->success('', $delivery['list']);
  145. }
  146. /**
  147. * 获取订单信息
  148. */
  149. public function getOrders()
  150. {
  151. // 0=全部,1=待付款,2=待发货,3=待收货,4=待评价,5=售后
  152. $type = $this->request->get('type', 0);
  153. $page = $this->request->get('page', 1);
  154. $pagesize = $this->request->get('pagesize', 10);
  155. try {
  156. $orderModel = new \addons\unishop\model\Order();
  157. $result = $orderModel->getOrdersByType($this->auth->id, $type, $page, $pagesize);
  158. $this->success('', $result);
  159. } catch (Exception $e) {
  160. $this->error($e->getMessage());
  161. }
  162. }
  163. /**
  164. * 取消订单
  165. * 未支付的订单才叫取消,已支付的叫退货
  166. */
  167. public function cancel()
  168. {
  169. $order_id = $this->request->get('order_id', 0);
  170. $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
  171. $orderModel = new \addons\unishop\model\Order();
  172. $order = $orderModel->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
  173. if (!$order) {
  174. $this->error(__('Order not exist'));
  175. }
  176. switch ($order['status']) {
  177. case \addons\unishop\model\Order::STATUS_REFUND:
  178. $this->error('此订单已退款,无法取消');
  179. break;
  180. case \addons\unishop\model\Order::STATUS_CANCEL:
  181. $this->error('此订单已取消, 无需再取消');
  182. break;
  183. }
  184. if ($order['have_paid'] != \addons\unishop\model\Order::PAID_NO) {
  185. $this->error('此订单已支付,无法取消');
  186. }
  187. if ($order['status'] == \addons\unishop\model\Order::STATUS_NORMAL && $order['have_paid'] == \addons\unishop\model\Order::PAID_NO) {
  188. $order->status = \addons\unishop\model\Order::STATUS_CANCEL;
  189. $order->save();
  190. $this->success('取消成功', true);
  191. }
  192. }
  193. /**
  194. * 删除订单
  195. * 只能删除已取消或已退货的订单
  196. */
  197. public function delete()
  198. {
  199. $order_id = $this->request->get('order_id', 0);
  200. $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
  201. $orderModel = new \addons\unishop\model\Order();
  202. $order = $orderModel->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
  203. if (!$order) {
  204. $this->error(__('Order not exist'));
  205. }
  206. if ($order['status'] == \addons\unishop\model\Order::STATUS_NORMAL) {
  207. $this->error('只能删除已取消或已退货的订单');
  208. }
  209. if ($order['status'] == \addons\unishop\model\Order::STATUS_REFUND && $order['refund_status'] == \addons\unishop\model\Order::REFUND_STATUS_APPLY) {
  210. $this->error('订单退款中,不可删除订单');
  211. }
  212. $order->delete();
  213. $this->success('删除成功', true);
  214. }
  215. /**
  216. * 确认收货
  217. */
  218. public function received()
  219. {
  220. $order_id = $this->request->get('order_id', 0);
  221. $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
  222. $orderModel = new \addons\unishop\model\Order();
  223. $order = $orderModel->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
  224. if (!$order) {
  225. $this->error(__('Order not exist'));
  226. }
  227. if ($order->have_delivered == 0) {
  228. $this->error('未发货,不能确认收货');
  229. }
  230. $order->have_received = time();
  231. $order->save();
  232. $this->success('已确认收货', true);
  233. }
  234. /**
  235. * 发表评论
  236. */
  237. public function comment()
  238. {
  239. $rate = $this->request->post('rate', 5);
  240. $anonymous = $this->request->post('anonymous', 0);
  241. $comment = $this->request->post('comment');
  242. $order_id = $this->request->post('order_id', 0);
  243. $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
  244. $product_id = $this->request->post('product_id');
  245. $product_id = \addons\unishop\extend\Hashids::decodeHex($product_id);
  246. $orderProductModel = new \addons\unishop\model\OrderProduct();
  247. $orderProduct = $orderProductModel->where(['product_id' => $product_id, 'order_id' => $order_id, 'user_id' => $this->auth->id])->find();
  248. $orderModel = new \addons\unishop\model\Order();
  249. $order = $orderModel->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
  250. if (!$orderProduct || !$order) {
  251. $this->error(__('Order not exist'));
  252. }
  253. if ($order->have_received == $orderModel::RECEIVED_NO) {
  254. $this->error(__('未收货,不可评价'));
  255. }
  256. $result = false;
  257. try {
  258. $evaluate = new Evaluate();
  259. $evaluate->user_id = $this->auth->id;
  260. $evaluate->order_id = $order_id;
  261. $evaluate->product_id = $product_id;
  262. $evaluate->rate = $rate;
  263. $evaluate->anonymous = $anonymous;
  264. $evaluate->comment = $comment;
  265. $evaluate->spec = $orderProduct->spec;
  266. $result = $evaluate->save();
  267. if ($result) {
  268. $order->have_commented = time();
  269. $order->save();
  270. }
  271. } catch (Exception $e) {
  272. $this->error($e->getMessage());
  273. }
  274. if ($result !== false) {
  275. $this->success(__('Thanks for the evaluation'));
  276. } else {
  277. $this->error(__('Evaluation failure'));
  278. }
  279. }
  280. /**
  281. * 获取订单数量
  282. */
  283. public function count()
  284. {
  285. if (!$this->auth->isLogin()) {
  286. $this->error('');
  287. }
  288. $order = new \addons\unishop\model\Order();
  289. $list = $order
  290. ->where([
  291. 'user_id' => $this->auth->id,
  292. ])
  293. ->where('status', '<>', \addons\unishop\model\Order::STATUS_CANCEL)
  294. ->where(function ($query) {
  295. $query
  296. ->whereOr([
  297. 'have_paid' => \addons\unishop\model\Order::PAID_NO,
  298. 'have_delivered' => \addons\unishop\model\Order::DELIVERED_NO,
  299. 'have_received' => \addons\unishop\model\Order::RECEIVED_NO,
  300. 'have_commented' => \addons\unishop\model\Order::COMMENTED_NO
  301. ])
  302. ->whereOr('refund_status', '>', \addons\unishop\model\Order::REFUND_STATUS_NONE);
  303. })
  304. ->field('have_paid,have_delivered,have_received,have_commented,refund_status,had_refund')
  305. ->select();
  306. $data = [
  307. 'unpaid' => 0,
  308. 'undelivered' => 0,
  309. 'unreceived' => 0,
  310. 'uncomment' => 0,
  311. 'refund' => 0
  312. ];
  313. foreach ($list as $item) {
  314. switch (true) {
  315. case $item['have_paid'] > 0 && $item['have_delivered'] > 0 && $item['have_received'] > 0 && $item['have_commented'] == 0 && $item['refund_status'] == 0:
  316. $data['uncomment']++;
  317. break;
  318. case $item['have_paid'] > 0 && $item['have_delivered'] > 0 && $item['have_received'] == 0 && $item['have_commented'] == 0 && $item['refund_status'] == 0:
  319. $data['unreceived']++;
  320. break;
  321. case $item['have_paid'] > 0 && $item['have_delivered'] == 0 && $item['have_received'] == 0 && $item['have_commented'] == 0 && $item['refund_status'] == 0:
  322. $data['undelivered']++;
  323. break;
  324. case $item['have_paid'] == 0 && $item['have_delivered'] == 0 && $item['have_received'] == 0 && $item['have_commented'] == 0 && $item['refund_status'] == 0:
  325. $data['unpaid']++;
  326. break;
  327. case $item['refund_status'] > 0 && $item['had_refund'] == 0 && $item['refund_status'] != 3:
  328. $data['refund']++;
  329. break;
  330. }
  331. }
  332. $this->success('', $data);
  333. }
  334. /**
  335. * 订单详情细节
  336. */
  337. public function detail()
  338. {
  339. $order_id = $this->request->get('order_id', 0);
  340. $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
  341. try {
  342. $orderModel = new \addons\unishop\model\Order();
  343. $order = $orderModel
  344. ->with([
  345. 'products' => function ($query) {
  346. $query->field('id,order_id,image,number,price,spec,title,product_id');
  347. },
  348. 'extend' => function ($query) {
  349. $query->field('id,order_id,address_id,address_json,express_number');
  350. },
  351. 'evaluate' => function ($query) {
  352. $query->field('id,order_id,product_id');
  353. }
  354. ])
  355. ->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
  356. if ($order) {
  357. $order = $order->append(['state', 'paidtime', 'deliveredtime', 'receivedtime', 'commentedtime', 'pay_type_text', 'refund_status_text'])->toArray();
  358. // 快递单号
  359. $order['express_number'] = $order['extend']['express_number'];
  360. // 送货地址
  361. // $address = json_decode($order['extend']['address_json'], true);
  362. // $area = (new \addons\unishop\model\Area())
  363. // ->whereIn('id', [$address['province_id'], $address['city_id'], $address['area_id']])
  364. // ->column('name', 'id');
  365. // $delivery['username'] = $address['name'];
  366. // $delivery['mobile'] = $address['mobile'];
  367. // $delivery['address'] = $area[$address['province_id']] . ' ' . $area[$address['city_id']] . ' ' . $area[$address['area_id']] . ' ' . $address['address'];
  368. // $order['delivery'] = $delivery;
  369. // 是否已评论
  370. $evaluate = array_column($order['evaluate'], 'product_id');
  371. foreach ($order['products'] as &$product) {
  372. $product['image'] = Config::getImagesFullUrl($product['image']);
  373. if (in_array($product['id'], $evaluate)) {
  374. $product['evaluate'] = true;
  375. } else {
  376. $product['evaluate'] = false;
  377. }
  378. }
  379. unset($order['evaluate']);
  380. unset($order['extend']);
  381. }
  382. $this->success('', $order);
  383. } catch (Exception $e) {
  384. $this->error($e->getMessage());
  385. }
  386. }
  387. /**
  388. * 申请售后信息
  389. */
  390. public function refundInfo()
  391. {
  392. $order_id = $this->request->post('order_id');
  393. $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
  394. $orderModel = new \addons\unishop\model\Order();
  395. $order = $orderModel
  396. ->with([
  397. 'products' => function ($query) {
  398. $query->field('id,order_id,image,number,price,spec,title,product_id,(1) as choose');
  399. },
  400. 'refund',
  401. 'refundProducts'
  402. ])
  403. ->field('id,status,total_price,delivery_price,have_commented,have_delivered,have_paid,have_received,refund_status')
  404. ->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
  405. if (!$order) {
  406. $this->error(__('Order not exist'));
  407. }
  408. $order = $order->append(['refund_status_text'])->toArray();
  409. foreach ($order['products'] as &$product) {
  410. $product['image'] = Config::getImagesFullUrl($product['image']);
  411. $product['choose'] = 0;
  412. // 如果是已提交退货的全选
  413. if ($order['status'] == \addons\unishop\model\Order::STATUS_REFUND) {
  414. foreach ($order['refund_products'] as $refundProduct) {
  415. if ($product['order_product_id'] == $refundProduct['order_product_id']) {
  416. $product['choose'] = 1;
  417. }
  418. }
  419. }
  420. }
  421. unset($order['refund_products']);
  422. $this->success('', $order);
  423. }
  424. /**
  425. * 申请售后
  426. * @throws \think\db\exception\DataNotFoundException
  427. * @throws \think\db\exception\ModelNotFoundException
  428. * @throws \think\exception\DbException
  429. */
  430. public function refund()
  431. {
  432. $order_id = $this->request->post('order_id');
  433. $order_id = Hashids::decodeHex($order_id);
  434. $orderModel = new \addons\unishop\model\Order();
  435. $order = $orderModel->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
  436. if (!$order) {
  437. $this->error(__('Order not exist'));
  438. }
  439. if ($order['have_paid'] == 0) {
  440. $this->error(__('订单未支付,可直接取消,无需申请售后'));
  441. }
  442. $amount = $this->request->post('amount', 0);
  443. $serviceType = $this->request->post('service_type');
  444. $receivingStatus = $this->request->post('receiving_status');
  445. $reasonType = $this->request->post('reason_type');
  446. $refundExplain = $this->request->post('refund_explain');
  447. $orderProductId = $this->request->post('order_product_id');
  448. if (!$orderProductId) {
  449. $this->error(__('Please select goods'));
  450. }
  451. if (!in_array($receivingStatus, [OrderRefund::UNRECEIVED, OrderRefund::RECEIVED])) {
  452. $this->error(__('Please select goods status'));
  453. }
  454. if (!in_array($serviceType, [OrderRefund::TYPE_REFUND_NORETURN, OrderRefund::TYPE_REFUND_RETURN, OrderRefund::TYPE_EXCHANGE])) {
  455. $this->error(__('Please select service type'));
  456. }
  457. if (in_array($serviceType, [OrderRefund::TYPE_REFUND_NORETURN, OrderRefund::TYPE_REFUND_RETURN]) && $order['total_price'] > 0) {
  458. if (!$amount) {
  459. $this->error(__('Please fill in the refund amount'));
  460. }
  461. }
  462. try {
  463. Db::startTrans();
  464. $orderRefund = new OrderRefund();
  465. $orderRefund->user_id = $this->auth->id;
  466. $orderRefund->order_id = $order_id;
  467. $orderRefund->receiving_status = $receivingStatus;
  468. $orderRefund->service_type = $serviceType;
  469. $orderRefund->reason_type = $reasonType;
  470. $orderRefund->amount = $amount;
  471. $orderRefund->refund_explain = $refundExplain;
  472. $orderRefund->save();
  473. $productIdArr = explode(',', $orderProductId);
  474. $refundProduct = [];
  475. foreach ($productIdArr as $orderProductId) {
  476. $tmp['order_product_id'] = $orderProductId;
  477. $tmp['order_id'] = $order_id;
  478. $tmp['user_id'] = $this->auth->id;
  479. $tmp['refund_id'] = $orderRefund['id'];
  480. $tmp['createtime'] = time();
  481. $refundProduct[] = $tmp;
  482. }
  483. (new OrderRefundProduct)->insertAll($refundProduct);
  484. $order->status = \addons\unishop\model\Order::STATUS_REFUND;
  485. $order->refund_status = \addons\unishop\model\Order::REFUND_STATUS_APPLY;
  486. $order->save();
  487. Db::commit();
  488. $this->success(__('Commit'), 1);
  489. } catch (Exception $e) {
  490. Db::rollback();
  491. $this->error($e->getMessage());
  492. }
  493. }
  494. public function doRefund(){
  495. $order_id = $this->request->post('order_id');
  496. $order_id = Hashids::decodeHex($order_id);
  497. $orderModel = new \addons\unishop\model\Order();
  498. $order = $orderModel->where([
  499. 'id' => $order_id,
  500. 'user_id' => $this->auth->id,
  501. 'status'=>1,//订单状态正常
  502. 'have_paid'=>[">",0],//已支付
  503. 'have_received'=>0,//订单完成前
  504. 'had_refund'=>0
  505. ])->find();
  506. if (!$order){
  507. $this->error("订单信息错误");
  508. }
  509. $order->status = \addons\unishop\model\Order::STATUS_REFUND;
  510. $order->refund_status = \addons\unishop\model\Order::REFUND_STATUS_AGREE;
  511. $result = $order->save();
  512. if ($result !== false){
  513. //order_id:订单ID name:订单名称 total_fee:总金额-元 refund_fee退款金额
  514. $param = [
  515. "order_id"=>$order['out_trade_no'],
  516. "total_fee"=>$order['total_price'],
  517. "refund_fee"=>$order['total_price'],
  518. "name"=>$order['订单退款'],
  519. ];
  520. PayService::cancel($param,$order["pay_type"]);
  521. $this->success("success",[]);
  522. }
  523. $this->error("订单信息错误");
  524. }
  525. /**
  526. * 售后发货
  527. */
  528. public function refundDelivery()
  529. {
  530. $orderId = $this->request->post('order_id');
  531. $expressNumber = $this->request->post('express_number');
  532. if (!$expressNumber) {
  533. $this->error(__('Please fill in the express number'));
  534. }
  535. $orderId = Hashids::decodeHex($orderId);
  536. $orderModel = new \addons\unishop\model\Order();
  537. $order = $orderModel
  538. ->where(['id' => $orderId, 'user_id' => $this->auth->id])
  539. ->with(['refund'])->find();
  540. if (!$order || !$order->refund) {
  541. $this->error(__('Order not exist'));
  542. }
  543. try {
  544. Db::startTrans();
  545. $order->refund->express_number = $expressNumber;
  546. $order->refund_status = \addons\unishop\model\Order::REFUND_STATUS_APPLY;
  547. if ($order->refund->save() && $order->save()) {
  548. Db::commit();
  549. $this->success('', 1);
  550. } else {
  551. throw new Exception(__('Operation failed'));
  552. }
  553. } catch (Exception $e) {
  554. Db::rollback();
  555. $this->success($e->getMessage());
  556. }
  557. }
  558. }