Fleagoods.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Fleagoods extends BaseFlea {
  17. public function initialize() {
  18. parent::initialize(); // TODO: Change the autogenerated stub
  19. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/fleacommon.lang.php');
  20. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/fleagoods.lang.php');
  21. }
  22. /**
  23. * 单个闲置物品信息页
  24. */
  25. public function index() {
  26. /**
  27. * 地区输出
  28. */
  29. $fleaarea_model = model('fleaarea');
  30. $area_array = $fleaarea_model->fleaarea_show();
  31. View::assign('area_one_level', $area_array['area_one_level']);
  32. View::assign('area_two_level', $area_array['area_two_level']);
  33. /**
  34. * 验证goods_id
  35. */
  36. $goods_id = intval(input('param.goods_id'));
  37. if ($goods_id<=0) {
  38. $this->error(lang('miss_argument')); //"缺少参数:商品编号"
  39. }
  40. //留言成功调转到留言
  41. if (!empty(input('get.succ'))) {
  42. if (input('get.succ') == 'succ') {
  43. $succ_link = HOME_SITE_URL.'/Fleagoods/index.html?goods_id=' . $goods_id . "#flea_message";
  44. @header("Location: " . $succ_link);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. if (empty(session('member_id'))) {
  132. ds_json_encode(10001,lang('flea_consult_notice'));
  133. }
  134. /**
  135. * 判断商品编号的存在性和合法性
  136. */
  137. $flea_model = model('flea');
  138. $special_condition = array();
  139. $goods_info = array();
  140. if (input('post.type_name') == '') {
  141. $special_condition['goods_id'] = intval(input('post.goods_id'));
  142. $goods_info = $flea_model->getFleaList($special_condition);
  143. }
  144. if (empty($goods_info)) {
  145. if (input('post.type_name') == '') {
  146. ds_json_encode(10001,lang('goods_index_goods_not_exists'));
  147. }
  148. }
  149. /**
  150. * 咨询内容的非空验证
  151. */
  152. if (trim(input('post.content')) === "") {
  153. ds_json_encode(10001,lang('goods_index_input_consult'));
  154. }
  155. $member_model = model('member');
  156. $member_info = $member_model->infoMember(array('member_id' => input('post.goods_id')));
  157. /**
  158. * 接收数据并保存
  159. */
  160. $input = array();
  161. $input['seller_id'] = $member_info['member_id'];
  162. $input['member_id'] = input('post.hide_name') ? 0 : (empty(session('member_id')) ? 0 : session('member_id'));
  163. $input['goods_id'] = input('post.goods_id');
  164. $input['email'] = input('post.email');
  165. $input['consult_content'] = input('post.content');
  166. if (input('post.type_name') == '') {
  167. $input['type'] = 'flea';
  168. } else {
  169. $input['type'] = input('post.type_name');
  170. }
  171. $consult = model('fleaconsult');
  172. if ($consult->addFleaconsult($input)) {
  173. /* 闲置物品表增加评论次数 */
  174. $data = array();
  175. $data['flea_commentnum'] = 'flea_commentnum+1';
  176. $flea_model->editFlea($data, array('goods_id'=>intval(input('post.goods_id'))));
  177. ds_json_encode(10000,lang('goods_index_consult_success'));
  178. } else {
  179. ds_json_encode(10001,lang('goods_index_consult_fail'));
  180. }
  181. }
  182. /**
  183. * 取得的时间间隔
  184. */
  185. public static function checkTime($time) {
  186. if ($time == '') {
  187. return false;
  188. }
  189. $catch_time = (TIMESTAMP - $time);
  190. if ($catch_time < 60) {
  191. echo $catch_time . lang('second');
  192. } elseif ($catch_time < 60 * 60) {
  193. echo intval($catch_time / 60) . lang('minute');
  194. } elseif ($catch_time < 60 * 60 * 24) {
  195. echo intval($catch_time / 60 / 60) . lang('hour');
  196. } elseif ($catch_time < 60 * 60 * 24 * 365) {
  197. echo intval($catch_time / 60 / 60 / 24) . lang('day');
  198. } elseif ($catch_time < 60 * 60 * 24 * 365 * 999) {
  199. echo intval($catch_time / 60 / 60 / 24 / 365) . lang('year');
  200. }
  201. }
  202. }