Base.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php namespace Service\Src;
  2. use Dever;
  3. class Base
  4. {
  5. public $key = 'jmbuybuybuy';
  6. public function __construct()
  7. {
  8. $p = Dever::input('p');
  9. if ($p) {
  10. $this->config = Dever::json_decode(Dever::decode($p, $this->key));
  11. }
  12. # 第三方账户
  13. $this->account = $this->getConfig('account', 1);
  14. # 小刊分类
  15. $this->cate = $this->getConfig('cate', 1);
  16. # 渠道
  17. $this->source = $this->getConfig('source', 1);
  18. # 类型 1为直接购买 2为购买兑换码
  19. $this->type = $this->getConfig('type', 1);
  20. # 销售商
  21. $this->seller = $this->getConfig('seller', 1);
  22. # 用户信息
  23. $this->user = Dever::load('passport/user')->data();
  24. }
  25. # 创建url
  26. public function createUrl()
  27. {
  28. # 第三方账户
  29. $this->account = Dever::input('account', 1);
  30. # 分类
  31. $this->cate = Dever::input('cate', 1);
  32. # 渠道
  33. $this->source = Dever::input('source', 1);
  34. # 类型 1为直接购买 2为购买兑换码
  35. $this->type = Dever::input('type', 1);
  36. # 销售商
  37. $this->seller = Dever::input('seller', 1);
  38. $url = $this->url('home');
  39. return $url;
  40. }
  41. private function getConfig($key, $value)
  42. {
  43. if (isset($this->config[$key]) && $this->config[$key]) {
  44. return $this->config[$key];
  45. }
  46. return $value;
  47. }
  48. # 获取基本配置
  49. public function config()
  50. {
  51. $cate = Dever::db('journal/cate')->one($this->cate);
  52. $cate['login_title'] = '登录后才可以使用' . $cate['name'] . '服务';
  53. $cate['bglogo'] = 'background:url('.$cate['logo'].') no-repeat;background-size: 2.2667rem 2.2667rem;';
  54. $url = urlencode($this->url('list'));
  55. $cate['login'] = 'location.href=\'' . Dever::url('request.auth?account='.$this->account.'&source='.$this->source.'&refer=' . $url, 'oauth') . '\'';
  56. $info = Dever::db('journal/info')->getOne($cate['journal_id']);
  57. if ($info && $info['pic_gd']) {
  58. $cate['cover'] = $info['pic_gd'];
  59. }
  60. return $cate;
  61. }
  62. # 生成url
  63. protected function url($uri, $param = array())
  64. {
  65. if ($uri == 'list' && $this->type == 2) {
  66. $uri = 'list_code';
  67. }
  68. $send['cate'] = $this->cate;
  69. $send['source'] = $this->source;
  70. $send['type'] = $this->type;
  71. $send['seller'] = $this->seller;
  72. $param['p'] = Dever::encode(Dever::json_encode($send), $this->key);
  73. $param = http_build_query($param);
  74. $url = Dever::url($uri . '?' . $param, 'service');
  75. return $url;
  76. }
  77. protected function location($uri, $param = array())
  78. {
  79. return Dever::location($this->url($uri, $param));
  80. }
  81. protected function createOrder($prefix = 'JC')
  82. {
  83. $order = Dever::order($prefix);
  84. //$order = Dever::rand(2, 2) . Dever::rand(6, 0);
  85. $info = Dever::db('journal/order')->one(array('order_id' => $order));
  86. if ($info) {
  87. return $this->createOrder($prefix);
  88. }
  89. return $order;
  90. }
  91. }