/** * 创建一个会员卡 * 每个账号只有一个会员卡 * 所以若没有则创建一个,若有则直接返回 * */ public function get($mpid) { $q = array('*', 'xxt_member_card', "mpid='{$mpid}'"); if (!($card = parent::query_obj_ss($q))) { parent::insert('xxt_member_card', array('mpid' => $mpid), false); $card = parent::query_obj_ss($q); } return $card; }
/** * */ public function delete($filename) { $abs = $this->rootDir . '/' . TMS_MODEL::toLocalEncoding($filename); if (file_exists($abs)) { return unlink($abs); } else { return false; } }
/** * 获得指定分类的模版消息 */ public function &byCatelog($catelogId, $eventName = null) { // $mappings = new \stdClass(); // $fields = $eventName === null ? array('submit_order', 'pay_order', 'feedback_order') : array($eventName); $q = array(implode('_tmplmsg,', $fields) . '_tmplmsg', 'xxt_merchant_catelog', "id={$catelogId}"); $catelog = $this->query_obj_ss($q); if ($catelog) { foreach ($fields as $eventName) { $mapping = \TMS_MODEL::M('matter\\tmplmsg')->mappingById($catelog->{$eventName . '_tmplmsg'}); $mappings->{$eventName} = $mapping; } } return $mappings; }
public function isOpen($mpid, $mid, $last = null) { if ($last === null) { $q = array('checkin_at,times_accumulated', 'xxt_checkin_log', "mid='{$mid}' and last=1"); $last = parent::query_obj_ss($q); } if ($last) { $lastdate = getdate($last->checkin_at); $nowdate = getdate(time()); if ($lastdate['year'] === $nowdate['year'] && $nowdate['yday'] === $lastdate['yday']) { return false; } } return true; }
/** * 获得指定产品下符合条件的sku * * @param int $productId * @param array options * */ public function &byProduct($productId, $options = array()) { $fields = isset($options['fields']) ? $options['fields'] : 'id,cate_sku_id,icon_url,ori_price,price,product_code,unlimited_quantity,quantity,sku_value,validity_begin_at,validity_end_at,required'; $beginAt = isset($options['beginAt']) ? $options['beginAt'] : 0; $endAt = isset($options['endAt']) ? $options['endAt'] : 0; $q = array($fields, 'xxt_merchant_product_sku', "prod_id={$productId}"); /*根据sku的状态*/ if (isset($options['state'])) { $state = $options['state']; isset($state['disabled']) && ($q[2] .= " and disabled='" . $state['disabled'] . "'"); isset($state['active']) && ($q[2] .= " and active='" . $state['active'] . "'"); } /*根据sku的有效期*/ if ($beginAt || $endAt) { $q[2] .= " and (has_validity='N' or (has_validity>='Y'"; $beginAt && ($q[2] .= " and validity_begin_at>={$beginAt}"); $endAt && ($q[2] .= " and validity_begin_at<={$endAt}"); $q[2] .= "))"; } $q2 = array('o' => 'validity_begin_at'); $skus = $this->query_objs_ss($q, $q2); /*sku的分类信息*/ $cateSkus = array(); if (!empty($skus)) { $modelCate = \TMS_MODEL::M('app\\merchant\\catelog'); $cateSkuOptions = array('fields' => 'id,name,has_validity,require_pay'); foreach ($skus as &$sku) { if (isset($cateSkus[$sku->cate_sku_id])) { $cateSkus[$sku->cate_sku_id]->skus[] = $sku; } else { $cateSku = $modelCate->skuById($sku->cate_sku_id, $cateSkuOptions); $cateSku->skus = array($sku); $cateSkus[$sku->cate_sku_id] = $cateSku; } unset($sku->cate_sku_id); } } return $cateSkus; }
/** * 更新商店的属性信息 * * @param int $shop */ public function update_action($shop) { $nv = (array) $this->getPostJson(); if (isset($nv['buyer_api'])) { $nv['buyer_api'] = \TMS_MODEL::toJson($nv['buyer_api']); } $rst = $this->model()->update('xxt_merchant_shop', $nv, "id='{$shop}'"); return new \ResponseData($rst); }
/** * 保存订单反馈信息并通知用户 */ public function feedback_action($mpid, $order) { $order = $this->model('app\\merchant\\order')->byId($order); $order->extPropValue = json_decode($order->ext_prop_value); $feedback = $this->getPostJson(); $pv = empty($feedback) ? '{}' : \TMS_MODEL::toJson($feedback); $rst = $this->model()->update('xxt_merchant_order', array('feedback' => $pv, 'order_status' => 3), "id={$order->id}"); /*发通知*/ $order->feedback = json_decode($pv); $this->notify($mpid, $order); return new \ResponseData($rst); }
$tokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token"; $tokenUrl .= "?appid={$wx_appid}"; $tokenUrl .= "&secret={$wx_appsecret}"; $tokenUrl .= "&code={$code}"; $tokenUrl .= "&grant_type=authorization_code"; $ch = curl_init($tokenUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); if (false === ($response = curl_exec($ch))) { $err = curl_error($ch); curl_close($ch); die($err); } curl_close($ch); $token = json_decode($response); if (isset($token->errcode)) { die($token->errmsg); } $openid = $token->openid; /** * 将openid保存在cookie,可用于进行用户身份绑定 */ $who = array($openid, 'wx'); require_once dirname(dirname(__FILE__)) . '/tms/tms_model.php'; $model = new TMS_MODEL(); $encoded = $model->encrypt(json_encode($who), 'ENCODE', $mpid); setcookie("xxt_{$mpid}_oauth", $encoded, null, '/', null, false); } }
/** * 建立资源和标签之间的关联 * * $res_id * $res_type * $aAdded 标签对象的集合 * $aRemoved 标签对象的集合 */ public function save($mpid, $res_id, $res_type, $aAdded = null, $aRemoved = null) { $resTable = $this->resTable($res_type); /** * 建立关联 */ if (!empty($aAdded)) { foreach ($aAdded as $added) { if (!isset($added->id)) { /** * 标签是否已经存在? */ $q = array('id', 'xxt_tag', "mpid='{$mpid}' and title='{$added->title}'"); if (!($tag_id = $this->query_val_ss($q))) { /** * 不存在,创建新标签 */ $tag_id = $this->insert('xxt_tag', array('mpid' => $mpid, 'title' => $added->title), true); } $added->id = $tag_id; } if ('1' === parent::query_value('1', 'xxt_article_tag', "mpid='{$mpid}' and res_id={$res_id} and tag_id={$added->id}")) { // 关联已经存在 continue; } /** * 建立资源与标签之间的关联 */ $tag2res = array('mpid' => $mpid, 'res_id' => $res_id, 'tag_id' => $added->id); $this->insert('xxt_article_tag', $tag2res); } } /** * 删除关联 */ if (!empty($aRemoved)) { foreach ($aRemoved as $removed) { if (!isset($removed->id)) { /** * 没有指定标签的id * 查找标签是否存在,若不存在跳过 */ $q = array('id', 'xxt_tag', "mpid='{$mpid}' and title='{$removed->title}'"); if (!($removed->id = $this->query_val_ss($q))) { continue; } } /** * 删除资源与标签之间的关联 */ $this->delete('xxt_article_tag', "mpid='{$mpid}' and res_id={$res_id} and tag_id={$removed->id}"); } } return true; }
/** * 处理分段上传的请求 */ public function handleRequest($resumabled) { $chunkNumber = $resumabled['resumableChunkNumber']; $filename = str_replace(' ', '_', $resumabled['resumableFilename']); $chunkDir = $resumabled['resumableIdentifier'] . '_part'; $chunkFile = \TMS_MODEL::toLocalEncoding($filename) . '.part' . $chunkNumber; $content = base64_decode(preg_replace('/data:(.*?)base64\\,/', '', $resumabled['resumableChunkContent'])); $ret = $this->modelFs->write($chunkDir . '/' . $chunkFile, $content); if (false === $ret) { $this->_log('Error saving chunk ' . $chunkNumber . ' for file ' . $filename); } else { // check if all the parts present, and create the final destination file $absChunkDir = $this->modelFs->rootDir . '/' . $chunkDir; $this->createFileFromChunks($absChunkDir, $filename, $resumabled['resumableTotalChunks']); } }
/** * 上传文件并创建图文 */ public function articleUpload_action($mpid, $entry = null, $state = null) { if ($state === 'done') { $fan = $this->model('user/fans')->byId($this->user->fid, 'nickname'); $posted = $this->getPostJson(); $file = $posted->file; $modelFs = \TMS_APP::M('fs/local', $mpid, '_resumable'); $fileUploaded = $modelFs->rootDir . '/article_' . $file->uniqueIdentifier; $current = time(); $filename = str_replace(' ', '_', $file->name); $d = array(); $d['mpid'] = $mpid; $d['entry'] = $entry; $d['creater'] = $this->user->mid; $d['creater_name'] = $fan->nickname; $d['creater_src'] = 'M'; $d['create_at'] = $current; $d['modifier'] = $this->user->mid; $d['modifier_src'] = 'M'; $d['modifier_name'] = $fan->nickname; $d['modify_at'] = $current; $d['title'] = substr($filename, 0, strrpos($filename, '.')); $d['author'] = $fan->nickname; $d['url'] = ''; $d['hide_pic'] = 'Y'; $d['can_picviewer'] = 'Y'; $d['has_attachment'] = 'Y'; $d['pic'] = ''; $d['summary'] = ''; $d['body'] = ''; $d['finished'] = 'N'; $d['approved'] = 'N'; $d['public_visible'] = 'Y'; $d['remark_notice'] = 'Y'; $id = $this->model()->insert('xxt_article', $d, true); /** * 设置频道 */ list($entryType, $entryId) = explode(',', $entry); $entry = $this->model('matter\\' . $entryType)->byId($entryId, 'params'); $params = json_decode($entry->params); if (!empty($params->channel)) { $channelId = $params->channel; $this->model('matter\\channel')->addMatter($channelId, array('id' => $id, 'type' => 'article'), $this->user->mid, $fan->nickname, 'M'); } /** * 保存附件 */ $att = array(); $att['article_id'] = $id; $att['name'] = $filename; $att['type'] = $file->type; $att['size'] = $file->size; $att['last_modified'] = $file->lastModified; $att['url'] = 'local://article_' . $id . '_' . $filename; $this->model()->insert('xxt_article_attachment', $att, true); $modelFs = \TMS_APP::M('fs/local', $mpid, '附件'); $attachment = $modelFs->rootDir . '/article_' . $id . '_' . \TMS_MODEL::toLocalEncoding($filename); rename($fileUploaded, $attachment); /** * 获取附件的内容 */ $appRoot = $_SERVER['DOCUMENT_ROOT']; $ext = explode('.', $filename); $ext = array_pop($ext); $attAbs = $appRoot . '/' . $attachment; if (in_array($ext, array('doc', 'docx', 'ppt', 'pptx'))) { /* 存放附件转换结果 */ $attDir = str_replace('.' . $ext, '', $attachment); mkdir($appRoot . '/' . $attDir); /* 执行转换操作 */ $output = array(); $attPng = $appRoot . '/' . $attDir . '/%d.jpg'; $cmd = $appRoot . '/cus/conv2pdf2img ' . $attAbs . ' ' . $attPng; $rsp = exec($cmd, $output, $status); if ($status == 1) { return new \ResponseError('转换文件失败:' . $rsp); } $this->setBodyByAtt($id, $attDir); if (in_array($ext, array('ppt', 'pptx'))) { $this->setCoverByAtt($id, $attDir); } } else { if ($ext === 'pdf') { /* 存放附件转换结果 */ $attDir = str_replace('.' . $ext, '', $attachment); mkdir($appRoot . '/' . $attDir); $attPng = $appRoot . '/' . $attDir . '/%d.jpg'; $cmd = $appRoot . '/cus/conv2img ' . $attAbs . ' ' . $attPng; $rsp = exec($cmd); $this->setBodyByAtt($id, $attDir); } } return new \ResponseData($id); } else { /** * 分块上传文件 */ $modelFs = \TMS_APP::M('fs/local', $mpid, '_resumable'); $dest = '/article_' . $_POST['resumableIdentifier']; $resumable = new resumable($mpid, $dest, $modelFs); $resumable->handleRequest(); exit; } }
/** * 上传文件并创建图文 */ public function uploadAndCreate_action($state = null) { if ($state === 'done') { $account = \TMS_CLIENT::account(); if ($account === false) { return new \ResponseError('长时间未操作,请重新登陆!'); } $posted = $this->getPostJson(); $file = $posted->file; $current = time(); $uid = \TMS_CLIENT::get_client_uid(); $uname = $account->nickname; $filename = str_replace(' ', '_', $file->name); /* 生成图文*/ $d = array(); $d['mpid'] = $this->mpid; $d['creater'] = $uid; $d['creater_src'] = 'A'; $d['creater_name'] = $uname; $d['create_at'] = $current; $d['modifier'] = $uid; $d['modifier_src'] = 'A'; $d['modifier_name'] = $uname; $d['modify_at'] = $current; $d['title'] = substr($filename, 0, strrpos($filename, '.')); $d['author'] = $uname; $d['url'] = ''; $d['hide_pic'] = 'Y'; $d['can_picviewer'] = 'Y'; $d['has_attachment'] = 'Y'; $d['pic'] = ''; $d['summary'] = ''; $d['body'] = ''; $id = $this->model()->insert('xxt_article', $d, true); /** * 保存附件 */ $att = array(); $att['article_id'] = $id; $att['name'] = $filename; $att['type'] = $file->type; $att['size'] = $file->size; $att['last_modified'] = $file->lastModified; $att['url'] = 'local://article_' . $id . '_' . $filename; $this->model()->insert('xxt_article_attachment', $att, true); /* 处理附件 */ $modelRes = $this->model('fs/local', $this->mpid, '_resumable'); $modelAtt = $this->model('fs/local', $this->mpid, '附件'); $fileUploaded = $modelRes->rootDir . '/article_' . $file->uniqueIdentifier; $attachment = $modelAtt->rootDir . '/article_' . $id . '_' . \TMS_MODEL::toLocalEncoding($filename); if (false === rename($fileUploaded, $attachment)) { return new ResponseError('移动上传文件失败'); } /** * 获取附件的内容 */ $appRoot = $_SERVER['DOCUMENT_ROOT']; $ext = explode('.', $filename); $ext = array_pop($ext); $attAbs = $appRoot . '/' . $attachment; if (in_array($ext, array('doc', 'docx', 'ppt', 'pptx'))) { /* 存放附件转换结果 */ $attDir = str_replace('.' . $ext, '', $attachment); mkdir($appRoot . '/' . $attDir); /* 执行转换操作 */ $output = array(); $attPng = $appRoot . '/' . $attDir . '/%d.jpg'; $cmd = $appRoot . '/cus/conv2pdf2img ' . $attAbs . ' ' . $attPng; $rsp = exec($cmd, $output, $status); if ($status == 1) { return new \ResponseError('转换文件失败:' . $rsp); } $this->setBodyByAtt($id, $attDir); if (in_array($ext, array('ppt', 'pptx'))) { $this->setCoverByAtt($id, $attDir); } } else { if ($ext === 'pdf') { /* 存放附件转换结果 */ $attDir = str_replace('.' . $ext, '', $attachment); mkdir($appRoot . '/' . $attDir); $attPng = $appRoot . '/' . $attDir . '/%d.jpg'; $cmd = $appRoot . '/cus/conv2img ' . $attAbs . ' ' . $attPng; $rsp = exec($cmd); $this->setBodyByAtt($id, $attDir); } } return new \ResponseData($id); } else { /** * 分块上传文件 */ $modelFs = $this->model('fs/local', $this->mpid, '_resumable'); $dest = '/article_' . $_POST['resumableIdentifier']; $resumable = $this->model('fs/resumable', $this->mpid, $dest, $modelFs); $resumable->handleRequest($_POST); return new \ResponseData('ok'); } }