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