MoneyLog.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller\user;
  4. use app\common\controller\Backend;
  5. use app\admin\traits\Actions;
  6. use think\annotation\route\Group;
  7. use think\annotation\route\Route;
  8. use think\facade\Db;
  9. use app\common\model\MoneyLog as MoneyLogModel;
  10. #[Group("user/money_log")]
  11. class MoneyLog extends Backend
  12. {
  13. use Actions{
  14. edit as private _edit;
  15. multi as private _multi;
  16. import as private _import;
  17. }
  18. protected function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new MoneyLogModel();
  22. //$this->assign('typeList', site_config('addonsd.money_in_type'));
  23. $list = site_config('addonsd.money_out_type');
  24. //dump( $list);die;
  25. $this->assign('bankList', site_config('addonsd.bank_account'));
  26. $this->relationField=['users'];
  27. }
  28. //查看
  29. #[Route('GET,JSON','index')]
  30. public function index()
  31. {
  32. if (false === $this->request->isAjax()) {
  33. return $this->fetch();
  34. }
  35. if($this->request->post('selectpage')){
  36. return $this->selectpage();
  37. }
  38. [$where, $order, $limit, $with] = $this->buildparams();
  39. $list = $this->model
  40. ->withJoin($with,'left')
  41. //如果没有使用operate filter过滤的情况下,推荐使用with关联,可以提高查询效率
  42. ->where('money_log.status', 1)
  43. ->where($where)
  44. ->order($order)
  45. ->paginate($limit);
  46. $result = ['total' => $list->total(), 'rows' => $list->items()];
  47. return json($result);
  48. }
  49. //修改
  50. #[Route("GET,POST","edit")]
  51. public function edit()
  52. {
  53. if(!$this->request->isPost()){
  54. $catelist= site_config('addonsd.money_in_type');;
  55. $this->assign('parentList',$catelist);
  56. }
  57. return $this->_edit();
  58. }
  59. //删除
  60. #[Route("GET,POST","del")]
  61. public function del()
  62. {
  63. $ids = $this->request->param("ids");
  64. if (empty($ids)) {
  65. $this->error(__('参数%s不能为空', ['s'=>'ids']));
  66. }
  67. $pk = $this->model->getPk();
  68. $list = $this->model->where($pk, 'in', $ids)->select();
  69. $count = 0;
  70. Db::startTrans();
  71. try {
  72. foreach ($list as $item) {
  73. if(count($this->volidateFields)>0){
  74. foreach ($this->volidateFields as $field=>$value){
  75. if($item[$field]!=$value){
  76. $this->error(__('没有操作权限'));
  77. }
  78. }
  79. }
  80. $item->status=0;
  81. $count += $item->save();
  82. }
  83. if($this->callback){
  84. $callback=$this->callback;
  85. $callback($ids);
  86. }
  87. Db::commit();
  88. } catch (\Exception $e) {
  89. Db::rollback();
  90. $this->error($e->getMessage());
  91. }
  92. if ($count) {
  93. $this->success();
  94. }
  95. $this->error(__('没有记录被删除'));
  96. }
  97. //更新
  98. #[Route("GET,POST","multi")]
  99. public function multi()
  100. {
  101. //通过定义callback回调函数来执行更新后的操作
  102. $this->callback=function ($ids,$field,$value){};
  103. return $this->_multi();
  104. }
  105. //导入
  106. #[Route("GET,POST","import")]
  107. public function import()
  108. {
  109. //通过定义callback回调函数来处理导入的数据
  110. $this->callback=function ($inserData){
  111. return $inserData;
  112. };
  113. return $this->_import();
  114. }
  115. }