6 changed files with 146 additions and 6 deletions
@ -0,0 +1,80 @@ |
|||
<?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',4) * 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 |
|||
]; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue