IntegralRechargeController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\modules\admin\controllers;
  3. use app\models\IntegralRecharge;
  4. use app\modules\admin\models\IntegralRechargeForm;
  5. use app\modules\admin\models\IntegralReOrderForm;
  6. use app\modules\admin\models\q_and_a\IntegralRechargeListForm;
  7. class IntegralRechargeController extends BaseController
  8. {
  9. public function actionList()
  10. {
  11. $form = new IntegralRechargeListForm();
  12. $form->attributes = get_params();
  13. $form->store_id = get_store_id();
  14. return $this->asJson($form->search());
  15. }
  16. public function actionInfo($id = null)
  17. {
  18. return $this->asJson([
  19. 'code' => 0,
  20. 'data' => [
  21. 'model' => IntegralRecharge::findOne($id)
  22. ]
  23. ]);
  24. }
  25. public function actionEdit()
  26. {
  27. $id = post_params('id');
  28. $model = IntegralRecharge::findOne(['id' => $id, 'is_delete' => 0, 'store_id' => get_store_id()]);
  29. if (!$model) {
  30. $model = new IntegralRecharge();
  31. }
  32. if (\Yii::$app->request->isPost) {
  33. $form = new IntegralRechargeForm();
  34. $form->model = $model;
  35. $form->store_id = get_store_id();
  36. $form->attributes = post_params();
  37. return $this->asJson($form->save());
  38. }
  39. }
  40. public function actionState($id = null, $state = 1)
  41. {
  42. $id = json_decode($id, true);
  43. foreach ($id as $v) {
  44. $model = IntegralRecharge::findOne($v);
  45. if (!$model) {
  46. return $this->asJson([
  47. 'code' => 1,
  48. 'msg' => '请刷新重试'
  49. ]);
  50. }
  51. $model->state = $state;
  52. $model->save();
  53. }
  54. return $this->asJson([
  55. 'code' => 0,
  56. 'msg' => '成功'
  57. ]);
  58. }
  59. public function actionDel($id = null)
  60. {
  61. $model = IntegralRecharge::findOne(['id' => $id, 'is_delete' => 0, 'store_id' => get_store_id()]);
  62. if (!$model) {
  63. return $this->asJson([
  64. 'code' => 1,
  65. 'msg' => '请刷新重试'
  66. ]);
  67. }
  68. $model->is_delete = 1;
  69. if ($model->save()) {
  70. return $this->asJson([
  71. 'code' => 0,
  72. 'msg' => '成功'
  73. ]);
  74. } else {
  75. foreach ($model->errors as $errors) {
  76. return $this->asJson([
  77. 'code' => 1,
  78. 'msg' => $errors[0],
  79. ]);
  80. }
  81. }
  82. }
  83. public function actionIntegralRechargeOrder()
  84. {
  85. $param = get_params();
  86. $form = new IntegralReOrderForm();
  87. $form->attributes = $param;
  88. $form->store_id = get_store_id();
  89. return $this->asJson($form->search());
  90. }
  91. }