'/index.php/Retail/Transfer/export', 'apply' => '/index.php/Retail/AllocationApply/apply_details', 'warehousing' => '/index.php/Retail/Transfer/warehousing', 'refuseInfo' => '/index.php/Retail/StockOutOrder/refuseInfo' ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $this->display(); } /* * 订单列表 */ public function OrderList() { $merchant_id = session("merchant_userinfo")['id']; $data = I("post."); $add_time = $data['add_time']; $status = $data['status']; $order_number = $data['order_number']; $page = $data['page']; $limit = $data['limit']; if (!empty($add_time)) { $start_time = strtotime($add_time[0]); $end_time = strtotime($add_time[1]); $where['add_time'] = array('between', array($start_time, $end_time)); } if (!empty($order_number)) { $where['order_number'] = $order_number; } if (!empty($status)) { $where['status'] = $status; } $where['merchant_id'] = $merchant_id; $list = D('AllocationOrder')->getSelect($where, $page, $limit); if ($list) { $count = D('AllocationOrder')->getCount($where); foreach ($list as $key => &$val) { $val['index'] = $key + 1; $val['store_name'] = D('Store')->getStoreName(array('id' => $val['store_id'])); $val['operator'] = A('Api/Inventory')->OperatorName($val['m_operator_id']); $val['add_time'] = date('Y-m-d H:i:s', $val['add_time']); if (!empty($val['stock_time'])) { $val['stock_time'] = date('Y-m-d H:i:s', $val['stock_time']); } if (!empty($val['storage_time'])) { $val['storage_time'] = date('Y-m-d H:i:s', $val['storage_time']); } else if (!empty($val['refuse_time'])) { $val['storage_time'] = date('Y-m-d H:i:s', $val['refuse_time']); } switch ($val['status']) { case 1: $val['status_name'] = "申请中"; break; case 2: if ($val['refuse_status'] == 2) { $val['status_name'] = "已拒收"; } else { $val['status_name'] = "已出库"; } break; case 3: $val['status_name'] = "已入库"; break; } } } else { $count = 0; } $res['status'] = 1; $res['count'] = $count; $res['data'] = $list; $this->ajaxReturn($res); } /* * 出库详情 */ public function warehousing() { $arr = array( 'onSubmit' => '/index.php/Retail/Transfer/stockOperation' ); $authArr = checkFunction($arr); $this->assign('authArr', $authArr); $id = I("get.id"); $info = D('AllocationOrder')->getFind(array('id' => $id)); $info['add_time'] = date('Y-m-d H:i:s', $info['add_time']); $info['remarks'] = str_replace("\n", "", $info['remarks']); $this->assign('id', $id); $this->assign('info', $info); $this->display(); } /* * 出库详情列表 */ public function warehousingList() { $id = I("post.id"); $AllocationGoodsModel = new AllocationGoodsModel(); $SaleMGoodsModel = new SaleMGoodsModel(); $list = $AllocationGoodsModel->getSelect(array('allocation_id' => $id), $page = '', $limit = '', $fields = '', 'id asc'); foreach ($list as $key => &$val) { $where = [ 'goods_id' => $val['goods_id'] ]; if ($val['attribute_state'] == 2) { $where['sku_id'] = $val['sku_id']; } $goods = $SaleMGoodsModel->getFind($where); $val['apply_num'] = round($val['apply_num'], 3); if ($val['serial_number_state'] == 1) { $val['stock_num'] = 0; } else { $val['stock_num'] = $val['apply_num']; } $val['sku_num'] = round($val['sku_num'], 3); $val['goods_num'] = round($goods['goods_num'], 3); $val['cost_price'] = round($goods['cost_price'], 2); $stockInfo = D('StockOutGoods')->getFind($where, "id desc"); if ($stockInfo) { $val['stock_price'] = $stockInfo['stock_price']; } else { $val['stock_price'] = $goods['cost_price']; } $val['stock_price'] = round($val['stock_price'], 2); $val['subtotal'] = round($val['stock_price'] * $val['stock_num'], 2); } $res['status'] = 1; $res['data'] = $list; $this->ajaxReturn($res); } //出库操作 public function stockOperation() { $merchant_id = $this->merchant_id; $operator_id = session("jurisdiction_user")['id']; $goodsList = I("post.goodsList"); $goodsList = json_decode(htmlspecialchars_decode($goodsList), true); $id = I("post.id"); $remarks = I("post.remarks"); if (!$id || !$goodsList) { $res['status'] = 0; $res['msg'] = "参数错误"; $this->ajaxReturn($res); } $AllocationOrderModel = new AllocationOrderModel(); $info = $AllocationOrderModel->getFind(array('id' => $id)); if (!$info) { $res['status'] = 0; $res['msg'] = '未找到该订单'; $this->ajaxReturn($res); } if ($info['status'] == 2) { $res['status'] = 0; $res['msg'] = '已出库,请勿重复操作'; $this->ajaxReturn($res); } $store_id = $info['store_id']; $SaleWarehouseModel = new SaleWarehouseModel(); $warehouse_id = $SaleWarehouseModel->getFindField(array('merchant_id' => $merchant_id, 'status' => 1), "id"); $type = 3;//门店申请调拨出库 $order_number = $info['order_number']; foreach ($goodsList as $key => &$val) { $val['output_num'] = round($val['stock_num'], 3); if ($val['serial_number_state'] == 1 && $val['output_num'] != count($val['serial_list'])) { $res = ['status' => 0, 'msg' => '串号信息与数量不符']; $this->ajaxReturn($res); } unset($val['stock_num']); } if (C('IS_SET_REDIS')) { $ApiRedis = new \Addons\Api\RedisController(); $key_name = "Retail_merchant_id_" . $merchant_id . "_store_id_" . $store_id . "_allocation_id_" . $id; if ($ApiRedis::$redis->exists($key_name)) { $res['status'] = 0; $res['msg'] = "正在入库,请勿重复操作"; $this->ajaxReturn($res); } $ApiRedis::$redis->setex($key_name, 60, $id); } $parameter = array( 'merchant_id' => $merchant_id, 'store_id' => $store_id, 'operator_id' => $operator_id, 'warehouse_id' => $warehouse_id, 'type' => $type, 'goodsList' => $goodsList, 'remarks' => $remarks, 'order_number' => $order_number ); $res = A("Api/Inventory")->MerStockOut($parameter); if ($res['status'] == 1) { //出库成功 $saveData = array(); $saveData['stock_order_id'] = $res['stockOrderId']; $saveData['warehouse_order_id'] = $res['warehouseOrderId']; $saveData['goods_species'] = $res['goods_species']; $saveData['money_total'] = $res['money_total']; $saveData['status'] = 2; $saveData['stock_time'] = time(); $saveData['m_operator_id'] = session("jurisdiction_user")['id']; $res = D('AllocationOrder')->updateData(array('id' => $id), $saveData); if ($res['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); } } else { $res['status'] = 0; } if (C('IS_SET_REDIS')) { $ApiRedis::$redis->delete($key_name); } $this->ajaxReturn($res); } /* * 订单导出 */ public function export() { $merchant_id = $this->merchant_id; $data = I("get."); $add_time = $data['add_time']; $status = $data['status']; $order_number = $data['order_number']; if (!empty($add_time)) { if (!is_array($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)); } if (!empty($order_number)) { $where['order_number'] = $order_number; } if (!empty($status)) { $where['status'] = $status; } $where['merchant_id'] = $merchant_id; $list = D('AllocationOrder')->getSelect($where); if ($list) { foreach ($list as $key => &$val) { $val['index'] = $key + 1; $val['store_name'] = D('Store')->getStoreName(array('id' => $val['store_id'])); $val['operator'] = A('Api/Inventory')->OperatorName($val['m_operator_id']); $val['add_time'] = date('Y-m-d H:i:s', $val['add_time']); if (!empty($val['stock_time'])) { $val['stock_time'] = date('Y-m-d H:i:s', $val['stock_time']); } if (!empty($val['storage_time'])) { $val['storage_time'] = date('Y-m-d H:i:s', $val['storage_time']); } else if (!empty($val['refuse_time'])) { $val['storage_time'] = date('Y-m-d H:i:s', $val['refuse_time']); } switch ($val['status']) { case 1: $val['status_name'] = "申请中"; break; case 2: if ($val['refuse_status'] == 2) { $val['status_name'] = "已拒收"; } else { $val['status_name'] = "已出库"; } break; case 3: $val['status_name'] = "已入库"; break; } } } $fileds_name = "调拨单导出"; $arr = array( array('index', '序号'), array('operator', '操作人'), array('store_name', '申请门店'), array('add_time', '申请时间'), array('stock_time', '出库时间'), array('storage_time', '操作时间'), array('order_number', '调拨单号'), array('store_goods_species', '申请合计(种)'), array('goods_species', '应收合计(种)'), array('money_total', '应收金额'), array('accept_goods_species', '实收合计(种)'), array('accept_money_total', '实收金额'), array('remarks', '备注'), array('status_name', '状态'), ); $str = $fileds_name . ',导出日期:' . date('Y-m-d H:i:s', time()); getExcel($fileds_name, $arr, $list, $str); } }