SeedLog.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace addons\Seed\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\user\User;
  5. use Yii;
  6. use yii\db\Exception;
  7. /**
  8. * This is the model class for table "{{%addons_seed_log}}".
  9. *
  10. * @property int $id
  11. * @property int $seed_order_id 对应seed_order.id
  12. * @property int $mall_id 商城ID
  13. * @property int $store_id 门店id
  14. * @property int $user_id 用户ID
  15. * @property int $order_id 订单ID
  16. * @property int $event_pay 事件类型[1=普通订单,2=收银台订单]
  17. * @property int $seed_num 种子金数量
  18. * @property float $seed_cost 种子金总价值,单位:元
  19. * @property float $change_unit_price 变动的单价
  20. * @property float $after_unit_price 变动后单价
  21. * @property string|null $desc 变动说明
  22. * @property string $capital_type 资金类型
  23. * @property int $pool_id 能量池ID
  24. * @property string $setting 生成数据的设置
  25. * @property int $status 状态,-1:失效,1:正常,2:冻结
  26. * @property int $created_at 添加时间戳
  27. * @property int $updated_at 更新时间戳
  28. */
  29. class SeedLog extends \common\models\base\BaseActiveRecord
  30. {
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public static function tableName()
  35. {
  36. return '{{%addons_seed_log}}';
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function rules()
  42. {
  43. return [
  44. [['seed_order_id', 'mall_id', 'store_id', 'user_id', 'order_id', 'event_pay', 'seed_num', 'pool_id', 'status', 'created_at', 'updated_at'], 'integer'],
  45. [['seed_cost', 'change_unit_price', 'after_unit_price'], 'number'],
  46. [['desc', 'capital_type'], 'string', 'max' => 255],
  47. [['setting'], 'string', 'max' => 1000],
  48. ];
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function attributeLabels()
  54. {
  55. return [
  56. 'id' => 'ID',
  57. 'seed_order_id' => '对应seed_order.id',
  58. 'mall_id' => '商城ID',
  59. 'store_id' => '门店id',
  60. 'user_id' => '用户ID',
  61. 'order_id' => '订单ID',
  62. 'event_pay' => '事件类型[1=普通订单,2=收银台订单]',
  63. 'seed_num' => '种子金数量',
  64. 'seed_cost' => '种子金总价值,单位:元',
  65. 'change_unit_price' => '变动的单价',
  66. 'after_unit_price' => '变动后单价',
  67. 'desc' => '变动说明',
  68. 'capital_type' => '资金类型',
  69. 'pool_id' => '能量池ID',
  70. 'setting' => '生成数据的设置',
  71. 'status' => '状态,-1:失效,1:正常,2:冻结',
  72. 'created_at' => '添加时间戳',
  73. 'updated_at' => '更新时间戳',
  74. ];
  75. }
  76. /**
  77. * 关联用户表
  78. * @Author: lun
  79. * @DateTime: 2022/7/28 0028 10:07
  80. * @Copyright: copyright (c) 2021 广东七件事集团
  81. * @return \yii\db\ActiveQuery
  82. */
  83. public function getUser()
  84. {
  85. return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,username,avatar_url');
  86. }
  87. /**
  88. * 关联种子金订单表
  89. * @Author: lun
  90. * @DateTime: 2022/7/28 0028 10:07
  91. * @Copyright: copyright (c) 2021 广东七件事集团
  92. * @return \yii\db\ActiveQuery
  93. */
  94. public function getSeedOrder()
  95. {
  96. return $this->hasOne(SeedOrder::class, ['order_id' => 'order_id'])->select('order_id,order_no,basic_unit_price')->where(['status' => StatusEnum::ENABLED]);
  97. }
  98. /**
  99. * 保存数据
  100. * @Author: lun
  101. * @DateTime: 2022/7/27 0027 14:07
  102. * @Copyright: copyright (c) 2021 广东七件事集团
  103. * @param $params
  104. * @return bool
  105. */
  106. public static function setData($params)
  107. {
  108. try {
  109. $model = new self();
  110. $model->loadDefaultValues();
  111. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  112. return true;
  113. } catch (\Exception $e) {
  114. self::setStaticError('种子金变动记录:'.$e->getMessage());
  115. return false;
  116. }
  117. }
  118. }