Selleralbum.php 31 KB

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