Sellersns.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 Sellersns extends BaseSeller
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellersns.lang.php');
  18. }
  19. public function index()
  20. {
  21. $this->add();
  22. }
  23. /**
  24. * 发布动态
  25. */
  26. public function add()
  27. {
  28. $goods_model = model('goods');
  29. // 热销商品
  30. // where条件
  31. $where = array(array('store_id', '=', session('store_id')));
  32. $field = 'goods_id,goods_name,goods_image,goods_price,goods_salenum,store_id';
  33. $order = 'goods_salenum desc';
  34. $hotsell_list = $goods_model->getGoodsOnlineList($where, $field, 0, $order, 8);
  35. View::assign('hotsell_list', $hotsell_list);
  36. // 新品
  37. // where条件
  38. $where = array(array('store_id', '=', session('store_id')));
  39. $field = 'goods_id,goods_name,goods_image,goods_price,goods_salenum,store_id';
  40. $order = 'goods_id desc';
  41. $new_list = $goods_model->getGoodsOnlineList($where, $field, 0, $order, 8);
  42. View::assign('new_list', $new_list);
  43. $this->setSellerCurItem('store_sns_add');
  44. $this->setSellerCurMenu('sellersns');
  45. echo View::fetch($this->template_dir . 'store_sns_add');
  46. exit;
  47. }
  48. /**
  49. * 上传图片
  50. */
  51. public function image_upload()
  52. {
  53. // 判断图片数量是否超限
  54. $album_model = model('album');
  55. $album_limit = $this->store_grade['storegrade_album_limit'];
  56. if ($album_limit > 0) {
  57. $album_count = $album_model->getCount(array('store_id' => session('store_id')));
  58. if ($album_count >= $album_limit) {
  59. $error = lang('store_goods_album_climit');
  60. exit(json_encode(array('error' => $error)));
  61. }
  62. }
  63. $class_info = $album_model->getOne(array('store_id' => session('store_id'), 'aclass_isdefault' => 1), 'albumclass');
  64. $time = TIMESTAMP;
  65. //上传文件保存路径
  66. $upload_path = ATTACH_GOODS . DIRECTORY_SEPARATOR . session('store_id') . '/' . date('Ymd', $time);
  67. $save_name = session('store_id') . '_' . date('YmdHis', $time) . rand(10000, 99999);
  68. $file = input('param.id');
  69. $result = upload_albumpic($upload_path, $file, $save_name);
  70. if ($result['code'] == '10000') {
  71. $img_path = $result['result'];
  72. // 取得图像大小
  73. list($width, $height, $type, $attr) = getimagesize($img_path);
  74. $img_path = substr(strrchr($img_path, "/"), 1);
  75. } else {
  76. exit($result['message']);
  77. }
  78. // 存入相册
  79. $insert_array = array();
  80. $insert_array['apic_name'] = $img_path;
  81. $insert_array['apic_tag'] = '';
  82. $insert_array['aclass_id'] = $class_info['aclass_id'];
  83. $insert_array['apic_cover'] = $img_path;
  84. $insert_array['apic_size'] = intval($_FILES[input('param.id')]['size']);
  85. $insert_array['apic_spec'] = $width . 'x' . $height;
  86. $insert_array['apic_uploadtime'] = $time;
  87. $insert_array['store_id'] = session('store_id');
  88. $album_model->addAlbumpic($insert_array);
  89. $data = array();
  90. $data['image'] = goods_cthumb($img_path, 240, session('store_id'));
  91. // 整理为json格式
  92. $output = json_encode($data);
  93. echo $output;
  94. exit();
  95. }
  96. /**
  97. * 保存动态
  98. */
  99. public function store_sns_save()
  100. {
  101. /**
  102. * 验证表单
  103. */
  104. $data = [
  105. 'content' => input('param.content'),
  106. 'goods_url' => input('goods_url')
  107. ];
  108. $sellersns_validate = ds_validate('sellersns');
  109. if (!$sellersns_validate->scene('store_sns_save')->check($data)) {
  110. ds_json_encode(10001, $sellersns_validate->getError());
  111. }
  112. $goodsdata = '';
  113. $content = '';
  114. $type = intval(input('param.type'));
  115. switch ($type) {
  116. case '2':
  117. $sns_image = trim(input('param.sns_image'));
  118. if ($sns_image != '')
  119. $content = '<div class="fd-media">
  120. <div class="thumb-image"><a href="javascript:void(0);" ds_type="thumb-image"><img src="' . $sns_image . '" /><i></i></a></div>
  121. <div class="origin-image"><a href="javascript:void(0);" ds_type="origin-image"></a></div>
  122. </div>';
  123. break;
  124. case '9':
  125. $data = $this->getGoodsByUrl(html_entity_decode(input('param.goods_url')));
  126. $goodsdata = addslashes(json_encode($data));
  127. break;
  128. case '10':
  129. $goods_id_array = input('post.goods_id/a'); #获取数组
  130. if (empty($goods_id_array)) {
  131. ds_json_encode(10001, lang('store_sns_choose_goods'));
  132. }
  133. $field = 'goods_id,store_id,goods_name,goods_image,goods_price,goods_freight';
  134. $where = array(array('store_id', '=', session('store_id')), array('goods_id', 'in', $goods_id_array));
  135. $goods_array = model('goods')->getGoodsList($where, $field);
  136. if (!empty($goods_array) && is_array($goods_array)) {
  137. $goodsdata = array();
  138. foreach ($goods_array as $val) {
  139. $goodsdata[] = addslashes(json_encode($val));
  140. }
  141. }
  142. break;
  143. case '3':
  144. $goods_id_array = input('post.goods_id/a'); #获取数组
  145. if (empty($goods_id_array)) {
  146. ds_json_encode(10001, lang('store_sns_choose_goods'));
  147. }
  148. $field = 'goods_id,store_id,goods_name,goods_image,goods_price,goods_freight';
  149. $where = array(array('store_id', '=', session('store_id')), array('goods_id', 'in', $goods_id_array));
  150. $goods_array = model('goods')->getGoodsList($where, $field);
  151. if (!empty($goods_array) && is_array($goods_array)) {
  152. $goodsdata = array();
  153. foreach ($goods_array as $val) {
  154. $goodsdata[] = addslashes(json_encode($val));
  155. }
  156. }
  157. break;
  158. default:
  159. ds_json_encode(10001, lang('param_error'));
  160. }
  161. $storesnstracelog_model = model('storesnstracelog');
  162. // 插入数据
  163. $stracelog_array = array();
  164. $stracelog_array['stracelog_storeid'] = $this->store_info['store_id'];
  165. $stracelog_array['stracelog_storename'] = $this->store_info['store_name'];
  166. $stracelog_array['stracelog_storelogo'] = empty($this->store_info['store_avatar']) ? '' : $this->store_info['store_avatar'];
  167. $stracelog_array['stracelog_title'] = input('param.content');
  168. $stracelog_array['stracelog_content'] = $content;
  169. $stracelog_array['stracelog_time'] = TIMESTAMP;
  170. $stracelog_array['stracelog_type'] = $type;
  171. if (isset($goodsdata) && is_array($goodsdata)) {
  172. $stracelog = array();
  173. foreach ($goodsdata as $val) {
  174. $stracelog_array['stracelog_goodsdata'] = $val;
  175. $stracelog[] = $stracelog_array;
  176. }
  177. $rs = $storesnstracelog_model->addStoresnstracelogAll($stracelog);
  178. } else {
  179. $stracelog_array['stracelog_goodsdata'] = $goodsdata;
  180. $rs = $storesnstracelog_model->addStoresnstracelog($stracelog_array);
  181. }
  182. if ($rs) {
  183. ds_json_encode(10000, lang('ds_common_op_succ'));
  184. } else {
  185. ds_json_encode(10001, lang('ds_common_op_fail'));
  186. }
  187. }
  188. /**
  189. * 动态设置
  190. */
  191. public function setting()
  192. {
  193. // 实例化模型
  194. $storesnssetting_model = model('storesnssetting');
  195. $storesnsset_info = $storesnssetting_model->getStoresnssettingInfo(array('storesnsset_storeid' => session('store_id')));
  196. if (request()->isPost()) {
  197. $update = array();
  198. $update['storesnsset_storeid'] = session('store_id');
  199. $update['storesnsset_new'] = input('post.new', 0);
  200. $update['storesnsset_newtitle'] = trim(input('post.new_title'));
  201. $update['storesnsset_coupon'] = input('post.coupon', 0);
  202. $update['storesnsset_coupontitle'] = trim(input('post.coupon_title'));
  203. $update['storesnsset_xianshi'] = input('post.xianshi', 0);
  204. $update['storesnsset_xianshititle'] = trim(input('post.xianshi_title'));
  205. $update['storesnsset_mansong'] = input('post.mansong', 0);
  206. $update['storesnsset_mansongtitle'] = trim(input('post.mansong_title'));
  207. $update['storesnsset_bundling'] = input('post.bundling', 0);
  208. $update['storesnsset_bundlingtitle'] = trim(input('post.bundling_title'));
  209. $update['storesnsset_groupbuy'] = input('post.groupbuy', 0);
  210. $update['storesnsset_groupbuytitle'] = trim(input('post.groupbuy_title'));
  211. $info = !empty($storesnsset_info) ? true : false;
  212. if ($info) {
  213. $result = $storesnssetting_model->editStoresnssetting($update, array(array('storesnsset_storeid', '=', $storesnsset_info['storesnsset_storeid'])));
  214. } else {
  215. $result = $storesnssetting_model->addStoresnssetting($update);
  216. }
  217. if ($result >= 0) {
  218. ds_json_encode(10000, lang('ds_common_save_succ'));
  219. } else {
  220. ds_json_encode(10001, lang('ds_common_save_fail'));
  221. }
  222. } else {
  223. View::assign('storesnsset_info', $storesnsset_info);
  224. $this->setSellerCurItem('store_sns_setting');
  225. $this->setSellerCurMenu('sellersns');
  226. return View::fetch($this->template_dir . 'store_sns_setting');
  227. }
  228. }
  229. /**
  230. * 用户中心右边,小导航
  231. *
  232. * @param string $menu_type 导航类型
  233. * @param string $menu_key 当前导航的menu_key
  234. * @return
  235. */
  236. protected function getSellerItemList()
  237. {
  238. $menu_array = array(
  239. array('name' => 'store_sns_add', 'text' => lang('store_sns_add'), 'url' => (string) url('Sellersns/add')),
  240. array('name' => 'store_sns_setting', 'text' => lang('store_sns_setting'), 'url' => (string) url('Sellersns/setting')),
  241. array('name' => 'store_sns_brower', 'text' => lang('store_sns_browse'), 'url' => (string) url('Storesnshome/index', ['sid' => session('store_id')])),
  242. );
  243. return $menu_array;
  244. }
  245. /**
  246. * 根据url取得商品信息
  247. */
  248. private function getGoodsByUrl($url)
  249. {
  250. $array = parse_url($url);
  251. if (isset($array['query'])) {
  252. // 未开启伪静态
  253. parse_str($array['query'], $arr);
  254. $id = $arr['goods_id'];
  255. } else {
  256. // 开启伪静态
  257. $item = explode('/', $array['path']);
  258. $item = end($item);
  259. $id = preg_replace('/item-(\d+)\.html/i', '$1', $item);
  260. }
  261. if (intval($id) > 0) {
  262. // 查询商品信息
  263. $result = model('goods')->getGoodsInfoByID($id);
  264. if (!empty($result) && is_array($result)) {
  265. return $result;
  266. } else {
  267. ds_json_encode(10001, lang('store_sns_goods_url_error'));
  268. }
  269. } else {
  270. ds_json_encode(10001, lang('store_sns_goods_url_error'));
  271. }
  272. }
  273. }