<?php

/**
 * 用户分享邀请
 * 2020-9-4 10:13:34
 * junshi
*/

class userShareModule extends commonModule
{
    public function __construct()
    {
        parent::__construct("sl_user_share");
    }

    //增加分享日志
    public function addShareLog($request){

        //参数验证
        $userModeule = new userModule();
        $user = $userModeule->getUserInfoByNumber($request["user_number"]);
        if (empty($request["user_number"]) || empty($user)){
            returnFail([],getcodestr(3020),3020);
        }
        $usered = $userModeule->getUserInfoByNumber($request["usered_number"]);
        if (empty($request["usered_number"]) || empty($usered)){
            returnFail([],getcodestr(3021),3021);
        }
        //验证是否已经分享过了
        $ver = $this->where(["user_number"=>$request["user_number"],"usered_number"=>$request["usered_number"]])->one();
        if (!empty($ver)){
            returnFail([],getcodestr(3022),3022);
        }

        //查询分享金额
        $coin_info = (new parameterModel())->findOne(609);
        $coin = !empty($coin_info)?$coin_info["u2"]:0;

        //组装数据
        $data = [
            "user_number" => $request["user_number"],
            "usered_number" => $request["usered_number"],
            "code" => $request["user_number"],
            "coin" => $coin,
            "create_time" => date("Y-m-d H:i:s"),
        ];

        //添加数据
        $res = $this->insert($data);
        if ($res){
            returnSuccess([],getcodestr(200),200);
        }else{
            returnFail([],getcodestr(3023),3023);
        }

    }

}