SeedEnergyPool.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace addons\Seed\common\models;
  3. use addons\Seed\common\enums\SeedEnum;
  4. use common\enums\StatusEnum;
  5. use Yii;
  6. use yii\db\Exception;
  7. /**
  8. * This is the model class for table "{{%addons_seed_energy_pool}}".
  9. *
  10. * @property int $id ID
  11. * @property int $mall_id 商城ID
  12. * @property int $release_num 第N次能量池释放
  13. * @property int|null $total_seed_num 本次释放种子金总数量
  14. * @property float|null $release_energy_pool 释放能量池总额
  15. * @property float|null $unit_price 释放的增长值,单位:元
  16. * @property int $release_at 释放时间
  17. * @property string $reason 失败原因
  18. * @property int $release_status 释放状态【0:释放中 1释放成功 2释放失败】
  19. * @property int $status 状态【1启用 0禁用 -1删除】
  20. * @property int $created_at 创建时间
  21. * @property int $updated_at 更新数据时间
  22. */
  23. class SeedEnergyPool extends \common\models\base\BaseActiveRecord
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%addons_seed_energy_pool}}';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['mall_id', 'release_num', 'total_seed_num', 'release_at', 'release_status', 'status', 'created_at', 'updated_at'], 'integer'],
  39. [['release_energy_pool', 'unit_price'], 'number'],
  40. [['reason'], 'string'],
  41. ];
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'id' => 'ID',
  50. 'mall_id' => '商城ID',
  51. 'release_num' => '第N次能量池释放',
  52. 'total_seed_num' => '本次释放种子金总数量',
  53. 'release_energy_pool' => '释放能量池总额',
  54. 'unit_price' => '释放的增长值,单位:元',
  55. 'release_at' => '释放时间',
  56. 'reason' => '释放失败原因',
  57. 'release_status' => '[0:释放中,1:释放成功,2:释放失败]',
  58. 'status' => '状态【1启用 0禁用 -1删除】',
  59. 'created_at' => '创建时间',
  60. 'updated_at' => '更新数据时间',
  61. ];
  62. }
  63. /**
  64. * 保存数据
  65. * @Author: lun
  66. * @DateTime: 2022/8/1 0001 18:40
  67. * @Copyright: copyright (c) 2021 广东七件事集团
  68. * @param $params
  69. * @return array|bool
  70. */
  71. public static function setData($params)
  72. {
  73. try {
  74. $model = new self();
  75. $model->loadDefaultValues();
  76. if ($params['release_energy_pool'] <= 0 && $params['unit_price'] <= 0) {
  77. $model->release_status = SeedEnum::RELEASE_FAIL;
  78. $model->reason = '本次释放的能量池总额不足';
  79. }
  80. if (!$model->load($params, '') || !$model->save())throw new Exception($model->getErrorMessage());
  81. return $model->toArray();
  82. } catch (\Exception $e) {
  83. self::setStaticError($e->getMessage());
  84. return false;
  85. }
  86. }
  87. }