AdmintuanzhangController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace app\index\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Tuanzhang;
  5. use app\model\Category;
  6. use app\model\Order;
  7. use app\model\Openid;
  8. use app\model\UuidRelation;
  9. class AdmintuanzhangController extends Base
  10. {
  11. public function check()
  12. {
  13. $message = '';
  14. $is_login = 0;
  15. $data = Tuanzhang::getInfobyuid(UID());
  16. if ($data['status'] != 1) {
  17. $data = 0;
  18. $message = '请先登录!';
  19. } else {
  20. $is_login = 1;
  21. $data['statistical'] = $this->statistical($data['uuid']);
  22. }
  23. return $this->json(['message' => $message, 'is_login' => $is_login, 'data' => $data]);
  24. }
  25. public function statistical($uuid)
  26. {
  27. $query = Order::where(['weid' => weid(), 'ptype' => 2]);
  28. $withJoin = [
  29. 'staff' => ['order_id', 'uuid', 'title', 'end_time', 'begin_time'],
  30. ];
  31. $query->withJoin($withJoin, 'left');
  32. $query->where(['staff.uuid' => $uuid]);
  33. $query2 = $query;
  34. $statistical['status2'] = $query2->where('order_status_id', 2)->count();
  35. $query3 = $query;
  36. $statistical['status3'] = $query3->where('order_status_id', 3)->count();
  37. $query5 = $query;
  38. $statistical['status5'] = $query5->where('order_status_id', 5)->count();
  39. $query4 = $query;
  40. $statistical['status4'] = $query4->where('order_status_id', 4)->count();
  41. return $statistical;
  42. }
  43. public function business()
  44. {
  45. $id = $this->request->post('id');
  46. $Tuanzhang = Tuanzhang::find($id);
  47. if ($Tuanzhang->is_business == 1) {
  48. $Tuanzhang->is_business = 0;
  49. } else {
  50. $Tuanzhang->is_business = 1;
  51. }
  52. try {
  53. $Tuanzhang->save();
  54. $data = $Tuanzhang->toArray();
  55. $data['statistical'] = $this->statistical($data['uuid']);
  56. } catch (\Exception $e) {
  57. throw new ValidateException($e->getMessage());
  58. }
  59. return $this->json(['msg' => '操作成功', 'data' => $data]);
  60. }
  61. public function update()
  62. {
  63. $id = $this->request->post('id');
  64. $data = input('post.');
  65. try {
  66. Tuanzhang::update($data);
  67. } catch (\Exception $e) {
  68. throw new ValidateException($e->getMessage());
  69. }
  70. return $this->json(['msg' => '修改成功']);
  71. }
  72. function getInfo()
  73. {
  74. $uuid = UuidRelation::getuuid(UID(), 'tuanzhang');
  75. $data = Tuanzhang::where(['uuid' => $uuid])->find();
  76. if (!empty($data)) {
  77. $data = $data->toArray();
  78. } else {
  79. $data = Tuanzhang::where(['uid' => UID()])->find();
  80. if (!empty($data)) {
  81. $data = $data->toArray();
  82. if (!empty($uuid)) {
  83. Tuanzhang::where('id', $data['id'])->update(['uuid' => $uuid]);
  84. }
  85. }
  86. }
  87. if (!empty($data)) {
  88. $data = $data->toArray();
  89. }
  90. //空判定
  91. if (empty($data['cate_ids'])) {
  92. $data['cate_ids'] = [];
  93. } else {
  94. $data['cate_ids'] = explode(',', $data['cate_ids']);
  95. }
  96. $data['Category'] = Category::gettoparray();
  97. return $this->json(['data' => $data]);
  98. }
  99. }