ScoreBonusCapitalModel.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace addons\ScoreBonus\common\models;
  3. use Yii;
  4. use common\models\base\BaseActiveRecord;
  5. use yii\behaviors\TimestampBehavior;
  6. use yii\db\Exception;
  7. /**
  8. * This is the model class for table "{{%addon_default}}".
  9. */
  10. class ScoreBonusCapitalModel extends BaseActiveRecord
  11. {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public static function tableName()
  16. {
  17. return '{{%addons_score_bonus_capital}}';
  18. }
  19. public function rules()
  20. {
  21. return [
  22. [['mall_id','order_id', 'status', 'created_at', 'bonus_pre', 'updated_at', 'date_time'], 'integer'],
  23. [['goods_price', 'bonus_price'], 'number'],
  24. ];
  25. }
  26. /**
  27. * 保存数据
  28. * @Author: lun
  29. * @DateTime: 2023/6/2 0002 15:53
  30. * @Copyright: copyright (c) 2021 广东七件事集团
  31. * @param $params
  32. * @return bool
  33. */
  34. public static function setData(array $params)
  35. {
  36. try {
  37. $model = new self();
  38. $model->loadDefaultValues();
  39. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  40. return $model;
  41. } catch (Exception $e) {
  42. self::$static_error = $e->getMessage();
  43. return false;
  44. }
  45. }
  46. public static function getAllData($params)
  47. {
  48. $res = self::find()->where($params)->asArray()->all();
  49. return $res;
  50. }
  51. public static function getFieldSum($params = [], $sum = '*')
  52. {
  53. return self::find()->where($params)->sum($sum);
  54. }
  55. }