UserLevelServices.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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\services\BaseServices;
  14. use app\dao\user\UserLevelDao;
  15. use app\services\system\SystemUserLevelServices;
  16. use crmeb\exceptions\AdminException;
  17. use crmeb\exceptions\ApiException;
  18. use crmeb\services\FormBuilder as Form;
  19. use think\facade\Route as Url;
  20. /**
  21. *
  22. * Class UserLevelServices
  23. * @package app\services\user
  24. * @method getDiscount(int $uid, string $field)
  25. */
  26. class UserLevelServices extends BaseServices
  27. {
  28. /**
  29. * UserLevelServices constructor.
  30. * @param UserLevelDao $dao
  31. */
  32. public function __construct(UserLevelDao $dao)
  33. {
  34. $this->dao = $dao;
  35. }
  36. /**
  37. * 某些条件获取单个
  38. * @param array $where
  39. * @param string $field
  40. * @return mixed
  41. */
  42. public function getWhereLevel(array $where, string $field = '*')
  43. {
  44. return $this->getOne($where, $field);
  45. }
  46. /**
  47. * 获取一些用户等级信息
  48. * @param array $uids
  49. * @param string $field
  50. * @param string $key
  51. * @return array
  52. */
  53. public function getUsersLevelInfo(array $uids)
  54. {
  55. return $this->dao->getColumn([['uid', 'in', $uids]], 'level_id,is_forever,valid_time', 'uid');
  56. }
  57. /**
  58. * 清除用户等级
  59. * @param $uids
  60. * @return \crmeb\basic\BaseModel|mixed
  61. */
  62. public function delUserLevel($uids)
  63. {
  64. $where = [];
  65. if (is_array($uids)) {
  66. $where[] = ['uid', 'IN', $uids];
  67. $re = $this->dao->batchUpdate($uids, ['is_del' => 1, 'status' => 0], 'uid');
  68. } else {
  69. $where[] = ['uid', '=', $uids];
  70. $re = $this->dao->update($uids, ['is_del' => 1, 'status' => 0], 'uid');
  71. }
  72. if (!$re)
  73. throw new AdminException(400671);
  74. $where[] = ['category', 'IN', ['exp']];
  75. /** @var UserBillServices $userbillServices */
  76. $userbillServices = app()->make(UserBillServices::class);
  77. $userbillServices->update($where, ['status' => -1]);
  78. return true;
  79. }
  80. /**
  81. * 根据用户uid 获取用户等级详细信息
  82. * @param int $uid
  83. * @param string $field
  84. */
  85. public function getUerLevelInfoByUid(int $uid, string $field = '')
  86. {
  87. $userLevelInfo = $this->dao->getUserLevel($uid);
  88. $data = [];
  89. if ($userLevelInfo) {
  90. $data = ['id' => $userLevelInfo['id'], 'level_id' => $userLevelInfo['level_id'], 'add_time' => $userLevelInfo['add_time']];
  91. $data['discount'] = $userLevelInfo['levelInfo']['discount'] ?? 0;
  92. $data['name'] = $userLevelInfo['levelInfo']['name'] ?? '';
  93. $data['money'] = $userLevelInfo['levelInfo']['money'] ?? 0;
  94. $data['icon'] = $userLevelInfo['levelInfo']['icon'] ?? '';
  95. $data['is_pay'] = $userLevelInfo['levelInfo']['is_pay'] ?? 0;
  96. $data['grade'] = $userLevelInfo['levelInfo']['grade'] ?? 0;
  97. $data['exp_num'] = $userLevelInfo['levelInfo']['exp_num'] ?? 0;
  98. }
  99. if ($field) return $data[$field] ?? '';
  100. return $data;
  101. }
  102. /**
  103. * 设置用户等级
  104. * @param $uid 用户uid
  105. * @param $level_id 等级id
  106. * @return UserLevel|bool|\think\Model
  107. * @throws \think\db\exception\DataNotFoundException
  108. * @throws \think\db\exception\ModelNotFoundException
  109. * @throws \think\exception\DbException
  110. */
  111. public function setUserLevel(int $uid, int $level_id, $vipinfo = [])
  112. {
  113. /** @var SystemUserLevelServices $systemLevelServices */
  114. $systemLevelServices = app()->make(SystemUserLevelServices::class);
  115. if (!$vipinfo) {
  116. $vipinfo = $systemLevelServices->getLevel($level_id);
  117. if (!$vipinfo) {
  118. throw new AdminException(400672);
  119. }
  120. }
  121. /** @var $user */
  122. $user = app()->make(UserServices::class);
  123. $userinfo = $user->getUserInfo($uid);
  124. //把之前等级作废
  125. $this->dao->update(['uid' => $uid], ['status' => 0, 'is_del' => 1]);
  126. //检查是否购买过
  127. $uservipinfo = $this->getWhereLevel(['uid' => $uid, 'level_id' => $level_id]);
  128. $data['mark'] = '尊敬的用户' . $userinfo['nickname'] . '在' . date('Y-m-d H:i:s', time()) . '成为了' . $vipinfo['name'];
  129. $data['add_time'] = time();
  130. if ($uservipinfo) {
  131. $data['status'] = 1;
  132. $data['is_del'] = 0;
  133. if (!$this->dao->update(['id' => $uservipinfo['id']], $data))
  134. throw new AdminException(400671);
  135. } else {
  136. $data = array_merge($data, [
  137. 'is_forever' => $vipinfo->is_forever,
  138. 'status' => 1,
  139. 'is_del' => 0,
  140. 'grade' => $vipinfo->grade,
  141. 'uid' => $uid,
  142. 'level_id' => $level_id,
  143. 'discount' => $vipinfo->discount,
  144. ]);
  145. $data['valid_time'] = 0;
  146. if (!$this->dao->save($data)) throw new AdminException(100006);
  147. }
  148. if ($level_id > $userinfo['level']) {
  149. $change_exp = $vipinfo['exp_num'] - $userinfo['exp'];
  150. $pm = 1;
  151. $type = 'system_exp_add';
  152. $title = '系统增加经验';
  153. $mark = '系统增加' . $change_exp . '经验';
  154. } else {
  155. $change_exp = $userinfo['exp'] - $vipinfo['exp_num'];
  156. $pm = 0;
  157. $type = 'system_exp_sub';
  158. $title = '系统减少经验';
  159. $mark = '系统减少' . $change_exp . '经验';
  160. }
  161. $bill_data['uid'] = $uid;
  162. $bill_data['pm'] = $pm;
  163. $bill_data['title'] = $title;
  164. $bill_data['category'] = 'exp';
  165. $bill_data['type'] = $type;
  166. $bill_data['number'] = abs($change_exp);
  167. $bill_data['balance'] = $userinfo['exp'];
  168. $bill_data['mark'] = $mark;
  169. $bill_data['status'] = 1;
  170. $bill_data['add_time'] = time();
  171. /** @var UserBillServices $userBillService */
  172. $userBillService = app()->make(UserBillServices::class);
  173. if (!$userBillService->save($bill_data)) throw new AdminException(100006);
  174. if (!$user->update(['uid' => $uid], ['level' => $level_id, 'exp' => $vipinfo['exp_num']])) throw new AdminException(100007);
  175. return true;
  176. }
  177. /**
  178. * 会员列表
  179. * @param $where
  180. * @return mixed
  181. */
  182. public function getSytemList($where)
  183. {
  184. /** @var SystemUserLevelServices $systemLevelServices */
  185. $systemLevelServices = app()->make(SystemUserLevelServices::class);
  186. return $systemLevelServices->getLevelList($where);
  187. }
  188. /**
  189. * 获取添加修改需要表单数据
  190. * @param int $id
  191. * @return array
  192. * @throws \FormBuilder\Exception\FormBuilderException
  193. */
  194. public function edit(int $id)
  195. {
  196. if ($id) {
  197. $vipInfo = app()->make(SystemUserLevelServices::class)->getlevel($id);
  198. $vipInfo->image = set_file_url($vipInfo->image);
  199. $vipInfo->icon = set_file_url($vipInfo->icon);
  200. if (!$vipInfo) {
  201. throw new AdminException(100026);
  202. }
  203. $field[] = Form::hidden('id', $id);
  204. $msg = '编辑用户等级';
  205. } else {
  206. $msg = '添加用户等级';
  207. }
  208. $field[] = Form::input('name', '等级名称', isset($vipInfo) ? $vipInfo->name : '')->maxlength(10)->col(24)->required();
  209. $field[] = Form::number('grade', '等级', isset($vipInfo) ? $vipInfo->grade : 0)->min(0)->precision(0)->required();
  210. // $field[] = Form::number('discount', '享受折扣', isset($vipInfo) ? $vipInfo->discount : 100)->min(0)->max(100)->placeholder('输入折扣数100,代表原价,90代表9折')->required();
  211. // $field[] = Form::number('exp_num', '解锁经验值', isset($vipInfo) ? $vipInfo->exp_num : 0)->min(0)->precision(0)->required();
  212. $field[] = Form::frameImage('icon', '图标', Url::buildUrl(config('app.admin_prefix', 'admin') . '/widget.images/index', array('fodder' => 'icon')), isset($vipInfo) ? $vipInfo->icon : '')->icon('el-icon-picture-outline')->width('950px')->height('560px')->props(['footer' => false]);
  213. $field[] = Form::frameImage('image', '用户等级背景', Url::buildUrl(config('app.admin_prefix', 'admin') . '/widget.images/index', array('fodder' => 'image')), isset($vipInfo) ? $vipInfo->image : '')->icon('el-icon-picture-outline')->width('950px')->height('560px')->props(['footer' => false]);
  214. $field[] = Form::number('radio', '分红比例', isset($vipInfo) ? $vipInfo->radio : 0)->min(0)->placeholder('输入比例0.1,代表礼包订单金额的0.1%')->col(12);
  215. $field[] = Form::radio('is_show', '是否显示', isset($vipInfo) ? $vipInfo->is_show : 0)->options([['label' => '显示', 'value' => 1], ['label' => '隐藏', 'value' => 0]])->col(12);
  216. return create_form($msg, $field, Url::buildUrl('/user/user_level'), 'POST');
  217. }
  218. /*
  219. * 会员等级添加或者修改
  220. * @param $id 修改的等级id
  221. * @return json
  222. * */
  223. public function save(int $id, array $data)
  224. {
  225. /** @var SystemUserLevelServices $systemUserLevel */
  226. $systemUserLevel = app()->make(SystemUserLevelServices::class);
  227. $levelOne = $systemUserLevel->getWhereLevel(['is_del' => 0, 'grade' => $data['grade']]);
  228. $levelTwo = $systemUserLevel->getWhereLevel(['is_del' => 0, 'exp_num' => $data['exp_num']]);
  229. $levelThree = $systemUserLevel->getWhereLevel(['is_del' => 0, 'name' => $data['name']]);
  230. $levelPre = $systemUserLevel->getPreLevel($data['grade']);
  231. $levelNext = $systemUserLevel->getNextLevel($data['grade']);
  232. // if ($levelPre && $data['exp_num'] <= $levelPre['exp_num']) {
  233. // throw new AdminException(400673);
  234. // }
  235. // if ($levelNext && $data['exp_num'] >= $levelNext['exp_num']) {
  236. // throw new AdminException(400674);
  237. // }
  238. //修改
  239. if ($id) {
  240. if (($levelOne && $levelOne['id'] != $id) || ($levelThree && $levelThree['id'] != $id)) {
  241. throw new AdminException(400675);
  242. }
  243. // if ($levelTwo && $levelTwo['id'] != $id) {
  244. // throw new AdminException(400676);
  245. // }
  246. if (!$systemUserLevel->update($id, $data)) {
  247. throw new AdminException(100007);
  248. }
  249. return true;
  250. } else {
  251. if ($levelOne || $levelThree) {
  252. throw new AdminException(400675);
  253. }
  254. // if ($levelTwo) {
  255. // throw new AdminException(400676);
  256. // }
  257. //新增
  258. $data['add_time'] = time();
  259. if (!$systemUserLevel->save($data)) {
  260. throw new AdminException(100022);
  261. }
  262. return true;
  263. }
  264. }
  265. /**
  266. * 假删除
  267. * @param int $id
  268. * @return mixed
  269. */
  270. public function delLevel(int $id)
  271. {
  272. /** @var SystemUserLevelServices $systemUserLevel */
  273. $systemUserLevel = app()->make(SystemUserLevelServices::class);
  274. $level = $systemUserLevel->getWhereLevel(['id' => $id]);
  275. if ($level && $level['is_del'] != 1) {
  276. if (!$systemUserLevel->update($id, ['is_del' => 1]))
  277. throw new AdminException(100008);
  278. }
  279. return 100002;
  280. }
  281. /**
  282. * 设置是否显示
  283. * @param int $id
  284. * @param $is_show
  285. * @return mixed
  286. */
  287. public function setShow(int $id, int $is_show)
  288. {
  289. /** @var SystemUserLevelServices $systemUserLevel */
  290. $systemUserLevel = app()->make(SystemUserLevelServices::class);
  291. if (!$systemUserLevel->getWhereLevel(['id' => $id]))
  292. throw new AdminException(100026);
  293. if ($systemUserLevel->update($id, ['is_show' => $is_show])) {
  294. return 100014;
  295. } else {
  296. throw new AdminException(100015);
  297. }
  298. }
  299. /**
  300. * 快速修改
  301. * @param int $id
  302. * @param $is_show
  303. * @return mixed
  304. */
  305. public function setValue(int $id, array $data)
  306. {
  307. /** @var SystemUserLevelServices $systemUserLevel */
  308. $systemUserLevel = app()->make(SystemUserLevelServices::class);
  309. if (!$systemUserLevel->getWhereLevel(['id' => $id]))
  310. throw new AdminException(100026);
  311. if ($systemUserLevel->update($id, [$data['field'] => $data['value']])) {
  312. return true;
  313. } else {
  314. throw new AdminException(100006);
  315. }
  316. }
  317. /**
  318. * 检测用户会员升级
  319. * @param $uid
  320. * @return bool
  321. */
  322. public function detection(int $uid)
  323. {
  324. //商城会员是否开启
  325. if (!sys_config('member_func_status')) {
  326. return true;
  327. }
  328. /** @var UserServices $userServices */
  329. $userServices = app()->make(UserServices::class);
  330. $user = $userServices->getUserInfo($uid);
  331. if (!$user) {
  332. throw new ApiException(410284);
  333. }
  334. /** @var SystemUserLevelServices $systemUserLevel */
  335. $systemUserLevel = app()->make(SystemUserLevelServices::class);
  336. $userAllLevel = $systemUserLevel->getList([['is_del', '=', 0], ['is_show', '=', 1], ['exp_num', '<=', (float)$user['exp']]]);
  337. if (!$userAllLevel) {
  338. return true;
  339. }
  340. $data = [];
  341. $data['add_time'] = time();
  342. $userLevel = $this->dao->getColumn(['uid' => $uid, 'status' => 1, 'is_del' => 0], 'level_id');
  343. foreach ($userAllLevel as $vipinfo) {
  344. if (in_array($vipinfo['id'], $userLevel)) {
  345. continue;
  346. }
  347. $data['mark'] = '尊敬的用户' . $user['nickname'] . '在' . date('Y-m-d H:i:s', time()) . '成为了' . $vipinfo['name'];
  348. $uservip = $this->dao->getOne(['uid' => $uid, 'level_id' => $vipinfo['id']]);
  349. if ($uservip) {
  350. //降级在升级情况
  351. $data['status'] = 1;
  352. $data['is_del'] = 0;
  353. if (!$this->dao->update($uservip['id'], $data, 'id')) {
  354. throw new ApiException(410285);
  355. }
  356. } else {
  357. $data = array_merge($data, [
  358. 'is_forever' => $vipinfo['is_forever'],
  359. 'status' => 1,
  360. 'is_del' => 0,
  361. 'grade' => $vipinfo['grade'],
  362. 'uid' => $uid,
  363. 'level_id' => $vipinfo['id'],
  364. 'discount' => $vipinfo['discount'],
  365. ]);
  366. if (!$this->dao->save($data)) {
  367. throw new ApiException(410285);
  368. }
  369. }
  370. $data['add_time'] += 1;
  371. }
  372. if (!$userServices->update($uid, ['level' => end($userAllLevel)['id']], 'uid')) {
  373. throw new ApiException(410285);
  374. }
  375. return true;
  376. }
  377. /**
  378. * 会员等级列表
  379. * @param int $uid
  380. */
  381. public function grade(int $uid)
  382. {
  383. //商城会员是否开启
  384. if (!sys_config('member_func_status')) {
  385. return [];
  386. }
  387. /** @var UserServices $userServices */
  388. $userServices = app()->make(UserServices::class);
  389. $user = $userServices->getUserInfo($uid);
  390. if (!$user) {
  391. throw new ApiException(410284);
  392. }
  393. $userLevelInfo = $this->getUerLevelInfoByUid($uid);
  394. if (empty($userLevelInfo)) {
  395. $level_id = 0;
  396. } else {
  397. $level_id = $userLevelInfo['level_id'];
  398. }
  399. /** @var SystemUserLevelServices $systemUserLevel */
  400. $systemUserLevel = app()->make(SystemUserLevelServices::class);
  401. return $systemUserLevel->getLevelListAndGrade($level_id);
  402. }
  403. /**
  404. * 获取会员信息
  405. * @param int $uid
  406. * @return array[]
  407. */
  408. public function getUserLevelInfo(int $uid)
  409. {
  410. $data = ['user' => [], 'level_info' => [], 'level_list' => [], 'task' => []];
  411. //商城会员是否开启
  412. if (!sys_config('member_func_status')) {
  413. return $data;
  414. }
  415. /** @var UserServices $userServices */
  416. $userServices = app()->make(UserServices::class);
  417. $user = $userServices->getUserInfo($uid);
  418. if (!$user) {
  419. throw new ApiException(410032);
  420. }
  421. $data['user'] = $user;
  422. /** @var SystemUserLevelServices $systemUserLevel */
  423. $systemUserLevel = app()->make(SystemUserLevelServices::class);
  424. $levelList = $systemUserLevel->getList(['is_del' => 0, 'is_show' => 1]);
  425. $i = 0;
  426. foreach ($levelList as &$level) {
  427. $level['next_exp_num'] = $levelList[$i + 1]['exp_num'] ?? $level['exp_num'];
  428. $level['image'] = set_file_url($level['image']);
  429. $level['icon'] = set_file_url($level['icon']);
  430. $i++;
  431. }
  432. $data['level_list'] = $levelList;
  433. $data['level_info'] = $this->getUerLevelInfoByUid($uid);
  434. $data['level_info']['exp'] = $user['exp'] ?? 0;
  435. /** @var UserBillServices $userBillservices */
  436. $userBillservices = app()->make(UserBillServices::class);
  437. $data['level_info']['today_exp'] = $userBillservices->getExpSum($uid, 'today');
  438. $task = [];
  439. /** @var UserSignServices $userSignServices */
  440. $userSignServices = app()->make(UserSignServices::class);
  441. $task['sign_count'] = $userSignServices->getSignSumDay($uid);
  442. $task['sign'] = sys_config('sign_give_exp', 0);
  443. $task['order'] = sys_config('order_give_exp', 0);
  444. $task['invite'] = sys_config('invite_user_exp', 0);
  445. $data['task'] = $task;
  446. return $data;
  447. }
  448. /**
  449. * 经验列表
  450. * @param int $uid
  451. * @return array
  452. */
  453. public function expList(int $uid)
  454. {
  455. /** @var UserServices $userServices */
  456. $userServices = app()->make(UserServices::class);
  457. $user = $userServices->getUserInfo($uid);
  458. if (!$user) {
  459. throw new ApiException(410032);
  460. }
  461. /** @var UserBillServices $userBill */
  462. $userBill = app()->make(UserBillServices::class);
  463. $data = $userBill->getExpList($uid, [], 'id,title,number,pm,add_time');
  464. $list = $data['list'] ?? [];
  465. return $list;
  466. }
  467. /**
  468. * 等级分红
  469. * @return string
  470. * @throws \think\db\exception\DataNotFoundException
  471. * @throws \think\db\exception\DbException
  472. * @throws \think\db\exception\ModelNotFoundException
  473. */
  474. public function levelDividend()
  475. {
  476. // 获取今天的开始和结束时间戳
  477. $todayStart = strtotime(date('Y-m-d 00:00:00'));
  478. $todayEnd = strtotime(date('Y-m-d 23:59:59'));
  479. // 获取今天所有礼包订单的总金额
  480. /** @var \app\model\order\StoreOrder $orderModel */
  481. $orderModel = new \app\model\order\StoreOrder();
  482. $totalGiftAmount = $orderModel->where([
  483. ['paid', '=', 1],
  484. ['is_del', '=', 0],
  485. ['refund_status', '=', 0],
  486. ['is_lb', '=', 1],
  487. ['add_time', '>=', $todayStart],
  488. ['add_time', '<=', $todayEnd]
  489. ])->sum('pay_price');
  490. if ($totalGiftAmount <= 0) {
  491. return '今日无礼包订单金额';
  492. }
  493. // 获取所有分红比例大于0的等级
  494. /** @var SystemUserLevelServices $systemLevelServices */
  495. $systemLevelServices = app()->make(SystemUserLevelServices::class);
  496. $levels = $systemLevelServices->getList([
  497. ['is_del', '=', 0],
  498. ['is_show', '=', 1],
  499. ['radio', '>', 0]
  500. ]);
  501. if (!$levels) {
  502. return '无分红等级';
  503. }
  504. /** @var UserServices $userServices */
  505. $userServices = app()->make(UserServices::class);
  506. /** @var UserBrokerageServices $brokerageServices */
  507. $brokerageServices = app()->make(UserBrokerageServices::class);
  508. $totalDivided = 0;
  509. foreach ($levels as $level) {
  510. $radio = $level['radio'];
  511. $levelId = $level['id'];
  512. // 计算该等级能分到的总金额
  513. $levelTotalAmount = bcmul((string)$totalGiftAmount, bcdiv((string)$radio, '100', 4), 2);
  514. if ($levelTotalAmount <= 0) {
  515. continue;
  516. }
  517. // 获取该等级的用户数量
  518. $users = $userServices->getColumn([
  519. ['level', '=', $levelId],
  520. ['status', '=', 1],
  521. ['is_del', '=', 0]
  522. ], 'uid', 'uid');
  523. if (!$users) {
  524. continue;
  525. }
  526. $userCount = count($users);
  527. // 计算每个用户能分到的金额
  528. $userAmount = bcdiv($levelTotalAmount, (string)$userCount, 2);
  529. if ($userAmount <= 0) {
  530. continue;
  531. }
  532. // 为该等级的每个用户分红
  533. foreach ($users as $uid) {
  534. $userInfo = $userServices->getUserInfo($uid);
  535. if (!$userInfo) {
  536. continue;
  537. }
  538. $currentBrokerage = $userInfo['brokerage_price'] ?? 0;
  539. $newBrokerage = bcadd((string)$currentBrokerage, $userAmount, 2);
  540. // 更新用户佣金
  541. $userServices->update($uid, ['brokerage_price' => $newBrokerage], 'uid');
  542. // 添加佣金记录
  543. $brokerageServices->income('level_dividend', $uid, [
  544. 'number' => $userAmount
  545. ], $newBrokerage, 0);
  546. $totalDivided = bcadd((string)$totalDivided, $userAmount, 2);
  547. }
  548. }
  549. return '分红完成,共分红金额:' . $totalDivided . '元';
  550. }
  551. }