<?php
/**
 * 运营设置
 */

namespace app\admin\controller;


use think\Lang;
use think\Validate;
class Operation extends AdminControl
{
public function _initialize()
{
    parent::_initialize(); // TODO: Change the autogenerated stub
    Lang::load(APP_PATH.'admin/lang/zh-cn/config.lang.php');
}

    /**
     * 基本设置
     */
    public function setting(){
        $model_setting = Model('config');
        if (request()->isPost()){

                $update_array = array();
                $update_array['goods_verify'] = isset($_POST['goods_verify']) ? $_POST['goods_verify'] :'0';
                $update_array['flea_isuse'] = isset($_POST['flea_isuse'])?$_POST['flea_isuse']:'0';
                $update_array['promotion_allow'] = isset($_POST['promotion_allow'])?$_POST['promotion_allow']:'0';
                $update_array['groupbuy_allow'] = isset($_POST['groupbuy_allow'])?$_POST['groupbuy_allow']:'0';
                $update_array['points_isuse'] = isset($_POST['points_isuse'])?$_POST['points_isuse']:'0';
                $update_array['pointshop_isuse'] = $_POST['pointshop_isuse'];
                $update_array['voucher_allow'] = $_POST['voucher_allow'];
                $update_array['pointprod_isuse'] = $_POST['pointprod_isuse'];
                $update_array['points_reg'] = intval($_POST['points_reg'])?$_POST['points_reg']:0;
                $update_array['points_login'] = intval($_POST['points_login'])?$_POST['points_login']:0;
                $update_array['points_comments'] = intval($_POST['points_comments'])?$_POST['points_comments']:0;
                $update_array['points_orderrate'] = intval($_POST['points_orderrate'])?$_POST['points_orderrate']:0;
                $update_array['points_ordermax'] = intval($_POST['points_ordermax'])?$_POST['points_ordermax']:0;
                $update_array['points_signin'] = intval($_POST['points_signin'])?$_POST['points_signin']:0;
                $update_array['points_invite'] = intval($_POST['points_invite'])?$_POST['points_invite']:0;
                $update_array['points_rebate'] = intval($_POST['points_rebate'])?$_POST['points_rebate']:0;

                $result = $model_setting->updateConfig($update_array);
                if ($result === true){
                    $this->log(lang('ds_edit').lang('ds_operation').lang('ds_operation_set'),1);
                    $this->success(lang('ds_common_save_succ'));
                }else {
                    $this->error(lang('ds_common_save_fail'));
                }
            
        }
        $list_setting = $model_setting->getListConfig();
        $this->assign('list_setting',$list_setting);
        $this->setAdminCurItem('index');
        return $this->fetch('index');
    }

    /**
     * 获取卖家栏目列表,针对控制器下的栏目
     */
    protected function getAdminItemList() {
        $menu_array = array(
            array(
                'name' => 'index',
                'text' => '基本设置',
                'url' => url('Operation/setting')
            ),
        );
        return $menu_array;
    }
}