| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- /*
- * @Descripttion:
- * @copyright: Copyright (c) 2021 广东七件事集团
- * @Author: lun
- * @Date: 2021-12-31 23:43:05
- */
- namespace app\plugins\rebate\models;
- use app\models\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_rebate_setting".
- *
- * @property int $id
- * @property int $mall_id
- * @property string $key
- * @property string $value
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class RebateSetting extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_rebate_setting';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'key', 'value'], 'required'],
- [['mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['value'], 'string'],
- [['key'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'key' => 'Key',
- 'value' => 'Value',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 字符串转数字
- *
- * @param [type] $key
- * @param [type] $str
- * @return void
- */
- public static function strToNumber($key, $str)
- {
- $default = ['title', 'settlement_method', 'explain'];
- if (in_array($key, $default)) {
- return round($str, 2);
- }
- return $str;
- }
- /**
- * 保存数据
- *
- * @return void
- */
- public static function setData($mall_id, $params)
- {
- try {
- $setting_list = [];
- foreach ($params as $index => $item) {
- $setting_list[] = [
- 'key' => $index,
- 'value' => $item
- ];
- }
- foreach ($setting_list as $item) {
- $setting = self::findOne(['mall_id' => $mall_id, 'key' => $item['key']]);
- if (!$setting) {
- $setting = new self();
- }
- $setting->key = $item['key'];
- $setting->value = $item['value'];
- $setting->mall_id = $mall_id;
- $setting->status = 1;
- $setting->save();
- }
- return true;
- } catch (\Exception $e) {
- self::$error = $e->getMessage();
- return false;
- }
- }
- /**
- * @param null $key
- * @return bool|string|void
- */
- public static function getValueByKey($key = null, $mall_id = null)
- {
- if (!$key) {
- return false;
- }
- if (!$mall_id) {
- $mall_id = Yii::$app->mall->id;
- }
- if (!$mall_id) {
- return false;
- }
- $model = self::findOne(['mall_id' => $mall_id, 'status' => 1, 'key' => $key]);
- if ($model) {
- return $model->value;
- }
- return false;
- }
- }
|