Sellersns.php 12 KB

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