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(); }
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); }
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 __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(); }
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(); }
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; }
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; } }
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(); }
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; }
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(); }