<?php

namespace admin\controllers\prod;

use admin\service\prod\ProdService;
use common\Controller\AdminController;
use common\util\Util;
use admin\service\user\FxUserService;
use Yii;

class ProdController extends AdminController
{
    /**
     * Des:获取
     * Name: service
     * @author 倪宗锋
     */
    public function service()
    {
        if ($this->service == '') {
            $this->service = new ProdService();
        }
        return $this->service;
    }

    /*
     * 产品列表
     */
    public function actionProdList()
    {
        $param = [
            'category_id' => $this->_post('cms_category_id'),
            'pro_cate_name' => $this->_post('pro_cate_name'),
            'current_page' => $this->_post('current_page', 1),
            'page_size' => $this->_post('page_size', 10),
            'is_recom' => $this->_post('is_recom', '')
        ];
        $result = $this->service()->getProdList($param);
        return json_encode($result);
    }

    /*
     * 大类型基础数据
     */
    public function actionGetCmsCategory()
    {
        $result = $this->service()->getCmsCategory();
        return json_encode($result);
    }

    /**
     * Function Description:新增产品
     * Function Name: actionAddProd
     *
     * @return string
     *
     * @author 娄梦宁
     */
    public function actionAddProd()
    {
        $price_type = $this->_post('price_type');
        $param = [
            'category_id' => $this->_post('category_id'),
            'cms_category_name' => $this->_post('cms_category_name'),
            'cms_category_id' => $this->_post('cms_category_id'),
            'pro_cate_name' => $this->_post('pro_cate_name'),
            'price_type' => json_decode($price_type, true),
            //           'price_type'=>[['price_type_name'=>'成人票','price_type_price'=>369],['price_type_price'=>368,'price_type_name'=>'儿童票']],
            'show_img' => $this->_post('show_img', ''),
            'prod_des' => $this->_post('prod_des', ''),
            'memo' => $this->_post('memo'),
            'close_sale_time' => $this->_post('close_sale_time', '24')    //截止售卖时间 2017-05-18 fuhc
        ];
        $result = $this->service()->AddProd($param);
        return json_encode($result);
    }

    /**
     * Function Description:修改产品信息
     * Function Name: actionUptProd
     *
     *
     * @author 娄梦宁
     */
    public function actionUptProd()
    {
        $price_type = $this->_post('price_type');
        $param = [
            'pro_cate_id' => $this->_post('pro_cate_id'),
            'category_id' => $this->_post('category_id'),
            'cms_category_name' => $this->_post('cms_category_name'),
            'cms_category_id' => $this->_post('cms_category_id'),
            'pro_cate_name' => $this->_post('pro_cate_name'),
            'price_type' => json_decode($price_type, true),
//            'price_type'=>[['price_type_name'=>'成人','price_type_price'=>31,'prod_id'=>3],['price_type_price'=>368,'price_type_name'=>'儿童','prod_id'=>555555]],
            'show_img' => $this->_post('show_img'),
            'prod_des' => $this->_post('prod_des', ''),
            'memo' => $this->_post('memo'),
            'close_sale_time' => $this->_post('close_sale_time', '24')    //截止售卖时间 2017-05-18 fuhc
        ];
        $result = $this->service()->UptProd($param);
        return json_encode($result);
    }

    /*
     * 产品推荐
     */
    public function actionRecomProd()
    {
        $pro_cate_id = $this->_post('pro_cate_id');
        $result = $this->service()->RecomProd($pro_cate_id);
        return json_encode($result);
    }

    /*
     * 自定义佣金
     */
    public function actionDefineCommission()
    {
        $pro_cate_id = $this->_post('pro_cate_id');
        $commission = $this->_post('commission');
        $result = $this->service()->DefineCommission($pro_cate_id, $commission);
        return json_encode($result);
    }

    /*
     * 自定义佣金
     */
    public function actionDefineCommissionProd()
    {
        $prod_commission_arr = $this->_post('prod_commission_arr');
        $result = $this->service()->DefineCommissionByProdId(["prod_commission_arr" => $prod_commission_arr]);
        return json_encode($result);
    }

    /*
     * 图片上传
     */
    public function actionUploadImg()
    {
        $imgFile = $_FILES['file_upload'];
        $result = $this->service()->uploadImg($imgFile);
        return json_encode($result);
    }

    /**
     * Des:同步巴士产品
     * Name: actionUptEntranceTicket
     * @return string
     * @author 倪宗锋
     */
    public function actionUptBus()
    {
        $shell_1 = 'php ' . ROOT_PATH . '/yii count/upt-bus ' . YII_ENV;
        shell_exec($shell_1);
        $shell_2 = 'php ' . ROOT_PATH . '/yii count/up-line-prod ' . YII_ENV;
        shell_exec($shell_2);
        return '更新完成';
    }

    /**
     * Des:同步门票产品
     * Name: actionUptMp
     * @return string
     * @author 倪宗锋
     */
    public function actionUptMp()
    {
        $shell = 'php ' . ROOT_PATH . '/yii count/upt-entrance-ticket ' . YII_ENV;
        shell_exec($shell);
        return '更新完成';
    }


}