Sellersns.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 Sellersns extends BaseSeller {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellersns.lang.php');
  21. }
  22. public function index() {
  23. $this->add();
  24. }
  25. /**
  26. * 发布动态
  27. */
  28. public function add() {
  29. $goods_model = model('goods');
  30. // 热销商品
  31. // where条件
  32. $where = array(array('store_id' ,'=', session('store_id')));
  33. $field = 'goods_id,goods_name,goods_image,goods_price,goods_salenum,store_id';
  34. $order = 'goods_salenum desc';
  35. $hotsell_list = $goods_model->getGoodsOnlineList($where, $field, 0, $order, 8);
  36. View::assign('hotsell_list', $hotsell_list);
  37. // 新品
  38. // where条件
  39. $where = array(array('store_id' ,'=', session('store_id')));
  40. $field = 'goods_id,goods_name,goods_image,goods_price,goods_salenum,store_id';
  41. $order = 'goods_id desc';
  42. $new_list = $goods_model->getGoodsOnlineList($where, $field, 0, $order, 8);
  43. View::assign('new_list', $new_list);
  44. $this->setSellerCurItem('store_sns_add');
  45. $this->setSellerCurMenu('sellersns');
  46. echo View::fetch($this->template_dir . 'store_sns_add');
  47. exit;
  48. }
  49. /**
  50. * 上传图片
  51. */
  52. public function image_upload() {
  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. $data = [
  104. 'content' => input('param.content'),
  105. 'goods_url' => input('goods_url')
  106. ];
  107. $sellersns_validate = ds_validate('sellersns');
  108. if (!$sellersns_validate->scene('store_sns_save')->check($data)) {
  109. ds_json_encode(10001, $sellersns_validate->getError());
  110. }
  111. $goodsdata = '';
  112. $content = '';
  113. $type = intval(input('param.type'));
  114. switch ($type) {
  115. case '2':
  116. $sns_image = trim(input('param.sns_image'));
  117. if ($sns_image != '')
  118. $content = '<div class="fd-media">
  119. <div class="thumb-image"><a href="javascript:void(0);" ds_type="thumb-image"><img src="' . $sns_image . '" /><i></i></a></div>
  120. <div class="origin-image"><a href="javascript:void(0);" ds_type="origin-image"></a></div>
  121. </div>';
  122. break;
  123. case '9':
  124. $data = $this->getGoodsByUrl(html_entity_decode(input('param.goods_url')));
  125. $goodsdata = addslashes(json_encode($data));
  126. break;
  127. case '10':
  128. $goods_id_array = input('post.goods_id/a'); #获取数组
  129. if (empty($goods_id_array)) {
  130. ds_json_encode(10001, lang('store_sns_choose_goods'));
  131. }
  132. $field = 'goods_id,store_id,goods_name,goods_image,goods_price,goods_freight';
  133. $where = array(array('store_id', '=', session('store_id')), array('goods_id', 'in', $goods_id_array));
  134. $goods_array = model('goods')->getGoodsList($where, $field);
  135. if (!empty($goods_array) && is_array($goods_array)) {
  136. $goodsdata = array();
  137. foreach ($goods_array as $val) {
  138. $goodsdata[] = addslashes(json_encode($val));
  139. }
  140. }
  141. break;
  142. case '3':
  143. $goods_id_array = input('post.goods_id/a'); #获取数组
  144. if (empty($goods_id_array)) {
  145. ds_json_encode(10001, lang('store_sns_choose_goods'));
  146. }
  147. $field = 'goods_id,store_id,goods_name,goods_image,goods_price,goods_freight';
  148. $where = array(array('store_id', '=', session('store_id')), array('goods_id', 'in', $goods_id_array));
  149. $goods_array = model('goods')->getGoodsList($where, $field);
  150. if (!empty($goods_array) && is_array($goods_array)) {
  151. $goodsdata = array();
  152. foreach ($goods_array as $val) {
  153. $goodsdata[] = addslashes(json_encode($val));
  154. }
  155. }
  156. break;
  157. default:
  158. ds_json_encode(10001, lang('param_error'));
  159. }
  160. $storesnstracelog_model = model('storesnstracelog');
  161. // 插入数据
  162. $stracelog_array = array();
  163. $stracelog_array['stracelog_storeid'] = $this->store_info['store_id'];
  164. $stracelog_array['stracelog_storename'] = $this->store_info['store_name'];
  165. $stracelog_array['stracelog_storelogo'] = empty($this->store_info['store_avatar']) ? '' : $this->store_info['store_avatar'];
  166. $stracelog_array['stracelog_title'] = input('param.content');
  167. $stracelog_array['stracelog_content'] = $content;
  168. $stracelog_array['stracelog_time'] = TIMESTAMP;
  169. $stracelog_array['stracelog_type'] = $type;
  170. if (isset($goodsdata) && is_array($goodsdata)) {
  171. $stracelog = array();
  172. foreach ($goodsdata as $val) {
  173. $stracelog_array['stracelog_goodsdata'] = $val;
  174. $stracelog[] = $stracelog_array;
  175. }
  176. $rs = $storesnstracelog_model->addStoresnstracelogAll($stracelog);
  177. } else {
  178. $stracelog_array['stracelog_goodsdata'] = $goodsdata;
  179. $rs = $storesnstracelog_model->addStoresnstracelog($stracelog_array);
  180. }
  181. if ($rs) {
  182. ds_json_encode(10000, lang('ds_common_op_succ'));
  183. } else {
  184. ds_json_encode(10001, lang('ds_common_op_fail'));
  185. }
  186. }
  187. /**
  188. * 动态设置
  189. */
  190. public function setting() {
  191. // 实例化模型
  192. $storesnssetting_model = model('storesnssetting');
  193. $storesnsset_info = $storesnssetting_model->getStoresnssettingInfo(array('storesnsset_storeid' => session('store_id')));
  194. if (request()->isPost()) {
  195. $update = array();
  196. $update['storesnsset_storeid'] = session('store_id');
  197. $update['storesnsset_new'] = input('post.new', 0);
  198. $update['storesnsset_newtitle'] = trim(input('post.new_title'));
  199. $update['storesnsset_coupon'] = input('post.coupon', 0);
  200. $update['storesnsset_coupontitle'] = trim(input('post.coupon_title'));
  201. $update['storesnsset_xianshi'] = input('post.xianshi', 0);
  202. $update['storesnsset_xianshititle'] = trim(input('post.xianshi_title'));
  203. $update['storesnsset_mansong'] = input('post.mansong', 0);
  204. $update['storesnsset_mansongtitle'] = trim(input('post.mansong_title'));
  205. $update['storesnsset_bundling'] = input('post.bundling', 0);
  206. $update['storesnsset_bundlingtitle'] = trim(input('post.bundling_title'));
  207. $update['storesnsset_groupbuy'] = input('post.groupbuy', 0);
  208. $update['storesnsset_groupbuytitle'] = trim(input('post.groupbuy_title'));
  209. $info = !empty($storesnsset_info) ? true : false;
  210. if($info){
  211. $result = $storesnssetting_model->editStoresnssetting($update,array(array('storesnsset_storeid','=',$storesnsset_info['storesnsset_storeid'])));
  212. }else{
  213. $result = $storesnssetting_model->addStoresnssetting($update);
  214. }
  215. if ($result >= 0) {
  216. ds_json_encode(10000, lang('ds_common_save_succ'));
  217. } else {
  218. ds_json_encode(10001, lang('ds_common_save_fail'));
  219. }
  220. } else {
  221. View::assign('storesnsset_info', $storesnsset_info);
  222. $this->setSellerCurItem('store_sns_setting');
  223. $this->setSellerCurMenu('sellersns');
  224. return View::fetch($this->template_dir . 'store_sns_setting');
  225. }
  226. }
  227. /**
  228. * 用户中心右边,小导航
  229. *
  230. * @param string $menu_type 导航类型
  231. * @param string $menu_key 当前导航的menu_key
  232. * @return
  233. */
  234. protected function getSellerItemList() {
  235. $menu_array = array(
  236. array('name' => 'store_sns_add', 'text' => lang('store_sns_add'), 'url' => (string) url('Sellersns/add')),
  237. array('name' => 'store_sns_setting', 'text' => lang('store_sns_setting'), 'url' => (string) url('Sellersns/setting')),
  238. array('name' => 'store_sns_brower', 'text' => lang('store_sns_browse'), 'url' => (string) url('Storesnshome/index', ['sid' => session('store_id')])),
  239. );
  240. return $menu_array;
  241. }
  242. /**
  243. * 根据url取得商品信息
  244. */
  245. private function getGoodsByUrl($url) {
  246. $array = parse_url($url);
  247. if (isset($array['query'])) {
  248. // 未开启伪静态
  249. parse_str($array['query'], $arr);
  250. $id = $arr['goods_id'];
  251. } else {
  252. // 开启伪静态
  253. $item = explode('/', $array['path']);
  254. $item = end($item);
  255. $id = preg_replace('/item-(\d+)\.html/i', '$1', $item);
  256. }
  257. if (intval($id) > 0) {
  258. // 查询商品信息
  259. $result = model('goods')->getGoodsInfoByID($id);
  260. if (!empty($result) && is_array($result)) {
  261. return $result;
  262. } else {
  263. ds_json_encode(10001, lang('store_sns_goods_url_error'));
  264. }
  265. } else {
  266. ds_json_encode(10001, lang('store_sns_goods_url_error'));
  267. }
  268. }
  269. }
  270. ?>