PointLog.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 中闽 < 1464674022@qq.com >
  5. * Date: 2019/12/5
  6. * Time: 17:44
  7. */
  8. namespace app\admin\controller;
  9. use app\admin\controller\base\Permissions;
  10. use app\common\model\PointLog as pointLogModel;
  11. use think\Db;
  12. class PointLog extends Permissions
  13. {
  14. public function index()
  15. {
  16. if ($this->request->isAjax()) {
  17. $post = $this->request->param();
  18. $where = [];
  19. if (isset($post['user_id']) and !empty($post['user_id'])) {
  20. $where['user_id'] = $post['user_id'];
  21. }
  22. if (isset($post['type']) and !empty($post['type'])) {
  23. $where['type'] = $post['type'];
  24. }
  25. if (isset($post['create_time']) and !empty($post['create_time'])) {
  26. $timerang = explode(' - ', $post['create_time']);
  27. $min_time = strtotime($timerang[0]);
  28. $max_time = strtotime($timerang[1]);
  29. $where['create_time'] = [['>=', $min_time], ['<=', $max_time]];
  30. }
  31. $model = new pointLogModel();
  32. $count = $model->count();
  33. $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('create_time desc')->select();
  34. foreach ($data as $k => $v) {
  35. $v['type_text'] = $v->type_text;
  36. $data[$k] = $v;
  37. }
  38. return array('code' => 0, 'count' => $count, 'data' => $data);
  39. } else {
  40. $this->assign("types", pointLogModel::TYPES);
  41. return $this->fetch();
  42. }
  43. }
  44. public function deletes()
  45. {
  46. if ($this->request->isAjax()) {
  47. $post = $this->request->param();
  48. $ids = $post['ids'];
  49. // 启动事务
  50. Db::startTrans();
  51. try {
  52. $model = new pointLogModel();
  53. if ($model->where('id', 'in', $ids)->delete()) {
  54. }
  55. // 提交事务
  56. Db::commit();
  57. } catch (\Exception $e) {
  58. // 回滚事务
  59. Db::rollback();
  60. $this->error('删除失败');
  61. }
  62. $this->success('删除成功');
  63. }
  64. }
  65. }