parent
f8ca21913e
commit
85777c314e
@ -0,0 +1,53 @@ |
||||
<?php |
||||
|
||||
namespace app\common\service; |
||||
|
||||
use think\Cache; |
||||
use think\Model; |
||||
use app\common\model\User; |
||||
use app\admin\model\transaction\Record; |
||||
/** |
||||
* 订单服务服务 |
||||
*/ |
||||
class OrderService |
||||
{ |
||||
|
||||
/** |
||||
* 用户佣金变化 |
||||
* [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; |
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue