<?php

namespace app\common\model;

use think\Model;

class Ex extends Model
{

    // 表名
    protected $name = 'ex';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
    ];
    //统计订单量和订单金额
    public static function Orders($popularize_id)
    {
        $totalPrice = 0;
        $totalCount = 0;
        if ($popularize_id <= 0){
            $data = [
                "totalPrice" => $totalPrice,
                "totalCount" => $totalCount,
            ];
            return $data;
        }

        $orderlist = self::field("name12")->where('name8', $popularize_id)->select();

        foreach ($orderlist as $k => $v) {
          $totalPrice += $v["name12"];
        }
        $totalCount = count($orderlist);
        $data = [
            "totalPrice" => $totalPrice,
            "totalCount" => $totalCount,
        ];
        return $data;
    }

}
