Financial.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller\cpuser;
  4. use app\admin\BaseController;
  5. use app\admin\model\Department as DepartmentModel;
  6. use app\admin\validate\FinancialValidate;
  7. use think\exception\ValidateException;
  8. use think\facade\Db;
  9. use think\facade\View;
  10. class Financial extends BaseController
  11. {
  12. /**
  13. * 构造函数
  14. */
  15. public function __construct()
  16. {
  17. $this->model = new DepartmentModel();
  18. $this->uid = get_login_admin('id');
  19. }
  20. /**
  21. * 数据列表
  22. */
  23. public function datalist()
  24. {
  25. if (request()->isAjax()) {
  26. $param = get_params();
  27. $where = [
  28. ["delete_time","=",0],
  29. ["pid","=",0],
  30. ["type","=",0]
  31. ];
  32. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  33. $order = empty($param['order']) ? 'id desc' : $param['order'];
  34. $list = $this->model->where($where)->field('id,title,leader_id,phone,landline,address,company_type,authorization_module')
  35. ->order($order)->paginate($rows, false, ['query' => $param])
  36. ->each(function ($item){
  37. $data = Db::name("admin")->where("id",$item->leader_id)->find();
  38. if(!empty($data["nickname"])){
  39. $item->leader =$data["nickname"];
  40. }
  41. if(!empty($data["username"])){
  42. $item->username = $data["username"];
  43. }
  44. if(!empty($data["mobile"])){
  45. $item->phone = $data["mobile"];
  46. }
  47. });
  48. // halt($list);
  49. return table_assign(0, '', $list);
  50. }
  51. else{
  52. return view();
  53. }
  54. }
  55. /**
  56. * 添加
  57. */
  58. public function add()
  59. {
  60. if (request()->isAjax()) {
  61. $param = get_params();
  62. // 检验完整性
  63. // try {
  64. // validate(FinancialValidate::class)->check($param);
  65. // } catch (ValidateException $e) {
  66. // // 验证失败 输出错误信息
  67. // return to_assign(1, $e->getError());
  68. // }
  69. $param = array_merge($param,['type'=>0]);
  70. try {
  71. $did = Db::name('Department')->strict(false)->field(true)->insertGetId($param);
  72. $pid = $did;
  73. while($pid != 0){
  74. $value = Db::name('department')->where('id', $pid)->column('id,pid,title')[0];
  75. $unit_name = $value['id'];
  76. $pid = $value['pid'];
  77. $title = $value['title'];
  78. }
  79. $unit_name = [
  80. 'unit_name' => $unit_name,
  81. ];
  82. Db::name('Department')->where('id', $did)->update($unit_name);
  83. add_log('add', $did, $param);
  84. } catch(\Exception $e) {
  85. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  86. }
  87. return to_assign(0,'操作成功');
  88. // halt($param);
  89. }else{
  90. return view();
  91. }
  92. }
  93. /**
  94. * 编辑
  95. */
  96. public function edit()
  97. {
  98. $param = get_params();
  99. // halt($param);
  100. if (request()->isAjax()) {
  101. // 检验完整性
  102. // try {
  103. // validate(FinancialValidate::class)->check($param);
  104. // } catch (ValidateException $e) {
  105. // // 验证失败 输出错误信息
  106. // return to_assign(1, $e->getError());
  107. // }
  108. try {
  109. $param['update_time'] = time();
  110. $this->model->where('id', $param['id'])->strict(false)->field(true)->update($param);
  111. add_log('edit', $param['id'], $param);
  112. } catch(\Exception $e) {
  113. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  114. }
  115. return to_assign();
  116. }else{
  117. $id = isset($param['id']) ? $param['id'] : 0;
  118. $detail = $this->model->where('id', $id)->find();
  119. if (!empty($detail)) {
  120. View::assign('detail', $detail);
  121. return view();
  122. }
  123. else{
  124. throw new \think\exception\HttpException(404, '找不到页面');
  125. }
  126. }
  127. }
  128. /**
  129. * 查看信息
  130. */
  131. public function read()
  132. {
  133. $param = get_params();
  134. $id = isset($param['id']) ? $param['id'] : 0;
  135. $detail = $this->model->where('id', $id)->find();
  136. if (!empty($detail)) {
  137. View::assign('detail', $detail);
  138. return view();
  139. }
  140. else{
  141. throw new \think\exception\HttpException(404, '找不到页面');
  142. }
  143. }
  144. /**
  145. * 删除
  146. * type=0,逻辑删除,默认
  147. * type=1,物理删除
  148. */
  149. public function del()
  150. {
  151. $param = get_params();
  152. $id = isset($param['id']) ? $param['id'] : 0;
  153. $type = isset($param['type']) ? $param['type'] : 0;
  154. if($type==0){
  155. //逻辑删除
  156. try {
  157. $param['delete_time'] = time();
  158. $this->model->where('id', $id)->update(['delete_time'=>time()]);
  159. add_log('delete', $id);
  160. } catch(\Exception $e) {
  161. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  162. }
  163. }
  164. else{
  165. //物理删除
  166. try {
  167. $this->model->where('id', $id)->delete();
  168. add_log('delete', $id);
  169. } catch(\Exception $e) {
  170. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  171. }
  172. }
  173. return to_assign();
  174. }
  175. }