Selleralbum.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  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, '*','apic_name desc');
  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. $return_json = input('post.return_json');//是否为json 返回
  444. $id = input('post.id/a');
  445. $cid = input('post.cid');
  446. if (empty($id)) {
  447. $this->error(lang('album_parameter_error'));
  448. }
  449. if (!empty($id) && is_array($id)) {
  450. $id = trim(implode(',', $id), ',');
  451. }
  452. $update = array();
  453. $update['aclass_id'] = $cid;
  454. $condition[] = array('apic_id', 'in', $id);
  455. $condition[] = array('store_id', '=', session('store_id'));
  456. $return = $album_model->editAlbumpic($update, $condition);
  457. if ($return) {
  458. if ($return_json) {
  459. ds_json_encode(10000, lang('album_class_pic_move_succeed'));
  460. } else {
  461. $this->success(lang('album_class_pic_move_succeed'));
  462. }
  463. } else {
  464. if ($return_json) {
  465. ds_json_encode(10001, lang('album_class_pic_move_lose'));
  466. } else {
  467. $this->success(lang('album_class_pic_move_lose'));
  468. }
  469. }
  470. } else {
  471. $id = input('param.id');
  472. $cid = input('param.cid');
  473. $condition[] = array('store_id', '=', session('store_id'));
  474. $condition[] = array('aclass_id', 'not in', $cid);
  475. $class_list = $album_model->getAlbumclassList($condition);
  476. if (isset($id) && !empty($id)) {
  477. View::assign('id', $id);
  478. }
  479. View::assign('class_list', $class_list);
  480. return View::fetch($this->template_dir . 'album_pic_move');
  481. }
  482. }
  483. /**
  484. * 替换图片
  485. */
  486. public function replace_image_upload() {
  487. $file = input('param.id');
  488. $tpl_array = explode('_', $file);
  489. $id = intval(end($tpl_array));
  490. $album_model = model('album');
  491. $condition = array();
  492. $condition[] = array('apic_id', '=', $id);
  493. $condition[] = array('store_id', '=', session('store_id'));
  494. $apic_info = $album_model->getOneAlbumpicById($condition);
  495. if (substr(strrchr($apic_info['apic_cover'], "."), 1) != substr(strrchr($_FILES[$file]["name"], "."), 1)) {
  496. // 后缀名必须相同
  497. $error = lang('album_replace_same_type');
  498. echo json_encode(array('state' => 'false', 'message' => $error));
  499. exit();
  500. }
  501. $pic_cover = implode(DIRECTORY_SEPARATOR, explode(DIRECTORY_SEPARATOR, $apic_info['apic_cover'], -1)); // 文件路径
  502. $tmpvar = explode(DIRECTORY_SEPARATOR, $apic_info['apic_cover']);
  503. $pic_name = end($tmpvar); // 文件名称
  504. /**
  505. * 上传图片
  506. */
  507. //上传文件保存路径
  508. $store_id = session('store_id');
  509. $upload_path = ATTACH_GOODS . '/' . $store_id . '/' .date('Ymd',$apic_info['apic_uploadtime']);
  510. $result = upload_albumpic($upload_path, $file, $pic_name);
  511. if ($result['code'] == '10000') {
  512. $img_path = $result['result'];
  513. list($width, $height, $type, $attr) = getimagesize($img_path);
  514. $img_path = substr(strrchr($img_path, "/"), 1);
  515. } else {
  516. $data['state'] = 'false';
  517. $data['origin_file_name'] = $_FILES[$file]['name'];
  518. $data['message'] = $result['message'];
  519. echo json_encode($data);
  520. exit;
  521. }
  522. $update_array = array();
  523. $update_array['apic_size'] = intval($_FILES[$file]['size']);
  524. $update_array['apic_spec'] = $width . 'x' . $height;
  525. $condition = array();
  526. $condition[] = array('apic_id', '=', $id);
  527. $result = model('album')->editAlbumpic($update_array, $condition);
  528. echo json_encode(array('state' => 'true', 'id' => $id));
  529. exit();
  530. }
  531. /**
  532. * 添加水印
  533. */
  534. public function album_pic_watermark() {
  535. $id_array = input('post.id/a');
  536. if (empty($id_array) && !is_array($id_array)) {
  537. $this->error(lang('album_parameter_error'));
  538. }
  539. $id = trim(implode(',', $id_array), ',');
  540. /**
  541. * 实例化图片模型
  542. */
  543. $album_model = model('album');
  544. $param[] = array('apic_id', 'in', $id);
  545. $param[] = array('store_id', '=', session('store_id'));
  546. $wm_list = $album_model->getAlbumpicList($param);
  547. $storewatermark_model = model('storewatermark');
  548. $store_wm_info = $storewatermark_model->getOneStorewatermarkByStoreId(session('store_id'));
  549. if ($store_wm_info['swm_image_name'] == '' && $store_wm_info['swm_text'] == '') {
  550. $this->error(lang('album_class_setting_wm'));
  551. }
  552. //获取店铺生成缩略图规格
  553. $ifthumb = FALSE;
  554. if (defined('GOODS_IMAGES_WIDTH') && defined('GOODS_IMAGES_HEIGHT') && defined('GOODS_IMAGES_EXT')) {
  555. $thumb_width = explode(',', GOODS_IMAGES_WIDTH);
  556. $thumb_height = explode(',', GOODS_IMAGES_HEIGHT);
  557. $thumb_ext = explode(',', GOODS_IMAGES_EXT);
  558. if (count($thumb_width) == count($thumb_height) && count($thumb_width) == count($thumb_ext)) {
  559. $ifthumb = TRUE;
  560. }
  561. }
  562. //文件路径
  563. $upload_path = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_GOODS . DIRECTORY_SEPARATOR . session('store_id');
  564. if ($ifthumb) {
  565. foreach ($wm_list as $v) {
  566. //商品的图片路径
  567. $image_file = $upload_path . DIRECTORY_SEPARATOR . date('Ymd',$v['apic_uploadtime']) . DIRECTORY_SEPARATOR . $v['apic_cover'];
  568. //原图不做修改,对缩略图做修改
  569. if (!file_exists($image_file)) {
  570. continue;
  571. }
  572. //重新生成缩略图,以及水印
  573. for ($i = 0; $i < count($thumb_width); $i++) {
  574. //打开图片
  575. $gd_image = \think\Image::open($image_file);
  576. //水印图片名称
  577. $thumb_image_file = $upload_path . DIRECTORY_SEPARATOR . date('Ymd',$v['apic_uploadtime']) . '/' . str_ireplace('.', $thumb_ext[$i] . '.', $v['apic_cover']);
  578. //添加图片水印
  579. if (!empty($store_wm_info['swm_image_name'])) {
  580. //水印图片的路径
  581. $w_image = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_WATERMARK . DIRECTORY_SEPARATOR . $store_wm_info['swm_image_name'];
  582. if(file_exists($w_image)){
  583. $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']);
  584. }
  585. }
  586. //添加文字水印
  587. if (!empty($store_wm_info['swm_text'])) {
  588. //字体文件路径
  589. $font = 'font' . DIRECTORY_SEPARATOR . $store_wm_info['swm_text_font'] . '.ttf';
  590. $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']);
  591. }
  592. }
  593. }
  594. }
  595. $this->success(lang('album_pic_plus_wm_succeed'));
  596. }
  597. /**
  598. * 水印管理
  599. */
  600. public function store_watermark() {
  601. /**
  602. * 读取语言包
  603. */
  604. $storewatermark_model = model('storewatermark');
  605. /**
  606. * 获取会员水印设置
  607. */
  608. $store_wm_info = $storewatermark_model->getOneStorewatermarkByStoreId(session('store_id'));
  609. /**
  610. * 保存水印配置信息
  611. */
  612. if (!request()->isPost()) {
  613. /**
  614. * 获取水印字体
  615. */
  616. $fontInfo = array();
  617. include PUBLIC_PATH . DIRECTORY_SEPARATOR . 'font' . DIRECTORY_SEPARATOR . 'font.info.php';
  618. foreach ($fontInfo as $key => $value) {
  619. if (!file_exists(PUBLIC_PATH . DIRECTORY_SEPARATOR . 'font' . DIRECTORY_SEPARATOR . $key . '.ttf')) {
  620. unset($fontInfo[$key]);
  621. }
  622. }
  623. View::assign('file_list', $fontInfo);
  624. if (empty($store_wm_info)) {
  625. /**
  626. * 新建店铺水印设置信息
  627. */
  628. $storewatermark_model->addStorewatermark(array(
  629. 'swm_text_font' => 'default',
  630. 'store_id' => session('store_id')
  631. ));
  632. $store_wm_info = $storewatermark_model->getOneStorewatermarkByStoreId(session('store_id'));
  633. }
  634. /* 设置卖家当前菜单 */
  635. $this->setSellerCurMenu('selleralbum');
  636. /* 设置卖家当前栏目 */
  637. $this->setSellerCurItem('watermark');
  638. View::assign('store_wm_info', $store_wm_info);
  639. return View::fetch($this->template_dir . 'store_watermark');
  640. } else {
  641. $param = array();
  642. $param['swm_image_pos'] = input('post.swm_image_pos');
  643. $param['swm_image_transition'] = intval(input('post.swm_image_transition'));
  644. $param['swm_text'] = input('post.swm_text');
  645. $param['swm_text_size'] = input('post.swm_text_size');
  646. $param['swm_text_angle'] = input('post.swm_text_angle');
  647. $param['swm_text_font'] = input('post.swm_text_font');
  648. $param['swm_text_pos'] = input('post.swm_text_pos');
  649. $param['swm_text_color'] = input('post.swm_text_color');
  650. $param['swm_quality'] = intval(input('post.swm_quality'));
  651. $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_WATERMARK;
  652. if (!empty($_FILES['image']['name'])) {
  653. if (!empty($_FILES['image']['name'])) {
  654. $res = ds_upload_pic(ATTACH_WATERMARK, 'image');
  655. if ($res['code']) {
  656. $file_name = $res['data']['file_name'];
  657. $param['swm_image_name'] = $file_name;
  658. //删除旧水印
  659. if (!empty($store_wm_info['swm_image_name'])) {
  660. @unlink($upload_file . DIRECTORY_SEPARATOR . $store_wm_info['swm_image_name']);
  661. }
  662. } else {
  663. $this->error($res['msg']);
  664. }
  665. }
  666. } elseif (input('post.is_del_image') == 'ok') {
  667. //删除水印
  668. if (!empty($store_wm_info['swm_image_name'])) {
  669. $param['swm_image_name'] = '';
  670. @unlink($upload_file . DIRECTORY_SEPARATOR . $store_wm_info['swm_image_name']);
  671. }
  672. }
  673. $result = $storewatermark_model->editStorewatermark($store_wm_info['swm_id'], $param);
  674. if ($result) {
  675. $this->success(lang('store_watermark_congfig_success'));
  676. } else {
  677. $this->error(lang('store_watermark_congfig_fail'));
  678. }
  679. }
  680. }
  681. /**
  682. * 上传图片
  683. *
  684. */
  685. public function image_upload() {
  686. $store_id = session('store_id');
  687. if (input('param.category_id')) {
  688. $category_id = intval(input('param.category_id'));
  689. } else {
  690. $error = lang('param_error');
  691. $data['state'] = 'false';
  692. $data['message'] = $error;
  693. $data['origin_file_name'] = $_FILES["file"]["name"];
  694. echo json_encode($data);
  695. exit();
  696. }
  697. // 判断图片数量是否超限
  698. $album_limit = $this->store_grade['storegrade_album_limit'];
  699. if ($album_limit > 0) {
  700. $album_count = model('album')->getCount(array('store_id' => $store_id));
  701. if ($album_count >= $album_limit) {
  702. // 目前并不出该提示,而是提示上传0张图片
  703. $error = lang('album_upload_file_tips');
  704. $data['state'] = 'false';
  705. $data['message'] = $error;
  706. $data['origin_file_name'] = $_FILES["file"]["name"];
  707. echo json_encode($data);
  708. exit();
  709. }
  710. }
  711. /**
  712. * 上传图片
  713. */
  714. $index=intval(input('param.index'));
  715. $time=TIMESTAMP;
  716. //上传文件保存路径
  717. $upload_path = ATTACH_GOODS . '/' . $store_id . '/' . date('Ymd',$time);
  718. $save_name = session('store_id') . '_' . date('YmdHis',$time) . ($index?(10000+$index):(rand(20000, 99999)));
  719. $name = 'file';
  720. $result = upload_albumpic($upload_path, $name, $save_name);
  721. if ($result['code'] == '10000') {
  722. $img_path = $result['result'];
  723. list($width, $height, $type, $attr) = getimagesize($img_path);
  724. $pic = substr(strrchr($img_path, "/"), 1);
  725. } else {
  726. exit($result['message']);
  727. }
  728. $insert_array = array();
  729. $insert_array['apic_name'] = $pic;
  730. $insert_array['apic_tag'] = '';
  731. $insert_array['aclass_id'] = $category_id;
  732. $insert_array['apic_cover'] = $pic;
  733. $insert_array['apic_size'] = intval($_FILES['file']['size']);
  734. $insert_array['apic_spec'] = $width . 'x' . $height;
  735. $insert_array['apic_uploadtime'] = $time;
  736. $insert_array['store_id'] = $store_id;
  737. $result = model('album')->addAlbumpic($insert_array);
  738. $data = array();
  739. $data['file_id'] = $result;
  740. $data['file_name'] = $pic;
  741. $data['origin_file_name'] = $_FILES["file"]["name"];
  742. $data['file_path'] = $pic;
  743. $data['instance'] = input('get.instance');
  744. $data['state'] = 'true';
  745. /**
  746. * 整理为json格式
  747. */
  748. $output = json_encode($data);
  749. echo $output;
  750. exit;
  751. }
  752. /**
  753. * 用户中心右边,小导航
  754. *
  755. * @param string $menu_type 导航类型
  756. * @param string $menu_key 当前导航的menu_key
  757. * @return
  758. */
  759. function getSellerItemList() {
  760. $item_list = array(
  761. array(
  762. 'name' => 'album_cate',
  763. 'text' => lang('ds_member_path_my_album'),
  764. 'url' => (string) url('Selleralbum/index'),
  765. ),
  766. array(
  767. 'name' => 'watermark',
  768. 'text' => lang('ds_member_path_watermark'),
  769. 'url' => (string) url('Selleralbum/store_watermark'),
  770. ),
  771. );
  772. if (request()->action() == 'album_pic_list') {
  773. $item_list[] = array(
  774. 'name' => 'pic_list',
  775. 'text' => lang('ds_member_path_album_pic_list'),
  776. 'url' => "javascript:void(0)",
  777. );
  778. }
  779. return $item_list;
  780. }
  781. /**
  782. * ajax验证名称时候重复
  783. */
  784. public function ajax_check_class_name() {
  785. $ac_name = trim(input('get.ac_name'));
  786. if ($ac_name == '') {
  787. echo 'true';
  788. die;
  789. }
  790. $album_model = model('album');
  791. $condition = array();
  792. $condition[] = array('store_id', '=', session('store_id'));
  793. $condition[] = array('aclass_name', '=', $ac_name);
  794. $class_info = $album_model->getOneAlbumclass($condition);
  795. if (!empty($class_info)) {
  796. echo 'false';
  797. die;
  798. } else {
  799. echo 'true';
  800. die;
  801. }
  802. }
  803. }
  804. ?>