StoreBossSetting.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace addons\Store\common\models;
  3. use Yii;
  4. use yii\base\Model;
  5. /**
  6. * This is the model class for table "{{%addons_store_boss_setting}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property int $store_id
  11. * @property string $key
  12. * @property string $value
  13. * @property int $created_at 创建时间
  14. * @property int $updated_at 修改时间
  15. * @property int $is_delete 是否删除 0--未删除 1--已删除
  16. * @property int $deleted_at 删除时间
  17. */
  18. class StoreBossSetting extends \yii\db\ActiveRecord //BaseActiveRecord
  19. {
  20. const IS_ENABLE = 'is_enable'; // 是否启用
  21. const COMPUTE_PERIOD = 'compute_period'; // 结算周期
  22. const COMPUTE_TYPE = 'compute_type'; // 佣金计算方式:0=订单金额,1=利润,2=商品售价
  23. const SETTLEMENT_METHOD = 'settlement_method'; // 结算方式:0=支付完成发放,1=订单完成发放
  24. const SETTLEMENT_PERIOD = 'settlement_period'; // 佣金结算周期
  25. const DETAIL = 'detail'; // 股东说明
  26. const COMPUTE_TYPE_PRICE = 0;// 订单金额
  27. const COMPUTE_TYPE_PROFIT = 1;// 利润
  28. const COMPUTE_TYPE_SELLING = 2;// 商品售价
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public static function tableName()
  33. {
  34. return '{{%addons_store_boss_setting}}';
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function rules()
  40. {
  41. return [
  42. [['mall_id', 'key', 'value'], 'required'],
  43. [['mall_id','store_id', 'created_at', 'updated_at', 'is_delete', 'deleted_at'], 'integer'],
  44. [['value'], 'string'],
  45. [['key'], 'string', 'max' => 255],
  46. ];
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function attributeLabels()
  52. {
  53. return [
  54. 'id' => 'ID',
  55. 'mall_id' => 'Mall ID',
  56. 'store_id' => 'Store ID',
  57. 'key' => 'Key',
  58. 'value' => 'Value',
  59. 'created_at' => '创建时间',
  60. 'updated_at' => '修改时间',
  61. 'is_delete' => '是否删除 0--未删除 1--已删除',
  62. 'deleted_at' => '删除时间',
  63. ];
  64. }
  65. /**
  66. * 获取数据
  67. * @param null $key
  68. * @param null $mall_id
  69. * @param int $store_id
  70. * @return bool|string
  71. */
  72. public static function getValueByKey($key = null, $mall_id = null,$store_id = 0)
  73. {
  74. if (!$key) {
  75. return false;
  76. }
  77. if (!$mall_id) {
  78. $mall_id = Yii::$app->mall->id;
  79. }
  80. if (!$mall_id) {
  81. return false;
  82. }
  83. $model = BossSetting::findOne(['mall_id' => $mall_id,'store_id' => $store_id, 'is_delete' => 0, 'key' => $key]);
  84. if ($model) {
  85. return $model->value;
  86. }
  87. return false;
  88. }
  89. public static function strToNumber($key, $str)
  90. {
  91. $default = ['is_enable', 'compute_period', 'compute_type'];
  92. if (in_array($key, $default)) {
  93. return round($str, 2);
  94. }
  95. return $str;
  96. }
  97. /**
  98. * 获取股东配置,并组成key-value数组
  99. * @param $mallId
  100. * @param $store_id
  101. * @return array
  102. */
  103. public static function getData($mallId,$store_id = 0)
  104. {
  105. $list = self::find()->where(['mall_id' => $mallId,'store_id' => $store_id, 'is_delete' => 0])->all();
  106. $newList = [];
  107. /* @var self[] $list */
  108. foreach ($list as $item) {
  109. $newList[$item->key] = self::strToNumber($item->key, Yii::$app->serializer->decode($item->value));
  110. }
  111. return $newList;
  112. }
  113. }