Memberbank.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Memberbank extends BaseMember
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberbank.lang.php');
  18. }
  19. public function index()
  20. {
  21. $memberbank_model = model('memberbank');
  22. $memberbank_list = $memberbank_model->getMemberbankList(array('member_id' => session('member_id')));
  23. View::assign('memberbank_list', $memberbank_list);
  24. /* 设置买家当前菜单 */
  25. $this->setMemberCurMenu('member_bank');
  26. /* 设置买家当前栏目 */
  27. $this->setMemberCurItem('memberbank_index');
  28. return View::fetch($this->template_dir . 'index');
  29. }
  30. public function add()
  31. {
  32. if (!request()->isPost()) {
  33. $memberbank = array(
  34. 'memberbank_type' => 'bank',
  35. );
  36. View::assign('memberbank', $memberbank);
  37. /* 设置买家当前菜单 */
  38. $this->setMemberCurMenu('member_bank');
  39. /* 设置买家当前栏目 */
  40. $this->setMemberCurItem('memberbank_add');
  41. return View::fetch($this->template_dir . 'form');
  42. } else {
  43. $data = array(
  44. 'member_id' => session('member_id'),
  45. 'memberbank_type' => input('post.memberbank_type'),
  46. 'memberbank_truename' => input('post.memberbank_truename'),
  47. 'memberbank_name' => input('post.memberbank_name'),
  48. 'memberbank_no' => input('post.memberbank_no'),
  49. );
  50. $memberbank_validate = ds_validate('memberbank');
  51. if (!$memberbank_validate->scene('add')->check($data)) {
  52. ds_json_encode(10001, $memberbank_validate->getError());
  53. }
  54. $memberbank_model = model('memberbank');
  55. $result = $memberbank_model->addMemberbank($data);
  56. if ($result) {
  57. ds_json_encode(10000, lang('ds_common_save_succ'));
  58. } else {
  59. ds_json_encode(10001, lang('ds_common_save_fail'));
  60. }
  61. }
  62. }
  63. public function edit()
  64. {
  65. $memberbank_id = intval(input('param.memberbank_id'));
  66. if (0 >= $memberbank_id) {
  67. ds_json_encode(10001, lang('param_error'));
  68. }
  69. $memberbank_model = model('memberbank');
  70. $memberbank = $memberbank_model->getMemberbankInfo(array('member_id' => session('member_id'), 'memberbank_id' => $memberbank_id));
  71. if (empty($memberbank)) {
  72. ds_json_encode(10001, lang('memberbank_does_not_exist'));
  73. }
  74. if (!request()->isPost()) {
  75. View::assign('memberbank', $memberbank);
  76. /* 设置买家当前菜单 */
  77. $this->setMemberCurMenu('member_bank');
  78. /* 设置买家当前栏目 */
  79. $this->setMemberCurItem('memberbank_edit');
  80. return View::fetch($this->template_dir . 'form');
  81. } else {
  82. $data = array(
  83. 'memberbank_type' => input('post.memberbank_type'),
  84. 'memberbank_truename' => input('post.memberbank_truename'),
  85. 'memberbank_name' => input('post.memberbank_name'),
  86. 'memberbank_no' => input('post.memberbank_no'),
  87. );
  88. $memberbank_validate = ds_validate('memberbank');
  89. if (!$memberbank_validate->scene('edit')->check($data)) {
  90. ds_json_encode(10001, $memberbank_validate->getError());
  91. }
  92. $result = $memberbank_model->editMemberbank($data, array('member_id' => session('member_id'), 'memberbank_id' => $memberbank_id));
  93. if ($result) {
  94. ds_json_encode(10000, lang('ds_common_save_succ'));
  95. } else {
  96. ds_json_encode(10001, lang('ds_common_save_fail'));
  97. }
  98. }
  99. }
  100. public function drop()
  101. {
  102. $memberbank_id = intval(input('param.memberbank_id'));
  103. if (0 >= $memberbank_id) {
  104. ds_json_encode(10001, lang('empty_error'));
  105. }
  106. $memberbank_model = model('memberbank');
  107. $condition = array();
  108. $condition[] = array('memberbank_id', '=', $memberbank_id);
  109. $condition[] = array('member_id', '=', session('member_id'));
  110. $result = $memberbank_model->delMemberbank($condition);
  111. if ($result) {
  112. ds_json_encode(10000, lang('ds_common_del_succ'));
  113. } else {
  114. ds_json_encode(10001, lang('ds_common_del_fail'));
  115. }
  116. }
  117. /**
  118. * 栏目菜单
  119. */
  120. function getMemberItemList()
  121. {
  122. $item_list = array(
  123. array(
  124. 'name' => 'memberbank_index',
  125. 'text' => lang('memberbank_index'),
  126. 'url' => (string)url('Memberbank/index'),
  127. ),
  128. array(
  129. 'name' => 'memberbank_add',
  130. 'text' => lang('memberbank_add'),
  131. 'url' => (string)url('Memberbank/add'),
  132. ),
  133. );
  134. if (request()->action() == 'edit') {
  135. $item_list[] = array(
  136. 'name' => 'memberbank_edit',
  137. 'text' => lang('memberbank_edit'),
  138. 'url' => "javascript:void(0)",
  139. );
  140. }
  141. return $item_list;
  142. }
  143. }