|
|
@@ -7,6 +7,7 @@ use app\common\model\ShopList;
|
|
|
use app\common\model\StockLog;
|
|
|
use think\exception\ValidateException;
|
|
|
use app\api\validate\Stock as StockValidate;
|
|
|
+use app\common\model\StockDetail;
|
|
|
use think\facade\Db;
|
|
|
|
|
|
class Index extends Base
|
|
|
@@ -25,17 +26,35 @@ class Index extends Base
|
|
|
}
|
|
|
|
|
|
//库存统计
|
|
|
- public function statistics(StockConfig $stockConfig)
|
|
|
- {
|
|
|
- $list = $stockConfig->alias('a')->where('a.status', $stockConfig::StatusNormal)
|
|
|
- ->leftjoin('stock_detail b', 'a.id = b.key')
|
|
|
- ->field('a.id, a.type_id,a.title,b.num')
|
|
|
-
|
|
|
- ->select();
|
|
|
-
|
|
|
- dump($list->toArray());die;// StockConfig::Status::NORMAL
|
|
|
-
|
|
|
- $this->success('ok', $list);
|
|
|
+ public function statistics(StockConfig $stockConfig, StockDetail $stockDetail)
|
|
|
+ {
|
|
|
+ $result = [];
|
|
|
+ $list = $stockConfig->where('status', $stockConfig::StatusNormal)->field('id,type_id,title')
|
|
|
+ ->orderRaw("field('variety_name','packing_box','material')")->select();
|
|
|
+ foreach ($list as $item) {
|
|
|
+ switch ($item['type_id']) {
|
|
|
+ case $stockConfig::VarietyName:
|
|
|
+ $result['variety_name'][] = [
|
|
|
+ 'name' => $item->title,
|
|
|
+ 'num' => $stockDetail->where('key', $item['id'])->value('num')
|
|
|
+ ];
|
|
|
+ break;
|
|
|
+ case $stockConfig::PackingBox:
|
|
|
+ $result['packing_box'][] = [
|
|
|
+ 'name' => $item->title,
|
|
|
+ 'num' => $stockDetail->where('key', $item['id'])->value('num')
|
|
|
+ ];
|
|
|
+ break;
|
|
|
+ case $stockConfig::Material:
|
|
|
+ $result['material'][] = [
|
|
|
+ 'name' => $item->title,
|
|
|
+ 'num' => $stockDetail->where('key', $item['id'])->value('num')
|
|
|
+ ];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success('ok', $result);
|
|
|
}
|
|
|
|
|
|
|