searchGoodsTerm($param); //查询条件 if ($param['type'] == 2 && !empty($param['search_info'])) { $SerialClass = new SerialNumberGoods(); $result = $SerialClass->basisSerialGetGoods([ 'user_type' => $param['user_type'], 'serial_number' => trim($param['search_info'], ' '), 'store_id' => $param['store_id'] ? $param['store_id'] : 0, 'merchant_id' => $param['merchant_id'] ]); if ($result['status'] != 1) { return callBack(statusCode()['success'], '查询成功', [ 'list' => [], 'count' => 0 ]); } $where['goods_id'] = ['in',array_column($result['data'],'goods_id')]; if (!empty($result['data']['sku_id'])) { $where['sku_id'] = $result['data']['sku_id']; } } if (!empty($param['stock_status'])) { switch ($param['stock_status']) { case 1: $where['_string'] = "goods_num <= less_num"; break; case 2: $where['_string'] = "goods_num >= more_num"; break; case 3: $where['_string'] = "goods_num <= 0"; break; } } switch ($param['user_type']) { case 3: $SaleMGoodsModel = new SaleMGoodsModel(); $PurchaseGoodsModel = new PurchaseGoodsModel(); break; case 4: $SaleMGoodsModel = new SSaleMGoodsModel(); $PurchaseGoodsModel = new SPurchaseGoodsModel(); break; } $list = $SaleMGoodsModel->getSelect($where, $param['page'], $param['limit'], "*", "goods_num asc"); if (!empty($list)) { $count = $SaleMGoodsModel->getCount($where); foreach ($list as $key => &$val) { $val['index'] = $key + 1; $val['more_num'] = round($val['more_num'], 3); $val['less_num'] = round($val['less_num'], 3); $val['goods_num'] = round($val['goods_num'], 3); $val['sku_num'] = round($val['sku_num'], 3); if ($val['attribute_state'] == 2) { $val['goods_number'] = $val['sku_goods_number']; $val['goods_code'] = $val['sku_code']; } $map = [ 'merchant_id' => $param['merchant_id'], 'goods_id' => $val['goods_id'], 'surplus_num' => ['gt', 0] ]; if ($val['attribute_state'] == 2) { $map['sku_id'] = $val['sku_id']; } $purchaseGoodsList = $PurchaseGoodsModel->getSelect($map, '', '', 'surplus_num,purchase_price'); $actual_num = 0; //采购库总数量 $amount_total = 0; //采购库总金额 if (!empty($purchaseGoodsList)) { foreach ($purchaseGoodsList as $ke => &$va) { $actual_num += $va['surplus_num']; $amount_total += ($va['surplus_num'] * $va['purchase_price']); } } $val['actual_num'] = round($val['goods_num'] + $actual_num, 3); if ($param['user_type'] == 4 && $param['showPrice'] == 2 && $param['identity'] == 2) { $val['cost_price'] = '***'; $val['amount_total'] = '***'; } else { $val['cost_price'] = round($val['cost_price'], 2); $val['amount_total'] = round(($val['cost_price'] * $val['goods_num']) + $amount_total, 2); } if ($val['goods_num'] <= $val['less_num']) { $val['warning_name'] = "缺货"; } else if ($val['goods_num'] >= $val['more_num']) { $val['warning_name'] = "超量"; } else { $val['warning_name'] = "正常"; } switch ($val['status']) { case 0: $val['status_name'] = "上架"; break; case 1: $val['status_name'] = "下架"; break; } } } return callBack(statusCode()['success'], '查询成功', [ 'list' => $list ? $list : [], 'count' => $count ? $count : 0 ]); } /** * 根据商品id获取商品列表(用于优惠券详情) * @param goods_id_str string * @return mixed */ public function appointGoodsList($goods_id_str) { $goods_id_arr = explode(',', $goods_id_str); $arr = []; foreach ($goods_id_arr as $key => $val) { if (strpos($val, '_') !== false) { $id_arr = explode('_', $val); $arr[$key]['goods_id'] = $id_arr[0]; $arr[$key]['sku_id'] = $id_arr[1]; } else { $arr[$key]['goods_id'] = $val; } } if (!empty($arr)) { try { $SaleModel = new SSaleMGoodsModel(); $fields = [ 'id', 'goods_id', 'sku_id', 'goods_name', 'sku_name', 'goods_number', 'sku_goods_number', 'goods_code', 'sku_code', 'attribute_state', 'goods_num', ]; foreach ($arr as $key => &$value) { $where['goods_id'] = $value['goods_id']; if (!empty($value['sku_id'])) { $where['sku_id'] = $value['sku_id']; } $value = $SaleModel->basisOrderFind($where, $fields, 'id desc'); if (!empty($value) && !empty($value['sku_id'])) { $value['goods_number'] = $value['sku_goods_number']; $value['goods_code'] = $value['sku_code']; } $value['index'] = $key + 1; unset($where); } } catch (\Exception $e) { return []; } } return $arr; } /** * 依据分类id查询商品信息 * @param $param * [ * operator_type 1后台端 2收银端 3助手端 * user_type 3商户 4门店 * merchant_id * store_id * id 分类id * class_type 1一级分类 2二级分类 3三级分类 * search_info 搜索的信息(名称货号条码) * exists_id_arr 已经选择了的商品id集合 * status 0上架 1下架 2删除 * page * limit * ] * @return mixed */ public function basisClassIdGetGoods($param) { if (empty($param['id']) || empty($param['class_type'])) { return callBack(statusCode()['error'], "缺少分类参数"); } switch ($param['class_type']) { case 1: $param['person1'] = $param['id']; break; case 2: $param['person2'] = $param['id']; break; case 3: $param['person3'] = $param['id']; break; } $result = $this->getGoodsList($param); return $result; } /** * 门店指定单品时的商品信息 * @param $param * operator_type 1后台端 2收银端 3助手端 * user_type 3商户 4门店 * merchant_id * store_id * person1 一级分类 * person2 二级分类 * person3 三级分类 * search_info 搜索的信息(名称货号条码) * exists_id_arr 已经选择了的商品id集合 * status 0上架 1下架 2删除 * page * limit * @return mixed */ public function getGoodsList($param) { $VerifyClass = new VerifyParam(); $verifyResult = $VerifyClass->identityVerify($param); if ($verifyResult['status'] != 1) { return $verifyResult; } $where = $this->searchGoodsTerm($param); $fields = [ 'id', 'goods_id', 'sku_id', 'goods_name', 'sku_name', 'goods_number', 'sku_goods_number', 'goods_code', 'sku_code', 'attribute_state', 'goods_num', ]; $SaleModel = new SSaleMGoodsModel(); $list = $SaleModel->getSelect($where, $param['page'], $param['limit'], $fields, 'id desc'); if (!empty($list)) { $count = $SaleModel->getCount($where); $GoodsModel = new RetailGoodsModel(); $SkuGoodsModel = new RetailSkuGoodsModel(); $ImageGalleryModel = new ImageGalleryModel(); foreach ($list as $key => &$val) { $val['index'] = $key + 1; if ($val['attribute_state'] == 2) { $val['goods_number'] = $val['sku_goods_number']; $val['goods_code'] = $val['sku_code']; $map = [ 'id' => $val['sku_id'] ]; $img_id = $SkuGoodsModel->getFindField($map, 'goods_img_id'); } else { $map = [ 'id' => $val['goods_id'] ]; $img_id = $GoodsModel->getFindField($map, 'goods_img_id'); } if (!empty($img_id)) { $val['image_url'] = $ImageGalleryModel->getImagePath($img_id); } else { $val['image_url'] = ''; } } } return callBack(statusCode()['success'], "查询成功", [ 'count' => $count ? $count : 0, 'list' => $list ? $list : [] ]); } /** *出库单的扫码查询 * @param $param * [ * operator_type 1后台端 2收银端 3助手端 * user_type 3商户 4门店 * merchant_id * store_id * search_info 搜索的信息(条码) * type 向商户退货出库 * ] * @return mixed */ public function warehouseScanCodeGoods($param) { $VerifyClass = new VerifyParam(); $verifyResult = $VerifyClass->identityVerify($param); //参数验证 if ($verifyResult['status'] != 1) { return $verifyResult; } if (empty($param['search_info'])) { return callBack(statusCode()['error'], "请将摄像头对准条码扫描"); } $where = $this->codeGoodsTerm($param); //查询条件 try { switch ($param['user_type']) { case 3: //商户 $SaleMGoodsModel = new SaleMGoodsModel(); $StockOutGoodsModel = new StockOutGoodsModel(); break; case 4: //门店 $SaleMGoodsModel = new SSaleMGoodsModel(); $StockOutGoodsModel = new SStockOutGoodsModel(); if ($param['type'] == 1) { // 退货至商户出库 $goods_id_arr = M('retail_store_warehouse_goods') ->where(array('merchant_id' => $param['merchant_id'], 'store_id' => $param['store_id'], 'type' => array('in', '4,6'))) ->group("goods_id") ->getField("goods_id", true); if (!empty($goods_id_arr)) { $where['goods_id'] = array('in', $goods_id_arr); } else { return callBack(statusCode()['error'], "未从商户调拨", []); } } break; } $info = $SaleMGoodsModel->getFind($where); if (!empty($info)) { $info['output_num'] = 1; //默认出库数量 $info['goods_num'] = round($info['goods_num'], 3); if ($info['goods_num'] < 0) { return callBack(statusCode()['error'], "暂无库存"); } if ($info['goods_num'] < 1) { $info['output_num'] = $info['goods_num']; } $info['cost_price'] = round($info['cost_price'], 2); $map = []; $map['merchant_id'] = $param['merchant_id']; $map['goods_id'] = $info['goods_id']; if ($param['user_type'] == 4) { //门店 $map['store_id'] = $param['store_id']; } if ($info['attribute_state'] == 2) { $map['sku_id'] = $info['sku_id']; } $stockInfo = $StockOutGoodsModel->getFind($map, "id desc"); if (!empty($stockInfo)) { $info['stock_price'] = round($stockInfo['stock_price'], 2); } else { $info['stock_price'] = $info['cost_price']; } return callBack(statusCode()['success'], "查询成功", $info); } else { return callBack(statusCode()['error'], "未找到该商品"); } } catch (\Exception $e) { return callBack(statusCode()['error'], "未找到该商品"); } } /** * 出库单的单品查询 * @param $param * [ * operator_type 1后台端 2收银端 3助手端 * user_type 3商户 4门店 * merchant_id * store_id * type * industry_id 调拨目标门店的行业id * person1 一级分类 * person2 二级分类 * person3 三级分类 * search_info 搜索的信息(名称货号条码) * exists_id_arr 已经选择了的商品id集合 * page * limit * ] * @return mixed */ public function warehouseSearchGoods($param) { $where = $this->searchGoodsTerm($param); //查询条件 try { switch ($param['user_type']) { case 3: //商户 $SaleMGoodsModel = new SaleMGoodsModel(); $StockOutGoodsModel = new StockOutGoodsModel(); $WarehouseGoodsModel = new WarehousingGoodsModel(); break; case 4: //门店 $SaleMGoodsModel = new SSaleMGoodsModel(); $StockOutGoodsModel = new SStockOutGoodsModel(); $WarehouseGoodsModel = new SWarehousingGoodsModel(); if ($param['type'] == 1) { // 退货至商户出库 $goods_id_arr = M('retail_store_warehouse_goods') ->where(array('merchant_id' => $param['merchant_id'], 'store_id' => $param['store_id'], 'type' => array('in', '4,6'))) ->group("goods_id") ->getField("goods_id", true); if (!empty($goods_id_arr)) { $where['goods_id'] = array('in', $goods_id_arr); } else { return callBack(statusCode()['error'], "查询成功", [ 'list' => [], 'count' => 0 ]); } } break; } $list = $SaleMGoodsModel->getSelect($where, $param['page'], $param['limit'], '', "id desc"); if (!empty($list)) { if ($param['operator_type'] == 1) { //后台端 $count = $SaleMGoodsModel->getCount($where); } foreach ($list as $key => &$value) { $value['index'] = $key + 1; $value['output_num'] = ""; $value['goods_num'] = round($value['goods_num'], 3); $value['cost_price'] = round($value['cost_price'], 2); $map = [ 'merchant_id' => $param['merchant_id'], 'goods_id' => $value['goods_id'] ]; if ($value['attribute_state'] == 2) { $map['sku_id'] = $value['sku_id']; } switch ($param['user_type']) { case 3: if ($param['type'] == 4) { //向供货商退货出库 $map['type'] = 4; } else { $map['type'] = array('neq', 4); } break; case 4: if ($param['type'] == 9) { //向供货商退货出库 $map['type'] = 9; } else { $map['type'] = array('neq', 9); } $map['store_id'] = $param['store_id']; break; } $stockInfo = $StockOutGoodsModel->getFind($map, "id desc"); if (!empty($stockInfo)) { $value['stock_price'] = round($stockInfo['stock_price'], 2); } else { $value['stock_price'] = $value['cost_price']; } unset($map['type']); $map['surplus_num'] = ['gt', 0]; //先进先出原则获取生成日期与保质期 $wareInfo = $WarehouseGoodsModel->basisOrderFind($map, 'build_date,quality_guarantee_period', 'id asc'); $value['build_date'] = $wareInfo['build_date'] ? date('Y-m-d', $wareInfo['build_date']) : ''; $value['quality_guarantee_period'] = $wareInfo['quality_guarantee_period'] ? $wareInfo['quality_guarantee_period'] : ''; unset($map); unset($stockInfo); unset($wareInfo); } } return callBack(statusCode()['success'], "查询成功", [ 'list' => $list ? $list : [], 'count' => $count ? $count : 0 ]); } catch (\Exception $e) { return callBack(statusCode()['error'], "查询失败"); } } /** * 采购的扫码查询 * @param $param * [ * operator_type 1后台端 2收银端 3助手端 * user_type 3商户 4门店 * merchant_id * store_id * search_info 搜索的信息(条码) * ] * @return mixed */ public function purchaseScanCodeGoods($param) { $VerifyClass = new VerifyParam(); $verifyResult = $VerifyClass->identityVerify($param); //参数验证 if ($verifyResult['status'] != 1) { return $verifyResult; } if (empty($param['search_info'])) { return callBack(statusCode()['error'], "请将摄像头对准条码扫描"); } $where = $this->codeGoodsTerm($param); //查询条件 try { switch ($param['user_type']) { case 3: //商户 $GoodsModel = new SaleMGoodsModel(); break; case 4: //门店 $GoodsModel = new SSaleMGoodsModel(); break; } $info = $GoodsModel->getFind($where); if (!empty($info)) { switch ($param['user_type']) { case 3: //商户 $GoodsModel = new RetailMgoodsModel(); $SkuGoodsModel = new SkuMGoodsModel(); $PurchaseGoodsModel = new PurchaseGoodsModel(); break; case 4: //门店 $GoodsModel = new RetailGoodsModel(); $SkuGoodsModel = new RetailSkuGoodsModel(); $PurchaseGoodsModel = new SPurchaseGoodsModel(); break; } $info['purchase_num'] = 1; //默认进货数量 $info['goods_num'] = round($info['goods_num'], 3); $info['build_date'] = ""; //默认生产日期 $info['quality_guarantee_period'] = ""; //默认保质期 if ($info['attribute_state'] == 2) { //规格 switch ($param['user_type']) { case 3: $goods = $SkuGoodsModel->field("retail_price,online_price")->where([ 'mgoods_id' => $info['goods_id'], 'id' => $info['sku_id'] ])->find(); break; case 4: $goods = $SkuGoodsModel->field("retail_price,online_price")->where([ 'goods_id' => $info['goods_id'], 'id' => $info['sku_id'] ])->find(); break; } } else { //无规格 $goods = $GoodsModel->getFind(['id' => $info['goods_id']], "retail_price,online_price"); } $info['retail_price'] = $goods['retail_price'] ? round($goods['retail_price'], 2) : ''; //线下价 $info['online_price'] = $goods['online_price'] ? round($goods['online_price'], 2) : ''; //线上价 $map['goods_id'] = $info['goods_id']; if ($info['attribute_state'] == 2) { $map['sku_id'] = $info['sku_id']; } if ($param['user_type'] == 4) { //门店 $map['store_id'] = $param['store_id']; } $purchase_info = $PurchaseGoodsModel->getFind($map, "id desc"); if (!empty($purchase_info)) { $info['purchase_price'] = round($purchase_info['purchase_price'], 2); //最近一次的采购价 } else { $info['purchase_price'] = round($info['cost_price'], 2); } return callBack(statusCode()['success'], "查询成功", $info); } else { return callBack(statusCode()['error'], "未找到该商品"); } } catch (\Exception $e) { return callBack(statusCode()['error'], "未找到该商品"); } } /** * 采购的单品查询 * @param $param * [ * operator_type 1后台端 2收银端 3助手端 * user_type 3商户 4门店 * merchant_id * store_id * modify_price_state 采购可以修改店内价与商城价 1关闭 2开启 * person1 一级分类 * person2 二级分类 * person3 三级分类 * search_info 搜索的信息(名称货号条码) * exists_id_arr 已经选择了的商品id集合 * page * limit * ] * @return mixed */ public function purchaseSearchGoods($param) { $VerifyClass = new VerifyParam(); $verifyResult = $VerifyClass->identityVerify($param); //参数验证 if ($verifyResult['status'] != 1) { return $verifyResult; } $where = $this->searchGoodsTerm($param); //查询条件 try { switch ($param['user_type']) { case 3: //商户 $SaleGoodsModel = new SaleMGoodsModel(); break; case 4: //门店 $SaleGoodsModel = new SSaleMGoodsModel(); break; } $list = $SaleGoodsModel->getSelect($where, $param['page'], $param['limit'], "*", "goods_num asc"); if (!empty($list)) { if ($param['operator_type'] == 1) { //后台端 $count = $SaleGoodsModel->getCount($where); } switch ($param['user_type']) { case 3: $GoodsModel = new RetailMgoodsModel(); $SkuGoodsModel = new SkuMGoodsModel(); $PurchaseGoodsModel = new PurchaseGoodsModel(); break; case 4: $GoodsModel = new RetailGoodsModel(); $SkuGoodsModel = new RetailSkuGoodsModel(); $PurchaseGoodsModel = new SPurchaseGoodsModel(); break; } foreach ($list as $key => &$value) { $value['index'] = $key + 1; $value['purchase_num'] = ""; //默认进货数量 $value['goods_num'] = round($value['goods_num'], 3); $value['build_date'] = ""; //默认生产日期 $value['quality_guarantee_period'] = ""; //默认保质期 //最近一次的采购价 $map = [ 'goods_id' => $value['goods_id'] ]; if ($value['attribute_state'] == 2) { $map['sku_id'] = $value['sku_id']; } if ($param['user_type'] == 4) { //门店 $map['store_id'] = $param['store_id']; } $purchase_info = $PurchaseGoodsModel->getFind($map, "id desc"); if (!empty($purchase_info)) { $value['purchase_price'] = round($purchase_info['purchase_price'], 2); } else { $value['purchase_price'] = round($value['cost_price'], 2); } //开启修改售价 if ($param['modify_price_state'] == 2) { if ($value['attribute_state'] == 2) { //规格 switch ($param['user_type']) { case 3: $goods = $SkuGoodsModel->getFind([ 'mgoods_id' => $value['goods_id'], 'id' => $value['sku_id'] ], 'retail_price,online_price'); break; case 4: $goods = $SkuGoodsModel->getFind([ 'goods_id' => $value['goods_id'], 'id' => $value['sku_id'] ], 'retail_price,online_price'); break; } } else { //无规格 $goods = $GoodsModel->getFind(['id' => $value['goods_id']], "retail_price,online_price"); } $value['retail_price'] = $goods['retail_price'] ? round($goods['retail_price'], 2) : ''; //线下价 $value['online_price'] = $goods['online_price'] ? round($goods['online_price'], 2) : ''; //线上价 unset($goods); } unset($map); } } return callBack(statusCode()['success'], "查询成功", [ 'list' => $list ? $list : [], 'count' => $count ? $count : 0 ]); } catch (\Exception $e) { return callBack(statusCode()['error'], "查询失败"); } } /** * 报损的扫码查询 * @param $param * [ * operator_type 1后台端 2收银端 3助手端 * user_type 3商户 4门店 * merchant_id * store_id * search_info 搜索的信息(条码) * ] * @return mixed */ public function lossScanCodeGoods($param) { $VerifyClass = new VerifyParam(); $verifyResult = $VerifyClass->identityVerify($param); //参数验证 if ($verifyResult['status'] != 1) { return $verifyResult; } if (empty($param['search_info'])) { return callBack(statusCode()['error'], "请将摄像头对准条码扫描"); } $where = $this->codeGoodsTerm($param); try { switch ($param['user_type']) { case 3: //商户 $GoodsModel = new SaleMGoodsModel(); break; case 4: //门店 $GoodsModel = new SSaleMGoodsModel(); break; } $info = $GoodsModel->getFind($where); if (!empty($info)) { if (empty($info['goods_num']) || $info['goods_num'] <= 0) { return callBack(statusCode()['error'], "该商品暂无库存无法报损"); } $info['loss_num'] = 1; //默认的报损数量 if ($info['goods_num'] < 1) { $info['loss_num'] = $info['goods_num']; //默认的报损数量 } $info['goods_num'] = round($info['goods_num'], 3); $info['cost_price'] = round($info['cost_price'], 2); return callBack(statusCode()['success'], "查询成功", $info); } else { return callBack(statusCode()['error'], "未找到该商品"); } } catch (\Exception $e) { return callBack(statusCode()['error'], "未找到该商品"); } } /** * 报损的单品查询 * @param $param * [ * operator_type 1后台端 2收银端 3助手端 * user_type 3商户 4门店 * merchant_id * store_id * person1 一级分类 * person2 二级分类 * person3 三级分类 * search_info 搜索的信息(名称货号条码) * exists_id_arr 已经选择了的商品id集合 * page * limit * ] * @return mixed */ public function lossSearchGoods($param) { $VerifyClass = new VerifyParam(); $verifyResult = $VerifyClass->identityVerify($param); //参数验证 if ($verifyResult['status'] != 1) { return $verifyResult; } $where = $this->searchGoodsTerm($param); try { switch ($param['user_type']) { case 3: //商户 $GoodsModel = new SaleMGoodsModel(); break; case 4: //门店 $GoodsModel = new SSaleMGoodsModel(); break; } $list = $GoodsModel->getSelect($where, $param['page'], $param['limit'], '*', "id desc"); if (!empty($list)) { if ($param['operator_type'] == 1) { $count = $GoodsModel->getCount($where); } foreach ($list as $key => &$value) { $value['index'] = $key + 1; $value['loss_num'] = ""; //初始化报损数量 $value['goods_num'] = round($value['goods_num'], 3); $value['cost_price'] = round($value['cost_price'], 2); $value['store_id'] = $value['store_id'] ? $value['store_id'] : null; } } return callBack(statusCode()['success'], "查询成功", [ 'list' => $list ? $list : [], 'count' => $count ? $count : 0 ]); } catch (\Exception $e) { return callBack(statusCode()['error'], "查询失败"); } } /** * 盘点扫描条码查询 * @param $param * [ * operator_type 1后台端 2收银端 3助手端 * user_type 3商户 4门店 * merchant_id * store_id * supplier_type 1普通供货商 2寄售供货商 (针对门店) * search_info 搜索的信息(名称货号条码) * ] * @return mixed */ public function InventoryScanCodeGoods($param) { $VerifyClass = new VerifyParam(); $verifyResult = $VerifyClass->identityVerify($param); //参数验证 if ($verifyResult['status'] != 1) { return $verifyResult; } if (empty($param['search_info'])) { return callBack(statusCode()['error'], "请将摄像头对准条码扫描"); } $where = $this->codeGoodsTerm($param); //查询条件 try { switch ($param['user_type']) { case 3: //商户 $GoodsModel = new SaleMGoodsModel(); break; case 4: //门店 $GoodsModel = new SSaleMGoodsModel(); break; } $info = $GoodsModel->getFind($where); if (!empty($info)) { if (empty($info['cost_price']) || $info['cost_price'] <= 0) { return callBack(statusCode()['error'], "该商品还未进行任何入库无法盘点"); } $info['inventory_num'] = 1; //默认的盘点数量 $info['goods_num'] = round($info['goods_num'], 3); $info['cost_price'] = round($info['cost_price'], 2); if ($param['user_type'] == 4 && $param['supplier_type'] == 2) { //门店的寄售供货商的采购批次号 $info['pur_id'] = $GoodsModel->getPurchaseId([ 'goods_id' => $info['goods_id'], 'sku_id' => $info['sku_id'], 'store_id' => $param['store_id'], ]); $info['purchase_order_id'] = ''; //默认选中的采购单 } return callBack(statusCode()['success'], "查询成功", $info); } else { return callBack(statusCode()['error'], "未找到该商品"); } } catch (\Exception $e) { return callBack(statusCode()['error'], "未找到该商品"); } } /** * 盘点的单品查询 * @param $param * [ * operator_type 1后台端 2收银端 3助手端 * user_type 3商户 4门店 * merchant_id * store_id * person1 一级分类 * person2 二级分类 * person3 三级分类 * search_info 搜索的信息(名称货号条码) * exists_id_arr 已经选择了的商品id集合 * page * limit * ] * @return mixed * [ * data=>[ * list * count * ] * ] */ public function InventorySearchGoods($param) { $VerifyClass = new VerifyParam(); $verifyResult = $VerifyClass->identityVerify($param); //参数验证 if ($verifyResult['status'] != 1) { return $verifyResult; } $where = $this->searchGoodsTerm($param); //搜索条件 $where['cost_price'] = ['gt', 0]; $page = $param['page'] ? $param['page'] : 1; $limit = $param['limit'] ? $param['limit'] : 10; try { switch ($param['user_type']) { case 3: //商户 $GoodsModel = new SaleMGoodsModel(); break; case 4: //门店 $GoodsModel = new SSaleMGoodsModel(); break; } $list = $GoodsModel->getSelect($where, $page, $limit, "", "id desc"); if (!empty($list)) { if ($param['operator_type'] == 1) { $count = $GoodsModel->getCount($where); } if ($param['user_type'] == 4) { $StoreClass = new Store(); $supplier_type = $StoreClass->getSupplierType($param['store_id']); //门店供货商类型 } foreach ($list as $key => &$value) { $value['index'] = ($key + 1); $value['inventory_num'] = ""; //默认的盘点数量 $value['goods_num'] = round($value['goods_num'], 3); $value['cost_price'] = round($value['cost_price'], 2); $value['checked'] = false; //默认未选择 if ($supplier_type == 2 && $param['user_type'] == 4) { //寄售供货商的采购批次号 $value['pur_id'] = $GoodsModel->getPurchaseId([ 'goods_id' => $value['goods_id'], 'sku_id' => $value['sku_id'], 'store_id' => $param['store_id'], ]); $value['purchase_order_id'] = ''; //默认选中的采购单 } } } return callBack(statusCode()['success'], "查询成功", [ 'list' => $list ? $list : [], 'count' => $count ? $count : 0 ]); } catch (\Exception $e) { return callBack(statusCode()['error'], "查询失败"); } } /** * 其他入库的单品查询 * @param $param * [ * operator_type 1后台端 2收银端 3助手端 * user_type 3商户的商品 4门店的商品 * merchant_id * store_id * person1 一级分类 * person2 二级分类 * person3 三级分类 * search_info 搜索的信息(名称货号条码) * exists_id_arr 已经选择了的商品id集合 * page * limit * ] * @return mixed */ public function otherGoodsList($param) { $VerifyClass = new VerifyParam(); $verifyResult = $VerifyClass->identityVerify($param); //参数验证 if ($verifyResult['status'] != 1) { return $verifyResult; } $where = $this->searchGoodsTerm($param); //查询条件 switch ($param['user_type']) { case 3: //商户 $SaleMGoodsModel = new SaleMGoodsModel(); break; case 4: //门店 $SaleMGoodsModel = new SSaleMGoodsModel(); break; } $list = $SaleMGoodsModel->getSelect($where, $param['page'], $param['limit'], '*', "goods_num asc"); if (!empty($list)) { $count = $SaleMGoodsModel->getCount($where); foreach ($list as $key => &$value) { $value['index'] = $key + 1; $value['surplus_num'] = ""; $value['order_number'] = ""; $value['build_date'] = ""; $value['quality_guarantee_period'] = ""; $value['purchase_price'] = $value['cost_price']; } } return callBack(statusCode()['success'], '查询成功', [ 'list' => $list ? $list : [], 'count' => $count ? $count : 0 ]); } /** * 扫描商户门店条码查询条件 * @param $param * [ * user_type 3商户 4门店 * merchant_id * store_id * supplier_type 1普通供货商 2寄售供货商 (针对门店) * search_info 搜索的信息(条码) * ] * @return mixed */ public function codeGoodsTerm($param) { $where = [ 'merchant_id' => $param['merchant_id'], 'status' => ['in', ['0', '1']], 'goods_code|sku_code' => $param['search_info'] ]; if ($param['user_type'] == 4) { $where['store_id'] = $param['store_id']; } return $where; } /** * 查询商户门店单品的条件 * @param $param * [ * user_type 3商户的商品 4门店的商品 * merchant_id * store_id * industry_id 调拨目标门店的行业id * type 1名称货号条码 2串号 * person1 一级分类 * person2 二级分类 * person3 三级分类 * search_info 搜索的信息(名称货号条码) * exists_id_arr 已经选择了的商品id集合 * status 0上架 1下架 2删除 * ] * @return mixed */ public function searchGoodsTerm($param) { $GoodsClass = new GoodsClassify(); $where = $GoodsClass->getGoodsClassId($param, [], "goods_class_id"); //分类条件 if (!empty($param['search_info']) && $param['type'] != 2) { $where['goods_name|sku_name|goods_code|sku_code|goods_number|sku_goods_number'] = ['like', '%' . $param['search_info'] . '%']; } if (isset($param['status']) && in_array($param['status'], ['0', '1', '2'])) { $where['status'] = $param['status']; } else { $where['status'] = array('in', '0,1'); } if (!empty($param['exists_id_arr'])) { $where['id'] = ['not in', $param['exists_id_arr']]; //排除已经存在的id } //调拨目标门店的行业id if (!empty($param['industry_id']) && empty($where['goods_class_id'])) { $classResult = $GoodsClass->basisIndustryGetClass([ 'industry_id' => $param['industry_id'], 'merchant_id' => $param['merchant_id'] ]); if (!empty($classResult['data'])) { $where['goods_class_id'] = ['in', $classResult['data']]; } } if ($param['user_type'] == 4) { //门店 $where['store_id'] = $param['store_id']; } $where['merchant_id'] = $param['merchant_id']; return $where; } }