Commit 9668d362 authored by wwccw0591's avatar wwccw0591

pc

parent 428be239
...@@ -121,9 +121,11 @@ class MessageServiceModel extends \Business\AbstractModel ...@@ -121,9 +121,11 @@ class MessageServiceModel extends \Business\AbstractModel
$avatar=Common::getStaticFile(ImageConst::expressAvatarName,ImageConst::systemAvatar,ImageConst::imageDomain); $avatar=Common::getStaticFile(ImageConst::expressAvatarName,ImageConst::systemAvatar,ImageConst::imageDomain);
} }
if($type==4){ if($type==4){
$member=\DAO\MemberModel::getInstance();
$storeId=$member->getInfo($userid,'store_id');
$store=\DAO\StoreModel::getInstance(); $store=\DAO\StoreModel::getInstance();
$store->setDb($db); $store->setDb($db);
$avatar=$store->getInfoById($userid,'store_label','store_label'); $avatar=$store->getInfoById($storeId,'store_label','store_label');
$avatar=Common::getStaticFile($avatar,ImageConst::storeLabel,ImageConst::imageDomain); $avatar=Common::getStaticFile($avatar,ImageConst::storeLabel,ImageConst::imageDomain);
} }
......
...@@ -5,6 +5,7 @@ namespace Business\Store; ...@@ -5,6 +5,7 @@ namespace Business\Store;
use DAO\StoreModel; use DAO\StoreModel;
use DAO\MemberModel; use DAO\MemberModel;
use DAO\StoreStatisticsModel; use DAO\StoreStatisticsModel;
use Elastics\ElasticsToolModel;
use Error\CodeConfigModel; use Error\CodeConfigModel;
use Error\ErrorModel; use Error\ErrorModel;
use Our\ApiConst; use Our\ApiConst;
...@@ -479,10 +480,71 @@ class ShopkeeperServiceModel extends \Business\AbstractModel ...@@ -479,10 +480,71 @@ class ShopkeeperServiceModel extends \Business\AbstractModel
$beginTime=$gmtCreate; $beginTime=$gmtCreate;
$this->taskIndex=PageConst::taskPageBegin; $this->taskIndex=PageConst::taskPageBegin;
$this->taskSize=PageConst::taskPageSize; $this->taskSize=PageConst::taskPageSize;
$elasticsTool=ElasticsToolModel::getInstance('orders');
$res= $elasticsTool->indexExists();
echo json_encode($res);exit;
do{ do{
$addDatas=array(); $addDatas=array();
$where=Common::format(" add_time>={0} and add_time<{1} ",$beginTime,TIMESTAMP); $where=Common::format(" add_time>={0} and add_time<{1} ",$beginTime,TIMESTAMP);
$orders=$orderDao->getList($where, 'order_id as orderId,delete_state as deleteState,order_sn as orderSn', $this->taskIndex, $this->taskSize, array( 'add_time'=>'desc')); $orders=$orderDao->getList($where, 'order_id as orderId,delete_state as deleteState,order_sn as orderSn,store_id as storeId,buyer_id as buyerId', $this->taskIndex, $this->taskSize, array( 'add_time'=>'desc'));
if(!empty($orders['list'])){
$indexs=array();
$orderIds=array_column($orders['list'],'orderId');
$orderGoods=$orderGoodDao->getOrderGoodsByOrderIds($orderIds,'order_id as orderId,goods_name as goodsName');
$resultOrders=Common::intergrateOneToMany($orders['list'], $orderGoods, 'orderId', 'orderId', 'orderGoods');
foreach($resultOrders as $result){
$one['orderId']=$result['orderId'];
$one['orderSn']=$result['orderSn'];
$namesArr=array_column($result['orderGoods'],'goodsName');
$nameStr=implode(',',$namesArr);
$one['goodsName']=$nameStr;
$one['orderId']=$result['orderId'];
array_push($indexs,$one);
}
}
$storeMemberStatisticData= $orderGoodDao->getMemberStoreStaticsByCreateTime($beginTime,$this->taskIndex,$this->taskSize);
$storeMemberStatisticData=isset($storeMemberStatisticData['list'])?$storeMemberStatisticData['list']:false;
if($storeMemberStatisticData){
$this->taskIndex++;
foreach($storeMemberStatisticData as $value){
$addDatas[$value['buyerId'].'-'.$value['storeId']]['storeId']=$value['storeId'];
$addDatas[$value['buyerId'].'-'.$value['storeId']]['memberId']=$value['buyerId'];
if(isset($addDatas[$value['buyerId'].'-'.$value['storeId']]['orderGoodsCount'])){
$addDatas[$value['buyerId'].'-'.$value['storeId']]['orderGoodsCount']+=$value['goodsNum'];
}else{
$addDatas[$value['buyerId'].'-'.$value['storeId']]['orderGoodsCount']=$value['goodsNum'];
}
if(isset($addDatas[$value['buyerId'].'-'.$value['storeId']]['orderTotal'])){
$addDatas[$value['buyerId'].'-'.$value['storeId']]['orderTotal']+=$value['goodsPrice'];
}else{
$addDatas[$value['buyerId'].'-'.$value['storeId']]['orderTotal']=$value['goodsPrice'];
}
}
}
$addDatas=array_values($addDatas);
$storeMemberStatisticDao->addAll($addDatas);
}while($orders);
file_put_contents($this->baseDir . PathConst::orderLastCreateTime, TIMESTAMP);
}
//grow orderIndex
//创建索引
public function growOrdersIndex()
{
$orderGoodDao=\DAO\Order\OrderGoodsModel::getInstance(DbNameConst::salveDBConnectName);
$orderDao=\DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName);
$gmtCreate = file_get_contents($this->baseDir . PathConst::orderLastCreateTime);
$gmtCreate = !empty($gmtCreate)?$gmtCreate:ApiConst::zero;
$beginTime=$gmtCreate;
$this->taskIndex=PageConst::taskPageBegin;
$this->taskSize=PageConst::taskPageSize;
$elasticsTool=ElasticsToolModel::getInstance('orders');
$res= $elasticsTool->indexExists();
echo json_encode($res);exit;
do{
$addDatas=array();
$where=Common::format(" add_time>={0} and add_time<{1} ",$beginTime,TIMESTAMP);
$orders=$orderDao->getList($where, 'order_id as orderId,delete_state as deleteState,order_sn as orderSn,store_id as storeId,buyer_id as buyerId', $this->taskIndex, $this->taskSize, array( 'add_time'=>'desc'));
if(!empty($orders['list'])){ if(!empty($orders['list'])){
$indexs=array(); $indexs=array();
$orderIds=array_column($orders['list'],'orderId'); $orderIds=array_column($orders['list'],'orderId');
......
...@@ -43,6 +43,7 @@ class ElasticsToolModel ...@@ -43,6 +43,7 @@ class ElasticsToolModel
'type' => $this->tbName 'type' => $this->tbName
]; ];
} }
/** /**
* 创建索引 结果["acknowledged": true] * 创建索引 结果["acknowledged": true]
*/ */
...@@ -74,7 +75,7 @@ class ElasticsToolModel ...@@ -74,7 +75,7 @@ class ElasticsToolModel
], ],
] ]
], ],
$this->tbName=> [ $this->tbName => [
'properties' => [ 'properties' => [
'phone' => [ 'phone' => [
'type' => 'string', 'type' => 'string',
...@@ -87,6 +88,7 @@ class ElasticsToolModel ...@@ -87,6 +88,7 @@ class ElasticsToolModel
$res = $this->client->indices()->create($params); $res = $this->client->indices()->create($params);
return $res; return $res;
} }
/* /*
* 陈传文 * 陈传文
* 创建索引在设置mapping之前要创建索引 * 创建索引在设置mapping之前要创建索引
...@@ -153,25 +155,26 @@ class ElasticsToolModel ...@@ -153,25 +155,26 @@ class ElasticsToolModel
$response = $this->client->update($updateParams); $response = $this->client->update($updateParams);
} }
//一般传where就可以了, //一般传where就可以了,
public function searchMatch($where,$pageIndex=ApiConst::pageIndex,$pageSize=ApiConst::pageSize,$sort=array('_score' => array('order' => 'desc'))) public function searchMatch($where, $pageIndex = ApiConst::pageIndex, $pageSize = ApiConst::pageSize, $sort = array('_score' => array('order' => 'desc')))
{ {
$searchParams['index'] = $this->dbName; $searchParams['index'] = $this->dbName;
$searchParams['type'] = $this->tbName; $searchParams['type'] = $this->tbName;
$from=($pageIndex)*$pageSize; $from = ($pageIndex) * $pageSize;
$searchParams['from'] = $from; $searchParams['from'] = $from;
$searchParams['size'] = $pageSize; $searchParams['size'] = $pageSize;
$searchParams['sort'] =$sort; $searchParams['sort'] = $sort;
$searchParams['body']=array( $searchParams['body'] = array(
'query'=>array('match'=>$where), 'query' => array('match' => $where),
); );
$retDoc = $this->client->search($searchParams); $retDoc = $this->client->search($searchParams);
if(!isset($retDoc['hits'])){ if (!isset($retDoc['hits'])) {
ErrorModel::throwException(CodeConfigModel::elasticsError); ErrorModel::throwException(CodeConfigModel::elasticsError);
} }
$htis=$retDoc['hits']['hits']; $htis = $retDoc['hits']['hits'];
$returnData['list']=array_column($htis,'_source'); $returnData['list'] = array_column($htis, '_source');
$returnData['total']=$retDoc['hits']['total']; $returnData['total'] = $retDoc['hits']['total'];
return $returnData; return $returnData;
} }
...@@ -215,12 +218,16 @@ class ElasticsToolModel ...@@ -215,12 +218,16 @@ class ElasticsToolModel
*/ */
public function deleteIndex() public function deleteIndex()
{ {
$params = [ try {
'index' => $this->dbName $params = [
]; 'index' => $this->dbName
];
$res = $this->client->indices()->delete($params);
return $res;
} catch (\Exception $ex) {
throw new \Exception($ex->getMessage(), $ex->getCode());
}
$res = $this->client->indices()->delete($params);
return $res;
} }
/** /**
...@@ -236,6 +243,7 @@ class ElasticsToolModel ...@@ -236,6 +243,7 @@ class ElasticsToolModel
$res = $this->client->indices()->delete($params); $res = $this->client->indices()->delete($params);
return $res; return $res;
} }
/** /**
* 删除索引 * 删除索引
*/ */
...@@ -249,30 +257,34 @@ class ElasticsToolModel ...@@ -249,30 +257,34 @@ class ElasticsToolModel
$res = $this->client->index($params); $res = $this->client->index($params);
return $res; return $res;
} }
//插入多条 Document: //插入多条 Document:
public function postBulkDoc($rows){ public function postBulkDoc($rows)
{
foreach($rows as $row){ foreach ($rows as $row) {
$params['body'][] = [ $params['body'][] = [
'index' => [ 'index' => [
'_index' => $this->dbName, '_index' => $this->dbName,
'_type' => $this->tbName, '_type' => $this->tbName,
] ]
]; ];
$params['body'][]=$row; $params['body'][] = $row;
} }
$res = $this->client->bulk($params); $res = $this->client->bulk($params);
return $res; return $res;
} }
public function createIkField(){
public function createIkField()
{
$params = [ $params = [
'index' => $this->dbName, //索引名称 'index' => $this->dbName, //索引名称
'body' => [ 'body' => [
'settings' => [ //配置 'settings' => [ //配置
'analysis' => array( 'analysis' => array(
'analyzer'=>array( 'analyzer' => array(
'ik'=>[ 'ik' => [
'tokenizer'=>'ik_max_word', 'tokenizer' => 'ik_max_word',
] ]
) )
), ),
...@@ -284,8 +296,8 @@ class ElasticsToolModel ...@@ -284,8 +296,8 @@ class ElasticsToolModel
], ],
'properties' => [ //配置数据结构与类型 'properties' => [ //配置数据结构与类型
'goodsName' => [ //字段1 'goodsName' => [ //字段1
"type" =>"string", "type" => "string",
"analyzer"=> "ik_max_word" "analyzer" => "ik_max_word"
], ],
] ]
], ],
...@@ -326,17 +338,33 @@ class ElasticsToolModel ...@@ -326,17 +338,33 @@ class ElasticsToolModel
$res = $this->client->search($params); $res = $this->client->search($params);
return $res; return $res;
} }
//查看mapping
public function getMappings() public function indexExists()
{ {
$params = [ try{
'index' =>$this->dbName, $res =$this->client->exists(array('index'=>$this->dbName));
]; }catch(\Exception $ex){
$res = $this->es->indices()->getMapping($params); return false;
}
return $res; return $res;
} }
/** //查看mapping
public function getMappings()
{
try {
$params = [
'index' => $this->dbName,
];
$res = $this->client->indices()->getMapping($params);
return $res;
} catch (\Exception $ex) {
throw new \Exception($ex->getMessage(), $ex->getCode());
}
}
/**
* 类实例 * 类实例
* *
* @var \DAO\UserModel * @var \DAO\UserModel
......
<?php
/**
* 生成店铺订单索引
* 执行时间:每分钟执行一次
*
* @author chenjiebin <sjlinyu@qq.com>
*/
define("APPLICATION_PATH", realpath(dirname(__FILE__) . '/../../../')); //指向public的上一级
require APPLICATION_PATH . '/scripts/crontab/baseCli.php';
require APPLICATION_PATH . '/scripts/crontab/common.php';
error_reporting(E_ALL ^ E_NOTICE);
class cliShopkeeperOrders extends basecli
{
const CLI_ADMIN_ID = 255;
private $bDoUnLock = FALSE; // 是否允许释放 LOCK 文件
private $_debug = 0;
private $lockFileName;
public $key='';
private $fromState;
private function mkdirs($dir, $mode = 0777)
{
if (is_dir($dir) || @mkdir($dir, $mode)) {
return TRUE;
}
if (!$this->mkdirs(dirname($dir), $mode)) {
return FALSE;
}
return @mkdir($dir, $mode);
}
/**
* 析构
*/
public function __destruct()
{
parent::__destruct();
if ($this->bDoUnLock) {
@unlink($this->lockFileName);
}
}
protected function _runCli()
{
$this->_debug = isset($this->aArgv[1]) ? intval($this->aArgv[1]) : 0;
if ($this->_debug) {
echo "*** Debug mode ***\n";
}
// Step: 02 检查是否已有相同CLI在运行中
$lockDir = $this->_getBaseFileName('shopkeeper');
if (!$this->mkdirs($lockDir)) {
echo '****create dir fail ****';
exit;
}
$this->lockFileName = $lockDir . DS . 'orders.locks';
if (file_exists($this->lockFileName)) {
$stat = stat($this->lockFileName);
if ((TIMESTAMP - $stat['mtime']) > 1800) {
echo "文件被锁超过1800秒,被强制删除";
@unlink($this->lockFileName);
} else {
$this->halt('[' . date('Y-m-d H:i:s') . '] The CLI is running' . "\n");
}
}
$this->bDoUnLock = true;
file_put_contents($this->lockFileName, "running"); // CLI 独占锁
$shopkeeperService = \Business\Store\ShopkeeperServiceModel::getInstance();
$shopkeeperService->baseDir= \Our\Common::getConfig('out.config');
try {
$shopkeeperService->createOrdersIndex();
} catch (\Exception $ex) {
throw new \Exception($ex->getMessage(),$ex->getCode());
}
echo '店铺订单索引生成成功' .date('Y-m-d H:i:s',TIMESTAMP). "\r\n";
}
}
$oCli = new cliShopkeeperOrders(TRUE);
EXIT;
?>
...@@ -73,8 +73,8 @@ class cliShopkeeperOrders extends basecli ...@@ -73,8 +73,8 @@ class cliShopkeeperOrders extends basecli
try { try {
$shopkeeperService->createOrdersIndex(); $shopkeeperService->createOrdersIndex();
} catch (Exception $ex) { } catch (\Exception $ex) {
throw new Exception($ex->getCode() . '|' . $ex->getMessage()); throw new \Exception($ex->getMessage(),$ex->getCode());
} }
echo '店铺订单索引生成成功' .date('Y-m-d H:i:s',TIMESTAMP). "\r\n"; echo '店铺订单索引生成成功' .date('Y-m-d H:i:s',TIMESTAMP). "\r\n";
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment