You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.5 KiB
80 lines
2.5 KiB
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\model;
|
|
|
|
use think\Model;
|
|
|
|
/**
|
|
* 返点记录
|
|
* @mixin \think\Model
|
|
*/
|
|
class RebateRecords extends Model
|
|
{
|
|
/**
|
|
* 生成记录
|
|
* @param $user_id
|
|
* @param $aid
|
|
* @param $c_r_id // 消费ID
|
|
* @param $c_amount // 消费金额
|
|
* @param $amount // 返点金额
|
|
* @param $h_rebate_ratio // 当前返点占比
|
|
*/
|
|
public static function createRecords($user_id,$aid,$c_r_id,$c_amount,$amount,$h_rebate_ratio)
|
|
{
|
|
$RebateRecords = new RebateRecords();
|
|
|
|
$RebateRecords->user_id = $user_id;
|
|
$RebateRecords->aid = $aid;
|
|
$RebateRecords->c_r_id = $c_r_id;
|
|
$RebateRecords->consumption_amount = $c_amount;
|
|
$RebateRecords->amount = $amount;
|
|
$RebateRecords->h_rebate_ratio = $h_rebate_ratio;
|
|
$RebateRecords->create_time = date("Y-m-d H:i:s",time());
|
|
|
|
$RebateRecords->save();
|
|
}
|
|
|
|
/**
|
|
* 查询列表
|
|
* @param $param // 查询条件
|
|
* @param $limit //
|
|
* @param $is_manage // 0 = 代理 1 = 管理
|
|
* @return array
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public static function getList($param,$limit = 10,$is_manage = 0)
|
|
{
|
|
|
|
$RebateRecords = new RebateRecords();
|
|
|
|
$filed = 'id,aid,user_id,consumption_amount as c_amount,amount,h_rebate_ratio,create_time';
|
|
$where = [];
|
|
$order = 'create_time desc';
|
|
|
|
if (!empty($param['aid'])) $where['aid'] = $param['aid'];
|
|
|
|
$res = $RebateRecords->field($filed)->where($where)->order($order)->paginate($limit);
|
|
|
|
$list = $res->items();
|
|
$total = $res->total();
|
|
|
|
foreach ($list as &$item) {
|
|
|
|
$item['id'] = $is_manage ? '代理ID:' . $item['aid'] : '记录ID:' . $item['id'];
|
|
$item['datetime'] = get_datetime($item['create_time'],2);
|
|
$item['h_rebate_ratio'] = bcmul($item['h_rebate_ratio'],'100',2) * 1 . '%';
|
|
$item['str'] = 'ID:' . $item['user_id'] . '消费' . ($item['c_amount'] * 1) . '元,返点' . $item['h_rebate_ratio'];
|
|
$amount = $item['amount'];
|
|
give_symbol($amount);
|
|
$item['amount'] = $amount;
|
|
|
|
unset($item['create_time'],$item['user_id'],$item['c_amount'],$item['c_amount'],$item['h_rebate_ratio'],$item['aid']);
|
|
}
|
|
|
|
return [
|
|
'list' => $list,
|
|
'total' => $total
|
|
];
|
|
}
|
|
}
|
|
|