Money.php 6.5 KB
<?php

namespace app\api\controller;

use app\api\model\MoneyLog;
use app\api\model\promoter\PromoterLast;
use app\api\model\WithdrawalLog;
use app\common\controller\Api;

/**
 * 佣金,提现接口
 */
class Money extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = [''];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    /**
     * 申请提现
     *
     * @ApiTitle    (申请提现)
     * @ApiSummary  (申请提现)
     * @ApiParams   (name="price", type="integer", required=true, description="提现金额")
     */
    public function apply()
    {
        $params = $this->request->param('price');
        if (empty($params) || $params <= 0) {
            $this->error('提现金额不能小于0');
        }
        $price          = $params;   //用户输入金额
        $withdrawal_fee = config('site.withdrawal_fee'); //提现手续费比例
        $user_price     = $this->auth->withdrawable_cash_price;  //可提现金额
        if ($price > $user_price) {
            $this->error('您的可提现金额不足');
        }
        $service_charge = $price * ($withdrawal_fee / 100);   //手续费
        $data           = [
            'user_id'          => $this->auth->id,
            'username'         => $this->auth->username,
            'order_no'         => 'tx' . getOrderNo($this->auth->id),
            'status'           => 2,
            'apply_time'       => time(),
            'withdrawal_price' => $price,
            'percentage'       => $withdrawal_fee . '%',
            'service_charge'   => $service_charge,
            'arrival_price'    => $price - $service_charge,
        ];
        $model          = new WithdrawalLog();
        $model->save($data);
        $this->success('申请提现成功');
    }

    /**
     * 提现记录
     *
     * @ApiTitle    (提现记录)
     * @ApiSummary  (提现记录)
     * @ApiParams   (name="status", type="integer", required=true, description="审核状态:1=审核通过,0=待发起提现,-1=已驳回,2=处理中")
     * @ApiReturnParams    (name="id", type="integer", required=true, description="id")
     * @ApiReturnParams    (name="apply_time", type="integer", required=true, description="申请时间")
     * @ApiReturnParams    (name="withdrawal_price", type="integer", required=true, description="提现金额")
     * @ApiReturnParams    (name="arrival_price", type="integer", required=true, description="实际提现金额")
     * @ApiReturnParams    (name="percentage", type="integer", required=true, description="手续费百分比")
     * @ApiReturnParams    (name="reasons_rejection", type="integer", required=true, description="驳回理由")
     */
    public function apply_price_log()
    {
        $model  = new WithdrawalLog();
        $status = $this->request->param('status', 0);
        $field  = ['id,status,apply_time,withdrawal_price,arrival_price,percentage,reasons_rejection'];
        $list   = $model->field($field)
            ->where(['status' => $status, 'user_id' => $this->auth->id])
            ->order('apply_time', 'desc')->paginate();
        $this->success('提现记录', $list);
    }

    /**
     * 我的成员
     *
     * @ApiTitle    (我的成员)
     * @ApiSummary  (我的成员)
     * @ApiReturnParams    (name="avatar", type="integer", required=true, description="头像")
     * @ApiReturnParams    (name="nickname", type="integer", required=true, description="昵称")
     * @ApiReturnParams    (name="mobile", type="integer", required=true, description="电话")
     * @ApiReturnParams    (name="binding_time", type="integer", required=true, description="绑定时间")
     */
    public function my_member()
    {
        $model = new PromoterLast();
        $list  = $model->with(['user' => function ($query) {
            $query->field('avatar,nickname,mobile,user.binding_time');
        }])
            ->where('user_id', $this->auth->id)
	        ->where('is_last',1)
            ->order('user.binding_time','desc')
            ->paginate();
        $this->success('我的成员', $list);
    }

    /**
     * 佣金记录
     *
     * @ApiTitle    (佣金记录)
     * @ApiSummary  (佣金记录)
     *
     * @ApiParams   (name="time", type="string", required=true, description="佣兵记录状态:all=全波,today=今日,week=近七日")
     *
     * @ApiReturnParams    (name="time", type="integer", required=true, description="查询范围:all=全部,today=今天,week=最近七天")
     * @ApiReturnParams    (name="order_on", type="integer", required=true, description="订单编号")
     * @ApiReturnParams    (name="money", type="integer", required=true, description="佣金")
     * @ApiReturnParams    (name="type", type="integer", required=true, description="类型:get=获得,out=退回")
     * @ApiReturnParams    (name="commission_type", type="integer", required=true, description="佣金类型:1=直推,2=推广")
     * @ApiReturnParams    (name="createtime", type="integer", required=true, description="佣金变更时间")
     */
    public function commission_log()
    {
        $time  = $this->request->param('time', 'all');
        $model = new MoneyLog();
        switch ($time) {
            case 'all':
                $list = $model
                    ->where('user_id', $this->auth->id)
                    ->order('createtime', 'desc')->paginate();
                break;
            case 'today':
                $list = $model
                    ->whereTime('createtime', 'today')
                    ->where('user_id', $this->auth->id)
                    ->order('createtime', 'desc')->paginate();
                break;
            case 'week':
                $time      = date('Y-m-d', time());
                $time      = time();
                $week_time = time() - 7 * 24 * 60 * 60;
//                $week_time = date('Y-m-d', $week_time);
                $list      = $model
                    ->where('createtime', 'between', [$week_time, $time])
                    ->where('user_id', $this->auth->id)
                    ->order('createtime', 'desc')->paginate();
                break;
            default:
                $list = $model
                    ->where('user_id', $this->auth->id)
                    ->order('createtime', 'desc')->paginate();
        }
        $this->success('佣金记录', $list);
    }


}