| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace addons\Store\common\models;
- use Yii;
- use yii\base\Model;
- /**
- * This is the model class for table "{{%addons_store_boss_setting}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $store_id
- * @property string $key
- * @property string $value
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- * @property int $is_delete 是否删除 0--未删除 1--已删除
- * @property int $deleted_at 删除时间
- */
- class StoreBossSetting extends \yii\db\ActiveRecord //BaseActiveRecord
- {
- const IS_ENABLE = 'is_enable'; // 是否启用
- const COMPUTE_PERIOD = 'compute_period'; // 结算周期
- const COMPUTE_TYPE = 'compute_type'; // 佣金计算方式:0=订单金额,1=利润,2=商品售价
- const SETTLEMENT_METHOD = 'settlement_method'; // 结算方式:0=支付完成发放,1=订单完成发放
- const SETTLEMENT_PERIOD = 'settlement_period'; // 佣金结算周期
- const DETAIL = 'detail'; // 股东说明
- const COMPUTE_TYPE_PRICE = 0;// 订单金额
- const COMPUTE_TYPE_PROFIT = 1;// 利润
- const COMPUTE_TYPE_SELLING = 2;// 商品售价
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_store_boss_setting}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'key', 'value'], 'required'],
- [['mall_id','store_id', 'created_at', 'updated_at', 'is_delete', 'deleted_at'], 'integer'],
- [['value'], 'string'],
- [['key'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'store_id' => 'Store ID',
- 'key' => 'Key',
- 'value' => 'Value',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- 'is_delete' => '是否删除 0--未删除 1--已删除',
- 'deleted_at' => '删除时间',
- ];
- }
- /**
- * 获取数据
- * @param null $key
- * @param null $mall_id
- * @param int $store_id
- * @return bool|string
- */
- public static function getValueByKey($key = null, $mall_id = null,$store_id = 0)
- {
- if (!$key) {
- return false;
- }
- if (!$mall_id) {
- $mall_id = Yii::$app->mall->id;
- }
- if (!$mall_id) {
- return false;
- }
- $model = BossSetting::findOne(['mall_id' => $mall_id,'store_id' => $store_id, 'is_delete' => 0, 'key' => $key]);
- if ($model) {
- return $model->value;
- }
- return false;
- }
- public static function strToNumber($key, $str)
- {
- $default = ['is_enable', 'compute_period', 'compute_type'];
- if (in_array($key, $default)) {
- return round($str, 2);
- }
- return $str;
- }
- /**
- * 获取股东配置,并组成key-value数组
- * @param $mallId
- * @param $store_id
- * @return array
- */
- public static function getData($mallId,$store_id = 0)
- {
- $list = self::find()->where(['mall_id' => $mallId,'store_id' => $store_id, 'is_delete' => 0])->all();
- $newList = [];
- /* @var self[] $list */
- foreach ($list as $item) {
- $newList[$item->key] = self::strToNumber($item->key, Yii::$app->serializer->decode($item->value));
- }
- return $newList;
- }
- }
|