<?php

namespace Shop\Src;

use Dever;
use Main\Lib\Core;

class Main extends Core
{
    public function __construct()
    {
        parent::__construct();
        //$this->checkLogin();
    }

    public function test()
    {
        # 退款到原支付账户 待处理
        $param = array
        (
            'project_id' => 1,
            'channel_id' => 1,
            'system_source' => 5,
            'order_id' => Dever::input('order_id', 'G202112297347788956443487'),
            'refund_cash' => Dever::input('cash', '1'),
            'refund_order_id' => Dever::input('refund_order_id', '1'),
        );

        $result = Dever::load('pay/api.refund', $param);

        print_r($result);die;

        $data = array
        (
            'character_string6' => array
            (
                'value' => '111111112',
            ),
            'phrase7' => array
            (
                'value' => '已发货',
            ),
            'thing8' => array
            (
                'value' => '货号',
            ),
            'amount1' => array
            (
                'value' => '100元',
            ),
            'thing5' => array
            (
                'value' => '提示',
            ),
        );

        $data = array
        (
            'thing3' => array
            (
                'value' => '111111112',
            ),
            'thing6' => array
            (
                'value' => date('Y-m-d H:i:s'),
            ),
            'thing7' => array
            (
                'value' => '提示',
            ),
        );

        $data = Dever::json_encode($data);

        return $data;
    }

    # 获取当前登录的信息
    public function user()
    {
        $this->data['user'] = $this->user;
        $this->data['config'] = Dever::db('main/config')->find();
        return $this->data;
    }

    # 获取模板消息
    public function getSubscribeTemplate()
    {
        $this->data['template'] = Dever::load('wechat_applet/subscribe')->getList();
        return $this->data;
    }

    # 获取店铺信息
    public function shop()
    {
        $id = Dever::input('id');
        $this->data['shop'] = Dever::db('shop/info')->find($id);

        if ($this->data['shop']) {
            unset($this->data['shop']['goods']);
            unset($this->data['shop']['factory']);
            unset($this->data['shop']['store']);
        }
        return $this->data;
    }
    
    # 获取门店销售小程序首页的数据
    public function home()
    {
        $city = Dever::input('city');
        $lng = Dever::input('lng');
        $lat = Dever::input('lat');

        # 获取门店
        $this->data['shop'] = array();
        if ($city && $lng && $lat) {
            $this->data['shop'] = Dever::load('shop/lib/info')->get($city, $lng, $lat);
        }

        # 焦点图
        $this->data['focus'] = Dever::load('push/lib/data')->get('home_focus', '首页焦点图', 5);

        # 获取活动推荐
        $this->data['act'] = Dever::load('push/lib/data')->get('home_act', '首页活动推荐', 3);

        # 获取热门商品
        $this->data['hot'] = Dever::load('push/lib/data')->get('home_hot', '首页热门商品', 6);

        # 获取推荐商品
        $this->data['top'] = Dever::load('push/lib/data')->get('home_top', '首页推荐商品', 6);

        # 首页弹窗
        $this->data['alert'] = Dever::load('push/lib/data')->get('home_alert', '首页弹窗', 1);

        return $this->data;
    }

    # 获取店铺列表
    public function getShop()
    {
        $city = Dever::input('city');
        $lng = Dever::input('lng');
        $lat = Dever::input('lat');
        $name = Dever::input('name');
        $shop_id = Dever::input('shop_id');
        $address = Dever::input('address');

        # 获取门店
        $this->data['shop'] = array();
        if ($city) {
            $this->data['shop'] = Dever::load('shop/lib/info')->get($city, $lng, $lat, $name, 'fetchAll', $shop_id, $address);
        }

        return $this->data;
    }

    # 获取店铺单个信息
    public function getShopOne()
    {
        $city = Dever::input('city');
        $lng = Dever::input('lng');
        $lat = Dever::input('lat');
        $name = Dever::input('name');
        $shop_id = Dever::input('shop_id');
        $address = Dever::input('address');

        # 获取门店
        $this->data['shop'] = array();
        if ($city) {
            $this->data['shop'] = Dever::load('shop/lib/info')->get($city, $lng, $lat, $name, 'fetch', $shop_id, $address);
        }

        return $this->data;
    }

    # 根据店铺获取商品列表
    public function getGoods()
    {
        return Dever::load('shop/lib/goods')->getList();
    }

    # 获取文章详情
    public function news()
    {
        $id = Dever::input('id');

        $this->data['news'] = Dever::load('content/lib/news')->get($id);

        return $this->data;
    }

    # 获取专题详情
    public function feature()
    {
        $id = Dever::input('id');

        $this->data['feature'] = Dever::load('content/lib/feature')->get($id);

        return $this->data;
    }

    # 获取平台店信息
    public function getShopByType()
    {
        $where['type'] = 10;
        return Dever::db('shop/info')->getDataByType($where);
    }
}