Commit 482510f6 authored by christ's avatar christ

ccw:master_dev

parent a947d714
...@@ -14,6 +14,7 @@ use Our\ImageConst; ...@@ -14,6 +14,7 @@ use Our\ImageConst;
use Our\ImageUtil; use Our\ImageUtil;
use Our\NameConst; use Our\NameConst;
use Our\OrderConst; use Our\OrderConst;
use Zend\Validator\File\Count;
/** /**
* 店铺service * 店铺service
...@@ -992,6 +993,7 @@ class RefundServiceModel extends \Business\AbstractModel ...@@ -992,6 +993,7 @@ class RefundServiceModel extends \Business\AbstractModel
$orderGoodsDao = \DAO\Order\OrderGoodsModel::getInstance(); $orderGoodsDao = \DAO\Order\OrderGoodsModel::getInstance();
$orderGoodses = \Our\RedisHelper::cachedFunction(\Redis\Db5\RefundReasonRedisModel::getInstance(), array(&$orderGoodsDao, 'getOrderGoodsByOrderIds'), array($orderInfo['orderId'], $this->orderGoodsField), \Our\ApiConst::oneDaySecond); $orderGoodses = \Our\RedisHelper::cachedFunction(\Redis\Db5\RefundReasonRedisModel::getInstance(), array(&$orderGoodsDao, 'getOrderGoodsByOrderIds'), array($orderInfo['orderId'], $this->orderGoodsField), \Our\ApiConst::oneDaySecond);
$orderGoodses = $orderGoodsDao->convertOrderGoods($orderGoodses, 'goodsId'); $orderGoodses = $orderGoodsDao->convertOrderGoods($orderGoodses, 'goodsId');
$allOrderGoods=$orderGoodses;
$goodsIds = $orderGoodsDao->getRefundOrderGoodsIds($orderGoodses); $goodsIds = $orderGoodsDao->getRefundOrderGoodsIds($orderGoodses);
$alreadyRefundGoodsIds=$goodsIds; $alreadyRefundGoodsIds=$goodsIds;
// $this->store=$storeDao->get($this->order['storeId']); // $this->store=$storeDao->get($this->order['storeId']);
...@@ -1006,11 +1008,18 @@ class RefundServiceModel extends \Business\AbstractModel ...@@ -1006,11 +1008,18 @@ class RefundServiceModel extends \Business\AbstractModel
ErrorModel::throwException(CodeConfigModel::notExistOrderGoods); ErrorModel::throwException(CodeConfigModel::notExistOrderGoods);
} }
$shippingFee = ApiConst::zero; $shippingFee = ApiConst::zero;
if (count($orderGoods) == ApiConst::one) { $allReadyGoodsCount=count($goodsIds);
$shippingFee = $storeDao->isFee($orderInfo['storeId'], $orderInfo['shippingType'], $orderInfo['order_state']) ? $orderInfo['shippingFee'] : ApiConst::zero; $allGoodsCount=count($orderGoodses);
} else { if($allReadyGoodsCount==$allGoodsCount){
$shippingFee = $storeDao->isFee($orderInfo['storeId'], $orderInfo['shippingType'], $orderInfo['orderState']) ? $orderInfo['shippingFee'] : ApiConst::zero;
}else{
$shippingFee == ApiConst::zero; $shippingFee == ApiConst::zero;
} }
// if (count($orderGoods) == ApiConst::one) {
// $shippingFee = $storeDao->isFee($orderInfo['storeId'], $orderInfo['shippingType'], $orderInfo['orderState']) ? $orderInfo['shippingFee'] : ApiConst::zero;
// } else {
// $shippingFee == ApiConst::zero;
// }
$orderGoodsConvert = $orderGoodsDao->getRefundOrderGoods($orderGoods); $orderGoodsConvert = $orderGoodsDao->getRefundOrderGoods($orderGoods);
$returnData = array( $returnData = array(
...@@ -1035,6 +1044,10 @@ class RefundServiceModel extends \Business\AbstractModel ...@@ -1035,6 +1044,10 @@ class RefundServiceModel extends \Business\AbstractModel
// } // }
//修改后的优惠金额 //修改后的优惠金额
$discountAmount=$orderInfo['originAmount']- $orderInfo['orderAmount']; $discountAmount=$orderInfo['originAmount']- $orderInfo['orderAmount'];
$mustReduceAmount=ApiConst::zero;
if($discountAmount){
$mustReduceAmount=$orderGoodsDao->getMustReduceAmount($allOrderGoods,$discountAmount,$orderGoodsConvert);
}
if ($orderInfo['paymentTime']) { if ($orderInfo['paymentTime']) {
$orderConfirmUtil = \Order\OrderConfirmUtil::getInstance(); $orderConfirmUtil = \Order\OrderConfirmUtil::getInstance();
...@@ -1048,16 +1061,18 @@ class RefundServiceModel extends \Business\AbstractModel ...@@ -1048,16 +1061,18 @@ class RefundServiceModel extends \Business\AbstractModel
$refundAmount = $orderInfo['orderAmount'] - $orderInfo['shippingFee'] - ApiConst::zero;; $refundAmount = $orderInfo['orderAmount'] - $orderInfo['shippingFee'] - ApiConst::zero;;
} }
} }
if(!$alreadyRefundGoodsIds){ // if(!$alreadyRefundGoodsIds){
$refundAmount=$refundAmount-$discountAmount; // $refundAmount=$refundAmount-$discountAmount;
} // }
} else { } else {
$refundAmount = $orderGoods['goodsPrice']*$orderGoods['goodsNum']; $refundAmount = $orderGoods['goodsPrice']*$orderGoods['goodsNum'];
if(!$alreadyRefundGoodsIds){ // if(!$alreadyRefundGoodsIds){
$refundAmount=$refundAmount-$discountAmount; // $refundAmount=$refundAmount-$discountAmount;
} // }
} }
$refundAmount=$refundAmount-$mustReduceAmount;
$liveMoney=$orderInfo['orderAmount']-$orderInfo['refundAmount']; $liveMoney=$orderInfo['orderAmount']-$orderInfo['refundAmount'];
if($refundAmount>$liveMoney){ if($refundAmount>$liveMoney){
$refundAmount=$liveMoney; $refundAmount=$liveMoney;
......
<?php <?php
namespace DAO\Order; namespace DAO\Order;
use Our\ApiConst; use Our\ApiConst;
use Our\ArrayConst; use Our\ArrayConst;
use Our\Common; use Our\Common;
...@@ -9,7 +10,8 @@ use Our\ImageConst; ...@@ -9,7 +10,8 @@ use Our\ImageConst;
use Our\ImageUtil; use Our\ImageUtil;
class OrderGoodsModel extends \DAO\AbstractModel { class OrderGoodsModel extends \DAO\AbstractModel
{
/** /**
...@@ -18,9 +20,9 @@ class OrderGoodsModel extends \DAO\AbstractModel { ...@@ -18,9 +20,9 @@ class OrderGoodsModel extends \DAO\AbstractModel {
* @var string * @var string
*/ */
protected $_tableName = 'han_order_goods'; protected $_tableName = 'han_order_goods';
public $sumField="rec_id,store_id as storeId,buyer_id as buyerId,goods_num as goodsNum,goods_price as goodsPrice,gmt_create as gmtCreate,order_id as orderId"; public $sumField = "rec_id,store_id as storeId,buyer_id as buyerId,goods_num as goodsNum,goods_price as goodsPrice,gmt_create as gmtCreate,order_id as orderId";
public $groupField=array('buyer_id','store_id'); public $groupField = array('buyer_id', 'store_id');
public $sumGoodsNum=' store_id as storeId,buyer_id as buyerId,sum(goods_num) as orderGoodsCount'; public $sumGoodsNum = ' store_id as storeId,buyer_id as buyerId,sum(goods_num) as orderGoodsCount';
public $orderGoodsField = "order_id as orderId,rec_id as recId,goods_id as goodsId,goods_name as goodsName,goods_price as goodsPrice,goods_num as goodsNum,goods_image as goodsImage,goods_pay_price as goodsPayPrice,sale_act_id as saleActId,sale_id as saleId,comment_state as commentState,is_refund as isRefund,goods_spec as goodsSpec,refund_state_name as refundStateName,refund_id as refundId,goods_commonid as goodsCommonId,goods_commonid as goodsCommonid,goods_group as goodsGroup"; public $orderGoodsField = "order_id as orderId,rec_id as recId,goods_id as goodsId,goods_name as goodsName,goods_price as goodsPrice,goods_num as goodsNum,goods_image as goodsImage,goods_pay_price as goodsPayPrice,sale_act_id as saleActId,sale_id as saleId,comment_state as commentState,is_refund as isRefund,goods_spec as goodsSpec,refund_state_name as refundStateName,refund_id as refundId,goods_commonid as goodsCommonId,goods_commonid as goodsCommonid,goods_group as goodsGroup";
/** /**
* 主键 * 主键
...@@ -29,193 +31,232 @@ class OrderGoodsModel extends \DAO\AbstractModel { ...@@ -29,193 +31,232 @@ class OrderGoodsModel extends \DAO\AbstractModel {
*/ */
protected $_primaryKey = 'rec_id'; protected $_primaryKey = 'rec_id';
public $orderGoodsGoodsNumCountField=" sum(goods_num) as goodsNum"; public $orderGoodsGoodsNumCountField = " sum(goods_num) as goodsNum";
public function init(){ public function init()
{
} }
public function getOrderGoodsList($where,$field,$group = null,$limit = []){ public function getOrderGoodsList($where, $field, $group = null, $limit = [])
{
$this->setDb(); $this->setDb();
if($limit){ if ($limit) {
return $this->db->from($this->_tableName)->select($field)->where($where)->group($group)->limit($limit[0],$limit[1])->fetchAll(); return $this->db->from($this->_tableName)->select($field)->where($where)->group($group)->limit($limit[0], $limit[1])->fetchAll();
} }
return $this->db->from($this->_tableName)->select($field)->where($where)->group($group)->fetchAll(); return $this->db->from($this->_tableName)->select($field)->where($where)->group($group)->fetchAll();
} }
/** /**
* 更新数据 * 更新数据
* @param $data * @param $data
* @param $where * @param $where
* @return mixed * @return mixed
*/ */
public function update($where, $data){ public function update($where, $data)
{
$this->setDb(DbNameConst::masterDBConnectName); $this->setDb(DbNameConst::masterDBConnectName);
$data['gmt_update']=TIMESTAMP; $data['gmt_update'] = TIMESTAMP;
return $this->db->update($this->_tableName)->where($where)->rows($data)->execute(); return $this->db->update($this->_tableName)->where($where)->rows($data)->execute();
} }
public function getOrderGoods($where,$field,$db=DbNameConst::salveDBConnectName){ public function getOrderGoods($where, $field, $db = DbNameConst::salveDBConnectName)
{
$this->setDb($this->dbName); $this->setDb($this->dbName);
$list = $this->db->select($field)->from($this->_tableName)->where($where)->fetchAll(); $list = $this->db->select($field)->from($this->_tableName)->where($where)->fetchAll();
return $list; return $list;
} }
public function getOrderGoodsCountByStoreId($storeId){
public function getOrderGoodsCountByStoreId($storeId)
{
$this->setDb($this->dbName); $this->setDb($this->dbName);
$orderDao=\DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName); $orderDao = \DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName);
$where['store_id']=$storeId; $where['store_id'] = $storeId;
$where['is_refund']=array('neq',ApiConst::refundSuccess); $where['is_refund'] = array('neq', ApiConst::refundSuccess);
$whereOrder['store_id']=array('eq',$storeId); $whereOrder['store_id'] = array('eq', $storeId);
$whereOrder['order_state']=array('in',ArrayConst::orderCloseAndCancel); $whereOrder['order_state'] = array('in', ArrayConst::orderCloseAndCancel);
$orderIds=$orderDao->getFieldByWhere($whereOrder,'order_id'); $orderIds = $orderDao->getFieldByWhere($whereOrder, 'order_id');
if($orderIds){ if ($orderIds) {
$where['order_id']=array('notin',$orderIds); $where['order_id'] = array('notin', $orderIds);
} }
if(is_array($where)){ if (is_array($where)) {
$where=$this->db->getSqlWhereByArray($where); $where = $this->db->getSqlWhereByArray($where);
} }
$goodsCount = $this->db->select($this->orderGoodsGoodsNumCountField)->from($this->_tableName)->where($where)->fetchValue(); $goodsCount = $this->db->select($this->orderGoodsGoodsNumCountField)->from($this->_tableName)->where($where)->fetchValue();
return (int)$goodsCount; return (int)$goodsCount;
} }
/** /**
* 获取单条数据 * 获取单条数据
* @param $where * @param $where
* @return array * @return array
*/ */
public function find($where,$field='*',$db=DbNameConst::salveDBConnectName) { public function find($where, $field = '*', $db = DbNameConst::salveDBConnectName)
{
$this->setDb($db); $this->setDb($db);
$data=$this->db->from($this->_tableName)->select($field)->where($where)->fetchOne(); $data = $this->db->from($this->_tableName)->select($field)->where($where)->fetchOne();
return $data; return $data;
} }
/** /**
* 根据订单id 和商品id 获得订单商品记录 * 根据订单id 和商品id 获得订单商品记录
* @param $where * @param $where
* @return array * @return array
*/ */
public function getOneByOrderIdAndGoodsId($orderId,$goodsId,$field='*'){ public function getOneByOrderIdAndGoodsId($orderId, $goodsId, $field = '*')
$where['order_id']=$orderId; {
$where['goods_id']=$goodsId; $where['order_id'] = $orderId;
$res=$this->find($where,$field); $where['goods_id'] = $goodsId;
$res = $this->find($where, $field);
return $res; return $res;
} }
public function findByRecId($RecId,$field='*'){
$where['rec_id']=$RecId; public function findByRecId($RecId, $field = '*')
return $this->find($where,$field); {
$where['rec_id'] = $RecId;
return $this->find($where, $field);
} }
/** /**
* 根据订单id 获得订单商品记录 * 根据订单id 获得订单商品记录
* @param $where * @param $where
* @return array * @return array
*/ */
public function getOrderGoodsByOrderIds($orderIds,$field='*'){ public function getOrderGoodsByOrderIds($orderIds, $field = '*')
if(is_array($orderIds)){ {
$where=Common::format(" order_id in ({0})",implode(',',$orderIds)); if (is_array($orderIds)) {
}else{ $where = Common::format(" order_id in ({0})", implode(',', $orderIds));
$where['order_id']=$orderIds; } else {
$where['order_id'] = $orderIds;
} }
return $this->getOrderGoods($where,$field); return $this->getOrderGoods($where, $field);
} }
public function deleteOrderGoodsCache($memberId,$orderIds,$storeId=false){ public function deleteOrderGoodsCache($memberId, $orderIds, $storeId = false)
if($memberId){ {
// return \Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::get:Instance(), array(&$this, 'getOrderGoodsByOrderIds'), array($memberId)); if ($memberId) {
// \Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$this, 'getO:rderGoodsByOrderIds'), array($memberId)); // return \Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::get:Instance(), array(&$this, 'getOrderGoodsByOrderIds'), array($memberId));
\Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$this, 'getOrderGoodsByOrderIds'),array(),array($memberId)); // \Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$this, 'getO:rderGoodsByOrderIds'), array($memberId));
\Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$this, 'getOrderGoodsByOrderIds'), array(), array($memberId));
} }
if($orderIds){ if ($orderIds) {
//return \Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$this, 'getOrderGoodsByOrderIds'), array(),array($orderIds)); //return \Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$this, 'getOrderGoodsByOrderIds'), array(),array($orderIds));
\Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$this, 'getOrderGoodsByOrderIds'), array(),array($orderIds)); \Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$this, 'getOrderGoodsByOrderIds'), array(), array($orderIds));
} }
if(!empty($storeId)){ if (!empty($storeId)) {
// return \Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$this, 'getOrderGoodsCountByStoreId'), array(),array($storeId)); // return \Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$this, 'getOrderGoodsCountByStoreId'), array(),array($storeId));
\Our\RedisHelper::delCachedFunction(\Redis\Db6\StoreRedisModel::getInstance(), array(&$this, 'getOrderGoodsCountByStoreId'), array(),array($storeId)); \Our\RedisHelper::delCachedFunction(\Redis\Db6\StoreRedisModel::getInstance(), array(&$this, 'getOrderGoodsCountByStoreId'), array(), array($storeId));
} }
return true; return true;
} }
public function getIsRefundMoney($orderGoodses,$promotionsId){
$isRefundMoney=ApiConst::zero; public function getIsRefundMoney($orderGoodses, $promotionsId)
foreach($orderGoodses as $orderGood){ {
if($orderGood['promotionsId']=$promotionsId){ $isRefundMoney = ApiConst::zero;
$isRefundMoney+=$orderGood['goodsPrice']; foreach ($orderGoodses as $orderGood) {
if ($orderGood['promotionsId'] = $promotionsId) {
$isRefundMoney += $orderGood['goodsPrice'];
} }
} }
return $isRefundMoney; return $isRefundMoney;
} }
//转换数组 //转换数组
public function convertOrderGoods($orderGoodses,$key='rec_id'){ public function convertOrderGoods($orderGoodses, $key = 'rec_id')
$convertOrderGoods=array(); {
foreach($orderGoodses as $orderGoods){ $convertOrderGoods = array();
$convertOrderGoods[$orderGoods[$key]]=$orderGoods; foreach ($orderGoodses as $orderGoods) {
$convertOrderGoods[$orderGoods[$key]] = $orderGoods;
} }
return $convertOrderGoods; return $convertOrderGoods;
} }
//获得已经退款退货的商品id //获得已经退款退货的商品id
public function getRefundOrderGoodsIds($orderGoods){ public function getRefundOrderGoodsIds($orderGoods)
$newOrderGoods=array(); {
$orderGoods=array_values($orderGoods); $newOrderGoods = array();
for($i=ApiConst::zero;$i<count($orderGoods);$i++){ $orderGoods = array_values($orderGoods);
if($orderGoods[$i]['refundId']!=ApiConst::zero){ for ($i = ApiConst::zero; $i < count($orderGoods); $i++) {
array_push($newOrderGoods,$orderGoods); if ($orderGoods[$i]['refundId'] != ApiConst::zero) {
// unset($orderGoods[$i]); array_push($newOrderGoods, $orderGoods);
// unset($orderGoods[$i]);
} }
} }
$goodsIds=array_column($newOrderGoods,'goodsId'); $goodsIds = array_column($newOrderGoods, 'goodsId');
return $goodsIds; return $goodsIds;
} }
/** /**
* 根据订单id 获得订单商品记录 * 根据订单id 获得订单商品记录
* @param $where * @param $where
* @return array * @return array
*/ */
public function getOrderGoodsByRecIds($recIds,$field='*'){ public function getOrderGoodsByRecIds($recIds, $field = '*')
if(is_array($recIds)){ {
$where=Common::format(" rec_id in ({0})",implode(',',$recIds)); if (is_array($recIds)) {
}else{ $where = Common::format(" rec_id in ({0})", implode(',', $recIds));
$where['rec_id']=$recIds; } else {
$where['rec_id'] = $recIds;
} }
return $this->getOrderGoods($where,$field); return $this->getOrderGoods($where, $field);
} }
//更具订单id获取商品的单挑信息 //更具订单id获取商品的单挑信息
public function getOneByOrderId($orderId,$field='*'){ public function getOneByOrderId($orderId, $field = '*')
$this->setDb(DbNameConst::salveDBConnectName); {
$where['order_id']=$orderId; $this->setDb(DbNameConst::salveDBConnectName);
return $this->db->from($this->_tableName)->where($where)->select($field)->fetchOne(); $where['order_id'] = $orderId;
} return $this->db->from($this->_tableName)->where($where)->select($field)->fetchOne();
}
public function getGoodsCount($orderGoods){ public function getGoodsCount($orderGoods)
{
return array_sum(array_column($orderGoods, 'goodsNum')); return array_sum(array_column($orderGoods, 'goodsNum'));
} }
public function getRefundOrderGoods($orderGoods){ public function getRefundOrderGoods($orderGoods)
return array( {
'goodsId'=>$orderGoods['goodsId'], return array(
'goodsName'=>$orderGoods['goodsName'], 'goodsId' => $orderGoods['goodsId'],
'goodsPrice'=>$orderGoods['goodsPrice'], 'goodsName' => $orderGoods['goodsName'],
'goodsNum'=>$orderGoods['goodsNum'], 'goodsPrice' => $orderGoods['goodsPrice'],
'goodsImage'=>ImageUtil::getGoodsImgUrl($orderGoods['goodsImage'],ApiConst::goodsSmallSize), 'goodsNum' => $orderGoods['goodsNum'],
'goodsPayPrice'=>$orderGoods['goodsPayPrice'], 'goodsImage' => ImageUtil::getGoodsImgUrl($orderGoods['goodsImage'], ApiConst::goodsSmallSize),
'goodsPayPrice' => $orderGoods['goodsPayPrice'],
); );
} }
public function getMustReduceAmount($orderGoodses, $discountAmount, $orderGoods)
{
$allNumbers = array_column($orderGoodses, 'goodsNum');
$allGoodsPrice = array_column($orderGoodses, 'goodsPrice');
$allMoney = $allNumbers * $allGoodsPrice;
$thisOrderGoodsAmount = $orderGoods['goodsNum'] * $orderGoods['goodsPrice'];
$reduceAmount=($discountAmount*$thisOrderGoodsAmount)/($allMoney);
return round($reduceAmount);
}
//销售订单 //销售订单
public function getSaleOrderGoods($field,$updateTime,$pageIndex,$pageSize) { public function getSaleOrderGoods($field, $updateTime, $pageIndex, $pageSize)
{
$pageIndex += 1; $pageIndex += 1;
$this->setDb($this->dbName); $this->setDb($this->dbName);
return $this->db->select($field)->from($this->_tableName)->join('han_order',"han_order.order_id = han_order_goods.order_id",'inner')->join('han_refund_return','han_order_goods.refund_id = han_refund_return.refund_id','left')->where("sale_act_id > 0 AND (han_order_goods.gmt_update > {$updateTime} OR han_order.gmt_update > {$updateTime} OR han_refund_return.gmt_update > {$updateTime})")->page($pageIndex,$pageSize)->fetchAll(); return $this->db->select($field)->from($this->_tableName)->join('han_order', "han_order.order_id = han_order_goods.order_id", 'inner')->join('han_refund_return', 'han_order_goods.refund_id = han_refund_return.refund_id', 'left')->where("sale_act_id > 0 AND (han_order_goods.gmt_update > {$updateTime} OR han_order.gmt_update > {$updateTime} OR han_refund_return.gmt_update > {$updateTime})")->page($pageIndex, $pageSize)->fetchAll();
} }
public function insertAll($datas){
public function insertAll($datas)
{
$this->setDb(\Our\DbNameConst::masterDBConnectName); $this->setDb(\Our\DbNameConst::masterDBConnectName);
$error = 0; $error = 0;
$baseSql = "insert IGNORE into {$this->_tableName}(order_id,store_id,goods_id,goods_name,goods_num,goods_image,goods_price,goods_pay_price,buyer_id,snapshot_id,goods_spec,goods_commonid,gc_id,gc_id_1,gc_id_2,gc_id_3,gmt_create,gmt_update,sale_act_id,sale_id,goods_group) values"; $baseSql = "insert IGNORE into {$this->_tableName}(order_id,store_id,goods_id,goods_name,goods_num,goods_image,goods_price,goods_pay_price,buyer_id,snapshot_id,goods_spec,goods_commonid,gc_id,gc_id_1,gc_id_2,gc_id_3,gmt_create,gmt_update,sale_act_id,sale_id,goods_group) values";
$insertAllSql = $baseSql; $insertAllSql = $baseSql;
for ($i = 0; $i < count($datas); $i++) { for ($i = 0; $i < count($datas); $i++) {
$addSql = \Our\Common::format("('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}'),", $datas[$i]['order_id'], $datas[$i]['store_id'], $datas[$i]['goods_id'], $datas[$i]['goods_name'], $datas[$i]['goods_num'], $datas[$i]['goods_image'], $datas[$i]['goods_price'], $datas[$i]['goods_pay_price'], $datas[$i]['buyer_id'], $datas[$i]['snapshot_id'], $datas[$i]['goods_spec'], $datas[$i]['goods_commonid'], $datas[$i]['gc_id'], $datas[$i]['gc_id_1'], $datas[$i]['gc_id_2'], $datas[$i]['gc_id_3'], $datas[$i]['gmt_create'], $datas[$i]['gmt_update'], $datas[$i]['sale_act_id'], $datas[$i]['sale_id'],$datas[$i]['goods_group']); $addSql = \Our\Common::format("('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}'),", $datas[$i]['order_id'], $datas[$i]['store_id'], $datas[$i]['goods_id'], $datas[$i]['goods_name'], $datas[$i]['goods_num'], $datas[$i]['goods_image'], $datas[$i]['goods_price'], $datas[$i]['goods_pay_price'], $datas[$i]['buyer_id'], $datas[$i]['snapshot_id'], $datas[$i]['goods_spec'], $datas[$i]['goods_commonid'], $datas[$i]['gc_id'], $datas[$i]['gc_id_1'], $datas[$i]['gc_id_2'], $datas[$i]['gc_id_3'], $datas[$i]['gmt_create'], $datas[$i]['gmt_update'], $datas[$i]['sale_act_id'], $datas[$i]['sale_id'], $datas[$i]['goods_group']);
$insertAllSql .= $addSql; $insertAllSql .= $addSql;
if ($i % 1000 == 0 && $i != 0) { if ($i % 1000 == 0 && $i != 0) {
$insertAllSql = rtrim($insertAllSql, ','); $insertAllSql = rtrim($insertAllSql, ',');
...@@ -239,30 +280,36 @@ class OrderGoodsModel extends \DAO\AbstractModel { ...@@ -239,30 +280,36 @@ class OrderGoodsModel extends \DAO\AbstractModel {
} }
return true; return true;
} }
public function getMemberStoreStaticsByCreateTime($gmtCreate,$pageIndex,$pageSize){
public function getMemberStoreStaticsByCreateTime($gmtCreate, $pageIndex, $pageSize)
{
$this->setDb($this->dbName); $this->setDb($this->dbName);
$where =\Our\Common::format(' gmt_update>={0} and gmt_update<{1} ',$gmtCreate,TIMESTAMP); $where = \Our\Common::format(' gmt_update>={0} and gmt_update<{1} ', $gmtCreate, TIMESTAMP);
$res=$this->lists($where,array('gmt_update'=>'asc'),$this->sumField,$pageIndex,$pageSize); $res = $this->lists($where, array('gmt_update' => 'asc'), $this->sumField, $pageIndex, $pageSize);
return $res['list']?$res:false; return $res['list'] ? $res : false;
} }
public function getMemberStoreOrderGoodsCount($storeIds,$memberIds){
public function getMemberStoreOrderGoodsCount($storeIds, $memberIds)
{
$this->setDb($this->dbName); $this->setDb($this->dbName);
$where['store_id']=array('in',$storeIds); $where['store_id'] = array('in', $storeIds);
$where['buyer_id']=array('in',$memberIds); $where['buyer_id'] = array('in', $memberIds);
$where=$this->db->getSqlWhereByArray($where); $where = $this->db->getSqlWhereByArray($where);
$res=$this->db->from($this->_tableName)->select($this->sumGoodsNum)->where($where)->group("buyer_id")->group("store_id")->fetchAll(); $res = $this->db->from($this->_tableName)->select($this->sumGoodsNum)->where($where)->group("buyer_id")->group("store_id")->fetchAll();
return $res; return $res;
} }
public function getOrderGoodsCountBuyStoreIdAndMemberId($storeId,$memberId=false){
public function getOrderGoodsCountBuyStoreIdAndMemberId($storeId, $memberId = false)
{
$this->setDb($this->dbName); $this->setDb($this->dbName);
if($memberId){ if ($memberId) {
$selectSql=Common::format("select {0} from {1} where store_id={2} and buyer_id={3} and is_refund<>{4} and order_id in (select order_id from han_order where store_id={2} and buyer_id={3} and order_state not in({5}) ) ",$this->sumGoodsNum,$this->_tableName,$storeId,$memberId,ApiConst::refundSuccess,"0,-1"); $selectSql = Common::format("select {0} from {1} where store_id={2} and buyer_id={3} and is_refund<>{4} and order_id in (select order_id from han_order where store_id={2} and buyer_id={3} and order_state not in({5}) ) ", $this->sumGoodsNum, $this->_tableName, $storeId, $memberId, ApiConst::refundSuccess, "0,-1");
}else{ } else {
$selectSql=Common::format("select {0} from {1} where store_id={2} and is_refund<>{4} and order_id in (select order_id from han_order where store_id={2} and order_state not in({5}) ) ",$this->sumGoodsNum,$this->_tableName,$storeId,$memberId,ApiConst::refundSuccess,"0,-1"); $selectSql = Common::format("select {0} from {1} where store_id={2} and is_refund<>{4} and order_id in (select order_id from han_order where store_id={2} and order_state not in({5}) ) ", $this->sumGoodsNum, $this->_tableName, $storeId, $memberId, ApiConst::refundSuccess, "0,-1");
} }
$res=$this->db->from($this->_tableName)->query($selectSql); $res = $this->db->from($this->_tableName)->query($selectSql);
return $res->one?$res->one:array(); return $res->one ? $res->one : array();
} }
// public function getMemberStoreOrderGoodsCount($storeIds,$memberIds){ // public function getMemberStoreOrderGoodsCount($storeIds,$memberIds){
...@@ -283,33 +330,37 @@ class OrderGoodsModel extends \DAO\AbstractModel { ...@@ -283,33 +330,37 @@ class OrderGoodsModel extends \DAO\AbstractModel {
// return $res; // return $res;
// //
// } // }
public function getMemberStoreOrderGoodsCountBak($storeIds,$memberIds){ public function getMemberStoreOrderGoodsCountBak($storeIds, $memberIds)
{
$this->setDb($this->dbName); $this->setDb($this->dbName);
$orderDao=\DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName); $orderDao = \DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName);
$whereOrder['store_id']=array('in',$storeIds); $whereOrder['store_id'] = array('in', $storeIds);
$whereOrder['buyer_id']=array('in',$memberIds); $whereOrder['buyer_id'] = array('in', $memberIds);
$whereOrder['order_state']=array('in',ArrayConst::orderCloseAndCancel); $whereOrder['order_state'] = array('in', ArrayConst::orderCloseAndCancel);
$orderIds=$orderDao->getFieldByWhere($whereOrder,'order_id'); $orderIds = $orderDao->getFieldByWhere($whereOrder, 'order_id');
$where['store_id']=array('in',$storeIds); $where['store_id'] = array('in', $storeIds);
$where['buyer_id']=array('in',$memberIds); $where['buyer_id'] = array('in', $memberIds);
$where['is_refund']=array('neq',ApiConst::refundSuccess); $where['is_refund'] = array('neq', ApiConst::refundSuccess);
if($orderIds){ if ($orderIds) {
$where['order_id']=array('notin',$orderIds); $where['order_id'] = array('notin', $orderIds);
} }
$where=$this->db->getSqlWhereByArray($where); $where = $this->db->getSqlWhereByArray($where);
$res=$this->db->from($this->_tableName)->select($this->sumGoodsNum)->where($where)->group("buyer_id")->group("store_id")->fetchAll(); $res = $this->db->from($this->_tableName)->select($this->sumGoodsNum)->where($where)->group("buyer_id")->group("store_id")->fetchAll();
return $res; return $res;
} }
public function convertRefundOrderGoods($orderGoods,$orderGoodsId){
$newOrderGoods=Array(); public function convertRefundOrderGoods($orderGoods, $orderGoodsId)
foreach($orderGoods as $orderGood){ {
if($orderGood['recId']==$orderGoodsId){ $newOrderGoods = Array();
array_push($newOrderGoods,$orderGood); foreach ($orderGoods as $orderGood) {
if ($orderGood['recId'] == $orderGoodsId) {
array_push($newOrderGoods, $orderGood);
} }
} }
return $newOrderGoods; return $newOrderGoods;
} }
/** /**
* 类实例 * 类实例
* *
...@@ -318,12 +369,11 @@ class OrderGoodsModel extends \DAO\AbstractModel { ...@@ -318,12 +369,11 @@ class OrderGoodsModel extends \DAO\AbstractModel {
private static $_instance = null; private static $_instance = null;
/** /**
* 单例模式获取类实例 * 单例模式获取类实例
* *
*/ */
public static function getInstance($dbName=DbNameConst::salveDBConnectName) public static function getInstance($dbName = DbNameConst::salveDBConnectName)
{ {
if (!(self::$_instance instanceof self)) { if (!(self::$_instance instanceof self)) {
self::$_instance = new self($dbName); self::$_instance = new self($dbName);
......
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