* @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; } }