| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\controller\user;
- use app\common\controller\Backend;
- use app\admin\traits\Actions;
- use think\annotation\route\Group;
- use think\annotation\route\Route;
- use think\facade\Db;
- use app\common\model\MoneyLog as MoneyLogModel;
- #[Group("user/money_log")]
- class MoneyLog extends Backend
- {
- use Actions{
- edit as private _edit;
- multi as private _multi;
- import as private _import;
- }
- protected function _initialize()
- {
- parent::_initialize();
- $this->model = new MoneyLogModel();
- //$this->assign('typeList', site_config('addonsd.money_in_type'));
- $list = site_config('addonsd.money_out_type');
- //dump( $list);die;
- $this->assign('bankList', site_config('addonsd.bank_account'));
- $this->relationField=['users'];
- }
- //查看
- #[Route('GET,JSON','index')]
- public function index()
- {
- if (false === $this->request->isAjax()) {
- return $this->fetch();
- }
- if($this->request->post('selectpage')){
- return $this->selectpage();
- }
- [$where, $order, $limit, $with] = $this->buildparams();
- $list = $this->model
- ->withJoin($with,'left')
- //如果没有使用operate filter过滤的情况下,推荐使用with关联,可以提高查询效率
- ->where('money_log.status', 1)
- ->where($where)
- ->order($order)
- ->paginate($limit);
- $result = ['total' => $list->total(), 'rows' => $list->items()];
- return json($result);
- }
-
- //修改
- #[Route("GET,POST","edit")]
- public function edit()
- {
- if(!$this->request->isPost()){
- $catelist= site_config('addonsd.money_in_type');;
- $this->assign('parentList',$catelist);
- }
- return $this->_edit();
- }
-
- //删除
- #[Route("GET,POST","del")]
- public function del()
- {
- $ids = $this->request->param("ids");
- if (empty($ids)) {
- $this->error(__('参数%s不能为空', ['s'=>'ids']));
- }
- $pk = $this->model->getPk();
- $list = $this->model->where($pk, 'in', $ids)->select();
- $count = 0;
- Db::startTrans();
- try {
- foreach ($list as $item) {
- if(count($this->volidateFields)>0){
- foreach ($this->volidateFields as $field=>$value){
- if($item[$field]!=$value){
- $this->error(__('没有操作权限'));
- }
- }
- }
- $item->status=0;
- $count += $item->save();
- }
- if($this->callback){
- $callback=$this->callback;
- $callback($ids);
- }
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($count) {
- $this->success();
- }
- $this->error(__('没有记录被删除'));
- }
- //更新
- #[Route("GET,POST","multi")]
- public function multi()
- {
- //通过定义callback回调函数来执行更新后的操作
- $this->callback=function ($ids,$field,$value){};
- return $this->_multi();
- }
- //导入
- #[Route("GET,POST","import")]
- public function import()
- {
- //通过定义callback回调函数来处理导入的数据
- $this->callback=function ($inserData){
- return $inserData;
- };
- return $this->_import();
- }
- }
|