AdmintechnicalController.php 2.9 KB

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