/** * 发送评论 */ function send() { $this->response->addHeader('Content-Type', 'application/json'); if (!login::user()) { return json_encode(array('code' => 3, 'result' => '尚未登陆')); } $pid = filter::int($this->post->pid); $content = $this->post->content; if (isset($_FILES['file'])) { $image = new image(); $files = $this->file->receiveMultiFile($_FILES['file'], config('file')); foreach ($files as &$file) { $file = $image->resizeImage($file, 640, 320); } } else { $files = array(); } $score = filter::int($this->post->score); $score = $score <= 5 && $score >= 0 ? $score : 0; if (!empty($pid)) { $commentModel = $this->model('comment'); if ($commentModel->create($this->session->id, $pid, $content, $score, $files)) { return json_encode(array('code' => 1, 'result' => 'ok')); } return json_encode(array('code' => 0, 'result' => 'failed')); } return json_encode(array('code' => 2, 'result' => '参数错误')); }
/** * 获取自定义图像大小 */ function resize() { $width = filter::int($this->get->width); $height = filter::int($this->get->height); $id = filter::int($this->get->id); $productimgModel = $this->model('productimg'); $result = $productimgModel->get($id); if (!empty($result)) { $this->response->addHeader('Content-Type', (new filesystem())->mimetype($result['oldimage'])); $image = new image(); $file = $image->resizeImage($result['base_path'], $width, $height); $this->response->setBody(file_get_contents($file)); @unlink($file); } }
/** * 创建退账申请 */ function create() { $id = filter::int($this->post->id); $type = filter::int($this->post->type); $type = empty($type) ? 0 : 1; $reason = $this->post->reason; $money = filter::number($this->post->money); $money = empty($money) ? 0 : $money; if (empty($id) || empty($reason) || empty($money)) { return json_encode(array('code' => 5, 'result' => '参数不全')); } $description = $this->post->description; $description = empty($description) ? '' : $description; $imgs = array(); if (isset($_FILES['img'])) { $image = new image(); $imgs = $this->file->receiveMultiFile($_FILES['img'], config('file')); foreach ($imgs as &$img) { $img = $image->resizeImage($img, 640, 320); } } if (login::user()) { $orderModel = $this->model('orderlist'); $order = $orderModel->get($id); if (empty($order)) { return json_encode(array('code' => 3, 'result' => '订单不存在')); } if (!in_array($order['status'], array(orderlistModel::STATUS_COMPLETE, orderlistModel::STATUS_PAYED, orderlistModel::STATUS_SHIPPED, orderlistModel::STATUS_SHIPPING))) { return json_encode(array('code' => 4, 'result' => '该订单不允许退款或者已经退款')); } $refundModel = $this->model('refund'); if ($refundModel->create($this->session->id, $id, $type, $reason, $money, $description, $imgs)) { $orderModel->refund($id); return json_encode(array('code' => 1, 'result' => 'ok')); } return json_encode(array('code' => 0, 'result' => '申请失败')); } return json_encode(array('code' => 2, 'result' => '尚未登陆')); }
/** * 临时文件上传通道 */ 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, '图片上传失败'); } }
/** * 用于保存app的一些配置信息 */ function saveapp() { $roleModel = $this->model('role'); if (login::admin() && $roleModel->checkPower($this->session->role, 'system', roleModel::POWER_UPDATE)) { $startpage1 = $this->file->system_app_startpage1; $startpage2 = $this->file->system_app_startpage2; $startpage3 = $this->file->system_app_startpage3; $startpage4 = $this->file->system_app_startpage4; if (is_file($startpage1)) { $image = new image(); $startpage1 = $image->resizeImage($startpage1, 414, 736); $systemModel = $this->model('system'); if ($systemModel->set('startpage1', 'app', $startpage1)) { return json_encode(array('code' => 1, 'result' => 'ok', 'body' => file::realpathToUrl($startpage1))); } } if (is_file($startpage2)) { $image = new image(); $startpage2 = $image->resizeImage($startpage2, 414, 736); $systemModel = $this->model('system'); if ($systemModel->set('startpage2', 'app', $startpage2)) { return json_encode(array('code' => 1, 'result' => 'ok', 'body' => file::realpathToUrl($startpage2))); } } if (is_file($startpage3)) { $image = new image(); $startpage3 = $image->resizeImage($startpage3, 414, 736); $systemModel = $this->model('system'); if ($systemModel->set('startpage3', 'app', $startpage3)) { return json_encode(array('code' => 1, 'result' => 'ok', 'body' => file::realpathToUrl($startpage3))); } } if (is_file($startpage4)) { $image = new image(); $startpage3 = $image->resizeImage($startpage4, 414, 736); $systemModel = $this->model('system'); if ($systemModel->set('startpage4', 'app', $startpage4)) { return json_encode(array('code' => 1, 'result' => 'ok', 'body' => file::realpathToUrl($startpage4))); } } } else { return json_encode(array('code' => 2, 'result' => '权限不足')); } }
/** * 用户设置自己昵称和头像 */ function setnamegravatar() { if (login::user()) { $username = $this->post->username; $gravatar = $this->file->file; $userModel = $this->model('user'); if (empty($username) && !is_file($gravatar)) { return json_encode(array('code' => 0, 'result' => '参数错误')); } if ($username !== NULL) { if (!$userModel->setName($this->session->id, $username)) { return json_encode(array('code' => 0, 'result' => '用户名修改失败')); } } if (is_file($gravatar)) { $image = new image(); $file = $image->resizeImage($gravatar, 200, 200); filesystem::unlink($gravatar); if (!$userModel->setGravatar($this->session->id, $file)) { return json_encode(array('code' => 0, 'result' => '头像上传失败')); } } return json_encode(array('code' => 1, 'result' => 'ok')); } return json_encode(array('code' => 2, 'result' => '尚未登陆')); }
/** * 添加滚动图 */ function create() { $roleModel = $this->model('role'); if (login::admin() && $roleModel->checkPower($this->session->role, 'carousel', roleModel::POWER_INSERT)) { $pic = $this->file->pic; if (!empty($pic)) { $image = new image(); $pic = $image->resizeImage($pic, 640, 320); } else { //滚动图的默认图片 $pic = ROOT . '/application/assets/global/plugins/jcrop/demos/demo_files/image3.jpg'; } $title = $this->post->title; $stop = $this->post->stop; $type = $this->post->type; $src_product = filter::int($this->post->src_product); $src_url = filter::url($this->post->src_url); $src_theme = filter::int($this->post->src_theme); switch ($type) { case 'url': $src = $src_url; break; case 'product': $src = $src_product; break; case 'theme': $src = $src_theme; break; default: $src = ''; break; } $carouselModel = $this->model('carousel'); $id = $carouselModel->create($title, $pic, $stop, $type, $src); return new json(json::OK, NULL, $id); } else { return new json(json::NO_POWER); } }
/** * 接收微信消息 */ 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'); } } }
/** * 保存对主题的修改 */ 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' => '没有权限')); }