HappinessVoucherWallet.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace addons\Happiness\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "qimall_addons_happiness_voucher_wallet".
  7. *
  8. * @property int $id
  9. * @property int $level 商品标签权重
  10. * @property float $balance 提货券数量
  11. * @property float $freeze_balance 提货券数量
  12. * @property int $store_id 小店ID
  13. * @property int $mall_id 商城ID
  14. * @property int $status 状态:0:禁用,1:正常
  15. * @property int $created_at
  16. * @property int $updated_at
  17. */
  18. class HappinessVoucherWallet extends \common\models\base\BaseActiveRecord
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static function tableName()
  24. {
  25. return 'qimall_addons_happiness_voucher_wallet';
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['level', 'store_id', 'mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
  34. [['balance','freeze_balance'], 'number'],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'level' => 'Level',
  45. 'balance' => 'Balance',
  46. 'freeze_balance'=>'Freeze Balance',
  47. 'store_id' => 'Store ID',
  48. 'mall_id' => 'Mall ID',
  49. 'status' => 'Status',
  50. 'created_at' => 'Created At',
  51. 'updated_at' => 'Updated At',
  52. ];
  53. }
  54. public static function setData($params)
  55. {
  56. try {
  57. if (isset($params['id']) && !empty($params['id'])) {
  58. $model = self::findOne(['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  59. if (!$model) {
  60. throw new \Exception('数据不存在或者已被删除');
  61. }
  62. } else {
  63. $model = new self();
  64. $model->loadDefaultValues();
  65. }
  66. if (!$model->load($params, '') || !$model->save()) {
  67. throw new \Exception($model->getErrorMessage());
  68. }
  69. return $model;
  70. } catch (\Exception $e) {
  71. self::$static_error = $e->getMessage();
  72. return false;
  73. }
  74. }
  75. }