123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace app\services\out;
- use app\services\BaseServices;
- use app\dao\user\UserDao;
- use app\services\user\UserBillServices;
- use app\services\user\UserMoneyServices;
- use crmeb\exceptions\AdminException;
- class UserServices extends BaseServices
- {
-
- public function __construct(UserDao $dao)
- {
- $this->dao = $dao;
- }
-
- public function getUserInfo(int $uid, $field = '*')
- {
- if (is_string($field)) $field = explode(',', $field);
- $info = $this->dao->getOutOne($uid, $field);
- $info = $info ? $info->toArray() : [];
- return $info;
- }
-
- public function updateInfo(int $id, array $data)
- {
- $user = $this->getUserInfo($id);
- if (!$user) {
- throw new AdminException('数据不存在!');
- }
- $res1 = false;
- $res2 = false;
- $edit = array();
- if (isset($data['is_other']) && $data['is_other']) {
- if ($data['money_status'] && $data['money']) {
-
- $userMoneyServices = app()->make(UserMoneyServices::class);
- if ($data['money_status'] == 1) {
- $edit['now_money'] = bcadd($user['now_money'], $data['money'], 2);
- $res1 = $userMoneyServices->income('system_add', $user['uid'], $data['money'], $edit['now_money'], $data['adminId'] ?? 0);
- } else if ($data['money_status'] == 2) {
- if ($user['now_money'] > $data['money']) {
- $edit['now_money'] = bcsub($user['now_money'], $data['money'], 2);
- } else {
- $edit['now_money'] = 0;
- $data['money'] = $user['now_money'];
- }
- $res1 = $userMoneyServices->income('system_sub', $user['uid'], $data['money'], $edit['now_money'], $data['adminId'] ?? 0);
- }
- } else {
- $res1 = true;
- }
- if ($data['integration_status'] && $data['integration']) {
- $integral_data = ['link_id' => $data['adminId'] ?? 0, 'number' => $data['integration'], 'balance' => $user['integral']];
-
- $userBill = app()->make(UserBillServices::class);
- if ($data['integration_status'] == 1) {
- $edit['integral'] = bcadd($user['integral'], $data['integration'], 2);
- $integral_data['title'] = '系统增加积分';
- $integral_data['mark'] = '系统增加了' . floatval($data['integration']) . '积分';
- $type = 'system_add';
- $pm = 1;
- } else if ($data['integration_status'] == 2) {
- $edit['integral'] = bcsub($user['integral'], $data['integration'], 2);
- $integral_data['title'] = '系统减少积分';
- $integral_data['mark'] = '系统扣除了' . floatval($data['integration']) . '积分';
- $type = 'system_sub';
- $pm = 0;
- }
- $res2 = $userBill->incomeIntegral($user['uid'], $type, $integral_data, $pm);
- } else {
- $res2 = true;
- }
- } else {
- $res2 = $res1 = true;
- }
-
- if (!isset($data['is_other']) || !$data['is_other']) {
- $edit['real_name'] = $data['real_name'];
- $edit['card_id'] = $data['card_id'];
- $edit['birthday'] = strtotime($data['birthday']);
- $edit['phone'] = $data['phone'];
- $edit['addres'] = $data['addres'];
- }
- if ($edit) $res3 = $this->dao->update($id, $edit);
- else $res3 = true;
- if ($res1 && $res2 && $res3)
- return true;
- else throw new AdminException('修改失败');
- }
- }
|