ScoreBonusCapitalPool.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace addons\ScoreBonus\common\models;
  3. use Exception;
  4. use Yii;
  5. /**
  6. * This is the model class for table "qimall_addons_score_bonus_capital_pool".
  7. *
  8. * @property int $id id
  9. * @property int $mall_id 商城id
  10. * @property float $bonus_price 当前分红池总额
  11. * @property float $total_price 已发放分红总额
  12. * @property int $status 状态
  13. * @property int|null $created_at 添加时间
  14. * @property int|null $updated_at 修改时间
  15. */
  16. class ScoreBonusCapitalPool extends \common\models\base\BaseActiveRecord
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName()
  22. {
  23. return 'qimall_addons_score_bonus_capital_pool';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['mall_id', 'bonus_price', 'total_price'], 'required'],
  32. [['mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
  33. [['bonus_price', 'total_price'], 'number'],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'mall_id' => 'Mall ID',
  44. 'bonus_price' => 'Bonus Price',
  45. 'total_price' => 'Total Price',
  46. 'status' => 'Status',
  47. 'created_at' => 'Created At',
  48. 'updated_at' => 'Updated At',
  49. ];
  50. }
  51. public static function setData(array $params)
  52. {
  53. try {
  54. if (!empty($params['id'])) {
  55. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id']]);
  56. if (empty($model)) throw new \Exception('服务不存在或已删除');
  57. } else {
  58. $model = new self();
  59. $model->loadDefaultValues();
  60. }
  61. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  62. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  63. return $model;
  64. } catch (Exception $e) {
  65. self::$static_error = $e->getMessage();
  66. return false;
  67. }
  68. }
  69. }