| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?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\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\utils\Tools;
- use yii\base\Model;
- use yii\data\Pagination;
- use yii\helpers\Json;
- use yii\helpers\Json as HelpersJson;
- class MyProductProcessForm extends Model
- {
- public $store_id;
- public $user_id;
- public $page;
- public $limit;
- public function rules()
- {
- return [
- [['store_id', 'user_id'], 'required'],
- [['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]];
- }
- $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,
- ],
- ];
- }
- }
|