Commit 6e9adccc authored by wwccw0591's avatar wwccw0591

Merge branch 'master_dev' of git.shenbd.com:qm-develop/shenbd into ccw

parents bc6bbecc e99f0977
...@@ -57,4 +57,11 @@ class CommonController extends \Our\Controller_AbstractIndex{ ...@@ -57,4 +57,11 @@ class CommonController extends \Our\Controller_AbstractIndex{
$this->success(array(),\Our\DescribeConst::emptyMyAddresses,\Our\DescribeConst::emptyMyAddresses); $this->success(array(),\Our\DescribeConst::emptyMyAddresses,\Our\DescribeConst::emptyMyAddresses);
} }
public function getProblemListAction(){
$commonProbleService = \Business\Common\CommonProblemServiceModel::getInstance();
$articleList = $commonProbleService->getProblemList(true);
$this->success($articleList);
}
} }
\ No newline at end of file
...@@ -15,7 +15,7 @@ class StoreController extends \Our\Controller_AbstractIndex { ...@@ -15,7 +15,7 @@ class StoreController extends \Our\Controller_AbstractIndex {
public function getStoreInfoAction(){ public function getStoreInfoAction(){
$storeInfo = $this->storeService->getStoreInfo($this->req[\Our\NameConst::data],$this->memberId); $storeInfo = $this->storeService->getStoreInfo($this->req[\Our\NameConst::data],$this->memberId);
//. //.
$storeInfo['adv'] = array('href'=>'http://qm.22ca.com/qm/tmpl/goods.html?goods_commonid=101654','imageUrl'=>'http://qmoss-01.oss-cn-hangzhou.aliyuncs.com/data/upload/mall/adv/05715960161498410.jpg'); $storeInfo['adv'] = array('href'=>'','imageUrl'=>'http://qmoss-01.oss-cn-hangzhou.aliyuncs.com/data/upload/mall/adv/05715960161498410.jpg');
$storeInfo['share'] = \Business\Common\CommonServiceModel::getInstance()->getShareInfo(\Our\ApiConst::shareStore,$this->req[\Our\NameConst::data]['storeId']); $storeInfo['share'] = \Business\Common\CommonServiceModel::getInstance()->getShareInfo(\Our\ApiConst::shareStore,$this->req[\Our\NameConst::data]['storeId']);
$this->success($storeInfo); $this->success($storeInfo);
} }
......
<?php <?php
namespace Lock;
/** /**
* User: liuyuzhen * User: liuyuzhen
* Date: 2018/8/20 * Date: 2018/8/20
* Time: 11:02 * Time: 11:02
* Description: * Description:
*/ */
class DbLock implements \Lock\ILock{
private $lockModel ;
public function __construct(){
$this->lockModel = \DAO\LockModel::getInstance();
}
public function getLock($key, $timeout=self::EXPIRE){
return $this->lockModel->getLock($key, $timeout);
}
public function releaseLock($key){
return $this->lockModel->releaseLock($key);
}
/**
* 类实例
*
*/
private static $_instance = null;
/**
* 获取类实例
*/
public static function getInstance() {
if (!(self::$_instance instanceof self)) {
self::$_instance = new self();
}
return self::$_instance;
}
}
\ No newline at end of file
<?php <?php
namespace Lock;
/** /**
* User: liuyuzhen * User: liuyuzhen
* Date: 2018/8/20 * Date: 2018/8/20
* Time: 10:10 * Time: 10:10
* Description: * Description:
*/ */
class FileLock implements \Lock\ILock{
private $_fp;
private $_single;
public function __construct($options)
{
if (isset($options['path']) && is_dir($options['path']))
{
$this->_lockPath = $options['path'].'/';
}
else
{
$this->_lockPath = '/tmp/';
}
$this->_single = isset($options['single'])?$options['single']:false;
}
public function getLock($key, $timeout=self::EXPIRE)
{
$startTime = TIMESTAMP;
$file = md5(__FILE__.$key);
$this->fp = fopen($this->_lockPath.$file.'.lock', "w+");
if (true || $this->_single)
{
$op = LOCK_EX + LOCK_NB;
}
else
{
$op = LOCK_EX;
}
if (false == flock($this->fp, $op, $a))
{
throw new Exception('failed');
}
return true;
}
public function releaseLock($key)
{
flock($this->fp, LOCK_UN);
fclose($this->fp);
}
}
\ No newline at end of file
<?php <?php
namespace Lock;
/** /**
* User: liuyuzhen * User: liuyuzhen
* Date: 2018/8/20 * Date: 2018/8/20
* Time: 10:09 * Time: 10:09
* Description: * Description:
*/ */
interface ILock{
const EXPIRE = 5;
public function getLock($key, $timeout = self::EXPIRE);
public function releaseLock($key);
}
\ No newline at end of file
<?php <?php
namespace Lock;
/** /**
* User: liuyuzhen * User: liuyuzhen
* Date: 2018/8/20 * Date: 2018/8/20
* Time: 11:18 * Time: 11:18
* Description: * Description:
*/ */
class LockConst {
const goodsStoreagePrefix = 'goodsStorage_';
}
\ No newline at end of file
<?php
namespace Lock;
/**
* User: liuyuzhen
* Date: 2018/8/20
* Time: 15:30
* Description:
*/
class LockSystem{
const LOCK_TYPE_DB = 'DbLock';
const LOCK_TYPE_FILE = 'FileLock';
const LOCK_TYPE_REDIS = 'RedisLock';
private $_lock = null;
private static $_supportLocks = array('FileLock', 'DbLock', 'RedisLock');
public function __construct($type, $options = array()){
if(false == empty($type))
{
$this->createLock($type, $options);
}
}
public function createLock($type, $options=array()){
if (false == in_array($type, self::$_supportLocks))
{
throw new Exception("not support lock of ${type}");
}
$this->_lock = new $type($options);
}
public function getLock($key, $timeout = \Lock\ILock::EXPIRE){
if (false == $this->_lock instanceof \Lock\ILock)
{
throw new Exception('false == $this->_lock instanceof ILock');
}
$this->_lock->getLock($key, $timeout);
}
public function releaseLock($key){
if (false == $this->_lock instanceof \Lock\ILock)
{
throw new Exception('false == $this->_lock instanceof ILock');
}
$this->_lock->releaseLock($key);
}
/**
* 类实例
*
*/
private static $_instance = null;
/**
* 获取类实例
*/
public static function getInstance($type,$options= array()) {
if (!(self::$_instance instanceof self)) {
self::$_instance = new self($type,$options);
}
return self::$_instance;
}
}
\ No newline at end of file
<?php <?php
namespace Lock;
/** /**
* User: liuyuzhen * User: liuyuzhen
* Date: 2018/8/20 * Date: 2018/8/20
* Time: 10:48 * Time: 10:48
* Description: * Description:
*/ */
class RedisLock implements \Lock\ILock{
private $lockRedis ;
public function __construct()
{
$this->lockRedis = \Redis\Db0\LockRedisModel::getInstance();
}
public function getLock($key, $timeout=self::EXPIRE)
{
$waitime = 20000;
$totalWaitime = 0;
$time = $timeout*1000000;
while ($totalWaitime < $time && false == $this->lockRedis->update($key, 1, $timeout)){
usleep($waitime);
$totalWaitime += $waitime;
}
if ($totalWaitime >= $time){
\Our\Log::getInstance()->write($key.' can not get lock for waiting '.$timeout.'s.');
throw new Exception('can not get lock for waiting '.$timeout.'s.');
}
}
public function releaseLock($key)
{
$this->lockRedis->tableDel($key);
}
/**
* 类实例
*
*/
private static $_instance = null;
/**
* 获取类实例
*/
public static function getInstance() {
if (!(self::$_instance instanceof self)) {
self::$_instance = new self();
}
return self::$_instance;
}
}
\ No newline at end of file
...@@ -889,7 +889,6 @@ class OrderConfirmUtil { ...@@ -889,7 +889,6 @@ class OrderConfirmUtil {
$updateOrder['order_state'] = \Our\ApiConst::orderStateWaitConfirm; $updateOrder['order_state'] = \Our\ApiConst::orderStateWaitConfirm;
$updateOrder['is_receive_payment'] = \Our\ApiConst::one; $updateOrder['is_receive_payment'] = \Our\ApiConst::one;
$updateOrder['payment_time'] = (isset($data['payment_time'])? strtotime($data['payment_time']) : TIMESTAMP); $updateOrder['payment_time'] = (isset($data['payment_time'])? strtotime($data['payment_time']) : TIMESTAMP);
$updateOrder['gmt_update'] = TIMESTAMP;
$updateOrder['payment_type'] = $this->getOrderPaymentType($data['pay_type']); $updateOrder['payment_type'] = $this->getOrderPaymentType($data['pay_type']);
$orderUpdateResult = $orderModel->update($orderCon,$updateOrder); $orderUpdateResult = $orderModel->update($orderCon,$updateOrder);
if(!$orderUpdateResult){ if(!$orderUpdateResult){
......
...@@ -92,6 +92,14 @@ class Common ...@@ -92,6 +92,14 @@ class Common
return $configValue; return $configValue;
} }
public static function getBaseUrl(){
$prefix = 'http';
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'){
$prefix = 'https';
}
$url = $prefix.'://'.$_SERVER['SERVER_NAME'];
return $url;
}
/** /**
......
...@@ -8,9 +8,14 @@ namespace Business\Common; ...@@ -8,9 +8,14 @@ namespace Business\Common;
*/ */
class CommonProblemServiceModel extends \Business\AbstractModel{ class CommonProblemServiceModel extends \Business\AbstractModel{
public function getProblemList(){ public function getProblemList($urlFlag=false){
$articleDao = \DAO\Article\ArticleModel::getInstance(); $articleDao = \DAO\Article\ArticleModel::getInstance();
$articleList = \Our\RedisHelper::cachedFunction(\Redis\Db10\ArticleRedisModel::getInstance(),array(&$articleDao, 'getList'),array(array('ac_id'=>\Our\ApiConst::commonProblemArticleClassId),'article_id as problemId,article_title as problemTitle',array('article_sort'=>'asc','article_id'=>'desc')),\Our\ApiConst::oneHour,array(\Our\ApiConst::commonProblemArticleClassId)); $articleList = \Our\RedisHelper::cachedFunction(\Redis\Db10\ArticleRedisModel::getInstance(),array(&$articleDao, 'getList'),array(array('ac_id'=>\Our\ApiConst::commonProblemArticleClassId),'article_id as problemId,article_title as problemTitle',array('article_sort'=>'asc','article_id'=>'desc')),\Our\ApiConst::oneHour,array(\Our\ApiConst::commonProblemArticleClassId));
if($urlFlag){
foreach($articleList as &$article){
$article['problemUrl'] = '/qa/detail?id='.$article['problemId'];
}
}
return $articleList; return $articleList;
} }
......
...@@ -261,7 +261,7 @@ class GoodsCommonServiceModel extends \Business\AbstractModel ...@@ -261,7 +261,7 @@ class GoodsCommonServiceModel extends \Business\AbstractModel
if(is_array($list) && !empty($list)){ if(is_array($list) && !empty($list)){
$totalCount = \Our\RedisHelper::cachedFunction(\Redis\Db4\GoodsCommonRedisModel::getInstance(),array(&$commonDAO, 'getCount'),array(implode(' and ',$where),$attrStr),\Our\ApiConst::oneDaySecond,array($storeId)); $totalCount = \Our\RedisHelper::cachedFunction(\Redis\Db4\GoodsCommonRedisModel::getInstance(),array(&$commonDAO, 'getCount'),array(implode(' and ',$where),$attrStr),\Our\ApiConst::oneDaySecond,array($storeId));
foreach ($list as $v){ foreach ($list as $v){
$v['goodsImage'] = \DAO\GoodsCommonModel::getInstance()->getGoodsImgSrc($v['goods_image'],360); $v['goodsImage'] = \DAO\GoodsCommonModel::getInstance()->getGoodsImgSrc($v['goodsImage'],360);
$v['goodsPrice'] = (int)$v['goodsPrice']; $v['goodsPrice'] = (int)$v['goodsPrice'];
unset($v['goods_price']); unset($v['goods_price']);
$goods[] = $v; $goods[] = $v;
......
...@@ -54,7 +54,7 @@ class StoreServiceModel extends \Business\AbstractModel{ ...@@ -54,7 +54,7 @@ class StoreServiceModel extends \Business\AbstractModel{
if($param['sid']) { if($param['sid']) {
$sale = \DAO\SaleModel::getInstance()->getOne(array('sale_id'=>$param['sid']),'sale_act_id,member_id'); $sale = \DAO\SaleModel::getInstance()->getOne(array('sale_id'=>$param['sid']),'sale_act_id,member_id');
if($sale) { if($sale) {
\DAO\SaleMemberModel::getInstance()->insert(array('sale_id'=>$sale['member_id'],'sale_act_id'=>$sale['member_id'],'member_id'=>$memberId,'storeId'=>$storeId)); \DAO\SaleMemberModel::getInstance()->insertOrUpdate(array('sale_id'=>$sale['member_id'],'sale_act_id'=>$sale['sale_act_id'],'member_id'=>$memberId,'storeId'=>$storeId));
} }
} }
}else{ }else{
...@@ -67,9 +67,10 @@ class StoreServiceModel extends \Business\AbstractModel{ ...@@ -67,9 +67,10 @@ class StoreServiceModel extends \Business\AbstractModel{
$scan_sale_ids = $sess->get('scan_sale_ids'); $scan_sale_ids = $sess->get('scan_sale_ids');
is_array($scan_sale_ids) ? $scan_sale_ids = $scan_sale_ids : $scan_sale_ids = []; is_array($scan_sale_ids) ? $scan_sale_ids = $scan_sale_ids : $scan_sale_ids = [];
$sid = (int)$param['sid']; $sid = (int)$param['sid'];
array_push($scan_sale_ids,$sid); $scan_sale_ids[$sid] = $storeId;
//$scan_sale_ids[$sid.','.$aid] = array('sid'=>$sid,'aid'=>$aid); //array_push($scan_sale_ids,$sid);
$sess['scan_sale_ids'] = array_unique($scan_sale_ids); //$scan_sale_ids[$sid.','.$aid] = array($sid=>$storeId);
$sess['scan_sale_ids'] = $scan_sale_ids;
} }
} }
} }
......
...@@ -14,14 +14,16 @@ class FeedBackServiceModel extends \Business\AbstractModel ...@@ -14,14 +14,16 @@ class FeedBackServiceModel extends \Business\AbstractModel
public function saveFeedback($param,$memberId){ public function saveFeedback($param,$memberId){
$feedbackDescribe = trim($param['feedbackDescribe']); $feedbackDescribe = trim($param['feedbackDescribe']);
$feedbackTelepone = trim($param['feedbackTelepone']); $feedbackTelepone = trim($param['feedbackTelepone']);
$feedbackTelephone = trim($param['feedbackTelephone']);
$telephone = $feedbackTelepone ? $feedbackTelepone : $feedbackTelephone;
$type = (int)$param['type']; $type = (int)$param['type'];
if(!$feedbackDescribe){ if(!$feedbackDescribe){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::emptyFeedbackDescribe); \Error\ErrorModel::throwException(\Error\CodeConfigModel::emptyFeedbackDescribe);
} }
if(!$feedbackTelepone){ if(!$telephone){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::emptyFeedbackDescribe); \Error\ErrorModel::throwException(\Error\CodeConfigModel::emptyFeedbackDescribe);
} }
$return = \Our\Common::checkMobilePhone($feedbackTelepone); $return = \Our\Common::checkMobilePhone($telephone);
if($return === false){ if($return === false){
\Error\ErrorModel::throwException(\Error\CodeConfigModel::feedbackTelError); \Error\ErrorModel::throwException(\Error\CodeConfigModel::feedbackTelError);
} }
...@@ -44,7 +46,7 @@ class FeedBackServiceModel extends \Business\AbstractModel ...@@ -44,7 +46,7 @@ class FeedBackServiceModel extends \Business\AbstractModel
$insert['feedback_image'] = serialize($imgArr); $insert['feedback_image'] = serialize($imgArr);
$insert['feedback_describe'] = $feedbackDescribe; $insert['feedback_describe'] = $feedbackDescribe;
$insert['feedback_time'] = time(); $insert['feedback_time'] = time();
$insert['feedback_telepone'] = $feedbackTelepone; $insert['feedback_telephone'] = $telephone;
$insert['member_id'] = $memberId; $insert['member_id'] = $memberId;
$return = \DAO\FeedBackModel::getInstance()->insert($insert); $return = \DAO\FeedBackModel::getInstance()->insert($insert);
......
...@@ -4,6 +4,7 @@ namespace Business\User; ...@@ -4,6 +4,7 @@ namespace Business\User;
use DAO\MbUserTokenModel; use DAO\MbUserTokenModel;
use DAO\MemberModel; use DAO\MemberModel;
use DAO\SaleMemberModel;
use Error\CodeConfigModel; use Error\CodeConfigModel;
use Error\ErrorModel; use Error\ErrorModel;
use Our\ApiConst; use Our\ApiConst;
...@@ -283,6 +284,22 @@ class MemberServiceModel extends \Business\AbstractModel ...@@ -283,6 +284,22 @@ class MemberServiceModel extends \Business\AbstractModel
$result = $storeMemberDao->addBatch($storeMember); $result = $storeMemberDao->addBatch($storeMember);
return $result; return $result;
} }
$scan_sale_ids = $sess->get('scan_sale_ids');
if($scan_sale_ids){
$saleIds = array_keys($scan_sale_ids);
$saleList = \DAO\SaleModel::getInstance()->getList(array('sale_id'=>array('in',$saleIds)),'sale_id,sale_act_id,member_id');
$saleMembers = array();
foreach($saleList as $sale){
$saleMember = array();
$saleMember['member_id'] = $memberId;
$saleMember['store_id'] = $scan_sale_ids[$sale['sale_id']];
$saleMember['sale_id'] = $sale['member_id'];
$saleMember['sale_act_id'] = $sale['sale_act_id'];
$saleMembers[]=$saleMember;
}
$resultSaleMember = \DAO\SaleMemberModel::getInstance()->insertAllOrUpdate($saleMembers);
return $resultSaleMember;
}
return true; return true;
} }
......
<?php <?php
namespace DAO;
/** /**
* User: liuyuzhen * User: liuyuzhen
* Date: 2018/8/20 * Date: 2018/8/20
* Time: 10:15 * Time: 10:15
* Description: * Description:
*/ */
class LockModel extends \DAO\AbstractModel{
public function init(){
}
public function getLock($key, $timeout)
{
$sql = "SELECT GET_LOCK('".$key."', '".$timeout."')";
$res = $this->db->query($sql);
return $res;
}
public function releaseLock($key)
{
$sql = "SELECT RELEASE_LOCK('".$key."')";
return $this->db->query($sql);
}
/**
* 类实例
*
* @var \DAO\UserModel
*/
private static $_instance = null;
/**
* 获取类实例
*
* @return \DAO\UserModel
*/
public static function getInstance($dbName = \Our\DbNameConst::salveDBConnectName) {
if (!(self::$_instance instanceof self)) {
self::$_instance = new self($dbName);
}
return self::$_instance;
}
}
\ No newline at end of file
...@@ -116,17 +116,57 @@ class SaleMemberModel extends \DAO\AbstractModel { ...@@ -116,17 +116,57 @@ class SaleMemberModel extends \DAO\AbstractModel {
$this->setDb(\Our\DbNameConst::masterDBConnectName); $this->setDb(\Our\DbNameConst::masterDBConnectName);
return $this->db->insert($this->_tableName)->rows($data)->execute(); return $this->db->insert($this->_tableName)->rows($data)->execute();
} }
public function insertOrUpdate($data){
$this->setDb(\Our\DbNameConst::masterDBConnectName);
$baseSql = "insert into {$this->_tableName}(sale_id,sale_act_id,member_id,store_id) values({0},{1},{2},{3}) ON DUPLICATE KEY UPDATE sale_id=VALUES (sale_id)";
$sql = \Our\Common::format($baseSql, $data['sale_id'], $data['sale_act_id'],$data['member_id'],$data['store_id']);
return $this->db->insert($this->_tableName)->query($sql);
}
public function insertAllOrUpdate($datas){
$this->setDb(\Our\DbNameConst::masterDBConnectName);
$error = 0;
$baseSql = "insert into {$this->_tableName}(sale_id,sale_act_id,member_id,store_id) values";
$insertAllSql = $baseSql;
for ($i = 0; $i < count($datas); $i++) {
$addSql = \Our\Common::format("('{0}','{1}','{2}','{3}'),", $datas[$i]['sale_id'], $datas[$i]['sale_act_id'], $datas[$i]['member_id'], $datas[$i]['store_id']);
$insertAllSql .= $addSql;
if ($i % 1000 == 0 && $i != 0) {
$insertAllSql = rtrim($insertAllSql, ',');
$insertAllSql .= 'ON DUPLICATE KEY UPDATE sale_id = VALUES(sale_id)';
$one = $this->db->insert()->query($insertAllSql);
if ($one === false) {
$error++;
}
$insertAllSql = $baseSql;
}
}
if ($insertAllSql != $baseSql) {
$insertAllSql = rtrim($insertAllSql, ',');
$insertAllSql .= 'ON DUPLICATE KEY UPDATE sale_id = VALUES(sale_id)';
$one = $this->db->insert($this->_tableName)->query($insertAllSql);
if ($one === false) {
$error++;
}
}
if ($error > 0) {
return false;
}
return true;
}
/** /**
* 类实例 * 类实例
* *
* @var \DAO\UserModel
*/ */
private static $_instance = null; private static $_instance = null;
/** /**
* 获取类实例 * 获取类实例
* *
* @return \DAO\UserModel
*/ */
public static function getInstance() { public static function getInstance() {
if (!(self::$_instance instanceof self)) { if (!(self::$_instance instanceof self)) {
......
...@@ -6,3 +6,100 @@ namespace Redis\Db0; ...@@ -6,3 +6,100 @@ namespace Redis\Db0;
* Time: 10:30 * Time: 10:30
* Description: * Description:
*/ */
class LockRedisModel extends \Redis\Db0\AbstractModel {
/**
* 表名
*
* @var string
*/
protected $_tableName = 'han_lock';
/**
* 计算key
*
* @param int $id
* @return string
*/
public function calcKey($id) {
return $this->_tableName . self::DELIMITER . $id;
}
/**
* 根据id查找用户信息
*
* @param int $id
* @return array
*/
public function find($id) {
$result = $this->get($this->calcKey($id));
if ($result) {
return json_decode($result, true);
}
return null;
}
/**
* 更新数据
*
* @param int $id
* @param array $data
*/
public function update($id, $data,$expire=\Our\ApiConst::zero) {
return $this->set($this->calcKey($id), json_encode($data),$expire);
}
public function tableHSet($h,$key,$val,$experio=0){
return $this->hset($this->calcKey($h),$key,$val,$experio);
}
public function tableHGet($h,$key){
return $this->hget($this->calcKey($h),$key);
}
public function tableHMSet($h,$keysvalue,$experio=0){
return $this->hmset($this->calcKey($h),$keysvalue,$experio);
}
public function tableHMGet($h,$keyvalues){
return $this->hmget($this->calcKey($h),$keyvalues);
}
public function tableHGAll($h){
return $this->hGetAll($this->calcKey($h));
}
public function tableDel($h){
return $this->del($this->calcKey($h));
}
public function tableExpire($key,$experio=0){
return $this->expire($this->calcKey($key),$experio);
}
public function tableCacheGet($id){
$result = $this->get($this->calcKey($id));
return $result;
}
public function tableCacheSet($id,$data,$experio){
$res=$this->set($this->calcKey($id), $data,$experio);
return $res;
}
/**
* 类实例
*
*/
private static $_instance = null;
/**
* 获取类实例
*/
public static function getInstance() {
if (!(self::$_instance instanceof self)) {
self::$_instance = new self();
}
return self::$_instance;
}
}
\ No newline at end of file
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