SeedStoreSetting.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace addons\Seed\common\models;
  3. use addons\Store\common\models\Store;
  4. use common\enums\StatusEnum;
  5. use Yii;
  6. use yii\db\Exception;
  7. /**
  8. * This is the model class for table "{{%addons_seed_store_setting}}".
  9. *
  10. * @property int $id ID
  11. * @property int $mall_id 商城ID
  12. * @property int $store_id 店铺ID
  13. * @property float|null $percent 设置比例,单位:百分比
  14. * @property int $status 状态【-1删除 0发放中,1正常】
  15. * @property int $created_at 创建时间
  16. * @property int $updated_at 更新数据时间
  17. */
  18. class SeedStoreSetting extends \common\models\base\BaseActiveRecord
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%addons_seed_store_setting}}';
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['mall_id', 'store_id', 'status', 'created_at', 'updated_at'], 'integer'],
  34. [['percent'], 'number'],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'mall_id' => '商城ID',
  45. 'store_id' => '店铺ID',
  46. 'percent' => '设置比例,单位:百分比',
  47. 'status' => '状态【-1删除 0发放中,1正常】',
  48. 'created_at' => '创建时间',
  49. 'updated_at' => '更新数据时间',
  50. ];
  51. }
  52. /**
  53. * 关联店铺表
  54. * @Author: lun
  55. * @DateTime: 2022/8/23 0023 18:30
  56. * @Copyright: copyright (c) 2021 广东七件事集团
  57. * @return \yii\db\ActiveQuery
  58. */
  59. public function getStore()
  60. {
  61. return $this->hasOne(Store::class, ['id' => 'store_id'])->select('id,store_name,logo_img,user_id');
  62. }
  63. /**
  64. * 保存数据
  65. * @Author: lun
  66. * @DateTime: 2022/8/23 0023 17:29
  67. * @Copyright: copyright (c) 2021 广东七件事集团
  68. * @param $params
  69. * @return array|bool
  70. */
  71. public static function setData($params)
  72. {
  73. try {
  74. $model = self::findOne(['store_id' => $params['store_id'], 'status' => StatusEnum::ENABLED]);
  75. if (empty($model)) {
  76. $model = new self();
  77. $model->loadDefaultValues();
  78. }
  79. if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
  80. return $model->toArray();
  81. } catch (\Exception $e) {
  82. self::setStaticError($e->getMessage());
  83. return false;
  84. }
  85. }
  86. }