UserExtract.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\merchant\controller\finance;
  12. use app\merchant\controller\AuthController;
  13. use service\FormBuilder as Form;
  14. use app\merchant\model\user\UserExtract as UserExtractModel;
  15. use app\merchant\model\merchant\Merchant;
  16. use app\merchant\model\merchant\MerchantBill;
  17. use service\JsonService;
  18. use service\SystemConfigService;
  19. use think\Request;
  20. use think\Url;
  21. /**
  22. * 用户提现管理
  23. * Class UserExtract
  24. */
  25. class UserExtract extends AuthController
  26. {
  27. public function index()
  28. {
  29. return $this->fetch();
  30. }
  31. public function get_mer_user_extract()
  32. {
  33. $where = parent::getMore([
  34. ['status', ''],
  35. ['extract_type', ''],
  36. ], $this->request);
  37. $where['mer_id'] = $this->merchantId;
  38. return JsonService::successlayui(UserExtractModel::systemPage($where));
  39. }
  40. /**编辑提现
  41. * @param $id
  42. * @return mixed|void
  43. * @throws \think\exception\DbException
  44. */
  45. public function edit($id)
  46. {
  47. if (!$id) return $this->failed('数据不存在');
  48. $UserExtract = UserExtractModel::get($id);
  49. if (!$UserExtract) return JsonService::fail('数据不存在!');
  50. $f = array();
  51. if ($UserExtract['extract_type'] == 'alipay') {
  52. $f[] = Form::input('real_name', '姓名', $UserExtract['real_name']);
  53. $f[] = Form::input('alipay_code', '支付宝账号', $UserExtract['alipay_code']);
  54. } else if ($UserExtract['extract_type'] == 'bank') {
  55. $f[] = Form::input('real_name', '姓名', $UserExtract['real_name']);
  56. $f[] = Form::input('bank_code', '银行卡号', $UserExtract['bank_code']);
  57. $f[] = Form::input('bank_address', '开户行', $UserExtract['bank_address']);
  58. } else if ($UserExtract['extract_type'] == 'weixin') {
  59. $f[] = Form::input('real_name', '姓名', $UserExtract['real_name']);
  60. $f[] = Form::input('wechat', '微信号', $UserExtract['wechat']);
  61. }
  62. $f[] = Form::number('extract_price', '提现金额', $UserExtract['extract_price'])->precision(2);
  63. $f[] = Form::input('mark', '备注', $UserExtract['mark'])->type('textarea');
  64. $form = Form::make_post_form('编辑', $f, Url::build('update', array('id' => $id)), 2);
  65. $this->assign(compact('form'));
  66. return $this->fetch('public/form-builder');
  67. }
  68. public function update(Request $request, $id)
  69. {
  70. $UserExtract = UserExtractModel::get($id);
  71. if (!$UserExtract) return JsonService::fail('数据不存在!');
  72. if ($UserExtract['extract_type'] == 'alipay') {
  73. $data = parent::postMore([
  74. 'real_name',
  75. 'mark',
  76. 'extract_price',
  77. 'alipay_code',
  78. ], $request);
  79. if (!$data['real_name']) return JsonService::fail('请输入姓名');
  80. if ($data['extract_price'] <= -1) return JsonService::fail('请输入提现金额');
  81. if (!$data['alipay_code']) return JsonService::fail('请输入支付宝账号');
  82. } else if ($UserExtract['extract_type'] == 'weixin') {
  83. $data = parent::postMore([
  84. 'real_name',
  85. 'mark',
  86. 'extract_price',
  87. 'wechat',
  88. ], $request);
  89. if (!$data['real_name']) return JsonService::fail('请输入姓名');
  90. if ($data['extract_price'] <= -1) return JsonService::fail('请输入提现金额');
  91. if (!$data['wechat']) return JsonService::fail('请输入wechat');
  92. } else if ($UserExtract['extract_type'] == 'bank') {
  93. $data = parent::postMore([
  94. 'real_name',
  95. 'extract_price',
  96. 'mark',
  97. 'bank_code',
  98. 'bank_address',
  99. ], $request);
  100. if (!$data['real_name']) return JsonService::fail('请输入姓名');
  101. if ($data['extract_price'] <= -1) return JsonService::fail('请输入提现金额');
  102. if (!$data['bank_code']) return JsonService::fail('请输入银行卡号');
  103. if (!$data['bank_address']) return JsonService::fail('请输入开户行');
  104. } else if ($UserExtract['extract_type'] == 'yue') {
  105. $data = parent::postMore([
  106. 'extract_price',
  107. 'mark',
  108. ], $request);
  109. if ($data['extract_price'] <= -1) return JsonService::fail('请输入提现金额');
  110. }
  111. if (!UserExtractModel::edit($data, $id))
  112. return JsonService::fail(UserExtractModel::getErrorInfo('修改失败'));
  113. else
  114. return JsonService::successful('修改成功!');
  115. }
  116. public function forward_list()
  117. {
  118. $where = parent::getMore([
  119. ['status', 'all'],
  120. ['uid', $this->merchantInfo['uid']],
  121. ['mer_id', $this->merchantId]
  122. ]);
  123. $where['act'] = $this->request->param('act', 'my');
  124. $adminInfo = $this->adminInfo;
  125. if ($adminInfo['uid'] == $this->merchantInfo['uid']) {
  126. $is_son_admin = 2;
  127. } else {
  128. $is_son_admin = 1;
  129. }
  130. $this->assign([
  131. 'is_son_admin' => $is_son_admin,
  132. 'gold_name' => SystemConfigService::get("gold_name"),
  133. 'gold_coin_ratio' => SystemConfigService::get("gold_coin_ratio"),
  134. 'money' => Merchant::where('id', $this->merchantId)->field('now_money,gold_num')->find(),
  135. 'where' => $where
  136. ]);
  137. return $this->fetch();
  138. }
  139. public function extract()
  140. {
  141. $this->assign('merchat', json_encode($this->merchantInfo));
  142. return $this->fetch();
  143. }
  144. /**
  145. * 提现申请
  146. */
  147. public function save_extract()
  148. {
  149. $extractInfo = parent::postMore([
  150. ['extract_type', ''],
  151. ['extract_price', 0],
  152. ['real_name', ''],
  153. ['bank_code', ''],
  154. ['bank_address', ''],
  155. ['weixin', ''],
  156. ['alipay_code', '']
  157. ]);
  158. $res = UserExtractModel::userExtract($this->merchantId, $extractInfo, SystemConfigService::get('extract_price'));
  159. if ($res)
  160. return JsonService::successful('申请提现成功!');
  161. else
  162. return JsonService::fail(UserExtractModel::getErrorInfo());
  163. }
  164. public function save_gold()
  165. {
  166. $where = parent::getMore([
  167. ['gold', 0]
  168. ]);
  169. $merchant = Merchant::where('id', $this->merchantId)->find();
  170. if ($merchant['gold_num'] < $where['gold']) return JsonService::fail('余额不足');
  171. $gold_name = SystemConfigService::get("gold_name");
  172. $gold_coin_ratio = SystemConfigService::get("gold_coin_ratio");
  173. $gold_coin_ratio = bcdiv($gold_coin_ratio, 100, 2);
  174. $price = bcmul($gold_coin_ratio, $where['gold'], 2);
  175. Merchant::beginTrans();
  176. $mark = '提现' . $where['gold'] . '个' . $gold_name . '成余额';
  177. $mark1 = '提现' . $where['gold'] . '个' . $gold_name . '获得' . $price . '余额';
  178. $res1 = MerchantBill::expend($gold_name . '提现', 0, $merchant['id'], 'gold_num', 'gold_turn_balance', $where['gold'], bcsub($merchant['gold_num'], $where['gold'], 0), $mark);
  179. $res2 = MerchantBill::income($gold_name . '提现', 0, $merchant['id'], 'now_money', 'gold_extract', $price, bcadd($merchant['now_money'], $price, 2), $mark1);
  180. $res3 = Merchant::bcDec($merchant['id'], 'gold_num', $where['gold'], 'id', true);
  181. $res4 = Merchant::bcInc($merchant['id'], 'now_money', $price, 'id');
  182. $res = $res1 && $res2 && $res3 && $res4;
  183. if ($res) {
  184. Merchant::commitTrans();
  185. return JsonService::successful('提现成功!');
  186. } else {
  187. Merchant::rollbackTrans();
  188. return JsonService::fail('提现失败');
  189. }
  190. }
  191. }