init
- 框架初始化 - 安装插件 - 修复PHP8.4报错
This commit is contained in:
250
application/admin/controller/shopro/commission/Agent.php
Normal file
250
application/admin/controller/shopro/commission/Agent.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro\commission;
|
||||
|
||||
use app\admin\controller\shopro\Common;
|
||||
use app\admin\model\shopro\commission\Agent as AgentModel;
|
||||
use app\admin\model\shopro\user\User as UserModel;
|
||||
use app\admin\model\shopro\commission\Log as LogModel;
|
||||
use app\admin\model\shopro\commission\Level as LevelModel;
|
||||
use addons\shopro\service\commission\Agent as AgentService;
|
||||
use think\Db;
|
||||
|
||||
class Agent extends Common
|
||||
{
|
||||
protected $noNeedRight = ['select'];
|
||||
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new AgentModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$list = $this->model->sheepFilter()->with(['user.parent_user', 'level_info', 'level_status_info', 'upgrade_level'])->paginate($this->request->param('list_rows', 10));
|
||||
|
||||
$this->success('分销商列表', null, $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*
|
||||
* @param $id
|
||||
*/
|
||||
public function detail($id)
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$detail = $this->model->with(['user.parent_user', 'level_info', 'level_status_info', 'upgrade_level'])->where('user_id', $id)->find();
|
||||
if (!$detail) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
$this->success('分销商详情', null, $detail);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 团队
|
||||
*
|
||||
* @param $id
|
||||
*/
|
||||
public function team($id)
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$detail = $this->model->with(['user.parent_user', 'level_info'])->where('user_id', $id)->find();
|
||||
if (!$detail) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
$detail->agent_team = AgentModel::hasWhere('user', function ($query) use ($detail) {
|
||||
return $query->where('parent_user_id', $detail->user_id);
|
||||
})->with(['user', 'level_info'])->select();
|
||||
$this->success('分销商详情', null, $detail);
|
||||
}
|
||||
|
||||
// 选择分销商
|
||||
public function select()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$data = $this->model->sheepFilter()->with(['user', 'level_info', 'level_status_info', 'upgrade_level'])
|
||||
->paginate($this->request->param('list_rows', 10));
|
||||
|
||||
$this->success('选择分销商', null, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param $id
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$params = $this->request->only(['status', 'upgrade_lock', 'level_status', 'level', 'apply_info']);
|
||||
|
||||
$result = Db::transaction(function () use ($id, $params) {
|
||||
$row = $this->model->with(['user', 'level_info', 'level_status_info', 'upgrade_level'])->where('user_id', $id)->find();
|
||||
if (!$row) {
|
||||
$this->error('未找到该分销商');
|
||||
}
|
||||
|
||||
foreach ($params as $field => $value) {
|
||||
switch ($field) {
|
||||
case 'status': // 修改状态
|
||||
return $this->changeStatus($row, $value);
|
||||
break;
|
||||
case 'level_status': // 审核等级
|
||||
return $this->changeLevelStatus($row, $value);
|
||||
break;
|
||||
case 'level': // 修改等级
|
||||
return $this->changeLevel($row, $value);
|
||||
break;
|
||||
default:
|
||||
return $row->save([$field => $value]);
|
||||
}
|
||||
}
|
||||
});
|
||||
if ($result) {
|
||||
$this->success('更新成功', null, $result);
|
||||
} else {
|
||||
$this->error('更新失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 修改状态
|
||||
private function changeStatus($row, $value)
|
||||
{
|
||||
$result = $row->save(['status' => $value]);
|
||||
if ($result) {
|
||||
LogModel::add($row->user_id, 'agent', ['type' => 'status', 'value' => $value]);
|
||||
(new AgentService($row->user_id))->createAsyncAgentUpgrade();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 审核等级
|
||||
private function changeLevelStatus($row, $value)
|
||||
{
|
||||
if ($row->level_status == 0 && $value > 0) {
|
||||
$this->error('非法操作');
|
||||
}
|
||||
|
||||
if ($value == 0) { // 拒绝操作
|
||||
return $row->save(['level_status' => 0]);
|
||||
} else { // 同意操作
|
||||
if ($row->upgrade_level) {
|
||||
$result = $row->save(['level_status' => 0, 'level' => $row->upgrade_level->level]);
|
||||
if ($result) {
|
||||
LogModel::add($row->user_id, 'agent', ['type' => 'level', 'level' => $row->upgrade_level]);
|
||||
(new AgentService($row->user_id))->createAsyncAgentUpgrade();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 修改等级
|
||||
private function changeLevel($row, $value)
|
||||
{
|
||||
$level = LevelModel::find($value);
|
||||
if ($level) {
|
||||
$result = $row->save(['level' => $level->level]);
|
||||
if ($result) {
|
||||
LogModel::add($row->user_id, 'agent', ['type' => 'level', 'level' => $level]);
|
||||
(new AgentService($row->user_id))->createAsyncAgentUpgrade();
|
||||
}
|
||||
return $result;
|
||||
} else {
|
||||
$this->error('未找到该等级');
|
||||
}
|
||||
}
|
||||
|
||||
// 更换推荐人
|
||||
public function changeParentUser($id)
|
||||
{
|
||||
$userAgent = new AgentService($id);
|
||||
|
||||
if (!$userAgent->user) {
|
||||
$this->error('未找到该用户');
|
||||
}
|
||||
|
||||
$parentUserId = $this->request->param('parent_user_id', 0);
|
||||
|
||||
// 更换推荐人检查
|
||||
if ($parentUserId != 0) {
|
||||
$parentAgent = new AgentService($parentUserId);
|
||||
if (!$parentAgent->isAgentAvaliable()) {
|
||||
$this->error('选中用户暂未成为分销商,不能成为推荐人');
|
||||
}
|
||||
if (!$this->checkChangeParentAgent($id, $parentUserId)) {
|
||||
$this->error('不能绑定该上级');
|
||||
}
|
||||
LogModel::add($parentUserId, 'share', ['user' => $userAgent->user]);
|
||||
|
||||
if ($userAgent->isAgentAvaliable()) {
|
||||
LogModel::add($id, 'bind', ['user' => $parentAgent->user ?? NULL]);
|
||||
}
|
||||
}
|
||||
|
||||
$lastParentUserId = $userAgent->user->parent_user_id;
|
||||
|
||||
$userAgent->user->parent_user_id = $parentUserId;
|
||||
$userAgent->user->save();
|
||||
|
||||
if ($lastParentUserId > 0) {
|
||||
$userAgent->createAsyncAgentUpgrade($lastParentUserId);
|
||||
}
|
||||
|
||||
if ($parentUserId > 0) {
|
||||
$userAgent->createAsyncAgentUpgrade($parentUserId);
|
||||
}
|
||||
$this->success('绑定成功');
|
||||
}
|
||||
|
||||
// 递归往上找推荐人,防止出现推荐循环
|
||||
private function checkChangeParentAgent($userId, $parentUserId)
|
||||
{
|
||||
if ($userId == $parentUserId) {
|
||||
|
||||
$this->error('推荐人不能是本人');
|
||||
}
|
||||
if ($parentUserId == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$parentAgent = UserModel::find($parentUserId);
|
||||
|
||||
if ($parentAgent) {
|
||||
if ($parentAgent->parent_user_id == $userId) {
|
||||
$this->error("已选中分销商的上级团队中已存在该用户");
|
||||
}
|
||||
if ($parentAgent->parent_user_id == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return $this->checkChangeParentAgent($userId, $parentAgent->parent_user_id);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
89
application/admin/controller/shopro/commission/Goods.php
Normal file
89
application/admin/controller/shopro/commission/Goods.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro\commission;
|
||||
|
||||
use app\admin\controller\shopro\Common;
|
||||
use app\admin\model\shopro\commission\CommissionGoods as CommissionGoodsModel;
|
||||
use app\admin\model\shopro\goods\Goods as GoodsModel;
|
||||
use think\Db;
|
||||
|
||||
class Goods extends Common
|
||||
{
|
||||
protected $model = null;
|
||||
protected $goodsModel;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new CommissionGoodsModel();
|
||||
$this->goodsModel = new GoodsModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$data = $this->goodsModel->sheepFilter()->with('commission_goods')->paginate($this->request->param('list_rows', 10));
|
||||
$this->success('分销商品列表', null, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*
|
||||
* @param $id
|
||||
*/
|
||||
public function detail($id)
|
||||
{
|
||||
$goodsList = collection(GoodsModel::with(['commission_goods'])->whereIn('id', $id)->select())->each(function ($goods) {
|
||||
$goods->skus = $goods->skus;
|
||||
$goods->sku_prices = $goods->sku_prices;
|
||||
});
|
||||
|
||||
$config = sheep_config('shop.commission');
|
||||
$this->success('分销商品详情', null, [
|
||||
'goods' => $goodsList,
|
||||
'config' => $config
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置佣金(支持批量)
|
||||
*
|
||||
* @param $id
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
// 接受全部参数
|
||||
$params = $this->request->only(['status', 'self_rules', 'commission_order_status', 'commission_config', 'commission_rules']);
|
||||
|
||||
$result = Db::transaction(function () use ($id, $params) {
|
||||
$count = 0;
|
||||
$ids = explode(',', $id);
|
||||
|
||||
foreach ($ids as $goods_id) {
|
||||
if ($row = $this->model->get($goods_id)) {
|
||||
$row->save($params);
|
||||
} else {
|
||||
$model = new CommissionGoodsModel();
|
||||
$params['goods_id'] = $goods_id;
|
||||
$model->save($params);
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
|
||||
return $count;
|
||||
});
|
||||
|
||||
if ($result) {
|
||||
$this->success('更新成功', null, $result);
|
||||
} else {
|
||||
$this->error('更新失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
144
application/admin/controller/shopro/commission/Level.php
Normal file
144
application/admin/controller/shopro/commission/Level.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro\commission;
|
||||
|
||||
use app\admin\controller\shopro\Common;
|
||||
use app\admin\model\shopro\commission\Level as LevelModel;
|
||||
use think\Db;
|
||||
|
||||
class Level extends Common
|
||||
{
|
||||
|
||||
protected $noNeedRight = ['select'];
|
||||
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new LevelModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$defaultLevel = $this->model->find(1);
|
||||
if (!$defaultLevel) {
|
||||
$this->model->save([
|
||||
'name' => '默认等级',
|
||||
'level' => 1,
|
||||
'commission_rules' => [
|
||||
'commission_1' => '0.00',
|
||||
'commission_2' => '0.00',
|
||||
'commission_3' => '0.00'
|
||||
]
|
||||
]);
|
||||
}
|
||||
$list = $this->model->sheepFilter()->select();
|
||||
|
||||
$this->success('全部等级', null, $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$params = $this->request->only(['name', 'level', 'image', 'commission_rules', 'upgrade_type', 'upgrade_rules']);
|
||||
|
||||
$this->model->save($params);
|
||||
|
||||
$this->success('保存成功', null, $this->model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param $id
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch('add');
|
||||
}
|
||||
|
||||
$params = $this->request->only(['level', 'name', 'image', 'commission_rules', 'upgrade_type', 'upgrade_rules']);
|
||||
|
||||
$result = Db::transaction(function () use ($id, $params) {
|
||||
|
||||
$this->svalidate($params);
|
||||
|
||||
$data = $this->model->where('level', $id)->find();
|
||||
if (!$data) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
return $data->save($params);
|
||||
});
|
||||
|
||||
if ($result) {
|
||||
$this->success('更新成功', null, $result);
|
||||
} else {
|
||||
$this->error('更新失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*
|
||||
* @param $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function detail($id)
|
||||
{
|
||||
$detail = $this->model->get($id);
|
||||
if (!$detail) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
$this->success('等级详情', null, $detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if (empty($id)) {
|
||||
$this->error(__('Parameter %s can not be empty', 'id'));
|
||||
}
|
||||
|
||||
$result = Db::transaction(function () use ($id) {
|
||||
return $this->model->where('level', $id)->delete();
|
||||
});
|
||||
|
||||
if ($result) {
|
||||
$this->success('删除成功', null, $result);
|
||||
} else {
|
||||
$this->error(__('No rows were deleted'));
|
||||
}
|
||||
}
|
||||
|
||||
// 选择分销商等级
|
||||
public function select()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$data = $this->model->sheepFilter()->field('level, name, image, commission_rules')->select();
|
||||
$this->success('选择等级', null, $data);
|
||||
}
|
||||
}
|
||||
50
application/admin/controller/shopro/commission/Log.php
Normal file
50
application/admin/controller/shopro/commission/Log.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro\commission;
|
||||
|
||||
use app\admin\controller\shopro\Common;
|
||||
use app\admin\model\shopro\commission\Log as LogModel;
|
||||
use app\admin\model\shopro\user\User as UserModel;
|
||||
use app\admin\model\Admin as AdminModel;
|
||||
use addons\shopro\library\Operator;
|
||||
|
||||
class Log extends Common
|
||||
{
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new LogModel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$logs = $this->model->sheepFilter()->with(['agent'])->paginate($this->request->param('list_rows', 10));
|
||||
|
||||
$morphs = [
|
||||
'user' => UserModel::class,
|
||||
'admin' => AdminModel::class,
|
||||
'system' => AdminModel::class
|
||||
];
|
||||
$logs = morph_to($logs, $morphs, ['oper_type', 'oper_id']);
|
||||
$logs = $logs->toArray();
|
||||
|
||||
// 格式化操作人信息
|
||||
foreach ($logs['data'] as &$log) {
|
||||
$log['oper'] = Operator::info($log['oper_type'], $log['oper'] ?? null);
|
||||
}
|
||||
|
||||
$this->success('获取成功', null, $logs);
|
||||
}
|
||||
}
|
||||
323
application/admin/controller/shopro/commission/Order.php
Normal file
323
application/admin/controller/shopro/commission/Order.php
Normal file
@@ -0,0 +1,323 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro\commission;
|
||||
|
||||
use think\Db;
|
||||
use think\exception\HttpResponseException;
|
||||
use app\admin\controller\shopro\Common;
|
||||
use app\admin\model\shopro\commission\Order as OrderModel;
|
||||
use app\admin\model\shopro\commission\Reward as RewardModel;
|
||||
use addons\shopro\service\commission\Reward as RewardService;
|
||||
|
||||
class Order extends Common
|
||||
{
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new OrderModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
$exportConfig = (new \addons\shopro\library\Export())->getConfig();
|
||||
$this->assignconfig("save_type", $exportConfig['save_type'] ?? 'download');
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$list = $this->model->sheepFilter()->with(['buyer', 'agent', 'order', 'rewards.agent', 'order_item'])->paginate($this->request->param('list_rows', 10));
|
||||
$list = $list->toArray();
|
||||
|
||||
// 统计数据
|
||||
$count = [
|
||||
'total' => $list['total'],
|
||||
'total_amount' => 0,
|
||||
'total_commission' => 0,
|
||||
'total_commission_cancel' => 0,
|
||||
'total_commission_accounted' => 0,
|
||||
'total_commission_back' => 0,
|
||||
'total_commission_pending' => 0
|
||||
];
|
||||
|
||||
$orders = $this->model->sheepFilter()->with(['rewards'])->select();
|
||||
collection($orders)->each(function ($order) use (&$count) {
|
||||
$count['total_amount'] += $order['amount'];
|
||||
foreach ($order['rewards'] as $reward) {
|
||||
$count['total_commission'] += $reward['commission'];
|
||||
switch ($reward['status']) {
|
||||
case RewardModel::COMMISSION_REWARD_STATUS_ACCOUNTED:
|
||||
$count['total_commission_accounted'] += $reward['commission'];
|
||||
break;
|
||||
case RewardModel::COMMISSION_REWARD_STATUS_BACK:
|
||||
$count['total_commission_back'] += $reward['commission'];
|
||||
break;
|
||||
case RewardModel::COMMISSION_REWARD_STATUS_PENDING:
|
||||
$count['total_commission_pending'] += $reward['commission'];
|
||||
break;
|
||||
case RewardModel::COMMISSION_REWARD_STATUS_CANCEL:
|
||||
$count['total_commission_cancel'] += $reward['commission'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$this->success('', null, [
|
||||
'list' => $list,
|
||||
'count' => $count
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 结算佣金
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
$params = $this->request->only(['commission_reward_id', 'commission_order_id']);
|
||||
|
||||
try {
|
||||
Db::transaction(function () use ($params) {
|
||||
$rewardService = new RewardService('admin');
|
||||
if (isset($params['commission_reward_id'])) {
|
||||
return $rewardService->runCommissionReward($params['commission_reward_id']);
|
||||
} elseif (isset($params['commission_order_id'])) {
|
||||
return $rewardService->runCommissionRewardByOrder($params['commission_order_id']);
|
||||
}
|
||||
});
|
||||
} catch (HttpResponseException $e) {
|
||||
$data = $e->getResponse()->getData();
|
||||
$message = $data ? ($data['msg'] ?? '') : $e->getMessage();
|
||||
$this->error($message);
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$this->success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消结算
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function cancel()
|
||||
{
|
||||
$params = $this->request->only(['commission_reward_id', 'commission_order_id']);
|
||||
|
||||
try {
|
||||
|
||||
Db::transaction(function () use ($params) {
|
||||
$rewardService = new RewardService('admin');
|
||||
if (isset($params['commission_reward_id'])) {
|
||||
return $rewardService->cancelCommissionReward($params['commission_reward_id']);
|
||||
} elseif (isset($params['commission_order_id'])) {
|
||||
return $rewardService->backCommissionRewardByOrder($params['commission_order_id']);
|
||||
}
|
||||
});
|
||||
} catch (HttpResponseException $e) {
|
||||
$data = $e->getResponse()->getData();
|
||||
$message = $data ? ($data['msg'] ?? '') : $e->getMessage();
|
||||
$this->error($message);
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 退回已结算佣金
|
||||
*/
|
||||
public function back()
|
||||
{
|
||||
$params = $this->request->only(['commission_reward_id', 'commission_order_id', 'deduct_order_money']);
|
||||
|
||||
try {
|
||||
Db::transaction(function () use ($params) {
|
||||
$rewardService = new RewardService('admin');
|
||||
if (isset($params['commission_reward_id'])) {
|
||||
return $rewardService->backCommissionReward($params['commission_reward_id']);
|
||||
} elseif (isset($params['commission_order_id'])) {
|
||||
return $rewardService->backCommissionRewardByOrder($params['commission_order_id'], $params['deduct_order_money']);
|
||||
}
|
||||
});
|
||||
} catch (HttpResponseException $e) {
|
||||
$data = $e->getResponse()->getData();
|
||||
$message = $data ? ($data['msg'] ?? '') : $e->getMessage();
|
||||
$this->error($message);
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改待结算佣金
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$params = $this->request->only(['commission_reward_id', 'commission']);
|
||||
$reward = RewardModel::get($params['commission_reward_id']);
|
||||
if (!$reward) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
$reward->commission = $params['commission'];
|
||||
$result = $reward->save();
|
||||
if ($result) {
|
||||
$this->success('操作成功');
|
||||
}
|
||||
$this->error('操作失败');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function export()
|
||||
{
|
||||
$cellTitles = [
|
||||
// 主要字段
|
||||
'commission_order_id' => 'Id',
|
||||
'order_sn' => '订单号',
|
||||
'goods_title' => '商品名称',
|
||||
'goods_sku_text' => '商品规格',
|
||||
'goods_price' => '商品价格',
|
||||
'goods_num' => '购买数量',
|
||||
'refund_status_text' => '退款状态',
|
||||
'buyer_nickname' => '下单用户',
|
||||
'buyer_mobile' => '手机号',
|
||||
'share_nickname' => '推广分销商',
|
||||
'share_mobile' => '手机号',
|
||||
'commission_reward_status_text' => '佣金状态',
|
||||
'reward_event_text' => '结算方式',
|
||||
'commission_time' => '结算时间',
|
||||
'reward_type_text' => '商品结算方式',
|
||||
'amount' => '商品结算金额',
|
||||
'commission_order_status_text' => '分销商业绩',
|
||||
'total_commission' => '分销总金额',
|
||||
'total_commissioned' => '到账金额',
|
||||
// 佣金明细
|
||||
'reward_agent_nickname' => '分佣用户',
|
||||
'reward_agent_mobile' => '分佣手机号',
|
||||
'reward_commission' => '分佣金额',
|
||||
'reward_status_text' => '分佣状态',
|
||||
'reward_type_text' => '入账方式',
|
||||
'reward_commission_time' => '结算时间',
|
||||
];
|
||||
|
||||
// 数据总条数
|
||||
$total = $this->model->sheepFilter()->count();
|
||||
if ($total <= 0) {
|
||||
$this->error('导出数据为空');
|
||||
}
|
||||
|
||||
$export = new \addons\shopro\library\Export();
|
||||
$params = [
|
||||
'file_name' => '分销订单列表',
|
||||
'cell_titles' => $cellTitles,
|
||||
'total' => $total,
|
||||
'is_sub_cell' => true,
|
||||
'sub_start_cell' => 'reward_agent_nickname',
|
||||
'sub_field' => 'rewards'
|
||||
];
|
||||
|
||||
$total_amount = 0;
|
||||
$total_commission = 0;
|
||||
$total_commission_cancel = 0;
|
||||
$total_commission_accounted = 0;
|
||||
$total_commission_back = 0;
|
||||
$total_commission_pending = 0;
|
||||
$result = $export->export($params, function ($pages) use (&$total_amount, &$total_commission, &$total_commission_cancel, &$total_commission_accounted, &$total_commission_back, &$total_commission_pending, $total) {
|
||||
$datas = $this->model->sheepFilter()->with(['buyer', 'agent', 'order', 'rewards.agent', 'order_item'])
|
||||
->limit((($pages['page'] - 1) * $pages['list_rows']), $pages['list_rows'])
|
||||
->select();
|
||||
|
||||
$datas = collection($datas);
|
||||
$datas->each(function ($commissionOrder) use (&$total_amount, &$total_commission, &$total_commission_cancel, &$total_commission_accounted, &$total_commission_back, &$total_commission_pending, $total) {
|
||||
$total_amount += $commissionOrder['amount'];
|
||||
foreach ($commissionOrder['rewards'] as $reward) {
|
||||
$total_commission += $reward['commission'];
|
||||
switch ($reward['status']) {
|
||||
case RewardModel::COMMISSION_REWARD_STATUS_ACCOUNTED:
|
||||
$total_commission_accounted += $reward['commission'];
|
||||
break;
|
||||
case RewardModel::COMMISSION_REWARD_STATUS_BACK:
|
||||
$total_commission_back += $reward['commission'];
|
||||
break;
|
||||
case RewardModel::COMMISSION_REWARD_STATUS_PENDING:
|
||||
$total_commission_pending += $reward['commission'];
|
||||
break;
|
||||
case RewardModel::COMMISSION_REWARD_STATUS_CANCEL:
|
||||
$total_commission_cancel += $reward['commission'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
})->toArray();
|
||||
|
||||
$newDatas = [];
|
||||
foreach ($datas as $commissionOrder) {
|
||||
$commission = 0;
|
||||
$commissioned = 0;
|
||||
foreach ($commissionOrder['rewards'] as $reward) {
|
||||
if ($reward['status'] == 1) {
|
||||
$commissioned += $reward['commission'];
|
||||
}
|
||||
$commission += $reward['commission'];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'commission_order_id' => $commissionOrder['id'],
|
||||
'order_sn' => $commissionOrder['order'] ? $commissionOrder['order']['order_sn'] : '',
|
||||
'goods_title' => $commissionOrder['order_item'] ? '#' . $commissionOrder['order_item']['goods_id'] . ' ' . $commissionOrder['order_item']['goods_title'] : '',
|
||||
'goods_sku_text' => $commissionOrder['order_item'] ? $commissionOrder['order_item']['goods_sku_text'] : '',
|
||||
'goods_price' => $commissionOrder['order_item'] ? $commissionOrder['order_item']['goods_price'] : '',
|
||||
'goods_num' => $commissionOrder['order_item'] ? $commissionOrder['order_item']['goods_num'] : '',
|
||||
'refund_status_text' => $commissionOrder['order_item'] ? $commissionOrder['order_item']['refund_status_text'] : '',
|
||||
'buyer_nickname' => $commissionOrder['buyer'] ? $commissionOrder['buyer']['nickname'] : '-',
|
||||
'buyer_mobile' => $commissionOrder['buyer'] ? $commissionOrder['buyer']['mobile'] . ' ' : '-',
|
||||
'share_nickname' => $commissionOrder['agent'] ? $commissionOrder['agent']['nickname'] : '-',
|
||||
'share_mobile' => $commissionOrder['agent'] ? $commissionOrder['agent']['mobile'] . ' ' : '-',
|
||||
|
||||
// 这里循环 rewards 佣金详情
|
||||
|
||||
'commission_reward_status_text' => $commissionOrder['commission_reward_status_text'],
|
||||
'reward_event_text' => $commissionOrder['reward_event_text'],
|
||||
'commission_time' => $commissionOrder['commission_time'],
|
||||
'reward_type_text' => $commissionOrder['reward_type_text'],
|
||||
'amount' => $commissionOrder['amount'],
|
||||
'commission_order_status_text' => $commissionOrder['commission_order_status_text'],
|
||||
'total_commission' => $commission,
|
||||
'total_commissioned' => $commissioned,
|
||||
];
|
||||
|
||||
$rewardsItems = [];
|
||||
foreach ($commissionOrder['rewards'] as $reward) {
|
||||
$rewardsItems[] = [
|
||||
'reward_agent_nickname' => $reward['agent'] ? $reward['agent']['nickname'] : '',
|
||||
'reward_agent_mobile' => $reward['agent'] ? $reward['agent']['mobile'] : '',
|
||||
'reward_commission' => $reward['commission'],
|
||||
'reward_status_text' => $reward['status_text'],
|
||||
'reward_type_text' => $reward['type_text'],
|
||||
'reward_commission_time' => $reward['commission_time']
|
||||
];
|
||||
}
|
||||
|
||||
$data['rewards'] = $rewardsItems;
|
||||
|
||||
$newDatas[] = $data;
|
||||
}
|
||||
|
||||
if ($pages['is_last_page']) {
|
||||
$newDatas[] = ['order_id' => "商品总订单数:" . $total . ";商品结算总金额:¥" . $total_amount . ";分佣总金额:¥" . $total_commission . ";已取消佣金:¥" . $total_commission_cancel . ";已退回佣金:¥" . $total_commission_back . ";未结算佣金:" . $total_commission_pending . ";已结算佣金:" . $total_commission_accounted];
|
||||
}
|
||||
return $newDatas;
|
||||
});
|
||||
|
||||
$this->success('导出成功' . (isset($result['file_path']) && $result['file_path'] ? ',请在服务器: “' . $result['file_path'] . '” 查看' : ''), null, $result);
|
||||
}
|
||||
}
|
||||
108
application/admin/controller/shopro/commission/Reward.php
Normal file
108
application/admin/controller/shopro/commission/Reward.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro\commission;
|
||||
|
||||
use app\admin\controller\shopro\Common;
|
||||
use app\admin\model\shopro\commission\Reward as RewardModel;
|
||||
|
||||
class Reward extends Common
|
||||
{
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new RewardModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
$exportConfig = (new \addons\shopro\library\Export())->getConfig();
|
||||
$this->assignconfig("save_type", $exportConfig['save_type'] ?? 'download');
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$list = $this->model->sheepFilter()->with(['buyer', 'agent', 'order', 'order_item'])->paginate($this->request->param('list_rows', 10));
|
||||
|
||||
$this->success('获取成功', null, $list);
|
||||
}
|
||||
|
||||
|
||||
public function export()
|
||||
{
|
||||
$cellTitles = [
|
||||
'reward_id' => 'Id',
|
||||
'order_sn' => '订单号',
|
||||
'buyer_nickname' => '下单用户',
|
||||
'buyer_mobile' => '手机号',
|
||||
'agent_nickname' => '分销用户',
|
||||
'agent_mobile' => '分销手机号',
|
||||
'original_commission' => '原始佣金',
|
||||
'commission' => '分销佣金',
|
||||
'commission_level' => '执行层级',
|
||||
'agent_level' => '执行等级',
|
||||
'status_text' => '状态',
|
||||
'type_text' => '入账方式',
|
||||
'commission_time' => '结算时间'
|
||||
];
|
||||
|
||||
// 数据总条数
|
||||
$total = $this->model->sheepFilter()->count();
|
||||
if ($total <= 0) {
|
||||
$this->error('导出数据为空');
|
||||
}
|
||||
|
||||
$export = new \addons\shopro\library\Export();
|
||||
$params = [
|
||||
'file_name' => '佣金明细列表',
|
||||
'cell_titles' => $cellTitles,
|
||||
'total' => $total,
|
||||
'is_sub_cell' => false,
|
||||
];
|
||||
|
||||
$total_commission = 0;
|
||||
$result = $export->export($params, function ($pages) use (&$total_commission, $total) {
|
||||
$datas = $this->model->sheepFilter()->with(['buyer', 'agent', 'order', 'order_item'])
|
||||
->limit((($pages['page'] - 1) * $pages['list_rows']), $pages['list_rows'])
|
||||
->select();
|
||||
|
||||
$datas = collection($datas);
|
||||
$datas->each(function ($order) {
|
||||
})->toArray();
|
||||
|
||||
$newDatas = [];
|
||||
foreach ($datas as &$reward) {
|
||||
$data = [
|
||||
'reward_id' => $reward['id'],
|
||||
'order_sn' => $reward['order'] ? $reward['order']['order_sn'] : '',
|
||||
'buyer_nickname' => $reward['buyer'] ? $reward['buyer']['nickname'] : '-',
|
||||
'buyer_mobile' => $reward['buyer'] ? $reward['buyer']['mobile'] . ' ' : '-',
|
||||
'agent_nickname' => $reward['agent'] ? $reward['agent']['nickname'] : '-',
|
||||
'agent_mobile' => $reward['agent'] ? $reward['agent']['mobile'] . ' ' : '-',
|
||||
'original_commission' => $reward['original_commission'],
|
||||
'commission' => $reward['commission'],
|
||||
'commission_level' => $reward['commission_level'],
|
||||
'agent_level' => $reward['agent_level'],
|
||||
'status_text' => $reward['status_text'],
|
||||
'type_text' => $reward['type_text'],
|
||||
'commission_time' => $reward['commission_time'],
|
||||
];
|
||||
|
||||
$newDatas[] = $data;
|
||||
}
|
||||
|
||||
$total_commission += array_sum(array_column($newDatas, 'commission'));
|
||||
|
||||
if ($pages['is_last_page']) {
|
||||
$newDatas[] = ['reward_id' => "总数:" . $total . ";总佣金金额:¥" . $total_commission . ";"];
|
||||
}
|
||||
return $newDatas;
|
||||
});
|
||||
|
||||
$this->success('导出成功' . (isset($result['file_path']) && $result['file_path'] ? ',请在服务器: “' . $result['file_path'] . '” 查看' : ''), null, $result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user