where($where)->field($field)->find(); } /** * 添加订单 * @param array $data * @return int|false */ public function addOrder($data) { return $this->add($data); } /** * 更新订单 * @param array $where 查询条件 * @param array $data 更新数据 * @return bool */ public function updateOrder($where, $data) { return $this->where($where)->save($data); } /** * 删除订单 * @param array $where 查询条件 * @return bool */ public function deleteOrder($where) { return $this->where($where)->delete(); } /** * 获取订单列表 * @param array $where 查询条件 * @param int $page 页码 * @param int $pageSize 每页数量 * @return array */ public function getOrderList($where = [], $page = 1, $pageSize = 20) { $list = $this->where($where) ->order('create_time DESC') ->page($page, $pageSize) ->select(); $total = $this->where($where)->count(); return [ 'list' => $list ?: [], 'total' => $total, 'page' => $page, 'page_size' => $pageSize ]; } /** * 获取订单详情 * @param int $riderOrderId 骑手订单ID * @param int $riderId 骑手ID * @return array|null */ public function getOrderDetail($riderOrderId, $riderId = null) { $where = ['id' => $riderOrderId]; if ($riderId) { $where['rider_id'] = $riderId; } $order = $this->getFind($where); if (empty($order)) { return null; } // 获取原订单信息 $billOrderModel = D('RetailBillOrder'); $originalOrder = $billOrderModel->getFind(['id' => $order['bill_id']]); if ($originalOrder) { $order['original_order'] = $originalOrder; // 获取在线订单信息 $billOnlineModel = D('RetailBillOnline'); $onlineOrder = $billOnlineModel->getFind(['bill_id' => $order['bill_id']]); if ($onlineOrder) { $order['online_order'] = $onlineOrder; } } return $order; } /** * 获取骑手当前订单数量 * @param int $riderId 骑手ID * @return int */ public function getRiderCurrentOrderCount($riderId) { // 统一为进行中状态集合(1,2,3,4,5) import('@.Common.Business.OrderStatusUtil'); $inProgress = \Common\Business\OrderStatusUtil::getInProgressStatuses(); return $this->getCount([ 'rider_id' => $riderId, 'order_status' => ['in', implode(',', $inProgress)] ]); } /** * 获取记录数量 * @param array $where 查询条件 * @return int */ public function getCount($where = []) { return $this->where($where)->count(); } /** * 获取指定字段的值 * @param array $where 查询条件 * @param string $field 字段名 * @param bool $multiple 是否返回多个值 * @return mixed */ public function getColumn($where = [], $field = 'id', $multiple = false) { if ($multiple) { return $this->where($where)->getField($field, true); } else { return $this->where($where)->getField($field); } } }