| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace addons\QiJuhe\backend\controllers;
- use addons\QiJuhe\common\models\GoodsSkuModel;
- use addons\QiJuhe\common\service\ApiService;
- use addons\QiJuhe\common\service\OrderService;
- use common\helpers\ApiCode;
- use common\models\order\OrderDetail;
- use common\models\order\OrderRefund;
- /**
- * 订单控制器
- *
- * Class OrderController
- * @package addons\JuheShop\backend\controllers
- */
- class OrderController extends BaseController
- {
- /**
- * 订单首页
- *
- * @return void
- */
- public function actionIndex()
- {
- if ($this->request->isAjax) {
-
- $param = $this->request->getQueryParams();
- $order = new OrderService(['mall_id' => $this->mall_id]);
- $list = $order->getOrderList($param);
- return $this->success('ok', $list);
- }
- return $this->render('index');
- }
- /**
- * 补单
- *
- * @return void
- */
- public function actionPatchOrder()
- {
- if ($this->request->isAjax) {
- $ids = $this->request->getQueryParam('order_ids');
- $order = new OrderService(['mall_id' => $this->mall_id]);
- $result = $order->patchOrder($ids);
- if ($result === false) {
- return $this->error($order->error);
- }
- return $this->success('推单成功', $result);
- }
- }
- /**
- * 转换订单(订单无法补单 转换成普通订单进行售后)
- *
- * @return mixed
- */
- public function actionChangeOrder()
- {
- if ($this->request->isAjax) {
- $id = $this->request->getQueryParam('id');
- $order = new OrderService(['mall_id' => $this->mall_id]);
- $result = $order->changeOrder($id);
- if ($result === false) {
- return $this->error($order->error);
- }
- return $this->success('转换成功', $result);
- }
- }
- public function actionThirdOrderDetail()
- {
- $supply_id = $this->request->get('supply_id') ?? 0;
- $api = ApiService::getConnect($this->mall_id, $supply_id);
- $ret = $api->orderDetailByThirdOrderSn($this->request->getQueryParam('order_no'));
- if (!$ret) return $this->error($api->error);
- // 过滤退款信息
- if (!empty($ret['read'][0]['order_items'])) {
- // 通过SKU ID 进行
- $refund = OrderRefund::findOne(['id' => $this->request->getQueryParam('refund_id')]);
- if (empty($refund)) return $this->error('退款不存在');
- $orderDetail = OrderDetail::findOne(['id' => $refund->order_detail_id]);
- $sku = GoodsSkuModel::findOne(['attr_id' => $orderDetail->goods_attr_id]);
- $order_items = $ret['read'][0]['order_items'];
- $sku_ids = array_column($order_items, 'sku_id');
- $index = array_search($sku->sku_id, $sku_ids);
- if ($index === false) return $this->error('无法获取SKU');
- $ret = $order_items[$index];
- $ret['price'] = bcmul($ret['price'], 0.01, 2);
- $ret['amount'] = bcmul($ret['amount'], 0.01, 2);
- $ret['supply_amount'] = bcmul($ret['supply_amount'], 0.01, 2);
- }
- return $this->success('ok', $ret, ApiCode::CODE_SUCCESS, JSON_BIGINT_AS_STRING);
- }
- }
|