StoreBossAgent.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace addons\Store\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_store_boss_agent}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property int $user_id
  11. * @property int $store_id
  12. * @property string|null $remarks 备注
  13. * @property int $status
  14. * @property int $created_at 创建时间
  15. * @property int $deleted_at 删除时间
  16. * @property int $updated_at 修改时间
  17. * @property int $upgrade_level_at 分销商等级升级时间
  18. * @property float $total_price 累计佣金
  19. * @property float $frozen_price 冻结佣金
  20. * @property string|null $delete_reason 删除原因
  21. * @property int $upgrade_status 1条件升级 2 购买指定商品升级 3手动升级
  22. * @property int $level 经销商等级
  23. */
  24. class StoreBossAgent extends \common\models\base\BaseActiveRecord
  25. {
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public static function tableName()
  30. {
  31. return '{{%addons_store_boss_agent}}';
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function rules()
  37. {
  38. return [
  39. [['mall_id', 'user_id'], 'required'],
  40. [['mall_id', 'user_id', 'store_id', 'status', 'created_at', 'deleted_at', 'updated_at', 'upgrade_level_at', 'upgrade_status', 'level'], 'integer'],
  41. [['remarks', 'delete_reason'], 'string'],
  42. [['total_price', 'frozen_price'], 'number'],
  43. ];
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function attributeLabels()
  49. {
  50. return [
  51. 'id' => 'ID',
  52. 'mall_id' => 'Mall ID',
  53. 'user_id' => 'User ID',
  54. 'store_id' => 'Store ID',
  55. 'remarks' => 'Remarks',
  56. 'status' => 'Status',
  57. 'created_at' => 'Created At',
  58. 'deleted_at' => 'Deleted At',
  59. 'updated_at' => 'Updated At',
  60. 'upgrade_level_at' => 'Upgrade Level At',
  61. 'total_price' => 'Total Price',
  62. 'frozen_price' => 'Frozen Price',
  63. 'delete_reason' => 'Delete Reason',
  64. 'upgrade_status' => 'Upgrade Status',
  65. 'level' => 'Level',
  66. ];
  67. }
  68. /**
  69. * @desc:保存数据
  70. * @Author: hua
  71. * @Date: 2021/10/23
  72. * @Time: 17:23
  73. * @Copyright: copyright (c) 2021 广东七件事集团
  74. * @param array $params
  75. * @return Agent|false|null
  76. */
  77. public static function setData(array $params)
  78. {
  79. try {
  80. if(!empty($params['id'])){
  81. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  82. if (empty($model)) throw new \Exception('服务不存在或已删除');
  83. }else{
  84. $model = new self();
  85. $model->loadDefaultValues();
  86. }
  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. }