2023-12-27 14:06:33 +08:00
|
|
|
|
<?php
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
|
|
|
|
// | 开源版本可自由商用,可去除界面版权logo
|
|
|
|
|
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
|
|
|
|
// | github下载:https://github.com/likeshop-github/likeadmin
|
|
|
|
|
// | 访问官网:https://www.likeadmin.cn
|
|
|
|
|
// | likeadmin团队 版权所有 拥有最终解释权
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
// | author: likeadminTeam
|
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
namespace app\adminapi\logic\user;
|
|
|
|
|
|
|
|
|
|
use app\common\enum\user\AccountLogEnum;
|
|
|
|
|
use app\common\enum\user\UserTerminalEnum;
|
|
|
|
|
use app\common\logic\AccountLogLogic;
|
|
|
|
|
use app\common\logic\BaseLogic;
|
|
|
|
|
use app\common\model\contract\Contract;
|
|
|
|
|
use app\common\model\dict\DictData;
|
|
|
|
|
use app\common\model\user\User;
|
|
|
|
|
use app\common\service\ConfigService;
|
|
|
|
|
use think\facade\Config;
|
|
|
|
|
use think\facade\Db;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户逻辑层
|
|
|
|
|
* Class UserLogic
|
|
|
|
|
* @package app\adminapi\logic\user
|
|
|
|
|
*/
|
|
|
|
|
class UserLogic extends BaseLogic
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 用户详情
|
|
|
|
|
* @param int $userId
|
|
|
|
|
* @return array
|
|
|
|
|
* @author 段誉
|
|
|
|
|
* @date 2022/9/22 16:32
|
|
|
|
|
*/
|
|
|
|
|
public static function detail(int $userId): array
|
|
|
|
|
{
|
|
|
|
|
// $field = [
|
|
|
|
|
// 'id', 'sn', 'account', 'nickname', 'avatar', 'real_name',
|
|
|
|
|
// 'sex', 'mobile', 'create_time', 'login_time', 'channel',
|
|
|
|
|
// 'user_money',
|
|
|
|
|
// ];
|
|
|
|
|
|
|
|
|
|
$user = User::where(['id' => $userId])
|
|
|
|
|
->findOrEmpty();
|
|
|
|
|
|
|
|
|
|
$user['channel'] = UserTerminalEnum::getTermInalDesc($user['channel']);
|
|
|
|
|
// $user->sex = $user->getData('sex');
|
|
|
|
|
$user['qualification']=json_decode($user->qualification,true);
|
2023-12-29 18:49:41 +08:00
|
|
|
|
$user['deposit_date'] = date('Y-m-d', $user['deposit_date']);
|
2023-12-27 14:06:33 +08:00
|
|
|
|
if($user->is_contract==1){
|
|
|
|
|
$user['contract']=Contract::where(['type'=>2,'party_b'=>$userId])->with(['party_a_info','contractType'])->find();
|
|
|
|
|
}
|
|
|
|
|
return $user->toArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 更新用户信息
|
|
|
|
|
* @param array $params
|
|
|
|
|
* @return User
|
|
|
|
|
* @author 段誉
|
|
|
|
|
* @date 2022/9/22 16:38
|
|
|
|
|
*/
|
|
|
|
|
public static function setUserInfo(array $params)
|
|
|
|
|
{
|
|
|
|
|
return User::update([
|
|
|
|
|
'id' => $params['id'],
|
2024-01-12 09:46:19 +08:00
|
|
|
|
'nickname' => $params['nickname'],
|
|
|
|
|
'account' => $params['account'],
|
|
|
|
|
'mobile' => $params['account'],
|
|
|
|
|
'id_card' => $params['id_card'],
|
|
|
|
|
'channel' => 0,
|
|
|
|
|
'sex' => $params['sex'],
|
|
|
|
|
'province' => $params['province'],
|
|
|
|
|
'city' => $params['city'],
|
|
|
|
|
'area' => $params['area'],
|
|
|
|
|
'street' => $params['street'],
|
|
|
|
|
'village' => $params['village'],
|
|
|
|
|
'brigade' => $params['brigade'],
|
|
|
|
|
'address' => $params['address'],
|
|
|
|
|
'qualification' => json_encode($params['qualification']),
|
|
|
|
|
'company_id' => $params['company_id'],
|
|
|
|
|
'deposit' => $params['deposit'],
|
|
|
|
|
'deposit_date' => strtotime($params['deposit_date']),
|
|
|
|
|
'user_information_count' => $params['user_information_count'],
|
|
|
|
|
'register_num' => $params['register_num'],
|
|
|
|
|
'merchant_num' => $params['merchant_num'],
|
|
|
|
|
'trade_amount' => $params['trade_amount'],
|
2023-12-27 14:06:33 +08:00
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-12 10:51:12 +08:00
|
|
|
|
public static function editUser($params)
|
|
|
|
|
{
|
|
|
|
|
return User::update([
|
|
|
|
|
'id' => $params['id'],
|
|
|
|
|
'nickname' => $params['nickname'],
|
|
|
|
|
'account' => $params['account'],
|
|
|
|
|
'mobile' => $params['account'],
|
|
|
|
|
'id_card' => $params['id_card'],
|
2024-01-16 17:19:30 +08:00
|
|
|
|
'avatar' => $params['avatar'],
|
2024-01-12 10:51:12 +08:00
|
|
|
|
'channel' => 0,
|
|
|
|
|
'sex' => $params['sex'],
|
|
|
|
|
'province' => $params['province'],
|
|
|
|
|
'city' => $params['city'],
|
|
|
|
|
'area' => $params['area'],
|
|
|
|
|
'street' => $params['street'],
|
|
|
|
|
'village' => $params['village'],
|
|
|
|
|
'brigade' => $params['brigade'],
|
|
|
|
|
'address' => $params['address'],
|
|
|
|
|
'qualification' => json_encode($params['qualification']),
|
|
|
|
|
'company_id' => $params['company_id'],
|
|
|
|
|
'deposit' => $params['deposit'],
|
|
|
|
|
'deposit_date' => strtotime($params['deposit_date']),
|
|
|
|
|
'user_information_count' => $params['user_information_count'],
|
|
|
|
|
'register_num' => $params['register_num'],
|
|
|
|
|
'merchant_num' => $params['merchant_num'],
|
|
|
|
|
'trade_amount' => $params['trade_amount'],
|
2024-01-19 14:35:51 +08:00
|
|
|
|
'group_id' => $params['group_id'],
|
2024-01-12 13:50:48 +08:00
|
|
|
|
'update_time' => time()
|
2024-01-12 10:51:12 +08:00
|
|
|
|
]);
|
|
|
|
|
}
|
2023-12-27 14:06:33 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 调整用户余额
|
|
|
|
|
* @param array $params
|
|
|
|
|
* @return bool|string
|
|
|
|
|
* @author 段誉
|
|
|
|
|
* @date 2023/2/23 14:25
|
|
|
|
|
*/
|
|
|
|
|
public static function adjustUserMoney(array $params)
|
|
|
|
|
{
|
|
|
|
|
Db::startTrans();
|
|
|
|
|
try {
|
|
|
|
|
$user = User::find($params['user_id']);
|
|
|
|
|
if (AccountLogEnum::INC == $params['action']) {
|
|
|
|
|
//调整可用余额
|
|
|
|
|
$user->user_money += $params['num'];
|
|
|
|
|
$user->save();
|
|
|
|
|
//记录日志
|
|
|
|
|
AccountLogLogic::add(
|
|
|
|
|
$user->id,
|
|
|
|
|
AccountLogEnum::UM_INC_ADMIN,
|
|
|
|
|
AccountLogEnum::INC,
|
|
|
|
|
$params['num'],
|
|
|
|
|
'',
|
|
|
|
|
$params['remark'] ?? ''
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$user->user_money -= $params['num'];
|
|
|
|
|
$user->save();
|
|
|
|
|
//记录日志
|
|
|
|
|
AccountLogLogic::add(
|
|
|
|
|
$user->id,
|
|
|
|
|
AccountLogEnum::UM_DEC_ADMIN,
|
|
|
|
|
AccountLogEnum::DEC,
|
|
|
|
|
$params['num'],
|
|
|
|
|
'',
|
|
|
|
|
$params['remark'] ?? ''
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Db::commit();
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Db::rollback();
|
|
|
|
|
return $e->getMessage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function addUser($params)
|
|
|
|
|
{
|
|
|
|
|
// 手机号已被使用
|
|
|
|
|
$mobileUser = User::where(['account' => $params['account']])->find();
|
|
|
|
|
if (!empty($mobileUser)) {
|
|
|
|
|
self::setError('手机号已被注册');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-12-29 17:43:07 +08:00
|
|
|
|
// $count = User::where('company_id', $params['company_id'])->count();
|
|
|
|
|
// $value = DictData::where('id', 28)->value('value');
|
|
|
|
|
// if ($count >= $value) {
|
|
|
|
|
// self::setError('你创建的账号已达上限');
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
2023-12-27 14:06:33 +08:00
|
|
|
|
$group_id = $params['group_id'];
|
|
|
|
|
// 每个公司市场部长只有1个
|
2024-01-12 09:46:19 +08:00
|
|
|
|
// if($group_id == 16) {
|
|
|
|
|
// $marketManger = User::where(['group_id' =>$group_id,'company_id'=>$params['company_id']])->findOrEmpty();
|
|
|
|
|
// if (!$marketManger->isEmpty()) {
|
|
|
|
|
// self::setError('公司已创建市场部长账号');
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2023-12-27 14:06:33 +08:00
|
|
|
|
// 每个公司服务部长只有1个
|
2024-01-12 09:46:19 +08:00
|
|
|
|
// if($group_id == 14) {
|
|
|
|
|
// $marketManger = User::where(['group_id' =>$group_id,'company_id'=>$params['company_id']])->findOrEmpty();
|
|
|
|
|
// if (!$marketManger->isEmpty()) {
|
|
|
|
|
// self::setError('公司已创建服务部长账号');
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2023-12-27 14:06:33 +08:00
|
|
|
|
$userSn = User::createUserSn();
|
|
|
|
|
$passwordSalt = Config::get('project.unique_identification');
|
|
|
|
|
$password = create_password(123456, $passwordSalt);
|
|
|
|
|
if ($params['avatar'] != '') {
|
|
|
|
|
$avatar = $params['avatar'];
|
|
|
|
|
} else {
|
|
|
|
|
$avatar = ConfigService::get('default_image', 'user_avatar');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
User::create([
|
|
|
|
|
'sn' => $userSn,
|
|
|
|
|
'avatar' => $avatar,
|
|
|
|
|
'is_captain' => $group_id == 2? 1: 0,
|
|
|
|
|
'nickname' => $params['nickname'],
|
|
|
|
|
'account' => $params['account'],
|
|
|
|
|
'mobile' => $params['account'],
|
|
|
|
|
'id_card' => $params['id_card'],
|
|
|
|
|
'password' => $password,
|
|
|
|
|
'channel' => 0,
|
|
|
|
|
'sex' => $params['sex'],
|
|
|
|
|
'province' => $params['province'],
|
|
|
|
|
'city' => $params['city'],
|
|
|
|
|
'area' => $params['area'],
|
|
|
|
|
'street' => $params['street'],
|
|
|
|
|
'village' => $params['village'],
|
|
|
|
|
'brigade' => $params['brigade'],
|
|
|
|
|
'address' => $params['address'],
|
|
|
|
|
'qualification' => json_encode($params['qualification']),
|
|
|
|
|
'company_id' => $params['company_id'],
|
|
|
|
|
'group_id' => $group_id,
|
2023-12-29 17:43:07 +08:00
|
|
|
|
'deposit' => $params['deposit'],
|
|
|
|
|
'deposit_date' => strtotime($params['deposit_date']),
|
|
|
|
|
'user_information_count' => $params['user_information_count'],
|
2024-01-12 09:46:19 +08:00
|
|
|
|
'register_num' => $params['register_num'],
|
|
|
|
|
'merchant_num' => $params['merchant_num'],
|
|
|
|
|
'trade_amount' => $params['trade_amount'],
|
|
|
|
|
'invite_code' => generate_rand_code(10),
|
2023-12-27 14:06:33 +08:00
|
|
|
|
]);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 14:35:51 +08:00
|
|
|
|
public static function getUserByInviteCode($inviteCode)
|
|
|
|
|
{
|
|
|
|
|
return User::where('invite_code', $inviteCode)->findOrEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getUser($where)
|
|
|
|
|
{
|
|
|
|
|
return User::where($where)->findOrEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-20 11:42:46 +08:00
|
|
|
|
public static function shareProfit($bridgeUser, $villageUser, $streetUser, $orderMoney, $orderNo)
|
2024-01-19 14:35:51 +08:00
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
Db::startTrans();
|
2024-01-20 11:42:46 +08:00
|
|
|
|
|
2024-01-19 14:35:51 +08:00
|
|
|
|
$proportion = 0.03; // 分润比例
|
2024-01-20 11:42:46 +08:00
|
|
|
|
|
|
|
|
|
if (!empty($bridgeUser)) {
|
|
|
|
|
// 小队
|
|
|
|
|
self::userProfit($bridgeUser, $orderMoney, $proportion, $orderNo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($villageUser)) {
|
|
|
|
|
// 村
|
|
|
|
|
self::userProfit($villageUser, $orderMoney, $proportion, $orderNo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($streetUser)) {
|
|
|
|
|
// 镇
|
|
|
|
|
$proportion = 0.01; // 分润比例
|
|
|
|
|
self::userProfit($streetUser, $orderMoney, $proportion, $orderNo);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 14:35:51 +08:00
|
|
|
|
Db::commit();
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Db::rollback();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-20 11:42:46 +08:00
|
|
|
|
public static function userProfit($user, $orderMoney, $proportion, $orderNo)
|
2024-01-19 14:35:51 +08:00
|
|
|
|
{
|
2024-01-20 11:42:46 +08:00
|
|
|
|
$money = bcdiv(bcmul($orderMoney, $proportion, 2), 100, 2);
|
|
|
|
|
$arr = [$user['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $money, $orderNo, '平台推广' . '获得劳务费' . $money . '元', ['company_id' => 0, 'proportion' => $proportion], 1];
|
2024-01-19 14:35:51 +08:00
|
|
|
|
self::addUserAccountLog($arr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**成员分润
|
|
|
|
|
* @param $data
|
|
|
|
|
*/
|
|
|
|
|
private static function addUserAccountLog($data)
|
|
|
|
|
{
|
|
|
|
|
User::where('id', $data[0])->update(['user_money'=>Db::raw('user_money+' . $data[3])]);
|
|
|
|
|
return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]);
|
|
|
|
|
}
|
2024-01-20 11:42:46 +08:00
|
|
|
|
|
|
|
|
|
public static function firstOrderLog($userIds, $orderMoney, $orderNo)
|
|
|
|
|
{
|
|
|
|
|
foreach ($userIds as $userId) {
|
|
|
|
|
Db::name('user_invite_first_order_log')->insert(['user_id' => $userId, 'order_money' => $orderMoney, 'order_no' => $orderNo, 'create_time' => time()]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-27 14:06:33 +08:00
|
|
|
|
}
|