MembersCardUsedLog.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_used_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 MembersCardUsedLog extends \common\models\base\BaseActiveRecord
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%addons_members_card_used_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','is_cashier'], 'integer'],
  38. [['discount_money', 'pay_money'], 'number'],
  39. ];
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function attributeLabels()
  45. {
  46. return [
  47. 'id' => 'ID',
  48. 'mall_id' => 'Mall ID',
  49. 'status' => 'Status',
  50. 'created_at' => 'Created At',
  51. 'updated_at' => 'Updated At',
  52. 'user_id' => 'user id',
  53. 'card_give_id' => 'card give id',
  54. 'discount_money' => 'discount money',
  55. 'pay_money' => 'pay money',
  56. 'order_id' => 'order id',
  57. 'order_detail_id' => 'order_detail id',
  58. 'store_id' => 'store id',
  59. 'is_cashier' => 'is cashier',
  60. ];
  61. }
  62. public static function setData(array $params)
  63. {
  64. try {
  65. if (!empty($params['id'])) {
  66. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  67. if (empty($model)) throw new \Exception('数据不存在或已删除');
  68. } else {
  69. $model = new self();
  70. $model->loadDefaultValues();
  71. }
  72. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  73. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  74. return $model;
  75. } catch (\Exception $e) {
  76. self::$static_error = $e->getMessage();
  77. return false;
  78. }
  79. }
  80. }