User.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Validate;
  4. use think\Lang;
  5. use app\admin\model\Userinfo;
  6. class User extends AdminControl
  7. {
  8. public function _initialize()
  9. {
  10. parent::_initialize();
  11. Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/member.lang.php');
  12. }
  13. /**
  14. * 用户列表
  15. * @return mixed
  16. */
  17. public function index()
  18. {
  19. $model_user = Model('User');
  20. $title = input('post.title');
  21. $time = input('post.timeRang');
  22. if (!empty($time)) {
  23. $gap = explode(' - ', $time);
  24. $begin = strtotime($gap[0]);
  25. $end = strtotime($gap[1]);
  26. }
  27. $condition = array();
  28. if ($title) {
  29. $condition['user_email|user_phone'] = $title;
  30. }
  31. if ($time && $begin && $end) {
  32. $condition['user_addTime'] = array('between', array($begin, $end));
  33. }
  34. $user_list = $model_user->getUserList($condition, '*', 10);
  35. for ($i = 0; $i < count($user_list); $i++) {
  36. $user_list[$i]['user_addTime'] = date("Y-m-d H:i:s", $user_list[$i]['user_addTime']);
  37. if ($user_list[$i]['user_status'] == -1) {
  38. $user_list[$i]['user_status'] = '未实名认证';
  39. }
  40. if ($user_list[$i]['user_status'] == 2) {
  41. $user_list[$i]['user_status'] = '实名认证中';
  42. }
  43. if ($user_list[$i]['user_status'] == 1) {
  44. $user_list[$i]['user_status'] = '已实名认证';
  45. }
  46. if ($user_list[$i]['user_type'] == 1) {
  47. $user_list[$i]['user_type'] = '个人用户';
  48. }
  49. if ($user_list[$i]['user_type'] == 2) {
  50. $user_list[$i]['user_type'] = '企业用户';
  51. }
  52. }
  53. $allpower = $this->qxhans();
  54. $this->assign('allpower', $allpower);
  55. $this->assign('user_list', $user_list);
  56. $this->assign('show_page', $model_user->page_info->render());
  57. $this->setAdminCurItem('index');
  58. return $this->fetch();
  59. }
  60. public function userinfo()
  61. {
  62. $uid = intval(input("uid", 0));
  63. $model = (new Userinfo())->findOne($uid, 1);
  64. $this->assign('userinfo', $model);
  65. return $this->fetch();
  66. }
  67. public function recharge()
  68. {
  69. $money = input('post.money');
  70. $user_id = input('post.user_id');
  71. $type = input('post.type');
  72. if ($money && $user_id) {
  73. $userInfo = Model('userinfo');
  74. $userMessage = Model('userMessage');
  75. $capitalMovements = Model('CapitalMovements');
  76. $getUserInfo = $userInfo->getUserInfo(['user_id' => $user_id]);
  77. $userInfo->startTrans();
  78. $userMessage->startTrans();
  79. $capitalMovements->startTrans();
  80. try {
  81. if ($type == 1) {
  82. $balance = $getUserInfo->userInfo_money + $money;
  83. $msg = '充值';
  84. } else {
  85. $balance = $getUserInfo->userInfo_money - $money;
  86. $msg = '扣款';
  87. }
  88. $userInfo->updateUserInfo(['user_id' => $user_id], ['userInfo_money' => $balance]);
  89. $nowDate = date('Y-m-d H:i:s');
  90. $userMessageData = [
  91. 'user_id' => $user_id,
  92. 'userMessage_title' => '充值消息',
  93. 'userMessage_content' => '后台管理员' . $msg . $money . '元',
  94. 'userMessage_create' => $nowDate,
  95. 'userMessage_update' => $nowDate,
  96. ];
  97. $userMessage->addMessage($userMessageData);
  98. $orderID = OrderID();
  99. $admin = session('admin_id');
  100. $cplMvtData = [
  101. 'user_id' => $user_id,
  102. 'capitalMovements_describe' => '后台管理员' . $msg . $money . '元',
  103. 'capitalMovements_identity' => $orderID,
  104. 'capitalMovements_create' => $nowDate,
  105. 'capitalMovements_update' => $nowDate,
  106. 'capitalMovements_money' => $money,
  107. 'capitalMovements_type' => $type,
  108. 'capitalMovements_cash' => $balance,
  109. 'capitalMovements_operator' => $admin,
  110. ];
  111. $capitalMovements->add($cplMvtData);
  112. $userInfo->commit();
  113. $userMessage->commit();
  114. $capitalMovements->commit();
  115. return ["msg" => $msg . "成功"];
  116. } catch (\Exception $e) {
  117. // 回滚事务
  118. $userInfo->rollBack();
  119. $userMessage->rollBack();
  120. $capitalMovements->rollBack();
  121. return ["msg" => "操作失败"];
  122. }
  123. } else {
  124. return ["msg" => "错误:请正确填写充值金额"];
  125. }
  126. }
  127. }