<?php
/** 店铺登录
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaoq <570035208@qq.com>
 */

namespace App\Model;
use Think\Model;
class InvoicingOrderModel extends Model{
    /**
        App查询商品格式化返回数据
    */
    public function search_by_keyword($postdata){
        $return=array('status'=>1,'msg'=>'','data'=>'');
        $sid=I('sid');
        $token=I('token');
        $postdata=I('param.');
        $result=D('Common/InvoicingOrder')->search_by_keyword($postdata);
        if($result['status'] == 0){
            return $result;
        }
        if($result['status']){
            $attr = array();
            if($result['data']['left_list']){
                foreach ($result['data']['left_list'] as $key => $value) {
                    if($value['goods_attrs']){  //有属性
                        foreach ($value['goods_attrs'] as $k => $v) {
                            unset($v['goods_attrs']);
                            $attr[$v['index']] = $v;
                        }unset($k,$v);
                    }else{
                        $attr[$value['index']] = $value;
                    }
                }unset($key,$value);
            }
            if($result['data']['right_list']){
                foreach ($result['data']['right_list'] as $key => $value) {
                    if($value['goods_attrs']){  //有属性
                        foreach ($value['goods_attrs'] as $k => $v) {
                            unset($v['goods_attrs']);
                            $attr[$v['index']] = $v;
                        }unset($k,$v);
                    }else{
                        $attr[$value['index']] = $value;
                    }
                }unset($key,$value);
            }
            if($attr){
				unset($result['data']['left_list']);unset($result['data']['right_list']);
				$new_arr = $result['data'];
				$return['arr'] = $new_arr;
                $return['data'] = $attr;
                $return['status'] = 1;
            }else{
                $return['msg'] = '没有更多商品了';
            }
        }
        return $return;
    }
    //用于数组分页
    public function arr_page($attr,$pagefrom=0,$pagesize=10){
        if(empty($attr))return false;
        $pagefrom=intval($pagefrom);
        $attr_count=count($attr);$return=array('attr'=>$attr,'pagefrom'=>0);
        if($attr_count>$pagesize){
            $newarr=array();$i=0;$x=0;
            foreach($attr as $k=>$v){
                if($x>=$pagefrom && $i<$pagesize){
                    $newarr[$k]=$v;$i++;
                }$x++;
            }
            $endnum=count($newarr)+$pagefrom;
            if($attr_count>$endnum){
                $return['pagefrom'] =$endnum;
            }
            $return['attr']=$newarr;
        }
        return $return;
    }
    /**
        得到商品分类节点树
    **/
    public function getcateTree($pid=0){
        $GoodsCategory = getcache('PurchaseCategory');
        $Tree = new \Common\Vendor\Tree();
        $select_categorys = '';
        $treemini = $Tree->treemini($GoodsCategory);
        $select_categorys .= $Tree->treeminioption($treemini, $pid);
        return $select_categorys;
    }
    public function check_auth($sid,$action){
        $return=array('status'=>0,'msg'=>'');
        if(empty($sid) || empty($action)){$return['msg']='参数错误'; return $return;}
        $map=array();
        $map['account_id']=$sid;
        $role_id=M('ShopsRoleAccount')->where($map)->getField('role_id');
        $map=array();
        $map['role_id']=$role_id;
        $map['module']='Pad';
        $map['action']=$action;
        $result=M('ShopsRoleAuth')->where($map)->count();
        if(empty($result)){ $return['msg']='没有操作此模块的权限'; return $return;}
        $return['status']=1;
        return $return;
    }
}
?>