PkPerformanceLog.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace addons\Pk\common\models;
  3. use common\models\user\User;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_pk_performance_log}}".
  7. *
  8. * @property int $id
  9. * @property int $order_id 订单ID
  10. * @property int $activity_id 活动ID
  11. * @property int $share_user_id 分享者用户ID
  12. * @property int $mall_id 商城ID
  13. * @property int $buyer_id 下单者
  14. * @property float $money 订单实际支付金额
  15. * @property int $activity_type 类型【1 个人PK 2战队PK】
  16. * @property string $year 年
  17. * @property string $month 月
  18. * @property string $date 日
  19. * @property int $status 状态[-1:删除;0:禁用;1启用]
  20. * @property int $created_at 创建时间
  21. * @property int $updated_at 更新时间
  22. */
  23. class PkPerformanceLog extends \common\models\base\BaseActiveRecord
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%addons_pk_performance_log}}';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['order_id', 'activity_id', 'share_user_id', 'mall_id', 'buyer_id', 'activity_type', 'status', 'created_at', 'updated_at'], 'integer'],
  39. [['money'], 'number'],
  40. [['year', 'month', 'date'], 'required'],
  41. [['year'], 'string', 'max' => 4],
  42. [['month', 'date'], 'string', 'max' => 2],
  43. ];
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function attributeLabels()
  49. {
  50. return [
  51. 'id' => 'ID',
  52. 'order_id' => '订单ID',
  53. 'activity_id' => '活动ID',
  54. 'share_user_id' => '分享者用户ID',
  55. 'mall_id' => '商城ID',
  56. 'buyer_id' => '下单者',
  57. 'money' => '订单实际支付金额',
  58. 'activity_type' => '类型【1 个人PK 2战队PK】',
  59. 'year' => '年',
  60. 'month' => '月',
  61. 'date' => '日',
  62. 'status' => '状态[-1:删除;0:禁用;1启用]',
  63. 'created_at' => '创建时间',
  64. 'updated_at' => '更新时间',
  65. ];
  66. }
  67. public function getUser()
  68. {
  69. return $this->hasOne(User::class, ['id' => 'buyer_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
  70. }
  71. /**
  72. * 保存数据
  73. * @Author: ltm
  74. * @DateTime: 2022/6/8 0015 9:26
  75. * @Copyright: copyright (c) 2021
  76. * @param $mall_id
  77. * @param array $params
  78. * @return Rebate|bool
  79. */
  80. public static function setData(array $params){
  81. try{
  82. $mall_id = $params['mall_id'];
  83. if(!empty($params['id'])){
  84. $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $mall_id],['<>','status', StatusEnum::ENABLED]]);
  85. if(empty($model)) throw new \Exception('活动不存在或已删除');
  86. }else{
  87. $model = new self();
  88. $model->loadDefaultValues();
  89. $model->mall_id = $mall_id;
  90. }
  91. if(!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
  92. return $model;
  93. }catch(\Exception $e){
  94. self::setStaticError($e->getMessage());
  95. return false;
  96. }
  97. }
  98. }