returnablePurchaseGoodsTerm($param); //查询条件 $where['goods_id'] = $param['goods_id']; if (!empty($param['sku_id'])) { $where['sku_id'] = $param['sku_id']; } switch ($param['user_type']) { case 3: $PurchaseGoodsModel = new PurchaseGoodsModel(); break; case 4: $PurchaseGoodsModel = new SPurchaseGoodsModel(); break; } $list = $PurchaseGoodsModel->getSelect($where, $param['page'], $param['limit']); if (!empty($list)) { $count = $PurchaseGoodsModel->getCount($where); foreach ($list as $key => &$val) { $val['index'] = $key + 1; $val['purchase_price'] = round($val['purchase_price'], 2); $val['surplus_num'] = round($val['surplus_num'], 3); $val['sku_num'] = round($val['sku_num'], 3); } } return callBack(statusCode()['success'], '查询成功', [ 'list' => $list ? $list : [], 'count' => $count ? $count : 0 ]); } /** * 采购退货的单品扫码查询 * @param $param * [ * user_type 3商户 4门店 * merchant_id * store_id * supplier_id 供货商id * warehouse_id 仓库id * search_info 搜索的信息(条码) * ] * @return mixed */ public function returnablePurchaseScanCodeGoods($param) { $verifyResult = $this->returnablePurchaseGoodsVerify($param); if ($verifyResult['status'] != 1) { $verifyResult['message'] = $verifyResult['msg']; return $verifyResult; } if (empty($param['search_info'])) { return callBack(statusCode()['error'], "请将摄像头对准条码扫描"); } $where = $this->ScanCodeGoodsTerm($param); switch ($param['user_type']) { case 3: //商户 $PurchaseGoodsModel = new PurchaseGoodsModel(); $PurchaseOrderModel = new PurchaseOrderModel(); break; case 4: //门店 $PurchaseGoodsModel = new SPurchaseGoodsModel(); $PurchaseOrderModel = new SPurchaseOrderModel(); break; } $info = $PurchaseGoodsModel->getFind($where); if (!empty($info)) { if (!empty($info['build_date'])) { $info['build_date'] = date("Y-m-d", $info['build_date']); } $info['purchase_num'] = round($info['purchase_num'], 3); $info['surplus_num'] = round($info['surplus_num'], 3); $info['retreat_num'] = round($info['retreat_num'], 3); $info['retreat_num_act'] = 1; //退货数量 $info['order_number'] = $PurchaseOrderModel->getFindField(['id' => $info['purchase_order_id']], "order_number"); if ($info['surplus_num'] <= 0) { return callBack(statusCode()['error'], "暂无可退库存"); } else { if ($info['surplus_num'] < $info['retreat_num_act']) { $info['retreat_num_act'] = $info['surplus_num']; } return callBack(statusCode()['success'], "查询成功", $info); } } else { return callBack(statusCode()['error'], "未找到该商品"); } } /** * 采购退货的单品扫码的查询条件 * @param $param * [ * user_type 3商户 4门店 * merchant_id * store_id * supplier_id 供货商id * warehouse_id 仓库id * search_info 搜索的信息(条码) * ] * @return mixed */ public function ScanCodeGoodsTerm($param) { $where = [ 'merchant_id' => $param['merchant_id'], 'supplier_id' => $param['supplier_id'], 'warehouse_id' => $param['warehouse_id'], 'goods_code|sku_code' => $param['search_info'], 'surplus_num' => ['gt', 0], ]; if ($param['user_type'] == 4) { $where['store_id'] = $param['store_id']; } return $where; } /** * 采购入库的商品列表 * @param $param * [ * user_type 3商户 4门店 * merchant_id * store_id * exists_id_arr 已选中的采购商品 * searchText 名称货号条码 * supplier_id 供货商id * ] * @return array *[ * status * message * data=>[ * list 列表 * count 总条数 * ] * ] * @return mixed */ public function warehousePurchaseGoodsList($param) { $where = $this->returnablePurchaseGoodsTerm($param); //查询条件 switch ($param['user_type']) { case 3: //商户 $PurchaseGoodsModel = new PurchaseGoodsModel(); break; case 4: //门店 $PurchaseGoodsModel = new SPurchaseGoodsModel(); break; } $list = $PurchaseGoodsModel->getSelect($where, $param['page'], $param['limit'], "*", "id desc"); if (!empty($list)) { $count = $PurchaseGoodsModel->getCount($where); foreach ($list as $key => &$value) { if (!empty($value['build_date'])) { $value['build_date'] = date("Y-m-d", $value['build_date']); } $value['purchase_num'] = round($value['purchase_num'], 3); $value['surplus_num'] = round($value['surplus_num'], 3); $value['purchase_price'] = round($value['purchase_price'], 2); } } return callBack(statusCode()['success'], '查询成功', [ 'list' => $list ? $list : [], 'count' => $count ? $count : 0 ]); } /** *采购退货的可退商品列表 * @param $param * [ * user_type 3商户 4门店 * merchant_id * store_id * exists_id_arr 已选中的采购商品 * searchText 名称货号条码 * supplier_id 供货商id * warehouse_id 仓库id * ] * @return array *[ * status * message * data=>[ * list 列表 * count 总条数 * ] * ] */ public function returnablePurchaseGoodsList($param) { $verify = $this->returnablePurchaseGoodsVerify($param); //验证参数 if ($verify['status'] != 1) { return $verify; } $where = $this->returnablePurchaseGoodsTerm($param); //查询条件 switch ($param['user_type']) { case 3: //商户 $PurchaseGoodsModel = new PurchaseGoodsModel(); break; case 4: //门店 $PurchaseGoodsModel = new SPurchaseGoodsModel(); break; } $list = $PurchaseGoodsModel->getSelect($where, $param['page'], $param['limit'], "*", "id desc"); if (!empty($list)) { $count = $PurchaseGoodsModel->getCount($where); foreach ($list as $key => &$value) { if (!empty($value['build_date'])) { $value['build_date'] = date("Y-m-d", $value['build_date']); } $value['purchase_num'] = round($value['purchase_num'], 3); $value['surplus_num'] = round($value['surplus_num'], 3); $value['retreat_num'] = round($value['retreat_num'], 3); } } return callBack(statusCode()['success'], '查询成功', [ 'list' => $list ? $list : [], 'count' => $count ? $count : 0 ]); } /** * 采购退货的可退商品列表的where条件 * @param $param * [ * user_type 3商户 4门店 * merchant_id * store_id * exists_id_arr 已选中的采购商品 * searchText 名称货号条码 * supplier_id 供货商id * warehouse_id 仓库id * ] * @return array|\Common\Business\条件数组[] */ public function returnablePurchaseGoodsTerm($param) { $goodsClassify = new GoodsClassify(); $where = $goodsClassify->getGoodsClassId($param, [], "goods_class_id"); //获取分类id if (!empty($param['searchText'])) { //名称货号条码 $where['goods_number|goods_code|goods_name|sku_code|order_number|sku_goods_number'] = array('like', '%' . $param['searchText'] . '%'); } if (!empty($param['exists_id_arr'])) { //已选中的商品 $where['id'] = array('not in', $param['exists_id_arr']); } if (!empty($param['warehouse_id'])) { $where['warehouse_id'] = $param['warehouse_id']; } if ($param['user_type'] == 4) { $where['store_id'] = $param['store_id']; } $where['merchant_id'] = $param['merchant_id']; $where['supplier_id'] = $param['supplier_id']; $where['surplus_num'] = array('gt', 0); return $where; } /** * 采购退货的可退商品列表的参数验证 * @param $parameter * [ * user_type 3商户 4门店 * merchant_id * store_id * supplier_id 供货商id * warehouse_id 仓库id * ] * @return array */ public function returnablePurchaseGoodsVerify($parameter) { if (empty($parameter['user_type']) || !in_array($parameter['user_type'], ['3', '4'])) { return ['status' => 0, 'msg' => '未知请求源']; } if (empty($parameter['merchant_id']) || ($parameter['user_type'] == 4 && empty($parameter['store_id']))) { return ['status' => 0, 'msg' => '登录超时']; } if (empty($parameter['supplier_id'])) { return ['status' => 0, 'msg' => '请选择供货商']; } if (empty($parameter['warehouse_id'])) { return ['status' => 0, 'msg' => '请选择仓库']; } return ['status' => 1, 'msg' => '验证成功']; } /** * 采购商品明细列表 * @param $param * [ * user_type 3商户 4门店 * merchant_id * store_id * showPrice 1可以查看进价 2不可以 * identity 1商户查看 2门店查看 * order_number * supplier_id * warehouse_id * add_time * person1 * person2 * person3 * page * limit * ] * @return mixed */ public function purchaseGoodsList($param) { $where = $this->purchaseGoodsTerm($param); $GoodsClassModel = new RetailGoodsClassModel(); switch ($param['user_type']) { case 3: $PurchaseGoodsModel = new PurchaseGoodsModel(); $SupplierModel = new RetailSupplierModel(); $PurchaseWarehouseModel = new PurchaseWarehouseModel(); break; case 4: $PurchaseGoodsModel = new SPurchaseGoodsModel(); $SupplierModel = new SSupplierModel(); $PurchaseWarehouseModel = new SPurchaseWarehouseModel(); break; } $list = $PurchaseGoodsModel->getSelect($where, $param['page'], $param['limit'], '*'); if (!empty($list)) { $count = $PurchaseGoodsModel->getCount($where); foreach ($list 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'] = round($val['sku_num'], 3); $val['class_name'] = $GoodsClassModel->getFindField(['id' => $val['goods_class_id']], 'class_name'); $val['supplier_name'] = $SupplierModel->getFindField(['id' => $val['supplier_id']], 'supplier_name'); $val['warehouse_name'] = $PurchaseWarehouseModel->getFindField(array('id' => $val['warehouse_id']), "name"); $val['purchase_num'] = round($val['purchase_num'], 3); $val['warehousing_num'] = round($val['warehousing_num'], 3); $val['retreat_num'] = round($val['retreat_num'], 3); if ($param['user_type'] == 3 || ($param['showPrice'] != 2 || $param['identity'] == 1)) { $val['purchase_price'] = round($val['purchase_price'], 2); $val['subtotal'] = round($val['subtotal'], 2); } else { $val['purchase_price'] = '***'; $val['subtotal'] = '***'; } if ($val['attribute_state'] == 2) { $val['goods_number'] = $val['sku_goods_number']; $val['goods_code'] = $val['sku_code']; } } } return callBack(statusCode()['success'], '查询成功', [ 'list' => $list ? $list : 0, 'count' => $count ? $count : 0 ]); } /** * 采购商品明细的查询条件 * @param $param * [ * user_type 3商户 4门店 * merchant_id * store_id * order_number * supplier_id * warehouse_id * add_time * person1 * person2 * person3 * ] * @return mixed */ public function purchaseGoodsTerm($param) { $GoodsClassify = new GoodsClassify(); $where = $GoodsClassify->getGoodsClassId($param, [], 'goods_class_id'); if (!empty($param['order_number'])) { $where['order_number|goods_number|sku_goods_number|goods_code|sku_code|goods_name|sku_name'] = array('like', '%' . $param['order_number'] . '%'); } if (!empty($param['supplier_id'])) { $where['supplier_id'] = $param['supplier_id']; } if (!empty($param['warehouse_id'])) { $where['warehouse_id'] = $param['warehouse_id']; } if (!empty($param['add_time'])) { $start_time = strtotime($param['add_time'][0]); $end_time = strtotime($param['add_time'][1]); $where['add_time'] = array('between', array($start_time, $end_time)); } if ($param['user_type'] == 4) { $where['store_id'] = $param['store_id']; } $where['merchant_id'] = $param['merchant_id']; return $where; } /** * 采购单商品详情 * @param $param * [ * user_type 3商户 4门店 * id 采购单id * serial_page_state 是否查询串号信息 1不查询2查询 * showPrice 1可以查看进价 2不可以 * identity 1商户查看 2门店查看 * ] * @return array */ public function basisIdGetPurchaseGoodsList($param) { $verify = $this->basisIdGetPurchaseGoodsTerm($param); if ($verify['status'] != 1) { return $verify; } $where['purchase_order_id'] = $param['id']; switch ($param['user_type']) { case 3: //商户 $PurchaseOrderModel = new PurchaseOrderModel(); $PurchaseGoodsModel = new PurchaseGoodsModel(); $PurchaseGoodsSerialModel = new PurchaseGoodsSerialModel(); $WarehouseGoodsModel = new WarehousingGoodsModel(); $WarehouseSerialModel = new WarehouseGoodsSerialModel(); $RetreatGoodsModel = new RetreatGoodsModel(); break; case 4: //门店 $PurchaseOrderModel = new SPurchaseOrderModel(); $PurchaseGoodsModel = new SPurchaseGoodsModel(); $PurchaseGoodsSerialModel = new SPurchaseGoodsSerialModel(); $WarehouseGoodsModel = new SWarehousingGoodsModel(); $WarehouseSerialModel = new SWarehouseGoodsSerialModel(); $RetreatGoodsModel = new SRetreatGoodsModel(); break; } $list = $PurchaseGoodsModel->getSelect($where, '', '', '*', 'id asc'); if (!empty($list)) { $warehouse_serial_arr = []; $not_sale = []; $SerialClass = new SerialNumberGoods(); $serial_page_state = $param['serial_page_state'] ? $param['serial_page_state'] : 2; if ($serial_page_state == 2) { //已经出售的无法编辑 $order_number = $PurchaseOrderModel->getFindField([ 'id' => $param['id'] ], 'order_number'); if (!empty($order_number)) { $warehouse_id_arr = $WarehouseGoodsModel->getFindField([ 'purchase_order_number' => $order_number ], 'id', true); if (!empty($warehouse_id_arr)) { $warehouseList = $WarehouseSerialModel->getSelect([ 'outside_id' => ['in', $warehouse_id_arr], ], '', '', 'num,main_serial_number'); if (!empty($warehouseList)) { foreach ($warehouseList as $v) { if ($v['num'] > 0) { $not_sale[] = $v['main_serial_number']; } else { $warehouse_serial_arr[] = $v['main_serial_number']; } } } } //已经退货的不可编辑 $retreat_id_arr = $RetreatGoodsModel->getFindField([ 'purchase_order_number' => $order_number ], 'id', true); if (!empty($retreat_id_arr)) { $retreat_serial_arr = $PurchaseGoodsSerialModel->getFindField([ 'outside_id' => ['in', $retreat_id_arr], 'type' => 2 ], 'main_serial_number',true); $warehouse_serial_arr = array_merge($warehouse_serial_arr, $retreat_serial_arr); } } } foreach ($list as $key => &$val) { $val['index'] = $key + 1; $val['sku_num'] = round($val['sku_num'], 3); $val['purchase_num'] = round($val['purchase_num'], 3); $val['retail_price'] = $val['retail_price'] ? round($val['retail_price'], 2) : ''; $val['online_price'] = $val['online_price'] ? round($val['online_price'], 2) : ''; $val['warehousing_num'] = round($val['warehousing_num'], 2); $val['retreat_num'] = round($val['retreat_num'], 2); $val['operated_num'] = round($val['retreat_num'] + $val['warehousing_num'], 2); if ($param['user_type'] == 3 || $serial_page_state == 2 || ($param['showPrice'] != 2 || $param['identity'] == 1)) { $val['purchase_price'] = round($val['purchase_price'], 2); $val['subtotal'] = round($val['subtotal'], 2); } else { $val['subtotal'] = '***'; $val['purchase_price'] = '***'; } if (!empty($val['build_date'])) { $val['build_date'] = date('Y-m-d', $val['build_date']); } if ($val['attribute_state'] == 2) { $val['goods_number'] = $val['sku_goods_number']; $val['goods_code'] = $val['sku_code']; } //串号信息 if ($val['serial_number_state'] == 1 && $serial_page_state == 2) { $serial_list = $SerialClass->purchaseDetailSerial([ 'user_type' => $param['user_type'], 'id' => $val['id'], 'type' => 1 ])['data']; if (!empty($warehouse_serial_arr) || !empty($not_sale)) { foreach ($serial_list as &$v) { if (in_array($v['main_serial_number'], $warehouse_serial_arr)) { $v['edit_status'] = 1; } else if (in_array($v['main_serial_number'], $not_sale)) { $v['edit_status'] = 2; } } } $val['serial_list'] = $serial_list; } } } return callBack(statusCode()['success'], '查询成功', $list); } /** * 采购单商品详情的参数验证 * @param $parameter * [ * user_type 3商户 4门店 * id 采购单id * ] * @return array */ public function basisIdGetPurchaseGoodsTerm($parameter) { if (!in_array($parameter['user_type'], ['3', '4'])) { return ['status' => 0, 'message' => '未知请求源']; } if (empty($parameter['id'])) { return ['status' => 0, 'message' => '缺少采购单ID']; } return ['status' => 1, 'message' => '验证成功']; } }