Settled.php 7.45 KB
<?php
use Action\WebAction;
use WebPlugin\Helpers;
use WebPlugin\AuthCode;
use Shop\SettledModel;
/**
 * 商家入驻的控制器
 * 
 * @name SettledController
 * @package shop
 * @copyright yoho.inc
 * @author xiaoxiao.hao <xiaoxiao.hao@yoho.cn>
 */
class SettledController extends WebAction
{
    private $_information = array('code' => 400, 'message' => '操作失败,请稍后再试!');
    /**
     *入住流程
     */
    public function indexAction()
    {
        /// 设置头部数据
        $this->setWebNavHeader();
        
        $data = array(
            'settledPage' => true
        );
        $this->_view->display('settled', $data);
    }
    /**
     * 添加申请
     */
    public function applyAction()
    {
        //判断是否登录
        $this->auditJumpLogin(true, Helpers::url('/settled/apply', array(), 'shop'));//登录后跳转到申请页
        
        $adpic = array(
            '_project' => 'adpic',
            'format_str' => array(
            )
	);
        
        $oneCategory = SettledModel::getOneCategory();
        
        /// 设置头部数据
        $this->setWebNavHeader();
        $state = $this->get('state' ,0);
        $data = array(
            'settledPage' => true,
            'oneCategory' => isset($oneCategory['data']) ? $oneCategory['data'] : array(),
            'uploadKey' => AuthCode::base64_str_encode(AuthCode::encode(json_encode($adpic), 'yohobuy_upload_system')),
            'state' => $state
        );
        $this->_view->display('apply', $data);
    }
    /**
     * 添加申请保存
     * @return type
     */
    public function applySaveAction()
    {
        $result = $this->_information;
        do {
            //判断是否登录
            $uid = $this->auditJumpLogin();
            
            $brandName = $this->post('brand-name', '');//品牌名称
            $registerStatus = $this->post('register-status', '');//品牌注册情况
            $sellerName = $this->post('seller-name', '');//入驻卖家名称
            $sellerAddress = $this->post('seller-address');//入驻卖家地址
            $zipCode = intval($this->post('zip-code'));//邮编
            $contacts = $this->post('contacts');//联系人
            $contactPhone = $this->post('contact-phone');//联系电话  
            $contactEmail = $this->post('contact-email');//联系邮箱
            $sellerRole = $this->post('seller-role');//卖家与品牌关系
            if ($sellerRole === '') {
                $sellerRole = $this->post('orther-seller_role');//其它关系
            }
            if (empty($brandName) || empty($registerStatus) || empty($sellerName) || empty($zipCode) ||
                empty($contacts) || empty($contactPhone) || empty($contactEmail) || empty($sellerRole)) {
                $result['message'] = '请输入必填信息';
                break;
            }
            $brandWebsite = $this->post('brand-website');//品牌官网
            $onlineShopWebsite = $this->post('online-shop-website');//其他线上店网址

            $categoryOne = $this->post('category-one', '');//一级品类
            $categoryTwo = $this->post('category-two', '');//二级品类
            $categoryPrice = $this->post('category-price', '');//品类价格区间
            $categoryInfo = array();
            if (isset($categoryOne) && is_array($categoryOne) && is_array($categoryTwo) && is_array($categoryPrice)) {
                foreach ($categoryOne as $key => $value){
                    if ($value === '') {
                        continue;
                    }
                    $categoryInfo[$key]['category_one'] = $value;
                    $categoryInfo[$key]['category_two'] = $categoryTwo[$key];
                    $categoryInfo[$key]['category_price'] = $categoryPrice[$key];
                }
            }
            $categoryInfo = json_encode($categoryInfo, true); //品类信息

            $billingCycle = $this->post('billing-cycle');//结算周期
            $warehouseProvince = $this->post('warehouse-province');//仓库地址省
            $warehouseCity = $this->post('warehouse-city');//仓库地址市
            $warehouseAddress = $warehouseProvince . ' ' . $warehouseCity; //仓库地址

            $originCountry = $this->post('origin-country');//产品产地国家
            $originProvince = $this->post('origin-province');//产品产地省
            $originCity = $this->post('origin-city');//产品产地市
            $producer = $originCountry . ' ' . $originProvince . ' ' . $originCity; //商品产地

            $invoiceType = $this->post('invoice-type');//发票类型

            $newCycle = $this->post('new-cycle');//上新周期

            if ($newCycle === '') {
                $newCycle = $this->post('orther-new-cycle');
            }

            $quarterNum = intval($this->post('quarter-num', 0));//每季度可提供数量
            $supplyCycle = $this->post('supply-cycle');//补货周期
            if ($supplyCycle === '') {
                $supplyCycle = $this->post('orther-supply-cycle');
            }
            $haveStore = intval($this->post('have-store', 0));//是否有线下店
            $storeAddress = $this->post('store-address');//线下店地址
            $storeSalesVolume = $this->post('store-sales-volume');//线下店月销售额
            $storeInfo = array();
            if ($haveStore && is_array($storeAddress) && is_array($storeSalesVolume)) {
                foreach ($storeAddress as $k => $v){
                    if ($v === '') {
                        continue;
                    }
                    $storeInfo[$k]['store_address'] = $v;
                    $storeInfo[$k]['store_sales_volume'] = $storeSalesVolume[$k];
                }
            }
            $storeInfo = json_encode($storeInfo, true);

            $brandMaterial = $this->post('brand-material', '');//品牌资料地址
            $goodsMaterial = $this->post('goods-material', '');//产品资料地址
            $result = SettledModel::insertApply(
                $brandName, $registerStatus, $sellerName, $sellerAddress, $zipCode, $contacts, $contactPhone,
                $contactEmail, $sellerRole, $brandWebsite, $onlineShopWebsite, $categoryInfo, $billingCycle,
                $warehouseAddress, $producer, $invoiceType, $newCycle, $quarterNum, $supplyCycle, $haveStore,
                $storeInfo, $brandMaterial, $goodsMaterial, $uid
            );
        } while (false);
        
        $this->go('/settled/apply?state=' . (isset($result['code']) && $result['code'] === 200));
    }
    /**
     * 一级品类
     */
    public function getOneCategoryAction()
    {
        $result = $this->_information;
        
        $oneCategory = SettledModel::getOneCategory();
        
        if (isset($oneCategory['code']) && $oneCategory['code'] === 200) {
            $result = $oneCategory;
        }
        
        $this->echoJson($result);
    }
    /**
     *  主要品类--获取二级分类
     */
    public function getTwoCategoryAction()
    {
        $result = $this->_information;
        $id = intval($this->get('id'));
        do {
            
            if ($id < 1) {
                $result['message'] = 'id不能为空';
                break;
            }

            $twoCategory = SettledModel::getTwoCategory($id);
            
            if (isset($twoCategory['code']) && $twoCategory['code'] === 200) {
                $result = $twoCategory;
            }
            
        } while (false);
        
        $this->echoJson($result);
    }
}