['store_id', 'user_id'], ]; } /** * @notes 获取列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function lists(): array { $query = AccountsReceivable::where($this->searchWhere); if (!empty($this->params['order_sn'])) { $orderIds = BeforehandOrder::where('order_id', 'like', '%' . $this->params['order_sn'] . '%')->column('id'); $query->whereIn('order_id', $orderIds); } $list = $query->with('info') ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() ->toArray(); $stores = SystemStore::field('id,name')->whereIn('id', array_column($list, 'store_id'))->select()->toArray(); $stores = reset_index($stores, 'id'); $orderInfo = BeforehandOrder::field('id,order_id')->whereIn('id', array_column($list, 'order_id'))->select()->toArray(); $orderInfo = reset_index($orderInfo, 'id'); $orderInfo = reset_index($orderInfo, 'id'); foreach ($list as &$item) { $item['store_name'] = $stores[$item['store_id']]['name']; $item['order_sn'] = $orderInfo[$item['order_id']]['order_id']; $item['debt_day'] = intval((time() - strtotime($item['create_time'])) / 86400); $item['deadline'] = date('Y-m-d H:i:s', $item['deadline']); } return $list; } /** * @notes 获取数量 * @return int */ public function count(): int { $query = AccountsReceivable::where($this->searchWhere); if (!empty($this->params['order_sn'])) { $orderIds = BeforehandOrder::where('order_id', 'like', '%' . $this->params['order_sn'] . '%')->column('id'); $query->whereIn('order_id', $orderIds); } return $query->count(); } }