Commit 90bda454 authored by zhz's avatar zhz

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

parents 616f56ac a9be1560
......@@ -20,7 +20,7 @@ class Common
const endpointPre=SecretKeys::ossEndpointPre;
const buketPre=SecretKeys::ossBucket;
const buketPre=SecretKeys::ossBucketPre;
public static function getOssClientOnline(){
try {
......
......@@ -1133,7 +1133,9 @@ class OrderConfirmUtil {
return array('flag'=>\Our\ApiConst::zero,'errorCode'=>$errorCode,'data'=>$data);
}
$oldOrderPay = $orderPayModel->find(array('pay_sn'=>$paySn));
if($oldOrderPay['api_pay_state']==\Our\ApiConst::one){
\Our\Log::getInstance()->write(json_encode($oldOrderPay),'/data/log/apptest');
if($oldOrderPay['api_pay_state']==\Our\ApiConst::one){
\Our\Log::getInstance()->write('testaldeary','/data/log/apptest');
return array('flag'=>\Our\ApiConst::one,'errorCode'=>$errorCode);
}
$resultOrderPay = $orderPayModel->update(array('api_pay_state'=>\Our\ApiConst::one,'pay_type'=>$data['pay_type']),array('pay_sn'=>$paySn));
......
......@@ -82,6 +82,7 @@ class TencentPay {
$this->parameters['trade_type']= $this->tradeType;
//$this->parameters['openid']=$_SESSION['openid'];
//print_r($this->parameters);exit;
\Our\Log::getInstance()->write(json_encode($this->parameters),'/data/log/apptest');
$prepay_id = $this->getPrepayId();
$this->setPrepayId($prepay_id);
}
......
......@@ -12,7 +12,8 @@ class WxLitePay extends \Payment\TencentPay{
public function __construct()
{
$this->appid = \Our\PayConst::wxLiteAppId;
$this->notify_url = \Our\Common::getBaseUrl().\Our\PayConst::wxLiteNotifyUrl;
//$this->notify_url = \Our\Common::getBaseUrl().\Our\PayConst::wxLiteNotifyUrl;
$this->notify_url = \Our\NameConst::httpPrefix. $_SERVER['SERVER_NAME'] .\Our\PayConst::wxLiteNotifyUrl;
$this->mch_id = \Our\PayConst::wxPayMchId;
$this->key = \Our\PayConst::wxSPayKey;
$this->sslcert_path = \Our\PayConst::wxSslcertPath;
......
......@@ -41,6 +41,7 @@ class PaymentServiceModel extends \Business\AbstractModel{
* app微信支付回调
*/
public function updateOrderToPayed($channel = \Our\NameConst::wxAppChannel){
\Our\Log::getInstance()->write(microtime(),'/data/log/apptest');
if($channel == \Our\NameConst::wxLiteChannel){
$wxpay = \Payment\WxLitePay::getInstance();
$param['pay_type'] = \Our\ApiConst::wxLitePayType;
......@@ -57,6 +58,9 @@ class PaymentServiceModel extends \Business\AbstractModel{
$param['paySn'] = $callbackInfo['out_trade_no'];
$orderConfirmUtil = \Order\OrderConfirmUtil::getInstance();
$return = $orderConfirmUtil->updateOrderToPayed($param);
\Our\Log::getInstance()->write(json_encode($return),'/data/log/apptest');
\Our\Log::getInstance()->write(microtime(),'/data/log/apptest');
\Our\Log::getInstance()->write(json_encode($callbackInfo),'/data/log/apptest');
if($return['flag']) {
echo $callbackInfo['returnXml'];
die;
......
......@@ -14,6 +14,7 @@ use Our\ImageConst;
use Our\ImageUtil;
use Our\NameConst;
use Our\OrderConst;
use Zend\Validator\File\Count;
/**
* 店铺service
......@@ -441,8 +442,9 @@ class RefundServiceModel extends \Business\AbstractModel
//获取订单
$order_id = $refund['order_id'];
$order_info = $orderDao->find( array('order_id'=>$order_id));
$orderGoodsDao = \DAO\Order\OrderGoodsModel::getInstance(DbNameConst::masterDBConnectName);
$orderData['refund_amount']=$refundAmount;
$orderDao->updateByOrderId($orderData,$order_id);
$refund_array = array();
$refund_array['seller_time'] = time();
$refund_array['seller_state'] = $seller_state;//卖家处理状态:1为待审核,2为同意,3为不同意
......@@ -991,7 +993,9 @@ class RefundServiceModel extends \Business\AbstractModel
$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 = $orderGoodsDao->convertOrderGoods($orderGoodses, 'goodsId');
$allOrderGoods=$orderGoodses;
$goodsIds = $orderGoodsDao->getRefundOrderGoodsIds($orderGoodses);
$alreadyRefundGoodsIds=$goodsIds;
// $this->store=$storeDao->get($this->order['storeId']);
// $this->store=Common::convertUnderline($this->store[0]);
$this->store = \Our\RedisHelper::cachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$storeDao, 'getInfoById'), array($orderInfo['storeId'], $storeDao->detailField), \Our\ApiConst::sevenDaySecond,array($orderInfo['storeId']));
......@@ -1004,11 +1008,18 @@ class RefundServiceModel extends \Business\AbstractModel
ErrorModel::throwException(CodeConfigModel::notExistOrderGoods);
}
$shippingFee = ApiConst::zero;
if (count($orderGoods) == ApiConst::one) {
$shippingFee = $storeDao->isFee($orderInfo['storeId'], $orderInfo['shippingType'], $orderInfo['order_state']) ? $orderInfo['shippingFee'] : ApiConst::zero;
} else {
$allReadyGoodsCount=count($goodsIds);
$allGoodsCount=count($orderGoodses);
if($allReadyGoodsCount==$allGoodsCount){
$shippingFee = $storeDao->isFee($orderInfo['storeId'], $orderInfo['shippingType'], $orderInfo['orderState']) ? $orderInfo['shippingFee'] : ApiConst::zero;
}else{
$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);
$returnData = array(
......@@ -1031,6 +1042,12 @@ class RefundServiceModel extends \Business\AbstractModel
// if($orderInfo['shippingType']==ApiConst::bySelf){
$returnData['needShippingFee']=ApiConst::zero;
// }
//修改后的优惠金额
$discountAmount=$orderInfo['originAmount']- $orderInfo['orderAmount'];
$mustReduceAmount=ApiConst::zero;
if($discountAmount){
$mustReduceAmount=$orderGoodsDao->getMustReduceAmount($allOrderGoods,$discountAmount,$orderGoodsConvert);
}
if ($orderInfo['paymentTime']) {
$orderConfirmUtil = \Order\OrderConfirmUtil::getInstance();
......@@ -1039,20 +1056,38 @@ class RefundServiceModel extends \Business\AbstractModel
$refundCondition['storeCarts']['storeCarts'] = $cartDao->refundGoodsRemove($refundCondition['storeCarts']['storeCarts'], $goodsIds);
if (!empty($refundCondition['storeCarts']['storeCarts'])) {
$newTotalPrice = $orderConfirmUtil->reCalcOrderAmount($refundCondition['coupon'], $refundCondition['storeCarts']['storeCarts']);
$refundAmount = $orderInfo['orderAmount'] - $orderInfo['shippingFee'] - $newTotalPrice;
$refundAmount = $orderInfo['orderAmount'] - $newTotalPrice;
} else {
$refundAmount = $orderInfo['orderAmount'] - $orderInfo['shippingFee'] - ApiConst::zero;;
$refundAmount = $orderInfo['orderAmount'] - ApiConst::zero;;
}
}
} else {
// if(!$alreadyRefundGoodsIds){
// $refundAmount=$refundAmount-$discountAmount;
// }
//$refundAmount = $orderGoods['goodsPrice']*$orderGoods['goodsNum'];
$refundAmount =$orderInfo['orderAmount'];
} else {
$refundAmount = $orderGoods['goodsPrice']*$orderGoods['goodsNum'];
// if(!$alreadyRefundGoodsIds){
// $refundAmount=$refundAmount-$discountAmount;
// }
}
$refundAmount=$refundAmount-$mustReduceAmount;
if($orderInfo['shippingType']==ApiConst::bySeller){
if(!$shippingFee){
$refundAmount=$refundAmount+$orderInfo['shippingFee'];
}
}
$returnData['refundAmount'] = $refundAmount - $orderInfo['refundAmount'] - $returnData['needShippingFee'] + $shippingFee;
$liveMoney=$orderInfo['orderAmount']-$orderInfo['refundAmount'];
if($refundAmount>$liveMoney){
$refundAmount=$liveMoney;
}
// $returnData['refundAmount'] = $refundAmount - $orderInfo['refundAmount'] - $returnData['needShippingFee'] + $shippingFee;
$returnData['refundAmount'] = $refundAmount - $returnData['needShippingFee'];
if((int)$returnData['refundAmount'] <ApiConst::zero){
$returnData['refundAmount']=ApiConst::zero;
}
// if($orderGoods['goodsType']==ApiConst::goodsTypeFour){
// //已经退款过的金额
// $alreadyRefundMoney=$orderGoodsDao->getIsRefundMoney($orderGoodses,$orderGoods['promotionsId']);
......@@ -1108,6 +1143,8 @@ class RefundServiceModel extends \Business\AbstractModel
$orderDao = \DAO\Order\OrderModel::getInstance(DbNameConst::masterDBConnectName);
$orderInfo = $orderDao->findByMemberIdAndOrderId($memberId, $refund['orderId'], $this->orderField);
$storeDao=\DAO\StoreModel::getInstance();
$orderDao->setDb(DbNameConst::masterDBConnectName);
$orderDao->db->doTransaction();
if($refund['refundType']==ApiConst::refundTypeGoods){
$refund['refundAmount']-=$orderInfo['needShippingFee'];
}
......@@ -1184,15 +1221,22 @@ class RefundServiceModel extends \Business\AbstractModel
$refundArray['refund_shipping_type']=isset($refund['refundShippingType'])?$refund['refundShippingType']:ApiConst::zero;
$refundArrayUnLine=Common::convertUnderline($refundArray);
$state = $refundReturnDao->addRefundReturn($refundArray,$orderInfo,$orderGoods);
$updateOrderData['refund_amount']= $refundArray['refund_amount'];
$orderDao->deleteOrderCache($memberId,$orderInfo['orderId'],$orderInfo['storeId'],true);
$storeDao->deleteStoreCache($orderInfo['storeId'],$orderInfo['orderId']);
$storeDao->deleteStoreRefundCache($orderInfo['storeId'],$orderInfo['orderId']);
if ($state) {
$orderDao->update(array('order_id'=>$orderInfo['orderId']),$updateOrderData);
$refundStateName=$refundReturnDao->getRefundTextStatus($refundArrayUnLine);
$orderGoodsDao->update(array('rec_id'=>$orderGoods['recId']),array('refund_state_name'=>$refundStateName,'refund_id'=>$state));
$refundReturnDao->deleteRefundCache($memberId);
$storeDao->deleteStoreRefundCache($refundOne['storeId']);
$orderLogDao->addRefundOrderLog($orderInfo['orderId'],$refundArray['refund_type'],DescribeConst::buyer,$orderInfo['buyerName'],$orderInfo['orderState']);
if ($orderInfo['orderState'] == ApiConst::orderStateWaitRecieve) {
$orderDao->editOrderLock($orderInfo['orderId']);
}
$orderDao->db->doCommit();
$push=\Our\Push::getInstance();
$pushData=array('storeId'=>$orderInfo['storeId'],
'type'=>ApiConst::messageRefund,
......@@ -1211,11 +1255,10 @@ class RefundServiceModel extends \Business\AbstractModel
$push->sendTcpMessage();
//\Our\RedisHelper::rpush('client_push',array('storeId'=>$refund['storeId'],'type'=>ApiConst::messageRefundProccessing,'op'=>NameConst::reduce,'num'=>ApiConst::one,'params'=>array('c'=>'shopkeeper','m'=>'getRefundDetail','refundId'=>$refund['refundId'])));
if ($orderInfo['orderState'] == ApiConst::orderStateWaitRecieve) {
$orderDao->editOrderLock($orderInfo['orderId']);
}
return $state;
} else {
$orderDao->db->doRollback();
ErrorModel::throwException(CodeConfigModel::refundRefuseByStore);
}
}
......
......@@ -488,7 +488,11 @@ class ShopkeeperServiceModel extends \Business\AbstractModel
ErrorModel::throwException(CodeConfigModel::emptyStoreId);
}
$diliveryMan = \DAO\Order\DiliverymanModel::getInstance();
return \Our\RedisHelper::cachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$diliveryMan, 'getDeliveryManByStoreId'), array($storeId), \Our\ApiConst::oneHourCache, array($storeId));
$diliveryMans=\Our\RedisHelper::cachedFunction(\Redis\Db5\OrderRedisModel::getInstance(), array(&$diliveryMan, 'getDeliveryManByStoreId'), array($storeId), \Our\ApiConst::oneHourCache, array($storeId));
foreach($diliveryMans as &$dilivery){
$dilivery['memberAvatar']=$memberDao->getMemberAvatar($dilivery['memberId']);
}
return $diliveryMans;
}
public function confirmReceivePayment($memberId,$orderId){
......
......@@ -45,7 +45,7 @@ class OrderModel extends \DAO\AbstractModel
public function getOrderDetailField()
{
return 'order_id as orderId,coupon_id as couponId,refund_amount as refundAmount,order_sn as orderSn,pay_sn as paySn,store_name as storeName,add_time as addTime,store_id as storeId,goods_amount as goodsAmount,shipping_fee as shippingFee,order_amount as orderAmount,shipping_type as shippingType,payment_type as paymentType,order_state as orderState,shipping_fee as shippingFee,refund_state as refundState,order_type as orderType,is_receive_payment as isReceivePayment,payment_time as paymentTime,finnshed_time as finnshedTime,need_shipping_fee as needShippingFee,payment_code as paymentCode,buyer_id as buyerId,buyer_name as buyerName,refund_condition as refundCondition,delay_time as delayTime,gmt_update as gmtUpdate,diliveryman_id as diliverymanId,shipping_arrival_time as shippingArrivalTime,delivery_time as deliveryTime,order_note as orderNote,send_time as sendTime';
return 'order_id as orderId,coupon_id as couponId,refund_amount as refundAmount,origin_amount as originAmount,order_sn as orderSn,pay_sn as paySn,store_name as storeName,add_time as addTime,store_id as storeId,goods_amount as goodsAmount,shipping_fee as shippingFee,order_amount as orderAmount,shipping_type as shippingType,payment_type as paymentType,order_state as orderState,shipping_fee as shippingFee,refund_state as refundState,order_type as orderType,is_receive_payment as isReceivePayment,payment_time as paymentTime,finnshed_time as finnshedTime,need_shipping_fee as needShippingFee,payment_code as paymentCode,buyer_id as buyerId,buyer_name as buyerName,refund_condition as refundCondition,delay_time as delayTime,gmt_update as gmtUpdate,diliveryman_id as diliverymanId,shipping_arrival_time as shippingArrivalTime,delivery_time as deliveryTime,order_note as orderNote,send_time as sendTime';
}
public function getOrderShippingField()
......
<?php
namespace DAO\Order;
use Our\ApiConst;
use Our\ArrayConst;
use Our\Common;
......@@ -9,7 +10,8 @@ use Our\ImageConst;
use Our\ImageUtil;
class OrderGoodsModel extends \DAO\AbstractModel {
class OrderGoodsModel extends \DAO\AbstractModel
{
/**
......@@ -18,9 +20,9 @@ class OrderGoodsModel extends \DAO\AbstractModel {
* @var string
*/
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 $groupField=array('buyer_id','store_id');
public $sumGoodsNum=' store_id as storeId,buyer_id as buyerId,sum(goods_num) as orderGoodsCount';
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 $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";
/**
* 主键
......@@ -29,192 +31,232 @@ class OrderGoodsModel extends \DAO\AbstractModel {
*/
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();
if($limit){
return $this->db->from($this->_tableName)->select($field)->where($where)->group($group)->limit($limit[0],$limit[1])->fetchAll();
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)->fetchAll();
}
/**
* 更新数据
* @param $data
* @param $where
* @return mixed
*/
public function update($where, $data){
public function update($where, $data)
{
$this->setDb(DbNameConst::masterDBConnectName);
$data['gmt_update']=TIMESTAMP;
$data['gmt_update'] = TIMESTAMP;
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);
$list = $this->db->select($field)->from($this->_tableName)->where($where)->fetchAll();
return $list;
}
public function getOrderGoodsCountByStoreId($storeId){
public function getOrderGoodsCountByStoreId($storeId)
{
$this->setDb($this->dbName);
$orderDao=\DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName);
$where['store_id']=$storeId;
$where['is_refund']=array('neq',ApiConst::refundSuccess);
$whereOrder['store_id']=array('eq',$storeId);
$whereOrder['order_state']=array('in',ArrayConst::orderCloseAndCancel);
$orderIds=$orderDao->getFieldByWhere($whereOrder,'order_id');
if($orderIds){
$where['order_id']=array('notin',$orderIds);
$orderDao = \DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName);
$where['store_id'] = $storeId;
$where['is_refund'] = array('neq', ApiConst::refundSuccess);
$whereOrder['store_id'] = array('eq', $storeId);
$whereOrder['order_state'] = array('in', ArrayConst::orderCloseAndCancel);
$orderIds = $orderDao->getFieldByWhere($whereOrder, 'order_id');
if ($orderIds) {
$where['order_id'] = array('notin', $orderIds);
}
if(is_array($where)){
$where=$this->db->getSqlWhereByArray($where);
if (is_array($where)) {
$where = $this->db->getSqlWhereByArray($where);
}
$goodsCount = $this->db->select($this->orderGoodsGoodsNumCountField)->from($this->_tableName)->where($where)->fetchValue();
return (int)$goodsCount;
}
/**
* 获取单条数据
* @param $where
* @return array
*/
public function find($where,$field='*',$db=DbNameConst::salveDBConnectName) {
public function find($where, $field = '*', $db = DbNameConst::salveDBConnectName)
{
$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;
}
/**
* 根据订单id 和商品id 获得订单商品记录
* @param $where
* @return array
*/
public function getOneByOrderIdAndGoodsId($orderId,$goodsId,$field='*'){
$where['order_id']=$orderId;
$where['goods_id']=$goodsId;
$res=$this->find($where,$field);
public function getOneByOrderIdAndGoodsId($orderId, $goodsId, $field = '*')
{
$where['order_id'] = $orderId;
$where['goods_id'] = $goodsId;
$res = $this->find($where, $field);
return $res;
}
public function findByRecId($RecId,$field='*'){
$where['rec_id']=$RecId;
return $this->find($where,$field);
public function findByRecId($RecId, $field = '*')
{
$where['rec_id'] = $RecId;
return $this->find($where, $field);
}
/**
* 根据订单id 获得订单商品记录
* @param $where
* @return array
*/
public function getOrderGoodsByOrderIds($orderIds,$field='*'){
if(is_array($orderIds)){
$where=Common::format(" order_id in ({0})",implode(',',$orderIds));
}else{
$where['order_id']=$orderIds;
public function getOrderGoodsByOrderIds($orderIds, $field = '*')
{
if (is_array($orderIds)) {
$where = Common::format(" order_id in ({0})", implode(',', $orderIds));
} else {
$where['order_id'] = $orderIds;
}
return $this->getOrderGoods($where,$field);
return $this->getOrderGoods($where, $field);
}
public function deleteOrderGoodsCache($memberId,$orderIds,$storeId=false){
if($memberId){
// return \Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::get:Instance(), array(&$this, 'getOrderGoodsByOrderIds'), 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));
public function deleteOrderGoodsCache($memberId, $orderIds, $storeId = false)
{
if ($memberId) {
// return \Our\RedisHelper::delCachedFunction(\Redis\Db5\OrderRedisModel::get:Instance(), array(&$this, 'getOrderGoodsByOrderIds'), 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));
\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)){
// 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));
if (!empty($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));
}
return true;
}
public function getIsRefundMoney($orderGoodses,$promotionsId){
$isRefundMoney=ApiConst::zero;
foreach($orderGoodses as $orderGood){
if($orderGood['promotionsId']=$promotionsId){
$isRefundMoney+=$orderGood['goodsPrice'];
public function getIsRefundMoney($orderGoodses, $promotionsId)
{
$isRefundMoney = ApiConst::zero;
foreach ($orderGoodses as $orderGood) {
if ($orderGood['promotionsId'] = $promotionsId) {
$isRefundMoney += $orderGood['goodsPrice'];
}
}
return $isRefundMoney;
}
//转换数组
public function convertOrderGoods($orderGoodses,$key='rec_id'){
$convertOrderGoods=array();
foreach($orderGoodses as $orderGoods){
$convertOrderGoods[$orderGoods[$key]]=$orderGoods;
public function convertOrderGoods($orderGoodses, $key = 'rec_id')
{
$convertOrderGoods = array();
foreach ($orderGoodses as $orderGoods) {
$convertOrderGoods[$orderGoods[$key]] = $orderGoods;
}
return $convertOrderGoods;
}
//获得已经退款退货的商品id
public function getRefundOrderGoodsIds($orderGoods){
$newOrderGoods=array();
$orderGoods=array_values($orderGoods);
for($i=ApiConst::zero;$i<count($orderGoods);$i++){
if($orderGoods[$i]['refundId']!=ApiConst::zero){
array_push($newOrderGoods,$orderGoods);
// unset($orderGoods[$i]);
public function getRefundOrderGoodsIds($orderGoods)
{
$newOrderGoods = array();
$orderGoods = array_values($orderGoods);
for ($i = ApiConst::zero; $i < count($orderGoods); $i++) {
if ($orderGoods[$i]['refundId'] != ApiConst::zero) {
array_push($newOrderGoods, $orderGoods);
// unset($orderGoods[$i]);
}
}
return array_column($newOrderGoods,'goodsId');
$goodsIds = array_column($newOrderGoods, 'goodsId');
return $goodsIds;
}
/**
* 根据订单id 获得订单商品记录
* @param $where
* @return array
*/
public function getOrderGoodsByRecIds($recIds,$field='*'){
if(is_array($recIds)){
$where=Common::format(" rec_id in ({0})",implode(',',$recIds));
}else{
$where['rec_id']=$recIds;
public function getOrderGoodsByRecIds($recIds, $field = '*')
{
if (is_array($recIds)) {
$where = Common::format(" rec_id in ({0})", implode(',', $recIds));
} else {
$where['rec_id'] = $recIds;
}
return $this->getOrderGoods($where,$field);
return $this->getOrderGoods($where, $field);
}
//更具订单id获取商品的单挑信息
public function getOneByOrderId($orderId,$field='*'){
$this->setDb(DbNameConst::salveDBConnectName);
$where['order_id']=$orderId;
return $this->db->from($this->_tableName)->where($where)->select($field)->fetchOne();
}
public function getOneByOrderId($orderId, $field = '*')
{
$this->setDb(DbNameConst::salveDBConnectName);
$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'));
}
public function getRefundOrderGoods($orderGoods){
return array(
'goodsId'=>$orderGoods['goodsId'],
'goodsName'=>$orderGoods['goodsName'],
'goodsPrice'=>$orderGoods['goodsPrice'],
'goodsNum'=>$orderGoods['goodsNum'],
'goodsImage'=>ImageUtil::getGoodsImgUrl($orderGoods['goodsImage'],ApiConst::goodsSmallSize),
'goodsPayPrice'=>$orderGoods['goodsPayPrice'],
public function getRefundOrderGoods($orderGoods)
{
return array(
'goodsId' => $orderGoods['goodsId'],
'goodsName' => $orderGoods['goodsName'],
'goodsPrice' => $orderGoods['goodsPrice'],
'goodsNum' => $orderGoods['goodsNum'],
'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;
$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);
$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";
$insertAllSql = $baseSql;
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;
if ($i % 1000 == 0 && $i != 0) {
$insertAllSql = rtrim($insertAllSql, ',');
......@@ -238,30 +280,36 @@ class OrderGoodsModel extends \DAO\AbstractModel {
}
return true;
}
public function getMemberStoreStaticsByCreateTime($gmtCreate,$pageIndex,$pageSize){
public function getMemberStoreStaticsByCreateTime($gmtCreate, $pageIndex, $pageSize)
{
$this->setDb($this->dbName);
$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);
return $res['list']?$res:false;
$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);
return $res['list'] ? $res : false;
}
public function getMemberStoreOrderGoodsCount($storeIds,$memberIds){
public function getMemberStoreOrderGoodsCount($storeIds, $memberIds)
{
$this->setDb($this->dbName);
$where['store_id']=array('in',$storeIds);
$where['buyer_id']=array('in',$memberIds);
$where=$this->db->getSqlWhereByArray($where);
$res=$this->db->from($this->_tableName)->select($this->sumGoodsNum)->where($where)->group("buyer_id")->group("store_id")->fetchAll();
$where['store_id'] = array('in', $storeIds);
$where['buyer_id'] = array('in', $memberIds);
$where = $this->db->getSqlWhereByArray($where);
$res = $this->db->from($this->_tableName)->select($this->sumGoodsNum)->where($where)->group("buyer_id")->group("store_id")->fetchAll();
return $res;
}
public function getOrderGoodsCountBuyStoreIdAndMemberId($storeId,$memberId=false){
public function getOrderGoodsCountBuyStoreIdAndMemberId($storeId, $memberId = false)
{
$this->setDb($this->dbName);
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");
}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");
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");
} 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");
}
$res=$this->db->from($this->_tableName)->query($selectSql);
return $res->one?$res->one:array();
$res = $this->db->from($this->_tableName)->query($selectSql);
return $res->one ? $res->one : array();
}
// public function getMemberStoreOrderGoodsCount($storeIds,$memberIds){
......@@ -282,33 +330,37 @@ class OrderGoodsModel extends \DAO\AbstractModel {
// return $res;
//
// }
public function getMemberStoreOrderGoodsCountBak($storeIds,$memberIds){
public function getMemberStoreOrderGoodsCountBak($storeIds, $memberIds)
{
$this->setDb($this->dbName);
$orderDao=\DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName);
$whereOrder['store_id']=array('in',$storeIds);
$whereOrder['buyer_id']=array('in',$memberIds);
$whereOrder['order_state']=array('in',ArrayConst::orderCloseAndCancel);
$orderIds=$orderDao->getFieldByWhere($whereOrder,'order_id');
$where['store_id']=array('in',$storeIds);
$where['buyer_id']=array('in',$memberIds);
$where['is_refund']=array('neq',ApiConst::refundSuccess);
if($orderIds){
$where['order_id']=array('notin',$orderIds);
$orderDao = \DAO\Order\OrderModel::getInstance(DbNameConst::salveDBConnectName);
$whereOrder['store_id'] = array('in', $storeIds);
$whereOrder['buyer_id'] = array('in', $memberIds);
$whereOrder['order_state'] = array('in', ArrayConst::orderCloseAndCancel);
$orderIds = $orderDao->getFieldByWhere($whereOrder, 'order_id');
$where['store_id'] = array('in', $storeIds);
$where['buyer_id'] = array('in', $memberIds);
$where['is_refund'] = array('neq', ApiConst::refundSuccess);
if ($orderIds) {
$where['order_id'] = array('notin', $orderIds);
}
$where=$this->db->getSqlWhereByArray($where);
$res=$this->db->from($this->_tableName)->select($this->sumGoodsNum)->where($where)->group("buyer_id")->group("store_id")->fetchAll();
$where = $this->db->getSqlWhereByArray($where);
$res = $this->db->from($this->_tableName)->select($this->sumGoodsNum)->where($where)->group("buyer_id")->group("store_id")->fetchAll();
return $res;
}
public function convertRefundOrderGoods($orderGoods,$orderGoodsId){
$newOrderGoods=Array();
foreach($orderGoods as $orderGood){
if($orderGood['recId']==$orderGoodsId){
array_push($newOrderGoods,$orderGood);
public function convertRefundOrderGoods($orderGoods, $orderGoodsId)
{
$newOrderGoods = Array();
foreach ($orderGoods as $orderGood) {
if ($orderGood['recId'] == $orderGoodsId) {
array_push($newOrderGoods, $orderGood);
}
}
return $newOrderGoods;
}
/**
* 类实例
*
......@@ -317,12 +369,11 @@ class OrderGoodsModel extends \DAO\AbstractModel {
private static $_instance = null;
/**
* 单例模式获取类实例
*
*/
public static function getInstance($dbName=DbNameConst::salveDBConnectName)
public static function getInstance($dbName = DbNameConst::salveDBConnectName)
{
if (!(self::$_instance instanceof self)) {
self::$_instance = new self($dbName);
......
......@@ -208,7 +208,8 @@ class StoreModel extends \DAO\AbstractModel
public function isChargeGet($storeId)
{
$isChargeGet = $this->getInfoById($storeId, 'is_charge_get');
return $isChargeGet > ApiConst::zero ? TRUE : FALSE;
return $isChargeGet['is_charge_get'] > ApiConst::zero ? TRUE : FALSE;
}
//线上支付订单已接单待发货退款是否收取服务费(0:否 1:是)
......
......@@ -303,7 +303,7 @@ class ShopkeeperController extends \Our\Controller_AbstractClient {
ErrorModel::throwException(CodeConfigModel::notExistRefund);
}
$refundService=\Business\Order\RefundServiceModel::getInstance();
$goodsState= intval($this->req['data']['goodsState']);
$goodsState=isset($this->req['data']['goodsState'])?intval($this->req['data']['goodsState']):\Our\ApiConst::goodsStateRecieved;
$res = $refundService->receive($this->storeId, $this->sellerId, $this->sellerName, $refundId, $goodsState);
if($res){
$this->success($res);
......
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