CommissionLog.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace addons\MembersCard\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_members_card_income_log}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id 商城ID
  10. * @property string $name 会员卡名称
  11. * @property int $is_enable 是否启用 0 否 1 是
  12. * @property float $discount 折扣
  13. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  14. * @property int $created_at 创建时间
  15. * @property int $updated_at 修改时间
  16. * @property float $child_discount 子卡折扣
  17. * @property int $child_num 子卡数量
  18. * @property int $child_expired_days 子卡有效期
  19. * @property string $background_url 会员卡背景图
  20. * @property string $member_limit 会员权限
  21. */
  22. class CommissionLog extends \common\models\base\BaseActiveRecord
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%addons_members_card_income_log}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['mall_id', 'user_id','card_give_id','order_id','order_detail_id','status', 'created_at', 'updated_at','store_id','goods_id','reward_user_id','is_frozen','is_cashier'], 'integer'],
  38. [['discount_money', 'pay_money','reward_money'], 'number'],
  39. [['goods_name'],'string'],
  40. ];
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function attributeLabels()
  46. {
  47. return [
  48. 'id' => 'ID',
  49. 'mall_id' => 'Mall ID',
  50. 'status' => 'Status',
  51. 'created_at' => 'Created At',
  52. 'updated_at' => 'Updated At',
  53. 'user_id' => 'user id',
  54. 'card_give_id' => 'card give id',
  55. 'discount_money' => 'discount money',
  56. 'pay_money' => 'pay money',
  57. 'order_id' => 'order id',
  58. 'order_detail_id' => 'order_detail id',
  59. 'store_id' => 'store id',
  60. 'is_frozen' => 'is frozen',
  61. 'reward_user_id' => 'reward user id',
  62. 'goods_id' => 'goods id',
  63. 'reward_money' => 'reward money',
  64. 'is_cashier' => 'is cashier',
  65. 'goods_name' => 'goods name',
  66. ];
  67. }
  68. public static function setData(array $params)
  69. {
  70. try {
  71. if (!empty($params['id'])) {
  72. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  73. if (empty($model)) throw new \Exception('数据不存在或已删除');
  74. } else {
  75. $model = new self();
  76. $model->loadDefaultValues();
  77. }
  78. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  79. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  80. return $model;
  81. } catch (\Exception $e) {
  82. self::$static_error = $e->getMessage();
  83. return false;
  84. }
  85. }
  86. }