getSelect($where, $page, $limit, $field, $order); if ($goodsList) { $StoreModel = new RetailStoreModel(); $sMap = [ 'merchantid' => self::$merchant_id, 'id' => ['neq', self::$store_id], 'state' => 0, 'store_status' => 0, ]; $store_ids = $StoreModel->getFindField($sMap, 'id', true); if (self::$merchant['platform_type'] == 2) { //第三方平台 $code_arr = []; } $SkuGoodsModel = new RetailSkuGoodsModel(); $GoodsModel = new RetailGoodsModel(); foreach ($goodsList as &$val) { if (!empty($val['sku_id'])) { $val['retail_price'] = $SkuGoodsModel->getFindField(['id' => $val['sku_id']], 'retail_price'); } else { $val['retail_price'] = $GoodsModel->getFindField(['id' => $val['goods_id']], 'retail_price'); } if (self::$merchant['platform_type'] == 2) { $code_arr[$val['id']] = $val['third_goods_code']; } $val['goods_num'] = round($val['goods_num'], 3); if ($val['attribute_state'] == 2) { $val['goods_number'] = $val['sku_goods_number']; $val['goods_code'] = $val['sku_code']; $val['specifications'] = $val['sku_name']; } switch ($val['status']) { case 0: $val['status_name'] = "上架"; break; case 1: $val['status_name'] = "下架"; break; } if (self::$cashier['other_store_goods'] == 1 && !empty($store_ids) && self::$merchant['platform_type'] == 1) { //有权限查看其他门店库存 $gMap = [ 'id' => ['neq', $val['id']], 'merchant_id' => self::$merchant_id, 'store_id' => ['in', $store_ids], 'status' => 0, ]; if ($val['attribute_state'] == 1) { //货号判断 $gMap['goods_number'] = $val['goods_number']; //条码判断 $gMap[] = [ ['goods_code' => $val['goods_code']], ['goods_code' => ''], ['goods_code' => ['EXP', 'IS NULL']], '_logic' => 'OR', ]; } else { //货号判断 $gMap['sku_goods_number'] = $val['sku_goods_number']; //条码判断 $gMap[] = [ ['sku_code' => $val['sku_code']], ['sku_code' => ''], ['sku_code' => ['EXP', 'IS NULL']], '_logic' => 'OR', ]; } $val['other_store_goods_num'] = $SSaleMGoodsModel->getSum($gMap, 'goods_num'); $val['other_store_goods_num'] = round($val['other_store_goods_num'], 3); } else { $val['other_store_goods_num'] = 0; } } if (self::$merchant['platform_type'] == 2 && !empty($code_arr)) { $ThirdGoodsClass = new Goods(); $thirdResult = $ThirdGoodsClass->goodsNumQuery([ 'merchant_id' => self::$merchant_id, 'type' => 2, 'code_arr' => $code_arr, 'Customer_Codes' => self::$store['third_code'] ]); $goods_stock = $thirdResult['data']; foreach ($goodsList as &$val) { $val['goods_num'] = $goods_stock[$val['id']] ? $goods_stock[$val['id']] : 0; } } } $result = [ 'status' => 1, 'msg' => $goodsList ? '获取成功' : '暂无数据', 'count' => $SSaleMGoodsModel->getCount($where), 'data' => $goodsList ? $goodsList : [], ]; $this->ajaxReturn($result); } /** * 获取商品分类列表 * @param pid 上级分类id */ public function getGoodsClass() { $ClassApi = new GoodsClassify(); $param = [ 'pid' => I('post.pid'), 'merchant_id' => self::$merchant_id, ]; $data = $ClassApi->getAbsolutelyGoodsClass($param); $this->ajaxReturn([ 'status' => 1, 'msg' => $data ? '获取成功' : '暂无分类', 'data' => $data ? $data : [], ]); } /** * 获取其他门店的商品库存详情 */ public function otherStoreGoodsDetails() { if (self::$cashier['other_store_goods'] != 1) { $this->ajaxReturn(callBack(statusCode()['error'], '您无权查看其他门店商品库存')); } $id = I('post.id'); if (empty($id)) { $this->ajaxReturn(callBack(statusCode()['error'], '缺少参数')); } $order_type = I('post.order_type');//排序方式 1库存降序 2距离升序 //判断商品是否存在 $SSaleMGoodsModel = new SSaleMGoodsModel(); $gMap = [ 'id' => $id, 'status' => ['in', '0,1'], 'merchant_id' => self::$merchant_id, 'store_id' => self::$store_id, ]; $goods = $SSaleMGoodsModel->getFind($gMap, 'attribute_state,goods_number,goods_code,sku_goods_number,sku_code'); if (empty($goods)) { $this->ajaxReturn(callBack(statusCode()['error'], '商品不存在')); } //获取门店ID列表 $map = [ 'id' => ['neq', $id], 'status' => 0, 'merchant_id' => self::$merchant_id, 'goods_num' => ['gt', 0], ]; //非规格商品 if ($goods['attribute_state'] == 1) { //货号判断 $map['goods_number'] = $goods['goods_number']; //条码判断 $map[] = [ ['goods_code' => $goods['goods_code']], ['goods_code' => ''], ['goods_code' => ['EXP', 'IS NULL']], '_logic' => 'OR', ]; } else { //货号判断 $map['sku_goods_number'] = $goods['sku_goods_number']; //条码判断 $map[] = [ ['sku_code' => $goods['sku_code']], ['sku_code' => ''], ['sku_code' => ['EXP', 'IS NULL']], '_logic' => 'OR', ]; } $store_ids = $SSaleMGoodsModel->getFindField($map, 'store_id', true); if (empty($store_ids)) { $this->ajaxReturn(callBack(statusCode()['error'], '暂无门店存在该商品')); } //查询门店及对应库存 $StoreModel = new RetailStoreModel(); $sMap = [ 'merchantid' => self::$merchant_id, 'id' => ['in', $store_ids], 'state' => 0, 'store_status' => 0, ]; $fields = [ 'id', 'storetag as store_name', 'province', 'city', 'area', 'address', 'latitude', 'longitude', ]; $storeList = $StoreModel->getSelect($sMap, $fields); if (empty($storeList)) { $this->ajaxReturn(callBack(statusCode()['error'], '暂无门店存在该商品')); } if (self::$store['longitude'] === null || self::$store['longitude'] === '') self::$store['longitude'] = 0; if (self::$store['latitude'] === null || self::$store['latitude'] === '') self::$store['latitude'] = 0; $ManagerModel = new RetailManagerModel(); foreach ($storeList as &$val) { if ($val['longitude'] === null || $val['longitude'] === '') $val['longitude'] = self::$store['longitude']; if ($val['latitude'] === null || $val['latitude'] === '') $val['latitude'] = self::$store['longitude']; $val['distance'] = get_distance(self::$store['longitude'], self::$store['latitude'], $val['longitude'], $val['latitude']); //距离 $map['store_id'] = $val['id']; $val['address'] = $val['province'] . $val['city'] . $val['area'] . $val['address']; unset($val['province']); unset($val['city']); unset($val['area']); unset($val['longitude']); unset($val['latitude']); $val['other_store_goods_num'] = $SSaleMGoodsModel->getSum($map, 'goods_num'); $val['other_store_goods_num'] = round($val['other_store_goods_num'], 3); $mMap = [ 'storeid' => $val['id'], 'status' => 1, ]; $val['managers'] = $ManagerModel->getSelect($mMap, 'name,mobile'); $val['managers'] = $val['managers'] ? $val['managers'] : []; } if (count($storeList) > 1) { if ($order_type == 2) { $storeList = array_sequence($storeList, 'distance'); } else { $storeList = array_sequence($storeList, 'other_store_goods_num', 'SORT_DESC'); } } $this->ajaxReturn(callBack(statusCode()['success'], '获取成功', $storeList)); } }