123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types = 1);
- namespace app\console\model;
- use app\common\enum\order\DeliveryStatus;
- use app\common\enum\order\ReceiptStatus;
- use app\common\model\Order as OrderModel;
- use app\console\model\OrderGoods as OrderGoodsModel;
- use app\common\enum\order\PayStatus as PayStatusEnum;
- use app\common\enum\order\OrderStatus as OrderStatusEnum;
- use app\common\enum\order\HxStatus as HxStatusEnum;
- use app\common\enum\order\DeliveryType as DeliveryTypeEnum;
- /**
- * 订单模型
- * Class Order
- * @package app\common\model
- */
- class Order extends OrderModel
- {
- /**
- * 获取订单列表
- * @param int $storeId 商城ID
- * @param array $filter
- * @param array $with
- * @return \think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getList(int $storeId, $filter = [], $with = [])
- {
- return $this->with($with)
- ->where($filter)
- ->where('store_id', '=', $storeId)
- ->where('is_delete', '=', 0)
- ->select();
- }
- /**
- * 获取订单ID集
- * @param int $storeId 商城ID
- * @param array $filter
- * @return array
- */
- public function getOrderIds(int $storeId, $filter = [])
- {
- return $this->where($filter)
- ->where('store_id', '=', $storeId)
- ->where('is_delete', '=', 0)
- ->column('order_id');
- }
- /**
- * 查询截止时间未支付的订单列表
- * @param int $storeId 商城ID
- * @param int $deadlineTime 截止日期的时间戳
- * @return \think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getListByClose(int $storeId, int $deadlineTime)
- {
- // 查询条件
- $filter = [
- ['pay_status', '=', PayStatusEnum::PENDING],
- ['order_status', '=', OrderStatusEnum::NORMAL],
- ['create_time', '<=', $deadlineTime],
- ];
- // 查询列表记录
- return $this->getList($storeId, $filter, ['goods', 'user']);
- }
- /**
- * 查询截止时间未自提的订单列表
- * @param int $storeId 商城ID
- * @param int $deadlineTime 截止日期的时间戳
- * @return \think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getListByUnPickup(int $storeId, int $deadlineTime)
- {
- // 查询条件
- $filter = [
- ['pay_status', '=', PayStatusEnum::SUCCESS], // 已支付
- ['order_status', '=', OrderStatusEnum::NORMAL],
- ['delivery_type', '=', DeliveryTypeEnum::SHOPS_DELIVERY], // 门店自提
- ['hx_status', '=', HxStatusEnum::PENDING], // 未核销
- ['create_time', '<=', $deadlineTime],
- ];
- // 查询列表记录
- return $this->getList($storeId, $filter, ['goods', 'user']);
- }
- /**
- * 查询截止时间已完成的订单列表
- * @param int $storeId 商城ID
- * @param array $orderIds 订单ID集
- * @return \think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getListByOrderIds(int $storeId, array $orderIds)
- {
- // 查询条件
- $filter = [['order_id', 'in', $orderIds]];
- // 查询列表记录
- return $this->getList($storeId, $filter, ['goods' => ['refund']]);
- }
- /**
- * 查询截止时间未确认收货的订单ID集
- * @param int $storeId 商城ID
- * @param int $deadlineTime 截止时间
- * @return array
- */
- public function getOrderIdsByReceive(int $storeId, int $deadlineTime)
- {
- // 查询条件
- $filter = [
- ['pay_status', '=', PayStatusEnum::SUCCESS],
- ['delivery_status', '=', DeliveryStatus::DELIVERED],
- ['receipt_status', '=', ReceiptStatus::NOT_RECEIVED],
- ['delivery_time', '<=', $deadlineTime]
- ];
- // 查询列表记录
- return $this->getOrderIds($storeId, $filter);
- }
- /**
- * 查询截止时间确认收货的订单列表
- * @param int $storeId 商城ID
- * @param int $deadlineTime 截止时间
- * @return \think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getOrderListBySettled(int $storeId, int $deadlineTime)
- {
- // 查询条件
- $filter = [
- ['order_status', '=', OrderStatusEnum::COMPLETED],
- ['receipt_time', '<=', $deadlineTime],
- ['is_settled', '=', 0]
- ];
- // 查询列表记录
- return $this->getList($storeId, $filter, ['goods.refund']);
- }
- /**
- * 查询截止时间确认收货待评价的订单列表
- * @param int $storeId 商城ID
- * @param int $deadlineTime 截止时间
- * @return \think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getOrderListByComment(int $storeId, int $deadlineTime)
- {
- // 查询条件
- $filter = [
- ['order_status', '=', OrderStatusEnum::COMPLETED],
- ['receipt_status', '=', ReceiptStatus::RECEIVED],
- ['receipt_time', '<=', $deadlineTime],
- ['is_comment', '=', 0]
- ];
- // 查询列表记录
- return $this->getList($storeId, $filter, ['user']);
- }
- /**
- * 批量更新订单状态为已收货
- * @param array $orderIds
- * @return false|int
- */
- public function onUpdateReceived(array $orderIds)
- {
- $newOrderIdsOne = $newOrderIdsTwo = [];
- foreach ($orderIds as $orderId){
- //判断订单下面的商品是否都已收货
- if(!OrderGoodsModel::where('order_id',$orderId)->where('receipt_status',ReceiptStatus::NOT_RECEIVED)->where('has_refund_full',0)->count()){
- $order = OrderModel::find($orderId);
- if($order['order_status']==OrderStatusEnum::NORMAL){//订单未关闭的情况下
- $newOrderIdsOne[] = $orderId;
- }else{
- $newOrderIdsTwo[] = $orderId;
- }
- }
- }
- if(!empty($newOrderIdsOne)){
- return $this->onBatchUpdate($newOrderIdsOne, [
- 'receipt_status' => ReceiptStatus::RECEIVED,
- 'receipt_time' => time(),
- 'order_status' => OrderStatusEnum::COMPLETED
- ]);
- }
- if(!empty($newOrderIdsTwo)){
- return $this->onBatchUpdate($newOrderIdsTwo, [
- 'receipt_status' => ReceiptStatus::RECEIVED,
- 'receipt_time' => time()
- ]);
- }
- }
- }
|