<?php
namespace Api\Controller;

use Think\Controller;

header("Content-Type:text/html;CharSet=UTF-8");
class ReimBurseController extends Controller
{
	/**
	 * 村管理员报损
	 */
	public function village_burse()
	{
		$village_id=$_GET['village_id'];
		$goods_name=I('goods_name');
		$good_id=M('goods')->where("goods_name='{$goods_name}'")->field('`id`')->find();
		$num=I('num');
		$thumb=json_decode($_GET['thumb']);
		$len=count($thumb);	
		//dump($len);die;	
		$create_time=date('Y-m-d',time());
		$sn=$village_id.time().$good_id['id'];
		if (!$village_id || $village_id == "undefined" || $village_id == "null") {
            $data = array("status" => -1, "msg" => "村ID有误");
        }elseif (!$num || $num == "undefined" || $num == "null" || $num == 0) {
            $data = array("status" => -1, "msg" => "数量必填");
        }elseif (!$goods_name || $goods_name == "undefined" || $goods_name == "null") {
            $data = array("status" => -1, "msg" => "商品名称必填");
        }elseif($len>4){
        	$data = array("status" => -1, "msg" => "最多上传四张图片");
        }else{
        	 $addData=array(
        	'sn'=>$sn,
        	'village_id'=>$village_id,
        	'goods_name'=>$goods_name,
        	'num'=>$num,
        	'thumb_1'=>$thumb[0],
        	'thumb_2'=>$thumb[1],
        	'thumb_3'=>$thumb[2],
        	'thumb_4'=>$thumb[3],
        	'create_time'=>$create_time        
        	);
        $result=M('reimburse')->add($addData);
        if($result){
        	$data = array("status" => 1, "msg" => "货物报损成功");
        } else {
        	$data = array("status" => -1, "msg" => "货物报损失败");
        }
        }
       
        apiReturn($data);	
	}
	
}

