Files
spacestation/api/controllers/plan/agent/Commission.php
T

57 lines
2.1 KiB
PHP

<?php
/**
* Notes:狸车宝任务
* Created on: 2021/10/19 17:15
* Created by: dengbw
*/
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->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($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'], $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);
}
}
}