| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace addons\Pk\common\models;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "{{%addons_pk_performance_log}}".
- *
- * @property int $id
- * @property int $order_id 订单ID
- * @property int $activity_id 活动ID
- * @property int $share_user_id 分享者用户ID
- * @property int $mall_id 商城ID
- * @property int $buyer_id 下单者
- * @property float $money 订单实际支付金额
- * @property int $activity_type 类型【1 个人PK 2战队PK】
- * @property string $year 年
- * @property string $month 月
- * @property string $date 日
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- */
- class PkPerformanceLog extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_pk_performance_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['order_id', 'activity_id', 'share_user_id', 'mall_id', 'buyer_id', 'activity_type', 'status', 'created_at', 'updated_at'], 'integer'],
- [['money'], 'number'],
- [['year', 'month', 'date'], 'required'],
- [['year'], 'string', 'max' => 4],
- [['month', 'date'], 'string', 'max' => 2],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'order_id' => '订单ID',
- 'activity_id' => '活动ID',
- 'share_user_id' => '分享者用户ID',
- 'mall_id' => '商城ID',
- 'buyer_id' => '下单者',
- 'money' => '订单实际支付金额',
- 'activity_type' => '类型【1 个人PK 2战队PK】',
- 'year' => '年',
- 'month' => '月',
- 'date' => '日',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'buyer_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2022/6/8 0015 9:26
- * @Copyright: copyright (c) 2021
- * @param $mall_id
- * @param array $params
- * @return Rebate|bool
- */
- public static function setData(array $params){
- try{
- $mall_id = $params['mall_id'];
- if(!empty($params['id'])){
- $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $mall_id],['<>','status', StatusEnum::ENABLED]]);
- if(empty($model)) throw new \Exception('活动不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- }
- if(!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- }catch(\Exception $e){
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|