コード例 #1
0
 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();
 }
コード例 #2
0
 public function index()
 {
     $id = $_GET['id'];
     $due = false;
     if ($id) {
         $itemsMdl = D('Items');
         $id = \Common\Lib\Idhandler::decode($id);
         $item = $itemsMdl->getRow(array('id' => $id));
         $itemsMdl->saveData(array('id' => $id, 'visits' => $item['visits'] + 1));
         $this->assign('item', $item);
         if ($item['due_at'] < time()) {
             $due = true;
         }
     }
     $this->assign('due', $due);
     $app = '';
     $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
     \Common\Lib\Utils::log('show', 'agent.log', $agent);
     if (strpos($agent, 'android')) {
         $app = 'android';
     } elseif (strpos($agent, 'iphone') || strpos($agent, 'ipad')) {
         $app = 'ios';
     }
     $wechat = 0;
     if (strpos($agent, 'micromessenger')) {
         $wechat = 1;
     }
     $this->assign('app', $app);
     $this->assign('wechat', $wechat);
     $this->display();
 }
コード例 #3
0
 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;
 }
コード例 #4
0
 public function display($templateFile = '', $charset = '', $contentType = '', $content = '', $prefix = '')
 {
     $this->assign('DEBUG', C('DEBUG'));
     $this->assign('BEAM', C('BEAM'));
     $this->assign('assets_path', C('DEBUG') ? '/src' : '/statics');
     $encodeShopId = $this->shop['shop_id'];
     $shopId = \Common\Lib\Idhandler::decode($encodeShopId);
     $this->assign('shop_id', $shopId);
     $this->assign('shop_is_closed', $this->shop['is_closed']);
     $this->assign('encode_shop_id', $encodeShopId);
     $this->assign('default_image', C('DEFAULT_IMAGE'));
     parent::display($templateFile, $charset, $contentType, $content, $prefix);
 }
コード例 #5
0
 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();
 }
コード例 #6
0
 public function __construct()
 {
     if (empty($_GET['nid'])) {
         die("非法访问");
     }
     $shopId = $_GET['nid'];
     $weixinMdl = D('Weixin');
     $shopId = \Common\Lib\Idhandler::decode($shopId);
     $weixin = $weixinMdl->getByShopId($shopId);
     if (!$weixin) {
         die("店铺不存在");
     }
     $options = array('appid' => $weixin['appid'], 'appsecret' => $weixin['appsecret'], 'token' => $weixin['token'], 'debug' => true);
     $this->_wechat = new \Common\Lib\Wechat($options);
     $this->_wechat->valid();
     $this->_shopId = $shopId;
     parent::__construct();
 }
コード例 #7
0
 public function index2()
 {
     $id = $_GET['id'];
     $due = false;
     if ($id) {
         $itemsMdl = D('Items');
         $id = \Common\Lib\Idhandler::decode($id);
         $item = $itemsMdl->getRow(array('id' => $id));
         $itemsMdl->saveData(array('id' => $id, 'visits' => $item['visits'] + 1));
         $this->assign('item', $item);
         if ($item['due_at'] < time()) {
             $due = true;
         }
     }
     $this->assign('due', $due);
     $app = '';
     $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
     if (strpos($agent, 'iphone')) {
         $app = 'ios';
     }
     $this->assign('app', $app);
     $this->display();
 }
コード例 #8
0
 public function back()
 {
     \Common\Lib\Utils::log('alipay', 'back.log', $_GET);
     $alipay_config = C('ALIPAY_CONFIG');
     //计算得出通知验证结果
     $alipayNotify = new \AlipayNotify($alipay_config);
     $verify_result = $alipayNotify->verifyReturn();
     if ($verify_result) {
         //验证成功
         //请在这里加上商户的业务逻辑程序代码
         //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
         //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表
         //商户订单号
         $out_trade_no = \Common\Lib\Idhandler::decode($_GET['out_trade_no']);
         //支付宝交易号
         $trade_no = $_GET['trade_no'];
         //交易状态
         $trade_status = $_GET['trade_status'];
         \Common\Lib\Utils::log('trade', 'alipay.log', $_GET);
         if ($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') {
             $tradeMdl = D('Trade');
             $params = array('id' => $out_trade_no, 'status' => 'success', 'pay_from' => 'taobao', 'pay_no' => $trade_no, 'paid_at' => time(), 'updated_at' => time());
             \Common\Lib\Utils::log('trade', 'alipay.log', $params);
             $res = $tradeMdl->saveData($params);
             \Common\Lib\Utils::log('trade', 'alipay.log', $res);
             if ($res['status'] == 'success') {
                 $trade = $tradeMdl->getRow(array('id' => $out_trade_no));
                 \Common\Lib\Utils::log('trade', 'alipay.log', $trade);
                 //更新用户的due_at
                 $level = $trade['level'];
                 switch ($level) {
                     case '1':
                         $due_at = time() + 5 * 86400;
                         break;
                     case '2':
                         $due_at = time() + 30 * 86400;
                         break;
                     default:
                         break;
                 }
                 $userMdl = D('User');
                 $uparams['id'] = $trade['user_id'];
                 $uparams['due_at'] = $due_at;
                 \Common\Lib\Utils::log('trade', 'alipay.log', $uparams);
                 $res = $userMdl->saveData($uparams);
                 \Common\Lib\Utils::log('trade', 'alipay.log', $res);
                 //更新有效商品的时间
                 $sql = "update items set due_at = {$due_at} where user_id = {$trade['user_id']} and due_at > " . time();
                 \Common\Lib\Utils::log('trade', 'alipay.log', $sql);
                 $res = $tradeMdl->execute($sql);
                 \Common\Lib\Utils::log('trade', 'alipay.log', $res);
                 echo "<script>localtion.href='/home/pay/success'</script>";
                 exit;
             }
             //判断该笔订单是否在商户网站中已经做过处理
             //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
             //如果有做过处理,不执行商户的业务程序
         } else {
             echo "trade_status=" . $_GET['trade_status'];
         }
         echo "验证成功<br />";
         //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——
         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     } else {
         //验证失败
         //如要调试,请看alipay_notify.php页面的verifyReturn函数
         echo "验证失败";
     }
     exit;
 }
コード例 #9
0
 public function del()
 {
     header('Content-type: application/json');
     $ids = $_POST['id'];
     if (!$ids) {
         echo json_encode(array('status' => 'error', 'msg' => '请选择要删除的商品'));
         exit;
     }
     $productsMdl = D('Items');
     $productsMdl->startTrans();
     $idArr = explode(',', $ids);
     $res = true;
     $current = time();
     foreach ($idArr as $id) {
         $id = \Common\Lib\Idhandler::decode($id);
         $filter = array('id' => $id);
         $product = $productsMdl->getRow($filter);
         if (!$product) {
             $productsMdl->rollback();
             echo json_encode(array('status' => 'error', 'msg' => '非法操作'));
             exit;
         }
     }
     foreach ($idArr as $id) {
         $id = \Common\Lib\Idhandler::decode($id);
         $rs = $productsMdl->delete($id);
         $res = $res & $rs;
     }
     if ($res) {
         $productsMdl->commit();
         echo json_encode(array('status' => 'success'));
         exit;
     } else {
         $productsMdl->rollback();
         echo json_encode(array('status' => 'error', 'msg' => '非法操作'));
         exit;
     }
 }
コード例 #10
0
 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();
 }
コード例 #11
0
 public function saveKeyword()
 {
     header('Content-type: application/json');
     $keywordMdl = D('Keyword');
     $encodeShopId = $this->shop['shop_id'];
     $shopId = \Common\Lib\Idhandler::decode($encodeShopId);
     $data = $_POST;
     $data['msg_keyword'] = strtolower(trim($data['msg_keyword']));
     $params = array('shop_id' => $shopId, 'msg_keyword' => $data['msg_keyword'], 'id' => $data['id']);
     if (!$keywordMdl->checkKeyword($params)) {
         echo json_encode(array('error' => 'true', 'msg' => '关键词重复,请重新添加'));
         exit;
     }
     $info['id'] = $data['id'];
     $info['msg_keyword'] = $data['msg_keyword'];
     $info['keyword_type'] = 'get';
     //get:发送被动响应消息 post:发送客服消息
     $info['active_state'] = '0';
     $info['shop_id'] = $shopId;
     if ($data['which'] == '0') {
         $info['msg_info_type'] = '1';
         $info['content'] = htmlspecialchars_decode((string) $data['text']['content'], ENT_QUOTES);
         $info['msg_data'] = '';
     } else {
         $info['msg_info_type'] = "2";
         //$info['sorted_ids'] = $data['sorted_ids'];
         $info['msg_data'] = $data['msg_data'];
         if ($data['sorted_ids']) {
             $ids = explode(',', $data['sorted_ids']);
             //unset($data['img']['sorted_ids'],$data['img']['editing_id']);
             if (count($data['msg_data']) > 1) {
                 $info['msg_data'] = $this->multi_array_sort_new($data['msg_data'], $ids);
             }
         }
         $info['content'] = '';
         $info['msg_data'] = serialize($info['msg_data']);
     }
     $res = $keywordMdl->saveData($info);
     echo json_encode($res);
     exit;
 }
コード例 #12
0
 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);
     */
 }
コード例 #13
0
 public function success()
 {
     $out_trade_no = \Common\Lib\Idhandler::decode($_GET['out_trade_no']);
     $trade_no = $_GET['trade_no'];
     $trade_status = $_GET['trade_status'];
     \Common\Lib\Utils::log('trade', 'alipay.log', $_GET);
     if ($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') {
         $tradeMdl = D('Trade');
         $trade = $tradeMdl->getRow(array('id' => $out_trade_no));
         if ($trade && $trade['status'] != 'success' && $trade['pay_no'] == '') {
             $params = array('id' => $out_trade_no, 'status' => 'success', 'pay_from' => 'taobao', 'pay_no' => $trade_no, 'paid_at' => time(), 'updated_at' => time(), 'pay_user' => $_GET['buyer_email']);
             \Common\Lib\Utils::log('trade', 'alipay.log', $params);
             $res = $tradeMdl->saveData($params);
             \Common\Lib\Utils::log('trade', 'alipay.log', $res);
             $userMdl = D('User');
             $user = $userMdl->getRow(array('id' => $trade['user_id']));
             $due_at = $user['due_at'];
             if ($due_at < time()) {
                 $due_at = time();
             }
             //更新用户的due_at
             $level = $trade['level'];
             switch ($level) {
                 case '2':
                     $due_at += 7 * 86400;
                     break;
                 case '3':
                     $due_at += 30 * 86400;
                     break;
                 default:
                     break;
             }
             $uparams['id'] = $trade['user_id'];
             $uparams['level'] = $level;
             $uparams['due_at'] = $due_at;
             \Common\Lib\Utils::log('trade', 'alipay.log', $uparams);
             $res = $userMdl->saveData($uparams);
             \Common\Lib\Utils::log('trade', 'alipay.log', $res);
             //更新有效商品的时间
             $sql = "update items set due_at = {$due_at} where uid = {$trade['user_id']} and due_at > " . time();
             \Common\Lib\Utils::log('trade', 'alipay.log', $sql);
             $res = $tradeMdl->execute($sql);
         }
         //更新用户的due_at
         $level = $trade['level'];
         $level_str = '';
         switch ($level) {
             case '2':
                 $level_str = '银牌会员';
                 break;
             case '3':
                 $level_str = '金牌会员';
                 break;
             default:
                 $level_str = "您还不是会员, <a href='/home/pay/index'>成为会员</a>";
                 break;
         }
         \Common\Lib\Utils::log('trade', 'alipay.log', $res);
         $this->assign('level', $level_str);
     } else {
         $this->assign('error', '支付失败');
     }
     $this->display();
 }