tp6框架的销售统计系统

Goods.php 1.1KB

    <?php namespace app\model; use think\model\concern\SoftDelete; use app\model\facade\GoodsCategory; class Goods extends \think\Model { protected $schema = [ 'id' => 'int', 'category_id' => 'int', 'category_name' => 'string', 'name' => 'string', 'price' => 'int', // 单位分 'type' => 'int', // 提成类别 'create_time' => 'int', 'is_del' => 'int' ]; use SoftDelete; protected $deleteTime = 'is_del'; protected $defaultSoftDelete = 0; public function getGoodsSubtotal() { $list = $this->order('id')->field('id,category_id,category_name,name,price')->select(); $goodsCategories = GoodsCategory::getGoodsCategories(); $data = []; foreach ($goodsCategories as $key => $val) { $data[$key] = ['goods_category_name'=>$val, 'items'=>[]]; foreach ($list as $value) { // var_dump($value->category_id); if ($key==$value->category_id) { array_push($data[$key]['items'], $value); } } } return $data; } }