You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
4.9 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Weixin;
  3. use App\Http\Controllers\Weixin\CommonController;
  4. use Illuminate\Http\Request;
  5. use App\Common\ReturnCode;
  6. class GoodsController extends BaseController
  7. {
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. }
  12. //商品详情
  13. public function goodsDetail($id)
  14. {
  15. $postdata = array(
  16. 'id' => $id
  17. );
  18. if (isset($_SESSION['weixin_user_info'])) {
  19. $postdata['user_id'] = $_SESSION['weixin_user_info']['id'];
  20. }
  21. $url = env('APP_API_URL') . "/goods_detail";
  22. $res = curl_request($url, $postdata, 'GET');
  23. $data['post'] = $res['data'];
  24. if (!$data['post']) {
  25. $this->error_jump(ReturnCode::NO_FOUND, route('weixin'), 3);
  26. }
  27. //添加浏览记录
  28. if (isset($_SESSION['weixin_user_info'])) {
  29. $postdata = array(
  30. 'goods_id' => $id,
  31. 'access_token' => $_SESSION['weixin_user_info']['access_token']
  32. );
  33. $url = env('APP_API_URL') . "/user_goods_history_add";
  34. curl_request($url, $postdata, 'POST');
  35. }
  36. return view('weixin.goods.goodsDetail', $data);
  37. }
  38. //商品列表
  39. public function goodsList(Request $request)
  40. {
  41. if ($request->input('typeid', null) != null) {
  42. $param['typeid'] = $request->input('typeid');
  43. }
  44. if ($request->input('tuijian', null) != null) {
  45. $param['tuijian'] = $request->input('tuijian');
  46. }
  47. if ($request->input('keyword', null) != null) {
  48. $param['keyword'] = $request->input('keyword');
  49. }
  50. if ($request->input('status', null) != null) {
  51. $param['status'] = $request->input('status');
  52. }
  53. if ($request->input('is_promote', null) != null) {
  54. $param['is_promote'] = $request->input('is_promote');
  55. }
  56. if ($request->input('orderby', null) != null) {
  57. $param['orderby'] = $request->input('orderby');
  58. }
  59. if ($request->input('max_price', null) != null) {
  60. $param['max_price'] = $request->input('max_price');
  61. } else {
  62. $param['max_price'] = 99999;
  63. }
  64. if ($request->input('min_price', null) != null) {
  65. $param['min_price'] = $request->input('min_price');
  66. } else {
  67. $param['min_price'] = 0;
  68. }
  69. if ($request->input('brand_id', null) != null) {
  70. $param['brand_id'] = $request->input('brand_id');
  71. }
  72. //商品列表
  73. $postdata = $param;
  74. $postdata['limit'] = 10;
  75. $postdata['offset'] = 0;
  76. $url = env('APP_API_URL') . "/goods_list";
  77. $res = curl_request($url, $postdata, 'GET');
  78. $data['goods_list'] = $res['data']['list'];
  79. $data['request_param'] = $param;
  80. return view('weixin.goods.goodsList', $data);
  81. }
  82. //商品列表
  83. public function categoryGoodsList(Request $request)
  84. {
  85. $data['typeid'] = 0;
  86. if ($request->input('typeid', null) != null) {
  87. $data['typeid'] = $request->input('typeid');
  88. }
  89. $pagesize = 10;
  90. $offset = 0;
  91. if (isset($_REQUEST['page'])) {
  92. $offset = ($_REQUEST['page'] - 1) * $pagesize;
  93. }
  94. //商品列表
  95. $postdata = array(
  96. 'typeid' => $data['typeid'],
  97. 'limit' => $pagesize,
  98. 'offset' => $offset
  99. );
  100. $url = env('APP_API_URL') . "/goods_list";
  101. $res = curl_request($url, $postdata, 'GET');
  102. $data['list'] = $res['data']['list'];
  103. $data['totalpage'] = ceil($res['data']['count'] / $pagesize);
  104. if (isset($_REQUEST['page_ajax']) && $_REQUEST['page_ajax'] == 1) {
  105. $html = '';
  106. if ($res['data']['list']) {
  107. foreach ($res['data']['list'] as $k => $v) {
  108. $html .= '<li>';
  109. $html .= '<a href="' . $v['goods_detail_url'] . '"><img alt="' . $v['title'] . '" src="' . $v['litpic'] . '"><div class="goods_info"><p class="goods_tit">';
  110. if ($v['is_promote_goods'] > 0) {
  111. $html .= '<span class="badge_comm" style="background-color:#f23030;">Hot</span>';
  112. }
  113. $html .= $v['title'] . '</p><div class="goods_price">¥<b>' . $v['price'] . '</b><span class="fr">' . $v['sale'] . '人付款</span></div></div></a>';
  114. $html .= '</li>';
  115. }
  116. }
  117. exit(json_encode($html));
  118. }
  119. //商品分类列表
  120. $postdata = array(
  121. 'pid' => 0,
  122. 'limit' => 15,
  123. 'offset' => 0
  124. );
  125. $url = env('APP_API_URL') . "/goodstype_list";
  126. $res = curl_request($url, $postdata, 'GET');
  127. $data['goodstype_list'] = $res['data']['list'];
  128. return view('weixin.goods.categoryGoodsList', $data);
  129. }
  130. }