123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988 |
- <?php
- /**
- * 基础Model类
- * Created by PhpStorm.
- * User: wxj
- * Date: 2019/11/27
- * Time: 12:01
- */
- namespace JinDouYun\Model;
- use JinDouYun\Controller\Common\Logger;
- use JinDouYun\Model\GoodsManage\MGoodsBasic;
- use JinDouYun\Model\GoodsManage\MSku;
- use JinDouYun\Model\Merchant\MMerchant;
- use JinDouYun\Model\Stock\MWarehouse;
- use JinDouYun\Model\System\MPrintNum;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Cache\GoodsBasicRelevant;
- use JinDouYun\Cache\RoleAclCache;
- use JinDouYun\Model\Common\MCommon;
- use Mall\Framework\Factory;
- class MBaseModel
- {
- private $onlineEnterpriseId;
- private $onlineUserId;
- //数据域相关
- private $objRoleAclCache;
- private static $dataField = [];
- static $salesManIds = [];//业务员ids
- static $staffUserCenterIds;//业务员对应的uids
- static $shopIds = [];//商铺ids
- static $warehouseIds = [];//仓库ids
- public function __construct($onlineEnterpriseId = '', $onlineUserId = '')
- {
- $this->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 .= '<gpWord Align=1 Bold=1 Wsize=1 Hsize=1 Reverse=0 Underline=0>'.$params['shopName'].'</gpWord><gpBr/>';//商铺名称
- $msgDetail .= '<gpWord Align=1 Bold=1 Wsize=0 Hsize=0 Reverse=0 Underline=0>'.$params['title'].'</gpWord><gpBr/>';//标题
- // $msgDetail .= '<gpBarCode Align=1 Type=7 Width=2 Height=80 Position=0>'.$params['code'].'</gpBarCode>';//单号
- $msgDetail .= '<gpWord Align=0 Bold=0 Wsize=0 Hsize=0 Reverse=0 Underline=0>'.$params['codeName'].':'.$params['code'].'</gpWord>';//单号详情
- $msgDetail .= '<gpWord Align=0 Bold=0 Wsize=0 Hsize=0 Reverse=0 Underline=0>订单日期:'.date('Y-m-d H:i:s', $params['createTime']).'</gpWord>';//订单日期
- $msgDetail .= '<gpWord Align=0 Bold=0 Wsize=0 Hsize=0 Reverse=0 Underline=0>顾客姓名:'.$params['userName'].'</gpWord>';//买家姓名
- $msgDetail .= '<gpWord Align=0 Bold=0 Wsize=0 Hsize=0 Reverse=0 Underline=0>顾客电话:'.$params['mobile'].'</gpWord>';//买家手机号
- $msgDetail .= '<gpWord Align=0 Bold=0 Wsize=0 Hsize=0 Reverse=0 Underline=0>收货地址:'.$params['address'].'</gpWord>';//买家手机号
- // $msgDetail .= '<gpWord Align=0 Bold=1 Wsize=0 Hsize=1 Reverse=0 Underline=0>买家留言:发顺丰,尽快发货,谢谢</gpWord>';//买家留言
- // $msgDetail .= '<gpWord Align=0 Bold=1 Wsize=0 Hsize=1 Reverse=0 Underline=0>卖家备注:发顺丰,优先处理</gpWord>';//卖家备注
- // $msgDetail .= '<gpWord Align=0 Bold=1 Wsize=0 Hsize=1 Reverse=0 Underline=0>买就送信息:送U盘</gpWord>';//活动信息 活动说明
- $msgDetail .= '<gpWord Align=0 Bold=0 Wsize=0 Hsize=0 Reverse=0 Underline=0>--------------------------------</gpWord>';
- $msgDetail .= '<gpTR4 Type=0><td>商品</td><td>单价</td><td>数量</td><td>金额</td></gpTR4>';//商品名称 商品单价 商品数量 商品总价
- //循环商品信息
- foreach($details as $value) {
- if(count($value['skuData']) > 1){
- $msgDetail .= '<gpTR4 Type=0><td>'.$value['title'].'</td><td></td><td></td><td></td></gpTR4>';
- foreach($value['skuData'] as $vv){
- $msgDetail .= '<gpTR4 Type=0><td> '.$vv['skuName'].'</td><td>'.$vv['unitPrice'].'</td><td>'.$vv['num'].$vv['unitName'].'</td><td>'.$vv['amountPrice'].'</td></gpTR4>';
- }
- }else{
- foreach($value['skuData'] as $vv){
- $msgDetail .= '<gpTR4 Type=0><td>'.$value['title'].' '.$vv['skuName'].'</td><td>'.$vv['unitPrice'].'</td><td>'.$vv['num'].$vv['unitName'].'</td><td>'.$vv['amountPrice'].'</td></gpTR4>';
- }
- }
- }
- $msgDetail .= '<gpWord Align=0 Bold=0 Wsize=0 Hsize=0 Reverse=0 Underline=0>-------------------------------- </gpWord>';
- $msgDetail .= '<gpTR2 Type=0><td>优惠:</td><td>-'.$params['preferential'].'元</td></gpTR2>';//优惠金额
- $msgDetail .= '<gpTR2 Type=0><td>合计:</td><td>'.$params['totalMoney'].'元</td></gpTR2>';//合计金额
- $msgDetail .= '<gpTR2 Type=0><td>应收:</td><td>'.$params['payAmount'].'元</td></gpTR2>';//应收金额
- $msgDetail .= '<gpCut/>';
- // $msgDetail .= '<gpWord Align=1 Bold=1 Wsize=1 Hsize=1 Reverse=0 Underline=0>扫码关注千鸟云商</gpWord><gpBr/>';//二维码说明
- // $msgDetail .= '<gpImg Align=1>http://onlineimg.qianniao.vip/b8ca10e4ce35fded735c980403dfedf7/gh_16db94f79967_430.jpg</gpImg>';//二维码地址
- $msgDetail .= '<gpCut/><gpBr/>';
- break;
- case 2:
- $details = $params['details'];
- $msgDetail .= '<CB>'.$params['shopName'].'</CB><BR>';
- $msgDetail .= '<CB>'.$params['title'].'</CB><BR>';
- $msgDetail .= $params['codeName'].':'.$params['code'].'<BR>';
- $msgDetail .= '订单日期:'.date('Y-m-d H:i:s', $params['createTime']).'<BR>';
- $msgDetail .= '顾客姓名:'.$params['userName'].'<BR>';
- $msgDetail .= '顾客电话:'.$params['mobile'].'<BR>';
- $msgDetail .= '收货地址:'.$params['address'].'<BR>';
- $msgDetail .= '--------------------------------<BR>';
- $msgDetail .= '商品 单价 数量 金额<BR>';
- foreach($details as $value) {
- if (count($value['skuData']) > 1) {
- $msgDetail .= $value['title'].'<BR>';
- $msgDetail .= self::formatText($value['skuData']);
- }else{
- $msgDetail .= self::formatText($value['skuData'], $value['title']);
- }
- }
- $msgDetail .= '--------------------------------<BR>';
- $msgDetail .= '优惠:<RIGHT>-'.$params['preferential'].'元</RIGHT><BR>';
- $msgDetail .= '合计:<RIGHT>'.$params['totalMoney'].'元</RIGHT><BR>';
- $msgDetail .= '应收:<RIGHT>'.$params['payAmount'].'元</RIGHT><BR>';
- $msgDetail .= '<CUT>';
- 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.'<BR>';
- }
- 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.'<BR>';
- }
- }
- $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);
- }
- }
- }
|