public function passport($thirdparty_type = '', $thirdparty_uid = '') { if (session('user_id')) { return array('user_id' => session('user_id')); } $user_id = ''; $userMdl = D('User'); $params = array(); $params['openid'] = $thirdparty_uid; //根据thirdparty 获得用户的passport $userRes = $userMdl->getRow($params); //如果thirdparty id 不存在,创建passport if ($userRes) { $user = $userRes; $user_id = \Common\Lib\Idhandler::encode($userRes['id']); } else { $params['level'] = 1; $params['created_at'] = time(); $params['updated_at'] = time(); $params['due_at'] = time() + 1800; $userRes = $userMdl->saveData($params); if ($userRes['status'] == 'success') { $user_id = \Common\Lib\Idhandler::encode($userRes['data']); $params['id'] = $userRes['data']; $user = $params; } } if ($user_id) { session('user_id', $user_id); session('user', $user); } $return['user_id'] = $user_id; return $return; }
public function index() { $user = session('user'); if ($user) { $userMdl = D('User'); $userRes = $userMdl->getRow(array('id' => $user['id'])); if ($userRes) { $user = $userRes; session('user', $user); } } $id = $user['id']; $user['id'] = \Common\Lib\Idhandler::encode($user['id']); $itemMdl = D('Items'); $items = $itemMdl->getList(array('uid' => $id), 1000, 1, 'created_at desc'); if ($items) { foreach ($items as &$item) { $item['id'] = \Common\Lib\Idhandler::encode($item['id']); $item['d_status'] = 'normal'; if ($item['due_at'] < time()) { $item['d_status'] = 'dued'; } elseif ($item['due_at'] - time() < 86400) { $item['d_status'] = 'soon_due'; } $item['url'] = $item['s_url']; $item['vurl'] = 'http://i.shopflow.cn/show/' . $item['id']; } } $this->assign('items', $items); $this->assign('user', $user); $this->display(); }
public function buy() { $level = $_GET['level']; $user_id = $_GET['user']; if (!$user_id || !$level || !in_array($level, array('3', '2'))) { echo "参数错误"; exit; } /* $product = array(); switch($level) { case '2': $product['title'] = '银牌会员'; $product['desc'] = '欢迎您成为银牌会员'; $product['price'] = '0.01'; break; case '3': $product['title'] = '金牌会员'; $product['desc'] = '欢迎您成为金牌会员'; $product['price'] = '0.01'; break; default: break; } */ $products = C('PRODUCTS'); $product = $products[$level]; //生成订单 $current = time(); $tradeMdl = D('Trade'); $data = array('user_id' => \Common\Lib\Idhandler::decode($user_id), 'level' => $level, 'price' => $product['price'], 'status' => 'pending', 'pay_from' => '', 'created_at' => $current, 'updated_at' => $current); $trade = $tradeMdl->saveData($data); $trade_id = ''; if ($trade['status'] == 'success') { $trade_id = \Common\Lib\Idhandler::encode($trade['data']); } else { echo "创建订单失败"; exit; } //生成交易链接 $sHtml = "<form id='buyfrm' name='buyfrm' action='http://wechat.vtshow.top/wappay/index.php' method='post'>"; $sHtml .= "<input type='hidden' name='out_trade_no' value='" . $trade_id . "'/>"; $sHtml .= "<input type='hidden' name='subject' value='" . $product['title'] . "'/>"; $sHtml .= "<input type='hidden' name='total_fee' value='" . $product['price'] . "'/>"; $sHtml .= "<input type='hidden' name='body' value='" . $product['desc'] . "'/>"; $sHtml .= "<input type='hidden' name='show_url' value='http://wechat.vtshow.top/home/pay/index' />"; //submit按钮控件请不要含有name属性 $sHtml = $sHtml . "<input type='submit' value='确认'></form>"; $sHtml = $sHtml . "<script>document.forms['buyfrm'].submit();</script>"; echo $sHtml; exit; }
public function share() { $source = $_GET['source'] ? $_GET['source'] : ''; $user = session('user'); if ($user) { $userMdl = D('User'); $userRes = $userMdl->getRow(array('id' => $user['id'])); if ($userRes) { $user = $userRes; session('user', $user); } } $id = $user['id']; $user['id'] = \Common\Lib\Idhandler::encode($user['id']); if (!$source) { $this->redirect('/home/events/share?source=' . $user['id']); exit; } $shareMdl = D('Share'); $curr_profile = 0; if ($source == $user['id']) { $curr_profile = 1; $useruplogMdl = D('Useruplog'); $useruplog = $useruplogMdl->getRow(array('user_id' => $id, 'up' => 'share')); $hasup = false; if ($useruplog) { $hasup = true; } $shareCount = $shareMdl->getCount(array('source' => \Common\Lib\Idhandler::decode($source), 'subscribe' => 1)); $res = $userMdl->uplevel($id, '2'); if ($res) { $hasup = true; } $this->assign('hasup', $hasup); $this->assign('share_count', $shareCount); } else { $params['source'] = \Common\Lib\Idhandler::decode($source); $params['user_id'] = $id; $shareRes = $shareMdl->getRow($params); if (!$shareRes) { $params['subscribe'] = 0; $params['created_at'] = time(); $params['updated_at'] = time(); $shareMdl->saveData($params); } } $this->assign('curr_profile', $curr_profile); $this->assign('user', $user); $this->display(); }
public function index() { $user = session('user'); if ($user) { $userMdl = D('User'); $userRes = $userMdl->getRow(array('id' => $user['id'])); if ($userRes) { $user = $userRes; session('user', $user); } } $user['id'] = \Common\Lib\Idhandler::encode($user['id']); $this->assign('user', $user); $this->display(); }
public function lists() { $page = isset($_GET['p']) ? $_GET['p'] : 1; $userMdl = D('User'); $filter = array(); //处理搜索问题 $fValue = ''; if (isset($_GET['f']) && in_array($_GET['f'], array('id'))) { $field = $_GET['f']; $fValue = trim(urldecode($_GET['q'])); if ('id' == $field) { $filter['id'] = \Common\Lib\Idhandler::decode($fValue); } elseif ('nickname' == $field) { $filter['nickname'] = array('like', '%' . trim($fValue) . '%'); } } $this->assign('field', $field); $this->assign('fv', $fValue); //处理排序问题 $order = 'updated_at desc'; if (isset($_GET['order']) && $_GET['order']) { $order = str_replace('_', ' ', $_GET['order']); } $orderArr = explode(' ', $order); $this->assign('order', $orderArr); $count = $userMdl->getCount($filter); $utils = new \Common\Lib\Utils(); $pagination = $utils->pagination($count, C('PAGE_LIMIT')); $users = $userMdl->getList($filter, C('PAGE_LIMIT'), $page, $order); foreach ($users as &$user) { $user['id'] = \Common\Lib\Idhandler::encode($user['id']); } $this->assign('count', $count); $this->assign('page', $pagination); $this->assign('users', $users); $this->display(); }
public function index() { $encodeShopId = $this->shop['shop_id']; $shopId = \Common\Lib\Idhandler::decode($encodeShopId); $tradeMdl = D('Trade'); $shopMdl = D('Shop'); $productMdl = D('Products'); $shopStatisticsMdl = D('ShopStatistics'); $tradeTransactionsMdl = D('TradeTransactions'); $filter = array('shop_id' => $shopId, 'status' => 'open', 'financial_status' => 'paid'); $paidCount = $tradeMdl->getCount($filter); $filter = array('shop_id' => $shopId, 'financial_status' => 'paid', 'fulfillment_status' => ''); $undeliveryCount = $tradeMdl->getCount($filter); //$undeliveryCount = 0; $shopInfo = $shopMdl->findByShopId($shopId); $productCount = $productMdl->getCount(array('shop_id' => $shopId, 'published' => 1, 'status' => 1)); $productDownCount = $productMdl->getCount(array('shop_id' => $shopId, 'published' => 0, 'status' => 1)); $start = strtotime(date('Y-m-01')); /* $params['shop_id'] = $shopId; $parasm['status'] = 'open'; $params['financial_status'] = 'paid'; $params['created_at'] = array('between', $start.",".time()); $orderCount = $tradeMdl->getCount($params); $income = $tradeMdl->getTotalAmount($params); */ $params['shop_id'] = $shopId; $parasm['kind'] = 'capture'; $params['status'] = 'success'; $params['created_at'] = array('between', $start . "," . time()); $orderCount = $tradeTransactionsMdl->getCount($params); $income = $tradeTransactionsMdl->getTotalAmount($params); /* $month = date("Y-m"); $filter = "LEFT(`date`, 7) = '{$month}' and shop_id = {$shopId}"; $income = $shopStatisticsMdl->sumAmount($filter); */ //微信关注 $userMdl = D('User'); $follower = $userMdl->findWechatFollower($shopId); if ($follower || session('ignoreWechat')) { $isFollow = true; } else { $isFollow = false; } //引导页面 $shopSettingMdl = D('ShopSetting'); $guideRs = $shopSettingMdl->findByKey($shopId, 'guide_desktop'); $this->assign('guide', $guideRs ? 0 : 1); //有料列表 $noticeMdl = D('Notice'); $notice = $noticeMdl->getList('5', '1'); $this->assign('notice', $notice); $this->assign('isFollow', $isFollow); $this->assign('shop', $shopInfo); $this->assign('productCount', number_format($productCount)); $this->assign('productDownCount', number_format($productDownCount)); $this->assign('orderCount', number_format($orderCount)); $this->assign('paidCount', number_format($paidCount)); $this->assign('undeliveryCount', number_format($undeliveryCount)); $this->assign('income', $income ? number_format($income, 2) : 0); $this->assign('shop_url', C('LOCAL_URL1') . 'shop/' . \Common\Lib\Idhandler::encode($shopId)); $this->display(); }
protected function processText() { date_default_timezone_set("Asia/Beijing"); $help_url = "http://wechat.vtshow.top/home/help/index"; $data = $this->_wechat->getRevData(); \Common\Lib\Utils::log('wechat', 'request.log', $data); $fromusername = $data['FromUserName']; $filter = array('openid' => $fromusername); $userMdl = D('User'); $user = $userMdl->getRow($filter); if ($user) { $userid = $user['id']; $level = $user['level'] ? $user['level'] : '1'; } else { $params = $filter; $params['level'] = 1; $params['created_at'] = time(); $params['updated_at'] = time(); $res = $userMdl->saveData($params); if ($res['status'] == 'success') { $userid = $res['data']; $level = 1; } } $rs['msg_info_type'] = 1; if (!$userid) { $rs['content'] = '请输入正确的商品链接地址, <a href="' . $help_url . '">查看帮助</a>'; $this->reply($rs); exit; } $itemsMdl = D('Items'); $ifilter['uid'] = $userid; $ifilter['due_at'] = array('gt', time()); $count = $itemsMdl->getCount($ifilter); //\Common\Lib\Utils::log('wechat', 'request.log', $ifilter); $level_str = ''; switch ($level) { case '1': if ($count >= 1) { $rs['content'] = '您的会员等级,只能创建1次链接,<a href="http://wechat.vtshow.top/home/pay/index">点击成为会员</a>,可创建更多'; } else { $yesterday_end = strtotime(date('Y-m-d', time())); $ifilter['due_at'] = array('lt', time()); $ifilter['updated_at'] = array('between', array($yesterday_end, $yesterday_end + 86400)); //\Common\Lib\Utils::log('wechat', 'request.log', $ifilter); //$count = $itemsMdl->getCount($ifilter); //\Common\Lib\Utils::log('wechat', 'request.log', $itemsMdl->getLastSql()); if ($itemsMdl->getCount($ifilter) > 0) { $rs['content'] = '您的会员等级,今天已经创建了1次链接,请等后天再创建, <a href="http://wechat.vtshow.top/home/pay/index">点击成为会员</a>,可创建更多'; } else { $yesterday_start = $yesterday_end - 86400; $ifilter['updated_at'] = array('between', array($yesterday_start, $yesterday_end)); \Common\Lib\Utils::log('wechat', 'request.log', $ifilter); if ($itemsMdl->getCount($ifilter) > 0) { $rs['content'] = '您的会员等级,昨天已经创建了1次链接,请等明天再创建, <a href="http://wechat.vtshow.top/home/pay/index">点击成为会员</a>,可创建更多'; } } } $level_str = '普通会员'; $due_at = time() + 1800; break; case '2': if ($count >= 10) { $rs['content'] = '您是银牌会员,已经创建10次链接,, <a href="http://wechat.vtshow.top/home/pay/index">点击成为会员</a>,可创建更多'; } //$due_at = time() + 7 * 86400; $due_at = $user['due_at']; $level_str = '银牌会员'; break; case '3': //$due_at = time() + 30 * 86400; $due_at = $user['due_at']; $level_str = '金牌会员'; break; default: break; } if (isset($rs['content']) && $rs['content']) { $this->reply($rs); exit; } $content_str = $data['Content']; /* $h_pos = strpos($content_str, 'http'); if(!$h_pos) { $h_pos = strpos($content_str, 'https'); } $content = substr($content_str, $h_pos, strlen($content_str)); */ //获得字符串中的url $urls = array(); preg_match_all("/http[s]?:\\/\\/?[^\\s]+/i", $content_str, $urls); $content = $urls[0][0]; $o_url = $content; \Common\Lib\Utils::log('wechat', 'request.log', $content); $title = ""; $http_pos = strpos($content_str, 'http'); if ($http_pos) { $title = substr($content_str, 0, $http_pos); } if (preg_match('/mashort.cn/', $content) || preg_match('/tb.cn/', $content)) { $n_content = file_get_contents($content); $pa = '%url = ("|\')?(.*?)("|\')?;%s'; preg_match($pa, $n_content, $r); \Common\Lib\Utils::log('wechat', 'request.log', $r); if ($r) { $url = urldecode($r[2]); \Common\Lib\Utils::log('wechat', 'request.log', $url); $n_query = explode('url=', $url); \Common\Lib\Utils::log('wechat', 'request.log', $n_query); $n_url = $n_query[1] ? $n_query[1] : $n_query[0]; $content = $n_url; } } \Common\Lib\Utils::log('wechat', 'request.log', $content); if (preg_match('/^http[s]?:\\/\\//i', $content) === 0) { $rs['content'] = '请输入正确的商品链接地址, <a href="' . $help_url . '">查看帮助</a>'; } else { $url_arr = parse_url($content); $type = ''; $host = $url_arr['host']; if (preg_match('/tmall.com/', $host) || preg_match('/taobao.com/', $host)) { $type = 'taobao'; } elseif (preg_match('/jd.com/', $host)) { $type = 'jd'; } $nid = ''; if ($type == 'taobao') { if ($url_arr['query']) { parse_str($url_arr['query'], $query); $nid = $query['id']; } } elseif ($type == 'jd') { $path = $url_arr['path']; if ($path) { $nid = substr($path, 1, strlen($path) - 6); } } if ($nid) { //判断是否已经生成 $itemRes = $itemsMdl->getRow(array('nid' => $nid, 'uid' => $userid)); } else { $itemRes = $itemsMdl->getRow(array('o_url' => $o_url, 'uid' => $userid)); } \Common\Lib\Utils::log('wechat', 'request.log', $itemRes); $s_url = ''; if ($itemRes) { $params['id'] = $itemRes['id']; $params['uid'] = $userid; $params['url'] = $content; $params['o_url'] = $o_url; $params['due_at'] = $due_at; $params['title'] = $itemRes['title'] ? $itemRes['title'] : $title; $params['updated_at'] = time(); $itemsMdl->saveData($params); $id = $itemRes['id']; $s_url = $itemRes['s_url']; \Common\Lib\Utils::log('wechat', 'request.log', $params); } else { $params['url'] = $content; $params['o_url'] = $o_url; $params['nid'] = $nid; $params['uid'] = $userid; $params['platform'] = $type; $params['created_at'] = time(); $params['updated_at'] = time(); $params['due_at'] = $due_at; $params['title'] = trim($title); $res = $itemsMdl->saveData($params); //\Common\Lib\Utils::log('wechat', 'request.log', $res); if ($res['status'] == 'success') { $id = $res['data']; } //\Common\Lib\Utils::log('wechat', 'request.log', $itemsMdl->getLastSql()); //\Common\Lib\Utils::log('wechat', 'request.log', $params); } if ($id) { if (!$s_url) { $url = 'http://i.shopflow.cn/show/' . \Common\Lib\Idhandler::encode($id); $s_url = \Common\Lib\Utils::short_url($url); if (!$s_url) { $s_url = $url; } $itemsMdl->saveData(array('id' => $id, 's_url' => $s_url)); } if ($s_url) { $out_content = "链接1: " . $s_url . "\n链接2: " . 'http://i.shopflow.cn/show/' . \Common\Lib\Idhandler::encode($id) . "\n请选择可以访问的链接分发\n\n您是" . $level_str . ",链接已创建!\n过期时间:" . date('Y-m-d H:i', $due_at); } else { $out_content = 'http://i.shopflow.cn/show/' . \Common\Lib\Idhandler::encode($id) . "\n您是" . $level_str . ",链接已创建!\n过期时间:" . date('Y-m-d H:i', $due_at); } $rs['content'] = $out_content; } else { $rs['content'] = '操作错误'; } } $this->reply($rs); /* $keyword = $keywordMdl->getList($this->_shopId, $kwd); if ($keyword) { $rs = $keyword[0]; } else { $messageMdl = D('Message'); $rs = $messageMdl->getRow($this->_shopId, 'message'); } $this->reply($rs); */ }
public function lists() { $page = isset($_GET['p']) ? $_GET['p'] : 1; $productMdl = D('Items'); $userMdl = D('User'); $filter = array(); //处理搜索问题 $fValue = ''; if (isset($_GET['f']) && in_array($_GET['f'], array('id', 'tid', 'link'))) { $field = $_GET['f']; $fValue = trim(urldecode($_GET['q'])); switch ($field) { case 'id': $filter['id'] = \Common\Lib\Idhandler::decode($fValue); break; case 'tid': $filter['nid'] = trim($fValue); $filter['platform'] = 'taobao'; break; case 'link': $filter['o_url'] = urldecode(trim($fValue)); break; default: break; } } $this->assign('field', $field); $this->assign('fv', $fValue); //处理排序问题 $order = 'updated_at desc'; if (isset($_GET['order']) && $_GET['order']) { $order = str_replace('_', ' ', $_GET['order']); } $orderArr = explode(' ', $order); $this->assign('order', $orderArr); $count = $productMdl->getCount($filter); $utils = new \Common\Lib\Utils(); $pagination = $utils->pagination($count, C('PAGE_LIMIT')); $products = $productMdl->getList($filter, C('PAGE_LIMIT'), $page, $order); $hosts = C('LOCALHOST'); if ($products) { foreach ($products as &$p) { $p['id'] = \Common\Lib\Idhandler::encode($p['id']); $user = array(); if ($p['uid'] > 0) { $user = $userMdl->getRow(array('id' => $p['uid'])); $user['id'] = \Common\Lib\Idhandler::encode($user['id']); } $p['user'] = $user; $p['product_url'] = $hosts . 'show/' . $p['id']; } } $this->assign('count', $count); $this->assign('page', $pagination); $this->assign('products', $products); $this->display(); }