| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\product_traceability\models\client;
- use app\models\Goods;
- use app\models\OrderRefund;
- use app\models\SaasUser;
- use app\models\Shop;
- use app\models\Store;
- use app\models\User;
- use app\plugins\food\models\FoodOrderDetail;
- use app\plugins\product_traceability\models\Product;
- use app\plugins\product_traceability\models\ProductBatch;
- use app\plugins\product_traceability\models\ProductBatchProcess;
- use app\plugins\product_traceability\models\ProductBatchProcessLog;
- use app\plugins\product_traceability\models\ProductBatchProcessLogSheet;
- use app\plugins\product_traceability\models\ProductBatchProcessSheet;
- use app\utils\Tools;
- use yii\base\Model;
- use yii\data\Pagination;
- use yii\db\Query;
- use yii\helpers\Json;
- use yii\helpers\Json as HelpersJson;
- class ProductBatchProcessLogHistoryForm extends Model
- {
- public $store_id;
- public $user_id;
- public $product_batch_id;
- public $page;
- public $limit;
- public function rules()
- {
- return [
- [['store_id', 'user_id', 'product_batch_id'], 'integer'],
- [['page', 'limit'], 'integer'],
- [['page'], 'default', 'value' => 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,
- ],
- ];
- }
- }
|