作者 何书鹏

经销商提现管理

... ... @@ -19,8 +19,8 @@ class Finish
if($item['dealer_id'] > 0){
$dealer = \app\api\model\Dealer::get($item['dealer_id']);
if($dealer){
// 记录 UserCommissionLog
\app\api\model\DealerMoneyLog::doAdd($dealer, $item['goods_price']*$item['goods_num'], 'order', $item['id'], 1);
// 记录经销商余额
\app\admin\model\dealer\DealerMoneyLog::doAdd($dealer, $item['goods_price']*$item['goods_num'], 'order', $item['id'], 1);
}
}
}
... ...
... ... @@ -53,15 +53,15 @@ class DealerMoneyLog extends Model
$oper = $adminAuth->getUserInfo();
}
if ($oper) {
// 经销商
$dealer = [];
// 经销商登录
$oper_dealer = [];
$group_id_arr = array_column($adminAuth->getGroups(), 'group_id');
if(!in_array(1,$group_id_arr) && in_array(2,$group_id_arr)){
$dealer = \app\admin\model\dealer\Dealer::where('admin_id',$oper['id'])->find();
$oper_dealer = \app\admin\model\dealer\Dealer::where('admin_id',$oper['id'])->find();
}
if($dealer){
if($oper_dealer){
$oper_type = 'dealer';
$oper_id = $dealer['id'];
$oper_id = $oper_dealer['id'];
}else{
$oper_type = 'admin';
$oper_id = $oper['id'];
... ...
<?php
namespace app\api\model;
use think\Model;
use addons\shopro\exception\Exception;
use addons\shopro\model\User;
use think\Db;
use app\admin\library\Auth as AdminAuth;
/**
* 经销商余额日志
*/
class DealerMoneyLog extends Model
{
// 表名,不含前缀
protected $name = 'dealer_money_log';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
protected $hidden = ['deletetime'];
// 追加属性
protected $append = [
'type_name',
];
public static $typeAll = [
// money
'order' => ['code' => 'order', 'name' => '下单'],
'cash' => ['code' => 'cash', 'name' => '提现'],
'cash_error' => ['code' => 'cash_error', 'name' => '提现驳回'],
];
public function scopeAdd($query)
{
return $query->where('money', '>', 0);
}
public function scopeToday($query)
{
return $query->where('money', '>', 0)->whereTime('createtime','today');
}
public function scopeSeven($query)
{
return $query->where('money', '>', 0)->whereTime('createtime','-7 days');
}
public static function doAdd($dealer, $money, $type, $item_id, $is_add = 0)
{
// 自动获取操作人
if (strpos(request()->url(), 'api') !== false) {
// 用户
$oper = User::info();
$oper_type = 'user';
$oper_id = $oper ? $oper->id : $dealer['id'];
} else {
$adminAuth = AdminAuth::instance(); // 没有登录返回的还是这个类实例
$oper = null;
if ($adminAuth){
$oper = $adminAuth->getUserInfo();
}
if ($oper) {
$oper_type = 'admin';
$oper_id = $oper['id'];
} else {
$oper_type = 'system';
$oper_id = 0;
}
}
$self = self::create([
"dealer_id" => $dealer->id,
"money" => $is_add ? $money : -$money, // 符号直接存到记录里面
"type" => $type,
"item_id" => $item_id,
"oper_type" => $oper_type,
"oper_id" => $oper_id
]);
return $self;
}
public static function getList($status = 'all')
{
$user = User::info();
$walletLogs = new self();
if ($status != 'all') {
$walletLogs = $walletLogs->{$status}();
}
$walletLogs = $walletLogs->where(['user_id' => $user->id])
->order('id', 'DESC')->paginate(10);
foreach ($walletLogs as $w) {
$w->createtime = date('Y/m/d',$w->createtime);
switch ($w['type']) {
case 'package_commission':
case 'order_commssion':
$oper = \addons\shopro\model\User::get($w->oper_id);
$w->avatar = $oper['avatar'] ?? '';
$w->nickname = $oper['nickname'] ?? '';
break;
case 'cash':
case 'cash_error':
$w->avatar = $user->avatar;
$w->nickname = $user->nickname;
break;
}
}
return $walletLogs;
}
public static function getTypeName($type)
{
return isset(self::$typeAll[$type]) ? self::$typeAll[$type]['name'] : '';
}
public function getTypeNameAttr($value, $data)
{
return self::getTypeName($data['type']);
}
}