1], [['limit'], 'default', 'value' => 20], ]; } public function search() { if (!$this->validate()) { return ['code' => 1, 'msg' => $this->getErrorSummary(false)[0]]; } if ($this->product_batch_id == 0){ $product_batch_process = ProductBatchProcess::find()->where(['process_user_id' => $this->user_id, 'is_delete' => 0, 'store_id' =>get_store_id() ]) ->orderBy("product_batch_id asc")->one(); $this->product_batch_id = $product_batch_process->product_batch_id; } $current_product_batch_info = ProductBatch::find()->alias('pb') ->leftJoin(['p' => Product::tableName()], 'p.id=pb.product_id') ->leftJoin(['g' => Goods::tableName()], 'g.id=pb.goods_id') ->where([ 'pb.is_delete' => 0, 'pb.store_id' => get_store_id(), 'pb.id' => $this->product_batch_id ])->select(['pb.*', 'p.product_name', 'g.name as goods_name'])->asArray()->one(); $query =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' => $this->product_batch_id ]) ->select(['pbp.*', 'pbpl.state',]); $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(); $product_list =ProductBatchProcess::find()->alias('pbp') ->innerJoin(['pb' => ProductBatch::tableName()], 'pb.id=pbp.product_batch_id') ->innerJoin(['p' => Product::tableName()], 'p.id=pb.product_id') ->where([ 'pbp.is_delete' => 0, 'pbp.store_id' => get_store_id(), 'pbp.process_user_id' => $this->user_id, ]) ->groupBy("pb.product_id") ->select(['p.id', 'p.product_name',])->asArray()->all(); foreach ($product_list as $k => $v) { $product_list[$k]['product_batch_list'] = ProductBatchProcess::find()->alias('pbp') ->innerJoin(['pb' => ProductBatch::tableName()], 'pb.id=pbp.product_batch_id') ->where([ 'pbp.is_delete' => 0, 'pbp.store_id' => get_store_id(), 'pbp.process_user_id' => $this->user_id, 'pb.product_id' => $v['id'], ]) ->groupBy("pbp.product_batch_id") ->select(['pb.id', 'pb.batch_name',])->asArray()->all(); } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'row_count' => $count, 'page_count' => $pagination->pageCount, 'list' => $list, 'current_product_batch_info' => $current_product_batch_info, 'product_list' => $product_list, ], ]; } }