HigoMall.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace addons\HiGo\common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%addons_higo_mall}}".
  6. *
  7. * @property int $id
  8. * @property int $mall_id 商城id
  9. * @property float $hi_bei 当前发放嗨呗数量
  10. * @property float $hi_value 已发放嗨值数量
  11. * @property float $available_hi_bei 当前可用嗨呗数量
  12. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  13. * @property int $created_at
  14. * @property int $updated_at
  15. */
  16. class HigoMall extends \common\models\base\BaseActiveRecord
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%addons_higo_mall}}';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
  32. [['hi_bei', 'hi_value','available_hi_bei'], 'number'],
  33. ];
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'mall_id' => 'Mall ID',
  43. 'hi_bei' => 'Hi Bei',
  44. 'hi_value' => 'Hi Value',
  45. 'status' => 'Status',
  46. 'created_at' => 'Created At',
  47. 'updated_at' => 'Updated At',
  48. ];
  49. }
  50. /**
  51. * 保存数据
  52. * @Author: zmz
  53. * @DateTime: 2022/11/16 12:13
  54. * @Copyright: copyright (c) 2022 广东七件事集团
  55. * @param array $params
  56. * @return bool
  57. */
  58. public static function setData(array $params){
  59. try{
  60. if(isset($params['id']) && $params['id']) {
  61. $model = self::findOne(['id' => $params['id']]);
  62. if (empty($model)) throw new \Exception('服务不存在或已删除');
  63. }else{
  64. $model = new self();
  65. $model->loadDefaultValues();
  66. }
  67. if(!$model->load($params,'') || !$model->save()){
  68. throw new \Exception($model->getErrorMessage());
  69. }
  70. return $model;
  71. }catch(\Exception $e){
  72. self::setStaticError($e->getMessage());
  73. return false;
  74. }
  75. }
  76. }