Loan.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\finance\controller;
  15. use app\base\BaseController;
  16. use app\finance\model\Loan as LoanModel;
  17. use app\finance\validate\LoanValidate;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Loan extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new LoanModel();
  31. }
  32. /**
  33. * 数据列表
  34. */
  35. public function datalist()
  36. {
  37. $param = get_params();
  38. if (request()->isAjax()) {
  39. $tab = isset($param['tab']) ? $param['tab'] : 0;
  40. $uid = $this->uid;
  41. $where = array();
  42. $whereOr = array();
  43. $where[]=['delete_time','=',0];
  44. if($tab == 0){
  45. //全部
  46. $auth = isAuthLoan($uid);
  47. if($auth == 0){
  48. $whereOr[] = ['admin_id', '=', $this->uid];
  49. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  50. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  51. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  52. $dids_a = get_leader_departments($uid);
  53. $dids_b = get_role_departments($uid);
  54. $dids = array_merge($dids_a, $dids_b);
  55. if(!empty($dids)){
  56. $whereOr[] = ['did','in',$dids];
  57. }
  58. }
  59. }
  60. if($tab == 1){
  61. //我创建的
  62. $where[] = ['admin_id', '=', $this->uid];
  63. }
  64. if($tab == 2){
  65. //待我审核的
  66. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  67. }
  68. if($tab == 3){
  69. //我已审核的
  70. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  71. }
  72. if($tab == 4){
  73. //抄送给我的
  74. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  75. }
  76. if($tab == 5){
  77. //已打款的
  78. $where[] = ['pay_status', '=', 1];
  79. $auth = isAuthLoan($uid);
  80. if($auth == 0){
  81. $dids_a = get_leader_departments($uid);
  82. $dids_b = get_role_departments($uid);
  83. $dids = array_merge($dids_a, $dids_b);
  84. if(!empty($dids)){
  85. $whereOr[] = ['did','in',$dids];
  86. }
  87. $whereOr[] = ['admin_id', '=', $this->uid];
  88. }
  89. }
  90. //按时间检索
  91. if (!empty($param['diff_time'])) {
  92. $diff_time =explode('~', $param['diff_time']);
  93. $where[] = ['create_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
  94. }
  95. if (isset($param['pay_status']) && $param['pay_status'] != "") {
  96. $where[] = ['pay_status', '=', $param['pay_status']];
  97. }
  98. if (isset($param['check_status']) && $param['check_status'] != "") {
  99. $where[] = ['check_status', '=', $param['check_status']];
  100. }
  101. $list = $this->model->datalist($param,$where,$whereOr);
  102. return table_assign(0, '', $list);
  103. }
  104. else{
  105. return view();
  106. }
  107. }
  108. /**
  109. * 添加/编辑
  110. */
  111. public function add()
  112. {
  113. $param = get_params();
  114. if (request()->isAjax()) {
  115. $param['loan_time'] = isset($param['loan_time']) ? strtotime(urldecode($param['loan_time'])) : 0;
  116. $param['plan_time'] = isset($param['plan_time']) ? strtotime(urldecode($param['plan_time'])) : 0;
  117. $param['admin_id'] = $this->uid;
  118. $param['did'] = $this->did;
  119. if (!empty($param['id']) && $param['id'] > 0) {
  120. try {
  121. validate(LoanValidate::class)->scene('edit')->check($param);
  122. } catch (ValidateException $e) {
  123. // 验证失败 输出错误信息
  124. return to_assign(1, $e->getError());
  125. }
  126. $this->model->edit($param);
  127. } else {
  128. try {
  129. validate(LoanValidate::class)->scene('add')->check($param);
  130. } catch (ValidateException $e) {
  131. // 验证失败 输出错误信息
  132. return to_assign(1, $e->getError());
  133. }
  134. $this->model->add($param);
  135. }
  136. }else{
  137. $id = isset($param['id']) ? $param['id'] : 0;
  138. $is_codeno = Db::name('DataAuth')->where('name','finance_admin')->value('conf_9');
  139. View::assign('is_codeno', $is_codeno);
  140. View::assign('user', get_admin($this->uid));
  141. if ($id>0) {
  142. $detail = $this->model->getById($id);
  143. View::assign('detail', $detail);
  144. if(is_mobile()){
  145. return view('qiye@/finance/add_loan');
  146. }
  147. return view('edit');
  148. }
  149. $codeno='';
  150. if($is_codeno==1){
  151. $codeno = get_codeno(4);
  152. }
  153. View::assign('codeno', $codeno);
  154. if(is_mobile()){
  155. return view('qiye@/finance/add_loan');
  156. }
  157. return view();
  158. }
  159. }
  160. /**
  161. * 查看
  162. */
  163. public function view($id)
  164. {
  165. $detail = $this->model->getById($id);
  166. if (!empty($detail)) {
  167. $detail['expense'] = Db::name('Expense')->where(['delete_time'=>0,'loan_id'=>$id])->select()->toArray();
  168. View::assign('detail', $detail);
  169. View::assign('create_user', get_admin($detail['admin_id']));
  170. if(is_mobile()){
  171. return view('qiye@/finance/view_loan');
  172. }
  173. return view();
  174. }
  175. else{
  176. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  177. }
  178. }
  179. /**
  180. * 删除
  181. */
  182. public function del()
  183. {
  184. $param = get_params();
  185. $id = isset($param['id']) ? $param['id'] : 0;
  186. if (request()->isDelete()) {
  187. $this->model->delById($id);
  188. } else {
  189. return to_assign(1, "错误的请求");
  190. }
  191. }
  192. //借支记录
  193. public function record()
  194. {
  195. if (request()->isAjax()) {
  196. $param = get_params();
  197. $where = [];
  198. $where[]=['delete_time','=',0];
  199. $where[]=['check_status','=',2];
  200. if(isAuthLoan($this->uid)==0){
  201. $where[] = ['admin_id', '=', $this->uid];
  202. }
  203. //按时间检索
  204. if (!empty($param['diff_time'])) {
  205. $diff_time =explode('~', $param['diff_time']);
  206. $where[] = ['loan_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
  207. }
  208. if (isset($param['pay_status']) && $param['pay_status'] != "") {
  209. $where[] = ['pay_status', '=', $param['pay_status']];
  210. }
  211. $list = $this->model->datalist($param,$where);
  212. $cost = $this->model::where($where)->sum('cost');
  213. $totalRow['cost'] = sprintf("%.2f",$cost);
  214. return table_assign(0, '', $list);
  215. } else {
  216. View::assign('isAuthLoan',isAuthLoan($this->uid));
  217. return view();
  218. }
  219. }
  220. }