User.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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_type'] == 1) {
  48. $user_list[$i]['user_type'] = '个人用户';
  49. }
  50. if ($user_list[$i]['user_type'] == 2) {
  51. $user_list[$i]['user_type'] = '企业用户';
  52. }
  53. }
  54. $allpower = $this->qxhans();
  55. $this->assign('allpower', $allpower);
  56. $this->assign('user_list', $user_list);
  57. $this->assign('show_page', $model_user->page_info->render());
  58. $this->setAdminCurItem('index');
  59. return $this->fetch();
  60. }
  61. public function userinfo()
  62. {
  63. $uid = intval(input("uid", 0));
  64. $model = (new Userinfo())->findOne($uid, 1);
  65. $this->assign('userinfo', $model);
  66. return $this->fetch();
  67. }
  68. public function recharge()
  69. {
  70. $money = input('post.money');
  71. $user_id = input('post.user_id');
  72. $type = input('post.type');
  73. if ($money && $user_id) {
  74. $userInfo = Model('userinfo');
  75. $userMessage = Model('userMessage');
  76. $capitalMovements = Model('CapitalMovements');
  77. $getUserInfo = $userInfo->getUserInfo(['user_id' => $user_id]);
  78. $userInfo->startTrans();
  79. $userMessage->startTrans();
  80. $capitalMovements->startTrans();
  81. try {
  82. if ($type == 1) {
  83. $balance = $getUserInfo->userInfo_money + $money;
  84. $msg = '充值';
  85. } else {
  86. $balance = $getUserInfo->userInfo_money - $money;
  87. $msg = '扣款';
  88. }
  89. $userInfo->updateUserInfo(['user_id' => $user_id], ['userInfo_money' => $balance]);
  90. $nowDate = date('Y-m-d H:i:s');
  91. $userMessageData = [
  92. 'user_id' => $user_id,
  93. 'userMessage_title' => '充值消息',
  94. 'userMessage_content' => '后台管理员' . $msg . $money . '元',
  95. 'userMessage_create' => $nowDate,
  96. 'userMessage_update' => $nowDate,
  97. ];
  98. $userMessage->addMessage($userMessageData);
  99. $orderID = OrderID();
  100. $admin = session('admin_id');
  101. $cplMvtData = [
  102. 'user_id' => $user_id,
  103. 'capitalMovements_describe' => '后台管理员' . $msg . $money . '元',
  104. 'capitalMovements_identity' => $orderID,
  105. 'capitalMovements_create' => $nowDate,
  106. 'capitalMovements_update' => $nowDate,
  107. 'capitalMovements_money' => $money,
  108. 'capitalMovements_type' => $type,
  109. 'capitalMovements_cash' => $balance,
  110. 'capitalMovements_operator' => $admin,
  111. ];
  112. $capitalMovements->add($cplMvtData);
  113. $userInfo->commit();
  114. $userMessage->commit();
  115. $capitalMovements->commit();
  116. return ["msg" => $msg . "成功"];
  117. } catch (\Exception $e) {
  118. // 回滚事务
  119. $userInfo->rollBack();
  120. $userMessage->rollBack();
  121. $capitalMovements->rollBack();
  122. return ["msg" => "操作失败"];
  123. }
  124. } else {
  125. return ["msg" => "错误:请正确填写充值金额"];
  126. }
  127. }
  128. }