TuanfoundController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\TuanFound;
  5. use app\model\TuanGoods;
  6. use app\model\TuanFollow;
  7. class TuanfoundController extends Base
  8. {
  9. function index()
  10. {
  11. $weid = weid();
  12. $keyword = input('post.keyword', '', 'serach_in');
  13. $query = TuanFound::where(['weid' => $weid]);
  14. if (!empty($keyword)) {
  15. $query->where('title', 'like', '%' . $keyword . '%');
  16. }
  17. if (!empty($this->sid)) {
  18. $query->where('sid', $this->sid);
  19. }
  20. $res = $query->order('id desc')
  21. ->paginate(getpage())
  22. ->toArray();
  23. foreach ($res['data'] as &$vo) {
  24. $vo['found_time'] = time_format($vo['found_time']);
  25. $vo['found_end_time'] = time_format($vo['found_end_time']);
  26. $vo['tuan_end_time'] = time_format($vo['tuan_end_time']);
  27. $vo['TuanGoods'] = TuanGoods::getTuanGoods($vo['tuan_id']);
  28. $vo['status'] = tuanFoundStatus($vo['status']);
  29. }
  30. $data['data'] = $res;
  31. return $this->json($data);
  32. }
  33. function listUpdate()
  34. {
  35. $data = only('id,status,sort');
  36. if (!$data['id']) throw new ValidateException('参数错误');
  37. TuanFound::update($data);
  38. return $this->json(['msg' => '操作成功']);
  39. }
  40. public function update()
  41. {
  42. $id = $this->request->post('id');
  43. $data = input('post.');
  44. unset($data['create_time']);
  45. if (!empty($id)) {
  46. try {
  47. TuanFound::update($data);
  48. } catch (\Exception $e) {
  49. throw new ValidateException($e->getMessage());
  50. }
  51. return $this->json(['msg' => '修改成功']);
  52. }
  53. }
  54. function getInfo()
  55. {
  56. $id = $this->request->post('id', '', 'serach_in');
  57. if (!$id) throw new ValidateException('参数错误');
  58. $data = TuanFound::find($id)->toArray();
  59. if (!empty($data['tuan_id'])) {
  60. $data['TuanGoods'] = TuanGoods::getTuanGoods($data['tuan_id']);
  61. }
  62. $data['TuanFollow'] = TuanFollow::getTuanFollow($data['id']);
  63. foreach ($data['TuanFollow'] as &$vo) {
  64. if($vo['pay_time']>0){
  65. $vo['pay_time'] = time_format($vo['pay_time']);
  66. }else{
  67. $vo['pay_time'] = '未支付';
  68. }
  69. $vo['is_robot'] = yesno($vo['is_robot']);
  70. $vo['status'] = tuanFoundStatus($vo['status']);
  71. }
  72. $data['found_time'] = time_format($data['found_time']);
  73. $data['found_end_time'] = time_format($data['found_end_time']);
  74. $data['tuan_end_time'] = time_format($data['tuan_end_time']);
  75. return $this->json(['data' => $data]);
  76. }
  77. function delete()
  78. {
  79. return $this->del(new TuanFound());
  80. }
  81. }