Selleralbum.php 31 KB

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