public static function help_edit($data) { if (!isset($data['name']) || $data['name'] === null || !preg_match('!^.{1,50}$!u', $data['name'])) { return array('flag' => false, 'data' => '标题不能为空,且不能超过50个文字'); } $data['name'] = htmlspecialchars($data['name'], ENT_QUOTES); if (!isset($data['cat_id']) || $data['cat_id'] === null) { return array('flag' => false, 'data' => '分类不能为空'); } $data['cat_id'] = intval($data['cat_id']); $data['content'] = strval($data['content']); $data['content'] = addslashes($data['content']); $data['sort'] = abs(intval($data['sort'])); $id = $data['id']; unset($data['id']); $tb_help = new IModel("help"); $tb_help->setData($data); if ($id === null) { $data['dateline'] = ITime::getNow(); $tb_help->setData($data); $tb_help->add(); } else { $tb_help->update("id={$id}"); } return array('flag' => true, 'data' => 'success'); }
/** * @brief 自定时间格式散列,书写与date()函数相同 当$rand 为false时生成format的散列,为true时生成format+5位随机数的散列,这也是默认方式 * @param string $format 默认是 Y/m/d/His * @param bool $rand true加5位随机数,false 不加随机数 默认为true * @return String */ public static function time($format = 'Y/m/d/His', $rand = true) { if ($rand) { return ITime::getNow($format) . rand(10000, 99999); } else { return ITime::getNow($format); } }
/** * @brief 日期的智能处理 * @param string $start 开始日期 Y-m-d * @param string $end 结束日期 Y-m-d */ public static function dateParse($start = '', $end = '') { //默认没有时间条件,查询之前7天的数据 if (!$start && !$end) { $diffSec = 86400 * 6; $beforeDate = ITime::pass(-$diffSec, self::$format); return array($beforeDate, ITime::getNow(self::$format)); } //有时间条件 if ($start && $end) { return array($start, $end); } else { if ($start) { return array($start, $start); } else { if ($end) { return array($end, $end); } } } }
/** * @brief 获取当前时间段正在使用的广告数据 * @param $position int 广告位ID * @param $goods_cat_id 商品分类ID * @return array */ public static function getAdList($position, $goods_cat_id = 0) { $now = date("Y-m-d H:i:s", ITime::getNow()); $adDB = new IModel("ad_manage"); return $adDB->query("position_id={$position} and goods_cat_id = {$goods_cat_id} and start_time < '{$now}' AND end_time > '{$now}' ORDER BY `order` ASC "); }
<td>¥<?php echo $item['sell_price'] - $item['regiment_price']; ?> </td> </tr> </tbody> </table> </div> <?php if ($item['store_nums'] > $item['sum_count']) { ?> <div class="orange_box"> <p>团购倒计时:</p> <?php $free_time = strtotime($item['end_time']) - ITime::getNow(); ?> <p class="t_c f14"><span id="cd_hour_<?php echo isset($item['id']) ? $item['id'] : ""; ?> " class="red2 bold"><?php echo floor($free_time / 3600); ?> </span>小时<span id="cd_minute_<?php echo isset($item['id']) ? $item['id'] : ""; ?> " class="red2 bold"><?php echo floor($free_time % 3600 / 60); ?> </span>分钟<span id="cd_second_<?php echo isset($item['id']) ? $item['id'] : "";
function integral() { /*获取积分增减的记录日期时间段*/ $this->historyTime = IFilter::string(IReq::get('history_time', 'post')); $defaultMonth = 3; //默认查找最近3个月内的记录 $lastStamp = ITime::getTime(ITime::getNow('Y-m-d')) - 3600 * 24 * 30 * $defaultMonth; $lastTime = ITime::getDateTime('Y-m-d', $lastStamp); if ($this->historyTime != null && $this->historyTime != 'default') { $historyStamp = ITime::getDateTime('Y-m-d', $lastStamp - 3600 * 24 * 30 * $this->historyTime); $this->c_datetime = 'datetime >= "' . $historyStamp . '" and datetime < "' . $lastTime . '"'; } else { $this->c_datetime = 'datetime >= "' . $lastTime . '"'; } $memberObj = new IModel('member'); $where = 'user_id = ' . $this->user['user_id']; $this->memberRow = $memberObj->getObj($where, 'point'); $this->redirect('integral', false); }
function ad_list() { $data = array('flag' => false, 'data' => ''); $id = IReq::get('id'); if ($id === null) { die(JSON::encode($data)); } $id = intval($id); $now = date("Y-m-d H:i:s", ITime::getNow()); $tb = new IModel("ad_manage"); $re = $tb->query("position_id={$id} AND start_time < '{$now}' AND end_time > '{$now}' ORDER BY `order` ASC "); if (!$re) { echo JSON::encode($data); die; } $data['flag'] = true; $data['data'] = $re; echo JSON::encode($data); die; }
/** * @brief 进行商品评论 ajax操作 */ public function comment_add() { if (!isset($this->user['user_id']) || $this->user['user_id'] === null) { die("未登录用户不能评论"); } if (IReq::get('id') === null) { die("传递的参数不完整"); } $id = IFilter::act(IReq::get('id'), 'int'); $data = array(); $data['point'] = IFilter::act(IReq::get('point'), 'float'); $data['contents'] = IFilter::act(IReq::get("contents"), 'content'); $data['status'] = 1; if ($data['point'] == 0) { die("请选择分数"); } $can_submit = Comment_Class::can_comment($id, $this->user['user_id']); if ($can_submit[0] != 1) { die("您不能评论此件商品"); } $data['comment_time'] = date("Y-m-d", ITime::getNow()); $tb_comment = new IModel("comment"); $tb_comment->setData($data); $re = $tb_comment->update("id={$id}"); if ($re) { //同步更新goods表,comments,grade $commentRow = $tb_comment->getObj('id = ' . $id); $goodsDB = new IModel('goods'); $goodsDB->setData(array('comments' => 'comments + 1', 'grade' => 'grade + ' . $commentRow['point'])); $goodsDB->update('id = ' . $commentRow['goods_id'], array('grade', 'comments')); echo "success"; } else { die("评论失败"); } }
/** * 整理从regiment表里提出的数据 * * 将会对每一行记录加上或整理以下索引的数据 * <ul> * <li>user_num,已报名人数</li> * <li>valid,本次团购是否还接受报名</li> * <li>sell_price,原价,整理成100.21的形式</li> * <li>regiment_price,团购价,整理成100.21的形式</li> * <li>discount,折扣</li> * </ul> * * @param array $list * @return array $list * @static */ public static function ps($list) { $list = Util::array_rekey($list, 'id'); if ($list) { //获取各个团购的已参与人数 $ids = array_keys($list); $ids = implode(",", $ids); $tb = new IModel("regiment_user_relation"); $time_limit = self::time_limit(); $join_time = ITime::getNow() - 60 * $time_limit; $join_time = date("Y-m-d H:i:s", $join_time); $user_relation = $tb->query("regiment_id IN ({$ids}) AND join_time>'{$join_time}' GROUP BY regiment_id ", " COUNT(*) AS num,regiment_id"); $user_relation = Util::array_rekey($user_relation, "regiment_id"); $now = time(); foreach ($list as $key => $value) { $list[$key]['valid'] = true; $list[$key]['user_num'] = isset($user_relation[$value['id']]) ? $user_relation[$value['id']]['num'] : 0; if (0 != $value['store_nums'] && $list[$key]['user_num'] >= $value['store_nums']) { $list[$key]['valid'] = false; } $tmp_time = strtotime($list[$key]['end_time']); if ($tmp_time < $now) { $list[$key]['valid'] = false; } $list[$key]['sell_price'] = round($value['sell_price'], 2); //原价 $list[$key]['regiment_price'] = round($value['regiment_price'], 2); //团购价 if ($value['regiment_price'] === round(0, 2)) { $list[$key]['discount'] = 0; } else { if ($list[$key]['sell_price'] == round(0, 2)) { $list[$key]['discount'] = 0; } else { $list[$key]['discount'] = $list[$key]['regiment_price'] / $list[$key]['sell_price'] * 10; $list[$key]['discount'] = round($list[$key]['discount'], 1); } } } } return $list; }