MemberBankAccount.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\model\member;
  11. use app\model\BaseModel;
  12. use think\facade\Cache;
  13. /**
  14. * 会员提现账号
  15. */
  16. class MemberBankAccount extends BaseModel
  17. {
  18. private $withdraw_type = [
  19. 'alipay' => '支付宝',
  20. 'bank' => '银行卡',
  21. 'wechatpay' => '微信'
  22. ];
  23. public function getWithdrawType()
  24. {
  25. return $this->withdraw_type;
  26. }
  27. /**
  28. * 添加会员提现账号
  29. * @param $data
  30. * @return array
  31. */
  32. public function addMemberBankAccount($data)
  33. {
  34. //获取提现设置
  35. $config_model = new Withdraw();
  36. $config_result = $config_model->getConfig(1, 'shop');
  37. $config = $config_result['data']['value'];
  38. if (!empty($config)) {
  39. //提现方式为微信的时候 判断用户是否已关注公众号
  40. if ($data['withdraw_type'] == 'wechatpay') {
  41. //获取会员信息
  42. $member_info = model('member')->getInfo([['member_id', '=', $data['member_id']]], 'wx_openid,weapp_openid');
  43. if (empty($member_info['wx_openid']) && empty($member_info['weapp_openid'])) {
  44. return $this->error('', '请先绑定微信');
  45. }
  46. }
  47. model('member_bank_account')->startTrans();
  48. try {
  49. if ($data['is_default'] == 1) {
  50. model('member_bank_account')->update(['is_default' => 0], ['member_id' => $data['member_id']]);
  51. }
  52. $data['create_time'] = time();
  53. $id = model('member_bank_account')->add($data);
  54. $count = model('member_bank_account')->getCount(['member_id' => $data['member_id']]);
  55. if ($count == 1)
  56. model('member_bank_account')->update(['is_default' => 1], ['member_id' => $data['member_id'], 'id' => $id]);
  57. Cache::tag("member_bank_account_" . $data['member_id'])->clear();
  58. model('member_bank_account')->commit();
  59. return $this->success($id);
  60. } catch (\Exception $e) {
  61. model('member_bank_account')->rollback();
  62. return $this->error('', $e->getMessage());
  63. }
  64. } else {
  65. return $this->error('', '平台未开启会员提现');
  66. }
  67. }
  68. /**
  69. * 修改会员提现账号
  70. * @param $data
  71. * @return array
  72. */
  73. public function editMemberBankAccount($data)
  74. {
  75. //获取提现设置
  76. $config_model = new Withdraw();
  77. $config_result = $config_model->getConfig(1, 'shop');
  78. $config = $config_result['data']['value'];
  79. if (!empty($config)) {
  80. //提现方式为微信的时候 判断用户是否已关注公众号
  81. if ($data['withdraw_type'] == 'wechatpay') {
  82. //获取会员信息
  83. $member_info = model('member')->getInfo([['member_id', '=', $data['member_id']]], 'wx_openid,weapp_openid');
  84. if (empty($member_info['wx_openid']) && empty($member_info['weapp_openid'])) {
  85. return $this->error('', '请先绑定微信');
  86. }
  87. }
  88. model('member_bank_account')->startTrans();
  89. try {
  90. if ($data['is_default'] == 1) {
  91. model('member_bank_account')->update(['is_default' => 0], ['member_id' => $data['member_id']]);
  92. }
  93. $data['modify_time'] = time();
  94. $res = model('member_bank_account')->update($data, ['id' => $data['id']]);
  95. Cache::tag("member_bank_account_" . $data['member_id'])->clear();
  96. model('member_bank_account')->commit();
  97. return $this->success($res);
  98. } catch (\Exception $e) {
  99. model('member_bank_account')->rollback();
  100. return $this->error('', $e->getMessage());
  101. }
  102. } else {
  103. return $this->error('', '平台未开启会员提现');
  104. }
  105. }
  106. /**
  107. * 删除会员提现账号
  108. * @param array $condition
  109. */
  110. public function deleteMemberBankAccount($condition)
  111. {
  112. $check_condition = array_column($condition, 2, 0);
  113. $res = model('member_bank_account')->delete($condition);
  114. Cache::tag("member_bank_account_" . $check_condition['member_id'])->clear();
  115. if ($res === false) {
  116. return $this->error('', 'RESULT_ERROR');
  117. }
  118. return $this->success($res);
  119. }
  120. /**
  121. * 设置默认会员提现账号
  122. * @param $id
  123. * @param $member_id
  124. * @return \multitype
  125. */
  126. public function modifyDefaultAccount($id, $member_id)
  127. {
  128. model('member_bank_account')->startTrans();
  129. try {
  130. model('member_bank_account')->update(['is_default' => 0], ['member_id' => $member_id]);
  131. $res = model('member_bank_account')->update(['is_default' => 1], ['member_id' => $member_id, 'id' => $id]);
  132. model('member_bank_account')->commit();
  133. Cache::tag("member_bank_account_" . $member_id)->clear();
  134. return $this->success($res);
  135. } catch (\Exception $e) {
  136. model('member_bank_account')->rollback();
  137. return $this->error('', $e->getMessage());
  138. }
  139. }
  140. /**
  141. * 获取会员提现账号信息
  142. * @param $condition
  143. * @param string $field
  144. * @return array
  145. */
  146. public function getMemberBankAccountInfo($condition, $field = '*')
  147. {
  148. $check_condition = array_column($condition, 2, 0);
  149. $data = json_encode([$condition, $field]);
  150. $cache = Cache::get("member_bank_account_getMemberBankAccountInfo_" . $data);
  151. if (!empty($cache)) {
  152. return $this->success($cache);
  153. }
  154. $res = model('member_bank_account')->getInfo($condition, $field);
  155. Cache::tag("member_bank_account_" . $check_condition['member_id'])->set("member_bank_account_getMemberBankAccountInfo_" . $data, $res);
  156. return $this->success($res);
  157. }
  158. /**
  159. * 获取会员提现账号分页列表
  160. * @param array $condition
  161. * @param int $page
  162. * @param int $page_size
  163. * @param string $order
  164. * @param string $field
  165. * @return array|\multitype
  166. */
  167. public function getMemberBankAccountPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc', $field = '*')
  168. {
  169. $check_condition = array_column($condition, 2, 0);
  170. $data = json_encode([$condition, $field, $order, $page, $page_size]);
  171. $cache = Cache::get("member_bank_account_getMemberBankAccountPageList_" . $data);
  172. if (!empty($cache)) {
  173. return $this->success($cache);
  174. }
  175. $list = model('member_bank_account')->pageList($condition, $field, $order, $page, $page_size);
  176. Cache::tag("member_bank_account_" . $check_condition['member_id'])->set("member_bank_account_getMemberBankAccountPageList_" . $data, $list);
  177. return $this->success($list);
  178. }
  179. }