Files
spacestation/api/controllers/plan/agent/Commission.php
T
2025-08-01 14:02:30 +08:00

94 lines
3.9 KiB
PHP

<?php
class Commission extends HD_Controller
{
private $dir;
public function __construct()
{
parent::__construct();
$this->load->model('receiver/receiver_clues_model', 'clues_model');
$this->load->model('biz/biz_account_model', 'account_model');
$this->load->model('biz/biz_accountLog_model', 'bizAccountLog');
$this->load->model('receiver/order/receiver_orders_model');
$this->load->model('agent/receiver_order_subsidy_model');
$this->load->model('agent/auto_product_coupon_model');
$this->load->model('agent/auto_product_model');
$this->load->model('agent/pingan/pingan_users_cmmssn_model');
$this->load->model('agent/organization/organization_cmmssn_model', 'mdOrganizationCmmssn');
$this->load->model('agent/organization/organization_model');
$this->load->model('agent/pingan/pingan_users_model');
$this->receiver_order_subsidy_model->set_db('agentdb');
$this->auto_product_coupon_model->set_db('agentdb');
$this->auto_product_model->set_db('agentdb');
$this->pingan_users_cmmssn_model->set_db('agentdb');
$this->mdOrganizationCmmssn->set_db('agentdb');
$this->organization_model->set_db('agentdb');
$this->pingan_users_model->set_db('agentdb');
$this->load->library('myResponse');
$this->dir = 'commission';
}
/**
* 线索分佣
* @return void
*/
public function bizClues()
{
$log_path = 'biz_clues.log';
try {
$page = 1;
$size = 20;
$where = ['comm_status' => Biz_accountLog_model::COMM_STATUS_WAIT, 'target_id>' => 0];
$rows = $this->bizAccountLog->select($where, 'id asc', $page, $size);
if (!$rows) {
throw new Exception('没有需要分佣的记录');
}
foreach ($rows as $key => $val) {
$account = $this->account_model->get(['id' => $val['account_id']]);
/** @var MyResponse $result */
$result = $this->clues_model->Commissions($val['target_id'], $account['biz_id'], $val['money_out']);
if (!$result->isSuccess()) {
debug_log("分佣失败:" . $result->getMessage(), $log_path, $this->dir);
}
$comm_status = $result->isSuccess() ? Biz_accountLog_model::COMM_STATUS_SUCCESS : Biz_accountLog_model::COMM_STATUS_FAIL;
$ret = $this->bizAccountLog->update(['comm_status' => $comm_status], ['id' => $val['id']]);
if ($ret && is_numeric($ret)) {
debug_log('更新状态成功,支付记录ID:' . $val['id'] . ',状态:' . $comm_status, $log_path, $this->dir);
} else {
debug_log('更新状态成功失败,支付记录ID:' . $val['id'], $log_path, $this->dir);
}
}
} catch (Exception $e) {
debug_log($e->getMessage(), $log_path, $this->dir);
}
}
/**
* 订单分佣
* @return void
*/
public function orderSubsidy()
{
$log_path = 'order_subsidy.log';
try {
$page = 1;
$size = 20;
$where = ['commStatus' => Receiver_order_subsidy_model::COMM_STATUS_WAIT];
/** @var ReceiverOrderSubsidyEntity[] $rows */
$rows = $this->receiver_order_subsidy_model->select($where, 'id asc', $page, $size, '', 'ReceiverOrderSubsidyEntity');
if (!$rows) {
throw new Exception('没有需要分佣的记录');
}
foreach ($rows as $row) {
debug_log('开始分佣,ID:' . $row->id, $log_path, $this->dir);
$result = $row->commission();
debug_log("分佣结束:" . $result->getMessage(), $log_path, $this->dir);
}
} catch (Exception $e) {
debug_log($e->getMessage(), $log_path, $this->dir);
}
}
}