| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 | <?php/** * DayModel.php UTF-8 * 每日数据 * * @date    : 2018/2/6 23:16 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : wuyonghong <wyh@huosdk.com> * @version : HUOSDK 8.0 */namespace huo\model\data;class DayModel extends DayBaseModel {    #protected $name = 'day';    protected $table = 'dw_day';    /**     * 根据日期获取     *     * @param string $field      字段,包括别名     * @param string $start_date 开始日期     * @param string $end_date   结束日期     *     * @param string  $alias 别名     *     * @return array     * @throws \think\db\exception\DataNotFoundException     * @throws \think\db\exception\ModelNotFoundException     * @throws \think\exception\DbException     */    public function getByDate($field, $start_date, $end_date, $alias = null) {        $alias or $alias = $field;        $_rows = $this->whereBetween('date', [$start_date, $end_date])                      ->field("date, $field")                      ->select()->toArray();        $_data = [];        foreach ($_rows as $_row) {            $_data[$_row['date']] = $_row[$alias];        }        $result = [];        for ($_i = strtotime($start_date); $_i <= strtotime($end_date); $_i += 24 * 3600) {            $_key = date('Y-m-d', $_i);            $result[date('m-d', $_i)] = isset($_data[$_key]) ? doubleval($_data[$_key]) : 0;        }        return $result;    }}
 |