My.php 13 KB

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