Adv.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Adv extends AdminControl {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/adv.lang.php');
  21. }
  22. /**
  23. *
  24. * 管理广告位
  25. */
  26. public function ap_manage() {
  27. $adv_model = model('adv');
  28. /**
  29. * 多选删除广告位
  30. */
  31. if (!request()->isPost()) {
  32. /**
  33. * 显示广告位管理界面
  34. */
  35. $condition = array();
  36. $orderby = '';
  37. $search_name = trim(input('get.search_name'));
  38. if ($search_name != '') {
  39. $condition[]=array('ap_name','like', "%" . $search_name . "%");
  40. }
  41. $ap_list = $adv_model->getAdvpositionList($condition, '10', $orderby);
  42. $adv_list = $adv_model->getAdvList();
  43. View::assign('ap_list', $ap_list);
  44. View::assign('adv_list', $adv_list);
  45. View::assign('showpage', $adv_model->page_info->render());
  46. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  47. $this->setAdminCurItem('ap_manage');
  48. return View::fetch('ap_manage');
  49. }
  50. }
  51. /**
  52. *
  53. * 修改广告位
  54. */
  55. public function ap_edit() {
  56. $ap_id = intval(input('param.ap_id'));
  57. $adv_model = model('adv');
  58. if (!request()->isPost()) {
  59. $condition = array();
  60. $condition[] = array('ap_id','=',$ap_id);
  61. $ap = $adv_model->getOneAdvposition($condition);
  62. View::assign('ref_url', get_referer());
  63. View::assign('ap', $ap);
  64. return View::fetch('ap_form');
  65. } else {
  66. $param['ap_name'] = trim(input('post.ap_name'));
  67. $param['ap_intro'] = trim(input('post.ap_intro'));
  68. $param['ap_width'] = intval(trim(input('post.ap_width')));
  69. $param['ap_height'] = intval(trim(input('post.ap_height')));
  70. if (input('post.ap_isuse') != '') {
  71. $param['ap_isuse'] = intval(input('post.ap_isuse'));
  72. }
  73. $adv_validate = ds_validate('adv');
  74. if (!$adv_validate->scene('ap_edit')->check($param)) {
  75. $this->error($adv_validate->getError());
  76. }
  77. $result = $adv_model->editAdvposition($ap_id,$param);
  78. if ($result>=0) {
  79. $this->log(lang('ap_change_succ') . '[' . input('post.ap_name') . ']', null);
  80. dsLayerOpenSuccess(lang('ap_change_succ'));
  81. } else {
  82. $this->error(lang('ap_change_fail'));
  83. }
  84. }
  85. }
  86. /**
  87. *
  88. * 新增广告位
  89. */
  90. public function ap_add() {
  91. if (!request()->isPost()) {
  92. $ap['ap_isuse'] = 1;
  93. View::assign('ap', $ap);
  94. return View::fetch('ap_form');
  95. } else {
  96. $adv_model = model('adv');
  97. $insert_array['ap_name'] = trim(input('post.ap_name'));
  98. $insert_array['ap_intro'] = trim(input('post.ap_intro'));
  99. $insert_array['ap_isuse'] = intval(input('post.ap_isuse'));
  100. $insert_array['ap_width'] = intval(input('post.ap_width'));
  101. $insert_array['ap_height'] = intval(input('post.ap_height'));
  102. $adv_validate = ds_validate('adv');
  103. if (!$adv_validate->scene('ap_add')->check($insert_array)) {
  104. $this->error($adv_validate->getError());
  105. }
  106. $result = $adv_model->addAdvposition($insert_array);
  107. if ($result) {
  108. $this->log(lang('ap_add_succ') . '[' . input('post.ap_name') . ']', null);
  109. dsLayerOpenSuccess(lang('ap_add_succ'));
  110. } else {
  111. $this->error(lang('ap_add_fail'));
  112. }
  113. }
  114. }
  115. /**
  116. *
  117. * 删除广告位
  118. */
  119. public function ap_del() {
  120. $adv_model = model('adv');
  121. /**
  122. * 删除一个广告
  123. */
  124. $ap_id = intval(input('param.ap_id'));
  125. $result = $adv_model->delAdvposition($ap_id);
  126. if (!$result) {
  127. ds_json_encode('10001', lang('ap_del_fail'));
  128. } else {
  129. $this->log(lang('ap_del_succ') . '[' . $ap_id . ']', null);
  130. ds_json_encode('10000', lang('ap_del_succ'));
  131. }
  132. }
  133. /**
  134. *
  135. * 广告管理
  136. */
  137. public function adv() {
  138. $adv_model = model('adv');
  139. $ap_id = intval(input('param.ap_id'));
  140. if (!request()->isPost()) {
  141. $condition = array();
  142. if ($ap_id) {
  143. $condition[] = array('ap_id','=',$ap_id);
  144. }
  145. $adv_info = $adv_model->getAdvList($condition, 20, '', '');
  146. View::assign('adv_info', $adv_info);
  147. $ap_list = $adv_model->getAdvpositionList();
  148. View::assign('ap_list', $ap_list);
  149. if ($ap_id) {
  150. $ap_condition=array();
  151. $ap_condition['ap_id'] = $ap_id;
  152. $ap = $adv_model->getOneAdvposition($ap_condition);
  153. View::assign('ap_name', $ap['ap_name']);
  154. } else {
  155. View::assign('ap_name', '');
  156. }
  157. View::assign('show_page', $adv_model->page_info->render());
  158. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  159. $this->setAdminCurItem('adv');
  160. return View::fetch('adv_index');
  161. }
  162. }
  163. /**
  164. * 管理员添加广告
  165. */
  166. public function adv_add() {
  167. $adv_model = model('adv');
  168. if (!request()->isPost()) {
  169. $ap_list = $adv_model->getAdvpositionList();
  170. View::assign('ap_list', $ap_list);
  171. $adv = array(
  172. 'ap_id' => 0,
  173. 'adv_enabled' => '1',
  174. 'adv_startdate' => TIMESTAMP,
  175. 'adv_enddate' => TIMESTAMP + 24 * 3600 * 365,
  176. );
  177. View::assign('adv', $adv);
  178. return View::fetch('adv_form');
  179. } else {
  180. $insert_array['ap_id'] = intval(input('post.ap_id'));
  181. $insert_array['adv_title'] = trim(input('post.adv_name'));
  182. $insert_array['adv_link'] = input('post.adv_link');
  183. $insert_array['adv_bgcolor'] = input('post.adv_bgcolor');
  184. $insert_array['adv_sort'] = input('post.adv_sort');
  185. $insert_array['adv_enabled'] = input('post.adv_enabled');
  186. $insert_array['adv_startdate'] = $this->getunixtime(input('post.adv_startdate'));
  187. $insert_array['adv_enddate'] = $this->getunixtime(input('post.adv_enddate'));
  188. //上传文件保存路径
  189. if (!empty($_FILES['adv_code']['name'])) {
  190. $res=ds_upload_pic(ATTACH_ADV,'adv_code');
  191. if($res['code']){
  192. $file_name=$res['data']['file_name'];
  193. $insert_array['adv_code'] = $file_name;
  194. }else{
  195. $this->error($res['msg']);
  196. }
  197. }
  198. $adv_validate = ds_validate('adv');
  199. if (!$adv_validate->scene('adv_add')->check($insert_array)) {
  200. $this->error($adv_validate->getError());
  201. }
  202. //广告信息入库
  203. $result = $adv_model->addAdv($insert_array);
  204. if ($result) {
  205. $this->log(lang('adv_add_succ') . '[' . input('post.adv_name') . ']', null);
  206. dsLayerOpenSuccess(lang('adv_add_succ'));
  207. // $this->success(lang('adv_add_succ'), (string)url('Adv/adv', ['ap_id' => input('post.ap_id')]));
  208. } else {
  209. $this->error(lang('adv_add_fail'));
  210. }
  211. }
  212. }
  213. /**
  214. *
  215. * 修改广告
  216. */
  217. public function adv_edit() {
  218. $adv_id = intval(input('param.adv_id'));
  219. $adv_model = model('adv');
  220. //获取指定广告
  221. $condition = array();
  222. $condition[] = array('adv_id','=',$adv_id);
  223. $adv = $adv_model->getOneAdv($condition);
  224. if (!request()->isPost()) {
  225. //获取广告列表
  226. $ap_list = $adv_model->getAdvpositionList();
  227. View::assign('ap_list', $ap_list);
  228. View::assign('adv', $adv);
  229. View::assign('ref_url', get_referer());
  230. return View::fetch('adv_form');
  231. } else {
  232. $param['ap_id'] = intval(input('post.ap_id'));
  233. $param['adv_title'] = trim(input('post.adv_name'));
  234. $param['adv_link'] = input('post.adv_link');
  235. $param['adv_bgcolor'] = input('post.adv_bgcolor');
  236. $param['adv_sort'] = input('post.adv_sort');
  237. $param['adv_enabled'] = input('post.adv_enabled');
  238. $param['adv_startdate'] = $this->getunixtime(trim(input('post.adv_startdate')));
  239. $param['adv_enddate'] = $this->getunixtime(trim(input('post.adv_enddate')));
  240. if (!empty($_FILES['adv_code']['name'])) {
  241. //上传文件保存路径
  242. $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_ADV;
  243. $res=ds_upload_pic(ATTACH_ADV,'adv_code');
  244. if($res['code']){
  245. //还需删除原来图片
  246. if (!empty($adv['adv_code'])) {
  247. @unlink($upload_file . DIRECTORY_SEPARATOR . $adv['adv_code']);
  248. }
  249. $file_name=$res['data']['file_name'];
  250. $param['adv_code'] = $file_name;
  251. }else{
  252. $this->error($res['msg']);
  253. }
  254. }
  255. $adv_validate = ds_validate('adv');
  256. if (!$adv_validate->scene('adv_edit')->check($param)) {
  257. $this->error($adv_validate->getError());
  258. }
  259. $result = $adv_model->editAdv($adv_id,$param);
  260. if ($result>=0) {
  261. $this->log(lang('adv_change_succ') . '[' . input('post.ap_name') . ']', null);
  262. dsLayerOpenSuccess(lang('adv_change_succ'));
  263. // $this->success(lang('adv_change_succ'), input('post.ref_url'));
  264. } else {
  265. $this->error(lang('adv_change_fail'));
  266. }
  267. }
  268. }
  269. /**
  270. *
  271. * 删除广告
  272. */
  273. public function adv_del() {
  274. $adv_model = model('adv');
  275. /**
  276. * 删除一个广告
  277. */
  278. $adv_id = intval(input('param.adv_id'));
  279. $result = $adv_model->delAdv($adv_id);
  280. if (!$result) {
  281. ds_json_encode('10001', lang('adv_del_fail'));
  282. } else {
  283. $this->log(lang('adv_del_succ') . '[' . $adv_id . ']', null);
  284. ds_json_encode('10000', lang('adv_del_succ'));
  285. }
  286. }
  287. /**
  288. *
  289. * 获取UNIX时间戳
  290. */
  291. public function getunixtime($time) {
  292. $array = explode("-", $time);
  293. $unix_time = mktime(0, 0, 0, $array[1], $array[2], $array[0]);
  294. return $unix_time;
  295. }
  296. public function ajax() {
  297. $adv_model = model('adv');
  298. switch (input('get.branch')) {
  299. case 'ap_branch':
  300. $column = trim(input('param.column'));
  301. $value = trim(input('param.value'));
  302. $ap_id = intval(input('param.id'));
  303. $param[$column] = trim($value);
  304. $result = $adv_model->editAdvposition($ap_id,$param);
  305. break;
  306. //ADV数据表更新
  307. case 'adv_branch':
  308. $column = trim(input('param.column'));
  309. $value = trim(input('param.value'));
  310. $adv_id = intval(input('param.id'));
  311. $param[$column] = trim($value);
  312. $result = $adv_model->editAdv($adv_id,$param);
  313. break;
  314. }
  315. if($result>=0){
  316. echo 'true';
  317. }else{
  318. echo false;
  319. }
  320. }
  321. function adv_template() {
  322. $pages = $this->_get_editable_pages();
  323. View::assign('pages', $pages);
  324. $this->setAdminCurItem('adv_template');
  325. return View::fetch();
  326. }
  327. /**
  328. * 获取可以编辑的页面列表
  329. */
  330. function _get_editable_pages() {
  331. return array(
  332. lang('homepage') => (string)url('home/Index/index',['edit_ad'=>1]),
  333. lang('flea') => (string)url('home/Flea/index',['edit_ad'=>1]),
  334. );
  335. }
  336. /**
  337. * 获取卖家栏目列表,针对控制器下的栏目
  338. */
  339. protected function getAdminItemList() {
  340. $menu_array = array(
  341. array(
  342. 'name' => 'ap_manage',
  343. 'text' => lang('ap_manage'),
  344. 'url' => (string)url('Adv/ap_manage')
  345. ),
  346. );
  347. $menu_array[] = array(
  348. 'name' => 'adv',
  349. 'text' => lang('adv_manage'),
  350. 'url' => (string)url('Adv/adv')
  351. );
  352. $menu_array[] = array(
  353. 'name' => 'adv_add',
  354. 'text' => lang('adv_add'),
  355. 'url' => "javascript:dsLayerOpen('".(string)url('Adv/adv_add', ['ap_id' => input('param.ap_id')])."','".lang('adv_add')."')"
  356. );
  357. return $menu_array;
  358. }
  359. }
  360. ?>