UserExtractServices.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\services\user;
  13. use app\jobs\system\CapitalFlowJob;
  14. use app\model\user\UserExtract;
  15. use app\services\BaseServices;
  16. use app\dao\user\UserExtractDao;
  17. use app\services\order\StoreOrderCreateServices;
  18. use app\services\wechat\WechatUserServices;
  19. use crmeb\exceptions\AdminException;
  20. use crmeb\services\wechat\Payment;
  21. use crmeb\services\FormBuilder as Form;
  22. use crmeb\services\WithdrawService;
  23. use crmeb\traits\ServicesTrait;
  24. use FormBuilder\Factory\Iview;
  25. use think\exception\ValidateException;
  26. use think\facade\Route as Url;
  27. /**
  28. *
  29. * Class UserExtractServices
  30. * @package app\services\user
  31. * @mixin UserExtractDao
  32. */
  33. class UserExtractServices extends BaseServices
  34. {
  35. use ServicesTrait;
  36. /**
  37. * UserExtractServices constructor.
  38. * @param UserExtractDao $dao
  39. */
  40. public function __construct(UserExtractDao $dao)
  41. {
  42. $this->dao = $dao;
  43. }
  44. /**
  45. * 获取一条提现记录
  46. * @param int $id
  47. * @param array $field
  48. * @return array|\think\Model|null
  49. */
  50. public function getExtract(int $id, array $field = [])
  51. {
  52. return $this->dao->get($id, $field);
  53. }
  54. /**
  55. * 获取某个用户提现总数
  56. * @param int $uid
  57. * @return float
  58. */
  59. public function getUserExtract(int $uid)
  60. {
  61. return $this->dao->getWhereSum(['uid' => $uid, 'status' => [0, 1]]);
  62. }
  63. /**
  64. * 获取某些用户的提现总数列表
  65. * @param array $uids
  66. */
  67. public function getUsersSumList(array $uids)
  68. {
  69. return $this->dao->getWhereSumList(['uid' => $uids, 'status' => [0, 1]]);
  70. }
  71. public function getCount(array $where = [])
  72. {
  73. return $this->dao->getCount($where);
  74. }
  75. /**
  76. * 获取提现列表
  77. * @param array $where
  78. * @param string $field
  79. * @return array
  80. * @throws \think\db\exception\DataNotFoundException
  81. * @throws \think\db\exception\DbException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. */
  84. public function getUserExtractList(array $where, string $field = '*')
  85. {
  86. [$page, $limit] = $this->getPageValue();
  87. $list = $this->dao->getExtractList($where, $field, $page, $limit);
  88. foreach ($list as &$item) {
  89. $item['nickname'] = $item['user']['nickname'] ?? '';
  90. }
  91. $count = $this->dao->count($where);
  92. return compact('list', 'count');
  93. }
  94. /**
  95. * 获取提现总数
  96. * @param array $where
  97. */
  98. public function getExtractSum(array $where)
  99. {
  100. return $this->dao->getExtractMoneyByWhere($where, 'extract_price');
  101. }
  102. /**
  103. * 拒绝提现申请
  104. * @param $id
  105. * @param $fail_msg
  106. * @return bool
  107. * @throws \think\db\exception\DataNotFoundException
  108. * @throws \think\db\exception\ModelNotFoundException
  109. * @throws \think\exception\DbException
  110. */
  111. public function changeFail(int $id, $userExtract, $message)
  112. {
  113. $fail_time = time();
  114. $extract_number = bcadd((string)$userExtract['extract_price'], (string)$userExtract['extract_fee'], 2);
  115. $mark = '提现失败,退回佣金' . $extract_number . '元';
  116. $uid = $userExtract['uid'];
  117. $status = -1;
  118. /** @var UserServices $userServices */
  119. $userServices = app()->make(UserServices::class);
  120. $user = $userServices->getUserInfo($uid);
  121. if (!$user) {
  122. throw new ValidateException('用户不存在');
  123. }
  124. /** @var UserBrokerageServices $userBrokerageServices */
  125. $userBrokerageServices = app()->make(UserBrokerageServices::class);
  126. $this->transaction(function () use ($user, $userBrokerageServices, $uid, $id, $extract_number, $message, $userServices, $status, $fail_time) {
  127. $now_brokerage = bcadd((string)$user['brokerage_price'], (string)$extract_number, 2);
  128. //增加佣金记录
  129. $userBrokerageServices->income('extract_fail', $uid, $extract_number, $now_brokerage, $id);
  130. //修改用户佣金
  131. if (!$userServices->update($uid, ['brokerage_price' => $now_brokerage], 'uid'))
  132. throw new AdminException('增加用户佣金失败');
  133. if (!$this->dao->update($id, ['fail_time' => $fail_time, 'fail_msg' => $message, 'status' => $status])) {
  134. throw new AdminException('修改失败');
  135. }
  136. });
  137. //消息推送
  138. event('notice.notice', [['uid' => $uid, 'userType' => strtolower($user['user_type']), 'extract_number' => $extract_number, 'nickname' => $user['nickname'], 'message' => $message], 'user_balance_change']);
  139. return true;
  140. }
  141. /**
  142. * 通过提现申请
  143. * @param $id
  144. * @return bool
  145. * @throws \think\db\exception\DataNotFoundException
  146. * @throws \think\db\exception\ModelNotFoundException
  147. * @throws \think\exception\DbException
  148. */
  149. public function changeSuccess(int $id, $userExtract)
  150. {
  151. $extractNumber = $userExtract['extract_price'];
  152. $this->transaction(function () use ($id, $userExtract, $extractNumber) {
  153. if ($userExtract['extract_type'] != 'bank') {
  154. if (!$this->dao->update($id, ['status' => 1])) {
  155. throw new AdminException('修改失败');
  156. }
  157. //配置开启自动到零钱
  158. if (sys_config('brokerage_type', 0)) {
  159. /** @var WechatUserServices $wechatServices */
  160. $wechatServices = app()->make(WechatUserServices::class);
  161. $openid = $wechatServices->getWechatOpenid((int)$userExtract['uid'], 'wechat');
  162. if ($openid) {//公众号用户
  163. $type = Payment::WEB;
  164. } else {//小程序用户
  165. $openid = $wechatServices->getWechatOpenid((int)$userExtract['uid'], 'routine');
  166. $type = Payment::MINI;
  167. }
  168. //app微信用户
  169. if (!$openid) {
  170. $openid = $wechatServices->getWechatOpenid((int)$userExtract['uid'], 'app');
  171. $type = Payment::APP;
  172. }
  173. if ($openid) {
  174. /** @var StoreOrderCreateServices $services */
  175. $services = app()->make(StoreOrderCreateServices::class);
  176. $wechat_order_id = $services->getNewOrderId();
  177. $res = Payment::merchantPay($openid, $wechat_order_id, $extractNumber, '提现佣金到零钱', $type);
  178. if (!$res) {
  179. throw new ValidateException('企业付款到零钱失败,请稍后再试');
  180. }
  181. } else {
  182. throw new ValidateException('该用户暂不支持企业付款到零钱,请手动转账');
  183. }
  184. }
  185. /** @var UserServices $userServices */
  186. $userServices = app()->make(UserServices::class);
  187. $userType = $userServices->value(['uid' => $userExtract['uid']], 'user_type');
  188. $nickname = $userServices->value(['uid' => $userExtract['uid']], 'nickname');
  189. $phone = $userServices->value(['uid' => $userExtract['uid']], 'phone');
  190. switch ($userExtract['extract_type']) {
  191. case 'bank':
  192. $order_id = $userExtract['bank_code'];
  193. break;
  194. case 'weixin':
  195. $order_id = $userExtract['wechat'];
  196. break;
  197. case 'alipay':
  198. $order_id = $userExtract['alipay_code'];
  199. break;
  200. default:
  201. $order_id = '';
  202. break;
  203. }
  204. //记录资金流水队列
  205. CapitalFlowJob::dispatch([['order_id' => $order_id, 'store_id' => 0, 'uid' => $userExtract['uid'], 'nickname' => $nickname, 'phone' => $phone, 'price' => $extractNumber, 'pay_type' => $userExtract['extract_type']], 'extract']);
  206. //消息推送
  207. event('notice.notice', [['uid' => $userExtract['uid'], 'userType' => strtolower($userType), 'extractNumber' => $extractNumber, 'nickname' => $nickname], 'user_extract']);
  208. } else {
  209. if (!$this->dao->update($id, ['status' => 1])) {
  210. throw new AdminException('修改失败');
  211. }
  212. // $userServices = app()->make(UserServices::class);
  213. // $userInfo = $userServices->get($userExtract['uid']);
  214. // if (!$userInfo['professional_id']) {
  215. // throw new ValidateException('用户未认证签约');
  216. // }
  217. // $bankInfo = WithdrawService::init()::contractInfo($userInfo['enterprise_professional_facilitator_id']);
  218. // if (!$bankInfo['sign_img']) throw new ValidateException('用户未签约');
  219. // $res = WithdrawService::init()::fastIssuing(
  220. // $userInfo['professional_id'],
  221. // $userExtract['id'],
  222. // $bankInfo['name'],
  223. // $bankInfo['cer_code'],
  224. // $bankInfo['mobile'],
  225. // $bankInfo['bank_code'],
  226. // $extractNumber,
  227. // '佣金提现'
  228. // );
  229. // if ($res) {
  230. // $this->dao->update($id, ['trade_number' => $res['trade_number']]);
  231. // }
  232. }
  233. });
  234. return true;
  235. }
  236. /**
  237. * 显示资源列表
  238. * @param array $where
  239. * @return array
  240. * @throws \think\db\exception\DataNotFoundException
  241. * @throws \think\db\exception\DbException
  242. * @throws \think\db\exception\ModelNotFoundException
  243. */
  244. public function index(array $where)
  245. {
  246. $list = $this->getUserExtractList($where);
  247. //待提现金额
  248. $where['status'] = 0;
  249. $extract_statistics['price'] = $this->getExtractSum($where);
  250. //已提现金额
  251. $where['status'] = 1;
  252. $extract_statistics['priced'] = $this->getExtractSum($where);
  253. //佣金总金额
  254. /** @var UserBrokerageServices $userBrokerageServices */
  255. $userBrokerageServices = app()->make(UserBrokerageServices::class);
  256. $extract_statistics['brokerage_count'] = $userBrokerageServices->getUsersBokerageSum(array_merge($where, ['pm' => 1, 'not_type' => ['extract_fail', 'refund']]));
  257. //未提现金额
  258. $extract_statistics['brokerage_not'] = $extract_statistics['brokerage_count'] > $extract_statistics['priced'] ? bcsub((string)$extract_statistics['brokerage_count'], (string)$extract_statistics['priced'], 2) : 0.00;
  259. return compact('extract_statistics', 'list');
  260. }
  261. /**
  262. * 显示资源列表
  263. * @param array $where
  264. * @return array
  265. * @throws \think\db\exception\DataNotFoundException
  266. * @throws \think\db\exception\DbException
  267. * @throws \think\db\exception\ModelNotFoundException
  268. */
  269. public function getExportList(array $where)
  270. {
  271. $list = $this->dao->getExtractList($where);
  272. foreach ($list as &$item) {
  273. $item['nickname'] = $item['user']['nickname'] ?? '';
  274. }
  275. return $list;
  276. }
  277. /**
  278. * 显示编辑资源表单页.
  279. *
  280. * @param int $id
  281. * @return \think\Response
  282. */
  283. public function edit(int $id)
  284. {
  285. $UserExtract = $this->getExtract($id);
  286. if (!$UserExtract) {
  287. throw new AdminException('数据不存在!');
  288. }
  289. $f = array();
  290. $f[] = Form::input('real_name', '姓名', $UserExtract['real_name']);
  291. $f[] = Form::number('extract_price', '提现金额', (float)$UserExtract['extract_price'])->precision(2)->disabled(true);
  292. if ($UserExtract['extract_type'] == 'alipay') {
  293. $f[] = Form::input('alipay_code', '支付宝账号', $UserExtract['alipay_code']);
  294. } else if ($UserExtract['extract_type'] == 'weixin') {
  295. $f[] = Form::input('wechat', '微信号', $UserExtract['wechat']);
  296. } else {
  297. $f[] = Form::input('bank_code', '银行卡号', $UserExtract['bank_code']);
  298. $f[] = Form::input('bank_address', '开户行', $UserExtract['bank_address']);
  299. }
  300. $f[] = Form::input('mark', '备注', $UserExtract['mark'])->type('textarea');
  301. return create_form('编辑', $f, Url::buildUrl('/finance/extract/' . $id), 'PUT');
  302. }
  303. public function changeOrderStatusForm(int $id)
  304. {
  305. $f = array();
  306. $f[] = Form::radio('status', '审核意见', '1')->setOptions([['label' => '通过', 'value' => '1'], ['label' => '拒绝', 'value' => '5'],]);
  307. $f[] = Form::frameImage('icon', '具体结算清单', Url::buildUrl(config('admin.admin_prefix') . '/widget.images/index', array('fodder' => 'icon')))->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true])->appendValidate(Iview::validateStr()->required()->message('请选择具体结算清单'));
  308. $f[] = Form::frameImage('image', '公章图片', Url::buildUrl(config('admin.admin_prefix') . '/widget.images/index', array('fodder' => 'image')))->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true])->appendValidate(Iview::validateStr()->required()->message('请选择公章图片'));
  309. $f[] = Form::input('remarks', '备注')->type('textarea');
  310. return create_form('编辑', $f, Url::buildUrl('/finance/extract/order/' . $id), 'PUT');
  311. }
  312. public function update(int $id, array $data)
  313. {
  314. if (!$this->dao->update($id, $data))
  315. throw new AdminException('修改失败');
  316. else
  317. return true;
  318. }
  319. /**
  320. * 拒绝
  321. * @param $id
  322. * @return mixed
  323. */
  324. public function refuse(int $id, string $message)
  325. {
  326. $extract = $this->getExtract($id);
  327. if (!$extract) {
  328. throw new AdminException('操作记录不存在!');
  329. }
  330. if ($extract->status == 1) {
  331. throw new AdminException('已经提现,错误操作');
  332. }
  333. if ($extract->status == -1) {
  334. throw new AdminException('您的提现申请已被拒绝,请勿重复操作!');
  335. }
  336. $res = $this->changeFail($id, $extract, $message);
  337. if ($res) {
  338. return true;
  339. } else {
  340. throw new AdminException('操作失败!');
  341. }
  342. }
  343. /**
  344. * 通过
  345. * @param $id
  346. * @return mixed
  347. */
  348. public function adopt(int $id)
  349. {
  350. $extract = $this->getExtract($id);
  351. if (!$extract) {
  352. throw new AdminException('操作记录不存!');
  353. }
  354. if ($extract->status == 1 || $extract->status == 2) {
  355. throw new AdminException('您已提现,请勿重复提现!');
  356. }
  357. if ($extract->status == -1) {
  358. throw new AdminException('您的提现申请已被拒绝!');
  359. }
  360. if ($this->changeSuccess($id, $extract)) {
  361. return true;
  362. } else {
  363. throw new AdminException('操作失败!');
  364. }
  365. }
  366. /**待提现的数量
  367. * @return int
  368. */
  369. public function userExtractCount()
  370. {
  371. return $this->dao->count(['status' => 0]);
  372. }
  373. /**
  374. * 银行卡提现
  375. * @param int $uid
  376. * @return mixed
  377. */
  378. public function bank(int $uid)
  379. {
  380. /** @var UserServices $userService */
  381. $userService = app()->make(UserServices::class);
  382. $user = $userService->getUserInfo($uid);
  383. if (!$user) {
  384. throw new ValidateException('数据不存在');
  385. }
  386. /** @var UserBrokerageServices $userBrokerageServices */
  387. $userBrokerageServices = app()->make(UserBrokerageServices::class);
  388. $data['broken_commission'] = $userBrokerageServices->getUserFrozenPrice($uid);
  389. if ($data['broken_commission'] < 0)
  390. $data['broken_commission'] = '0';
  391. $data['brokerage_price'] = $user['brokerage_price'];
  392. //可提现佣金
  393. $data['commissionCount'] = bcsub((string)$data['brokerage_price'], (string)$data['broken_commission'], 2);
  394. $extractBank = sys_config('user_extract_bank') ?? []; //提现银行
  395. $extractBank = str_replace("\r\n", "\n", $extractBank);//防止不兼容
  396. $data['extractBank'] = explode("\n", is_array($extractBank) ? (isset($extractBank[0]) ? $extractBank[0] : $extractBank) : $extractBank);
  397. $data['minPrice'] = sys_config('user_extract_min_price');//提现最低金额
  398. $data['withdraw_fee'] = sys_config('withdraw_fee');//提现手续费
  399. $data['extract_wechat_type'] = sys_config('brokerage_type');//微信提现到账方式
  400. return $data;
  401. }
  402. /**
  403. * 提现申请
  404. * @param int $uid
  405. * @param array $data
  406. */
  407. public function cash(int $uid, array $data)
  408. {
  409. /** @var UserServices $userService */
  410. $userService = app()->make(UserServices::class);
  411. $user = $userService->getUserInfo($uid);
  412. if (!$user) {
  413. throw new ValidateException('数据不存在');
  414. }
  415. if (UserExtract::where('uid', $user['uid'])
  416. ->whereTime('add_time', 'month')
  417. ->where('status', 0)->find()) {
  418. throw new ValidateException('请等待上次提现申请通过');
  419. }
  420. // if (!$user['enterprise_professional_facilitator_id']) {
  421. // throw new ValidateException('签约未完成');
  422. // }
  423. // $bank_info = WithdrawService::init()::contractInfo($user['enterprise_professional_facilitator_id']);
  424. // if (!$bank_info['sign_img']) {
  425. // throw new ValidateException('签约未完成');
  426. // }
  427. // $data['cardnum'] = $bank_info['bank_code'];
  428. // $data['bankname'] = '灵活用工提现';
  429. /** @var UserBrokerageServices $userBrokerageServices */
  430. $userBrokerageServices = app()->make(UserBrokerageServices::class);
  431. $data['broken_commission'] = $userBrokerageServices->getUserFrozenPrice($uid);
  432. if ($data['broken_commission'] < 0)
  433. $data['broken_commission'] = 0;
  434. $data['brokerage_price'] = $user['brokerage_price'];
  435. //可提现佣金
  436. $commissionCount = (float)bcsub((string)$data['brokerage_price'], (string)$data['broken_commission'], 2);
  437. if ($data['money'] > $commissionCount) {
  438. throw new ValidateException('可提现佣金不足');
  439. }
  440. $extractPrice = $user['brokerage_price'];
  441. $userExtractMinPrice = sys_config('user_extract_min_price');
  442. if ($data['money'] < $userExtractMinPrice) {
  443. throw new ValidateException('提现金额不能小于' . $userExtractMinPrice . '元');
  444. }
  445. if ($extractPrice < 0) {
  446. throw new ValidateException('提现佣金不足' . $data['money']);
  447. }
  448. if ($data['money'] > $extractPrice) {
  449. throw new ValidateException('提现佣金不足' . $data['money']);
  450. }
  451. if ($data['money'] <= 0) {
  452. throw new ValidateException('提现佣金大于0');
  453. }
  454. $fee = sys_data('withdraw_fee');
  455. $fees = [];
  456. foreach ($fee as $v) {
  457. $fees[$v['month_number']] = (string)$v['fee'];
  458. }
  459. krsort($fees, SORT_DESC);
  460. $sum_money = UserExtract::where('uid', $user['uid'])
  461. ->whereTime('add_time', 'month')
  462. ->where('extract_type', '<>', 'balance')
  463. ->where('status', 1)->sum('extract_price');
  464. $money = $data['money'];
  465. $extract_fee = 0;
  466. $max = PHP_INT_MAX;
  467. foreach ($fees as $k => $v) {
  468. if ($sum_money > $max) {
  469. break;
  470. }
  471. $max = $k;
  472. if ($sum_money + $money > $k) {
  473. $extract_fee = bcadd($extract_fee, bcmul((string)($sum_money + $money - ($sum_money > $k ? $sum_money : $k)), bcdiv($v, '100', 4), 2));
  474. $money = $money - ($sum_money + $money - $k);
  475. }
  476. }
  477. $insertData = [
  478. 'uid' => $user['uid'],
  479. 'extract_type' => $data['extract_type'],
  480. 'extract_price' => bcsub((string)$data['money'], (string)$extract_fee, 2),
  481. 'extract_fee' => $extract_fee,
  482. 'add_time' => time(),
  483. 'balance' => $user['brokerage_price'],
  484. 'image' => $data['image'],
  485. 'status' => 0
  486. ];
  487. if (isset($data['name']) && strlen(trim($data['name']))) $insertData['real_name'] = $data['name'];
  488. else $insertData['real_name'] = $user['nickname'];
  489. if (isset($data['cardnum'])) $insertData['bank_code'] = $data['cardnum'];
  490. else $insertData['bank_code'] = '';
  491. if (isset($data['bankname'])) $insertData['bank_address'] = $data['bankname'];
  492. else $insertData['bank_address'] = '';
  493. if (isset($data['weixin'])) $insertData['wechat'] = $data['weixin'];
  494. else $insertData['wechat'] = $user['nickname'];
  495. if ($data['extract_type'] == 'alipay') {
  496. $insertData['alipay_code'] = $data['alipay_code'];
  497. $insertData['qrcode_url'] = $data['qrcode_url'];
  498. $mark = '使用支付宝';
  499. } else if ($data['extract_type'] == 'bank') {
  500. $mark = '使用银联卡' . $insertData['bank_code'];
  501. } else if ($data['extract_type'] == 'weixin') {
  502. $insertData['qrcode_url'] = $data['qrcode_url'];
  503. $mark = '使用微信提现';
  504. /** @var WechatUserServices $wechatServices */
  505. $wechatServices = app()->make(WechatUserServices::class);
  506. $openid = $wechatServices->getWechatOpenid($uid, 'wechat');
  507. if (sys_config('brokerage_type', 0) && $openid) {
  508. if ($insertData['extract_price'] < 1) {
  509. throw new ValidateException('扣除手续费后,提现金额不足1元;而企业微信付款到零钱最低金额为1元');
  510. }
  511. }
  512. }
  513. /** @var UserBrokerageServices $userBrokerageServices */
  514. $userBrokerageServices = app()->make(UserBrokerageServices::class);
  515. $res1 = $this->transaction(function () use ($insertData, $data, $uid, $userService, $user, $userBrokerageServices, $mark) {
  516. if (!$res1 = $this->dao->save($insertData)) {
  517. throw new ValidateException('提现失败');
  518. }
  519. //修改用户佣金
  520. $balance = bcsub((string)$user['brokerage_price'], (string)$data['money'], 2) ?? 0;
  521. if (!$userService->update($uid, ['brokerage_price' => $balance], 'uid')) {
  522. throw new ValidateException('修改用户信息失败');
  523. }
  524. //保存佣金记录
  525. $userBrokerageServices->income('extract', $uid, ['mark' => $mark, 'number' => $data['money']], $balance, $res1['id']);
  526. return $res1;
  527. });
  528. //用户申请体现事件
  529. event('user.extract', [$user, $data, $res1]);
  530. return true;
  531. }
  532. /**
  533. * @param array $where
  534. * @param string $SumField
  535. * @param string $selectType
  536. * @param string $group
  537. * @return float|mixed
  538. */
  539. public function getOutMoneyByWhere(array $where, string $SumField, string $selectType, string $group = "")
  540. {
  541. switch ($selectType) {
  542. case "sum" :
  543. return $this->dao->getWhereSumField($where, $SumField);
  544. case "group" :
  545. return $this->dao->getGroupField($where, $SumField, $group);
  546. }
  547. }
  548. }