Express.php 7.6 KB

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