<?php

namespace MpApi\Controller;

class AdminController extends PublicController
{
	public function index()
	{
		echo "hello wolrd";
	}
	/**
	 * @description: 获取商铺列表
	 */
	public function getShopList()
	{
		if ($this->tokenShop_id != C('powerId')) {
			$where['shop_id'] = $this->tokenShop_id; //非总管理员 只返回自己的账户信息
		}

		$shopDb = D('shop');
		if ($shopList = $shopDb->where($where)->select()) {
			echo json_encode(array('status' => 1, 'msg' => '访问成功', "shopList" => $shopList));
		} else {
			echo json_encode(array('status' => 0, 'msg' => '暂无商铺数据'));
		}
	}
	/**
	 * @description: 商铺添加
	 */
	public function addShop()
	{
		//非总管理员 直接打断 退出
		if ($this->tokenShop_id != C('powerId')) { //非总管理员
			echo json_encode(array('status' => 0, 'msg' => '没有权限'));
			exit;
		}
		if ($_REQUEST['name']) {
			//生成shop_id随机值
			$arr = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
			$shop_id = "";
			for ($i = 0; $i < 16; $i++) {
				$rand = rand(0, 36);
				$shop_id = $shop_id . $arr[$rand];
			}
			//如果有上传图片得操作 执行如下
			if ($_REQUEST['upFile']) { //有新图上传 则把图片从temp目录 复制到目标目录
				if (!(copy("Data/UploadFiles/temp/" . $_REQUEST['upFile'], "Data/UploadFiles/photo/" . $_REQUEST['upFile']))) {
					echo json_encode(array('status' => 0, 'msg' => '图片复制失败'));
					exit;
				}
				$data['logo'] = json_encode(array($_REQUEST['upFile'])); //序列化储存
			}
			//data数据
			$data['shop_id'] = $shop_id;
			$data['name'] = $_REQUEST['name'];
			$data['waiter'] = $_REQUEST['waiter'];
			$data['service_wx'] = $_REQUEST['service_wx'];
			$data['tel'] = $_REQUEST['tel'];
			$data['email'] = $_REQUEST['email'];
			$data['price_min'] = $_REQUEST['price_min'];
			$data['weight_max'] = $_REQUEST['weight_max'];
			$data['describe'] = $_REQUEST['desc'];
			$data['opening_time'] = $_REQUEST['opening_time'];
			$data['closeing_time'] = $_REQUEST['closeing_time'];
			//录入数据库
			$shopDb = D('shop');
			if ($shopDb->data($data)->add()) {
				echo json_encode(array('status' => 1, 'msg' => '创建成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '创建失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: 商铺更新
	 */
	public function saveShop()
	{
		//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
		$this->isPower();

		if ($_REQUEST['shop_id'] && $_REQUEST['name']) {
			//data数据
			$data['name'] = $_REQUEST['name'];
			$data['waiter'] = $_REQUEST['waiter'];
			$data['service_wx'] = $_REQUEST['service_wx'];
			$data['tel'] = $_REQUEST['tel'];
			$data['email'] = $_REQUEST['email'];
			$data['price_min'] = $_REQUEST['price_min'];
			$data['weight_max'] = $_REQUEST['weight_max'];
			$data['describe'] = $_REQUEST['desc'];
			$data['opening_time'] = $_REQUEST['opening_time'];
			$data['closeing_time'] = $_REQUEST['closeing_time'];
			//如果有上传图片得操作 执行如下
			if ($_REQUEST['upFile']) { //有新图上传 则把图片从temp目录 复制到目标目录
				if (!(copy("Data/UploadFiles/temp/" . $_REQUEST['upFile'], "Data/UploadFiles/logo/" . $_REQUEST['upFile']))) {
					echo json_encode(array('status' => 0, 'msg' => '图片复制失败'));
					exit;
				}
				if ($_REQUEST['oldFile']) { //存在老图 既删掉老图 没有成功的话 将刚才复制到此目录得新图也一并删除
					if (!(unlink("Data/UploadFiles/logo/" . basename($_REQUEST['oldFile'])))) {
						unlink("Data/UploadFiles/logo/" . $_REQUEST['upFile']);
						echo json_encode(array('status' => 0, 'msg' => '原图删除失败'));
						exit;
					}
				}
				$data['logo'] = json_encode(array($_REQUEST['upFile'])); //序列化储存
			}
			//where条件
			$where['shop_id'] = $_REQUEST['shop_id'];
			//录入数据库
			$shopDb = D('shop');
			if ($shopDb->where($where)->save($data)) {
				echo json_encode(array('status' => 1, 'msg' => '更新成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '更新失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: 获取管理员列表
	 */
	public function getAdminList()
	{
		if ($this->tokenShop_id != C('powerId')) {
			$where['shop_id'] = $this->tokenShop_id; //非总管理员 只返回自己的账户信息
		}
		$where['del'] = '0';
		$adminuserDb = D('adminuser');
		if ($adminList = $adminuserDb->where($where)->field("id,name,uname,shop_id,photo,addtime,lasttime")->select()) {
			echo json_encode(array('status' => 1, 'msg' => '访问成功', "adminList" => $adminList));
		} else {
			echo json_encode(array('status' => 0, 'msg' => '暂无管理员数据'));
		}
	}
	/**
	 * @description: 管理员&商家会员的添加
	 */
	public function addAdmin()
	{
		//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
		$this->isPower();

		if ($_REQUEST['name'] && $_REQUEST['uname'] && $_REQUEST['pwd']) {
			//如果有上传图片得操作 执行如下
			if ($_REQUEST['upFile']) { //有新图上传 则把图片从temp目录 复制到目标目录
				if (!(copy("Data/UploadFiles/temp/" . $_REQUEST['upFile'], "Data/UploadFiles/photo/" . $_REQUEST['upFile']))) {
					echo json_encode(array('status' => 0, 'msg' => '图片复制失败'));
					exit;
				}
				$data['photo'] = json_encode(array($_REQUEST['upFile'])); //序列化储存
			}
			//data数据
			$data['name'] = $_REQUEST['name'];
			$data['uname'] = $_REQUEST['uname'];
			$data['pwd'] = MD5(MD5($_REQUEST['pwd']));
			$data['shop_id'] = $_REQUEST['shop_id'];
			$data['addtime'] = time();
			$data['qx'] = 5;

			//录入数据库
			$adminDb = D('adminuser');
			if ($adminDb->data($data)->add()) {
				echo json_encode(array('status' => 1, 'msg' => '创建成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '创建失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: 管理员&商家会员的更新
	 */
	public function saveAdmin()
	{
		//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
		$this->isPower();

		if ($_REQUEST['id'] && $_REQUEST['uname'] && $_REQUEST['shop_id']) {
			//data数据
			$data['uname'] = $_REQUEST['uname'];
			if ($_REQUEST['pwd']) {
				$data['pwd'] = MD5(MD5($_REQUEST['pwd']));
			}
			//如果有上传图片得操作 执行如下
			if ($_REQUEST['upFile']) { //有新图上传 则把图片从temp目录 复制到目标目录
				if (!(copy("Data/UploadFiles/temp/" . $_REQUEST['upFile'], "Data/UploadFiles/photo/" . $_REQUEST['upFile']))) {
					echo json_encode(array('status' => 0, 'msg' => '图片复制失败'));
					exit;
				}
				if ($_REQUEST['oldFile']) { //存在老图 既删掉老图 没有成功的话 将刚才复制到此目录得新图也一并删除
					if (!(unlink("Data/UploadFiles/photo/" . basename($_REQUEST['oldFile'])))) {
						unlink("Data/UploadFiles/photo/" . $_REQUEST['upFile']);
						echo json_encode(array('status' => 0, 'msg' => '原图删除失败'));
						exit;
					}
				}
				$data['photo'] = json_encode(array($_REQUEST['upFile'])); //序列化储存
			}
			//where条件
			$where['id'] = $_REQUEST['id'];
			$where['shop_id'] = $_REQUEST['shop_id'];
			//录入数据库
			$adminDb = D('adminuser');
			if ($adminDb->where($where)->data($data)->save()) {
				echo json_encode(array('status' => 1, 'msg' => '更新成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '更新失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: 管理员账号删除 ps:只改 del字段标识 并非真正删除
	 */
	public function deleteAdmin()
	{
		//非总管理员 直接打断 退出
		if ($this->tokenShop_id != C('powerId')) { //非总管理员
			echo json_encode(array('status' => 0, 'msg' => '没有权限'));
			exit;
		}

		if ($_REQUEST['idArr']) {
			// 获取要删除的航线ID数组
			$idArr = explode(',', strval($_REQUEST['idArr']));
			$where['id'] = array("in", $_REQUEST['idArr']);
			//data数据
			$data['del'] = '1';
			//录入数据库
			$adminDb = D('adminuser');
			if ($adminDb->where($where)->save($data)) {
				echo json_encode(array('status' => 1, 'msg' => '删除成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '删除失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: 分类列表
	 */
	public function getCategoryList()
	{
		if ($this->tokenShop_id != C('powerId')) {
			$where['shop_id'] = $this->tokenShop_id; //非总管理员 只返回自己的账户信息
		}

		$order['sort'] = 'desc';
		$field = array('id', 'pid', 'path', 'name', 'shop_id', 'sort', 'show', 'describe', 'photo');
		$categoryDb = D('category');
		if ($categoryList = $categoryDb->where($where)->order($order)->field($field)->select()) {
			echo json_encode(array('status' => 1, 'msg' => '访问成功', "categoryList" => $categoryList));
		} else {
			echo json_encode(array('status' => 0, 'msg' => '暂无分类数据'));
		}
	}
	/**
	 * @description: 添加分类
	 */
	public function addCategory()
	{
		//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
		$this->isPower();

		if ($_REQUEST['name'] && $_REQUEST['shop_id']) {
			//data数据
			$data['pid'] = $_REQUEST['id'];
			$data['shop_id'] = $_REQUEST['shop_id'];
			$data['name'] = $_REQUEST['name'];
			$data['sort'] = $_REQUEST['sort'];
			$data['show'] = $_REQUEST['show'] == 'true' ?  '1' : '0';
			$data['describe'] = $_REQUEST['desc'];
			//如果有上传图片得操作 执行如下
			if ($_REQUEST['upFile']) { //有新图上传 则把图片从temp目录 复制到目标目录
				if (!(copy("Data/UploadFiles/temp/" . $_REQUEST['upFile'], "Data/UploadFiles/category/" . $_REQUEST['upFile']))) {
					echo json_encode(array('status' => 0, 'msg' => '图片复制失败'));
					exit;
				}
				$data['photo'] = json_encode(array($_REQUEST['upFile'])); //序列化储存
			}
			//录入数据库
			$categoryDb = D('category');
			if ($id = $categoryDb->data($data)->add()) { //先添加一条新纪录
				$where['id'] = $id;
				if ($_REQUEST['path']) { //重新组合path
					$saveData['path'] = $_REQUEST['path'] . '-' . $id;
				} else {
					$saveData['path'] = $id;
				}
				if ($categoryDb->where($where)->data($saveData)->save()) { //再更新记录的path字段
					echo json_encode(array('status' => 1, 'msg' => '添加成功'));
				} else {
					echo json_encode(array('status' => 0, 'msg' => '添加失败'));
				}
			} else {
				echo json_encode(array('status' => 0, 'msg' => '添加失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: 更新分类
	 */
	public function saveCategory()
	{
		//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
		$this->isPower();

		if ($_REQUEST['id'] && $_REQUEST['name'] && $_REQUEST['shop_id']) {
			//data数据
			$data['name'] = $_REQUEST['name'];
			$data['sort'] = $_REQUEST['sort'];
			$data['show'] = $_REQUEST['show'] == 'true' ?  '1' : '0';
			$data['describe'] = $_REQUEST['desc'];
			//如果有上传图片得操作 执行如下
			if ($_REQUEST['upFile']) { //有新图上传 则把图片从temp目录 复制到目标目录
				if (!(copy("Data/UploadFiles/temp/" . $_REQUEST['upFile'], "Data/UploadFiles/category/" . $_REQUEST['upFile']))) {
					echo json_encode(array('status' => 0, 'msg' => '图片复制失败'));
					exit;
				}
				if ($_REQUEST['oldFile']) { //存在老图 既删掉老图 没有成功的话 将刚才复制到此目录得新图也一并删除
					if (!(unlink("Data/UploadFiles/category/" . basename($_REQUEST['oldFile'])))) {
						unlink("Data/UploadFiles/category/" . $_REQUEST['upFile']);
						echo json_encode(array('status' => 0, 'msg' => '原图删除失败'));
						exit;
					}
				}
				$data['photo'] = json_encode(array($_REQUEST['upFile'])); //序列化储存
			}
			//where条件
			$where['id'] = $_REQUEST['id'];
			$where['shop_id'] = $_REQUEST['shop_id'];
			//录入数据库
			$categoryDb = D('category');
			if ($categoryDb->where($where)->data($data)->save()) {
				echo json_encode(array('status' => 1, 'msg' => '更新成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '更新失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	public function deleteCategory()
	{
		//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
		$this->isPower();

		if ($_REQUEST['delIdArr'] && $_REQUEST['shop_id']) {
			//where条件
			$where['shop_id'] = $_REQUEST['shop_id'];
			$where['id'] = array("in", $_REQUEST['delIdArr']);
			$categoryDb = D('category');
			if ($categoryDb->where($where)->delete()) {
				echo json_encode(array('status' => 1, 'msg' => '删除成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '删除失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: 获取spu列表
	 */
	public function getSpuList()
	{
		if ($this->tokenShop_id != C('powerId')) {
			$where['shop_id'] = $this->tokenShop_id; //非总管理员 只返回自己的账户信息
		}
		$where['del'] = '0';
		$order['sort'] = 'desc';
		$order['id'] = 'desc';
		$spuDb = D('spu');
		if ($spuList = $spuDb->where($where)->order($order)->select()) {
			echo json_encode(array('status' => 1, 'msg' => '访问成功', "spuList" => $spuList));
		} else {
			echo json_encode(array('status' => 0, 'msg' => '暂无商品数据'));
		}
	}
	/**
	 * @description: 修改商品spu的排序字段
	 */
	public function orderSpu()
	{
		//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
		$this->isPower();

		if ($_REQUEST['id'] && $_REQUEST['sort'] != '' && $_REQUEST['shop_id']) {
			$data['sort'] = (int)$_REQUEST['sort'];
			//where条件
			$where['id'] = $_REQUEST['id'];
			$where['shop_id'] = $_REQUEST['shop_id'];
			//录入数据库
			$spuDb = D('spu');
			if ($spuDb->where($where)->save($data)) {
				echo json_encode(array('status' => 1, 'msg' => '更新成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '更新失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: 修改商品spu的显示隐藏字段
	 */
	public function showSpu()
	{
		//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
		$this->isPower();

		if ($_REQUEST['id'] && $_REQUEST['show'] != '' && $_REQUEST['shop_id']) {
			$data['show'] = $_REQUEST['show'];
			//where条件
			$where['id'] = $_REQUEST['id'];
			$where['shop_id'] = $_REQUEST['shop_id'];
			//录入数据库
			$spuDb = D('spu');
			if ($spuDb->where($where)->save($data)) {
				echo json_encode(array('status' => 1, 'msg' => '更新成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '更新失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: 修改商品spu的推荐位字段
	 */
	public function recommendSpu()
	{
		//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
		$this->isPower();

		if ($_REQUEST['id'] && $_REQUEST['recommend'] != '' && $_REQUEST['shop_id']) {
			$data['recommend'] = $_REQUEST['recommend'];
			//where条件
			$where['id'] = $_REQUEST['id'];
			$where['shop_id'] = $_REQUEST['shop_id'];
			//录入数据库
			$spuDb = D('spu');
			if ($spuDb->where($where)->save($data)) {
				echo json_encode(array('status' => 1, 'msg' => '更新成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '更新失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: 添加商品spu
	 */
	public function addSpu()
	{
		//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
		$this->isPower();

		if ($_REQUEST['name'] && $_REQUEST['shop_id']) {
			//如果有上传图片得操作 执行如下
			if ($_REQUEST['upFile']) { //有新图上传 则把图片从temp目录 复制到目标目录
				if (!(copy("Data/UploadFiles/temp/" . $_REQUEST['upFile'], "Data/UploadFiles/spu/" . $_REQUEST['upFile']))) {
					echo json_encode(array('status' => 0, 'msg' => '图片复制失败'));
					exit;
				}
				$data['photo'] = json_encode(array($_REQUEST['upFile'])); //序列化储存
			}
			//data数据
			$data['shop_id'] = $_REQUEST['shop_id'];
			$data['path'] = $_REQUEST['path'];
			$data['name'] = $_REQUEST['name'];
			$data['spu_number'] = $_REQUEST['spu_number'];
			$data['sort'] = $_REQUEST['sort'];
			$data['hot'] = $_REQUEST['hot'];
			$data['pro_tag'] = $_REQUEST['pro_tag'];
			$data['bind_sku'] = $_REQUEST['bind_sku'];
			$data['recommend'] = $_REQUEST['recommend'];
			$data['show'] = $_REQUEST['show'];

			$data['addtime'] = time();
			//录入数据库
			$spuDb = D('spu');
			if ($spuDb->data($data)->add()) {
				echo json_encode(array('status' => 1, 'msg' => '创建成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '创建失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: 更新商品 spu
	 */
	public function saveSpu()
	{
		//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
		$this->isPower();

		if ($_REQUEST['name'] && $_REQUEST['id'] && $_REQUEST['shop_id']) {
			//如果有上传图片得操作 执行如下
			if ($_REQUEST['upFile']) { //有新图上传 则把图片从temp目录 复制到目标目录
				if (!(copy("Data/UploadFiles/temp/" . $_REQUEST['upFile'], "Data/UploadFiles/spu/" . $_REQUEST['upFile']))) {
					echo json_encode(array('status' => 0, 'msg' => '图片复制失败'));
					exit;
				}
				if ($_REQUEST['oldFile']) { //存在老图 既删掉老图 没有成功的话 将刚才复制到此目录得新图也一并删除
					if (!(unlink("Data/UploadFiles/spu/" . basename($_REQUEST['oldFile'])))) {
						unlink("Data/UploadFiles/spu/" . $_REQUEST['upFile']);
						echo json_encode(array('status' => 0, 'msg' => '原图删除失败'));
						exit;
					}
				}
				$data['photo'] = json_encode(array($_REQUEST['upFile'])); //序列化储存
			}
			//data数据
			$data['path'] = $_REQUEST['path'];
			$data['name'] = $_REQUEST['name'];
			$data['spu_number'] = $_REQUEST['spu_number'];
			$data['sort'] = $_REQUEST['sort'];
			$data['hot'] = $_REQUEST['hot'];
			$data['pro_tag'] = $_REQUEST['pro_tag'];
			$data['bind_sku'] = $_REQUEST['bind_sku'];
			$data['recommend'] = $_REQUEST['recommend'];
			$data['show'] = $_REQUEST['show'];
			$data['shop_id'] = $_REQUEST['shop_id'];
			//where条件
			$where['id'] = $_REQUEST['id'];
			//录入数据库
			$spuDb = D('spu');
			if ($spuDb->where($where)->data($data)->save()) {
				echo json_encode(array('status' => 1, 'msg' => '更新成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '更新失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: spu删除 ps:只改 del字段标识 并非真正删除
	 */
	public function deleteSpu()
	{
		if ($this->tokenShop_id != C('powerId')) {
			$where['shop_id'] = $this->tokenShop_id; //非总管理员 只返回自己的账户信息
		}

		if ($_REQUEST['idArr']) {
			// 获取要删除的航线ID数组
			$where['id'] = array("in", $_REQUEST['idArr']);
			//data数据
			$data['del'] = '1';
			//录入数据库
			$spuDb = D('spu');
			if ($spuDb->where($where)->save($data)) {
				echo json_encode(array('status' => 1, 'msg' => '删除成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '删除失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: 获取sku列表
	 */
	public function getSkuList()
	{
		if ($this->tokenShop_id != C('powerId')) {
			$where['shop_id'] = $this->tokenShop_id; //非总管理员 只返回自己的账户信息
		}

		$where['del'] = '0';
		$order['id'] = 'desc';
		$skuDb = D('sku');
		if ($skuList = $skuDb->where($where)->order($order)->select()) {
			echo json_encode(array('status' => 1, 'msg' => '访问成功', "skuList" => $skuList));
		} else {
			echo json_encode(array('status' => 0, 'msg' => '暂无商品数据'));
		}
	}
	/**
	 * @description: 添加商品sku
	 */
	public function addSku()
	{
		//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
		$this->isPower();

		if ($_REQUEST['name'] && $_REQUEST['shop_id']) {
			//如果有上传图片得操作 执行如下
			if ($_REQUEST['upFile']) { //有新图上传 则把图片从temp目录 复制到目标目录
				if (!(copy("Data/UploadFiles/temp/" . $_REQUEST['upFile'], "Data/UploadFiles/sku/" . $_REQUEST['upFile']))) {
					echo json_encode(array('status' => 0, 'msg' => '图片复制失败'));
					exit;
				}
				$data['photo'] = json_encode(array($_REQUEST['upFile'])); //序列化储存
			}
			//data数据
			$data['shop_id'] = $_REQUEST['shop_id'];
			$data['name'] = $_REQUEST['name'];
			$data['sku_number'] = $_REQUEST['sku_number'];
			$data['price'] = (float)$_REQUEST['price'];
			$data['unit'] = $_REQUEST['unit'];
			$data['weight'] = $_REQUEST['weight'];
			if ($_REQUEST['stock'] != "") {
				$data['stock'] = $_REQUEST['stock'];
			}
			$data['purchase_channel'] = $_REQUEST['purchase_channel'];
			$data['addtime'] = time(); //插入记录时 调用当前系统时间值 插入
			//录入数据库
			$skuDb = D('sku');
			if ($skuDb->data($data)->add()) {
				echo json_encode(array('status' => 1, 'msg' => '创建成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '创建失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: 更新商品 sku
	 */
	public function saveSku()
	{
		//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
		$this->isPower();

		if ($_REQUEST['name'] && $_REQUEST['id'] && $_REQUEST['shop_id']) {
			//如果有上传图片得操作 执行如下
			if ($_REQUEST['upFile']) { //有新图上传 则把图片从temp目录 复制到目标目录
				if (!(copy("Data/UploadFiles/temp/" . $_REQUEST['upFile'], "Data/UploadFiles/sku/" . $_REQUEST['upFile']))) {
					echo json_encode(array('status' => 0, 'msg' => '图片复制失败'));
					exit;
				}
				if ($_REQUEST['oldFile']) { //存在老图 既删掉老图 没有成功的话 将刚才复制到此目录得新图也一并删除
					if (!(unlink("Data/UploadFiles/sku/" . $_REQUEST['oldFile']))) {

						if (unlink("Data/UploadFiles/temp/" . $_REQUEST['upFile'])) {
							echo json_encode(array('status' => 0, 'msg' => '成功'));
							exit;
						} else {
							echo json_encode(array('status' => 0, 'msg' => '失败'));
							exit;
						}
						echo json_encode(array('status' => 0, 'msg' => '原图删除失败'));
						exit;
					}
				}
				$data['photo'] = json_encode(array($_REQUEST['upFile'])); //序列化储存
			}
			//data数据
			$data['shop_id'] = $_REQUEST['shop_id'];
			$data['name'] = $_REQUEST['name'];
			$data['sku_number'] = $_REQUEST['sku_number'];
			$data['price'] = (float)$_REQUEST['price'];
			$data['unit'] = $_REQUEST['unit'];
			$data['weight'] = $_REQUEST['weight'];
			$data['stock'] = $_REQUEST['stock'];
			$data['purchase_channel'] = $_REQUEST['purchase_channel'];
			//where条件
			$where['id'] = $_REQUEST['id'];
			//录入数据库
			$skuDb = D('sku');
			if ($skuDb->where($where)->data($data)->save()) {
				echo json_encode(array('status' => 1, 'msg' => '更新成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '更新失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: sku删除 ps:只改 del字段标识 并非真正删除
	 */
	public function deleteSku()
	{
		if ($this->tokenShop_id != C('powerId')) {
			$where['shop_id'] = $this->tokenShop_id; //非总管理员 只返回自己的账户信息
		}

		if ($_REQUEST['idArr']) {
			// 获取要删除的航线ID数组
			$where['id'] = array("in", $_REQUEST['idArr']);
			//data数据
			$data['del'] = '1';
			//录入数据库
			$skuDb = D('sku');
			if ($skuDb->where($where)->save($data)) {
				echo json_encode(array('status' => 1, 'msg' => '删除成功'));
			} else {
				echo json_encode(array('status' => 0, 'msg' => '删除失败'));
			}
		} else {
			echo json_encode(array('status' => 0, 'msg' => '参数有误'));
		}
	}
	/**
	 * @description: 获取订单列表
	 */
	public function getOrderList()
	{
		if ($this->tokenShop_id != C('powerId')) {
			$where['shop_id'] = $this->tokenShop_id; //非总管理员 只返回自己的账户信息
		}
		$orderDb = D('order');
		if ($orderList = $orderDb->where($where)->select()) {
			echo json_encode(array('status' => 1, 'msg' => '访问成功', "orderList" => $orderList));
		} else {
			echo json_encode(array('status' => 0, 'msg' => '暂无订单数据'));
		}
	}
}
