Source.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <?php namespace Place_interface\Api;
  2. use Dever;
  3. use Place;
  4. use Place_interface\Lib\Core;
  5. use Place_act\Lib\Core as Act;
  6. class Source extends Core
  7. {
  8. # 首页
  9. public function home()
  10. {
  11. $channel_id = Dever::input('channel_id', 'is_numeric', '频道ID');
  12. # 获取频道信息
  13. $channel = Dever::load('channel', 'place_source')->getInfo($channel_id);
  14. $data['channel'] = [
  15. 'id' => $channel['id'],
  16. 'name' => $channel['name'],
  17. 'desc' => $channel['desc'],
  18. ];
  19. # 分类信息
  20. $top_id = 0;
  21. $data['top'] = [];
  22. if ($channel['type'] == 1) {
  23. # 显示子分类
  24. # 根据频道获取主分类
  25. $data['top'] = Dever::load('cate', 'place_source')->getTop($channel_id, 0);
  26. $top_id = Dever::input('top_id');
  27. if (!$top_id && $data['top']) {
  28. $top_id = $data['top'][0]['id'];
  29. }
  30. }
  31. $data['cate'] = Dever::load('cate', 'place_source')->getData($channel, $top_id);
  32. # 主页轮播、主页小导航、主页信息流
  33. $data['ad'] = Dever::load('ad', 'place_page')->gets([1,2,3,4,5], $channel_id, $top_id);
  34. return $data;
  35. }
  36. # 搜索页
  37. public function search()
  38. {
  39. $channel_id = Dever::input('channel_id', 'is_numeric', '频道ID');
  40. $source = Dever::input('source', 'is_numeric', '页面来源');
  41. # 搜索历史
  42. $data['history'] = [];
  43. if (Place::$uid) {
  44. $data['history'] = Dever::db('search', 'place_user')->select(['uid' => Place::$uid, 'channel_id' => $channel_id], ['limit' => 10]);
  45. }
  46. # 热门搜索
  47. $data['hot'] = Dever::db('search', 'place_source')->select(['channel_id' => $channel_id, 'status' => 1], ['limit' => 10]);
  48. return $data;
  49. }
  50. # 搜索页搜索
  51. public function searchData()
  52. {
  53. $search = Dever::input('search', 'is_string', '搜索词');
  54. $channel_id = Dever::input('channel_id', 'is_numeric', '频道ID');
  55. $source = Dever::input('source', 'is_numeric', '页面来源');
  56. $channel = Dever::load('channel', 'place_source')->getInfo($channel_id);
  57. $channel['score'] = Dever::load('info', 'place_score')->get($channel['score_id']);
  58. $channel['scope'] = '1,' . $channel['id'];
  59. $data['list'] = Dever::load('info', 'place_source')->getList($channel, false, 10);
  60. if (Place::$uid) {
  61. # 记录历史
  62. $history = ['uid' => Place::$uid, 'channel_id' => $channel_id, 'source' => $source, 'search' => $search];
  63. $info = Dever::db('search', 'place_user')->find($history);
  64. if (!$info) {
  65. $history['num'] = 1;
  66. Dever::db('search', 'place_user')->insert($history);
  67. } else {
  68. Dever::db('search', 'place_user')->update($info['id'], ['num' => ['+', 1]]);
  69. }
  70. Dever::db('search', 'place_source')->update(['channel_id' => $channel_id, 'value' => $search], ['num' => ['+', 1]]);
  71. Dever::load('log', 'place_score')->action('搜索')->add(Place::$uid);
  72. }
  73. # 搜索页轮播图、搜索页信息流
  74. $data['ad'] = Dever::load('ad', 'place_page')->gets([41,42], $channel_id, false);
  75. return $data;
  76. }
  77. # 频道分类页
  78. public function channel()
  79. {
  80. $channel_id = Dever::input('channel_id', 'is_numeric', '频道ID');
  81. # 获取频道信息
  82. $channel = Dever::load('channel', 'place_source')->getInfo($channel_id);
  83. $data['channel'] = [
  84. 'id' => $channel['id'],
  85. 'name' => $channel['name'],
  86. 'desc' => $channel['desc'],
  87. ];
  88. # 获取主分类
  89. $data['top'] = Dever::load('cate', 'place_source')->getTop($channel_id, 0);
  90. if ($data['top']) {
  91. foreach ($data['top'] as &$v) {
  92. $v['cate'][] = ['id' => $v['id'], 'name' => '全部'];
  93. $v['cate'] = array_merge($v['cate'], Dever::load('cate', 'place_source')->getList($channel_id, $v['id']));
  94. }
  95. }
  96. return $data;
  97. }
  98. # 分类列表页
  99. public function cate()
  100. {
  101. $show = Dever::input('show');
  102. $cate_id = Dever::input('id', 'is_numeric', '分类ID');
  103. $cate = Dever::load('cate', 'place_source')->getInfo($cate_id);
  104. $data['list'] = Dever::load('info', 'place_source')->getList($cate, false, 10);
  105. if ($show == 2) {
  106. # 仅展示分类列表
  107. return $data;
  108. }
  109. $data['cate'] = [
  110. 'id' => $cate['id'],
  111. 'name' => $cate['name'],
  112. 'desc' => $cate['desc'],
  113. ];
  114. $channel = Dever::load('channel', 'place_source')->getInfo($cate['channel_id']);
  115. $data['channel'] = [
  116. 'id' => $channel['id'],
  117. 'name' => $channel['name'],
  118. 'desc' => $channel['desc'],
  119. ];
  120. $data['child'] = [];
  121. if ($cate['parent_id'] == 0) {
  122. $cate_id = $cate['id'];
  123. $data['child'][] = ['id' => $cate['id'], 'name' => '全部'];
  124. $data['child'] = array_merge($data['child'], Dever::load('cate', 'place_source')->getList($cate['channel_id'], $cate['id']));
  125. } else {
  126. $cate_id = $cate['parent_id'];
  127. }
  128. # 列表页轮播图、列表页信息流
  129. $data['ad'] = Dever::load('ad', 'place_page')->gets([11,12], $cate['channel_id'], $cate_id);
  130. if (isset($data['ad']['info']) && $data['ad']['info']) {
  131. foreach ($data['list'] as $k => $v) {
  132. }
  133. }
  134. return $data;
  135. }
  136. # 资源介绍页
  137. public function info()
  138. {
  139. $source_id = Dever::input('id', 'is_numeric', '资源ID');
  140. $info = Dever::load('info', 'place_source')->getInfo($source_id);
  141. $data['user'] = Place::$user;
  142. $data['info'] = [
  143. 'id' => $info['id'],
  144. 'cate_id' => $info['cate_id'],
  145. 'channel_id' => $info['channel_id'],
  146. 'name' => $info['name'],
  147. 'info' => $info['info'],
  148. 'sku_name' => $info['sku_name'],
  149. 'price' => $info['price'],
  150. 'price_text' => $info['price_text'],
  151. 'm_price' => $info['m_price'],
  152. 'm_price_text' => $info['m_price_text'],
  153. 'rebate' => $info['rebate'],
  154. 'num_sell' => $info['num_sell'],
  155. 'stock' => $info['stock'],
  156. 'pic' => $info['pic'],
  157. 'content' => $info['content'],
  158. 'promotion_text' => $info['promotion_text'],
  159. 'promotion_tag' => $info['promotion_tag'],
  160. ];
  161. $data['have_vip'] = $info['have_vip'];
  162. $data['help'] = $info['help'];
  163. # 是否收藏
  164. $data['collect'] = $info['collect'];
  165. # 是否展示内容
  166. $content = Dever::db('content', 'place_source')->find(['info_id' => $source_id]);
  167. $data['content'] = false;
  168. if ($content) {
  169. $data['content'] = true;
  170. }
  171. # 是否展示工具
  172. /*
  173. $tool = Dever::db('tool', 'place_source')->find(['info_id' => $source_id]);
  174. $data['tool'] = false;
  175. if ($tool) {
  176. $data['tool'] = true;
  177. }*/
  178. # 获取评价
  179. $data['review'] = Act::load('review', 1, $source_id)->getList(['limit' => 3], 'content,pic,rate,open');
  180. # 评价总数
  181. $data['review_total'] = Act::load('review', 1, $source_id)->getTotal();
  182. # 详情页轮播、详情页信息流
  183. $data['ad'] = Dever::load('ad', 'place_page')->gets([21,22], $info['channel_id'], $info['cate_parent_id']);
  184. return $data;
  185. }
  186. # 资源sku
  187. public function sku()
  188. {
  189. $source_id = Dever::input('id', 'is_numeric', '资源ID');
  190. $data['sku'] = Dever::load('info', 'place_source')->getSku($source_id);
  191. return $data;
  192. }
  193. # 资源内容首页
  194. public function content()
  195. {
  196. $source_id = Dever::input('id', 'is_numeric', '资源ID');
  197. $source = Dever::load('info', 'place_source')->getBaseInfo($source_id);
  198. list($data['top'], $data['cate_id']) = Dever::load('content', 'place_source')->getCate($source_id);
  199. $data['top'] = array_merge([['id' => 0, 'name' => '全部']], $data['top']);
  200. # 内容页轮播、内容页信息流
  201. $data['ad'] = Dever::load('ad', 'place_page')->gets([31,32], $source['channel_id'], $source['cate_parent_id']);
  202. return $data;
  203. }
  204. # 获取内容列表
  205. public function contentList()
  206. {
  207. $source_id = Dever::input('id', 'is_numeric', '资源ID');
  208. $cate_id = Dever::input('cate_id', 'is_numeric', '分类ID', 0);
  209. $data['list'] = Dever::load('content', 'place_source')->getList($source_id, $cate_id);
  210. return $data;
  211. }
  212. # 资源内容列表详情页
  213. public function contentInfo()
  214. {
  215. $content_id = Dever::input('id', 'is_numeric', '内容ID');
  216. $data['content'] = Dever::load('content', 'place_source')->getInfo($content_id);
  217. $data['source'] = Dever::load('info', 'place_source')->getBaseInfo($data['content']['info_id']);
  218. return $data;
  219. }
  220. # 确认支付
  221. public function payConfirm()
  222. {
  223. if (!Place::$uid) {
  224. $this->showLogin();
  225. }
  226. $this->showBindMobile();
  227. $cate_id = Dever::input('type_id', 'is_numeric', '分类ID');
  228. $cate = Dever::load('cate', 'place_source')->getInfo($cate_id);
  229. //[{"id":6,"sku_id":10,"num":2}]
  230. $source = Dever::input('detail', 'is_string', '资源');
  231. $source = Dever::json_decode($source);
  232. if (!$source) {
  233. Dever::error('资源不存在');
  234. }
  235. if (!isset($source[0])) {
  236. Dever::error('资源不存在');
  237. }
  238. $data = Dever::load('source/pay', 'place_order')->get($source, $cate);
  239. return $data;
  240. }
  241. # 拉起支付
  242. public function pay()
  243. {
  244. $this->payConfirm();
  245. return Dever::load('source/pay', 'place_order')->act();
  246. }
  247. # 资源评论列表
  248. public function getReviewList()
  249. {
  250. $source_id = Dever::input('source_id', 'is_numeric', '资源ID');
  251. $num = Dever::input('num', 'is_numeric', '分页条数', 10);
  252. $data = Act::load('review', 1, $source_id)->getList(['num' => $num], 'content,pic,rate,open');
  253. $result['list'] = $data;
  254. $result['total'] = Dever::page('total');
  255. return $result;
  256. }
  257. # 资源订单列表
  258. public function getOrderList()
  259. {
  260. $where['uid'] = Place::$uid;
  261. $set['num'] = 10;
  262. $set['col'] = 'id,order_num,source_id,name,cash,num,cdate,status';
  263. $status = Dever::input('status');
  264. if ($status) {
  265. if ($status == 10) {
  266. $where['or'] = [
  267. 'refund_status' => '1',
  268. 'status' => '8',
  269. ];
  270. $where = ' uid = ' . $where['uid'] . ' and (refund_status = 1 or status = 8)';
  271. } else {
  272. $where['status'] = ['in', $status];
  273. }
  274. }
  275. $data = Dever::db('source', 'place_order')->select($where, $set);
  276. $result = [];
  277. if ($data) {
  278. foreach ($data as $k => $v) {
  279. $order = $this->getOrderInfo($v);
  280. if ($order) {
  281. $result[] = $order;
  282. }
  283. }
  284. }
  285. return $result;
  286. }
  287. }