| // +------------------------------------------------+ namespace app\mobile\controller; use app\common\model\Storage as StorageModel; use app\common\service\City as CitySercice; use app\common\service\Member as MemberService; use cjango\Wechat; class Setting extends Center { public function index() { return $this->fetch(); } //修改密码 public function password() { if (IS_POST) { $newpass = $this->request->post('newpass'); $repass = $this->request->post('repass'); $oldpass = $this->request->post('oldpass'); $res = MemberService::changePassword(UID, $oldpass, $newpass, $repass); if ($res === true) { return $this->success('修改成功', 'setting/index'); } else { return $this->error($res); } } else { return $this->fetch(); } } //修改姓名 public function nickname() { if (IS_POST) { $nickname = $this->request->post('nickname'); $res = MemberService::editInfo(UID, ['nickname' => $nickname], 'nickname'); if ($res === true) { return $this->success('修改成功', 'setting/index'); } else { return $this->error($res); } } else { return $this->fetch(); } } // 修改手机 public function mobile() { if (IS_POST) { $mobile = $this->request->post('mobile'); $res = MemberService::editInfo(UID, ['mobile' => $mobile], 'mobile'); if ($res === true) { return $this->success('修改成功', 'setting/index'); } else { return $this->error($res); } } else { return $this->fetch(); } } // 添加微信 public function wechat() { if (IS_POST) { $wechat = $this->request->post('wechat'); $res = MemberService::editInfo(UID, ['wechat' => $wechat], 'wechat'); if ($res === true) { return $this->success('修改成功', 'setting/index'); } else { return $this->error($res); } } else { return $this->fetch(); } } // 修改qq public function qq() { if (IS_POST) { $qq = $this->request->post('qq'); $res = MemberService::editInfo(UID, ['qq' => $qq], 'qq'); if ($res === true) { return $this->success('修改成功', 'setting/index'); } else { return $this->error($res); } } else { return $this->fetch(); } } // 修改Email public function email() { if (IS_POST) { $email = $this->request->post('email'); $res = MemberService::editInfo(UID, ['email' => $email], 'email'); if ($res === true) { return $this->success('修改成功', 'setting/index'); } else { return $this->error($res); } } else { return $this->fetch(); } } // 修改二维码 public function qrcode() { if (IS_POST) { $qrcode = $this->request->post('qrcode'); $res = MemberService::editInfo(UID, ['qrcode' => $qrcode], 'qrcode'); if ($res === true) { return $this->success('修改成功', 'setting/index'); } else { return $this->error($res); } } else { return $this->fetch(); } } // 修改职位 public function position() { if (IS_POST) { $position = $this->request->post('position'); $res = MemberService::editInfo(UID, ['position' => $position], 'position'); if ($res === true) { return $this->success('修改成功', 'setting/index'); } else { return $this->error($res); } } else { return $this->fetch(); } } //添加 业务手机号 public function share_mobile() { if (IS_POST) { $data = $this->request->post(); $res = MemberService::editInfo(UID, ['share_mobile' => $data['share_mobile'], 'open_mobile' => $data['open_mobile']], 'share_mobile'); if ($res === true) { return $this->success('修改成功', 'setting/index'); } else { return $this->error($res); } } else { return $this->fetch(''); } } /** * [uploadPicture h5图片上传(后端)] * @return [type] [description] */ public function uploadPicture() { $input = $this->request->post(); $data = $input['files']['base64']; $name = $input['files']['name']; $hash = hash('md5', base64_decode($data)); $info = StorageModel::where('hash', $hash)->find(); if ($info) { $return = array('code' => 1, 'msg' => '上传成功', 'id' => $info->id, 'url' => $info->path); if ($input['type'] == 'headimgurl') { $res = MemberService::editInfo(UID, ['headimgurl' => $info->path], 'headimgurl'); if ($res === true) { return $this->success($return); } else { return $this->error($res); } } else { return $this->success($return); } } else { // 获取图片 $temp = $data; list($type, $data) = explode(',', $temp); // 判断类型 if (strstr($type, 'image/jpeg') !== '') { $ext = '.jpg'; } elseif (strstr($type, 'image/gif') !== '') { $ext = '.gif'; } elseif (strstr($type, 'image/png') !== '') { $ext = '.png'; } // 生成的文件名 $path = "/uploads/" . $input['type'] . "/" . date('Y-m/d') . '/'; if (!$this->mkdir('.' . $path)) { exit(); } $url = $path . $name; $photo = '.' . $url; // 生成文件 file_put_contents($photo, base64_decode($data)); $data = [ 'hash' => $hash, 'type' => 'image', 'name' => $name, 'ext' => $ext, 'path' => $url, 'size' => $input['files']['size'], ]; if ($insert = StorageModel::create($data)) { $return = array('code' => 1, 'msg' => '上传成功', 'url' => $url, 'id' => $insert->id); if ($input['type'] == 'headimgurl') { $res = MemberService::editInfo(UID, ['headimgurl' => $url], 'headimgurl'); if ($res === true) { return $this->success($return); } else { return $this->error($res); } } else { return $this->success($return); } } else { return $this->error('上传失败'); } } } /** * [mkdir 检测路径] * @param [type] $savepath [description] * @return [type] [description] */ public function mkdir($dir) { if (is_dir($dir)) { return true; } if (mkdir($dir, 0777, true)) { return true; } else { return false; } } //获取城市数据 public function getCity($id) { $list = CitySercice::getData($id); echo json_encode($list); } }