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)); } /* * 商品分类 */ private function goodsClass($merchant_id) { $class_name = M('retail_goods_class')->where(array('merchantid' => $merchant_id, 'status' => 0, 'type' => 1))->order('code asc')->select(); $this->assign('goodsClass1', json_encode($class_name)); } /* * 采购退货单信息 */ public function index() { $arr = array( 'addRetreatOrder' => '/index.php/Retail/RetreatOrder/addRetreatOrder', 'exportOperation' => '/index.php/Retail/RetreatOrder/export', 'OrderInfo' => '/index.php/Retail/RetreatOrder/details' ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $user = session("merchant_userinfo"); $this->Info($user['id']); $this->display(); } //退货统计 public function OrderTotal() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 3; $data['merchant_id'] = $this->merchant_id; $RetreatOrderClass = new RetreatOrder(); $result = $RetreatOrderClass->orderTotal($data); $this->ajaxReturn($result); } //退货列表 public function retreatOrderList() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 3; $data['merchant_id'] = $this->merchant_id; $RetreatOrderClass = new RetreatOrder(); $result = $RetreatOrderClass->orderList($data); $this->ajaxReturn($result); } //新增采购退货退货退货退货单信息 public function addRetreatOrder() { $arr = array( 'goodsChoice' => '/index.php/Retail/RetreatOrder/goodsList', 'onSubmit' => '/index.php/Retail/RetreatOrder/retreatOperation', ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $user = session("merchant_userinfo"); $this->Info($user['id']); $this->goodsClass($user['id']); $this->display(); } //采购退货可退商品的串码列表 public function serialList() { $data = I('post.'); $data['user_type'] = 3; $SerialClass = new SerialNumberGoods(); $result = $SerialClass->returnableSerialList($data); $this->ajaxReturn($result); } //采购退货的可退商品列表goodsList public function goodsList() { $content = I("post."); $content['user_type'] = 3; //商户 $content['merchant_id'] = $this->merchant_id; $PurchaseGoodsClass = new PurchaseGoodsInfo(); $result = $PurchaseGoodsClass->returnablePurchaseGoodsList($content); $this->ajaxReturn($result); } //采购退货详情 public function details() { $arr = [ 'exportOperation' => '/index.php/Retail/RetreatOrder/detailsExport', ]; $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $id = I('get.id'); $operator = I('get.operator'); $this->assign('operator', $operator); $where['id'] = $id; $info = D('PurchaseRetreatOrder')->getFind($where); $info['add_time'] = date('Y-m-d H:i:s', $info['add_time']); $info['goods_species'] = round($info['goods_species'], 3); $info['remarks'] = str_replace("\n", "", $info['remarks']); $supplier = M('retail_supplier')->where(array('id' => $info['supplier_id']))->getField("supplier_name"); $warehouse = D('PurchaseWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name"); $this->assign('id', $id); $this->assign('info', $info); $this->assign('supplier', $supplier); $this->assign('warehouse', $warehouse); $this->display(); } //详情串号列表 public function detailSerialList() { $data = I('post.'); $data['user_type'] = 3; $data['type'] = 2; $SerialClass = new SerialNumberGoods(); $result = $SerialClass->purchaseDetailSerial($data); $this->ajaxReturn($result); } //退货详情列表 public function detailsList() { $data = I('post.'); $data['user_type'] = 3; $RetreatOrderClass = new RetreatOrder(); $result = $RetreatOrderClass->detailsList($data); $this->ajaxReturn($result); } /* * *************************************************操作****************************************************** */ /* * 采购退货操作 */ public function retreatOperation() { $data = I('post.'); $data['merchant_id'] = $this->merchant_id; $data['operator_id'] = session("jurisdiction_user")['id']; $result = A("Api/Inventory")->MerRetreatAction($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '采购退货管理-新增';//操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //导出 public function export() { $user = session("merchant_userinfo"); $content = I("get."); $order_number = $content['order_number']; $supplier_id = $content['supplier_id']; $warehouse_id = $content['warehouse_id']; $add_time = $content['add_time']; if (!empty($order_number)) { $where['order_number'] = 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)); } $where['merchant_id'] = $user['id']; $where['status'] = 1; $info = D('PurchaseRetreatOrder')->getSelect($where, $page = '', $limit = '', $field = "*", $order = "id desc"); if ($info) { foreach ($info as $key => &$val) { $val['index'] = $key + 1; $val['operator'] = A('Api/Inventory')->OperatorName($val['operator_id']); $val['add_time'] = date('Y-m-d H:i:s', $val['add_time']); $val['supplier'] = M('retail_supplier')->where(array('id' => $val['supplier_id']))->getField("supplier_name"); $val['warehouse'] = D('PurchaseWarehouse')->getFindField(array('id' => $val['warehouse_id']), "name"); $val['goods_species'] = $val['goods_species'] . "种"; $val['money_total'] = strval(round($val['money_total'], 2)); $val['total_cost_price'] = strval(round($val['total_cost_price'], 2)); $val['difference_money'] = strval(round($val['money_total'] - $val['total_cost_price'], 2)); } } $fileds_name = "采购退货单导出"; $arr = array( array('index', '序号'), array('operator', '操作人'), array('add_time', '退货时间'), array('order_number', '退货单号'), array('supplier', '供应商'), array('warehouse', '仓库'), array('goods_species', '合计(种)'), array('total_cost_price', '原采购金额'), array('money_total', '退货金额'), array('difference_money', '盈亏金额'), array('remarks', '备注'), ); $str = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time()); getExcel($fileds_name, $arr, $info, $str); } //详情导出 public function detailsExport() { $id = I('get.id'); $where['id'] = $id; $info = D('PurchaseRetreatOrder')->getFind($where); $info['add_time'] = date('Y-m-d H:i:s', $info['add_time']); $info['goods_species'] = round($info['goods_species'], 3); $supplier = M('retail_supplier')->where(array('id' => $info['supplier_id']))->getField("supplier_name"); $warehouse = D('PurchaseWarehouse')->getFindField(array('id' => $info['warehouse_id']), "name"); $map['retreat_order_id'] = $id; $detailsList = D('RetreatGoods')->getSelect($map, $page = '', $limit = '', $field = '', 'id asc'); if ($detailsList) { foreach ($detailsList as $key => &$val) { $val['index'] = $key + 1; if (!empty($val['build_date'])) { $val['build_date'] = date('Y-m-d', $val['build_date']); } $val['retreat_num'] = strval(round($val['retreat_num'], 3)); $val['retreat_price'] = strval(round($val['retreat_price'], 2)); $val['subtotal'] = strval(round($val['subtotal'], 2)); $val['sku_num'] = strval(round($val['sku_num'], 3)); if ($val['attribute_state'] == 2) { $val['goods_number'] = $val['sku_goods_number']; $val['goods_code'] = $val['sku_code']; } $val['purchase_price'] = strval(round($val['purchase_price'], 2)); $val['difference_money'] = strval(round(($val['retreat_price'] - $val['purchase_price']) * $val['retreat_num'], 2)); } } $fileds_name = "采购退货单详情导出"; $arr = array( array('index', '序号'), array('purchase_order_number', '采购单号'), 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_price', '原采购价'), array('retreat_price', '退货价'), array('retreat_num', '数量'), array('subtotal', '合计'), array('difference_money', '盈亏'), array('remarks', '备注'), ); $str = array(); $str[0] = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time()); $str[1] = '采购退货单号:' . $info['order_number'] . " 供应商:" . $supplier . " 出库仓库:" . $warehouse; $str[2] = '创建时间:' . $info['add_time'] . " 合计:" . $info['goods_species'] . " 金额:" . strval($info['money_total']); $str[3] = "备注:" . $info['remarks']; detailGetExcel($fileds_name, $arr, $detailsList, $str); } }