Collect.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace app\admin\controller\reward;
  3. use app\common\controller\Backend;
  4. use app\common\library\Redis;
  5. use think\Controller;
  6. use think\Request;
  7. /**
  8. * 赏金统计管理
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Collect extends Backend
  13. {
  14. /**
  15. * RewardCollect模型对象
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = model('Admin');
  22. }
  23. /**
  24. * 查看
  25. */
  26. public function index()
  27. {
  28. //设置过滤方法
  29. $this->request->filter(['strip_tags']);
  30. //今日赏金
  31. $today = date('Ymd',time());
  32. $todaySum = model('reward_collect')->alias('r')->join('admin_extend e','r.admin_id=e.admin_id and r.invite_id=0 and e.create_by='.$this->auth->id)->where(['r.createdate'=>$today,'r.type'=>1,'r.flag'=>2])->sum('r.reward');
  33. $this->assign('todaySum',$todaySum);
  34. //累计赏金
  35. $totalSum = model('reward_collect')->alias('r')->join('admin_extend e','r.admin_id=e.admin_id and r.invite_id=0 and e.create_by='.$this->auth->id)->where(['r.type'=>2,'r.flag'=>2])->sum('r.reward');
  36. $this->assign('totalSum',$totalSum);
  37. if ($this->request->isAjax())
  38. {
  39. //如果发送的来源是Selectpage,则转发到Selectpage
  40. if ($this->request->request('pkey_name'))
  41. {
  42. return $this->selectpage();
  43. }
  44. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  45. $total = $this->model
  46. ->alias('a')
  47. ->join('admin_extend e','e.admin_id = a.id and e.create_by = '.$this->auth->id)
  48. ->where($where)
  49. ->where('a.status','normal')
  50. ->count();
  51. $list = $this->model
  52. ->alias('a')
  53. ->join('admin_extend e','e.admin_id = a.id and e.create_by = '.$this->auth->id)
  54. ->join("reward_collect t","t.admin_id=a.id and t.createdate='{$today}' and t.type='1' and t.flag='2'","left")
  55. ->join("reward_collect all","all.admin_id=a.id and all.type='2' and all.flag='2'","left")
  56. ->join("reward_money m","m.admin_id=a.id","left")
  57. ->field('a.*,e.reward_benefit,e.reward_state,t.reward as treward,all.reward as allreward,m.no_cash_money')
  58. ->where($where)
  59. ->where('a.status','normal')
  60. ->order($sort, $order)
  61. ->limit($offset, $limit)
  62. ->select();
  63. //dump($this->model->getLastSql());
  64. $result = array("total" => $total, "rows" => $list);
  65. return json($result);
  66. }
  67. return $this->view->fetch();
  68. }
  69. /**
  70. * 编辑
  71. */
  72. public function edit($ids = NULL)
  73. {
  74. $row = $this->model->alias('a')
  75. ->join('admin_extend e','e.admin_id = a.id')
  76. ->field('a.id,a.username,e.reward_benefit,e.reward_state')
  77. ->where('a.id',$ids)->find();
  78. $this->assign('reward_state',['0'=>'关闭','1'=>'打开']);
  79. if (!$row)
  80. $this->error(__('No Results were found'));
  81. $adminIds = $this->getDataLimitAdminIds();
  82. if (is_array($adminIds))
  83. {
  84. if (!in_array($row[$this->dataLimitField], $adminIds))
  85. {
  86. $this->error(__('You have no permission'));
  87. }
  88. }
  89. if ($this->request->isPost())
  90. {
  91. $params = $this->request->post("row/a");
  92. if ($params)
  93. {
  94. try
  95. {
  96. //是否采用模型验证
  97. if ($this->modelValidate)
  98. {
  99. $name = basename(str_replace('\\', '/', get_class($this->model)));
  100. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate;
  101. $row->validate($validate);
  102. }
  103. $result = model('AdminExtend')->save($params,['admin_id'=>$ids]);
  104. if ($result !== false)
  105. {
  106. $redis = Redis::instance();
  107. $key = 'AE:'.$ids;
  108. $redis->del($key);
  109. $this->success();
  110. }
  111. else
  112. {
  113. $this->error($row->getError());
  114. }
  115. }
  116. catch (\think\exception\PDOException $e)
  117. {
  118. $this->error($e->getMessage());
  119. }
  120. }
  121. $this->error(__('Parameter %s can not be empty', ''));
  122. }
  123. $this->view->assign("row", $row);
  124. return $this->view->fetch();
  125. }
  126. }