Pc.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\pc\shop\controller;
  13. use app\model\goods\GoodsCategory as GoodsCategoryModel;
  14. use addon\pc\model\Pc as PcModel;
  15. use app\model\web\Config;
  16. use app\shop\controller\BaseShop;
  17. /**
  18. * Pc端 控制器
  19. */
  20. class Pc extends BaseShop
  21. {
  22. private $pc_model;
  23. protected $replace = [
  24. 'ADDON_PC_CSS' => __ROOT__ . '/addon/pc/shop/view/public/css',
  25. 'ADDON_PC_JS' => __ROOT__ . '/addon/pc/shop/view/public/js',
  26. 'ADDON_PC_IMG' => __ROOT__ . '/addon/pc/shop/view/public/img',
  27. ];
  28. public function __construct()
  29. {
  30. $this->pc_model = new PcModel();
  31. parent::__construct();
  32. }
  33. /**
  34. * 网站部署
  35. */
  36. public function deploy()
  37. {
  38. $refresh_time = 0;
  39. $path = 'web/refresh.log';
  40. if (file_exists($path)) {
  41. $refresh_time = file_get_contents($path);
  42. }
  43. $this->assign('refresh_time', $refresh_time);
  44. $config_model = new Config();
  45. $config = $config_model->getPcDomainName($this->site_id);
  46. if ($config[ 'data' ][ 'value' ][ 'deploy_way' ] == 'separate') {
  47. $root_url = $config[ 'data' ][ 'value' ][ 'domain_name_pc' ];
  48. } else {
  49. $root_url = __ROOT__;
  50. }
  51. $this->assign('config', $config[ 'data' ][ 'value' ]);
  52. $this->assign("roots_url", $root_url);
  53. $this->assign("root_url", __ROOT__);
  54. return $this->fetch('addon/pc/shop/view/pc/deploy.html');
  55. }
  56. /**
  57. * 设置pc端域名
  58. * @return array
  59. */
  60. public function pcDomainName()
  61. {
  62. $config_model = new Config();
  63. $domain_name = input("domain", "");
  64. $deploy_way = input("deploy_way", "default");
  65. if ($deploy_way == 'default') $domain_name = __ROOT__ . '/web';
  66. $result = $config_model->setPcDomainName([
  67. 'domain_name_pc' => $domain_name,
  68. 'deploy_way' => $deploy_way
  69. ]);
  70. return $result;
  71. }
  72. /**
  73. * 默认部署:无需下载,一键刷新,API接口请求地址为当前域名,编译代码存放到web文件夹中
  74. */
  75. public function downloadCsDefault()
  76. {
  77. $this->pcDomainName();
  78. return $this->pc_model->downloadCsDefault();
  79. }
  80. /**
  81. * 独立部署:下载编译代码包,参考开发文档进行配置
  82. */
  83. public function downloadCsSeparate()
  84. {
  85. if (strstr(ROOT_URL, 'niuteam.cn') === false) {
  86. $domain_name = input("domain", "");
  87. $res = $this->pc_model->downloadCsSeparate($domain_name);
  88. if ($res[ 'code' ] >= 0) {
  89. $config_model = new Config();
  90. $result = $config_model->setPcDomainName([
  91. 'domain_name_pc' => $domain_name,
  92. 'deploy_way' => 'separate'
  93. ]);
  94. }
  95. echo $res[ 'message' ];
  96. }
  97. }
  98. /**
  99. * 源码下载:下载开源代码包,参考开发文档进行配置,结合业务需求进行二次开发
  100. */
  101. public function downloadOs()
  102. {
  103. if (strstr(ROOT_URL, 'niuteam.cn') === false) {
  104. $res = $this->pc_model->downloadOs();
  105. echo $res[ 'message' ];
  106. }
  107. }
  108. /**
  109. * 首页浮层
  110. * @return mixed
  111. */
  112. public function floatLayer()
  113. {
  114. if (request()->isAjax()) {
  115. $data = [
  116. 'title' => input("title", ""),
  117. 'url' => input("url", ""),
  118. 'is_show' => input("is_show", 0),
  119. 'number' => input("number", ""),
  120. 'img_url' => input("img_url", "")
  121. ];
  122. $res = $this->pc_model->setFloatLayer($data, $this->site_id);
  123. return $res;
  124. } else {
  125. $link = $this->pc_model->getLink();
  126. $this->assign("link", $link);
  127. $float_layer = $this->pc_model->getFloatLayer($this->site_id);
  128. $float_layer = $float_layer[ 'data' ][ 'value' ];
  129. $this->assign("float_layer", $float_layer);
  130. return $this->fetch('pc/float_layer');
  131. }
  132. }
  133. /**
  134. * 导航设置
  135. * @return mixed
  136. */
  137. public function navList()
  138. {
  139. if (request()->isAjax()) {
  140. $page = input('page', 1);
  141. $page_size = input('page_size', PAGE_LIST_ROWS);
  142. $search_text = input('search_text', '');
  143. $condition = [
  144. [ 'site_id', '=', $this->site_id ]
  145. ];
  146. if (!empty($search_text)) $condition[] = [ 'nav_title', 'like', '%' . $search_text . '%' ];
  147. $order = 'create_time desc';
  148. $model = new PcModel();
  149. return $model->getNavPageList($condition, $page, $page_size, $order);
  150. } else {
  151. return $this->fetch('pc/nav_list');
  152. }
  153. }
  154. /**
  155. * 添加导航
  156. * @return mixed
  157. */
  158. public function addNav()
  159. {
  160. $model = new PcModel();
  161. if (request()->isAjax()) {
  162. $data = [
  163. 'nav_title' => input('nav_title', ''),
  164. 'nav_url' => input('nav_url', ''),
  165. 'sort' => input('sort', ''),
  166. 'is_blank' => input('is_blank', ''),
  167. 'nav_icon' => input('nav_icon', ''),
  168. 'is_show' => input('is_show', ''),
  169. 'create_time' => time(),
  170. 'site_id' => $this->site_id
  171. ];
  172. return $model->addNav($data);
  173. } else {
  174. $link_list = $model->getLink();
  175. $this->assign('link', $link_list);
  176. return $this->fetch('pc/add_nav');
  177. }
  178. }
  179. /**
  180. * 编辑导航
  181. * @return mixed
  182. */
  183. public function editNav()
  184. {
  185. $model = new PcModel();
  186. if (request()->isAjax()) {
  187. $data = [
  188. 'nav_title' => input('nav_title', ''),
  189. 'nav_url' => input('nav_url', ''),
  190. 'sort' => input('sort', ''),
  191. 'is_blank' => input('is_blank', ''),
  192. 'nav_icon' => input('nav_icon', ''),
  193. 'is_show' => input('is_show', ''),
  194. 'modify_time' => time(),
  195. ];
  196. $id = input('id', 0);
  197. $condition = [
  198. [ 'id', '=', $id ],
  199. [ 'site_id', '=', $this->site_id ]
  200. ];
  201. return $model->editNav($data, $condition);
  202. } else {
  203. $link_list = $model->getLink();
  204. $this->assign('link', $link_list);
  205. $id = input('id', 0);
  206. $this->assign('id', $id);
  207. $nav_info = $model->getNavInfo($id);
  208. $this->assign('nav_info', $nav_info[ 'data' ]);
  209. return $this->fetch('pc/edit_nav');
  210. }
  211. }
  212. /**
  213. * 删除导航
  214. * @return mixed
  215. */
  216. public function deleteNav()
  217. {
  218. if (request()->isAjax()) {
  219. $id = input('id', 0);
  220. $model = new PcModel();
  221. return $model->deleteNav([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
  222. }
  223. }
  224. /**
  225. * 修改排序
  226. */
  227. public function modifySort()
  228. {
  229. if (request()->isAjax()) {
  230. $sort = input('sort', 0);
  231. $id = input('id', 0);
  232. $model = new PcModel();
  233. return $model->modifyNavSort($sort, $id);
  234. }
  235. }
  236. public function modifyNavIsShow()
  237. {
  238. if (request()->isAjax()) {
  239. $is_show = input('is_show', 0);
  240. $id = input('id', 0);
  241. $model = new PcModel();
  242. return $model->editNav([ 'is_show' => $is_show ], [ [ 'id', '=', $id ] ]);
  243. }
  244. }
  245. /**
  246. * 友情链接
  247. * @return mixed
  248. */
  249. public function linklist()
  250. {
  251. if (request()->isAjax()) {
  252. $page = input('page', 1);
  253. $page_size = input('page_size', PAGE_LIST_ROWS);
  254. $search_text = input('search_text', '');
  255. $condition = [
  256. [ 'site_id', '=', $this->site_id ]
  257. ];
  258. if (!empty($search_text)) $condition[] = [ 'link_title', 'like', '%' . $search_text . '%' ];
  259. //排序
  260. $link_sort = input('order', 'link_sort');
  261. $sort = input('sort', 'desc');
  262. if ($link_sort == 'link_sort') {
  263. $order_by = $link_sort . ' ' . $sort;
  264. } else {
  265. $order_by = $link_sort . ' ' . $sort . ',link_sort desc';
  266. }
  267. $model = new PcModel();
  268. return $model->getLinkPageList($condition, $page, $page_size, $order_by);
  269. } else {
  270. return $this->fetch('pc/link_list');
  271. }
  272. }
  273. /**
  274. * 添加友情链接
  275. * @return mixed
  276. */
  277. public function addLink()
  278. {
  279. $model = new PcModel();
  280. if (request()->isAjax()) {
  281. $data = [
  282. 'link_title' => input('link_title', ''),
  283. 'link_url' => input('link_url', ''),
  284. 'link_pic' => input('link_pic', ''),
  285. 'link_sort' => input('link_sort', ''),
  286. 'is_blank' => input('is_blank', ''),
  287. 'is_show' => input('is_show', ''),
  288. 'site_id' => $this->site_id
  289. ];
  290. return $model->addLink($data);
  291. } else {
  292. return $this->fetch('pc/add_link');
  293. }
  294. }
  295. /**
  296. * 编辑友情链接
  297. * @return mixed
  298. */
  299. public function editLink()
  300. {
  301. $model = new PcModel();
  302. if (request()->isAjax()) {
  303. $data = [
  304. 'link_title' => input('link_title', ''),
  305. 'link_url' => input('link_url', ''),
  306. 'link_pic' => input('link_pic', ''),
  307. 'link_sort' => input('link_sort', ''),
  308. 'is_blank' => input('is_blank', ''),
  309. 'is_show' => input('is_show', ''),
  310. ];
  311. $id = input('id', 0);
  312. $condition = [
  313. [ 'id', '=', $id ],
  314. [ 'site_id', '=', $this->site_id ]
  315. ];
  316. return $model->editLink($data, $condition);
  317. } else {
  318. $id = input('id', 0);
  319. $this->assign('id', $id);
  320. $link_info = $model->getLinkInfo($id);
  321. $this->assign('link_info', $link_info[ 'data' ]);
  322. return $this->fetch('pc/edit_link');
  323. }
  324. }
  325. /**
  326. * 删除友情链接
  327. * @return mixed
  328. */
  329. public function deleteLink()
  330. {
  331. if (request()->isAjax()) {
  332. $id = input('id', 0);
  333. $model = new PcModel();
  334. return $model->deleteLink([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
  335. }
  336. }
  337. /**
  338. * 修改排序
  339. */
  340. public function modifyLinkSort()
  341. {
  342. if (request()->isAjax()) {
  343. $sort = input('sort', 0);
  344. $id = input('id', 0);
  345. return $this->pc_model->modifyLinkSort($sort, $id);
  346. }
  347. }
  348. /**
  349. * 首页楼层
  350. * @return array|mixed
  351. */
  352. public function floor()
  353. {
  354. if (request()->isAjax()) {
  355. $page = input('page', 1);
  356. $page_size = input('page_size', PAGE_LIST_ROWS);
  357. $search_text = input('search_text', '');
  358. $condition = [
  359. [ 'pf.site_id', '=', $this->site_id ]
  360. ];
  361. if (!empty($search_text)) $condition[] = [ 'pf.title', 'like', '%' . $search_text . '%' ];
  362. $list = $this->pc_model->getFloorPageList($condition, $page, $page_size);
  363. return $list;
  364. } else {
  365. return $this->fetch('pc/floor');
  366. }
  367. }
  368. /**
  369. * 修改首页楼层排序
  370. */
  371. public function modifyFloorSort()
  372. {
  373. if (request()->isAjax()) {
  374. $sort = input('sort', 0);
  375. $id = input('id', 0);
  376. $condition = array (
  377. [ 'id', '=', $id ],
  378. [ 'site_id', '=', $this->site_id ]
  379. );
  380. $res = $this->pc_model->modifyFloorSort($sort, $condition);
  381. return $res;
  382. }
  383. }
  384. /**
  385. * 删除首页楼层
  386. * @return array
  387. */
  388. public function deleteFloor()
  389. {
  390. if (request()->isAjax()) {
  391. $id = input('id', 0);
  392. $res = $this->pc_model->deleteFloor([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
  393. return $res;
  394. }
  395. }
  396. /**
  397. * 编辑楼层
  398. * @return mixed
  399. */
  400. public function editFloor()
  401. {
  402. if (request()->isAjax()) {
  403. $id = input("id", 0);
  404. $data = [
  405. 'block_id' => input("block_id", 0), //楼层模板关联id
  406. 'title' => input("title", ''), // 楼层标题
  407. 'value' => input("value", ''),
  408. 'state' => input("state", 0),// 状态(0:禁用,1:启用)
  409. 'sort' => input("sort", 0), //排序号
  410. 'site_id' => $this->site_id
  411. ];
  412. if ($id == 0) {
  413. $res = $this->pc_model->addFloor($data);
  414. } else {
  415. $res = $this->pc_model->editFloor($data, [ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
  416. }
  417. return $res;
  418. } else {
  419. $id = input("id", 0);
  420. $this->assign("id", $id);
  421. if (!empty($id)) {
  422. $floor_info = $this->pc_model->getFloorDetail($id, $this->site_id);
  423. $floor_info = $floor_info[ 'data' ];
  424. $this->assign("floor_info", $floor_info);
  425. }
  426. $floor_block_list = $this->pc_model->getFloorBlockList();
  427. $floor_block_list = $floor_block_list[ 'data' ];
  428. $this->assign("floor_block_list", $floor_block_list);
  429. $pc_link = $this->pc_model->getLink();
  430. $this->assign("pc_link", $pc_link);
  431. $goods_category_model = new GoodsCategoryModel();
  432. $category_list = $goods_category_model->getCategoryTree([ [ 'site_id', '=', $this->site_id ] ]);
  433. $category_list = $category_list[ 'data' ];
  434. $this->assign("category_list", $category_list);
  435. return $this->fetch('pc/edit_floor', [], $this->replace);
  436. }
  437. }
  438. /**
  439. * PC端首页分类设置
  440. * @return array|mixed
  441. */
  442. public function category()
  443. {
  444. $config_model = new Config();
  445. if (request()->isAjax()) {
  446. $data = array (
  447. "category" => input("category", "1"),
  448. "img" => input("img", "0")
  449. );
  450. $res = $config_model->setCategoryConfig($data, $this->site_id, $this->app_module);
  451. return $res;
  452. } else {
  453. $config_info = $config_model->getCategoryConfig($this->site_id, $this->app_module);
  454. $this->assign('config_info', $config_info[ 'data' ][ 'value' ]);
  455. return $this->fetch('pc/category');
  456. }
  457. }
  458. }