StoreBossAgentCommissionLog.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace addons\Store\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\user\User;
  5. use Yii;
  6. /**
  7. * This is the model class for table "{{%addons_store_boss_agent_commission_log}}".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property int $user_id 用户ID
  12. * @property int $store_id
  13. * @property float $commission 永久/额外佣金,单位:元
  14. * @property string $source_table 来源表
  15. * @property int $source_table_id 来源表id
  16. * @property int $is_settle 是否已结算 0 否 1 是
  17. * @property string $desc 说明
  18. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  19. * @property string $order_no 订单编号
  20. * @property int $created_at
  21. * @property int $updated_at
  22. */
  23. class StoreBossAgentCommissionLog extends \common\models\base\BaseActiveRecord
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%addons_store_boss_agent_commission_log}}';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['mall_id', 'user_id', 'store_id', 'source_table_id', 'is_settle', 'status', 'created_at', 'updated_at','level'], 'integer'],
  39. [['commission'], 'number'],
  40. [['source_table', 'desc'], 'string', 'max' => 255],
  41. [['order_no'], 'string', 'max' => 100],
  42. ];
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function attributeLabels()
  48. {
  49. return [
  50. 'id' => 'ID',
  51. 'mall_id' => 'Mall ID',
  52. 'user_id' => 'User ID',
  53. 'store_id' => 'Store ID',
  54. 'commission' => 'Commission',
  55. 'source_table' => 'Source Table',
  56. 'source_table_id' => 'Source Table ID',
  57. 'is_settle' => 'Is Settle',
  58. 'desc' => 'Desc',
  59. 'status' => 'Status',
  60. 'order_no' => 'Order No',
  61. 'created_at' => 'Created At',
  62. 'updated_at' => 'Updated At',
  63. ];
  64. }
  65. /**
  66. * @desc:保存数据
  67. * @Author: hua
  68. * @Date: 2021/11/18
  69. * @Time: 10:54
  70. * @Copyright: copyright (c) 2021 广东七件事集团
  71. * @param array $params
  72. * @return AgentCommissionBasisLog|false|null
  73. */
  74. public static function setData(array $params)
  75. {
  76. try {
  77. $model = self::findOne([
  78. 'user_id' => $params['user_id'],
  79. 'store_id' => $params['store_id'],
  80. 'mall_id' => $params['mall_id'],
  81. 'source_table_id' => $params['source_table_id'],
  82. 'source_table' => $params['source_table'],
  83. 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  84. if(!empty($model)) return $model;
  85. $model = new self();
  86. $model->loadDefaultValues();
  87. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  88. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  89. return $model;
  90. } catch (\Exception $e) {
  91. self::$static_error = $e->getMessage();
  92. return false;
  93. }
  94. }
  95. public function getUser()
  96. {
  97. return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,nickname,mobile,username,avatar_url');
  98. }
  99. }