public static function ucenter_order()
 {
     $siteConfig = new Config('site_config');
     $order_cancel_time = $siteConfig->order_cancel_time !== "" ? intval($siteConfig->order_cancel_time) : 7;
     $order_finish_time = $siteConfig->order_finish_time !== "" ? intval($siteConfig->order_finish_time) : 20;
     $orderModel = new IModel('order');
     $orderCancelData = $order_cancel_time >= 0 ? $orderModel->query(" if_del = 0 and pay_type != 0 and status in(1) and datediff(NOW(),create_time) >= {$order_cancel_time} ", "id,order_no,4 as type_data") : array();
     $orderCreateData = $order_finish_time >= 0 ? $orderModel->query(" if_del = 0 and distribution_status = 1 and status in(1,2) and datediff(NOW(),send_time) >= {$order_finish_time} ", "id,order_no,5 as type_data") : array();
     $resultData = array_merge($orderCreateData, $orderCancelData);
     if ($resultData) {
         foreach ($resultData as $key => $val) {
             $type = $val['type_data'];
             $order_id = $val['id'];
             $order_no = $val['order_no'];
             //oerder表的对象
             $tb_order = new IModel('order');
             $tb_order->setData(array('status' => $type, 'completion_time' => ITime::getDateTime()));
             $tb_order->update('id=' . $order_id);
             //生成订单日志
             $tb_order_log = new IModel('order_log');
             //订单自动完成
             if ($type == '5') {
                 $action = '完成';
                 $note = '订单【' . $order_no . '】完成成功';
                 //完成订单并且进行支付
                 Order_Class::updateOrderStatus($order_no);
                 //增加用户评论商品机会
                 Order_Class::addGoodsCommentChange($order_id);
                 $logObj = new log('db');
                 $logObj->write('operation', array("系统自动", "订单更新为完成", '订单号:' . $order_no));
             } else {
                 $action = '作废';
                 $note = '订单【' . $order_no . '】作废成功';
                 //订单重置取消
                 Order_class::resetOrderProp($order_id);
                 $logObj = new log('db');
                 $logObj->write('operation', array("系统自动", "订单更新为作废", '订单号:' . $order_no));
             }
             $tb_order_log->setData(array('order_id' => $order_id, 'user' => "系统自动", 'action' => $action, 'result' => '成功', 'note' => $note, 'addtime' => ITime::getDateTime()));
             $tb_order_log->add();
         }
     }
 }
Exemple #2
0
 /**
  * @brief 订单退款操作
  * @param int $refundId 退款单ID
  * @param int $authorId 操作人ID
  * @param string $type admin:管理员;seller:商家
  * @param int $isNotBalance 是否充值到余额, 0:退款余额; 1:不退款到余额
  * @return
  */
 public static function refund($refundId, $authorId, $type = 'admin', $isNotBalance = 0)
 {
     $orderGoodsDB = new IModel('order_goods');
     $refundDB = new IModel('refundment_doc');
     //获取goods_id和product_id用于给用户减积分,经验
     $refundsRow = $refundDB->getObj('id = ' . $refundId);
     $order_id = $refundsRow['order_id'];
     $order_no = $refundsRow['order_no'];
     $user_id = $refundsRow['user_id'];
     $orderGoodsRow = $orderGoodsDB->getObj('order_id = ' . $order_id . ' and goods_id = ' . $refundsRow['goods_id'] . ' and product_id = ' . $refundsRow['product_id'] . ' and is_send != 2');
     if (!$orderGoodsRow) {
         return false;
     }
     $order_goods_id = $orderGoodsRow['id'];
     //如果管理员(商家)自定义了退款金额。否则就使用默认的付款商品金额
     $amount = $refundsRow['amount'] > 0 ? $refundsRow['amount'] : $orderGoodsRow['goods_nums'] * $orderGoodsRow['real_price'];
     //库存增加
     self::updateStore($order_goods_id, 'add');
     //更新退款状态
     $orderGoodsDB->setData(array('is_send' => 2));
     $orderGoodsDB->update('id = ' . $order_goods_id);
     //更新order表状态
     $isSendData = $orderGoodsDB->getObj('order_id = ' . $order_id . ' and is_send != 2');
     $orderStatus = 6;
     //全部退款
     if ($isSendData) {
         $orderStatus = 7;
         //部分退款
     }
     $tb_order = new IModel('order');
     $tb_order->setData(array('status' => $orderStatus));
     $tb_order->update('id=' . $order_id);
     /**
      * 进行用户的余额增加操作,积分,经验的减少操作,
      * 1,当全部退款时候,减少订单中记录的积分和经验;且如果没有发货的商品直接退回订单中的运费,报价,税金等
      * 2,当部分退款时候,查询商品表中积分和经验
      */
     if ($orderStatus == 6) {
         Order_class::resetOrderProp($order_id);
         $orderRow = $tb_order->getObj('id = ' . $order_id);
         //是否返还运费,报价,税金
         $isDeliveryData = $orderGoodsDB->getObj('order_id = ' . $order_id . ' and delivery_id > 0');
         if (!$isDeliveryData) {
             $amount += $orderRow['real_freight'] + $orderRow['insured'] + $orderRow['taxes'];
         }
     }
     //退款积分,经验
     $goodsDB = new IModel('goods');
     $goodsRow = $goodsDB->getObj('id = ' . $orderGoodsRow['goods_id']);
     $orderRow = array('exp' => $goodsRow['exp'] * $orderGoodsRow['goods_nums'], 'point' => $goodsRow['point'] * $orderGoodsRow['goods_nums'], 'order_no' => $order_no);
     //更新退款表
     $updateData = array('amount' => $amount, 'pay_status' => 2, 'dispose_time' => ITime::getDateTime());
     $refundDB->setData($updateData);
     $refundDB->update('id = ' . $refundId);
     //更新用户的信息
     $obj = new IModel('member');
     $memberObj = $obj->getObj('user_id = ' . $user_id, 'exp,point');
     $exp = $memberObj['exp'] - $orderRow['exp'];
     $obj->setData(array('exp' => $exp <= 0 ? 0 : $exp));
     $obj->update('user_id = ' . $user_id);
     //积分记录日志
     $pointConfig = array('user_id' => $user_id, 'point' => '-' . $orderRow['point'], 'log' => '退款订单号:' . $orderRow['order_no'] . '中的商品,减掉积分 -' . $orderRow['point']);
     $pointObj = new Point();
     $pointObj->update($pointConfig);
     //用户余额进行的操作记入account_log表
     $log = new AccountLog();
     $config = array('user_id' => $user_id, 'event' => 'drawback', 'num' => $amount, 'order_no' => $order_no);
     if ($type == 'admin') {
         $config['admin_id'] = $authorId;
         $adminObj = new IModel('admin');
         $adminRow = $adminObj->getObj('id = ' . $authorId);
         $authorName = $adminRow['admin_name'];
     } else {
         if ($type == 'seller') {
             $config['seller_id'] = $authorId;
             $sellerObj = new IModel('seller');
             $sellerRow = $sellerObj->getObj('id = ' . $authorId);
             $authorName = $sellerRow['seller_name'];
         }
     }
     //生成订单日志
     $tb_order_log = new IModel('order_log');
     $tb_order_log->setData(array('order_id' => $order_id, 'user' => $authorName, 'action' => '退款', 'result' => '成功', 'note' => '订单【' . $order_no . '】退款,退款金额:¥' . $amount, 'addtime' => ITime::getDateTime()));
     $tb_order_log->add();
     return $isNotBalance == 0 ? $log->write($config) : true;
 }
 /**
  * @brief 订单删除功能_删除回收站中的数据,彻底删除
  */
 public function order_recycle_del()
 {
     //post数据
     $id = IFilter::act(IReq::get('id'), 'int');
     //生成order对象
     $tb_order = new IModel('order');
     if ($id) {
         $id = is_array($id) ? join(',', $id) : $id;
         Order_class::resetOrderProp($id);
         //删除订单
         $tb_order->del('id in (' . $id . ')');
         //记录日志
         $logObj = new log('db');
         $logObj->write('operation', array("管理员:" . ISafe::get('admin_name'), "删除回收站中退货单", '退货单ID:' . $id));
         $this->redirect('order_recycle_list');
     } else {
         $this->redirect('order_recycle_list', false);
         Util::showMessage('请选择要删除的数据');
     }
 }
Exemple #4
0
 /**
  * @brief 订单退款操作
  * @param int $refundId 退款单ID
  * @param int $authorId 操作人ID
  * @param string $type admin:管理员;seller:商家
  * @return
  */
 public static function refund($refundId, $authorId, $type = 'admin')
 {
     $orderGoodsDB = new IModel('order_goods');
     $refundDB = new IModel('refundment_doc');
     //更新退款表
     $updateData = array('pay_status' => 2, 'dispose_time' => ITime::getDateTime());
     $refundDB->setData($updateData);
     $refundDB->update('id = ' . $refundId);
     //获取goods_id和product_id用于给用户减积分,经验
     $refundsRow = $refundDB->getObj('id = ' . $refundId);
     $order_id = $refundsRow['order_id'];
     $order_no = $refundsRow['order_no'];
     $amount = $refundsRow['amount'];
     $user_id = $refundsRow['user_id'];
     $orderGoodsRow = $orderGoodsDB->getObj('order_id = ' . $order_id . ' and goods_id = ' . $refundsRow['goods_id'] . ' and product_id = ' . $refundsRow['product_id']);
     $order_goods_id = $orderGoodsRow['id'];
     //更新退款状态
     $orderGoodsDB->setData(array('is_send' => 2));
     $orderGoodsDB->update('id = ' . $order_goods_id);
     //更新order表状态
     $isSendData = $orderGoodsDB->getObj('order_id = ' . $order_id . ' and is_send != 2');
     $orderStatus = 6;
     //全部退款
     if ($isSendData) {
         $orderStatus = 7;
         //部分退款
     }
     $tb_order = new IModel('order');
     $tb_order->setData(array('status' => $orderStatus));
     $tb_order->update('id=' . $order_id);
     if ($orderStatus == 6) {
         Order_class::resetOrderProp($order_id);
     }
     //生成订单日志
     $authorName = $type == 'admin' ? ISafe::get('admin_name') : ISafe::get('seller_name');
     $tb_order_log = new IModel('order_log');
     $tb_order_log->setData(array('order_id' => $order_id, 'user' => $authorName, 'action' => '退款', 'result' => '成功', 'note' => '订单【' . $order_no . '】退款,退款金额:¥' . $amount, 'addtime' => ITime::getDateTime()));
     $tb_order_log->add();
     /**
      * 进行用户的余额增加操作,积分,经验的减少操作,
      * 1,当全部退款时候,减少订单中记录的积分和经验;
      * 2,当部分退款时候,查询商品表中积分和经验
      */
     if ($orderStatus == 6) {
         $orderRow = $tb_order->getObj('id = ' . $order_id);
     } else {
         $goodsDB = new IModel('goods');
         $goodsRow = $goodsDB->getObj('id = ' . $orderGoodsRow['goods_id']);
         $orderRow = array('exp' => $goodsRow['exp'], 'point' => $goodsRow['point'], 'order_no' => $order_no);
     }
     $obj = new IModel('member');
     $memberObj = $obj->getObj('user_id = ' . $user_id, 'balance,exp,point');
     $exp = $memberObj['exp'] - $orderRow['exp'];
     $balance = $memberObj['balance'] + $amount;
     $obj->setData(array('balance' => $balance, 'exp' => $exp <= 0 ? 0 : $exp));
     $isSuccess = $obj->update('user_id = ' . $user_id);
     //积分记录日志
     $pointConfig = array('user_id' => $user_id, 'point' => '-' . $orderRow['point'], 'log' => '退款订单号:' . $orderRow['order_no'] . '中的商品,减掉积分 -' . $orderRow['point']);
     $pointObj = new Point();
     $pointObj->update($pointConfig);
     if ($isSuccess) {
         //用户余额进行的操作记入account_log表
         $log = new AccountLog();
         $config = array('user_id' => $user_id, 'event' => 'drawback', 'num' => $amount, 'order_no' => $order_no);
         if ($type == 'admin') {
             $config['admin_id'] = $authorId;
         } else {
             if ($type == 'seller') {
                 $config['seller_id'] = $authorId;
             }
         }
         $re = $log->write($config);
         return true;
     }
     return false;
 }