Basic.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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\customer\controller;
  15. use app\base\BaseController;
  16. use app\customer\validate\BasicCustomerCheck;
  17. use think\exception\ValidateException;
  18. use think\facade\Db;
  19. use think\facade\View;
  20. class Basic extends BaseController
  21. {
  22. public function datalist()
  23. {
  24. if (request()->isAjax()) {
  25. $param = get_params();
  26. $where=[];
  27. if (!empty($param['types'])) {
  28. $where[] = ['types', '=', $param['types']];
  29. }
  30. $list = Db::name('BasicCustomer')->where($where)->order('create_time asc')->select();
  31. return to_assign(0, '', $list);
  32. } else {
  33. return view();
  34. }
  35. }
  36. //新建编辑
  37. public function add()
  38. {
  39. if (request()->isAjax()) {
  40. $param = get_params();
  41. if (!empty($param['id']) && $param['id'] > 0) {
  42. try {
  43. validate(BasicCustomerCheck::class)->scene('edit')->check($param);
  44. } catch (ValidateException $e) {
  45. // 验证失败 输出错误信息
  46. return to_assign(1, $e->getError());
  47. }
  48. $param['update_time'] = time();
  49. $res = Db::name('BasicCustomer')->strict(false)->field('title,types,id,update_time')->update($param);
  50. if ($res) {
  51. add_log('edit', $param['id'], $param);
  52. }
  53. return to_assign();
  54. } else {
  55. try {
  56. validate(BasicCustomerCheck::class)->scene('add')->check($param);
  57. } catch (ValidateException $e) {
  58. // 验证失败 输出错误信息
  59. return to_assign(1, $e->getError());
  60. }
  61. $param['create_time'] = time();
  62. $insertId = Db::name('BasicCustomer')->strict(false)->field('title,types,id,create_time')->insertGetId($param);
  63. if ($insertId) {
  64. add_log('add', $insertId, $param);
  65. }
  66. return to_assign();
  67. }
  68. }
  69. }
  70. //设置
  71. public function set()
  72. {
  73. $param = get_params();
  74. $res = Db::name('BasicCustomer')->strict(false)->field('id,status')->update($param);
  75. if ($res) {
  76. if($param['status'] == 0){
  77. add_log('disable', $param['id'], $param);
  78. }
  79. else if($param['status'] == 1){
  80. add_log('recovery', $param['id'], $param);
  81. }
  82. return to_assign();
  83. }
  84. else{
  85. return to_assign(0, '操作失败');
  86. }
  87. }
  88. }