Web Interfaces of PROSUME

XhrController.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Controller;
  3. class XhrController extends SSPController
  4. {
  5. public function transfer()
  6. {
  7. if( $this->request->is('ajax') ) {
  8. $request = $this->getRequestInput();
  9. if(!$user = $this->Auth->user())
  10. {
  11. return $this->response
  12. ->withStatus(401);
  13. }
  14. $_ = $this->EprosumeModel->meterList($user["meter_id"]);
  15. $role = $user["role"] ?? null;
  16. $meter_name = $_["name"] ?? null;
  17. if(!$meter_name) {
  18. return $this->response
  19. ->withStatus(403);
  20. }
  21. return $this->doTransfer(
  22. $meter_name,
  23. $request["prosumer"] ?? null,
  24. $request["amount"] ?? null,
  25. $request["asset"] ?? null,
  26. $request["memo"] ?? null
  27. );
  28. } else {
  29. return null;
  30. }
  31. }
  32. public function setPrice()
  33. {
  34. if( $this->request->is('ajax') ) {
  35. $request = $this->getRequestInput();
  36. $user = $this->Auth->user();
  37. if(!$user || $user['role'] != 'admin')
  38. {
  39. return $this->response
  40. ->withStatus(401);
  41. }
  42. return $this->doSetPrice(
  43. $request["prosumer"] ?? null,
  44. $request["buyPrice"] ?? null,
  45. $request["sellPrice"] ?? null
  46. );
  47. }
  48. return null;
  49. }
  50. public function history()
  51. {
  52. return $this->setResponse("history");
  53. }
  54. public function historyTransfer()
  55. {
  56. return $this->setResponse("historyTransfer");
  57. }
  58. public function payment()
  59. {
  60. return $this->setResponse("payment");
  61. }
  62. public function priceHistory()
  63. {
  64. return $this->setResponse("priceHistory");
  65. }
  66. public function setResponse($SSPResponse)
  67. {
  68. if(!$user = $this->Auth->user())
  69. {
  70. return $this->response
  71. ->withStatus(401);
  72. }
  73. $_ = $this->EprosumeModel->meterList($user["meter_id"]);
  74. $role = $user["role"] ?? null;
  75. if($role == "admin") {
  76. $meter_name = null;
  77. } else {
  78. $meter_name = $_["name"] ?? null;
  79. if(!$meter_name) {
  80. return $this->response
  81. ->withStatus(403);
  82. }
  83. }
  84. return $this->SSPResponse($SSPResponse, $meter_name);
  85. }
  86. public function chartsPayments($meter_name)
  87. {
  88. if( $this->request->is('ajax') ) {
  89. return $this->charts('payments', $meter_name);
  90. } else {
  91. return null;
  92. }
  93. }
  94. }