BlindBoxBonusLog.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace addons\BlindBox\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_addons_blind_box_bonus_log".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城id
  11. * @property int $user_id 会员id
  12. * @property int $type 类型:1:消费订单;2:直推消费;3:推荐新人
  13. * @property int is_feedback 类型:1:消费订单;2:直推消费;3:推荐新人
  14. * @property string $order_no 订单编号
  15. * @property int $total_times 总分红次数
  16. * @property int $divided_times 已分次数
  17. * @property float $divided_money 已分金额
  18. * @property float $contribution 贡献值
  19. * @property int $status 状态[-1:删除;0:禁用;1启用]
  20. * @property int $created_at
  21. * @property int $updated_at
  22. */
  23. class BlindBoxBonusLog extends BaseActiveRecord
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%addons_blind_box_bonus_log}}';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['mall_id', 'user_id','type', 'total_times', 'divided_times', 'status','is_feedback', 'created_at', 'updated_at'], 'integer'],
  39. [['divided_money', 'contribution'], 'number'],
  40. [['order_no'], 'string', 'max' => 255],
  41. ];
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'id' => 'ID',
  50. 'mall_id' => '商城id',
  51. 'user_id' => '会员id',
  52. 'type' => '类型:1:消费订单;2:直推消费;3:推荐新人',
  53. 'order_no' => '订单编号',
  54. 'total_times' => '总分红次数',
  55. 'divided_times' => '已分次数',
  56. 'divided_money' => '已分金额',
  57. 'contribution' => '贡献值',
  58. 'is_feedback' => '是否退款:0:否:1:是',
  59. 'status' => '状态[-1:删除;0:禁用;1启用]',
  60. 'created_at' => 'Created At',
  61. 'updated_at' => 'Updated At',
  62. ];
  63. }
  64. public static function addData(array $params)
  65. {
  66. try {
  67. $model = self::findOne([
  68. 'mall_id' => $params['mall_id'],
  69. 'user_id' => $params['user_id'],
  70. 'order_no' => $params['order_no'],
  71. 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  72. if (empty($model)) {
  73. $model = new self();
  74. $model->loadDefaultValues();
  75. }
  76. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  77. $res = $model->save();
  78. if ($res == false) throw new \Exception($model->getErrorMessage());
  79. return $model;
  80. } catch (\Exception $e) {
  81. self::$static_error = $e->getMessage();
  82. return false;
  83. }
  84. }
  85. }