PoolController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace addons\Seed\api\modules\v1\controllers;
  3. use addons\Seed\common\enums\SeedEnum;
  4. use addons\Seed\common\models\SeedCapitalStatistics;
  5. use addons\Seed\common\models\SeedOrder;
  6. use common\enums\StatusEnum;
  7. use Yii;
  8. use api\controllers\OnAuthController;
  9. /**
  10. * 默认控制器
  11. *
  12. * Class PoolController
  13. * @package addons\Seed\api\modules\v1\controllers
  14. */
  15. class PoolController extends OnAuthController
  16. {
  17. public $modelClass = '';
  18. /**
  19. * 不用进行登录验证的方法
  20. *
  21. * 例如: ['index', 'update', 'create', 'view', 'delete']
  22. * 默认全部需要验证
  23. *
  24. * @var array
  25. */
  26. protected $authOptional = ['index'];
  27. /**
  28. * 用户种子金
  29. * @return string
  30. */
  31. public function actionIndex()
  32. {
  33. $retuest = Yii::$app->request;
  34. if ($retuest->isGet) {
  35. // 能量池释放周期
  36. $release_cycle = Yii::$app->services->setting->addons->get($this->mall_id, SeedEnum::ADDONS_NAME, 'basic.release_cycle');
  37. // 种子金、能量池数据
  38. $statistics = SeedCapitalStatistics::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])->asArray()->one();
  39. $data['total_energy_pool'] = $statistics['total_energy_pool'];// 当前能量池能量
  40. $data['release_energy_pool'] = $statistics['release_energy_pool'];// 能量池累计释放总额
  41. $data['next_release_at'] = $statistics['last_release_at'] + 3600 * $release_cycle;// 下次释放时间
  42. $where = [];
  43. $where[] = ['=', 'mall_id', $this->mall_id];
  44. $where[] = ['=', 'status', StatusEnum::ENABLED];
  45. $with = ['user'];
  46. $params = array('where' => $where, 'select' => 'user_id,goods_name,created_at', 'with' => $with, 'order' => 'created_at desc', 'limit' => 100);
  47. $data['list'] = SeedOrder::lists($params, true);
  48. $this->success('获取成功', $data);
  49. }
  50. }
  51. }