| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace addons\Seed\common\models;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_seed_log}}".
- *
- * @property int $id
- * @property int $seed_order_id 对应seed_order.id
- * @property int $mall_id 商城ID
- * @property int $store_id 门店id
- * @property int $user_id 用户ID
- * @property int $order_id 订单ID
- * @property int $event_pay 事件类型[1=普通订单,2=收银台订单]
- * @property int $seed_num 种子金数量
- * @property float $seed_cost 种子金总价值,单位:元
- * @property float $change_unit_price 变动的单价
- * @property float $after_unit_price 变动后单价
- * @property string|null $desc 变动说明
- * @property string $capital_type 资金类型
- * @property int $pool_id 能量池ID
- * @property string $setting 生成数据的设置
- * @property int $status 状态,-1:失效,1:正常,2:冻结
- * @property int $created_at 添加时间戳
- * @property int $updated_at 更新时间戳
- */
- class SeedLog extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_seed_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['seed_order_id', 'mall_id', 'store_id', 'user_id', 'order_id', 'event_pay', 'seed_num', 'pool_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['seed_cost', 'change_unit_price', 'after_unit_price'], 'number'],
- [['desc', 'capital_type'], 'string', 'max' => 255],
- [['setting'], 'string', 'max' => 1000],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'seed_order_id' => '对应seed_order.id',
- 'mall_id' => '商城ID',
- 'store_id' => '门店id',
- 'user_id' => '用户ID',
- 'order_id' => '订单ID',
- 'event_pay' => '事件类型[1=普通订单,2=收银台订单]',
- 'seed_num' => '种子金数量',
- 'seed_cost' => '种子金总价值,单位:元',
- 'change_unit_price' => '变动的单价',
- 'after_unit_price' => '变动后单价',
- 'desc' => '变动说明',
- 'capital_type' => '资金类型',
- 'pool_id' => '能量池ID',
- 'setting' => '生成数据的设置',
- 'status' => '状态,-1:失效,1:正常,2:冻结',
- 'created_at' => '添加时间戳',
- 'updated_at' => '更新时间戳',
- ];
- }
- /**
- * 关联用户表
- * @Author: lun
- * @DateTime: 2022/7/28 0028 10:07
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,username,avatar_url');
- }
- /**
- * 关联种子金订单表
- * @Author: lun
- * @DateTime: 2022/7/28 0028 10:07
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getSeedOrder()
- {
- return $this->hasOne(SeedOrder::class, ['order_id' => 'order_id'])->select('order_id,order_no,basic_unit_price')->where(['status' => StatusEnum::ENABLED]);
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2022/7/27 0027 14:07
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params
- * @return bool
- */
- public static function setData($params)
- {
- try {
- $model = new self();
- $model->loadDefaultValues();
- if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- return true;
- } catch (\Exception $e) {
- self::setStaticError('种子金变动记录:'.$e->getMessage());
- return false;
- }
- }
- }
|