TuanzhangController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Tuanzhang;
  5. use app\model\TuanzhangLevel;
  6. use app\model\Category;
  7. use app\model\RegisterField;
  8. use app\model\Operatingcity;
  9. use app\model\Users;
  10. class TuanzhangController extends Base
  11. {
  12. function index()
  13. {
  14. $weid = weid();
  15. $page = input('post.page', 1, 'intval');
  16. $ptype = 'tuanzhang';
  17. $Fielddata = RegisterField::where(['weid' => $weid, 'ptype' => $ptype])->select()->toArray();
  18. if (empty($Fielddata)) {
  19. RegisterField::datainitial($ptype);
  20. }
  21. $query = $this->setSearch();
  22. $res = $query->order('sort asc,id desc')
  23. ->paginate(getpage())
  24. ->toArray();
  25. if (!empty($res['data'])) {
  26. foreach ($res['data'] as &$vo) {
  27. $vo = Tuanzhang::conversion($vo);
  28. }
  29. }
  30. $data['data'] = $res;
  31. if ($page == 1) {
  32. $data['field_data']['RegisterField'] = RegisterField::getlistViewField($ptype);
  33. }
  34. return $this->json($data);
  35. }
  36. function setSearch()
  37. {
  38. $keyword = trim(input('post.keyword', '', 'serach_in'));
  39. $status = input('post.status', '', 'serach_in');
  40. $path = input('post.path', '', 'serach_in');
  41. $weid = weid();
  42. if ($path == "/tuanzhang/audit") {
  43. $status = "0";
  44. }
  45. $query = Tuanzhang::where(['weid' => $weid]);
  46. if (!empty($this->sid)) {
  47. $query->where('sid', $this->sid);
  48. }
  49. if (!empty($this->ocid)) {
  50. $Operatingcitydata = Operatingcity::find($this->ocid);
  51. if ($Operatingcitydata) {
  52. $Operatingcitydata = $Operatingcitydata->toArray();
  53. if(empty($Operatingcitydata['areatype'])){
  54. $Operatingcitydata['areatype'] = 3;
  55. }
  56. if ($Operatingcitydata['areatype'] == 3) {
  57. $query->where('district_name', $Operatingcitydata['district_name']);
  58. } elseif ($Operatingcitydata['areatype'] == 2) {
  59. $query->where('city_name', $Operatingcitydata['city_name']);
  60. } elseif ($Operatingcitydata['areatype'] == 1) {
  61. $query->where('province_name', $Operatingcitydata['province_name']);
  62. }
  63. }
  64. }
  65. if (!empty($keyword)) {
  66. $query->where('title|tel', 'like', '%' . $keyword . '%');
  67. }
  68. if (!empty($status) || $status === "0") {
  69. $query->where(['status' => $status]);
  70. }
  71. return $query;
  72. }
  73. function listUpdate()
  74. {
  75. $data = only('id,status');
  76. if (!$data['id']) throw new ValidateException('参数错误');
  77. Tuanzhang::update($data);
  78. return $this->json(['msg' => '操作成功']);
  79. }
  80. function delete()
  81. {
  82. return $this->del(new Tuanzhang());
  83. }
  84. //导出
  85. function dumpdata()
  86. {
  87. $page = $this->request->post('page', 1, 'intval');
  88. $ptype = 'tuanzhang';
  89. $query = $this->setSearch();
  90. $data = RegisterField::dumpdata($query, $ptype, $page);
  91. return $this->json($data);
  92. }
  93. }