<?php
/**
 * Created by PhpStorm.
 * User: pc
 * Date: 2021/11/23
 * Time: 11:06
 */

namespace app\api\model;

use app\api\model\UsersDetailMoneyModel;
use think\Model;
use think\exception\HttpResponseException;
use think\Request;
use think\Response;
class UsersModel extends BaseModel {



    // 表名
    protected $name = 'user';
    protected $pk = 'id';




    /**
     * 获取用户信息
     */
    public static function getUserById($user_id,$field="*"){
        return self::where('id','=',$user_id)->field($field)->find();
    }

    /**添加减少余额
     * @param $user_id
     * @param $num
     * @param int $detail_type
     * @param string $intro
     * @param null $logs_id
     * @param null $code
     * @param null $mune
     * @param null $order_id
     * @param int $status
     * @return |bool
     */
    public static function addMoney($user_id, $num,$msgtype=0,$detail_type=0,$intro = '', $status = 0,$logs_id = null,$order_type=null,$pay_way=null,$order_id = null,$remark=null,$admin_id=null){
        $model =new static();
        if ($model->updateCount($user_id, 'money', $num)) {
//            MsgService::messageTemplate($msgtype,$user_id,$num,$intro);
            return UsersDetailMoneyModel::insertData($user_id,$num,1,$detail_type,$intro,$logs_id,$order_type,$pay_way,$order_id,$status,$remark,$admin_id);
        }
        return false;
    }

    /**添加减少佣金
     * @param $user_id
     * @param $num
     * @param int $msgtype
     * @param int $detail_type
     * @param string $intro
     * @param int $status
     * @param null $logs_id
     * @param null $code
     * @param null $order_id
     * @return |bool
     */
    public static function addCommission($user_id, $num,$msgtype=0, $detail_type=0,$intro = '', $status = 0,$logs_id = null, $order_type=null,$pay_way=null,$order_id = null,$remark=null,$admin_id=null){
        $model =new static();
        if ($model->updateCount($user_id, 'commission', $num)) {
//            MsgService::messageTemplate($msgtype,$user_id,$num,$intro);
            return UsersDetailMoneyModel::insertData($user_id,$num,3,$detail_type,$intro,$logs_id,$order_type,$pay_way,$order_id,$status,$remark,$admin_id);
        }
        return false;
    }
}