Appadv.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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 Appadv 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. function index()
  23. {
  24. /**
  25. * 显示广告位管理界面
  26. */
  27. $condition = array();
  28. $search_name = trim(input('get.search_name'));
  29. if ($search_name != '') {
  30. $condition[] = array('ap_name','=',$search_name);
  31. }
  32. $appadv_model = model('appadv');
  33. $ap_list= $appadv_model->getAppadvpositionList($condition,'10');
  34. $adv_list = $appadv_model->getAppadvList();
  35. View::assign('ap_list',$ap_list);
  36. View::assign('adv_list',$adv_list);
  37. View::assign('showpage', $appadv_model->page_info->render());
  38. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  39. $this->setAdminCurItem('index');
  40. return View::fetch();
  41. }
  42. /**
  43. *
  44. * 新增广告位
  45. */
  46. public function ap_add() {
  47. if (!request()->isPost()) {
  48. $ap['ap_isuse']=1;
  49. View::assign('ap',$ap);
  50. return View::fetch('ap_form');
  51. } else {
  52. $appadv_model = model('appadv');
  53. $insert_array['ap_name'] = trim(input('post.ap_name'));
  54. $insert_array['ap_intro'] = trim(input('post.ap_intro'));
  55. $insert_array['ap_isuse'] = intval(input('post.ap_isuse'));
  56. $insert_array['ap_width'] = intval(input('post.ap_width'));
  57. $insert_array['ap_height'] = intval(input('post.ap_height'));
  58. $adv_validate = ds_validate('adv');
  59. if (!$adv_validate->scene('app_ap_add')->check($insert_array)) {
  60. $this->error($adv_validate->getError());
  61. }
  62. $result = $appadv_model->addAppadvposition($insert_array);
  63. if ($result) {
  64. $this->log(lang('ap_add_succ') . '[' . input('post.ap_name') . ']', null);
  65. dsLayerOpenSuccess(lang('ap_add_succ'),(string)url('Appadv/index'));
  66. } else {
  67. $this->error(lang('ap_add_fail'));
  68. }
  69. }
  70. }
  71. /**
  72. *
  73. * 删除广告位
  74. */
  75. public function ap_del() {
  76. $appadv_model = model('appadv');
  77. /**
  78. * 删除一个广告位
  79. */
  80. $ap_id = intval(input('param.ap_id'));
  81. $result = $appadv_model->delAppadvposition($ap_id);
  82. if (!$result) {
  83. ds_json_encode(10001, lang('ap_del_fail'));
  84. } else {
  85. $this->log(lang('ap_del_succ') . '[' . $ap_id . ']', null);
  86. ds_json_encode(10000, lang('ap_del_succ'));
  87. }
  88. }
  89. /**
  90. *
  91. * 删除广告
  92. */
  93. public function adv_del() {
  94. $appadv_model = model('appadv');
  95. /**
  96. * 删除一个广告
  97. */
  98. $adv_id = intval(input('param.adv_id'));
  99. $result = $appadv_model->delAppadv($adv_id);
  100. if (!$result) {
  101. ds_json_encode(10001, lang('adv_del_fail'));
  102. } else {
  103. $this->log(lang('adv_del_succ') . '[' . $adv_id . ']', null);
  104. ds_json_encode(10000, lang('adv_del_succ'));
  105. }
  106. }
  107. /**
  108. *
  109. * 修改广告
  110. */
  111. public function adv_edit() {
  112. $adv_id = intval(input('param.adv_id'));
  113. $appadv_model = model('appadv');
  114. //获取指定广告
  115. $condition = array();
  116. $condition[] = array('adv_id','=',$adv_id);
  117. $adv = $appadv_model->getOneAppadv($condition);
  118. if (!request()->isPost()) {
  119. //获取广告列表
  120. $ap_list = $appadv_model->getAppadvpositionList();
  121. View::assign('ap_list', $ap_list);
  122. View::assign('adv', $adv);
  123. View::assign('ref_url', get_referer());
  124. return View::fetch('adv_form');
  125. } else {
  126. $param['ap_id'] = intval(input('post.ap_id'));
  127. $param['adv_title'] = trim(input('post.adv_name'));
  128. $param['adv_type'] = input('post.adv_type');
  129. $param['adv_typedate'] = input('post.adv_typedate');
  130. $param['adv_sort'] = input('post.adv_sort');
  131. $param['adv_enabled'] = input('post.adv_enabled');
  132. $param['adv_startdate'] = $this->getunixtime(trim(input('post.adv_startdate')));
  133. $param['adv_enddate'] = $this->getunixtime(trim(input('post.adv_enddate')));
  134. if (!empty($_FILES['adv_code']['name'])) {
  135. //上传文件保存路径
  136. $upload_file = BASE_UPLOAD_PATH . '/' . ATTACH_APPADV;
  137. $res=ds_upload_pic(ATTACH_APPADV,'adv_code');
  138. if($res['code']){
  139. //还需删除原来图片
  140. if (!empty($adv['adv_code'])) {
  141. @unlink($upload_file . DIRECTORY_SEPARATOR . $adv['adv_code']);
  142. }
  143. $file_name=$res['data']['file_name'];
  144. $param['adv_code'] = $file_name;
  145. }else{
  146. $this->error($res['msg']);
  147. }
  148. }
  149. $adv_validate = ds_validate('adv');
  150. if (!$adv_validate->scene('app_adv_edit')->check($param)) {
  151. $this->error($adv_validate->getError());
  152. }
  153. $result = $appadv_model->editAppadv($adv_id,$param);
  154. if ($result>=0) {
  155. $this->log(lang('adv_change_succ') . '[' . input('post.ap_name') . ']', null);
  156. dsLayerOpenSuccess(lang('adv_change_succ'),input('post.ref_url'));
  157. } else {
  158. $this->error(lang('adv_change_fail'));
  159. }
  160. }
  161. }
  162. public function ajax() {
  163. $appadv_model = model('appadv');
  164. switch (input('get.branch')) {
  165. case 'ap_branch':
  166. $column = input('param.column');
  167. $value = input('param.value');
  168. $ap_id = intval(input('param.id'));
  169. $param[$column] = trim($value);
  170. $result = $appadv_model->editAppadvposition($ap_id,$param);
  171. break;
  172. //ADV数据表更新
  173. case 'adv_branch':
  174. $column = input('param.column');
  175. $value = input('param.value');
  176. $adv_id = intval(input('param.id'));
  177. $param[$column] = trim($value);
  178. $result = $appadv_model->editAppAdv($adv_id,$param);
  179. break;
  180. }
  181. if($result>=0){
  182. echo 'true';
  183. }else{
  184. echo false;
  185. }
  186. }
  187. /**
  188. *
  189. * 广告管理
  190. */
  191. public function adv() {
  192. $appadv_model = model('appadv');
  193. $ap_id = intval(input('param.ap_id'));
  194. if (!request()->isPost()) {
  195. $condition = array();
  196. if ($ap_id) {
  197. $condition[] = array('ap_id','=',$ap_id);
  198. }
  199. $adv_info = $appadv_model->getAppadvList($condition, 20, '', '');
  200. View::assign('adv_info', $adv_info);
  201. $ap_list = $appadv_model->getAppadvpositionList();
  202. View::assign('ap_list', $ap_list);
  203. if ($ap_id) {
  204. $ap_condition=array();
  205. $ap_condition[] = array('ap_id','=',$ap_id);
  206. $ap = $appadv_model->getOneAppadvposition($ap_condition);
  207. View::assign('ap_name', $ap['ap_name']);
  208. } else {
  209. View::assign('ap_name', '');
  210. }
  211. View::assign('show_page', $appadv_model->page_info->render());
  212. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  213. $this->setAdminCurItem('adv');
  214. return View::fetch('adv_index');
  215. }
  216. }
  217. /**
  218. * 管理员添加广告
  219. */
  220. public function appadv_add() {
  221. $appadv_model = model('appadv');
  222. if (!request()->isPost()) {
  223. $ap_list = $appadv_model->getAppadvpositionList();
  224. View::assign('ap_list', $ap_list);
  225. $adv = array(
  226. 'ap_id' => 0,
  227. 'adv_enabled' => '1',
  228. 'adv_startdate' => TIMESTAMP,
  229. 'adv_enddate' => TIMESTAMP + 24 * 3600 * 365,
  230. 'adv_type'=>''
  231. );
  232. View::assign('adv', $adv);
  233. return View::fetch('adv_form');
  234. } else {
  235. $insert_array['ap_id'] = intval(input('post.ap_id'));
  236. $insert_array['adv_title'] = trim(input('post.adv_name'));
  237. $insert_array['adv_type'] = input('post.adv_type');
  238. $insert_array['adv_typedate'] = input('post.adv_typedate');
  239. $insert_array['adv_sort'] = input('post.adv_sort');
  240. $insert_array['adv_enabled'] = input('post.adv_enabled');
  241. $insert_array['adv_startdate'] = $this->getunixtime(input('post.adv_startdate'));
  242. $insert_array['adv_enddate'] = $this->getunixtime(input('post.adv_enddate'));
  243. //上传文件保存路径
  244. $upload_file = BASE_UPLOAD_PATH . '/' . ATTACH_APPADV;
  245. if (!empty($_FILES['adv_code']['name'])) {
  246. $res=ds_upload_pic(ATTACH_APPADV,'adv_code');
  247. if($res['code']){
  248. //还需删除原来图片
  249. if (!empty($adv['adv_code'])) {
  250. @unlink($upload_file . DIRECTORY_SEPARATOR . $adv['adv_code']);
  251. }
  252. $file_name=$res['data']['file_name'];
  253. $insert_array['adv_code'] = $file_name;
  254. }else{
  255. $this->error($res['msg']);
  256. }
  257. }
  258. $adv_validate = ds_validate('adv');
  259. if (!$adv_validate->scene('app_adv_add')->check($insert_array)) {
  260. $this->error($adv_validate->getError());
  261. }
  262. //广告信息入库
  263. $result = $appadv_model->addAppadv($insert_array);
  264. //更新相应广告位所拥有的广告数量
  265. $ap_condition=array();
  266. $ap_condition['ap_id']=intval(input('post.ap_id'));
  267. $appadv_model->getOneAppadvposition($ap_condition);
  268. if ($result) {
  269. $this->log(lang('adv_add_succ') . '[' . input('post.adv_name') . ']', null);
  270. dsLayerOpenSuccess(lang('adv_add_succ'),(string)url('Appadv/adv', ['ap_id' => input('post.ap_id')]));
  271. } else {
  272. $this->error(lang('adv_add_fail'));
  273. }
  274. }
  275. }
  276. /**
  277. *
  278. * 修改广告位
  279. */
  280. public function ap_edit() {
  281. $ap_id = intval(input('param.ap_id'));
  282. $appadv_model = model('appadv');
  283. if (!request()->isPost()) {
  284. $condition = array();
  285. $condition[] = array('ap_id','=',$ap_id);
  286. $ap = $appadv_model->getOneAppadvposition($condition);
  287. View::assign('ref_url', get_referer());
  288. View::assign('ap', $ap);
  289. return View::fetch('ap_form');
  290. } else {
  291. $param['ap_name'] = trim(input('post.ap_name'));
  292. $param['ap_intro'] = trim(input('post.ap_intro'));
  293. $param['ap_width'] = intval(trim(input('post.ap_width')));
  294. $param['ap_height'] = intval(trim(input('post.ap_height')));
  295. if (input('post.ap_isuse') != '') {
  296. $param['ap_isuse'] = intval(input('post.ap_isuse'));
  297. }
  298. $adv_validate = ds_validate('adv');
  299. if (!$adv_validate->scene('app_ap_edit')->check($param)) {
  300. $this->error($adv_validate->getError());
  301. }
  302. $result = $appadv_model->editAppadvposition($ap_id,$param);
  303. if ($result>=0) {
  304. $this->log(lang('ap_change_succ') . '[' . input('post.ap_name') . ']', null);
  305. dsLayerOpenSuccess(lang('ap_change_succ'),input('post.ref_url'));
  306. } else {
  307. $this->error(lang('ap_change_fail'));
  308. }
  309. }
  310. }
  311. /**
  312. *
  313. * 获取UNIX时间戳
  314. */
  315. public function getunixtime($time) {
  316. $array = explode("-", $time);
  317. $unix_time = mktime(0, 0, 0, $array[1], $array[2], $array[0]);
  318. return $unix_time;
  319. }
  320. /**
  321. * 获取卖家栏目列表,针对控制器下的栏目
  322. */
  323. protected function getAdminItemList() {
  324. $menu_array = array(
  325. array(
  326. 'name' => 'index',
  327. 'text' => lang('ap_manage'),
  328. 'url' => (string)url('Appadv/index')
  329. ),
  330. );
  331. $menu_array[] = array(
  332. 'name' => 'adv',
  333. 'text' => lang('adv_manage'),
  334. 'url' => (string)url('Appadv/adv')
  335. );
  336. $menu_array[] = array(
  337. 'name' => 'adv_add',
  338. 'text' => lang('adv_add'),
  339. 'url' => "javascript:dsLayerOpen('".(string)url('Appadv/appadv_add', ['ap_id' => input('param.ap_id')])."','".lang('adv_add')."')"
  340. );
  341. return $menu_array;
  342. }
  343. }