User.php 5.0 KB

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