1], [['limit'], 'default', 'value' => 20], ]; } public function search() { if (!$this->validate()) { return ['code' => 1, 'msg' => $this->getErrorSummary(false)[0]]; } $query = ProductBatchProcess::find()->alias('pbp') ->innerJoin(['pbpl' => ProductBatchProcessLog::tableName()], 'pbp.id=pbpl.product_batch_process_id') ->leftJoin(['u' => User::tableName()], 'u.id=pbp.process_user_id') ->leftJoin(['pb' => ProductBatch::tableName()], 'pb.id=pbp.product_batch_id') ->leftJoin(['p' => Product::tableName()], 'p.id=pb.product_id') ->leftJoin(['g' => Goods::tableName()], 'g.id=pb.goods_id') ->where([ 'pbpl.is_delete' => 0, 'pbpl.store_id' => get_store_id(), 'pbpl.state' => 0, 'pbp.process_user_id' => $this->user_id ]) ->orderBy('pbp.sort ASC') ->groupBy("pbpl.product_batch_id") ->select(['pbpl.*', 'pbp.process_name', 'pb.batch_number', 'pb.batch_name', 'p.product_name', 'g.name as goods_name', 'u.nickname']); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]); $list = $query->limit($pagination->limit)->offset($pagination->offset)->asArray()->all(); foreach ($list as $index => $value) { $product_batch_current_index = 0; $product_batch_current_count = 0; $product_batch_also_index = 0; $product_batch_also_count = 0; $product_batch_list = ProductBatchProcess::find()->alias("pbp") ->innerJoin(['pbpl' => ProductBatchProcessLog::tableName()], 'pbp.id=pbpl.product_batch_process_id') ->where([ 'pbp.is_delete' => 0, 'pbp.store_id' => get_store_id(), 'pbp.product_batch_id' => $value["product_batch_id"], ])->orderBy("pbp.sort asc")->select(['pbpl.*', 'pbp.process_name', 'pbp.process_user_id'])->asArray()->all(); foreach ($product_batch_list as $k => $v) { if ($v['state'] == 1 && $product_batch_list[$k+1]['state'] == 0) { $product_batch_current_count = $k+1; continue; } } foreach ($product_batch_list as $k => $v) { if ($v['process_user_id'] == $this->user_id && $v['state'] == 0 && $product_batch_also_index == 0) { $product_batch_also_count = $k; $product_batch_also_index++; continue; } } $product_batch_total_count = $product_batch_list ? count($product_batch_list) : 0; $product_batch_current_count = $product_batch_current_count > 0 ? $product_batch_current_count : 0; $product_batch_also_count = ($product_batch_also_count - $product_batch_current_count) > 0 ? $product_batch_also_count - $product_batch_current_count : 0; $list[$index]['product_batch_total_count'] = $product_batch_total_count; $list[$index]['product_batch_current_count'] = $product_batch_current_count; $list[$index]['product_batch_also_count'] = $product_batch_also_count; $list[$index]['product_batch_list'] = $product_batch_list; } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $list, ], ]; } }