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