ElectronCouponGiveLog.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace addons\ElectronCoupon\common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%addons_electron_coupon_give_log}}".
  6. *
  7. * @property int $id
  8. * @property int $mall_id 商城id
  9. * @property int $e_coupon_id 电子券id
  10. * @property int $user_id 接收者id
  11. * @property int $give_user_id 赠送者id
  12. * @property string $e_coupon_name 电子券名称
  13. * @property int $amount 赠送数量
  14. * @property int $is_proper 是否专有者
  15. * @property int $proper_id 专有者id
  16. * @property int $created_at
  17. * @property int $updated_at
  18. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  19. */
  20. class ElectronCouponGiveLog extends \common\models\base\BaseActiveRecord
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return '{{%addons_electron_coupon_give_log}}';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['mall_id', 'e_coupon_id', 'user_id', 'give_user_id'], 'required'],
  36. [['mall_id', 'e_coupon_id', 'user_id', 'give_user_id', 'amount', 'is_proper', 'proper_id', 'created_at', 'updated_at', 'status'], 'integer'],
  37. [['e_coupon_name'], 'string', 'max' => 255],
  38. ];
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function attributeLabels()
  44. {
  45. return [
  46. 'id' => 'ID',
  47. 'mall_id' => '商城id',
  48. 'e_coupon_id' => '电子券id',
  49. 'user_id' => '接收者id',
  50. 'give_user_id' => '赠送者id',
  51. 'e_coupon_name' => '电子券名称',
  52. 'amount' => '赠送数量',
  53. 'is_proper' => '是否专有者',
  54. 'proper_id' => '专有者id',
  55. 'created_at' => 'Created At',
  56. 'updated_at' => 'Updated At',
  57. 'status' => '状态[-1:删除;0:禁用;1启用]',
  58. ];
  59. }
  60. /**
  61. * 数据设置
  62. */
  63. public static function setData(array $params)
  64. {
  65. try{
  66. if (!isset($params['mall_id']) || empty($params['mall_id'])) throw new Exception('缺少商城ID');
  67. $mall_id = $params['mall_id'];
  68. if (isset($params['id']) && !empty($params['id'])) {
  69. $model = self::findOne(['id' => $params['id'], 'mall_id' => $mall_id, 'status' => StatusEnum::ENABLED]);
  70. if(empty($model)) throw new Exception('赠送记录不存在或已删除');
  71. } else {
  72. $model = new self();
  73. $model->loadDefaultValues();
  74. $model->mall_id = $mall_id;
  75. }
  76. if (!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
  77. return $model;
  78. }catch(Exception $e){
  79. self::setStaticError($e->getMessage());
  80. return false;
  81. }
  82. }
  83. }