OrderController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace addons\QiJuhe\backend\controllers;
  3. use addons\QiJuhe\common\models\GoodsSkuModel;
  4. use addons\QiJuhe\common\service\ApiService;
  5. use addons\QiJuhe\common\service\OrderService;
  6. use common\helpers\ApiCode;
  7. use common\models\order\OrderDetail;
  8. use common\models\order\OrderRefund;
  9. /**
  10. * 订单控制器
  11. *
  12. * Class OrderController
  13. * @package addons\JuheShop\backend\controllers
  14. */
  15. class OrderController extends BaseController
  16. {
  17. /**
  18. * 订单首页
  19. *
  20. * @return void
  21. */
  22. public function actionIndex()
  23. {
  24. if ($this->request->isAjax) {
  25. $param = $this->request->getQueryParams();
  26. $order = new OrderService(['mall_id' => $this->mall_id]);
  27. $list = $order->getOrderList($param);
  28. return $this->success('ok', $list);
  29. }
  30. return $this->render('index');
  31. }
  32. /**
  33. * 补单
  34. *
  35. * @return void
  36. */
  37. public function actionPatchOrder()
  38. {
  39. if ($this->request->isAjax) {
  40. $ids = $this->request->getQueryParam('order_ids');
  41. $order = new OrderService(['mall_id' => $this->mall_id]);
  42. $result = $order->patchOrder($ids);
  43. if ($result === false) {
  44. return $this->error($order->error);
  45. }
  46. return $this->success('推单成功', $result);
  47. }
  48. }
  49. /**
  50. * 转换订单(订单无法补单 转换成普通订单进行售后)
  51. *
  52. * @return mixed
  53. */
  54. public function actionChangeOrder()
  55. {
  56. if ($this->request->isAjax) {
  57. $id = $this->request->getQueryParam('id');
  58. $order = new OrderService(['mall_id' => $this->mall_id]);
  59. $result = $order->changeOrder($id);
  60. if ($result === false) {
  61. return $this->error($order->error);
  62. }
  63. return $this->success('转换成功', $result);
  64. }
  65. }
  66. public function actionThirdOrderDetail()
  67. {
  68. $supply_id = $this->request->get('supply_id') ?? 0;
  69. $api = ApiService::getConnect($this->mall_id, $supply_id);
  70. $ret = $api->orderDetailByThirdOrderSn($this->request->getQueryParam('order_no'));
  71. if (!$ret) return $this->error($api->error);
  72. // 过滤退款信息
  73. if (!empty($ret['read'][0]['order_items'])) {
  74. // 通过SKU ID 进行
  75. $refund = OrderRefund::findOne(['id' => $this->request->getQueryParam('refund_id')]);
  76. if (empty($refund)) return $this->error('退款不存在');
  77. $orderDetail = OrderDetail::findOne(['id' => $refund->order_detail_id]);
  78. $sku = GoodsSkuModel::findOne(['attr_id' => $orderDetail->goods_attr_id]);
  79. $order_items = $ret['read'][0]['order_items'];
  80. $sku_ids = array_column($order_items, 'sku_id');
  81. $index = array_search($sku->sku_id, $sku_ids);
  82. if ($index === false) return $this->error('无法获取SKU');
  83. $ret = $order_items[$index];
  84. $ret['price'] = bcmul($ret['price'], 0.01, 2);
  85. $ret['amount'] = bcmul($ret['amount'], 0.01, 2);
  86. $ret['supply_amount'] = bcmul($ret['supply_amount'], 0.01, 2);
  87. }
  88. return $this->success('ok', $ret, ApiCode::CODE_SUCCESS, JSON_BIGINT_AS_STRING);
  89. }
  90. }