ProductBatchProcessLogHistoryForm.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\plugins\product_traceability\models\client;
  8. use app\models\Goods;
  9. use app\models\OrderRefund;
  10. use app\models\SaasUser;
  11. use app\models\Shop;
  12. use app\models\Store;
  13. use app\models\User;
  14. use app\plugins\food\models\FoodOrderDetail;
  15. use app\plugins\product_traceability\models\Product;
  16. use app\plugins\product_traceability\models\ProductBatch;
  17. use app\plugins\product_traceability\models\ProductBatchProcess;
  18. use app\plugins\product_traceability\models\ProductBatchProcessLog;
  19. use app\plugins\product_traceability\models\ProductBatchProcessLogSheet;
  20. use app\plugins\product_traceability\models\ProductBatchProcessSheet;
  21. use app\utils\Tools;
  22. use yii\base\Model;
  23. use yii\data\Pagination;
  24. use yii\db\Query;
  25. use yii\helpers\Json;
  26. use yii\helpers\Json as HelpersJson;
  27. class ProductBatchProcessLogHistoryForm extends Model
  28. {
  29. public $store_id;
  30. public $user_id;
  31. public $product_batch_id;
  32. public $page;
  33. public $limit;
  34. public function rules()
  35. {
  36. return [
  37. [['store_id', 'user_id', 'product_batch_id'], 'integer'],
  38. [['page', 'limit'], 'integer'],
  39. [['page'], 'default', 'value' => 1],
  40. [['limit'], 'default', 'value' => 20],
  41. ];
  42. }
  43. public function search()
  44. {
  45. if (!$this->validate()) {
  46. return ['code' => 1, 'msg' => $this->getErrorSummary(false)[0]];
  47. }
  48. if ($this->product_batch_id == 0){
  49. $product_batch_process = ProductBatchProcess::find()->where(['process_user_id' => $this->user_id, 'is_delete' => 0, 'store_id' =>get_store_id() ])
  50. ->orderBy("product_batch_id asc")->one();
  51. $this->product_batch_id = $product_batch_process->product_batch_id;
  52. }
  53. $current_product_batch_info = ProductBatch::find()->alias('pb')
  54. ->leftJoin(['p' => Product::tableName()], 'p.id=pb.product_id')
  55. ->leftJoin(['g' => Goods::tableName()], 'g.id=pb.goods_id')
  56. ->where([
  57. 'pb.is_delete' => 0,
  58. 'pb.store_id' => get_store_id(),
  59. 'pb.id' => $this->product_batch_id
  60. ])->select(['pb.*', 'p.product_name', 'g.name as goods_name'])->asArray()->one();
  61. $query =ProductBatchProcess::find()->alias('pbp')
  62. ->innerJoin(['pbpl' => ProductBatchProcessLog::tableName()], 'pbp.id=pbpl.product_batch_process_id')
  63. ->where([
  64. 'pbp.is_delete' => 0,
  65. 'pbp.store_id' => get_store_id(),
  66. 'pbp.product_batch_id' => $this->product_batch_id
  67. ])
  68. ->select(['pbp.*', 'pbpl.state',]);
  69. $count = $query->count();
  70. $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
  71. $list = $query->limit($pagination->limit)->offset($pagination->offset)->asArray()->all();
  72. $product_list =ProductBatchProcess::find()->alias('pbp')
  73. ->innerJoin(['pb' => ProductBatch::tableName()], 'pb.id=pbp.product_batch_id')
  74. ->innerJoin(['p' => Product::tableName()], 'p.id=pb.product_id')
  75. ->where([
  76. 'pbp.is_delete' => 0,
  77. 'pbp.store_id' => get_store_id(),
  78. 'pbp.process_user_id' => $this->user_id,
  79. ])
  80. ->groupBy("pb.product_id")
  81. ->select(['p.id', 'p.product_name',])->asArray()->all();
  82. foreach ($product_list as $k => $v) {
  83. $product_list[$k]['product_batch_list'] = ProductBatchProcess::find()->alias('pbp')
  84. ->innerJoin(['pb' => ProductBatch::tableName()], 'pb.id=pbp.product_batch_id')
  85. ->where([
  86. 'pbp.is_delete' => 0,
  87. 'pbp.store_id' => get_store_id(),
  88. 'pbp.process_user_id' => $this->user_id,
  89. 'pb.product_id' => $v['id'],
  90. ])
  91. ->groupBy("pbp.product_batch_id")
  92. ->select(['pb.id', 'pb.batch_name',])->asArray()->all();
  93. }
  94. return [
  95. 'code' => 0,
  96. 'msg' => 'success',
  97. 'data' => [
  98. 'row_count' => $count,
  99. 'page_count' => $pagination->pageCount,
  100. 'list' => $list,
  101. 'current_product_batch_info' => $current_product_batch_info,
  102. 'product_list' => $product_list,
  103. ],
  104. ];
  105. }
  106. }