/** * 获得一个品牌信息 接口 */ function get() { $id = filter::int($this->get->id); $brandModel = $this->model('brand'); $result = $brandModel->get($id); $result['logo'] = file::realpathToUrl($result['logo']); return new json(json::OK, NULL, $result); }
function getByRid($id) { $array = array(); $imgs = $this->where('rid=?', array($id))->select(); foreach ($imgs as $img) { $array[] = file::realpathToUrl($img); } return $array; }
/** * app获取滚动图接口 */ function getlist() { $carousel = $this->model('carousel'); $result = $carousel->select(); foreach ($result as &$carousel) { $carousel['pic'] = file::realpathToUrl($carousel['pic']); } return new json(json::OK, NULL, $result); }
/** * 遍历所有数据 * @param string $mode 其中图片的路径 * @return Ambigous <boolean, multitype:> */ function fetchAll($mode = 'path') { $result = $this->select(); if ($mode == 'url') { foreach ($result as &$carousel) { $carousel['pic'] = empty($carousel['pic']) ? '' : file::realpathToUrl($carousel['pic']); } } return $result; }
function fetchAll($start, $length) { $this->limit($start, $length); $this->orderby('message.time', 'desc'); $this->table('user', 'left join', 'message.uid=user.id'); $result = $this->select(); foreach ($result as &$message) { $message['gravatar'] = file::realpathToUrl($message['gravatar']); } return $result; }
/** * 根据产品数量 对品牌进行分组 * @return Ambigous <boolean, multitype:> */ function fetchByProduct($start, $length) { $this->where('close=?', array(0)); $this->limit($start, $length); $brand = $this->select(); $productModel = $this->model('product'); foreach ($brand as &$value) { $value['logo'] = file::realpathToUrl($value['logo']); $productModel->where('bid=?', array($value['id'])); $result = $productModel->select('count(*)'); $value['num'] = $result[0]['count(*)']; } usort($brand, function ($a, $b) { if ($a['num'] == $b['num']) { return 0; } return $a['num'] > $b['num'] ? -1 : 1; }); return $brand; }
/** * 临时文件上传通道 */ function image() { $file = $this->file->file; if (is_file($file)) { $width = $this->get->width; $height = $this->get->height; $width = empty($width) ? 640 : $width; $height = empty($height) ? 640 * 2 : $height; $image = new image(); $file = $image->resizeImage($file, $width, $height); if ($this->get->type == 'text') { return json_encode(array('code' => 1, 'result' => 'ok', 'body' => file::realpathToUrl($file))); } else { return new json(json::OK, NULL, file::realpathToUrl($file)); } } if ($this->get->type == 'text') { return json_encode(array('code' => 0, 'result' => '图片上传失败')); } else { return new json(json::PARAMETER_ERROR, '图片上传失败'); } }
/** * 上传国家图标 * @return string */ function flag() { $roleModel = $this->model('role'); if (login::admin() && $roleModel->checkPower($this->session->role, 'system', roleModel::POWER_UPDATE)) { $name = $this->post->name; $config = config('file'); $config->path = ROOT . '/application/assets/flag/'; $flag = $this->file->receive($_FILES['flag'], $config); if (empty($name) || !is_file($flag)) { return json_encode(array('code' => 2, 'result' => '国家名或者国家图标上传失败')); } $flagModel = $this->model('flag'); if ($flagModel->create($name, $flag)) { return json_encode(array('code' => 1, 'result' => 'ok', 'body' => file::realpathToUrl($flag))); } return json_encode(array('code' => 0, 'result' => '国家已经存在')); } return json_encode(array('code' => 3, 'result' => '权限不足')); }
/** * 根据用户名或手机号前3位搜索匹配的用户 */ function search() { $search = $this->get->telephone_or_username; $length = filter::int($this->get->length); $userModel = $this->model('user'); $user = $userModel->search($search, $length); foreach ($user as &$userinfo) { $userinfo['gravatar'] = file::realpathToUrl($userinfo['gravatar']); } return json_encode($user); }
/** * o2o统计 */ function statistics() { if (login::o2o()) { $timetype = empty($this->get->timetype) ? 'day' : $this->get->timetype; if (!in_array($timetype, array('day', 'week', 'month'))) { return new json(json::PARAMETER_ERROR, '日期范围错误'); } switch ($timetype) { case 'day': $time = $_SERVER['REQUEST_TIME'] - 24 * 3600; break; case 'week': $time = $_SERVER['REQUEST_TIME'] - 7 * 24 * 3600; break; case 'month': $time = $_SERVER['REQUEST_TIME'] - 30 * 24 * 3600; break; default: $time = $_SERVER['REQUEST_TIME']; break; } $userModel = $this->model('user'); $o2oModel = $this->model('o2ouser'); $rate = $o2oModel->get($this->session->id, 'rate'); //$status = array(orderlistModel::STATUS_CLOSE,orderlistModel::STATUS_REFUND,orderlistModel::STATUS_QUITE,orderlistModel::STATUS_PAYING); $status = array(0, 2, 3, 7); if ($this->get->form == 1) { $userModel->where('user.oid=?', array($this->session->id)); $userModel->table('orderlist', 'left join', 'orderlist.uid=user.id'); $userModel->table('orderdetail', 'left join', 'orderdetail.oid=orderlist.id'); $userModel->where('orderlist.status not in (?)', $status); $userModel->where('orderlist.tradetime>?', array($time)); $sale = $userModel->select('sum(orderdetail.num)'); $result['sale'] = number_format($sale[0]['sum(orderdetail.num)']); $userModel->where('user.oid=?', array($this->session->id)); $userModel->table('orderlist', 'left join', 'orderlist.uid=user.id'); $userModel->where('orderlist.status not in (?)', $status); $userModel->where('orderlist.tradetime>?', array($time)); $revenue = $userModel->select('sum(orderlist.ordertotalamount)'); $result['revenue'] = number_format($revenue[0]['sum(orderlist.ordertotalamount)'] * $rate, 2); $userModel->where('user.oid=?', array($this->session->id)); $usernum = $userModel->select('count(id)'); $userModel->where('user.regtime>?', array($time)); $result['usernum'] = number_format($usernum[0]['count(id)']); $userModel->where('user.oid=?', array($this->session->id)); $userModel->table('orderlist', 'left join', 'orderlist.uid=user.id'); $userModel->where('orderlist.status not in (?)', $status); $userModel->where('orderlist.createtime>?', array($time)); $ordernum = $userModel->select('count(orderlist.id)'); $result['ordernum'] = number_format($ordernum[0]['count(orderlist.id)']); $temp = array(); if ($this->get->timetype == 'month') { for ($i = 0; $i < 6; $i++) { $obj = array(); $year = date("Y"); //echo $year; $month = date("m"); $day = date("d"); if ($month - $i < 1) { $month += 12; $year--; } $starttime = strtotime($year . '-' . ($month - $i) . '-1 0:0:0'); $obj['period'] = $month - $i . '月'; //$endtime = strtotime($year.'-'.$month.'-1 0:0:0'); $endtime = strtotime('+1 month', $starttime); //echo date("Y-m-d H:i:s",$starttime).'=>'; //echo date("Y-m-d H:i:s",$endtime).'<br>'; $userModel->where('user.oid=?', array($this->session->id)); $userModel->table('orderlist', 'left join', 'orderlist.uid=user.id'); $userModel->table('orderdetail', 'left join', 'orderdetail.oid=orderlist.id'); $userModel->where('orderlist.status not in (?)', $status); $userModel->where('orderlist.tradetime>? and orderlist.tradetime<?', array($starttime, $endtime)); $sale = $userModel->select('sum(orderdetail.num)'); $obj['sales'] = number_format($sale[0]['sum(orderdetail.num)']); $userModel->where('user.oid=?', array($this->session->id)); $userModel->table('orderlist', 'left join', 'orderlist.uid=user.id'); $userModel->where('orderlist.status not in (?)', $status); $userModel->where('orderlist.tradetime>? and orderlist.tradetime<?', array($starttime, $endtime)); $revenue = $userModel->select('sum(orderlist.ordertotalamount)'); $obj['profit'] = number_format($revenue[0]['sum(orderlist.ordertotalamount)'] * $rate, 2); $temp[] = $obj; } } $result['detail'] = $temp; } else { if ($this->get->form == 2) { $userModel->where('user.oid=?', array($this->session->id)); $userModel->table('user_login_log', 'left join', 'user.id=user_login_log.uid'); $userModel->where('user_login_log.time>?', array($time)); $logintimes = $userModel->select('count(user_login_log.id)'); $result['logintimes'] = number_format($logintimes[0]['count(user_login_log.id)']); $userModel->where('user.oid=?', array($this->session->id)); $userModel->where('user.regtime>?', array($time)); $newuser = $userModel->select('count(id)'); $result['newuser'] = number_format($newuser[0]['count(id)']); $userModel->where('user.oid=?', array($this->session->id)); $userModel->table('orderlist', 'left join', 'orderlist.uid=user.id'); $userModel->where('orderlist.status not in (?)', $status); $userModel->groupby('user.id'); $parameter = 'user.id,user.username,user.gravatar,user.telephone,sum(orderlist.ordertotalamount) as sum,count(orderlist.id) as count,avg(orderlist.ordertotalamount) as avg'; $result['detail'] = $userModel->select($parameter); foreach ($result['detail'] as &$value) { $value['gravatar'] = file::realpathToUrl($value['gravatar']); } } } return new json(json::OK, NULL, $result); } return new json(json::NOT_LOGIN); }
/** * 订单详情页面 */ function information() { $id = filter::int($this->get->id); if (!empty($id)) { $orderModel = $this->model('orderlist'); $result = $orderModel->where('orderlist.id=?', array($id))->select(); $goods = $orderModel->getOrderDetail($id); foreach ($goods as &$product) { $product['img'] = $this->model('productimg')->getByPid($product['pid']); $product['origin'] = $this->model('flag')->get($product['origin'], 'name'); } if ($this->get->type === 'json') { $result['orderdetail'] = $goods; return json_encode(array('code' => 1, 'result' => 'ok', 'body' => $result)); } $roleModel = $this->model('role'); if (login::admin() && $roleModel->checkPower($this->session->role, 'orderlist', roleModel::POWER_ALL)) { $this->view = new view(config('view'), 'admin/order_information.html'); $this->view->assign('role', $roleModel->get($this->session->role)); $systemModel = $this->model('system'); $system = $systemModel->fetch('system'); $system = $systemModel->toArray($system, 'system'); $this->view->assign('system', $system); if (isset($result[0])) { $result[0]['gravatar'] = file::realpathToUrl($result[0]['gravatar']); $this->view->assign('order', $result[0]); $this->view->assign('goods', $goods); if (!empty($_SERVER['HTTP_REFERER'])) { $this->view->assign('last_page', $_SERVER['HTTP_REFERER']); } return $this->view->display(); } else { $this->response->setCode(302); $this->response->addHeader('Location', $this->http->url('admin', '__404')); } } else { $this->response->setCode(302); $this->response->addHeader('Location', $this->http->url('admin', 'index')); } } else { $this->response->setCode(302); $this->response->addHeader('Location', $this->http->url('index', '__404')); } }
/** * 接收微信消息 */ function router() { if (!empty($this->get->signature) && !empty($this->get->echostr) && !empty($this->get->timestamp) && !empty($this->get->nonce)) { $token = $this->model('system')->get('token', 'weixin'); if ($this->_wechat->checkSignature($this->get->signature, $this->get->timestamp, $this->get->nonce, $token)) { return $this->get->echostr; } } else { $data = $this->_wechat->getData(); if (empty($data)) { return new json(json::PARAMETER_ERROR, '错误的访问'); } switch (strtolower($data->MsgType)) { case 'event': switch (strtolower($data->Event)) { case 'subscribe': $eventKey = $data->EventKey; list($qrscene, $eventKey) = explode('_', $eventKey); if (strtolower($qrscene) == 'qrscene') { $eventKey = ltrim($eventKey, 0); } else { echo "扫码参数错误"; } break; case 'scan': $eventKey = ltrim($data->EventKey, 0); break; case 'click': switch ($data->EventKey) { case 'myeqcode': $openid = $data->FromUserName; //二维码保存地址 $file = ROOT . '/application/upload/' . md5($data->FromUserName) . '.jpg'; $userModel = $this->model('user'); $user = $userModel->getByOpenid($openid); if (empty($user)) { $uid = $userModel->registerWeiXin($openid); } else { $uid = $user['id']; } $access_token = $this->access_token(); $action = 'upload'; $type = 'image'; file_put_contents($file, $this->eqcode($uid)); $systemModel = $this->model('system'); $dist = $systemModel->fetch('dist'); $dist = $systemModel->toArray($dist, 'dist'); $eqcodebackground = $dist['eqcodebackground']; $eqcodebackground_x = isset($dist['eqcodebackgroundx']) ? $dist['eqcodebackgroundx'] : 0; $eqcodebackground_y = isset($dist['eqcodebackgroundy']) ? $dist['eqcodebackgroundy'] : 0; $eqcodesize = isset($dist['eqcodesize']) ? $dist['eqcodesize'] : 250; if (is_file($eqcodebackground)) { //给二维码增加背景图 $alpha = 100; $image = new image(); $image->water($eqcodebackground, $file, $eqcodebackground_x, $eqcodebackground_y, $alpha, $file, $eqcodesize, $eqcodesize); } $result = $this->_wechat->file($access_token, $action, $file, $type); $result = json_decode($result, true); if (isset($result['media_id'])) { return new xml(array('ToUserName' => $data->FromUserName, 'FromUserName' => $data->ToUserName, 'CreateTime' => $_SERVER['REQUEST_TIME'], 'MsgType' => 'image', 'Image' => array('MediaId' => $result['media_id'])), true, false); } else { return new xml(array('ToUserName' => $data->FromUserName, 'FromUserName' => $data->ToUserName, 'CreateTime' => $_SERVER['REQUEST_TIME'], 'MsgType' => 'text', 'Content' => '无法获取二维码')); } break; default: return new xml(array('ToUserName' => $data->FromUserName, 'FromUserName' => $data->ToUserName, 'CreateTime' => $_SERVER['REQUEST_TIME'], 'MsgType' => 'text', 'Content' => '尚未定义消息事件'), true, false); } break; default: return; } //扫码之后绑定oid和openid 只允许第一次 $openid = $data->FromUserName; $user = $this->model('user')->getByOpenid($openid); if (!empty($user)) { if (empty($user['oid'])) { if ($eventKey === $user['id']) { return new xml(array('ToUserName' => $data->FromUserName, 'FromUserName' => $data->ToUserName, 'CreateTime' => $_SERVER['REQUEST_TIME'], 'MsgType' => 'text', 'Content' => 'Sorry,您不能把自己做为自己的分销商哦')); } $this->model('user')->where('openid=?', array($openid))->update('oid', $eventKey); return new xml(array('ToUserName' => $data->FromUserName, 'FromUserName' => $data->ToUserName, 'CreateTime' => $_SERVER['REQUEST_TIME'], 'MsgType' => 'text', 'Content' => '恭喜,您已经成功入住,成为TA旗下的一份子了'), true, false); } else { return new xml(array('ToUserName' => $data->FromUserName, 'FromUserName' => $data->ToUserName, 'CreateTime' => $_SERVER['REQUEST_TIME'], 'MsgType' => 'text', 'Content' => '您已经有了上级分销商了'), true, false); } } else { return new xml(array('ToUserName' => $data->FromUserName, 'FromUserName' => $data->ToUserName, 'CreateTime' => $_SERVER['REQUEST_TIME'], 'MsgType' => 'text', 'Content' => '尚未注册或绑定账号,请点此注册或登陆' . $this->http->url('mobile', 'login')), true, false); } break; case 'text': $tid = trim($data->Content); $themeModel = $this->model('theme'); $theme = $themeModel->get($tid); if (!empty($theme)) { return new xml(array('ToUserName' => $data->FromUserName, 'FromUserName' => $data->ToUserName, 'CreateTime' => $_SERVER['REQUEST_TIME'], 'MsgType' => 'news', 'ArticleCount' => 1, 'Articles' => array('item' => array('Title' => $theme['name'], 'Description' => $theme['description'], 'PicUrl' => file::realpathToUrl($theme['middlepic']), 'Url' => $this->http->url('mobile', 'themeDetail', array('id' => $tid))))), true, false); } break; default: //处理无法请求的事件 return file_get_contents('http://www.baidu.com'); } } }
/** * 添加一张图片信息 * * @param unknown $base * 基础图像地址 * @param unknown $small * 小图地址 * @param unknown $thumbnail * 缩略图地址 * @param string $pid * @return array|false 插入成功返回插入的所有信息 失败false */ function add($oldimage, $base, $small, $thumbnail, $title, $orderby = 1, $pid = 0) { $data = array(NULL, $pid, $title, $orderby, $oldimage, $base, $small, $thumbnail); $result = $this->insert($data); if ($result) { $data[0] = $this->lastInsertId(); $data[5] = file::realpathToUrl($data[5]); $data[6] = file::realpathToUrl($data[6]); $data[7] = file::realpathToUrl($data[7]); return $data; } return false; }
/** * ajax获取某商品下的评论 */ function ajaxcomment() { $resultObj = new \stdClass(); $resultObj->draw = $this->post->draw; $commentModel = $this->model('comment'); $pid = filter::int($this->get->pid); $result = $commentModel->searchable($this->post, $pid); $resultObj->recordsFiltered = count($result); $result = array_slice($result, $this->post->start, $this->post->length); $count = $commentModel->select('count(*)'); $resultObj->recordsTotal = isset($count[0]['count(*)']) ? $count[0]['count(*)'] : 0; foreach ($result as &$comment) { $img = $this->model('comment_pic')->getByCid($comment['id'], 'url'); foreach ($img as &$pic) { $pic = file::realpathToUrl($pic); } $comment['img'] = $img; } $resultObj->data = $result; return json_encode($resultObj); }
/** * 获取订单商品信息 */ function getOrderDetail($id) { $orderdetailModel = $this->model('orderdetail'); $result = $orderdetailModel->where('oid=?', array($id))->select(); $productimgModel = $this->model('productimg'); foreach ($result as &$goods) { $img = $productimgModel->limit(1)->orderby('orderby', 'desc')->where('pid=?', array($goods['pid']))->select(); if (isset($img[0]['thumbnail_path'])) { $goods['img'] = file::realpathToUrl($img[0]['thumbnail_path']); } } return $result; }
/** * 保存对主题的修改 */ function save() { $this->response->addHeader('Content-Type', 'application/json'); $roleModel = $this->model('role'); if (login::admin() && $roleModel->checkPower($this->session->role, 'theme', roleModel::POWER_UPDATE)) { $id = $this->post->id; $name = $this->post->name; $description = $this->post->description; $orderby = $this->post->orderby; $bigpic = $this->file->bigpic; $middlepic = $this->file->middlepic; $smallpic = $this->file->smallpic; $themeModel = $this->model('theme'); if (empty($id)) { return json_encode(array('code' => 2, 'result' => '空id')); } if ($name !== NULL) { $themeModel->where('id=?', array($id))->update('name', $name); $body = $name; } if ($description !== NULL) { $themeModel->where('id=?', array($id))->update('description', $description); $body = $description; } if ($orderby !== NULL) { $themeModel->where('id=?', array($id))->update('orderby', $orderby); $body = $orderby; } $image = new image(); if (is_file($bigpic)) { $bigpic = $image->resizeImage($bigpic, 640, 280); $themeModel->where('id=?', array($id))->update('bigpic', $bigpic); $body = file::realpathToUrl($bigpic); } if (is_file($middlepic)) { $middlepic = $image->resizeImage($middlepic, 320, 260); $themeModel->where('id=?', array($id))->update('middlepic', $middlepic); $body = file::realpathToUrl($middlepic); } if (is_file($smallpic)) { $smallpic = $image->resizeImage($smallpic, 320, 130); $themeModel->where('id=?', array($id))->update('smallpic', $smallpic); $body = file::realpathToUrl($smallpic); } return json_encode(array('code' => 1, 'result' => 'ok', 'body' => $body)); } return json_encode(array('code' => 0, 'result' => '没有权限')); }