Fleagoods.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Fleagoods extends BaseFlea
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize(); // TODO: Change the autogenerated stub
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/fleacommon.lang.php');
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/fleagoods.lang.php');
  19. }
  20. /**
  21. * 单个闲置物品信息页
  22. */
  23. public function index()
  24. {
  25. /**
  26. * 地区输出
  27. */
  28. $fleaarea_model = model('fleaarea');
  29. $area_array = $fleaarea_model->fleaarea_show();
  30. View::assign('area_one_level', $area_array['area_one_level']);
  31. View::assign('area_two_level', $area_array['area_two_level']);
  32. /**
  33. * 验证goods_id
  34. */
  35. $goods_id = intval(input('param.goods_id'));
  36. if ($goods_id <= 0) {
  37. $this->error(lang('miss_argument')); //"缺少参数:商品编号"
  38. }
  39. //留言成功调转到留言
  40. if (!empty(input('get.succ'))) {
  41. if (input('get.succ') == 'succ') {
  42. $succ_link = HOME_SITE_URL . '/Fleagoods/index.html?goods_id=' . $goods_id . "#flea_message";
  43. @header("Location: " . $succ_link);
  44. exit();
  45. }
  46. }
  47. /**
  48. * 实例化店铺商品模型
  49. */
  50. $flea_model = model('flea');
  51. $goods_array = $flea_model->getFleaList(array('goods_id' => $goods_id, 'goods_show' => '1'), 4);
  52. if (empty($goods_array))
  53. $this->error(lang('goods_index_no_goods')); //'商品不存在'
  54. /**
  55. * 图片路径
  56. */
  57. $goods_image_path = UPLOAD_SITE_URL . DIRECTORY_SEPARATOR . ATTACH_MFLEA . '/' . $goods_array[0]['member_id'] . '/';
  58. //店铺商品图片目录地址
  59. $goods_array[0]['goods_image'] = $goods_array[0]['goods_image'] != '' ? ds_get_pic(ATTACH_MFLEA . '/' . $goods_array[0]['member_id'], $goods_array[0]['goods_image']) : goods_thumb();
  60. $goods_array[0]['goods_tag'] = explode(',', str_replace(',', ',', $goods_array[0]['goods_tag']));
  61. /**
  62. * 页面title
  63. */
  64. View::assign('goods_title', $goods_array[0]['goods_name']);
  65. /**
  66. * 商品多图
  67. */
  68. $desc_image = $flea_model->getFleauploadList(array('store_id' => $goods_array[0]['member_id'], 'item_id' => $goods_array[0]['goods_id'], 'fleaupload_type' => 12));
  69. $flea_model->getThumb($desc_image, ATTACH_MFLEA . '/' . $goods_array[0]['member_id']);
  70. $image_key = 0;
  71. if (!empty($desc_image) && is_array($desc_image)) { //将封面图放到第一位显示
  72. $goods_image_1 = $goods_array[0]['goods_image']; //封面图
  73. foreach ($desc_image as $key => $val) {
  74. if ($goods_image_1 == $val['thumb_small']) {
  75. $image_key = $key;
  76. break;
  77. }
  78. }
  79. if ($image_key > 0) { //将封面图放到第一位显示
  80. $desc_image_0 = $desc_image[0];
  81. $desc_image[0] = $desc_image[$image_key];
  82. $desc_image[$image_key] = $desc_image_0;
  83. }
  84. }
  85. View::assign('goods', $goods_array[0]);
  86. isset($desc_image[0]) && View::assign('goods_image', $desc_image[0]);
  87. View::assign('desc_image', $desc_image);
  88. View::assign('goods_image_path', $goods_image_path);
  89. /**
  90. * 获取用户信息
  91. */
  92. $member_model = model('member');
  93. $member_info = $member_model->infoMember(array('member_id' => $goods_array[0]['member_id']));
  94. View::assign('flea_member_info', $member_info);
  95. /**
  96. * 闲置物品发布者的其他闲置物品
  97. */
  98. $other_flea_info2 = $flea_model->getFleaList(array('member_id' => $goods_array[0]['member_id'], 'goods_show' => '1'), '', '*');
  99. View::assign('goods_commend3', $other_flea_info2);
  100. /**
  101. * 得到商品的seo信息
  102. */
  103. $html_title = $goods_array[0]['goods_name'];
  104. $seo_keywords = $goods_array[0]['goods_keywords'];
  105. $seo_description = $goods_array[0]['goods_description'];
  106. View::assign('html_title', $html_title . '-' . config('ds_config.site_name'));
  107. View::assign('seo_keywords', $seo_keywords);
  108. View::assign('seo_description', $seo_description);
  109. /**
  110. * 得到商品咨询信息
  111. */
  112. $fleaconsult_model = model('fleaconsult');
  113. $consult_list = $fleaconsult_model->getFleaconsultList(array('fleaconsult.goods_id' => $goods_id), '', 'seller');
  114. View::assign('consult_list', $consult_list);
  115. /**
  116. * 浏览次数更新
  117. */
  118. $flea_model->editFlea(array('goods_click' => ($goods_array[0]['goods_click'] + 1)), array('goods_id' => $goods_id));
  119. /**
  120. * 推荐
  121. */
  122. $goods_commend_list = $flea_model->getFleaList(array('pic_input' => '2'), 27);
  123. View::assign('goods_commend', $goods_commend_list);
  124. return View::fetch($this->template_dir . 'flea_goods');
  125. }
  126. /**
  127. * 闲置物品咨询添加
  128. */
  129. public function save_consult()
  130. {
  131. //判断是否登录
  132. if (empty(session('member_id'))) {
  133. ds_json_encode(10001, lang('flea_consult_notice'));
  134. }
  135. /**
  136. * 判断商品编号的存在性和合法性
  137. */
  138. $flea_model = model('flea');
  139. $special_condition = array();
  140. $goods_info = array();
  141. if (input('post.type_name') == '') {
  142. $special_condition['goods_id'] = intval(input('post.goods_id'));
  143. $goods_info = $flea_model->getFleaList($special_condition);
  144. }
  145. if (empty($goods_info)) {
  146. if (input('post.type_name') == '') {
  147. ds_json_encode(10001, lang('goods_index_goods_not_exists'));
  148. }
  149. }
  150. /**
  151. * 咨询内容的非空验证
  152. */
  153. if (trim(input('post.content')) === "") {
  154. ds_json_encode(10001, lang('goods_index_input_consult'));
  155. }
  156. $member_model = model('member');
  157. $member_info = $member_model->infoMember(array('member_id' => input('post.goods_id')));
  158. /**
  159. * 接收数据并保存
  160. */
  161. $input = array();
  162. $input['seller_id'] = $member_info['member_id'];
  163. $input['member_id'] = input('post.hide_name') ? 0 : (empty(session('member_id')) ? 0 : session('member_id'));
  164. $input['goods_id'] = input('post.goods_id');
  165. $input['email'] = input('post.email');
  166. $input['consult_content'] = input('post.content');
  167. if (input('post.type_name') == '') {
  168. $input['type'] = 'flea';
  169. } else {
  170. $input['type'] = input('post.type_name');
  171. }
  172. $consult = model('fleaconsult');
  173. if ($consult->addFleaconsult($input)) {
  174. /* 闲置物品表增加评论次数 */
  175. $data = array();
  176. $data['flea_commentnum'] = 'flea_commentnum+1';
  177. $flea_model->editFlea($data, array('goods_id' => intval(input('post.goods_id'))));
  178. ds_json_encode(10000, lang('goods_index_consult_success'));
  179. } else {
  180. ds_json_encode(10001, lang('goods_index_consult_fail'));
  181. }
  182. }
  183. /**
  184. * 取得的时间间隔
  185. */
  186. public static function checkTime($time)
  187. {
  188. if ($time == '') {
  189. return false;
  190. }
  191. $catch_time = (TIMESTAMP - $time);
  192. if ($catch_time < 60) {
  193. echo $catch_time . lang('second');
  194. } elseif ($catch_time < 60 * 60) {
  195. echo intval($catch_time / 60) . lang('minute');
  196. } elseif ($catch_time < 60 * 60 * 24) {
  197. echo intval($catch_time / 60 / 60) . lang('hour');
  198. } elseif ($catch_time < 60 * 60 * 24 * 365) {
  199. echo intval($catch_time / 60 / 60 / 24) . lang('day');
  200. } elseif ($catch_time < 60 * 60 * 24 * 365 * 999) {
  201. echo intval($catch_time / 60 / 60 / 24 / 365) . lang('year');
  202. }
  203. }
  204. }