[ 'name' => '充值设置', 'list' => [ [ 'name' => OptionSetting::RECHARGE_WALLET_STATUS, 'text' => '开启余额', 'type' => 'radio', 'required' => true, 'default' => '0', 'unit' => '', 'muted' => '开启余额功能' ], [ 'name' => OptionSetting::RECHARGE_CUSTOM_STATUS, 'text' => '自定义金额', 'type' => 'radio', 'required' => true, 'default' => '0', 'unit' => '', 'muted' => '是否开放自定义金额' ], [ 'name' => OptionSetting::STORE_COMBINE_PAY, 'text' => '是否开启余额抵扣', 'type' => 'radio', 'required' => true, 'default' => '1', 'unit' => '', 'muted' => '是否开启余额抵扣' ], [ 'name' => OptionSetting::BALANCE_TO_COMMISSION, 'text' => '是否开启余额转佣金', 'type' => 'radio', 'required' => true, 'default' => '0', 'unit' => '', 'muted' => '是否开启余额转佣金' ], [ 'name' => 'give_integral_profit', 'text' => '积分转赠手续费比例', 'type' => 'number', 'required' => true, 'default' => '0.00', 'unit' => '%', 'muted' => '佣金转余额比例' ], [ 'name' => 'give_balance_profit', 'text' => '余额转赠手续费比例', 'type' => 'number', 'required' => true, 'default' => '0.00', 'unit' => '%', 'muted' => '佣金转余额比例' ], [ 'name' => OptionSetting::COMMISSION_TO_BALANCE, 'text' => '佣金转余额比例', 'type' => 'number', 'required' => true, 'default' => '0.00', 'unit' => '%', 'muted' => '佣金转余额比例' ], [ 'name' => OptionSetting::BALANCE_TO_CASH, 'text' => '是否开启余额提现', 'type' => 'radio', 'required' => true, 'default' => '0', 'unit' => '', 'muted' => '是否开启余额提现' ], [ 'name' => OptionSetting::BALANCE_TO_CASH_SETTING, 'text' => '余额提现设置', 'type' => 'text', 'required' => true, 'default' => '', 'unit' => '', 'muted' => '是否开启余额提现' ], [ 'name' => 'cash_service_charge', 'text' => '提现手续费', 'type' => 'text', 'required' => true, 'default' => '0.00', 'unit' => '', 'muted' => '' ], // [ // 'name' => OptionSetting::RECHARGE_PIC_URL, // 'text' => '背景图片', // 'type' => 'image', // 'size' => '200*50', // 'required' => false, // 'default' => '', // 'unit' => '' // ], // [ // 'name' => OptionSetting::RECHARGE_AD_PIC_URL, // 'text' => '广告图片', // 'type' => 'image', // 'size' => '200*50', // 'required' => false, // 'default' => '', // 'unit' => '' // ], // [ // 'name' => OptionSetting::RECHARGE_PAGE_URL, // 'text' => '跳转链接', // 'type' => 'text', // 'required' => true, // 'default' => 0, // 'unit' => '', // 'muted' => '广告图片跳转链接' // ], // [ // 'name' => OptionSetting::RECHARGE_P_PIC_URL, // 'text' => '说明图标', // 'type' => 'image', // 'size' => '200*50', // 'required' => false, // 'default' => '', // 'unit' => '充值说明图标' // ], // [ // 'name' => OptionSetting::RECHARGE_HELP, // 'text' => '充值说明', // 'type' => 'text', // 'required' => true, // 'default' => '', // 'unit' => '', // 'muted' => '' // ], ] ] ]; /** * {@inheritdoc} */ public function rules() { return [ // [['recharge_pic_url', 'recharge_ad_pic_url', 'recharge_page_url', 'recharge_p_pic_url', 'recharge_help'], 'string', 'max' => 255], [['recharge_wallet_status', 'recharge_custom_status', 'balance_to_commission', 'combine_pay'], 'in', 'range' => [0, 1]], // [['recharge_wallet_status', 'recharge_custom_status', 'balance_to_commission', 'combine_pay', 'commission_to_balance', 'give_integral_profit', 'give_balance_profit'],'required', 'on'=> [self::SCENARIO_ADD, self::SCENARIO_EDIT]], [['commission_to_balance', 'give_integral_profit', 'give_balance_profit','lg_cash'], 'number'], [['balance_to_cash', 'balance_to_cash_setting'], 'safe'], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'recharge_wallet_status' => '开启余额功能', 'recharge_custom_status' => '是否开放自定义金额', 'balance_to_commission' => '是否开启余额转佣金', 'combine_pay' => '是否开启余额抵扣', 'recharge_pic_url' => '背景图片', 'recharge_ad_pic_url' => '广告图片', // 'recharge_page_url' => '广告图片跳转链接', 'recharge_p_pic_url' => '充值说明图标', 'recharge_help' => '充值说明', "commission_to_balance" => '佣金转余额比例', "give_integral_profit" => '赠送积分比例', "give_balance_profit" => '赠送余额比例', ]; } public function scenarios() { $scenarios = parent::scenarios(); return $scenarios; } public function saveRechargeSetting() { if ($this->validate()) { $t = \Yii::$app->db->beginTransaction(); $store = Store::findOne($this->store_id); $store->lg_cash = $this->lg_cash; $store->save(); $data = self::getGroup(self::OPTION_KEY, get_store_id()); foreach($data as &$val){ if(isset($this->attributes[$val['name']])){ $val['value'] = $this->attributes[$val['name']]; } } $result = self::setGroup(self::OPTION_KEY, $data, get_store_id()); if (!$result) { $t->rollBack(); return [ 'code' => 1, 'msg' => '保存失败' ]; } $t->commit(); return [ 'code' => 0, 'msg' => '保存成功' ]; } else { // 验证失败:$errors 是一个包含错误信息的数组 return [ 'code' => 1, "msg" => $this->getErrorSummary(false)[0] ]; } } public static function getRechargeSettingList() { $result = self::getGroup(self::OPTION_KEY, get_store_id()); $data = []; foreach($result as $val){ $data[$val['name']] = (string)$val['value']; } $store = Store::findOne(get_store_id()); $data['balance'] = $store->balance == 1 ? 1 : 0; $data['lg_cash'] = $store->lg_cash == 1 ? 1 : 0; return $data; } /** * 根据类获取数据 * @param $group * @param $store_id * @return array */ public static function getGroup ($group, $store_id = 1) { $group_setting = self::OPTION_SETTING; $group_arr = $group_setting[$group]['list'] ?: []; $data = []; foreach ($group_arr as $val) { $group_data = Option::findOne(['store_id' => $store_id, 'group' => $group, 'name' => $val['name']]); if ($val['type'] == 'checkbox') { if ($group_data) { $attr = $val['default']; $data_val = json_decode($group_data->value,true); foreach ($attr as $k => &$v) { $v = $data_val[$k] ? $data_val[$k] : $v; } } } $data[] = [ 'name' => $group_data ? $group_data->name : $val['name'], 'text' => $val['text'], 'group' => $group_data ? $group_data->group : $group, 'type' => $val['type'], 'size' => isset($val['size']) ? $val['size'] : '', 'title' => isset($val['title']) ? $val['title'] : '', 'required' => $val['required'], 'muted' => isset($val['muted']) ? $val['muted'] : '', 'value' => $group_data ? ($val['type'] == 'checkbox' ? $attr : $group_data->value ) : $val['default'], 'updated_at' => $group_data ? $group_data->updated_at : 0, 'unit' => isset($val['unit']) ? $val['unit'] : '', ]; } return $data; } /** * 根据类型批量设置数据 * @param $group * @param $set_data * @param int $store_id * @return bool */ public static function setGroup ($group, $set_data, $store_id = 1) { foreach ($set_data as $val) { if ($val['name']) { $group_data = Option::findOne(['store_id' => $store_id, 'group' => $group, 'name' => $val['name']]); if (!$group_data) { $group_data = new Option(); $group_data->store_id = $store_id; $group_data->group = $group; } $group_data->name = $val['name']; if ($val['type'] == 'checkbox') { $group_data->value = json_encode($val['value']); }else { $group_data->value = "{$val['value']}"; } if (!$group_data->save()) { return false; } } } return true; } }