Kirin 4 anni fa
parent
commit
a97b907a06

+ 17 - 0
app/api/controller/activity/StoreExchangeController.php

@@ -5,6 +5,7 @@ namespace app\api\controller\activity;
 use app\admin\model\store\StoreDescription;
 use app\admin\model\store\StoreProductAttrValue;
 use app\models\store\StoreExchange;
+use app\models\store\StoreExchangeOrder;
 use app\models\store\StoreIntegral;
 use app\models\store\StoreProductAttr;
 use app\models\store\StoreProductRelation;
@@ -98,4 +99,20 @@ class StoreExchangeController
         $data['productValue'] = $productValue;
         return app('json')->successful($data);
     }
+
+    /**
+     * 订单列表
+     * @param Request $request
+     * @return mixed
+     */
+    public function order_lst(Request $request)
+    {
+        list($type, $page, $limit, $search) = UtilService::getMore([
+            ['type', ''],
+            ['page', 0],
+            ['limit', ''],
+            ['search', ''],
+        ], $request, true);
+        return app('json')->successful(StoreExchangeOrder::getUserOrderSearchList($request->uid(), $type, $page, $limit, $search));
+    }
 }

+ 58 - 0
app/models/store/StoreExchangeOrder.php

@@ -29,4 +29,62 @@ class StoreExchangeOrder extends BaseModel
      */
     protected $name = 'store_exchange_order';
     use ModelTrait;
+
+
+    public static function getUserOrderSearchList($uid, $type, $page, $limit, $search)
+    {
+        if ($search) {
+            $order = self::searchUserOrder($uid, $search) ?: [];
+            $list = $order == false ? [] : [$order];
+        } else {
+            $list = self::getUserOrderList($uid, $type, $page, $limit);
+        }
+        foreach ($list as $k => $order) {
+            $list[$k]['order'] = StoreOrder::get($order['oid']);
+            $list[$k]['cart_info'] = StoreOrderCartInfo::where('oid', $order['oid'])
+                ->where('cart_id', $order['cart_id'])
+                ->value('cart_info');
+            if (is_string($list[$k]['cart_info'])) $list[$k]['cart_info'] = json_decode($list[$k]['cart_info'], true);
+        }
+        return $list;
+    }
+
+    public static function searchUserOrder($uid, $order_id)
+    {
+        $order = self::where('uid|gift_uid', $uid)->where('order_id', $order_id)->where('is_del', 0)
+            ->order('add_time DESC')->select();
+        if (!$order)
+            return false;
+        else
+            return $order;
+
+    }
+
+    public static function getUserOrderList($uid, $status = '', $page = 0, $limit = 8)
+    {
+        if ($page) $list = self::statusByWhere($status, $uid)->where('is_del', 0)->where('uid|gift_uid', $uid)
+            ->order('add_time DESC')->page((int)$page, (int)$limit)->select()->toArray();
+        else  $list = self::statusByWhere($status, $uid)->where('is_del', 0)->where('uid|gift_uid', $uid)
+            ->order('add_time DESC')->page((int)$page, (int)$limit)->select()->toArray();
+        return $list;
+    }
+
+    public static function statusByWhere($status, $uid = 0, $model = null)
+    {
+        if ($model == null) $model = new self;
+        if ('' === $status)
+            return $model;
+        else if ($status == 0)//待使用
+            return $model->where('status', 0)->where('refund_status', 0);
+        else if ($status == 1)//已使用
+            return $model->where('status', 1)->where('refund_status', 0);
+        else if ($status == -1)//退款中
+            return $model->where('refund_status', 1);
+        else if ($status == -2)//已退款
+            return $model->where('refund_status', 2);
+        else if ($status == -3)//退款
+            return $model->where('refund_status', 'IN', '1,2');
+        else
+            return $model;
+    }
 }