123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php namespace Service\Src;
- use Dever;
- class Base
- {
- public $key = 'jmbuybuybuy';
- public function __construct()
- {
- $p = Dever::input('p');
- if ($p) {
- $this->config = Dever::json_decode(Dever::decode($p, $this->key));
- }
- # 第三方账户
- $this->account = $this->getConfig('account', 1);
- # 小刊分类
- $this->cate = $this->getConfig('cate', 1);
- # 渠道
- $this->source = $this->getConfig('source', 1);
- # 类型 1为直接购买 2为购买兑换码
- $this->type = $this->getConfig('type', 1);
- # 销售商
- $this->seller = $this->getConfig('seller', 1);
- # 用户信息
- $this->user = Dever::load('passport/user')->data();
- }
- # 创建url
- public function createUrl()
- {
- # 第三方账户
- $this->account = Dever::input('account', 1);
- # 分类
- $this->cate = Dever::input('cate', 1);
- # 渠道
- $this->source = Dever::input('source', 1);
- # 类型 1为直接购买 2为购买兑换码
- $this->type = Dever::input('type', 1);
- # 销售商
- $this->seller = Dever::input('seller', 1);
-
- $url = $this->url('home');
- return $url;
- }
- private function getConfig($key, $value)
- {
- if (isset($this->config[$key]) && $this->config[$key]) {
- return $this->config[$key];
- }
- return $value;
- }
- # 获取基本配置
- public function config()
- {
- $cate = Dever::db('journal/cate')->one($this->cate);
- $cate['login_title'] = '登录后才可以使用' . $cate['name'] . '服务';
- $cate['bglogo'] = 'background:url('.$cate['logo'].') no-repeat;background-size: 2.2667rem 2.2667rem;';
- $url = urlencode($this->url('list'));
- $cate['login'] = 'location.href=\'' . Dever::url('request.auth?account='.$this->account.'&source='.$this->source.'&refer=' . $url, 'oauth') . '\'';
- $info = Dever::db('journal/info')->getOne($cate['journal_id']);
- if ($info && $info['pic_gd']) {
- $cate['cover'] = $info['pic_gd'];
- }
- return $cate;
- }
- # 生成url
- protected function url($uri, $param = array())
- {
- if ($uri == 'list' && $this->type == 2) {
- $uri = 'list_code';
- }
- $send['cate'] = $this->cate;
- $send['source'] = $this->source;
- $send['type'] = $this->type;
- $send['seller'] = $this->seller;
- $param['p'] = Dever::encode(Dever::json_encode($send), $this->key);
- $param = http_build_query($param);
- $url = Dever::url($uri . '?' . $param, 'service');
- return $url;
- }
- protected function location($uri, $param = array())
- {
- return Dever::location($this->url($uri, $param));
- }
- protected function createOrder($prefix = 'JC')
- {
- $order = Dever::order($prefix);
- //$order = Dever::rand(2, 2) . Dever::rand(6, 0);
- $info = Dever::db('journal/order')->one(array('order_id' => $order));
- if ($info) {
- return $this->createOrder($prefix);
- }
- return $order;
- }
- }
|