Appadv.php 14 KB

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