/** * create a default category for reservation * @return array * @param $name, string * @param $propertyName, string */ public function createDefaultReservationCategory($name, $propertyName = 'price') { $condition = ['name' => $name, 'accountId' => $this->accountId]; $category = ModelProductCategory::findOne($condition); if (empty($category)) { $category = new ModelProductCategory(); $data = ['name' => $name, 'accountId' => $this->accountId, 'properties' => [['name' => $propertyName, 'type' => 'input', 'defaultValue' => '', 'isRequired' => 'true', 'order' => 1, 'propertyId' => 'wm' . $propertyName, 'id' => StringUtil::uuid()]]]; $category->load($data, ''); $category->save(); } return $category; }
/** * Generate a html page with content and upload to qiniu * @param string $fileContent The file content * @param string $fileName The html page name * @param bool $isAllowedOverwrite * @return string Html file url * @throws ServerErrorHttpException */ public function generateQiniuFile($fileContent, $isAllowedOverwrite = false, $fileName = null) { if (empty($fileName)) { $fileName = StringUtil::uuid() . '.html'; } $file = $this->generateHtml($fileContent, $fileName); $result = Yii::$app->qiniu->upload($file, $fileName, $isAllowedOverwrite); unlink($file); if (!empty($result['key'])) { return $this->qiniuUrl . $result['key']; } else { throw new ServerErrorHttpException(\Yii::t('common', 'upload_fail')); } }
public static function sendInviteEmail($user, $accountName, $link, $subject, $template = 'invitation') { $validation = new Validation(); $validation->userId = $user->_id; $validation->code = StringUtil::uuid(); $validation->expire = new \MongoDate(strtotime('+7 day')); if ($validation->save()) { $mail = Yii::$app->mail; $vars = ['name' => $accountName, 'email' => $user->email, 'host' => Yii::$app->request->hostInfo, 'link' => str_replace('code', $validation->code, $link)]; $mail->setView('//mail/' . $template, $vars, '//layouts/email'); $mail->sendMail($user->email, $subject); return true; } return false; }
/** * Update a store qrcode * * <b>Request Type</b>: PUT<br/><br/> * <b>Request Endpoint</b>:http://{server-domain}/api/offlinestore/qrcode/update<br/><br/> * <b>Response Content-type</b>: application/json<br/><br/> * <b>Summary</b>: This api is used for update a store qrcode * <br/><br/> * * <b>Request Params</b>:<br/> * storeId: string<br/> * msgType: TEXT or NEWS<br/> * content: string|array If msgType is TEXT, it's a string. If msgType is NEWS, it's an array<br/> * <br/><br/> * * <b>Response Params:</b><br/> * array, json array to querie qrcode detail information<br/> * <br/><br/> * * <br/><br/> * * <b>Response Example</b>:<br/> * <pre> * { * wechat: { * "id": "5473ffe7db7c7c2f0bee5c71", * "accountId": "5473ffe7db7c7c2f0bee5c71", * "replyMessage": { * "msgType": "NEWS", * "articles": [ * { * "title": "没有", * "description": "", * "url": "http://vincenthou.qiniudn.com/94b6e2756acb030f6f76f690.jpg", * "content": "<p>哈哈哈哈</p>" * } * ] * }, * "sceneId": 1, * "name": "这只是一个测试", * "type": "EVENT", * "description": "招聘一些人才为公司,以备用", * "ticket": "gQFh8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL3BrampCdVBtVlprc25JVDFHR1RQAAIErHaXVAMEAAAAAA==", * "scanCount": 0, * "subscribeCount": 0, * "createTime": 1421113098304, * "imageUrl": "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQFh8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL3BrampCdVBtVlprc25JVDFHR1RQAAIErHaXVAMEAAAAAA==" * }, * weibo: { * "id": "5473ffe7db7c7c2f0bee5c71", * "accountId": "5473ffe7db7c7c2f0bee5c71", * "replyMessage": { * "msgType": "NEWS", * "articles": [ * { * "title": "没有", * "description": "", * "url": "http://vincenthou.qiniudn.com/94b6e2756acb030f6f76f690.jpg", * "content": "<p>哈哈哈哈</p>" * } * ] * }, * "sceneId": 1, * "name": "这只是一个测试", * "type": "EVENT", * "description": "招聘一些人才为公司,以备用", * "ticket": "gQFh8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL3BrampCdVBtVlprc25JVDFHR1RQAAIErHaXVAMEAAAAAA==", * "scanCount": 0, * "subscribeCount": 0, * "createTime": 1421113098304, * "imageUrl": "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQFh8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL3BrampCdVBtVlprc25JVDFHR1RQAAIErHaXVAMEAAAAAA==" * } * } * </pre> */ public function actionUpdate() { $qrcode = $this->getParams(); if (empty($qrcode['storeId'])) { throw new BadRequestHttpException(Yii::t('common', 'parameters_missing')); } $result = ['wechat' => [], 'weibo' => []]; $storeId = new \MongoId($qrcode['storeId']); $store = Store::findByPk($storeId); $qrcode['name'] = $store->branchName . StringUtil::uuid(); $qrcode['type'] = self::QRCODE_TYPE_STORE; unset($qrcode['storeId']); if (!empty($store->wechat['channelId'])) { $wechatId = $store->wechat['channelId']; $qrcodeId = $store->wechat['qrcodeId']; $result['wechat'] = Yii::$app->weConnect->updateQrcode($wechatId, $qrcodeId, $qrcode); } if (!empty($store->weibo['channelId'])) { $weiboId = $store->weibo['channelId']; $qrcodeId = $store->weibo['qrcodeId']; $result['weibo'] = Yii::$app->weConnect->updateQrcode($weiboId, $qrcodeId, $qrcode); } return $result; }
/** * Send to preview mass message * * <b>Request Type</b>: POST<br/><br/> * <b>Request Endpoint</b>:http://{server-domain}/api/channel/mass-message/preview<br/><br/> * <b>Content-type</b>: application/json<br/><br/> * <b>Summary</b>: This api is used for sending to preview mass message. * <br/><br/> * * <b>Request Params</b>:<br/> * channelId: string<br/> * msgType: TEXT or MPNEWS<br/> * content: string, if TEXT<br/> * content.articles, if MPNEWS<br/> * <br/><br/> * * <b>Response Params:</b><br/> * msg: string, if query fail, it contains the error message<br/> * <br/><br/> * * <br/><br/> * * <b>Response Example</b>:<br/> * <pre> * { * "qrcode": "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQG/7joAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xLzFFZ2xZcG5taVpudzh2U0wzbWJQAAIEekd1VQMECAcAAA==", * "expireTime": 1800 * } * </pre> */ public function actionPreview() { $qrcode = $this->getParams(); $channelId = $this->getChannelId(); $qrcode['name'] = StringUtil::uuid(); $qrcode['type'] = 'PREVIEW'; $qrcode['temporary'] = true; $qrcode['expireSeconds'] = static::TEMP_QRCODE_EXPIRE; unset($qrcode['channelId']); $result = Yii::$app->weConnect->createQrcode($channelId, $qrcode); if ($result && isset($result['imageUrl'])) { return ['qrcode' => $result['imageUrl'], 'expireTime' => static::TEMP_QRCODE_EXPIRE]; } else { throw new ServerErrorHttpException('Create mass message fail.'); } }
/** * Register billing account * * <b>Request Type</b>: POST<br/><br/> * <b>Request Endpoint</b>:http://{server-domain}/site/register<br/><br/> * <b>Content-type</b>: application/json<br/><br/> * <b>Summary</b>: This api is used for registering user. * <br/><br/> * * <b>Request Params</b>:<br/> * name: string, the user name<br/> * email: string, the user email<br/> * password: string, the user password<br/> * <br/><br/> * * <b>Response Params:</b><br/> * ack: integer, mark the create result, 1 means create successfully, 0 means create fail<br/> * message: string, if create fail, it contains the error message<br/> * data: array, json array to describe all users detail information<br/> * <br/><br/> * * <b>Request Example:</b><br/> * <pre> * { * "name" : "harrysun", * "email" : "*****@*****.**", * "password" : "abc123_" * } * </pre> * <br/><br/> * * <b>Response Example</b>:<br/> * <pre> * { * 'ack' : 1, * 'message': '' * } * </pre> */ public function actionRegister() { $data = $this->getParams(); $account = new Account(); $account->save(); $user = new User(); $user->name = $data['name']; $user->email = $data['email']; $user->salt = StringUtil::rndString(6); $user->password = User::encryptPassword($data['password'], $user->salt); $user->accountId = $account->_id; $user->role = User::ROLE_ADMIN; $user->isActivated = User::NOT_ACTIVATED; $user->avatar = Yii::$app->params['defaultAvatar']; $user->language = 'zh_cn'; if ($user->validate()) { // all inputs are valid if ($user->save()) { $validation = new Validation(); $validation->userId = $user->_id; $validation->code = StringUtil::uuid(); $validation->expire = new \MongoDate(strtotime('+1 day')); if ($validation->save()) { $mail = Yii::$app->mail; $host = Yii::$app->request->hostInfo; $vars = ['name' => $user->name, 'link' => $host . '/api/old-site/activate?code=' . $validation->code, 'host' => $host]; $mail->setView('//mail/register', $vars, '//layouts/email'); $mail->sendMail($user->email, '欢迎注册WeMarketing'); return ["ack" => 1, "message" => 'Register success.']; } else { return ["ack" => 0, "message" => 'Validation save fail.']; } } else { return ["ack" => 0, "message" => 'Register user fail.']; } } else { // validation failed: $errors is an array containing error messages $errors = $user->errors; //revert the accout data Account::deleteAll(['_id' => $account->_id]); return ["ack" => 0, "message" => $errors]; } }
/** * Add a website into help desk setting * * <b>Request Type: </b>PUT<br/> * <b>Request Endpoint: </b>http://{server-domain}/api/helpdesk/setting/add-website<br/> * <b>Content-type: </b>Application/json<br/> * <b>Summary: </b>This api is for adding a website into help desk setting.<br/> * * <b>Request Example: </b> * <pre> * { * "settingId": '52d791327ae252f9149547cb', * "Website" : { * "name" : '爱不宅', * "url" : 'www.ibuzhai.com' * } * } * </pre> */ public function actionAddWebsite() { $checkUrl = "((http|ftp|https)://)(([a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\\&%_\\./-~-]*)?"; $website = $this->getParams('website'); $settingId = $this->getParams('settingId'); $accountId = $this->getAccountId(); if (!ereg($checkUrl, $website['url'])) { throw new InvalidParameterException(['url' => Yii::t('helpDesk', 'url_format_wrong')]); } if (!empty($website['name']) && !empty($website['url'])) { $settingId = new \MongoId($settingId); $website = ['id' => StringUtil::uuid(), 'name' => $website['name'], 'url' => $website['url'], 'code' => HelpDeskSetting::getCode($website['url'], $accountId)]; // Add a website into help desk setting $result = HelpDeskSetting::updateAll(['$push' => ['websites' => $website]], ['_id' => $settingId]); if ($result) { return $website; } throw new ServerErrorHttpException('add website fail'); } throw new BadRequestHttpException('parameters missing'); }
/** * Returns the list of all rules of user. * This method must be overridden by child classes to define available attributes. * * @return array list of rules. */ public function rules() { return array_merge(parent::rules(), [['code', 'default', 'value' => StringUtil::uuid()], ['toValidateAccount', 'default', 'value' => false]]); }
public static function createForWechat($accountId) { $account = Account::findByPk($accountId); if (empty($account)) { throw new Exception("Illegal accountId"); } $expire = 3600 * 24 * 10000; //never expired $token = new Token(); $token->accessToken = StringUtil::uuid(); $token->expireTime = new \MongoDate(time() + $expire); $token->userId = ''; $token->accountId = $account['_id']; $token->language = self::DEFAULT_LANGUAGE; $token->enabledMods = ['chat']; $token->role = User::ROLE_WECONNECT; if ($token->save()) { return $token; } throw new Exception("Faile to create token for database problems"); }
/** * set the qrcode imgurl and qrcodeId */ public static function setQrcodeParam($channelId) { $uuid = StringUtil::uuid(); $qrcodeData = ['name' => $uuid, 'type' => 'CHANNEL', 'temporary' => false]; $qrcode = Yii::$app->weConnect->createQrcode($channelId, $qrcodeData); $params = ['qrcodeUrl' => $qrcode['imageUrl'], 'qrcodeId' => $qrcode['id'], 'qrcodeName' => $uuid]; return $params; }
/** * @return string. file path * @param $fileName, string, file name * @param $fileType, string, file type */ public static function getFile($fileName, $fileType = 'csv') { //make sure the file name is unqiue $fileName = StringUtil::uuid() . self::FILE_SEPARATOR . $fileName; $fileName = Yii::$app->getRuntimePath() . '/temp/' . $fileName . '.' . strtolower($fileType); $filePath = dirname($fileName); if (!is_dir($filePath)) { FileHelper::createDirectory($filePath, 0777, true); } return $fileName; }
private function _sendRegistEmail($userId, $userInfo, $validation = null) { //active link availab time $linkAvailabDays = \Yii::$app->params['user_active_link_availab_time']; $host = Yii::$app->request->hostInfo; $mail = Yii::$app->mail; if (!empty($validation)) { $validation->expire = new \MongoDate(strtotime("+{$linkAvailabDays} day")); } else { $validation = new Validation(); $validation->userId = $userId; $validation->code = StringUtil::uuid(); $validation->expire = new \MongoDate(strtotime("+{$linkAvailabDays} day")); } $validation->toValidateAccount = true; if ($validation->save()) { $vars = ['name' => $userInfo['name'], 'link' => $host . '/site/invite/' . $validation->code . '?type=2', 'email' => $userInfo['email'], 'phone' => $userInfo['phone'], 'company' => $userInfo['company'], 'position' => $userInfo['position']]; $mail->setView('//mail/signup', $vars, '//layouts/email'); $result = $mail->sendMail(self::REGIST_EMAIL, '申请群脉账号'); return ["message" => 'Register success.']; } else { throw new ServerErrorHttpException('regist fail'); } }
/** * format the property struct * @param $param ,array */ public function formatPropertiesStr($params) { $params['propertyId'] = $params['categoryPropertyId']; $rule = ['id', 'order', 'name', 'type', 'options', 'defaultValue', 'isRequired', 'propertyId']; $uuid = StringUtil::uuid(); if (is_array($params)) { foreach ($params as $key => $param) { if (!in_array($key, $rule)) { unset($params[$key]); } } $params['id'] = $uuid; } if (is_array($this->properties)) { if (!empty($this->properties)) { foreach ($this->properties as $value) { $data[] = $value; } array_push($data, $params); } else { $data[] = $params; } } return ['properties' => $data, 'uuid' => $uuid]; }