Fleagoods.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Fleagoods extends BaseFlea {
  18. public function initialize() {
  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. $fleaarea_model = model('fleaarea');
  31. $area_array = $fleaarea_model->fleaarea_show();
  32. View::assign('area_one_level', $area_array['area_one_level']);
  33. View::assign('area_two_level', $area_array['area_two_level']);
  34. /**
  35. * 验证goods_id
  36. */
  37. $goods_id = intval(input('param.goods_id'));
  38. if ($goods_id<=0) {
  39. $this->error(lang('miss_argument')); //"缺少参数:商品编号"
  40. }
  41. //留言成功调转到留言
  42. if (!empty(input('get.succ'))) {
  43. if (input('get.succ') == 'succ') {
  44. $succ_link = HOME_SITE_URL.'/Fleagoods/index.html?goods_id=' . $goods_id . "#flea_message";
  45. @header("Location: " . $succ_link);exit();
  46. }
  47. }
  48. /**
  49. * 实例化店铺商品模型
  50. */
  51. $flea_model = model('flea');
  52. $goods_array = $flea_model->getFleaList(array('goods_id' => $goods_id, 'goods_show' => '1'), 4);
  53. if (empty($goods_array))
  54. $this->error(lang('goods_index_no_goods')); //'商品不存在'
  55. /**
  56. * 图片路径
  57. */
  58. $goods_image_path = UPLOAD_SITE_URL . DIRECTORY_SEPARATOR . ATTACH_MFLEA . '/' . $goods_array[0]['member_id'] . '/';
  59. //店铺商品图片目录地址
  60. $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();
  61. $goods_array[0]['goods_tag'] = explode(',', str_replace(',', ',', $goods_array[0]['goods_tag']));
  62. /**
  63. * 页面title
  64. */
  65. View::assign('goods_title', $goods_array[0]['goods_name']);
  66. /**
  67. * 商品多图
  68. */
  69. $desc_image = $flea_model->getFleauploadList(array('store_id' => $goods_array[0]['member_id'], 'item_id' => $goods_array[0]['goods_id'], 'fleaupload_type' => 12));
  70. $flea_model->getThumb($desc_image, ATTACH_MFLEA . '/' . $goods_array[0]['member_id']);
  71. $image_key = 0;
  72. if (!empty($desc_image) && is_array($desc_image)) {//将封面图放到第一位显示
  73. $goods_image_1 = $goods_array[0]['goods_image']; //封面图
  74. foreach ($desc_image as $key => $val) {
  75. if ($goods_image_1 == $val['thumb_small']) {
  76. $image_key = $key;
  77. break;
  78. }
  79. }
  80. if ($image_key > 0) {//将封面图放到第一位显示
  81. $desc_image_0 = $desc_image[0];
  82. $desc_image[0] = $desc_image[$image_key];
  83. $desc_image[$image_key] = $desc_image_0;
  84. }
  85. }
  86. View::assign('goods', $goods_array[0]);
  87. isset($desc_image[0]) && View::assign('goods_image', $desc_image[0]);
  88. View::assign('desc_image', $desc_image);
  89. View::assign('goods_image_path', $goods_image_path);
  90. /**
  91. * 获取用户信息
  92. */
  93. $member_model = model('member');
  94. $member_info = $member_model->infoMember(array('member_id' => $goods_array[0]['member_id']));
  95. View::assign('flea_member_info', $member_info);
  96. /**
  97. * 闲置物品发布者的其他闲置物品
  98. */
  99. $other_flea_info2 = $flea_model->getFleaList(array('member_id' => $goods_array[0]['member_id'], 'goods_show' => '1'), '', '*');
  100. View::assign('goods_commend3', $other_flea_info2);
  101. /**
  102. * 得到商品的seo信息
  103. */
  104. $html_title = $goods_array[0]['goods_name'];
  105. $seo_keywords = $goods_array[0]['goods_keywords'];
  106. $seo_description = $goods_array[0]['goods_description'];
  107. View::assign('html_title', $html_title.'-'.config('ds_config.site_name'));
  108. View::assign('seo_keywords', $seo_keywords);
  109. View::assign('seo_description', $seo_description);
  110. /**
  111. * 得到商品咨询信息
  112. */
  113. $fleaconsult_model = model('fleaconsult');
  114. $consult_list = $fleaconsult_model->getFleaconsultList(array('fleaconsult.goods_id' => $goods_id), '', 'seller');
  115. View::assign('consult_list', $consult_list);
  116. /**
  117. * 浏览次数更新
  118. */
  119. $flea_model->editFlea(array('goods_click' => ($goods_array[0]['goods_click'] + 1)), array('goods_id'=>$goods_id));
  120. /**
  121. * 推荐
  122. */
  123. $goods_commend_list = $flea_model->getFleaList(array('pic_input' => '2'), 27);
  124. View::assign('goods_commend', $goods_commend_list);
  125. return View::fetch($this->template_dir . 'flea_goods');
  126. }
  127. /**
  128. * 闲置物品咨询添加
  129. */
  130. public function save_consult() {
  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. if ($time == '') {
  188. return false;
  189. }
  190. $catch_time = (TIMESTAMP - $time);
  191. if ($catch_time < 60) {
  192. echo $catch_time . lang('second');
  193. } elseif ($catch_time < 60 * 60) {
  194. echo intval($catch_time / 60) . lang('minute');
  195. } elseif ($catch_time < 60 * 60 * 24) {
  196. echo intval($catch_time / 60 / 60) . lang('hour');
  197. } elseif ($catch_time < 60 * 60 * 24 * 365) {
  198. echo intval($catch_time / 60 / 60 / 24) . lang('day');
  199. } elseif ($catch_time < 60 * 60 * 24 * 365 * 999) {
  200. echo intval($catch_time / 60 / 60 / 24 / 365) . lang('year');
  201. }
  202. }
  203. }