Goods.php 4.8 KB
Newer Older
G
gongfuxiang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
<?php
namespace app\admin\controller;

use app\service\ResourcesService;
use app\service\GoodsService;
use app\service\RegionService;
use app\service\BrandService;

/**
 * 商品管理
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-01T21:51:08+0800
 */
class Goods extends Common
{
	/**
	 * 构造方法
	 * @author   Devil
	 * @blog     http://gong.gg/
	 * @version  0.0.1
	 * @datetime 2016-12-03T12:39:08+0800
	 */
	public function __construct()
	{
		// 调用父类前置方法
		parent::__construct();

		// 登录校验
		$this->Is_Login();

		// 权限校验
		$this->Is_Power();
	}

	/**
     * [Index 商品列表]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2016-12-06T21:31:53+0800
     */
	public function Index()
	{
		// 参数
		$params = input();

		// 条件
		$where = GoodsService::GetAdminIndexWhere($params);

		// 总数
		$total = GoodsService::GoodsTotal($where);

		// 分页
		$number = MyC('admin_page_number');
		$page_params = array(
				'number'	=>	$number,
				'total'		=>	$total,
				'where'		=>	$params,
G
gongfuxiang 已提交
61
				'page'		=>	isset($params['page']) ? intval($params['page']) : 1,
G
gongfuxiang 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
				'url'		=>	url('admin/goods/index'),
			);
		$page = new \base\Page($page_params);

		// 获取数据列表
		$data_params = [
			'where'			=> $where,
			'm'				=> $page->GetPageStarNumber(),
			'n'				=> $number,
			'is_category'	=> 1,
		];
		$data = GoodsService::GoodsList($data_params);

		// 是否上下架
		$this->assign('common_goods_is_shelves_list', lang('common_goods_is_shelves_list'));

		// 是否首页推荐
		$this->assign('common_is_text_list', lang('common_is_text_list'));

		$this->assign('params', $params);
		$this->assign('page_html', $page->GetPageHtml());
		$this->assign('data', $data);
		return $this->fetch();
	}

	/**
	 * [SaveInfo 商品添加/编辑页面]
	 * @author   Devil
	 * @blog     http://gong.gg/
	 * @version  0.0.1
	 * @datetime 2016-12-14T21:37:02+0800
	 */
	public function SaveInfo()
	{
		// 参数
		$params = input();

		// 商品信息
		if(!empty($params['id']))
		{
			$data_params = [
				'where'				=> ['id'=>$params['id']],
				'm'					=> 0,
				'n'					=> 1,
				'is_photo'			=> 1,
				'is_content_app'	=> 1,
				'is_category'		=> 1,
			];
			$data = GoodsService::GoodsList($data_params);
			if(empty($data[0]))
			{
				return $this->error('商品信息不存在', url('admin/goods/index'));
			}
			$this->assign('data', $data[0]);

			// 获取商品编辑规格
			$specifications = GoodsService::GoodsEditSpecifications($data[0]['id']);
			$this->assign('specifications', $specifications);
		}

		// 地区信息
		$this->assign('region_province_list', RegionService::RegionItems(['pid'=>0]));

		// 商品分类
		$this->assign('category_list', GoodsService::GoodsCategory());

		// 品牌分类
		$this->assign('brand_list', BrandService::CategoryBrand());

G
gongfuxiang 已提交
131 132 133
		// 参数
		$this->assign('params', $params);

G
gongfuxiang 已提交
134 135 136
		// 编辑器文件存放地址
		$this->assign('editor_path_type', 'goods');

G
gongfuxiang 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
		return $this->fetch();
	}

	/**
	 * [Save 商品添加/编辑]
	 * @author   Devil
	 * @blog     http://gong.gg/
	 * @version  0.0.1
	 * @datetime 2016-12-14T21:37:02+0800
	 */
	public function Save()
	{
		// 是否ajax
		if(!IS_AJAX)
		{
			return $this->error(lang('common_unauthorized_access'));
		}

		// 开始操作
		$params = input('post.');
		$params['admin'] = $this->admin;
		$ret = GoodsService::GoodsSave($params);
		return json($ret);
	}

	/**
	 * [Delete 商品删除]
	 * @author   Devil
	 * @blog     http://gong.gg/
	 * @version  0.0.1
	 * @datetime 2016-12-15T11:03:30+0800
	 */
	public function Delete()
	{
		// 是否ajax
		if(!IS_AJAX)
		{
			return $this->error(lang('common_unauthorized_access'));
		}

		// 开始操作
		$params = input('post.');
		$params['admin'] = $this->admin;
		$ret = GoodsService::GoodsDelete($params);
		return json($ret);
	}

	/**
	 * [StatusShelves 上下架状态更新]
	 * @author   Devil
	 * @blog     http://gong.gg/
	 * @version  0.0.1
	 * @datetime 2017-01-12T22:23:06+0800
	 */
	public function StatusShelves()
	{
		// 是否ajax
		if(!IS_AJAX)
		{
			return $this->error(lang('common_unauthorized_access'));
		}

		// 开始操作
		$params = input('post.');
		$params['admin'] = $this->admin;
		$params['field'] = 'is_shelves';
		$ret = GoodsService::GoodsStatusUpdate($params);
		return json($ret);
	}

	/**
	 * [StatusHomeRecommended 是否首页推荐状态更新]
	 * @author   Devil
	 * @blog     http://gong.gg/
	 * @version  0.0.1
	 * @datetime 2017-01-12T22:23:06+0800
	 */
	public function StatusHomeRecommended()
	{
		// 是否ajax
		if(!IS_AJAX)
		{
			return $this->error(lang('common_unauthorized_access'));
		}

		// 开始操作
		$params = input('post.');
		$params['admin'] = $this->admin;
		$params['field'] = 'is_home_recommended';
		$ret = GoodsService::GoodsStatusUpdate($params);
		return json($ret);
	}
}
?>