where(array('merchantid' => $merchant_id, 'status' => 0, 'type' => 1))->order('code asc')->select(); $this->assign('goodsClass1', json_encode($class_name)); } /* * 查询供货商与仓库 * @param $merchant_id 商户id */ private function Info($merchant_id) { $where['merchantid'] = $merchant_id; $where['status'] = 1; $supplier = M('retail_supplier')->field("id,supplier_name")->where($where)->order('id desc')->select(); $map['merchant_id'] = $merchant_id; $map['status'] = 1; $fields = "id,name"; $warehouse = D('PurchaseWarehouse')->getSelect($map, $page = '', $limit = '', $fields, $order = 'default_state desc'); $this->assign('supplier', json_encode($supplier)); $this->assign('warehouse', json_encode($warehouse)); } public function index() { $arr = array( 'exportOperation' => '/index.php/Retail/PurchaseGoods/export', ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $user = session("merchant_userinfo"); $this->Info($user['id']); $this->goodsClass($user['id']); $this->display(); } //采购串号信息 public function purchaseSerial() { $data = I('post.'); $data['user_type'] = 3; $data['type'] = 1; $SerialClass = new SerialNumberGoods(); $result = $SerialClass->purchaseDetailSerial($data); $this->ajaxReturn($result); } //采购退货串号信息 public function retreatSerial() { $data = I('post.'); $data['user_type'] = 3; $RetreatOrderClass = new RetreatOrder(); $result = $RetreatOrderClass->basisPurchaseOrderSerial($data); $this->ajaxReturn($result); } //入库的串号信息 public function warehouseSerial() { $data = I('post.'); $data['user_type'] = 3; $WarehousingClass = new WarehousingRecord(); $result = $WarehousingClass->basisOrderSerial($data); $this->ajaxReturn($result); } //采购商品明细列表goodsList public function goodsList() { $data = I('post.'); $data['user_type'] = 3; $data['merchant_id'] = $this->merchant_id; $PurchaseGoodsClass = new PurchaseGoodsInfo(); $result = $PurchaseGoodsClass->purchaseGoodsList($data); $this->ajaxReturn($result); } //导出 public function export() { $user = session("merchant_userinfo"); $merchant_id = $user['id']; $content = I("get."); $order_number = $content['order_number']; $supplier_id = $content['supplier_id']; $warehouse_id = $content['warehouse_id']; $add_time = $content['add_time']; $person1 = $content['person1']; $person2 = $content['person2']; $person3 = $content['person3']; if (!empty($order_number)) { $where['order_number|goods_number|sku_goods_number|goods_code|sku_code|goods_name|sku_name'] = array('like', '%' . $order_number . '%'); } if (!empty($supplier_id)) { $where['supplier_id'] = $supplier_id; } if (!empty($warehouse_id)) { $where['warehouse_id'] = $warehouse_id; } if (!empty($add_time)) { $add_time = explode(',', $add_time); $start_time = strtotime($add_time[0]); $end_time = strtotime($add_time[1]); $where['add_time'] = array('between', array($start_time, $end_time)); } $flag = 0; if (!empty($person3)) { $where['goods_class_id'] = $person3; } else if (!empty($person2)) { $class = M('retail_goods_class as c2') ->join('ls_retail_goods_class as c3 on c2.id=c3.pid') ->where(array('c2.id' => $person2, 'c3.status' => 0)) ->field('c3.id')->select(); $flag = 1; } else if (!empty($person1)) { $class = M('retail_goods_class as c1') ->join('ls_retail_goods_class as c2 on c1.id=c2.pid') ->join('ls_retail_goods_class as c3 on c2.id=c3.pid AND c3.status=0', 'LEFT') ->where(array('c1.id' => $person1, 'c2.status' => 0)) ->field('c2.id,c3.id as c3_id')->select(); $flag = 1; } if (!empty($class)) { $arr = array(); foreach ($class as &$val) { if (!in_array($val['id'], $arr)) { $arr[] = $val['id']; } if (!empty($val['c3_id'])) { if (!in_array($val['c3_id'], $arr)) { $arr[] = $val['c3_id']; } } } $str = implode(',', $arr); $where['goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1)); } else if ($flag == 1) { $where['goods_class_id'] = $person2 ? $person2 : $person1; } $where['merchant_id'] = $merchant_id; $goodsList = D('PurchaseGoods')->getSelect($where, $page = '', $limit = ''); if ($goodsList) { foreach ($goodsList as $key => &$val) { $val['index'] = $key + 1; if (!empty($val['build_date'])) { $val['build_date'] = date('Y-m-d', $val['build_date']); } $val['sku_num'] = strval(round($val['sku_num'], 3)); $val['class_name'] = M('retail_goods_class')->where(array('id' => $val['goods_class_id']))->getField("class_name"); $val['supplier_name'] = M('retail_supplier')->where(array('id' => $val['supplier_id']))->getField("supplier_name"); $val['warehouse_name'] = D('PurchaseWarehouse')->getFindField(array('id' => $val['warehouse_id']), "name"); $val['purchase_num'] = strval(round($val['purchase_num'], 3)); $val['warehousing_num'] = strval(round($val['warehousing_num'], 3)); $val['retreat_num'] = strval(round($val['retreat_num'], 3)); $val['purchase_price'] = strval(round($val['purchase_price'], 2)); $val['subtotal'] = strval(round($val['subtotal'], 2)); if ($val['attribute_state'] == 2) { $val['goods_number'] = $val['sku_goods_number']; $val['goods_code'] = $val['sku_code']; } } } else { $goodsList = array(); } $fileds_name = "采购商品明细导出"; $arr = array( array('index', '序号'), array('class_name', '分类'), array('goods_name', '商品名称'), array('sku_name', '规格'), array('goods_number', '货号'), array('goods_code', '条码'), array('company', '单位'), array('build_date', '生产日期'), array('quality_guarantee_period', '保质期'), array('sku_num', '规格基数'), array('purchase_num', '采购数量'), array('warehousing_num', '入库数量'), array('retreat_num', '退货数量'), array('purchase_price', '金额'), array('subtotal', '小计'), array('supplier_name', '供货商'), array('warehouse_name', '仓库'), array('order_number', '批次号'), array('remarks', '备注'), ); $str = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time()); getExcel($fileds_name, $arr, $goodsList, $str); } }