SeatingController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace app\admin\controller\kefu;
  3. use think\exception\ValidateException;
  4. use app\model\Users;
  5. use app\model\kefu\Seating;
  6. use app\model\kefu\Seatinggroups;
  7. use dh2y\qrcode\QRcode;
  8. class SeatingController extends Base
  9. {
  10. function index()
  11. {
  12. $keyword = input('post.keyword', '', 'serach_in');
  13. $status = input('post.status', '', 'serach_in');
  14. $weid = weid();
  15. $where = [];
  16. $where['weid'] = $weid;
  17. if ($status !== '') {
  18. $where['status'] = $status;
  19. }
  20. $field = 'id,title,touxiang,setopenidqrcode,status,px';
  21. $query = Seating::where($where);
  22. if (!empty($keyword)) {
  23. $query->where('title', 'like', '%' . $keyword . '%');
  24. }
  25. $res = $query->field($field)
  26. ->order('id desc')
  27. ->paginate(getpage())
  28. ->toArray();
  29. $qrcod = new QRcode();
  30. foreach ($res['data'] as &$vo) {
  31. if (empty($vo['setopenidqrcode'])) {
  32. $qrcodeurl = gethost() . scriptPath() . '/public/index.php?s=/index/member/setseatingopenid&xmtoken=' . $this->getToken() . '&seaid=' . $vo['id']. '&i=' . $weid;
  33. $qrcodres = $qrcod->png($qrcodeurl, false, 10)->getPath();
  34. $vo['setopenidqrcode'] = toimg('/public' . $qrcodres);
  35. Seating::update($vo);
  36. }
  37. }
  38. $data['data'] = $res;
  39. return $this->json($data);
  40. }
  41. function listUpdate()
  42. {
  43. $data = only('id,status');
  44. if (!$data['id']) throw new ValidateException('参数错误');
  45. Seating::update($data);
  46. return $this->json(['msg' => '操作成功']);
  47. }
  48. public function update()
  49. {
  50. $id = $this->request->post('id');
  51. $data = $this->postdata();
  52. if (empty($id)) {
  53. $weid = weid();
  54. $data['uid'] = (int) $data['uid'];
  55. $data['weid'] = $weid;
  56. $res = Seating::create($data);
  57. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  58. } else {
  59. Seating::update($data);
  60. return $this->json(['msg' => '修改成功']);
  61. }
  62. }
  63. function postdata()
  64. {
  65. $data = $this->request->post();
  66. if (!empty($data['kefutype'])) {
  67. if (in_array("is_mpkefu", $data['kefutype'])) {
  68. $data['is_mpkefu'] = "1";
  69. } else {
  70. $data['is_mpkefu'] = "0";
  71. }
  72. if (in_array("is_mobilekefu", $data['kefutype'])) {
  73. $data['is_mobilekefu'] = "1";
  74. } else {
  75. $data['is_mobilekefu'] = "0";
  76. }
  77. if (in_array("is_wxappkefu", $data['kefutype'])) {
  78. $data['is_wxappkefu'] = "1";
  79. } else {
  80. $data['is_wxappkefu'] = "0";
  81. }
  82. if (in_array("is_webkefu", $data['kefutype'])) {
  83. $data['is_webkefu'] = "1";
  84. } else {
  85. $data['is_webkefu'] = "0";
  86. }
  87. }
  88. if (!empty($data['week'])) {
  89. $arr = $data['week'];
  90. foreach ($arr as $key => $v) {
  91. $week .= $v . ',';
  92. }
  93. $slweek = rtrim($week, ",");
  94. $data['week'] = $slweek;
  95. }
  96. if (empty($data['week'])) {
  97. $data['week'] = '0';
  98. }
  99. return $data;
  100. }
  101. function getInfo()
  102. {
  103. $id = $this->request->post('id', '', 'serach_in');
  104. if (!$id) $this->error('参数错误');
  105. $res = Seating::find($id)->toArray();
  106. if ($res['is_mpkefu']) {
  107. $res['kefutype'][] = 'is_mpkefu';
  108. }
  109. if ($res['is_mobilekefu']) {
  110. $res['kefutype'][] = 'is_mobilekefu';
  111. }
  112. if ($res['is_wxappkefu']) {
  113. $res['kefutype'][] = 'is_wxappkefu';
  114. }
  115. if ($res['is_webkefu']) {
  116. $res['kefutype'][] = 'is_webkefu';
  117. }
  118. $res['week'] = explode(',', $res['week']);
  119. return $this->json(['data' => $res]);
  120. }
  121. function getField()
  122. {
  123. $data['userslist'] = Users::getallarray();
  124. $data['groups'] = Seatinggroups::getallarray();
  125. return $this->json(['data' => $data]);
  126. }
  127. function delete()
  128. {
  129. return $this->del(new Seating());
  130. }
  131. }