You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
53 lines
1.2 KiB
<?php
|
|
|
|
namespace app\common\service;
|
|
|
|
use think\Cache;
|
|
use think\Model;
|
|
use app\common\model\User;
|
|
use app\admin\model\transaction\Record;
|
|
/**
|
|
* 用户服务
|
|
*/
|
|
class UserService
|
|
{
|
|
|
|
/**
|
|
* 用户佣金变化
|
|
* [userCommission description]
|
|
* @param [type] $type [description]
|
|
* @param [type] $user [description]
|
|
* @param [type] $item_id [description]
|
|
* @param [type] $amount [description]
|
|
* @return [type] [description]
|
|
*/
|
|
public function userCommission($type, $user, $item_id, $amount){
|
|
$pidUser = User::where('id', $user['pid'])->find();
|
|
if (!$pidUser) {
|
|
return false;
|
|
}
|
|
$inData = [
|
|
'user_id' => $pidUser['id'],
|
|
'child_id' => $user['id'],
|
|
'item_id' => $item_id,
|
|
'amount' => $amount,
|
|
'type' => $type,
|
|
];
|
|
$ret = Record::create($inData);
|
|
if ($ret === false) {
|
|
return false;
|
|
}
|
|
$userData = [
|
|
"available_commission_amount" => $pidUser['available_commission_amount'] + $amount,
|
|
"updatetime" => time(),
|
|
];
|
|
if (in_array($type, [0,1])) {
|
|
$userData['total_commission_amount'] = $pidUser['total_commission_amount'] + $amount;
|
|
}
|
|
$ret = User::where('id', $pidUser['id'])->update($userData);
|
|
|
|
return $ret;
|
|
}
|
|
|
|
|
|
} |