Selleralbum.php 31 KB

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