Selleralbum.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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 Selleralbum extends BaseSeller {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/selleralbum.lang.php');
  21. }
  22. public function index() {
  23. $this->album_cate();
  24. exit;
  25. }
  26. /**
  27. * 相册分类列表
  28. *
  29. */
  30. public function album_cate() {
  31. $album_model = model('album');
  32. /**
  33. * 验证是否存在默认相册
  34. */
  35. $return = $album_model->checkAlbum(array('store_id' => session('store_id'), 'aclass_isdefault' => '1'));
  36. if (!$return) {
  37. $album_arr = array();
  38. $album_arr['aclass_name'] = lang('album_default_album');
  39. $album_arr['store_id'] = session('store_id');
  40. $album_arr['aclass_des'] = '';
  41. $album_arr['aclass_sort'] = '255';
  42. $album_arr['aclass_cover'] = '';
  43. $album_arr['aclass_uploadtime'] = TIMESTAMP;
  44. $album_arr['aclass_isdefault'] = '1';
  45. $album_model->addAlbumclass($album_arr);
  46. }
  47. /**
  48. * 相册分类
  49. */
  50. $condition = array();
  51. $condition[] = array('store_id', '=', session('store_id'));
  52. $order = 'aclass_sort desc';
  53. $sort = input('get.sort');
  54. if ($sort != '') {
  55. switch ($sort) {
  56. case '0':
  57. $order = 'aclass_uploadtime desc';
  58. break;
  59. case '1':
  60. $order = 'aclass_uploadtime asc';
  61. break;
  62. case '2':
  63. $order = 'aclass_name desc';
  64. break;
  65. case '3':
  66. $order = 'aclass_name asc';
  67. break;
  68. case '4':
  69. $order = 'aclass_sort desc';
  70. break;
  71. case '5':
  72. $order = 'aclass_sort asc';
  73. break;
  74. }
  75. }
  76. $aclass_info = $album_model->getAlbumclassList($condition, '', $order);
  77. View::assign('aclass_info', $aclass_info);
  78. View::assign('PHPSESSID', session_id());
  79. /* 设置卖家当前菜单 */
  80. $this->setSellerCurMenu('selleralbum');
  81. /* 设置卖家当前栏目 */
  82. $this->setSellerCurItem('album_cate');
  83. echo View::fetch($this->template_dir . 'album_cate');
  84. exit;
  85. }
  86. /**
  87. * 相册分类添加
  88. *
  89. */
  90. public function album_add() {
  91. /**
  92. * 实例化相册模型
  93. */
  94. $album_model = model('album');
  95. $class_count = $album_model->getAlbumclassCount(session('store_id'));
  96. View::assign('class_count', $class_count);
  97. return View::fetch($this->template_dir . 'album_add');
  98. }
  99. /**
  100. * 相册保存
  101. *
  102. */
  103. public function album_add_save() {
  104. if (request()->isPost()) {
  105. /**
  106. * 实例化相册模型
  107. */
  108. $album_model = model('album');
  109. $class_count = $album_model->getAlbumclassCount(session('store_id'));
  110. if ($class_count['count'] >= 20) {
  111. ds_json_encode(10001, lang('album_class_save_max_20'));
  112. }
  113. /**
  114. * 实例化相册模型
  115. */
  116. $param = array();
  117. $param['aclass_name'] = input('post.name');
  118. $param['store_id'] = session('store_id');
  119. $param['aclass_des'] = input('post.description');
  120. $param['aclass_sort'] = input('post.sort');
  121. $param['aclass_uploadtime'] = TIMESTAMP;
  122. $selleralbum_validate = ds_validate('selleralbum');
  123. if (!$selleralbum_validate->scene('album_add_save')->check($param)) {
  124. ds_json_encode(10001, $selleralbum_validate->getError());
  125. }
  126. $return = $album_model->addAlbumclass($param);
  127. if ($return) {
  128. ds_json_encode(10000, lang('album_class_save_succeed'));
  129. }
  130. }
  131. ds_json_encode(10001, lang('album_class_save_lose'));
  132. }
  133. /**
  134. * 相册分类编辑
  135. */
  136. public function album_edit() {
  137. $id = intval(input('param.id'));
  138. if ($id <= 0) {
  139. echo lang('album_parameter_error');
  140. exit;
  141. }
  142. /**
  143. * 实例化相册模型
  144. */
  145. $album_model = model('album');
  146. $condition[] = array('aclass_id', '=', $id);
  147. $condition[] = array('store_id', '=', session('store_id'));
  148. $class_info = $album_model->getOneAlbumclass($condition);
  149. View::assign('class_info', $class_info);
  150. return View::fetch($this->template_dir . 'album_edit');
  151. }
  152. /**
  153. * 相册分类编辑保存
  154. */
  155. public function album_edit_save() {
  156. $id = intval(input('param.id'));
  157. if ($id <= 0) {
  158. ds_json_encode(10001, lang('album_parameter_error'));
  159. }
  160. $param = array();
  161. $param['aclass_name'] = input('post.name');
  162. $param['aclass_des'] = input('post.description');
  163. $param['aclass_sort'] = input('post.sort');
  164. $selleralbum_validate = ds_validate('selleralbum');
  165. if (!$selleralbum_validate->scene('album_edit_save')->check($param)) {
  166. ds_json_encode(10001, $selleralbum_validate->getError());
  167. }
  168. /**
  169. * 实例化相册模型
  170. */
  171. $album_model = model('album');
  172. /**
  173. * 验证
  174. */
  175. $return = $album_model->checkAlbum(array('store_id' => session('store_id'), 'aclass_id' => $id));
  176. if ($return) {
  177. /**
  178. * 更新
  179. */
  180. $re = $album_model->editAlbumclass($param, $id);
  181. if ($re) {
  182. ds_json_encode(10000, lang('album_class_edit_succeed'));
  183. }
  184. } else {
  185. ds_json_encode(10001, lang('album_class_edit_lose'));
  186. }
  187. }
  188. /**
  189. * 相册删除
  190. */
  191. public function album_del() {
  192. $id = intval(input('param.id'));
  193. if ($id <= 0) {
  194. ds_json_encode(10001, lang('album_parameter_error'));
  195. }
  196. /**
  197. * 实例化相册模型
  198. */
  199. $album_model = model('album');
  200. /**
  201. * 验证是否为默认相册,
  202. */
  203. $return = $album_model->checkAlbum(array('store_id' => session('store_id'), 'aclass_id' => $id, 'aclass_isdefault' => '0'));
  204. if (!$return) {
  205. ds_json_encode(10001, lang('album_class_file_del_lose'));
  206. }
  207. /**
  208. * 删除分类
  209. */
  210. $condition = array();
  211. $condition[] = array('aclass_id', '=', $id);
  212. $return = $album_model->delAlbumclass($condition);
  213. if (!$return) {
  214. ds_json_encode(10001, lang('album_class_file_del_lose'));
  215. }
  216. /**
  217. * 更新图片分类
  218. */
  219. $condition = array();
  220. $condition[] = array('aclass_isdefault', '=', 1);
  221. $condition[] = array('store_id', '=', session('store_id'));
  222. $class_info = $album_model->getOneAlbumclass($condition);
  223. $param = array();
  224. $param['aclass_id'] = $class_info['aclass_id'];
  225. $album_model->editAlbumpic($param, array('aclass_id' => $id));
  226. if ($return) {
  227. ds_json_encode(10000, lang('album_class_file_del_succeed'));
  228. } else {
  229. ds_json_encode(10001, lang('album_class_file_del_lose'));
  230. }
  231. }
  232. /**
  233. * 图片列表
  234. */
  235. public function album_pic_list() {
  236. $id = intval(input('param.id'));
  237. if ($id <= 0) {
  238. $this->error(lang('album_parameter_error'));
  239. }
  240. /**
  241. * 实例化相册类
  242. */
  243. $album_model = model('album');
  244. $param = array();
  245. $param['aclass_id'] = $id;
  246. $param['store_id'] = session('store_id');
  247. $order = input('get.sort');
  248. switch ($order) {
  249. case '0':
  250. $order = 'apic_uploadtime desc';
  251. break;
  252. case '1':
  253. $order = 'apic_uploadtime asc';
  254. break;
  255. case '2':
  256. $order = 'apic_size desc';
  257. break;
  258. case '3':
  259. $order = 'apic_size asc';
  260. break;
  261. case '4':
  262. $order = 'apic_name desc';
  263. break;
  264. case '5':
  265. $order = 'apic_name asc';
  266. break;
  267. default :
  268. $order = 'apic_uploadtime desc';
  269. break;
  270. }
  271. $pic_list = $album_model->getAlbumpicList($param, 16, '*', $order);
  272. View::assign('pic_list', $pic_list);
  273. View::assign('show_page', $album_model->page_info->render());
  274. /**
  275. * 相册列表,移动
  276. */
  277. $param = array();
  278. $param[] = array('aclass_id', '<>', $id);
  279. $param[] = array('store_id', '=', session('store_id'));
  280. $class_list = $album_model->getAlbumclassList($param);
  281. View::assign('class_list', $class_list);
  282. /**
  283. * 相册信息
  284. */
  285. $condition = array();
  286. $condition[] = array('aclass_id', '=', $id);
  287. $condition[] = array('store_id', '=', session('store_id'));
  288. $class_info = $album_model->getOneAlbumclass($condition);
  289. View::assign('class_info', $class_info);
  290. View::assign('PHPSESSID', session_id());
  291. /* 设置卖家当前菜单 */
  292. $this->setSellerCurMenu('selleralbum');
  293. /* 设置卖家当前栏目 */
  294. $this->setSellerCurItem('pic_list');
  295. return View::fetch($this->template_dir . 'album_pic_list');
  296. }
  297. /**
  298. * 图片列表,外部调用
  299. */
  300. public function pic_list() {
  301. /**
  302. * 实例化相册类
  303. */
  304. $album_model = model('album');
  305. /**
  306. * 图片列表
  307. */
  308. $param = array();
  309. $param['store_id'] = session('store_id');
  310. $id = intval(input('param.id'));
  311. if ($id > 0) {
  312. $param['aclass_id'] = $id;
  313. /**
  314. * 分类列表
  315. */
  316. $condition = array();
  317. $condition[] = array('aclass_id', '=', $id);
  318. $condition[] = array('store_id', '=', session('store_id'));
  319. $cinfo = $album_model->getOneAlbumclass($condition);
  320. View::assign('class_name', $cinfo['aclass_name']);
  321. }
  322. $pic_list = $album_model->getAlbumpicList($param, 14);
  323. foreach ($pic_list as $key => $val) {
  324. $pic_list[$key]['apic_name'] = ds_get_pic( ATTACH_GOODS . '/' . $val['store_id'] . '/' .date('Ymd',$val['apic_uploadtime']) , $val['apic_name']);
  325. }
  326. View::assign('pic_list', $pic_list);
  327. View::assign('show_page', $album_model->page_info->render());
  328. /**
  329. * 分类列表
  330. */
  331. $condition = array();
  332. $condition[] = array('store_id', '=', session('store_id'));
  333. $class_info = $album_model->getAlbumclassList($condition);
  334. View::assign('class_list', $class_info);
  335. $item = input('param.item');
  336. switch ($item) {
  337. case 'goods':
  338. return View::fetch($this->template_dir . 'pic_list_goods');
  339. break;
  340. case 'des':
  341. echo View::fetch($this->template_dir . 'pic_list_des');
  342. break;
  343. case 'groupbuy':
  344. return View::fetch($this->template_dir . 'pic_list_groupbuy');
  345. break;
  346. case 'store_sns_normal':
  347. return View::fetch($this->template_dir . 'pic_list_store_sns_normal');
  348. break;
  349. case 'goods_image':
  350. View::assign('color_id', input('param.color_id'));
  351. return View::fetch($this->template_dir . 'pic_list_goods_image');
  352. break;
  353. case 'mobile':
  354. View::assign('type', input('param.type'));
  355. echo View::fetch($this->template_dir . 'pic_list_mobile');
  356. break;
  357. }
  358. }
  359. /**
  360. * 修改相册封面
  361. */
  362. public function change_album_cover() {
  363. $id = intval(input('get.id'));
  364. if ($id <= 0) {
  365. ds_json_encode(10001, lang('ds_common_op_fail'));
  366. }
  367. /**
  368. * 实例化相册类
  369. */
  370. $album_model = model('album');
  371. /**
  372. * 图片信息
  373. */
  374. $condition[] = array('apic_id', '=', $id);
  375. $condition[] = array('store_id', '=', session('store_id'));
  376. $pic_info = $album_model->getOneAlbumpicById($condition);
  377. $return = $album_model->checkAlbum(array('store_id' => session('store_id'), 'aclass_id' => $pic_info['aclass_id']));
  378. if ($return) {
  379. $re = $album_model->editAlbumclass(array('aclass_cover' => $pic_info['apic_cover']), $pic_info['aclass_id']);
  380. ds_json_encode(10000, lang('ds_common_op_succ'));
  381. } else {
  382. ds_json_encode(10001, lang('ds_common_op_fail'));
  383. }
  384. }
  385. /**
  386. * ajax修改图名称
  387. */
  388. public function change_pic_name() {
  389. $apic_id = intval(input('post.id'));
  390. $apic_name = input('post.name');
  391. if ($apic_id <= 0 && empty($apic_name)) {
  392. echo 'false';
  393. }
  394. /**
  395. * 实例化相册类
  396. */
  397. $album_model = model('album');
  398. $return = $album_model->editAlbumpic(array('apic_name' => $apic_name), array('apic_id' => $apic_id));
  399. if ($return) {
  400. echo 'true';
  401. } else {
  402. echo 'false';
  403. }
  404. }
  405. /**
  406. * 图片删除
  407. */
  408. public function album_pic_del() {
  409. $return_json = input('param.return_json'); //是否为json 返回
  410. $ids = input('param.id/a');
  411. if (empty($ids)) {
  412. $this->error(lang('album_parameter_error'));
  413. }
  414. $album_model = model('album');
  415. //删除图片
  416. $condition = array();
  417. $condition[] = array('apic_id', 'in', $ids);
  418. $condition[] = array('store_id', '=', session('store_id'));
  419. $return = $album_model->delAlbumpic($condition);
  420. if ($return) {
  421. if ($return_json) {
  422. ds_json_encode(10000, lang('album_class_pic_del_succeed'));
  423. } else {
  424. $this->success(lang('album_class_pic_del_succeed'));
  425. }
  426. } else {
  427. if ($return_json) {
  428. ds_json_encode(10000, lang('album_class_pic_del_lose'));
  429. } else {
  430. $this->error(lang('album_class_pic_del_lose'));
  431. }
  432. }
  433. }
  434. /**
  435. * 移动相册
  436. */
  437. public function album_pic_move() {
  438. /**
  439. * 实例化相册类
  440. */
  441. $album_model = model('album');
  442. if (request()->isPost()) {
  443. $id = input('post.id/a');
  444. $cid = input('post.cid');
  445. if (empty($id)) {
  446. $this->error(lang('album_parameter_error'));
  447. }
  448. if (!empty($id) && is_array($id)) {
  449. $id = trim(implode(',', $id), ',');
  450. }
  451. $update = array();
  452. $update['aclass_id'] = $cid;
  453. $condition[] = array('apic_id', 'in', $id);
  454. $condition[] = array('store_id', '=', session('store_id'));
  455. $return = $album_model->editAlbumpic($update, $condition);
  456. if ($return) {
  457. $this->success(lang('album_class_pic_move_succeed'));
  458. } else {
  459. $this->error(lang('album_class_pic_move_lose'));
  460. }
  461. } else {
  462. $id = input('param.id');
  463. $cid = input('param.cid');
  464. $condition[] = array('store_id', '=', session('store_id'));
  465. $condition[] = array('aclass_id', 'not in', $cid);
  466. $class_list = $album_model->getAlbumclassList($condition);
  467. if (isset($id) && !empty($id)) {
  468. View::assign('id', $id);
  469. }
  470. View::assign('class_list', $class_list);
  471. return View::fetch($this->template_dir . 'album_pic_move');
  472. }
  473. }
  474. /**
  475. * 替换图片
  476. */
  477. public function replace_image_upload() {
  478. $file = input('param.id');
  479. $tpl_array = explode('_', $file);
  480. $id = intval(end($tpl_array));
  481. $album_model = model('album');
  482. $condition = array();
  483. $condition[] = array('apic_id', '=', $id);
  484. $condition[] = array('store_id', '=', session('store_id'));
  485. $apic_info = $album_model->getOneAlbumpicById($condition);
  486. if (substr(strrchr($apic_info['apic_cover'], "."), 1) != substr(strrchr($_FILES[$file]["name"], "."), 1)) {
  487. // 后缀名必须相同
  488. $error = lang('album_replace_same_type');
  489. echo json_encode(array('state' => 'false', 'message' => $error));
  490. exit();
  491. }
  492. $pic_cover = implode(DIRECTORY_SEPARATOR, explode(DIRECTORY_SEPARATOR, $apic_info['apic_cover'], -1)); // 文件路径
  493. $tmpvar = explode(DIRECTORY_SEPARATOR, $apic_info['apic_cover']);
  494. $pic_name = end($tmpvar); // 文件名称
  495. /**
  496. * 上传图片
  497. */
  498. //上传文件保存路径
  499. $store_id = session('store_id');
  500. $upload_path = ATTACH_GOODS . '/' . $store_id . '/' .date('Ymd',$apic_info['apic_uploadtime']);
  501. $result = upload_albumpic($upload_path, $file, $pic_name);
  502. if ($result['code'] == '10000') {
  503. $img_path = $result['result'];
  504. list($width, $height, $type, $attr) = getimagesize($img_path);
  505. $img_path = substr(strrchr($img_path, "/"), 1);
  506. } else {
  507. $data['state'] = 'false';
  508. $data['origin_file_name'] = $_FILES[$file]['name'];
  509. $data['message'] = $result['message'];
  510. echo json_encode($data);
  511. exit;
  512. }
  513. $update_array = array();
  514. $update_array['apic_size'] = intval($_FILES[$file]['size']);
  515. $update_array['apic_spec'] = $width . 'x' . $height;
  516. $condition = array();
  517. $condition[] = array('apic_id', '=', $id);
  518. $result = model('album')->editAlbumpic($update_array, $condition);
  519. echo json_encode(array('state' => 'true', 'id' => $id));
  520. exit();
  521. }
  522. /**
  523. * 添加水印
  524. */
  525. public function album_pic_watermark() {
  526. $id_array = input('post.id/a');
  527. if (empty($id_array) && !is_array($id_array)) {
  528. $this->error(lang('album_parameter_error'));
  529. }
  530. $id = trim(implode(',', $id_array), ',');
  531. /**
  532. * 实例化图片模型
  533. */
  534. $album_model = model('album');
  535. $param[] = array('apic_id', 'in', $id);
  536. $param[] = array('store_id', '=', session('store_id'));
  537. $wm_list = $album_model->getAlbumpicList($param);
  538. $storewatermark_model = model('storewatermark');
  539. $store_wm_info = $storewatermark_model->getOneStorewatermarkByStoreId(session('store_id'));
  540. if ($store_wm_info['swm_image_name'] == '' && $store_wm_info['swm_text'] == '') {
  541. $this->error(lang('album_class_setting_wm'));
  542. }
  543. //获取店铺生成缩略图规格
  544. $ifthumb = FALSE;
  545. if (defined('GOODS_IMAGES_WIDTH') && defined('GOODS_IMAGES_HEIGHT') && defined('GOODS_IMAGES_EXT')) {
  546. $thumb_width = explode(',', GOODS_IMAGES_WIDTH);
  547. $thumb_height = explode(',', GOODS_IMAGES_HEIGHT);
  548. $thumb_ext = explode(',', GOODS_IMAGES_EXT);
  549. if (count($thumb_width) == count($thumb_height) && count($thumb_width) == count($thumb_ext)) {
  550. $ifthumb = TRUE;
  551. }
  552. }
  553. //文件路径
  554. $upload_path = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_GOODS . DIRECTORY_SEPARATOR . session('store_id');
  555. if ($ifthumb) {
  556. foreach ($wm_list as $v) {
  557. //商品的图片路径
  558. $image_file = $upload_path . DIRECTORY_SEPARATOR . date('Ymd',$v['apic_uploadtime']) . DIRECTORY_SEPARATOR . $v['apic_cover'];
  559. //原图不做修改,对缩略图做修改
  560. if (!file_exists($image_file)) {
  561. continue;
  562. }
  563. //重新生成缩略图,以及水印
  564. for ($i = 0; $i < count($thumb_width); $i++) {
  565. //打开图片
  566. $gd_image = \think\Image::open($image_file);
  567. //水印图片名称
  568. $thumb_image_file = $upload_path . DIRECTORY_SEPARATOR . date('Ymd',$v['apic_uploadtime']) . '/' . str_ireplace('.', $thumb_ext[$i] . '.', $v['apic_cover']);
  569. //添加图片水印
  570. if (!empty($store_wm_info['swm_image_name'])) {
  571. //水印图片的路径
  572. $w_image = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_WATERMARK . DIRECTORY_SEPARATOR . $store_wm_info['swm_image_name'];
  573. if(file_exists($w_image)){
  574. $gd_image->thumb($thumb_width[$i], $thumb_height[$i], \think\Image::THUMB_CENTER)->water($w_image, $store_wm_info['swm_image_pos'], $store_wm_info['swm_image_transition'])->save($thumb_image_file, null, $store_wm_info['swm_quality']);
  575. }
  576. }
  577. //添加文字水印
  578. if (!empty($store_wm_info['swm_text'])) {
  579. //字体文件路径
  580. $font = 'font' . DIRECTORY_SEPARATOR . $store_wm_info['swm_text_font'] . '.ttf';
  581. $gd_image->thumb($thumb_width[$i], $thumb_height[$i], \think\Image::THUMB_CENTER)->text($store_wm_info['swm_text'], $font, $store_wm_info['swm_text_size'], $store_wm_info['swm_text_color'], $store_wm_info['swm_text_pos'], $store_wm_info['swm_text_angle'])->save($thumb_image_file, null, $store_wm_info['swm_quality']);
  582. }
  583. }
  584. }
  585. }
  586. $this->success(lang('album_pic_plus_wm_succeed'));
  587. }
  588. /**
  589. * 水印管理
  590. */
  591. public function store_watermark() {
  592. /**
  593. * 读取语言包
  594. */
  595. $storewatermark_model = model('storewatermark');
  596. /**
  597. * 获取会员水印设置
  598. */
  599. $store_wm_info = $storewatermark_model->getOneStorewatermarkByStoreId(session('store_id'));
  600. /**
  601. * 保存水印配置信息
  602. */
  603. if (!request()->isPost()) {
  604. /**
  605. * 获取水印字体
  606. */
  607. $fontInfo = array();
  608. include PUBLIC_PATH . DIRECTORY_SEPARATOR . 'font' . DIRECTORY_SEPARATOR . 'font.info.php';
  609. foreach ($fontInfo as $key => $value) {
  610. if (!file_exists(PUBLIC_PATH . DIRECTORY_SEPARATOR . 'font' . DIRECTORY_SEPARATOR . $key . '.ttf')) {
  611. unset($fontInfo[$key]);
  612. }
  613. }
  614. View::assign('file_list', $fontInfo);
  615. if (empty($store_wm_info)) {
  616. /**
  617. * 新建店铺水印设置信息
  618. */
  619. $storewatermark_model->addStorewatermark(array(
  620. 'swm_text_font' => 'default',
  621. 'store_id' => session('store_id')
  622. ));
  623. $store_wm_info = $storewatermark_model->getOneStorewatermarkByStoreId(session('store_id'));
  624. }
  625. /* 设置卖家当前菜单 */
  626. $this->setSellerCurMenu('selleralbum');
  627. /* 设置卖家当前栏目 */
  628. $this->setSellerCurItem('watermark');
  629. View::assign('store_wm_info', $store_wm_info);
  630. return View::fetch($this->template_dir . 'store_watermark');
  631. } else {
  632. $param = array();
  633. $param['swm_image_pos'] = input('post.swm_image_pos');
  634. $param['swm_image_transition'] = intval(input('post.swm_image_transition'));
  635. $param['swm_text'] = input('post.swm_text');
  636. $param['swm_text_size'] = input('post.swm_text_size');
  637. $param['swm_text_angle'] = input('post.swm_text_angle');
  638. $param['swm_text_font'] = input('post.swm_text_font');
  639. $param['swm_text_pos'] = input('post.swm_text_pos');
  640. $param['swm_text_color'] = input('post.swm_text_color');
  641. $param['swm_quality'] = intval(input('post.swm_quality'));
  642. $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_WATERMARK;
  643. if (!empty($_FILES['image']['name'])) {
  644. if (!empty($_FILES['image']['name'])) {
  645. $res = ds_upload_pic(ATTACH_WATERMARK, 'image');
  646. if ($res['code']) {
  647. $file_name = $res['data']['file_name'];
  648. $param['swm_image_name'] = $file_name;
  649. //删除旧水印
  650. if (!empty($store_wm_info['swm_image_name'])) {
  651. @unlink($upload_file . DIRECTORY_SEPARATOR . $store_wm_info['swm_image_name']);
  652. }
  653. } else {
  654. $this->error($res['msg']);
  655. }
  656. }
  657. } elseif (input('post.is_del_image') == 'ok') {
  658. //删除水印
  659. if (!empty($store_wm_info['swm_image_name'])) {
  660. $param['swm_image_name'] = '';
  661. @unlink($upload_file . DIRECTORY_SEPARATOR . $store_wm_info['swm_image_name']);
  662. }
  663. }
  664. $result = $storewatermark_model->editStorewatermark($store_wm_info['swm_id'], $param);
  665. if ($result) {
  666. $this->success(lang('store_watermark_congfig_success'));
  667. } else {
  668. $this->error(lang('store_watermark_congfig_fail'));
  669. }
  670. }
  671. }
  672. /**
  673. * 上传图片
  674. *
  675. */
  676. public function image_upload() {
  677. $store_id = session('store_id');
  678. if (input('param.category_id')) {
  679. $category_id = intval(input('param.category_id'));
  680. } else {
  681. $error = lang('param_error');
  682. $data['state'] = 'false';
  683. $data['message'] = $error;
  684. $data['origin_file_name'] = $_FILES["file"]["name"];
  685. echo json_encode($data);
  686. exit();
  687. }
  688. // 判断图片数量是否超限
  689. $album_limit = $this->store_grade['storegrade_album_limit'];
  690. if ($album_limit > 0) {
  691. $album_count = model('album')->getCount(array('store_id' => $store_id));
  692. if ($album_count >= $album_limit) {
  693. // 目前并不出该提示,而是提示上传0张图片
  694. $error = lang('store_goods_album_climit');
  695. $data['state'] = 'false';
  696. $data['message'] = $error;
  697. $data['origin_file_name'] = $_FILES["file"]["name"];
  698. $data['state'] = 'true';
  699. echo json_encode($data);
  700. exit();
  701. }
  702. }
  703. /**
  704. * 上传图片
  705. */
  706. $time=TIMESTAMP;
  707. //上传文件保存路径
  708. $upload_path = ATTACH_GOODS . '/' . $store_id . '/' . date('Ymd',$time);
  709. $save_name = session('store_id') . '_' . date('YmdHis',$time) . rand(10000, 99999);
  710. $name = 'file';
  711. $result = upload_albumpic($upload_path, $name, $save_name);
  712. if ($result['code'] == '10000') {
  713. $img_path = $result['result'];
  714. list($width, $height, $type, $attr) = getimagesize($img_path);
  715. $pic = substr(strrchr($img_path, "/"), 1);
  716. } else {
  717. exit($result['message']);
  718. }
  719. $insert_array = array();
  720. $insert_array['apic_name'] = $pic;
  721. $insert_array['apic_tag'] = '';
  722. $insert_array['aclass_id'] = $category_id;
  723. $insert_array['apic_cover'] = $pic;
  724. $insert_array['apic_size'] = intval($_FILES['file']['size']);
  725. $insert_array['apic_spec'] = $width . 'x' . $height;
  726. $insert_array['apic_uploadtime'] = $time;
  727. $insert_array['store_id'] = $store_id;
  728. $result = model('album')->addAlbumpic($insert_array);
  729. $data = array();
  730. $data['file_id'] = $result;
  731. $data['file_name'] = $pic;
  732. $data['origin_file_name'] = $_FILES["file"]["name"];
  733. $data['file_path'] = $pic;
  734. $data['instance'] = input('get.instance');
  735. $data['state'] = 'true';
  736. /**
  737. * 整理为json格式
  738. */
  739. $output = json_encode($data);
  740. echo $output;
  741. exit;
  742. }
  743. /**
  744. * 用户中心右边,小导航
  745. *
  746. * @param string $menu_type 导航类型
  747. * @param string $menu_key 当前导航的menu_key
  748. * @return
  749. */
  750. function getSellerItemList() {
  751. $item_list = array(
  752. array(
  753. 'name' => 'album_cate',
  754. 'text' => lang('ds_member_path_my_album'),
  755. 'url' => (string) url('Selleralbum/index'),
  756. ),
  757. array(
  758. 'name' => 'watermark',
  759. 'text' => lang('ds_member_path_watermark'),
  760. 'url' => (string) url('Selleralbum/store_watermark'),
  761. ),
  762. );
  763. if (request()->action() == 'album_pic_list') {
  764. $item_list[] = array(
  765. 'name' => 'pic_list',
  766. 'text' => lang('ds_member_path_album_pic_list'),
  767. 'url' => (string) url('Selleralbum/album_pic_list', ['album_pic_list' => intval(input('param.id'))]),
  768. );
  769. }
  770. return $item_list;
  771. }
  772. /**
  773. * ajax验证名称时候重复
  774. */
  775. public function ajax_check_class_name() {
  776. $ac_name = trim(input('get.ac_name'));
  777. if ($ac_name == '') {
  778. echo 'true';
  779. die;
  780. }
  781. $album_model = model('album');
  782. $condition = array();
  783. $condition[] = array('store_id', '=', session('store_id'));
  784. $condition[] = array('aclass_name', '=', $ac_name);
  785. $class_info = $album_model->getOneAlbumclass($condition);
  786. if (!empty($class_info)) {
  787. echo 'false';
  788. die;
  789. } else {
  790. echo 'true';
  791. die;
  792. }
  793. }
  794. }
  795. ?>