public function listAction() { $this->setLeftNav('list'); $req = $this->request; $page = intval($req->getQuery('page', null, 1)); $page = $page > 0 ? $page : 1; $limit = $this->pageNavLimit; $offset = $limit * ($page - 1); $filterId = intval($req->getQuery('filterId', null, -10000)); $filterUserId = intval($req->getQuery('filterUserId', null, -10000)); $filterState = intval($req->getQuery('filterState', null, -10000)); $filterDtStart = $req->getQuery('filterDtStart', null, ''); $filterDtEnd = $req->getQuery('filterDtEnd', null, ''); $columns = ['order_id', 'order_long_id', 'ub.user_id', 'user_nickname', 'user_cover', 'order_mobile', 'order_type', 'order_origin', 'order_money', 'order_freight', 'order_remake', 'order_state', 'order_pay_type', 'order_pay_state', 'order_addtime']; $where = []; $bind = []; if ($filterId > 0) { $where[] = 'order_long_id = :id:'; $bind['id'] = $filterId; } if ($filterUserId > 0) { $where[] = 'Apps\\Common\\Models\\UserOrder.user_id = :uid:'; $bind['uid'] = $filterUserId; } if ($filterState > -10000) { if ($filterState == 2) { $where[] = 'order_pay_state = 2'; } else { $where[] = 'order_state = :state:'; $bind['state'] = $filterState; } } if (!empty($filterDtStart)) { $where[] = 'order_addtime >= :dtStart:'; $bind['dtStart'] = $filterDtStart . ' 00:00:00'; } if (!empty($filterDtEnd)) { $where[] = 'order_addtime <= :dtEnd:'; $bind['dtEnd'] = $filterDtEnd . ' 23:59:59'; } $whereStr = implode(' AND ', $where); $query = UserOrder::query()->columns($columns)->leftJoin('Apps\\Common\\Models\\UserBase', 'ub.user_id = Apps\\Common\\Models\\UserOrder.user_id', 'ub'); if (count($where) > 0) { $query = $query->where($whereStr)->bind($bind); } $data = $query->orderBy('order_id DESC')->limit($limit, $offset)->execute(); $total = UserOrder::count(['conditions' => $whereStr, 'bind' => $bind]); $this->view->setVar('data', $data); $this->view->setVar('page', $page); $this->view->setVar('limit', $limit); $this->view->setVar('total', $total); $this->view->setVar('filterId', $filterId); $this->view->setVar('filterUserId', $filterUserId); $this->view->setVar('filterState', $filterState); $this->view->setVar('filterDtStart', $filterDtStart); $this->view->setVar('filterDtEnd', $filterDtEnd); }
public function run() { /** * 验证用户权限 */ if (false == $this->verifyUserAuth()) { return false; } $type = $this->getDataItem('type', 'all'); $page = intval($this->getDataItem('page', 0)); $page = $page < 1 ? 1 : $page; $limit = $this->getConfig()->limit; $offset = ($page - 1) * $limit; $userId = $this->getUserAuth()->userId; $typeArray = ['all', 'pay', 'end']; if (!in_array($type, $typeArray)) { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '查询的类型不存在.'); } $where = 'user_id = :uid:'; $whereParams = ['uid' => $userId]; switch ($type) { case 'all': $where .= ' AND order_state >= 0'; break; case 'pay': $where .= ' AND order_state >= 0 AND order_pay_state = 0'; break; case 'end': $where .= ' AND order_state >= 0 AND order_pay_state > 0'; break; } $orders = UserOrder::query()->columns('order_id, order_long_id, order_money, order_mobile, order_pay_type, order_pay_state, order_addtime')->where($where, $whereParams)->orderBy('order_id desc')->limit($limit, $offset)->execute()->toArray(); $data = []; foreach ($orders as $order) { $order['order_pay_type'] = $this->getPayTypeStr($order['order_pay_type']); $order['order_pay_state'] = $order['order_pay_state'] > 0 ? 1 : 0; $order['order_addtime'] = date('Y-m-d', strtotime($order['order_addtime'])); $order['goods'] = $this->getGoods($order['order_id']); $data[] = $order; } $this->setResult($data); }