Express.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 控制器
  14. */
  15. class Express extends AdminControl {
  16. public function initialize() {
  17. parent::initialize();
  18. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/express.lang.php');
  19. }
  20. public function index() {
  21. $express_letter = input('get.express_letter');
  22. $condition = array();
  23. if (preg_match('/^[A-Z]$/', $express_letter)) {
  24. $condition[]=array('express_letter','=',$express_letter);
  25. }
  26. $express_name = input('get.express_name');
  27. if(!empty($express_name)){
  28. $condition[]=array('express_name','like', "%" . $express_name . "%");
  29. }
  30. $express_model = model('express');
  31. $express_list = $express_model->getAllExpresslist($condition, 10);
  32. View::assign('show_page', $express_model->page_info->render());
  33. View::assign('express_list', $express_list);
  34. $this->setAdminCurItem('index');
  35. return View::fetch();
  36. }
  37. /**
  38. * 添加品牌
  39. */
  40. public function add() {
  41. $express_mod = model('express');
  42. if (request()->isPost()) {
  43. $insert_array['express_name'] = trim(input('post.express_name'));
  44. $insert_array['express_code'] = input('post.express_code');
  45. $insert_array['express_state'] = intval(input('post.express_state'));
  46. $insert_array['express_letter'] = strtoupper(input('post.express_letter'));
  47. $insert_array['express_order'] = intval(input('post.express_order'));
  48. $insert_array['express_url'] = input('post.express_url');
  49. $result = $express_mod->addExpress($insert_array);
  50. if ($result) {
  51. $this->log(lang('ds_add') . lang('express') . '[' . input('post.express_name') . ']', 1);
  52. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  53. } else {
  54. $this->error(lang('ds_common_save_fail'));
  55. }
  56. } else {
  57. $express = [
  58. 'express_order' => 1,
  59. 'express_state' => 1,
  60. ];
  61. View::assign('express', $express);
  62. return View::fetch('form');
  63. }
  64. }
  65. public function edit() {
  66. $express_model = model('express');
  67. $express_id = input('param.express_id');
  68. $condition = array();
  69. if (request()->isPost()) {
  70. $condition[] = array('express_id','=',$express_id);
  71. $data['express_name'] = trim(input('post.express_name'));
  72. $data['express_code'] = input('post.express_code');
  73. $data['express_state'] = intval(input('post.express_state'));
  74. $data['express_letter'] = strtoupper(input('post.express_letter'));
  75. $data['express_order'] = intval(input('post.express_order'));
  76. $data['express_url'] = input('post.express_url');
  77. $result = $express_model->editExpress($condition, $data);
  78. if ($result) {
  79. $this->log(lang('ds_edit') . lang('express_name') . lang('ds_state') . '[ID:' . $express_id . ']', 1);
  80. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  81. } else {
  82. $this->log(lang('ds_edit') . lang('express_name') . lang('ds_state') . '[ID:' . $express_id . ']', 0);
  83. $this->error(lang('ds_common_save_fail'));
  84. }
  85. } else {
  86. $condition[] = array('express_id','=',$express_id);
  87. $express = $express_model->getOneExpress($condition);
  88. if (empty($express)) {
  89. $this->error(lang('param_error'));
  90. }
  91. View::assign('express', $express);
  92. return View::fetch('form');
  93. }
  94. }
  95. /**
  96. * 删除品牌
  97. */
  98. public function del() {
  99. $express_id = input('param.express_id');
  100. $express_id_array = ds_delete_param($express_id);
  101. if ($express_id_array == FALSE) {
  102. $this->log(lang('ds_del') . lang('express') . '[ID:' . $express_id . ']', 0);
  103. ds_json_encode(10001, lang('param_error'));
  104. }
  105. $express_mod = model('express');
  106. $express_mod->delExpress(array(array('express_id','in', implode(',', $express_id_array))));
  107. $this->log(lang('ds_del') . lang('express') . '[ID:' . $express_id . ']', 1);
  108. ds_json_encode(10000, lang('ds_common_del_succ'));
  109. }
  110. /**
  111. * ajax操作
  112. */
  113. public function ajax() {
  114. $branch = input('get.branch');
  115. $column = input('get.column');
  116. $value = trim(input('get.value'));
  117. $id = intval(input('get.id'));
  118. $condition = array();
  119. switch ($branch) {
  120. case 'state':
  121. $express_model = model('express');
  122. $update_array = array();
  123. $condition[] = array('express_id','=',$id);
  124. $update_array[$column] = $value;
  125. $express_model->editExpress($condition, $update_array);
  126. $this->log(lang('ds_edit') . lang('express_name') . lang('ds_state') . '[ID:' . $id . ']', 1);
  127. echo 'true';
  128. exit;
  129. break;
  130. case 'order':
  131. $express_model = model('express');
  132. $update_array = array();
  133. $condition[] = array('express_id','=',$id);
  134. $update_array[$column] = $value;
  135. $express_model->editExpress($condition, $update_array);
  136. $this->log(lang('ds_edit') . lang('express_name') . lang('ds_state') . '[ID:' . $id . ']', 1);
  137. echo 'true';
  138. exit;
  139. break;
  140. }
  141. }
  142. public function config(){
  143. $config_model = model('config');
  144. if (!request()->isPost()) {
  145. $list_config = rkcache('config', true);
  146. View::assign('list_config', $list_config);
  147. /* 设置卖家当前栏目 */
  148. $this->setAdminCurItem('express_config');
  149. return View::fetch();
  150. } else {
  151. $update_array = array();
  152. $update_array['expresscf_kdn_type'] = input('post.expresscf_kdn_type');
  153. $update_array['expresscf_kdn_id'] = input('post.expresscf_kdn_id');
  154. $update_array['expresscf_kdn_key'] = input('post.expresscf_kdn_key');
  155. $result = $config_model->editConfig($update_array);
  156. if ($result) {
  157. $this->success(lang('ds_common_save_succ'));
  158. } else {
  159. $this->error(lang('ds_common_save_fail'));
  160. }
  161. }
  162. }
  163. /**
  164. * 获取卖家栏目列表,针对控制器下的栏目
  165. */
  166. protected function getAdminItemList() {
  167. $menu_array = array(
  168. array(
  169. 'name' => 'index',
  170. 'text' => lang('ds_manage'),
  171. 'url' => (string)url('Express/index'),
  172. ),
  173. array(
  174. 'name' => 'express_config',
  175. 'text' => '快递查询设置',
  176. 'url' => (string)url('Express/config')
  177. ),
  178. array(
  179. 'name' => 'express_add',
  180. 'text' => lang('ds_add'),
  181. 'url' => "javascript:dsLayerOpen('" . (string)url('Express/add') . "','".lang('ds_add')."')"
  182. ),
  183. );
  184. return $menu_array;
  185. }
  186. }