Memberbank.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 用户提现账户控制器
  10. */
  11. class Memberbank extends MobileMember
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberbank.lang.php');
  17. }
  18. /**
  19. * @api {POST} api/memberbank/bank_list 获取用户提现账户
  20. * @apiVersion 1.0.0
  21. * @apiGroup Memberbank
  22. *
  23. * @apiHeader {String} X-DS-KEY 用户授权token
  24. *
  25. * @apiSuccess {String} code 返回码,10000为成功
  26. * @apiSuccess {String} message 返回消息
  27. * @apiSuccess {Object} result 返回数据
  28. * @apiSuccess {String} result.bank_list 提现账户
  29. * @apiSuccess {String} result.bank_list.memberbank_id ID
  30. * @apiSuccess {String} result.bank_list.memberbank_type 类型bank银行 alipay支付宝
  31. * @apiSuccess {String} result.bank_list.memberbank_truename 收款人姓名
  32. * @apiSuccess {String} result.bank_list.memberbank_name 收款银行
  33. * @apiSuccess {String} result.bank_list.memberbank_no 收款账户
  34. */
  35. public function bank_list()
  36. {
  37. $memberbank_model = model('memberbank');
  38. $bank_list = $memberbank_model->getMemberbankList(array('member_id' => $this->member_info['member_id']));
  39. $member_wxinfo = unserialize($this->member_info['member_wxinfo']);
  40. if (!empty($member_wxinfo) && is_array($member_wxinfo) && isset($member_wxinfo['member_wxopenid']) && $member_wxinfo['member_wxopenid']) {
  41. if (empty($bank_list)) {
  42. $bank_list = array();
  43. }
  44. $bank_list[] = array('memberbank_id' => -1, 'memberbank_type' => 'weixin', 'memberbank_no' => $member_wxinfo['nickname'], 'member_wxinfo' => $member_wxinfo);
  45. }
  46. ds_json_encode(10000, '', array('bank_list' => $bank_list));
  47. }
  48. /**
  49. * @api {POST} api/memberbank/bank_info 获取提现账户
  50. * @apiVersion 1.0.0
  51. * @apiGroup Memberbank
  52. *
  53. * @apiHeader {String} X-DS-KEY 用户授权token
  54. *
  55. * @apiParam {String} memberbank_id 提现账户ID
  56. *
  57. * @apiSuccess {String} code 返回码,10000为成功
  58. * @apiSuccess {String} message 返回消息
  59. * @apiSuccess {Object} result 返回数据
  60. * @apiSuccess {String} result.bank_info 提现账户信息
  61. * @apiSuccess {String} result.bank_info.memberbank_id ID
  62. * @apiSuccess {String} result.bank_info.memberbank_type 类型bank银行 alipay支付宝
  63. * @apiSuccess {String} result.bank_info.memberbank_truename 收款人姓名
  64. * @apiSuccess {String} result.bank_info.memberbank_name 收款银行
  65. * @apiSuccess {String} result.bank_info.memberbank_no 收款账户
  66. */
  67. public function bank_info()
  68. {
  69. $memberbank_id = intval(input('post.memberbank_id'));
  70. $memberbank_model = model('memberbank');
  71. $condition = array();
  72. $condition[] = array('memberbank_id', '=', $memberbank_id);
  73. $bank_info = $memberbank_model->getMemberbankInfo($condition);
  74. if (!empty($memberbank_id) && $bank_info['member_id'] == $this->member_info['member_id']) {
  75. ds_json_encode(10000, '', array('bank_info' => $bank_info));
  76. } else {
  77. ds_json_encode(10001, lang('memberbank_does_not_exist'));
  78. }
  79. }
  80. /**
  81. * @api {POST} api/memberbank/bank_del 删除提现账户
  82. * @apiVersion 1.0.0
  83. * @apiGroup Memberbank
  84. *
  85. * @apiHeader {String} X-DS-KEY 用户授权token
  86. *
  87. * @apiParam {String} memberbank_id 提现账户ID
  88. *
  89. * @apiSuccess {String} code 返回码,10000为成功
  90. * @apiSuccess {String} message 返回消息
  91. * @apiSuccess {Object} result 返回数据
  92. */
  93. public function bank_del()
  94. {
  95. $memberbank_id = intval(input('post.memberbank_id'));
  96. $memberbank_model = model('memberbank');
  97. $condition = array();
  98. $condition[] = array('memberbank_id', '=', $memberbank_id);
  99. $condition[] = array('member_id', '=', $this->member_info['member_id']);
  100. $memberbank_model->delMemberbank($condition);
  101. ds_json_encode(10000, '', 1);
  102. }
  103. /**
  104. * @api {POST} api/memberbank/bank_add 新增提现账户
  105. * @apiVersion 1.0.0
  106. * @apiGroup Memberbank
  107. *
  108. * @apiHeader {String} X-DS-KEY 用户授权token
  109. *
  110. * @apiParam {String} memberbank_type 类型bank银行 alipay支付宝
  111. * @apiParam {String} memberbank_truename 收款人姓名
  112. * @apiParam {String} memberbank_name 收款银行
  113. * @apiParam {String} memberbank_no 收款账户
  114. *
  115. * @apiSuccess {String} code 返回码,10000为成功
  116. * @apiSuccess {String} message 返回消息
  117. * @apiSuccess {Object} result 返回数据
  118. */
  119. public function bank_add()
  120. {
  121. $memberbank_model = model('memberbank');
  122. $data = array(
  123. 'member_id' => $this->member_info['member_id'],
  124. 'memberbank_type' => input('post.memberbank_type'),
  125. 'memberbank_truename' => input('post.memberbank_truename'),
  126. 'memberbank_name' => input('post.memberbank_name'),
  127. 'memberbank_no' => input('post.memberbank_no'),
  128. );
  129. $memberbank_validate = ds_validate('memberbank');
  130. if (!$memberbank_validate->scene('add')->check($data)) {
  131. ds_json_encode(10001, $memberbank_validate->getError());
  132. }
  133. $result = $memberbank_model->addMemberbank($data);
  134. if ($result) {
  135. ds_json_encode(10000, '', array('memberbank_id' => $result));
  136. } else {
  137. ds_json_encode(10001, lang('ds_common_op_fail'));
  138. }
  139. }
  140. /**
  141. * @api {POST} api/memberbank/bank_edit 编辑提现账户
  142. * @apiVersion 1.0.0
  143. * @apiGroup Memberbank
  144. *
  145. * @apiHeader {String} X-DS-KEY 用户授权token
  146. *
  147. * @apiParam {String} memberbank_id 提现账户ID
  148. * @apiParam {String} memberbank_type 类型bank银行 alipay支付宝
  149. * @apiParam {String} memberbank_truename 收款人姓名
  150. * @apiParam {String} memberbank_name 收款银行
  151. * @apiParam {String} memberbank_no 收款账户
  152. *
  153. * @apiSuccess {String} code 返回码,10000为成功
  154. * @apiSuccess {String} message 返回消息
  155. * @apiSuccess {Object} result 返回数据
  156. */
  157. public function bank_edit()
  158. {
  159. $memberbank_id = intval(input('post.memberbank_id'));
  160. $memberbank_model = model('memberbank');
  161. //验证提现账户是否为本人
  162. $memberbank_info = $memberbank_model->getOneMemberbank($memberbank_id);
  163. if ($memberbank_info['member_id'] != $this->member_info['member_id']) {
  164. ds_json_encode(10001, lang('param_error'));
  165. }
  166. $data = array(
  167. 'memberbank_type' => input('post.memberbank_type'),
  168. 'memberbank_truename' => input('post.memberbank_truename'),
  169. 'memberbank_name' => input('post.memberbank_name'),
  170. 'memberbank_no' => input('post.memberbank_no'),
  171. );
  172. $memberbank_validate = ds_validate('memberbank');
  173. if (!$memberbank_validate->scene('edit')->check($data)) {
  174. ds_json_encode(10001, $memberbank_validate->getError());
  175. }
  176. $result = $memberbank_model->editMemberbank($data, array('memberbank_id' => $memberbank_id, 'member_id' => $this->member_info['member_id']));
  177. if ($result) {
  178. ds_json_encode(10000, '', 1);
  179. } else {
  180. ds_json_encode(10001, lang('ds_common_op_fail'));
  181. }
  182. }
  183. }