<?php

namespace app\home\controller;


use think\Lang;
class Sellercallcenter extends BaseSeller
{
    public function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub
    }

    public function index()
    {
        $model_store = Model('store');
        $store_info = $model_store->getStoreInfo(array('store_id' => session('store_id')));
        $this->assign('storeinfo', $store_info);
       
        $model_seller = Model('seller');
        $seller_list = $model_seller->getSellerList(array('store_id' => $store_info['store_id']), '', 'seller_id asc');//账号列表
        $this->setSellerCurMenu('Sellercallcenter');
        $this->setSellerCurItem('index');
        $this->assign('seller_list', $seller_list);
        return $this->fetch($this->template_dir.'index');
    }

    /**
     * 保存
     */
    public function save()
    {
        if (request()->isPost()) {
            $update = array();
            $i = 0;
            if (is_array($_POST['pre']) && !empty($_POST['pre'])) {
                foreach ($_POST['pre'] as $val) {
                    if (empty($val['name']) || empty($val['type']) || empty($val['num']))
                        continue;
                    $update['store_presales'][$i]['name'] = $val['name'];
                    $update['store_presales'][$i]['type'] = intval($val['type']);
                    $update['store_presales'][$i]['num'] = $val['num'];
                    $i++;
                }
                $update['store_presales'] = serialize($update['store_presales']);
            }
            else {
                $update['store_presales'] = serialize(null);
            }

            $i = 0;
            if (is_array($_POST['after']) && !empty($_POST['after'])) {
                foreach ($_POST['after'] as $val) {
                    if (empty($val['name']) || empty($val['type']) || empty($val['num']))
                        continue;
                    $update['store_aftersales'][$i]['name'] = $val['name'];
                    $update['store_aftersales'][$i]['type'] = intval($val['type']);
                    $update['store_aftersales'][$i]['num'] = $val['num'];
                    $i++;
                }
                $update['store_aftersales'] = serialize($update['store_aftersales']);
            }
            else {
                $update['store_aftersales'] = serialize(null);
            }

            $update['store_workingtime'] = $_POST['working_time'];
            $where = array();
            $where['store_id'] = session('store_id');
            Model('store')->editStore($update, $where);
            showDialog(lang('ds_common_save_succ'), url('sellercallcenter/index'), 'succ');
        }
    }

    /**
     * 用户中心右边，小导航
     *
     * @param string $menu_type 导航类型
     * @param string $menu_key 当前导航的menu_key
     * @return
     */
    protected function getSellerItemList()
    {
        $menu_array = array(
             array(
                'name' => 'index', 'text' => lang('ds_member_path_store_callcenter'),
                'url' => url('sellercallcenter/index')
            ),
        );
        return $menu_array;
    }
}