CreditWriteoff.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\finance\controller;
  4. use app\base\BaseController;
  5. use app\finance\model\CreditWriteoff as CreditWriteoffModel;
  6. use app\finance\validate\CreditWriteoffValidate;
  7. use think\exception\ValidateException;
  8. use think\facade\Db;
  9. use think\facade\View;
  10. class CreditWriteoff extends BaseController
  11. {
  12. protected $model;
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. $this->model = new CreditWriteoffModel();
  17. }
  18. public function datalist()
  19. {
  20. $param = get_params();
  21. if (request()->isAjax()) {
  22. $uid = $this->uid;
  23. $where = [];
  24. $whereOr = [];
  25. $where[] = ['delete_time', '=', 0];
  26. $tab = isset($param['tab']) ? (int) $param['tab'] : 0;
  27. if ($tab === 0) {
  28. $whereOr[] = ['admin_id', '=', $uid];
  29. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  30. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  31. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  32. } elseif ($tab === 1) {
  33. $where[] = ['admin_id', '=', $uid];
  34. } elseif ($tab === 2) {
  35. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  36. } elseif ($tab === 3) {
  37. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  38. } elseif ($tab === 4) {
  39. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  40. }
  41. if (!empty($param['keywords'])) {
  42. $where[] = ['customer_id', 'like', '%' . $param['keywords'] . '%'];
  43. }
  44. if (isset($param['check_status']) && $param['check_status'] !== '') {
  45. $where[] = ['check_status', '=', $param['check_status']];
  46. }
  47. if (!empty($param['diff_time'])) {
  48. $diff = explode('~', $param['diff_time']);
  49. $where[] = ['create_time', 'between', [strtotime(urldecode($diff[0])), strtotime(urldecode($diff[1] . ' 23:59:59'))]];
  50. }
  51. $list = $this->model->datalist($param, $where, $whereOr);
  52. return table_assign(0, '', $list);
  53. }
  54. return view();
  55. }
  56. public function add()
  57. {
  58. $param = get_params();
  59. if (request()->isAjax()) {
  60. if (!empty($param['id']) && $param['id'] > 0) {
  61. try {
  62. validate(CreditWriteoffValidate::class)->scene('edit')->check($param);
  63. } catch (ValidateException $e) {
  64. return to_assign(1, $e->getError());
  65. }
  66. $this->model->edit($param);
  67. } else {
  68. try {
  69. validate(CreditWriteoffValidate::class)->scene('add')->check($param);
  70. } catch (ValidateException $e) {
  71. return to_assign(1, $e->getError());
  72. }
  73. $param['admin_id'] = $this->uid;
  74. $param['did'] = $this->did;
  75. $this->model->add($param);
  76. }
  77. } else {
  78. $id = isset($param['id']) ? (int) $param['id'] : 0;
  79. $detail = [
  80. 'id' => 0,
  81. 'customer_id' => '',
  82. 'trade_scene' => '',
  83. 'daily_trade_vol' => '',
  84. 'credit_amount' => '',
  85. 'return_date' => '',
  86. 'remark' => '',
  87. 'file_ids' => '',
  88. 'check_status' => 0,
  89. 'check_flow_id' => 0,
  90. ];
  91. if ($id > 0) {
  92. $detail = $this->model->getById($id);
  93. }
  94. View::assign('detail', $detail);
  95. return view();
  96. }
  97. }
  98. public function view($id)
  99. {
  100. $detail = $this->model->getById($id);
  101. if (!empty($detail)) {
  102. View::assign('create_user', get_admin($detail['admin_id']));
  103. View::assign('detail', $detail);
  104. return view();
  105. }
  106. return view(EEEOR_REPORTING, ['code' => 404, 'warning' => '找不到页面']);
  107. }
  108. public function del()
  109. {
  110. $param = get_params();
  111. $id = isset($param['id']) ? (int) $param['id'] : 0;
  112. if (request()->isDelete()) {
  113. return $this->model->delById($id);
  114. }
  115. return to_assign(1, '错误的请求');
  116. }
  117. }