/** * [联合操作,添加童鞋,添加宝贝并绑定] * @param [type] $uid [description] * @param [type] $nick [description] * @param [type] $sex [description] * @param [type] $birthday [description] * @param [type] $addtime [description] * @param [type] $shoeQr [description] * @param [type] $rolename [description] * @param [type] $file [description] */ public function add($uid, $nick, $sex, $birthday, $addtime, $shoeQr, $rolename, $file, $weight = '', $height = '') { if (!empty($file['file']['tmp_name'])) { $upload = new ImgUpload($this->di); $imageName = substr(md5(uniqid(true)), 8, 16); $rePath = substr($imageName, 0, 2) . '/' . substr($imageName, 2, 2); $picInfo = $upload->uploadFile($file['file'], $this->di['sysconfig']['babyPic'], $imageName, $rePath); if (is_numeric($picInfo)) { return $picInfo; } else { $pic = $this->di['sysconfig']['babyPic'] . '/' . $picInfo; } } else { return self::NON_IMG_UPLOAD; } //判断鞋子是否存在 $shoeInfo = $this->devices->getDevInfoByQr($shoeQr); if (!$shoeInfo) { return self::NON_EXIST_SHOE; } //开始计算服务期,如果值为0,则第一次添加 if (empty($shoeInfo['expire'])) { $expires = Common::expires($_SERVER['REQUEST_TIME']); } else { $expires = $shoeInfo['expire']; } $this->di['db']->begin(); //添加宝贝 $babyId = $this->baby->add($nick, $sex, $birthday, $addtime, $pic, $weight, $height, '1'); if (!$babyId) { $this->di['db']->rollback(); return self::FAILED_ADD; } if (!$this->family->addRel($babyId, $uid, empty($rolename) ? '' : $rolename, '1', $addtime, '1')) { $this->di['db']->rollback(); return self::FAILED_ADD; } //设备过期就不让添加 if ($_SERVER['REQUEST_TIME'] < $expires) { $devId = $this->devices->addShoe($uid, $shoeInfo['uuid'], $shoeInfo['imei'], $shoeInfo['mobi'], $shoeInfo['pass'], $shoeInfo['dver'], $expires, $shoeInfo['qr'], $shoeInfo['pic'], $_SERVER['REQUEST_TIME'], $babyId); if (!$babyId) { $this->di['db']->rollback(); return self::FAILED_ADD; } if (!$this->devices->updateExpires($shoeInfo['uuid'], $expires)) { $this->di['db']->rollback(); return self::FAILED_ADD; } $this->di['db']->commit(); return array('flag' => '1', 'shoe_info' => array('shoe_id' => (string) $devId), 'baby_info' => array('baby_id' => (string) $babyId, 'baby_pic' => $this->di['sysconfig']['babyPicServer'] . $pic)); } else { $this->di['db']->commit(); return array('flag' => '11077', 'target' => 'target', 'expires' => $expires, 'msg' => $this->di['flagmsg']['11077'], 'tel' => $this->di['sysconfig']['service-phone']); } }
/** * [宝贝编辑] * @param [type] $data [description] * @return [type] [description] */ public function editBaby($data) { if (!empty($data['baby_pic']['file']['tmp_name'])) { $upload = new ImgUpload($this->di); $imageName = substr(md5($_SERVER['REQUEST_TIME'] . $data['baby_id']), 8, 16); $rePath = substr($imageName, 0, 2) . '/' . substr($imageName, 2, 2) . '/'; $picInfo = $upload->uploadFile($data['baby_pic']['file'], $this->di['sysconfig']['babyPic'], $imageName, $rePath); if (is_numeric($picInfo)) { return $picInfo; } else { $data['baby_pic'] = $this->di['sysconfig']['babyPic'] . '/' . $picInfo; } } if ($this->baby->edit($data)) { return array('ret' => self::SUCCESS, 'data' => isset($data['baby_pic']) ? $this->di['sysconfig']['babyPicServer'] . $data['baby_pic'] : ''); } else { return array('ret' => self::FAILED_EDIT); } }
/** * [上传图片] * @return [type] [description] */ public function uploadAction() { if (empty($_FILES['file'])) { $this->_showMsg(self::NON_IMG_UPLOAD, $this->di['flagmsg'][self::NON_IMG_UPLOAD]); } //判断用户是否有上传权限 $rel = $this->locate->getLocateInfoByLiid($this->_sanReq['li_id']); $this->_oauthrity($this->userInfo['uid'], $rel['baby_id']); //查看上传的图片是否达到上限 if ($this->locate->countPicByLiid($this->_sanReq['li_id']) >= 9) { $this->_showMsg(self::FULLED_PICS, $this->di['flagmsg'][self::FULLED_PICS]); } //图片名 $imageName = substr(md5(uniqid() . $this->userInfo['uid'] . rand(0, 10000)), 8, 16); //用liid组成保存在本地的路径,在七牛出现问题时,方便从本地调取路径 $str = md5($this->_sanReq['li_id']); //图片入库 $upload = new ImgUpload($this->di); $picInfo = $upload->uploadFile($_FILES['file'], $this->di['sysconfig']['locatePic'], $imageName, substr($str, 0, 2) . '/' . substr($str, 2, 2)); if (is_numeric($picInfo)) { $this->_showMsg($picInfo, $this->di['flagmsg'][$picInfo]); } if (!($picId = $this->locate->addPic($this->_sanReq['locus_id'], $this->_sanReq['li_id'], $this->userInfo['uid'], $rel['baby_id'], $picInfo, $_SERVER['REQUEST_TIME']))) { $this->_showMsg(self::FAILED_IMG_UPLOAD, $this->di['flagmsg'][self::FAILED_IMG_UPLOAD]); } $redis = $this->redisObj->getRedis(); //更新对应的轨迹缓存信息 if ($this->_sanReq['locus_id'] == '0') { //更新今天的定位信息 $redisData = $redis->hgetAll(sprintf($this->di['sysconfig']['todayLocate'], $rel['baby_id'])); if (!isset($redisData[$this->_sanReq['li_id']]['pics']) || $redisData[$this->_sanReq['li_id']]['pics'] === null) { $redisData[$this->_sanReq['li_id']]['pics'] = array(); } array_push($redisData[$this->_sanReq['li_id']]['pics'], array('id' => $picId, 'name' => $this->di['sysconfig']['qiniu']['resourceUrl'] . '/' . $picInfo)); //更新缓存 $redis->hset(sprintf($this->di['sysconfig']['todayLocate'], $rel['baby_id']), $this->_sanReq['li_id'], $redisData[$this->_sanReq['li_id']]); //更新缓存时间 $redis->hset(sprintf($this->di['sysconfig']['todayLocate'], $rel['baby_id']), 'times', $_SERVER['REQUEST_TIME']); } else { //更新历史轨迹信息 $redisData = $redis->get(sprintf($this->di['sysconfig']['locusData'], $this->_sanReq['locus_id'])); if (!isset($redisData[$this->_sanReq['li_id']]['pics']) || $redisData[$this->_sanReq['li_id']]['pics'] === null) { $redisData[$this->_sanReq['li_id']]['pics'] = array(); } array_push($redisData[$this->_sanReq['li_id']]['pics'], array('id' => $picId, 'name' => $this->di['sysconfig']['qiniu']['resourceUrl'] . '/' . $picInfo)); $redisData['times'] = $_SERVER['REQUEST_TIME']; $redis->setex(sprintf($this->di['sysconfig']['locusData'], $this->_sanReq['locus_id']), $this->di['sysconfig']['tokenTime'], $redisData); } $this->_returnResult(array('flag' => '1', 'picinfo' => array('id' => $picId, 'name' => $this->di['sysconfig']['qiniu']['resourceUrl'] . '/' . $picInfo))); }