My.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <?php
  2. /**
  3. *
  4. * User: anyluck
  5. * Date: 2020/6/3
  6. * Time: 13:13
  7. */
  8. namespace app\web\controller;
  9. use app\common\controller\Orde;
  10. use app\common\model\About;
  11. use app\common\model\Bond;
  12. use app\common\model\BondFinance;
  13. use app\common\model\CommissionFinance;
  14. use app\common\model\Feedback;
  15. use app\common\model\GeneralFinance;
  16. use app\common\model\GeneralTransfer;
  17. use app\common\model\Message;
  18. use app\common\model\Notice;
  19. use app\common\model\Problem;
  20. use app\common\model\System;
  21. use app\common\model\User;
  22. use app\common\model\UserLevel;
  23. use app\common\model\UserMessage;
  24. use app\common\model\VendibilityFinance;
  25. use app\web\model\Orders;
  26. use app\web\model\Team;
  27. use app\web\model\Tripartite;
  28. use think\facade\Db;
  29. class My extends Base
  30. {
  31. // todo 个人中心
  32. // 获取个人信息
  33. public function index()
  34. {
  35. // 给用户加活跃度
  36. $where["id"]=$this->user_id;
  37. $update["update_time"]=time();
  38. User::update($update,$where);
  39. json_result(200, "", $this->user);
  40. }
  41. // 更新头像
  42. public function update_image()
  43. {
  44. $image = input("image");
  45. if (!$image) json_result(400, "请上传图片路径");
  46. $where["id"] = $this->user_id;
  47. $update["image"] = $image;
  48. User::update($update, $where);
  49. json_result(200, "设置成功");
  50. }
  51. // 更新用户名
  52. public function update_name()
  53. {
  54. $name = input("name");
  55. $where["id"] = $this->user_id;
  56. $update["name"] = $name;
  57. User::update($update, $where);
  58. json_result(200, "设置成功");
  59. }
  60. // 更新手机号码
  61. public function update_phone()
  62. {
  63. $phone = trim(input("phone"));
  64. if (!$phone) json_result(400, "请输入手机号");
  65. $code = trim(input("code"));
  66. if (!$code) json_result(400, "请输入验证码");
  67. $wheres["phone|mail"] = $phone;
  68. $user = User::where($wheres)->count();
  69. $phone_email= Orders::phone_email();
  70. if ($user>=$phone_email) {
  71. json_result(400, "账号手机号或邮箱已经注册超过".$phone_email);
  72. }
  73. $rest = Tripartite::push_code($phone, 0);
  74. if ($rest != $code) {
  75. json_result(400, "验证码错误");
  76. }
  77. $where["id"] = $this->user_id;
  78. $update["phone"] = $phone;
  79. User::update($update, $where);
  80. json_result(200, "设置成功");
  81. }
  82. // 更新邮箱
  83. public function update_mail()
  84. {
  85. $phone = trim(input("mail"));
  86. if (!$phone) json_result(400, "请输入邮箱");
  87. $code =trim(input("code"));
  88. if (!$code) json_result(400, "请输入验证码");
  89. $wheres["phone|mail"] = $phone;
  90. $user = User::where($wheres)->count();
  91. $phone_email= Orders::phone_email();
  92. if ($user>=$phone_email) {
  93. json_result(400, "账号手机号或邮箱已经注册超过".$phone_email);
  94. }
  95. $rest = Tripartite::push_code($phone, 1);
  96. if ($rest != $code) {
  97. json_result(400, "验证码错误");
  98. }
  99. $where["id"] = $this->user_id;
  100. $update["mail"] = $phone;
  101. User::update($update, $where);
  102. json_result(200, "设置成功");
  103. }
  104. // 显示收账信息
  105. public function receivable_show()
  106. {
  107. $where["user_id"] = $this->user_id;
  108. $user_message = UserMessage::where($where)->find();
  109. if (!$user_message) {// 没有数据就添加数据
  110. $add["user_id"] = $this->user_id;
  111. UserMessage::create($add);
  112. $user_message = UserMessage::where($where)->find();
  113. }
  114. json_result(200,"",$user_message);
  115. }
  116. // 修改收账信息
  117. public function update_receivable()
  118. {
  119. $id = input("id");
  120. if (!$id) json_result(400, "请上传更新id");
  121. $data["phone"] = trim(input("phone"));
  122. $data["name"] = trim(input("name"));
  123. $data["bank_name"] =trim(input("bank_name"));
  124. $data["bank_number"] = trim(input("bank_number"));
  125. $data["bank_branch"] = trim(input("bank_branch"));
  126. $data["ali_pay"] = trim(input("ali_pay"));
  127. $data["wx_pay"] =trim( input("wx_pay"));
  128. $data["ali_pay_image"] = input("ali_pay_image");
  129. $data["wx_pay_image"] = input("wx_pay_image");
  130. $where["id"] = $id;
  131. UserMessage::update($data, $where);
  132. json_result(200, "操作成功");
  133. }
  134. // 消息 获取最新的三条数据
  135. public function notice()
  136. {
  137. $notice = Message::where(["type" => 0,"user_id"=>$this->user_id])->order("id desc")->find(); // 公告
  138. $message_jiaoyi = Message::where(["type" => 2,"user_id"=>$this->user_id])->order("id desc")->find();// 交易
  139. $message_zijin = Message::where(["type" => 1,"user_id"=>$this->user_id])->order("id desc")->find();// 资金
  140. $data["notice"] = $notice?:new \ArrayObject();
  141. $data["message_jiaoyi"] = $message_jiaoyi?:new \ArrayObject();
  142. $data["message_zijin"] = $message_zijin?:new \ArrayObject();
  143. $notice_count=Message::where(["type" => 0,"user_id"=>$this->user_id])->count();
  144. $message_jiaoyi_count=Message::where(["type" => 2,"user_id"=>$this->user_id])->count();
  145. $message_zijin_count=Message::where(["type" =>1,"user_id"=>$this->user_id])->count();
  146. $data["notice_count"]=$notice_count;
  147. $data["message_jiaoyi_count"]=$message_jiaoyi_count;
  148. $data["message_zijin_count"]=$message_zijin_count;
  149. json_result(200, "", $data);
  150. }
  151. // 消息列表
  152. public function notice_list()
  153. {
  154. $type = input("type") ?: 0;
  155. $page = input("page") ?: 1;
  156. $limit = input("limit") ?: 10;
  157. $where["type"] = $type;
  158. $where["user_id"] = $this->user_id;
  159. $list = Message::where($where)->order("id desc,status asc")->paginate(['list_rows' => $limit, 'page' => $page])->each(function ($item) {
  160. $item["add_time"] = date("Y-m-d H:i", $item["add_time"]);
  161. return $item;
  162. });
  163. json_result(200, "", $list);
  164. }
  165. // 更新消息是否已读
  166. public function notice_status()
  167. {
  168. $id = input("id");
  169. $where["id"] = $id;
  170. $update["status"] = 1;
  171. Message::update($update, $where);
  172. json_result(200);
  173. }
  174. // 反馈意见
  175. public function feedback()
  176. {
  177. $content = input("content");
  178. $image = input("image");
  179. $add["user_id"] = $this->user_id;
  180. $add["content"] = $content;
  181. $add["image"] = $image;
  182. $add["add_time"] = time();
  183. Feedback::create($add);
  184. json_result(200, "反馈成功");
  185. }
  186. // 常见问题
  187. public function problem()
  188. {
  189. $page = input("page") ?: 1;
  190. $limit = input("limit") ?: 10;
  191. $list = Problem::order("id desc")->field("id,name")->paginate(['list_rows' => $limit, 'page' => $page]);
  192. json_result(200, "", $list);
  193. }
  194. // 常见问题详情
  195. public function problem_show()
  196. {
  197. $id = input("id");
  198. $where["id"] = $id;
  199. $data = Problem::where($where)->find();
  200. json_result(200, "", $data);
  201. }
  202. // 修改密码
  203. public function update_pwd()
  204. {
  205. // $phone=input("phone");// 系统内置手机号或邮件
  206. $yuan = trim(input("ypwd"));
  207. if (!$yuan) json_result(400, "请输入原密码");
  208. $pwd =trim( input("pwd"));
  209. if (!$pwd) json_result(400, "请输入新密码");
  210. $where["id"] = $this->user_id;
  211. $update["pwd"] = password_hash($pwd, PASSWORD_DEFAULT);;
  212. $user = User::where($where)->find();
  213. // 查看原密码是否错误
  214. if (!password_verify($yuan, $user->pwd)) {
  215. json_result(400, "原密码错误");
  216. }
  217. // if ($user->pwd == $update["pwd"]) {
  218. // json_result(400, "原密码不能和新密码一样");
  219. // }
  220. User::update($update, $where);
  221. json_result(200, "设置成功");
  222. }
  223. // 关于我们
  224. public function about()
  225. {
  226. $where["id"] = 1;
  227. $about = About::where($where)->find();
  228. json_result(200, "", $about);
  229. }
  230. // 我的推广显示页面
  231. public function extension()
  232. {
  233. $where["pid"] = $this->user_id;
  234. $count = User::where($where)->count();
  235. $data["push"] = $count;
  236. $data["team"] = Team::all_tem($this->user_id);
  237. json_result(200, "", $data);
  238. }
  239. // 直推列表
  240. public function extension_list()
  241. {
  242. $pid = input("pid");
  243. $page = input("page") ?: 1;
  244. $limit = input("limit") ?: 10;
  245. $where = [];
  246. if ($pid) {
  247. $where["pid"] = $pid;
  248. } else {
  249. $where["pid"] = $this->user_id;
  250. }
  251. $list = User::where($where)->order("id desc")->field("id,image,phone,name,mail,add_time")->paginate(['list_rows' => $limit, 'page' => $page])->each(function ($item) {
  252. // 统计人数
  253. $where["pid"] = $item["id"];
  254. $count = User::where($where)->count();
  255. $item["team"] = $count;
  256. if ($item["add_time"]) {
  257. $item["add_time"] = date("Y-m-d H:i", $item["add_time"]);
  258. }
  259. return $item;
  260. });
  261. json_result(200,"",$list);
  262. }
  263. // 可售额度
  264. public function vendibility_list()
  265. {//lm_vendibility_finance
  266. $page = input("page") ?: 1;
  267. $limit = input("limit") ?: 10;
  268. $where["user_id"]=$this->user_id;
  269. $list = VendibilityFinance::where($where)->order("id desc")->paginate(['list_rows' => $limit, 'page' => $page])->each(function ($item) {
  270. if ($item["add_time"]) {
  271. $item["add_time"] = date("Y-m-d H:i", $item["add_time"]);
  272. }
  273. return $item;
  274. });
  275. json_result(200,"",$list);
  276. }
  277. // 保证金交易明细
  278. public function bond_list()
  279. {
  280. $page = input("page") ?: 1;
  281. $limit = input("limit") ?: 10;
  282. $where["user_id"]=$this->user_id;
  283. $list = BondFinance::where($where)->order("id desc")->paginate(['list_rows' => $limit, 'page' => $page])->each(function ($item) {
  284. if ($item["add_time"]) {
  285. $item["add_time"] = date("Y-m-d H:i", $item["add_time"]);
  286. }
  287. return $item;
  288. });
  289. json_result(200,"",$list);
  290. }
  291. //佣金记录
  292. public function commission_list()
  293. {
  294. $page = input("page") ?: 1;
  295. $limit = input("limit") ?: 10;
  296. $where["user_id"]=$this->user_id;
  297. $list = CommissionFinance::where($where)->order("id desc")->paginate(['list_rows' => $limit, 'page' => $page])->each(function ($item) {
  298. if ($item["add_time"]) {
  299. $item["add_time"] = date("Y-m-d H:i", $item["add_time"]);
  300. }
  301. return $item;
  302. });
  303. json_result(200,"",$list);
  304. }
  305. // 充值和提现保证金
  306. public function bond()
  307. {
  308. $money=input("money");if (!$money)json_result(400,"请输入提现金额");
  309. $type=input("type")?:0;//0 充值 1 提现
  310. // 直接处理转账成功
  311. if ($type==0){
  312. if ($this->user->money<$money){
  313. json_result(400,"当前账号通证余额不足");
  314. }
  315. }else{
  316. // 查看账号余额
  317. if ($this->user->ensure_money<$money){
  318. json_result(400,"账号保证金不足");
  319. }
  320. }
  321. // 直接转账操作
  322. Orde::bond_transfer($this->user,$this->user_id,$money,$type);
  323. // 添加记录
  324. $add["money"]=$money;
  325. $add["type"]=$type;
  326. $add["status"]=0;
  327. $add["add_time"]=time();
  328. $add["user_id"]=$this->user_id;
  329. Bond::create($add);
  330. json_result(200,"申请成功");
  331. }
  332. // 通证充值
  333. public function general()
  334. {
  335. $money=input("money");
  336. $actual_moneys=input("actual_money");
  337. $charge_moneys=input("charge_money");
  338. $image=input("image");
  339. $where["level"]=$this->user["vip_level"];
  340. $level=UserLevel::where($where)->find();
  341. $vip_bili=$level->bili;
  342. $actual_money=$money;
  343. $charge_money=0;
  344. if ($vip_bili){
  345. $charge_money=$money*($vip_bili/100);
  346. $actual_money-=$charge_money;
  347. }
  348. if ($actual_money!=$actual_moneys){
  349. json_result(400,"实际到账金额计算错误");
  350. }
  351. if ($charge_money!=$charge_moneys){
  352. json_result(400,"优惠金额计算错误");
  353. }
  354. $add["money"]=$money;
  355. $add["user_id"]=$this->user_id;
  356. $add["actual_money"]=$actual_money;
  357. $add["charge_money"]=$charge_money;
  358. $add["status"]=0;
  359. $add["image"]=$image;
  360. $add["add_time"]=time();
  361. GeneralFinance::create($add);
  362. // 添加转账操作
  363. json_result(200,"申请成功");
  364. }
  365. //通证转账
  366. public function general_transfer()
  367. {
  368. $account=input("account");
  369. $money=input("money");
  370. if ($money>$this->user->money){
  371. json_result(400,"账号通证余额不足");
  372. }
  373. $where["name|uuid"]=$account;
  374. $user=User::where($where)->find();
  375. if (!$user){
  376. json_result(200,"账号不存在");
  377. }
  378. // 查找无限级
  379. $team=Team::father($this->user_id,$user->id);
  380. if (!$team){
  381. json_result(400,"非同一个直推链不能转账");
  382. }
  383. $add["user_id"]=$this->user_id;
  384. $add["puser_id"]=$user->id;
  385. $add["account"]=$account;
  386. $add["money"]=$money;
  387. $add["status"]=0;
  388. $add["add_time"]=time();
  389. GeneralTransfer::create($add);
  390. $jmoney=$this->user["money"]-$money;
  391. $name=$this->user["name"];
  392. Orde::transfer($this->user_id,$user->id,$money,$jmoney,$name);
  393. \app\common\controller\Message::add_message($user->id,1,"好友转账","您的好友".$this->user['name'].",已为您转账".$money."通证");
  394. json_result(200,"转账成功");
  395. }
  396. // 转账验证密码
  397. public function transfer_pwd()
  398. {
  399. $pwd=input("pwd");if (!$pwd)json_result(400,"请输入密码");
  400. if (!password_verify($pwd,$this->user->pwd)){
  401. json_result(400,"密码错误");
  402. }
  403. json_result(200,"密码正确");
  404. }
  405. // 购买通证显示页面
  406. public function general_show()
  407. {
  408. $where["level"]=$this->user["vip_level"];
  409. $level=UserLevel::where($where)->find();
  410. $data["vip_level"]=$this->user["vip_level"];
  411. $data["vip_bili"]=$level->bili;
  412. $data["tong_money"]=$this->user->money;
  413. $system=System::where(["type"=>"shouk"])->field("name,value")->select();
  414. foreach ($system as $v){
  415. if ($v->name=="usdt"){
  416. $data["usdt"]=$v->value?:"";
  417. }else{
  418. $data["code"]=$v->value?:"";
  419. }
  420. }
  421. json_result(200,"",$data);
  422. }
  423. // 设置性别
  424. public function update_sex()
  425. {
  426. $sex=input("sex");
  427. $where["id"]=$this->user_id;
  428. $update["sex"]=$sex;
  429. User::update($update,$where);
  430. json_result(200,"设置成功");
  431. }
  432. // 获取二维码和推广码
  433. public function code_url()
  434. {
  435. $where["name"]="register_url";
  436. $url=System::where($where)->value("value");
  437. $data["code"]=$this->user["code"];
  438. $data["url"]=$url;
  439. json_result(200,"",$data);
  440. }
  441. // 更新紧急联系人信息
  442. public function urgent_user()
  443. {
  444. $urgent_name=trim(input("urgent_name"));
  445. $urgent_phone=trim(input("urgent_phone"));
  446. $where["id"]=$this->user_id;
  447. $update["urgent_name"]=$urgent_name;
  448. $update["urgent_phone"]=$urgent_phone;
  449. User::update($update,$where);
  450. json_result(200,"操作成功");
  451. }
  452. }