<?php
namespace app\api\controller;
use app\api\service\RedPaper;
use app\api\service\UserService;
use app\api\service\WxCompany;
use app\common\Tension;
use app\urge\controller\Upload;
use think\Db;
use think\Debug;
use think\Request;
class User extends Base
{
public function book()
{
return 1;
}
public function get_user_info()
{
$rs = ["status" => "success"];
if ($this->user_info) {
$rs["msg"] = "获取成功!";
$info = $this->user_info;
$info["is_vip"] = $this->get_user_vip($info["id"]);
if ($info["vip_end_time"] > time()) {
$info["vip_end_time"] = date("Y-m-d", $info["vip_end_time"]) . "到期";
} else {
$info["vip_end_time"] = 0;
}
$trailing = Db::name("user_trailing")->where("user_id", $info["id"])->count();
$info["trailing"] = formatNumber($trailing);
$paper = Db::name("paper")->where("user_id", $info["id"])->count();
$info["paper"] = formatNumber($paper);
$user_track = Db::name("user_track")->where("at_user_id", $info["id"])->count();
$info["user_track"] = formatNumber($user_track);
$user_fs = Db::name("user_track")->where("qu_user_id", $info["id"])->count();
$info["user_fs"] = formatNumber($user_fs);
$info["autograph"] = emoji_decode($info["autograph"]);
$info["is_nick_name"] = false;
$info["is_nick_name_end"] = 0;
if ($info["is_vip"] == 0) {
if ($info["nick_name_time"] + 90 * 86400 > time()) {
$info["is_nick_name_end"] = date("Y-m-d H:i:s", $info["nick_name_time"] + 90 * 86400);
$info["is_nick_name"] = true;
}
}
if ($info["is_vip"] == 1) {
if ($info["nick_name_time"] + 30 * 86400 > time()) {
$info["is_nick_name_end"] = date("Y-m-d H:i:s", $info["nick_name_time"] + 30 * 86400);
$info["is_nick_name"] = true;
}
}
$check = Db::name("user_punch")->whereTime("punch_time", "today")->where("user_id", $info["id"])->order("punch_time desc")->count();
$info["is_sign"] = $check;
$user_male = Db::name("user_smail")->where("user_id", $info["id"])->where("status", 0)->count();
$info["user_male"] = $user_male;
$user_yzm = Db::name("user_invitation_code")->where("user_id", $info["id"])->find();
if (empty($user_yzm)) {
$yzm = $this->get_yzm_random(6);
Db::name("user_invitation_code")->insert(["user_id" => $info["id"], "code" => $yzm, "much_id" => $this->much_id]);
}
$ji_bei = Db::name("user_currency_conversion")->where("user_id", $info["id"])->where("much_id", $this->much_id)->where("conver_type", 1)->whereTime("conver_time", "today")->count();
$bei_ji = Db::name("user_currency_conversion")->where("user_id", $info["id"])->where("much_id", $this->much_id)->where("conver_type", 0)->whereTime("conver_time", "today")->count();
$info["ji_bei"] = $ji_bei;
$info["bei_ji"] = $bei_ji;
$rs["info"] = $info;
} else {
$rs["status"] = "error";
$rs["msg"] = "系统忙,请稍候重试!";
}
return json_encode($rs);
}
public function add_user_punch()
{
$data = input("param.");
$user_info = Db::name("user")->where("id", $this->user_info["id"])->where("much_id", $data["much_id"])->find();
$check = Db::name("user_punch")->whereTime("punch_time", "today")->where("user_id", $this->user_info["id"])->where("much_id", $data["much_id"])->order("punch_time desc")->find();
if ($check) {
$rs = ["status" => "error", "msg" => "今天已经签过,请明天再来!"];
return json_encode($rs);
}
Db::startTrans();
$is_vip = $this->get_user_vip($this->user_info["id"]);
$punch_range = Db::name("user_punch_range")->where("much_id", $data["much_id"])->find();
if ($is_vip == 1) {
$fraction = rand($punch_range["noble_min"] * 100, $punch_range["noble_max"] * 100) / 100;
} else {
$fraction = rand($punch_range["aver_min"] * 100, $punch_range["aver_max"] * 100) / 100;
}
try {
$ins = Db::name("user_punch")->insert(["user_id" => $this->user_info["id"], "fraction" => $fraction, "punch_time" => time(), "much_id" => $data["much_id"]]);
if (!$ins) {
Db::rollback();
$rs = ["status" => "error", "msg" => "签到失败,请稍候重试"];
return json_encode($rs);
}
$am["user_id"] = $this->user_info["id"];
$am["category"] = 3;
$am["poem_fraction"] = $user_info["fraction"];
$am["surplus_fraction"] = $user_info["fraction"] + $fraction;
$am["finance"] = $fraction;
$am["ruins_time"] = time();
$am["solution"] = "每日签到赠送" . $this->design["confer"];
$am["evaluate"] = 1;
$am["much_id"] = $data["much_id"];
$user_amount = Db::name("user_amount")->insert($am);
if (!$user_amount) {
Db::rollback();
$rs = ["status" => "error", "msg" => "签到失败,请稍候重试"];
return json_encode($rs);
}
$user_up = Db::name("user")->where("id", $this->user_info["id"])->where("much_id", $data["much_id"])->update(["fraction" => $am["surplus_fraction"]]);
if (!$user_up) {
Db::rollback();
$rs = ["status" => "error", "msg" => "签到失败,请稍候重试"];
return json_encode($rs);
}
Db::commit();
$rs = ["status" => "success", "msg" => "签到成功!" . $this->design["confer"] . "增加" . $fraction . $this->design["confer"]];
return json_encode($rs);
} catch (\Exception $e) {
Db::rollback();
$rs = ["status" => "error", "msg" => "签到失败,请稍候重试" . $e->getMessage()];
return json_encode($rs);
}
}
public function edit_user_info()
{
$rs = ["status" => "success", "msg" => "保存成功"];
$data = input("param.");
$user_info = Db::name("user")->where("id", $this->user_info["id"])->where("much_id", $data["much_id"])->find();
$user_list = Db::name("user")->where("id", "<>", $this->user_info["id"])->where("much_id", $data["much_id"])->where("user_nick_name", emoji_encode($data["nick_name"]))->find();
if ($user_list) {
$rs = ["status" => "error", "msg" => "昵称已存在,换个吧"];
return json_encode($rs);
}
if (emoji_encode($data["nick_name"]) != $user_info["user_nick_name"]) {
$up["user_nick_name"] = emoji_encode($data["nick_name"]);
$up["nick_name_time"] = emoji_encode($data["nick_name"]) == $user_info["user_nick_name"] ? 0 : time();
}
$up["user_head_sculpture"] = $data["img"];
$up["gender"] = $data["gender"];
$up["autograph"] = emoji_encode($data["autograph"]);
$up["user_head_sculpture"] = $data["img"];
$update = Db::name("user")->where("id", $this->user_info["id"])->where("much_id", $data["much_id"])->update($up);
if ($update !== false) {
return json_encode($rs);
} else {
$rs = ["status" => "error", "msg" => "保存失败"];
return json_encode($rs);
}
}
public function get_index_list()
{
$rs = ["status" => "success", "msg" => "获取成功"];
$data = input("param.");
$where = [];
$where_not_in = [];
$page = $data["index_page"];
if (isset($data