onlineEnterpriseId = $onlineEnterpriseId;
$this->onlineUserId = $onlineUserId;
$this->objRoleAclCache = new RoleAclCache();
}
/**
* 营销活动(领取优惠券)
* @param $data
* @param $className
*/
protected static function coupon($data, $className)
{
$i = 1;
do {
$postData = [
'topicName' => 'MyJob',
'topicClass' => "Jobs\Model\MTopic\Market\\".$className,
'topicMethon' => 'push',
'topicMethonParams' => [
'userCenterId' => $data['userCenterId'],
'enterpriseId' => $data['enterpriseId'],
'customerId' => $data['customerId'],
'payAmount' => isset($data['payAmount']) ? $data['payAmount'] : 0,
],
];
$url = QIANNIAO_QUEUE . '/CAddJob/add';
$result = request($url, $postData);
$i++;
} while ($result['httpcode'] != 200 && $i <= 3);
}
/**
* 登录注册日志
* @param $data
*/
public static function saveLoginLog($data)
{
$i = 1;
do {
$postData = [
'topicName' => 'MyJob',
'topicClass' => 'Jobs\Model\MTopic\Log\MLoginLog',
'topicMethon' => 'push',
'topicMethonParams' => [
'userCenterId' => $data['userCenterId'],
'enterpriseId' => $data['enterpriseId'],
'mobile' => $data['mobile'],
'createTime' => $data['createTime'],//操作时间
'source' => $data['source'], // 来源:
'actionType' => $data['actionType'], // 操作类型:登录/注册
'operationData' => $data['operationData'], //本次操作请求的数据(可空) json格式
],
];
$url = QIANNIAO_QUEUE . '/CAddJob/add';
$result = request($url, $postData);
$i++;
} while ($result['httpcode'] != 200 && $i <= 3);
}
/**
* 除登录注册之外的日志记录
*/
public static function saveLog($data)
{
$i = 1;
do {
$postData = [
'topicName' => 'MyJob',
'topicClass' => 'Jobs\Model\MTopic\Log\MLog',
'topicMethon' => 'push',
'topicMethonParams' => [
'userCenterId' => $data['userCenterId'],
'enterpriseId' => $data['enterpriseId'],
'createTime' => $data['createTime'],//操作时间
'no' => $data['no'], // 如:单据编号D563875634856 订单编号N42332435435
'actionType' => $data['actionType'], // 操作类型:下单 支付 取消订单
'operationData' => $data['operationData'], //本次操作请求的数据(可空) json格式
],
];
$url = QIANNIAO_QUEUE . '/CAddJob/add';
$result = request($url, $postData);
$i++;
} while ($result['httpcode'] != 200 && $i <= 3);
}
/**
* 格式化skuId
* @param $enterpriseId
* @param $value
* @return mixed
* @throws \Exception
*/
public function formatSkuId($enterpriseId, $value)
{
if(empty($enterpriseId) || empty($value)) return $value;
$objMSku = new MSku(false, $enterpriseId);
if (isset($value['skuId']) && !empty($value['skuId']) && !isset($value['unitName']) && !isset($value['skuName'])){
$modelResult = $objMSku->getSkuDataBySkuIds($value['skuId']);
$value['unitId'] = 0;
$value['unitName'] = '';
$value['skuName'] = '';
$value['barCode'] = '';
if($modelResult->isSuccess()){
$skuData = $modelResult->getData();
$value['skuName'] = $skuData[$value['skuId']]['skuName'];
$value['unitId'] = $skuData[$value['skuId']]['unitId'];
$value['unitName'] = $skuData[$value['skuId']]['unitName'];
$value['isMaster'] = $skuData[$value['skuId']]['isMaster'];
$value['barCode'] = $skuData[$value['skuId']]['barCode'];
}
}
return $value;
}
/**
* 究极无敌格式化订单数据方法
* @param $enterpriseId
* @param $array
* @param bool $orderType
* @param bool $isFormatNo
* @return array
* @throws \Exception
*/
static function formatOrderMan($enterpriseId, $array, $orderType = false, $isFormatNo = true)
{
if (empty($array)) return $array;
$objGoodsBasicRelevantCache = new GoodsBasicRelevant($enterpriseId);
$objMPrintNum = new MPrintNum($enterpriseId);
$objMCommon = new MCommon();
$objMGoodsBasic = new MGoodsBasic(false, $enterpriseId);
$objMSku = new MSku(false, $enterpriseId);
$objMWarehouse = new MWarehouse($enterpriseId);
$objMMerchant = new MMerchant($enterpriseId);
$formatData = isset($array['id']) ? [$array] : $array;
foreach ($formatData as &$value) {
// if (isset($value['no']) && !empty($value['no'])){
// $value['no'] = StatusCode::$noPrefix[13].'-'.$value['no'];
// }
if (isset($value['deliveryType']) && !empty($value['deliveryType'])) $value['deliveryName'] = isset(StatusCode::$deliveryType[$value['deliveryType']]) ? StatusCode::$deliveryType[$value['deliveryType']] : '';
if ($orderType) $value['type'] = $orderType;
if (isset($value['type']) && !empty($value['type'])) $value['no'] = StatusCode::$noPrefix[$value['type']] .'-'. $value['no'];
if (isset($value['type']) && !empty($value['type'])) $value['typeName'] = $objMCommon->formatOrderSource($value['type']);
if (isset($value['source']) && !empty($value['source'])) $value['sourceName'] = $objMCommon->formatOrderSource($value['source']);
if (isset($value['source']) && !empty($value['source']) && $isFormatNo){
$value['sourceNo'] = StatusCode::$noPrefix[$value['source']].'-' . $value['sourceNo'];
isset($value['originNo']) && $value['originNo'] = StatusCode::$noPrefix[$value['source']].'-' . $value['originNo'];
}
if(isset($value['skuId']) && !empty($value['skuId'])){
$modelResult = $objMSku->getSkuDataBySkuIds($value['skuId']);
if($modelResult->isSuccess()){
$skuData = $modelResult->getData();
if(!isset($value['unitId']) || empty($value['unitId'])){
$value['unitId'] = isset($skuData[$value['skuId']]['unitId'])?$skuData[$value['skuId']]['unitId']:'';
}
if(!isset($value['unitName']) || empty($value['unitName'])){
$value['unitName'] = isset($skuData[$value['skuId']]['unitName'])?$skuData[$value['skuId']]['unitName']:'';
}
if(!isset($value['skuName']) || empty($value['skuName'])){
$value['skuName'] = isset($skuData[$value['skuId']]['skuName'])?$skuData[$value['skuId']]['skuName']:'';
}
if(!isset($value['isMaster']) || empty($value['isMaster'])){
$value['isMaster'] = isset($skuData[$value['skuId']]['isMaster'])?$skuData[$value['skuId']]['isMaster']:'';
}
if(!isset($value['skuBarCode']) || empty($value['skuBarCode'])){
$value['skuBarCode'] = isset($skuData[$value['skuId']]['barCode'])?$skuData[$value['skuId']]['barCode']:'';
}
}else{
$value['unitId'] = 0;
$value['unitName'] = '';
$value['skuName'] = '';
$value['skuBarCode'] = '';
}
}
if (isset($value['categoryId']) && !empty($value['categoryId']) && !isset($value['categoryName'])) {
$value['categoryName'] = $objGoodsBasicRelevantCache->getNameByCategoryId($value['categoryId']);
} else {
if (isset($value['materielId']) && !isset($value['categoryName'])) {
$value['categoryName'] = $objGoodsBasicRelevantCache->getNameByBasicId($value['materielId'], 'categoryName');
}
}
//基础资料信息
if ((isset($value['goodsBasicId']) && !empty($value['goodsBasicId'])) || (isset($value['basicGoodsId']) && !empty($value['basicGoodsId']))){
$goodsBasicId = isset($value['goodsBasicId']) ? $value['goodsBasicId'] : $value['basicGoodsId'];
$modelResult = $objMGoodsBasic->getBasicGoodsFieldByIds([$goodsBasicId]);
$basicData = [];
if($modelResult->isSuccess()){
$basicData = $modelResult->getData();
$basicData = $basicData[$goodsBasicId];
}
if (isset($basicData['categoryId']) && !isset($value['categoryName'])){
unset($categoryName);
$categoryName = $objGoodsBasicRelevantCache->getNameByCategoryId($basicData['categoryId']);
if($categoryName){
$value['categoryName'] = $categoryName;
}
}
if(!isset($value['images']) || empty($value['images'])){
$value['images'] = isset($basicData['images']) ? $basicData['images'] : null;
}
if (!isset($value['storage'])){
$value['storage'] = '';
if(isset($basicData['extends']) && isset($basicData['extends']['storage'])){
$value['storage'] = $basicData['extends']['storage'];
}
}
if (!isset($value['goodsBasicName']) && isset($basicData['title'])){
$value['goodsBasicName'] = $basicData['title'];
}
if (!isset($value['isEq'])){
$value['isEq'] = !empty($basicData['isEq']) ? $basicData['isEq'] : 4;
}
}
//基础资料信息
if (isset($value['materielId'])){
$modelResult = $objMGoodsBasic->getBasicGoodsFieldByIds([$value['materielId']]);
$basicData = [];
if($modelResult->isSuccess()){
$basicData = $modelResult->getData();
$basicData = $basicData[$value['materielId']];
}
if($basicData){
if(!isset($value['images']) || empty($value['images'])){
$value['images'] = isset($basicData['images']) ? $basicData['images'] : null;
}
if (!isset($value['materielName'])){
$value['materielName'] = $basicData['title'];
}
if (!isset($value['storage'])){
$value['storage'] = '';
if(isset($basicData['extends']) && isset($basicData['extends']['storage'])){
$value['storage'] = $basicData['extends']['storage'];
}
}
if (!isset($value['isEq'])){
$value['isEq'] = !empty($basicData['isEq']) ? $basicData['isEq'] : 4;
}
}else{
$value['images'] = null;
$value['materielName'] = '';
$value['storage'] = '';
$value['isEq'] = 4;
}
}
if((isset($value['extends']) && !empty($value['extends'])) || (isset($value['extend']) && !empty($value['extend']))){
if(isset($value['extend'])){
$extends = is_array($value['extend'])?$value['extend']:json_decode($value['extend'], true);
}else if(isset($value['extends'])){
$extends = is_array($value['extend'])?$value['extend']:json_decode($value['extends'], true);
}else{
$extends = [];
}
if(!empty($extends)){
foreach($extends as $keys => $item){
$value[$keys] = $item;
}
}
}
if( isset($value['batch']) && !empty($value['batch']) ){
if(is_string($value['batch'] )){
$value['batch'] = json_decode($value['batch'], true);
}
}
if (isset($value['brandId']) && !empty($value['brandId']) && !isset($value['brandName'])) $value['brandName'] = $objGoodsBasicRelevantCache->getNameByBrandId($value['brandId']);
if (isset($value['warehouseId']) && !empty($value['warehouseId']) && (!isset($value['warehouseName']) || empty($value['warehouseName']))) $value['warehouseName'] = $objMWarehouse->getWarehouseName($value['warehouseId']);
if (isset($value['inWarehouseId']) && !empty($value['inWarehouseId']) && (!isset($value['inWarehouseName']) || empty($value['warehouseName']))) $value['inWarehouseName'] = $objMWarehouse->getWarehouseName($value['inWarehouseId']);
if (isset($value['shopId']) && !empty($value['shopId']) && !isset($value['shopName'])) $value['shopName'] = $objGoodsBasicRelevantCache->getNameByShopId($value['shopId']);
if (isset($value['details']) && !empty($value['details'])) $value['details'] = self::formatOrderMan($enterpriseId, $value['details']);
if (isset($value['no'])) $value['printNum'] = $objMPrintNum->getObjectPrintNum($value['no']);
if(isset($value['merchantId']) && (!isset($value['merchantName']) || empty($value['merchantName']))){
$merchant = $objMMerchant->getMerchant($value['merchantId']);
$value['merchantName'] = isset($merchant['name']) ? $merchant['name'] : '';
}
}
unset($value);
$returnData = isset($array['id']) ? array_shift($formatData) : $formatData;
return $returnData;
}
/**
* 格式化打印机数据
* @param $params
* @param $type 1:佳博打印机 2:飞鹅打印机
* @return string
*/
public function formatMsg($params, $type = 1)
{
$msgDetail = '';
switch ($type){
case 1:
$details = $params['details'];
$msgDetail .= ''.$params['shopName'].'';//商铺名称
$msgDetail .= ''.$params['title'].'';//标题
// $msgDetail .= ''.$params['code'].'';//单号
$msgDetail .= ''.$params['codeName'].':'.$params['code'].'';//单号详情
$msgDetail .= '订单日期:'.date('Y-m-d H:i:s', $params['createTime']).'';//订单日期
$msgDetail .= '顾客姓名:'.$params['userName'].'';//买家姓名
$msgDetail .= '顾客电话:'.$params['mobile'].'';//买家手机号
$msgDetail .= '收货地址:'.$params['address'].'';//买家手机号
// $msgDetail .= '买家留言:发顺丰,尽快发货,谢谢';//买家留言
// $msgDetail .= '卖家备注:发顺丰,优先处理';//卖家备注
// $msgDetail .= '买就送信息:送U盘';//活动信息 活动说明
$msgDetail .= '--------------------------------';
$msgDetail .= '商品 | 单价 | 数量 | 金额 | ';//商品名称 商品单价 商品数量 商品总价
//循环商品信息
foreach($details as $value) {
if(count($value['skuData']) > 1){
$msgDetail .= ''.$value['title'].' | | | | ';
foreach($value['skuData'] as $vv){
$msgDetail .= ' '.$vv['skuName'].' | '.$vv['unitPrice'].' | '.$vv['num'].$vv['unitName'].' | '.$vv['amountPrice'].' | ';
}
}else{
foreach($value['skuData'] as $vv){
$msgDetail .= ''.$value['title'].' '.$vv['skuName'].' | '.$vv['unitPrice'].' | '.$vv['num'].$vv['unitName'].' | '.$vv['amountPrice'].' | ';
}
}
}
$msgDetail .= '-------------------------------- ';
$msgDetail .= '优惠: | -'.$params['preferential'].'元 | ';//优惠金额
$msgDetail .= '合计: | '.$params['totalMoney'].'元 | ';//合计金额
$msgDetail .= '应收: | '.$params['payAmount'].'元 | ';//应收金额
$msgDetail .= '';
// $msgDetail .= '扫码关注千鸟云商';//二维码说明
// $msgDetail .= 'http://onlineimg.qianniao.vip/b8ca10e4ce35fded735c980403dfedf7/gh_16db94f79967_430.jpg';//二维码地址
$msgDetail .= '';
break;
case 2:
$details = $params['details'];
$msgDetail .= ''.$params['shopName'].'
';
$msgDetail .= ''.$params['title'].'
';
$msgDetail .= $params['codeName'].':'.$params['code'].'
';
$msgDetail .= '订单日期:'.date('Y-m-d H:i:s', $params['createTime']).'
';
$msgDetail .= '顾客姓名:'.$params['userName'].'
';
$msgDetail .= '顾客电话:'.$params['mobile'].'
';
$msgDetail .= '收货地址:'.$params['address'].'
';
$msgDetail .= '--------------------------------
';
$msgDetail .= '商品 单价 数量 金额
';
foreach($details as $value) {
if (count($value['skuData']) > 1) {
$msgDetail .= $value['title'].'
';
$msgDetail .= self::formatText($value['skuData']);
}else{
$msgDetail .= self::formatText($value['skuData'], $value['title']);
}
}
$msgDetail .= '--------------------------------
';
$msgDetail .= '优惠:-'.$params['preferential'].'元
';
$msgDetail .= '合计:'.$params['totalMoney'].'元
';
$msgDetail .= '应收:'.$params['payAmount'].'元
';
$msgDetail .= '';
break;
}
return $msgDetail;
}
/**
* 格式化飞鹅打印内容
* @param $params
* @param bool $title
* @param int $A
* @param int $B
* @param int $C
* @param int $D
* @return string
*/
public function formatText($params, $title = false, $A = 13,$B = 6,$C = 4,$D = 6)
{
$orderInfo = '';
foreach ($params as $k5 => $v5) {
$name = $title ? $title.' '.$v5['skuName'] : ' '.$v5['skuName'];
$price = $v5['unitPrice'];
$num = $v5['num'].$v5['unitName'];
$prices = $v5['amountPrice'];
$kw3 = '';
$kw1 = '';
$kw2 = '';
$kw4 = '';
$str = $name;
$blankNum = $A;//名称控制为14个字节
$lan = mb_strlen($str,'utf-8');
$m = 0;
$j=1;
$blankNum++;
$result = array();
if(strlen($price) < $B){
$k1 = $B - strlen($price);
for($q=0;$q<$k1;$q++){
$kw1 .= ' ';
}
$price = $price.$kw1;
}
if(strlen($num) < $C){
$k2 = $C - strlen($num);
for($q=0;$q<$k2;$q++){
$kw2 .= ' ';
}
$num = $num.$kw2;
}
if(strlen($prices) < $D){
$k3 = $D - strlen($prices);
for($q=0;$q<$k3;$q++){
$kw4 .= ' ';
}
$prices = $prices.$kw4;
}
for ($i=0;$i<$lan;$i++){
$new = mb_substr($str,$m,$j,'utf-8');
$j++;
if(mb_strwidth($new,'utf-8')<$blankNum) {
if($m+$j>$lan) {
$m = $m+$j;
$tail = $new;
$lenght = mb_convert_encoding($new,'GBK','UTF-8');
$k = $A - strlen($lenght);
for($q=0;$q<$k;$q++){
$kw3 .= ' ';
}
if($m==$j){
$tail .= $kw3.' '.$price.' '.$num.' '.$prices;
}else{
$tail .= $kw3.'
';
}
break;
}else{
$next_new = mb_substr($str,$m,$j,'utf-8');
if(mb_strwidth($next_new,'utf-8')<$blankNum)
continue;
else{
$m = $i+1;
$result[] = $new;
$j=1;
}
}
}
}
$head = '';
foreach ($result as $key=>$value) {
if($key < 1){
$v_lenght = mb_convert_encoding($value, 'GBK', 'UTF-8');
$v_lenght = strlen($v_lenght);
if($v_lenght == 13) $value = $value." ";
$head .= $value.' '.$price.' '.$num.' '.$prices;
}else{
$head .= $value.'
';
}
}
$orderInfo .= $head.$tail;
}
return $orderInfo;
}
/**
* 拼接esId
* @param $enterpriseId //企业id
* @param $id //自增id
* @param $title //表名
* @return string
*/
public function setEsId($enterpriseId, $title, $id)
{
return 'EnterpriseId_' . $enterpriseId . '_'.$title.'_' . $id;
}
/**
* 判断es返回值
* @param $result
* @return ResultWrapper
*/
public function isResult($result)
{
if(empty($result)){
return ResultWrapper::success($result);
}
if (isset($result['_shards']) && isset($result['_shards']['successful']) && $result['_shards']['successful'] == 1) {
return ResultWrapper::success(isset($result['_id']) ? $result['_id'] : false);
}
// return ResultWrapper::fail($result['error']['reason'], ErrorCode::$paramError);
return ResultWrapper::fail('ES添加失败', ErrorCode::$paramError);
}
/**
* @param $enterpriseId
* @param $params
* @return array
*/
protected static function formatBasic($enterpriseId, $params)
{
if (empty($params)) return [];
}
/**
* 映射 分类名称,基础商品名称,品牌名称,规格名称
* @param $enterpriseId
* @param $params ['skuId'=>[1,2,..],'categoryId'=>[1,2,..],'brandId'=>[1,2,..],'goodsBasicId'=>[1,2,...]]
* @return array
*/
protected static function formatMapping($enterpriseId, $params)
{
if (empty($params)) return [];
$mapping = [];
if (isset($params['skuId']) && !empty($params['skuId'])) $mapping['skuData'] = self::getSkuNameByIds($enterpriseId, $params['skuId']);
if (isset($params['categoryId']) && !empty($params['categoryId'])) $mapping['categoryData'] = self::getCategoryNameByIds($enterpriseId, $params['categoryId']);
if (isset($params['brandId']) && !empty($params['brandId'])) $mapping['brandData'] = self::getBrandNameByIds($enterpriseId, $params['brandId']);
if (isset($params['goodsBasicId']) && !empty($params['goodsBasicId'])) $mapping['basicData'] = self::getBasicNameByIds($enterpriseId, $params['goodsBasicId']);
return $mapping;
}
/**
* 获取skuName
* @param $enterpriseId
* @param $params
* @return array
*/
protected static function getSkuNameByIds($enterpriseId, $params)
{
if (empty($params)) return [];
$objGoodsBasicRelevantCache = new GoodsBasicRelevant($enterpriseId);
$allSkuData = [];
foreach ($params as $skuId) {
$name = $objGoodsBasicRelevantCache->getNameBySkuId($skuId);
$allSkuData[$skuId] = $name;
}
return $allSkuData;
}
/**
* 格式化查询语句
* @param array $where
* @param string $whereSql
* @return string
*/
public function formatSqlWhere($where = [], $whereSql = '')
{
foreach($where as $key => $value){
if(empty($value)){
continue;
}
switch ($key){
case 'createTime':
if(is_array($value)){
$end = $value['end'];
if(isset($value['star'])){
$start = $value['star'];
}else{
$start = $value['start'];
}
$whereSql .= (!empty($whereSql) ? ' and ' : '').'('.$key.' between '.$start.' and '.$end.')';
}else{
$whereSql .= (!empty($whereSql) ? ' and ' : '').$key.' = '.$value;
}
break;
case 'search':
if(is_array($value)){
$likeSql = '';
foreach($value as $k => $v){
$likeSql .= (!empty($likeSql) ? ' or ': '').$k.' like "%'.$v.'%"';
}
$whereSql .= (!empty($whereSql) ? ' and ' : '').'('.$likeSql.')';
}else{
$whereSql .= (!empty($whereSql) ? ' and ' : '').$value;
}
break;
case 'neq':
if(isset($value[0]) && isset($value[1])){
$whereSql .= (!empty($whereSql) ? ' and ' : '').$value[0].' <> '.$value[1];
}
break;
default:
if(is_array($value)){
$whereSql .= (!empty($whereSql) ? ' and ' : '').$key.' in ('.implode(",", $value).')';
}else{
$whereSql .= (!empty($whereSql) ? ' and ' : '').$key.' = '.$value;
}
break;
}
}
return $whereSql;
}
/**
* categoryName
* @param $enterpriseId
* @param $params
* @return array
*/
protected static function getCategoryNameByIds($enterpriseId, $params)
{
if (empty($params)) return [];
$objGoodsBasicRelevantCache = new GoodsBasicRelevant($enterpriseId);
$allCategoryData = [];
foreach ($params as $categoryId) {
$name = $objGoodsBasicRelevantCache->getNameByCategoryId($categoryId);
$allCategoryData[$categoryId] = $name;
}
return $allCategoryData;
}
/**
* brandName
* @param $enterpriseId
* @param $params
* @return array
*/
protected static function getBrandNameByIds($enterpriseId, $params)
{
if (empty($params)) return [];
$objGoodsBasicRelevantCache = new GoodsBasicRelevant($enterpriseId);
$allBrandData = [];
foreach ($params as $brandId) {
$name = $objGoodsBasicRelevantCache->getNameByBrandId($brandId);
$allBrandData[$brandId] = isset($name) ? $name : '';
}
return $allBrandData;
}
/**
* BasicName
* @param $enterpriseId
* @param $params
* @return array
*/
protected static function getBasicNameByIds($enterpriseId, $params)
{
if (empty($params)) return [];
$objGoodsBasicRelevantCache = new GoodsBasicRelevant($enterpriseId);
$allBasicData = [];
foreach ($params as $basicId) {
$name = $objGoodsBasicRelevantCache->getNameByBasicId($basicId);
$allBasicData[$basicId] = isset($name) ? $name : '';
}
return $allBasicData;
}
/**
* 数据域查询条件 业务员ID 数据库存的是staff的id用这个
* @param mixed $selectParams
* @param string $fieldsNameOfStaffId
* @return mixed|null
*/
public function getSalesManQueryParams($selectParams = null, $fieldsNameOfStaffId = 'salesManId')
{
// 限制查看的业务员ids
// self::getAccessSalesManIds();
if (empty(self::$salesManIds)) {
return $selectParams;
}
if (is_array($selectParams)) {
$selectParams[$fieldsNameOfStaffId] = self::$salesManIds;
return $selectParams;
}
$condition = '';
if (!empty($selectParams)) {
$condition .= ' AND ';
}
$selectParams .= $condition;
$selectParams .= $fieldsNameOfStaffId;
!empty(self::$salesManIds) ? self::$salesManIds : '';
$selectParams .= is_array(self::$salesManIds) ? ' in (' . implode(',', self::$salesManIds) . ')' : '=' . self::$salesManIds;
return $selectParams;
}
/**
* 数据域查询条件 商铺ID
* @param null $selectParams
* @param string $fieldsNameOfShopId
* @return array|string|null
*/
public function getShopIdQueryParams($selectParams = null, $fieldsNameOfShopId = 'shopId')
{
self::getAccessShopIds();
if (empty(self::$shopIds)) {
return $selectParams;
}
if (is_array($selectParams)) {
$selectParams[$fieldsNameOfShopId] = self::$shopIds;
return $selectParams;
}
$condition = '';
if (!empty($selectParams)) {
$condition .= ' AND ';
}
$selectParams .= $condition;
$selectParams .= $fieldsNameOfShopId;
$selectParams .= ' in (' . implode(',', self::$shopIds) . ')';
return $selectParams;
}
/**
* 数据域查询条件
* @param null $selectParams
* @param string $field
* @return array|string|null
*/
public function getWarehouseIdQueryParams($selectParams = null, $field = 'warehouseId')
{
self::getAccessWarehouseIds($field);
if(!empty(self::$warehouseIds)){
$fieldData = self::$warehouseIds;
}else{
$fieldData = self::$shopIds;
}
if(empty($fieldData)){
return $selectParams;
}
if (is_array($selectParams)) {
$selectParams[$field] = $fieldData;
return $selectParams;
}
$condition = '';
if (!empty($selectParams)) {
$condition .= ' AND ';
}
$selectParams .= $condition;
$selectParams .= $field;
$selectParams .= ' in (' . implode(',', $fieldData) . ')';
return $selectParams;
}
/**
* 数据域查询条件 数据库存的是staff的uid用这个
* @param null $selectParams
* @param string $field
* @return array|string|null
*/
public function getStaffQueryParams($selectParams = null, $field = 'salesManId')
{
self::getAccessStaffUserCenterIds();
if (empty(self::$staffUserCenterIds)) {
return $selectParams;
}
if (is_array($selectParams)) {
$selectParams[$field] = self::$staffUserCenterIds;
return $selectParams;
}
$condition = '';
if (!empty($selectParams)) {
$condition .= ' AND ';
}
$selectParams .= $condition;
$selectParams .= $field;
$selectParams .= ' in (' . implode(',', self::$staffUserCenterIds) . ')';
return $selectParams;
}
//限制查看的业务员ids
public function getAccessSalesManIds()
{
// 查询当前登录用户的数据域
if (empty(self::$dataField)) {
self::getDataFieldOfOnlineUser();
}
$dataField = self::$dataField;
if (!isset($dataField['dataField'])) {
self::$salesManIds = [];
return;
}
//设置了数据域
switch ($dataField['dataField']) {
case StatusCode::$dataFieldType['person'] : // 个人
$staffId = $this->objRoleAclCache->getStaffIdAndUserCenterId($this->onlineEnterpriseId, $this->onlineUserId);
self::$salesManIds = (!empty($staffId)) ? [$staffId] : [];
break;
case StatusCode::$dataFieldType['staff']: // 员工
self::$salesManIds = isset($dataField['staffIds']) ? $dataField['staffIds'] : [];
break;
case StatusCode::$dataFieldType['all']: // 所有
self::$salesManIds = [];
break;
default:
self::$salesManIds = [];
}
}
//限制查看的商铺ids
public function getAccessShopIds()
{
if (empty(self::$dataField)) {
self::getDataFieldOfOnlineUser();
}
$dataField = self::$dataField;
if (!isset($dataField['shopIds'])) {
self::$shopIds = [];
return;
}
self::$shopIds = $dataField['shopIds'];
}
//限制查看的仓库ids
public function getAccessWarehouseIds($field = '')
{
if (empty(self::$dataField)) {
self::getDataFieldOfOnlineUser();
}
if (empty(self::$shopIds)) {
self::getAccessShopIds();
}
if (empty(self::$shopIds)) {
self::$warehouseIds = [];
return self::$warehouseIds;
}
if(!empty($field) && $field == 'shopId'){
return self::$shopIds;
}
//查出商铺下的仓库ids
foreach (self::$shopIds as $shopId) {
$warehouseId = $this->objRoleAclCache->getShopIdAndWarehouseId($this->onlineEnterpriseId, $shopId);
if ($warehouseId) {
self::$warehouseIds[] = $warehouseId;
}
}
return self::$warehouseIds;
}
//限制查看的业务员对应的userCenterIds
public function getAccessStaffUserCenterIds()
{
if (empty(self::$dataField)) {
self::getDataFieldOfOnlineUser();
}
if (empty(self::$salesManIds)) {
self::getAccessSalesManIds();
}
if (empty(self::$salesManIds)) {
self::$staffUserCenterIds = [];
return self::$staffUserCenterIds;
}
if (is_array(self::$salesManIds)) {
//查出员工id对应的uid
foreach (self::$salesManIds as $staffId) {
$uid = $this->objRoleAclCache->getUserCenterIdAndStaffId($this->onlineEnterpriseId, $staffId);
if ($uid) {
self::$staffUserCenterIds[] = $uid;
}
}
} else {
$userCenterId = $this->objRoleAclCache->getUserCenterIdAndStaffId($this->onlineEnterpriseId, self::$salesManIds);
if ($userCenterId) {
self::$staffUserCenterIds[] = $userCenterId;
}
}
return self::$staffUserCenterIds;
}
//获取当前登录客户的数据域
private function getDataFieldOfOnlineUser()
{
$dataField = $this->objRoleAclCache->getStaffUidAndDataField($this->onlineEnterpriseId, $this->onlineUserId);
self::$dataField = $dataField;
}
/**
* 格式化es搜索查询数据
* @param $data
* @param bool $enterpriseId
* @param bool $orderType
* @return mixed
* @throws \Exception
*/
static function formatEsSelectData($data, $enterpriseId = false, $orderType = false)
{
if (empty($data)) return $data['data'] = [];
$returnData['data'] = [];
$returnData['total'] = $data['hits']['total'];
foreach ($data['hits']['hits'] as $value) {
$returnData['data'][] = $value['_source'];
}
$enterpriseId && $returnData['data'] = self::formatOrderMan($enterpriseId, $returnData['data'], $orderType, false);
return $returnData;
}
/**
* Doc: (des="websocket推送消息")
* User: XMing
* Date: 2020/11/10
* Time: 9:44 上午
* @param int $shopId 店铺id
* @param string $control 控制器
* @return ResultWrapper
* @throws \Exception
*/
public static function sendMessage(int $shopId,string $control,$source = 'order')
{
try {
echo '-1';
$swooleServerConfigData = Factory::config()->getAppoint('swooleServer', 'order');
if (empty($swooleServerConfigData)) {
return ResultWrapper::fail('swoole服务端链接信息配置项错误',ErrorCode::$paramError);
}
echo '-3';
var_dump($swooleServerConfigData);
$swooleClient = Factory::swoole($swooleServerConfigData, 'WebsocketClient');
// 触发商家新订单通知
$data = [
'controller' => $control,
'action' => 'autoSend',
'params' => [
'platfrom' => SOOOLE_SOURCE,
'shop_id' => $shopId,
'source' => $source
]
];
echo '-3';
$swooleClient->sendJson($data);
echo '-4';
return ResultWrapper::success('发送消息成功!');
}catch (\Throwable $exception){
echo '-error:'.$exception->getMessage();
return ResultWrapper::fail($exception->getMessage(),ErrorCode::$serviceError);
}
}
}