| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- declare (strict_types = 1);
- namespace app\model\api;
- use think\Model;
- use think\facade\Db;
- /**
- * @mixin \think\Model
- */
- class StoreOrder extends Model
- {
- protected $name = 'store_order';
- /**
- * 获取订单列表
- * @param array $where
- * @param int $page
- * @param int $pageSize
- * @return array
- */
- public function getList($where = [], $page = 1, $pageSize = 20)
- {
- $query = $this->where($where);
- $totalCount = $query->count();
- $list = $query
- ->order('id', 'desc')
- ->page($page, $pageSize)
- ->select()
- ->toArray();
- // 关联订单商品信息
- if (!empty($list)) {
- foreach ($list as &$order) {
- $cartInfo = Db::name('store_order_cart_info')
- ->where('oid', $order['id'])
- ->select()
- ->toArray();
- foreach ($cartInfo as &$item) {
- if (!empty($item['cart_info'])) {
- $innerCartInfo = json_decode($item['cart_info'], true);
- unset($item['cart_info']);
- $item = array_merge($item, $innerCartInfo);
- }
- }
- $order['cart_info'] = $cartInfo;
- }
- }
- return [
- 'list' => $list,
- 'totalCount' => $totalCount,
- 'pageSize' => $pageSize,
- 'page' => $page
- ];
- }
- /**
- * 获取订单详情
- * @param int $id
- * @return array|null
- */
- public function getOrderDetail($id)
- {
- $order = $this->where('id', $id)->find();
- if (!$order) {
- return null;
- }
- $data = $order->toArray();
- // 获取订单商品
- $cartInfo = (new StoreOrderCartInfo())->where('oid', $id)->select()->toArray();
- $data['cart_info'] = $cartInfo;
- return $data;
- }
- }
|