Worker.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\WorkerBalance;
  4. use think\App;
  5. use think\Db;
  6. use think\Exception;
  7. class Worker extends Auth {
  8. public function __construct(App $app = null) {
  9. parent::__construct($app);
  10. $this->model = new \app\common\model\Worker();
  11. }
  12. public function index() {
  13. if (request()->isAjax()) {
  14. //分页参数
  15. $length = input('rows', 10, 'intval'); //每页条数
  16. $page = input('page', 1, 'intval'); //第几页
  17. $title = input('title', '', 'trim');
  18. $map = [];
  19. if ($title) {
  20. $map['name'] = $title;
  21. }
  22. $recommend = input('recommend', '', 'trim');
  23. if ($recommend != '') {
  24. $map['recommend'] = $recommend;
  25. }
  26. $enable = input('enable', '', 'trim');
  27. if ($enable != '') {
  28. $map['enable'] = $enable;
  29. }
  30. $gender = input('gender', '', 'trim');
  31. if ($gender != '') {
  32. $map['gender'] = $gender;
  33. }
  34. //数据查询
  35. $result = $this->model->lists($this->orgId, $map, $page, $length);
  36. return json($result);
  37. }
  38. else {
  39. return $this->fetch();
  40. }
  41. }
  42. /**
  43. * 新增/编辑
  44. */
  45. public function add($id = 0) {
  46. $model = $this->model;
  47. if (request()->isPost()) {
  48. $res = $model->updates($this->orgId);
  49. if ($res) {
  50. $this->success('操作成功', url('index'));
  51. }
  52. else {
  53. $this->error($model->getError());
  54. }
  55. }
  56. else {
  57. $meta_title = '新增护工';
  58. if ($id) {
  59. $info = $model->getUserInfo($id);
  60. $this->assign('info', $info);
  61. $meta_title = '编辑护工';
  62. }
  63. $deps = model('Dep')->getList();
  64. $this->assign('deps', $deps);
  65. $roles = model('Roles')->getList(1);
  66. $this->assign('roles', $roles);
  67. $this->assign('meta_title', $meta_title);
  68. return $this->fetch();
  69. }
  70. }
  71. /**
  72. * 修改余额
  73. */
  74. public function edit_money($id = 0) {
  75. $model = new \app\common\model\Worker();
  76. $user_id = Db::name('worker')
  77. ->where('id',$id)
  78. ->value('user_id');
  79. if (request()->isPost()) {
  80. $balanceModel = new WorkerBalance();
  81. $data = request()->post();
  82. if ($data['balance'] > 0 || $data['balance'] < 0) {
  83. if ($data['balance'] > 0) {
  84. $type = 3;
  85. }
  86. else {
  87. $type = 4;
  88. }
  89. $res = $balanceModel->saveWorkerBalance($this->orgId,
  90. $data['balance'], $this->userId, $id, $type, $data['remark']);
  91. if ($res) {
  92. $this->success('操作成功', url('index'));
  93. }
  94. else {
  95. $this->error($balanceModel->getError());
  96. }
  97. }
  98. else {
  99. $this->success('操作成功', url('index'));
  100. }
  101. }
  102. else {
  103. $meta_title = '修改余额';
  104. if ($id) {
  105. $info = $model->getUserInfo($user_id);
  106. $this->assign('info', $info);
  107. $meta_title = '编辑护工';
  108. }
  109. $this->assign('meta_title', $meta_title);
  110. return $this->fetch();
  111. }
  112. }
  113. public function js_money($id) {
  114. $balanceModel = new WorkerBalance();
  115. $model = new \app\common\model\Worker();
  116. $user_id = Db::name('worker')
  117. ->where('id',$id)
  118. ->value('user_id');
  119. $info = $model->getUserInfo($user_id);
  120. $res = $balanceModel->saveWorkerBalance($this->orgId,
  121. -$info['balance'], $this->userId, $id, 2, '');
  122. if ($res) {
  123. $this->success('操作成功');
  124. }
  125. else {
  126. $this->error($balanceModel->getError());
  127. }
  128. }
  129. public function ye_log($id) {
  130. $list = Db::name('worker_balance')
  131. ->where('org_id', $this->orgId)
  132. ->where('worker_id', $id)
  133. ->order('id', 'desc')
  134. ->paginate(10, false, [
  135. 'query' => input()
  136. ]);
  137. $render = $list->render();
  138. $data = $list->toArray();
  139. foreach ($data['data'] as $k => $v) {
  140. $data['data'][$k]['uName'] = Db::name('user')
  141. ->where('id', $v['user_id'])
  142. ->value('real_name');
  143. }
  144. $this->assign('list', $data['data']);
  145. $this->assign('page', $render);
  146. $this->assign('meta_title', '余额记录');
  147. return $this->fetch();
  148. }
  149. /**
  150. * 删除记录
  151. * @param int $id
  152. */
  153. public function del($id = 0) {
  154. if (!$id) {
  155. $this->error('参数错误');
  156. }
  157. $res = db('user')->where('id', $id)->setField('del', 1);
  158. if ($res) {
  159. $this->success('删除成功');
  160. }
  161. else {
  162. $this->error('删除失败');
  163. }
  164. }
  165. /**
  166. * 改变字段值
  167. * @param int $fv
  168. * @param string $fn
  169. * @param int $fv
  170. */
  171. public function changeField($id = 0, $fn = '', $fv = 0) {
  172. if (!$fn || !$id) {
  173. $this->error('参数错误');
  174. }
  175. if ($fn == 'enable') {
  176. $res = Db::name('user')->where('id', $id)->update([$fn => $fv]);
  177. }
  178. else {
  179. $res = Db::name('worker')->where('id', $id)->update([$fn => $fv]);
  180. }
  181. if ($res) {
  182. $this->success('操作成功');
  183. }
  184. else {
  185. $this->error('操作失败');
  186. }
  187. }
  188. }