1000) { $distance = round($distance / 1000, 2) . 'km'; } else { $distance .= 'm'; } return $distance; } /** * 获取未过期且有使用次数的核销卡 * @param $ids * @return array */ public static function getVerifyList($ids, $order = null, $goods_model=null) { $arr = []; $verify_card = VerifyCard::find() ->where(['in', 'id', $ids]) ->asArray() ->all(); if (!empty($verify_card) && is_array($verify_card)) { foreach ($verify_card as &$val) { $is_add = true; $val['account'] = ''; $val['password'] = ''; $account = VerifyCardAccount::find()->where(['store_id' => $val['store_id'], 'card_id' => $val['id'], 'status' => 0])->limit(1)->one(); if ($account) { $val['account'] = $account->account; $val['password'] = $account->password; } if ($val['type'] > 1) { $is_add = false; if ($account && $account->status == 0) { $is_add = true; } } $val['sale_status'] = 0; $val['sale_id'] = 0; $val['is_use'] = 0; if ($order) { if ($val['type'] == 1) { //判断时间 $after_sale_time = Option::get(OptionSetting::STORE_AFTER_SALE_TIME, get_store_id())['value']; $sale_time = time() - ($after_sale_time * 86400); //判断订单状态已经完成 if ($order->confirm_time <= $sale_time && $order->trade_status == 3 && $order->is_sale == 0) { $val['is_use'] = 1; } } $sale_info = VerifyCardSale::find()->where([ 'verify_card_id' => $val['id'], 'user_id' => $order->user_id, 'store_id' => $val['store_id'], 'goods_id' => $goods_model->id, ])->orderBy('id desc')->asArray()->one(); if ($sale_info) { $is_add = true; $val['sale_status'] = $sale_info['status']; $val['sale_id'] = $sale_info['id']; $val['video_status'] = $sale_info['video_status']; } } $dbcount = VerifyCardAccount::find()->where(['card_id' => $val['id']])->count(); if (($dbcount > $val['send_times'] || $val['num'] == 0) && $is_add) { $arr[] = $val; } } if (!empty($arr)) { foreach ($arr as $key => $value) { if ($value['date_type'] == 2) { if (intval($value['end_time'] < time())) { unset($arr[$key]); } } if (intval($value['is_delete']) == 1) { unset($arr[$key]); } } } return array_values($arr); } else { return []; } } public static function getDate() { // 当前日期 $defaultDate = date("Y-m-d"); // $first = 1 表示每周星期一为开始日期 0表示每周日为开始日期 $first = 1; // 获取当前周的第几天 周日是 0 周一到周六是 1 - 6 $w = date('w', strtotime($defaultDate)); // 获取本周开始日期,如果$w是0,则表示周日,减去 6 天 $week_start = date('Y-m-d', strtotime("$defaultDate -" . ($w ? $w - $first : 6) . ' days')); // 本周结束日期 $week_end = date('Y-m-d', strtotime("$week_start +6 days")); return [ 'start' => $week_start, 'end' => $week_end, 'date' => self::getDateFromRange($week_start, $week_end) ]; } /** * 获取时间段内的日期 * @param $start_date * @param $end_date * @return array */ public static function getDateFromRange($start_date, $end_date){ $s_timestamp = strtotime($start_date); $e_timestamp = strtotime($end_date); // 计算日期段内有多少天 $days = ($e_timestamp - $s_timestamp) / 86400 + 1; // 保存每天日期 $date = []; for ($i = 0; $i < $days; $i++){ $date[] = date('Y-m-d', $s_timestamp + (86400 * $i)); } return $date; } /** * 将用户名进行处理,中间用星号表示 * @param $user_name * @return string */ public static function substr_cut($user_name){ // 获取字符串长度 $strlen = mb_strlen($user_name, 'utf-8'); // 如果字符创长度小于2,不做任何处理 if ($strlen < 2){ return $user_name . '**'; } else { // mb_substr — 获取字符串的部分 $firstStr = mb_substr($user_name, 0, 1, 'utf-8'); $lastStr = mb_substr($user_name, -1, 1, 'utf-8'); // str_repeat — 重复一个字符串 return $strlen == 2 ? $firstStr . str_repeat('*', mb_strlen($user_name, 'utf-8') - 1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr; } } /** * 格式化数字 */ public static function float_number($number) { $length = strlen($number); // 数字长度 if ($length > 8) { // 亿单位 $str = substr_replace(strstr($number, substr($number, -7), ' '), '.', -1, 0) . "亿"; } else if ($length > 4) { // 万单位 // 截取前俩为 $str = substr_replace(strstr($number, substr($number, -3), ' '), '.', -1, 0) . "万"; } else { return $number; } return $str; } /** * 获取特殊时间 */ public static function getTime($time, $now_time){ $times = $now_time - $time; if ($times <= 60) { $str_time = '刚刚'; } else if ($times <= 60 * 60) { $str_time = round($times / 60) . '分钟前'; } elseif ($times <= 60 * 60 * 24) { $str_time = round($times / (60 * 60)) . '小时前'; } elseif ($times <= 60 * 60 * 48){ $str_time = '昨天'; } else { $str_time = date('m-d', $time); } return $str_time; } /** * 获得几天前,几小时前,几月前 * @param int $time 时间戳 * @param int $now_time 当前时间 * @param array $unit 时间单位 * @return bool|string */ public static function date_before($time, $now_time, $unit = null) { $time = intval($time); $unit = is_null($unit) ? ["年", "月", "星期", "天", "小时", "分钟", "秒"] : $unit; switch (true) { case $time < ($now_time - 31536000) : return floor(($now_time - $time) / 31536000) . $unit[0] . '前'; case $time < ($now_time - 2592000) : return floor(($now_time - $time) / 2592000) . $unit[1] . '前'; case $time < ($now_time - 604800) : return floor(($now_time - $time) / 604800) . $unit[2] . '前'; case $time < ($now_time - 86400) : return floor(($now_time - $time) / 86400) . $unit[3] . '前'; case $time < ($now_time - 3600) : return floor(($now_time - $time) / 3600) . $unit[4] . '前'; case $time < ($now_time - 60) : return floor(($now_time - $time) / 60) . $unit[5] . '前'; default : return floor($now_time - $time) . $unit[6] . '前'; } } }