123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- namespace app\common\logic;
-
-
- use app\common\enum\GoodsEnum;
- use app\common\enum\OrderEnum;
- use app\common\model\goods\Goods;
- use app\common\model\order\Order;
-
-
- class GoodsVirtualLogic
- {
-
-
-
- public static function afterPayVirtualDelivery($orderIds)
- {
- $orderIds = is_array($orderIds) ? $orderIds : [$orderIds];
- $orders = Order::with(['order_goods'])->whereIn('id', $orderIds)->select()->toArray();
-
- foreach ($orders as $order) {
-
- $goodsId = $order['order_goods'][0]['goods_id'] ?? 0;
- $goods = Goods::findOrEmpty($goodsId);
-
-
- if ($goods->isEmpty() || $goods['type'] != GoodsEnum::TYPE_VIRTUAL) {
- continue;
- }
-
- $data = [
- 'delivery_content' => $goods['delivery_content'],
- 'update_time' => time(),
- ];
-
-
- if ($goods['after_pay'] == GoodsEnum::AFTER_PAY_AUTO_DELIVERY) {
- $data['order_status'] = OrderEnum::ORDER_STATUS_GOODS;
- $data['delivery_type'] = OrderEnum::DELIVERY_TYPE_VIRTUAL;
- $data['shipping_status'] = OrderEnum::SHIPPING_FINISH;
- $data['shipping_time'] = time();
-
-
- if ($goods['after_delivery'] == GoodsEnum::AFTER_DELIVERY_AUTO_COMFIRM) {
- $data['order_status'] = OrderEnum::ORDER_STATUS_COMPLETE;
- $data['confirm_take_time'] = time();
- }
- }
- Order::where(['id' => $order['id']])->update($data);
- }
-
- return true;
- }
-
-
-
-
-
- public static function shopSelfDelivery($orderId, $content = null)
- {
- $order = Order::with(['order_goods'])->where('id', $orderId)->findOrEmpty()->toArray();
-
- $goodsId = $order['order_goods'][0]['goods_id'] ?? 0;
- $goods = Goods::findOrEmpty($goodsId);
-
-
- if ($goods->isEmpty() || $goods['type'] != GoodsEnum::TYPE_VIRTUAL) {
- return '虚拟商品信息不存在';
- }
-
- $data = [
- 'order_status' => OrderEnum::ORDER_STATUS_GOODS,
- 'delivery_type' => OrderEnum::DELIVERY_TYPE_VIRTUAL,
- 'delivery_content' => empty($content) ? $goods['delivery_content'] : $content,
- 'shipping_status' => OrderEnum::SHIPPING_FINISH,
- 'shipping_time' => time(),
- 'update_time' => time(),
- ];
-
-
- if ($goods['after_delivery'] == GoodsEnum::AFTER_DELIVERY_AUTO_COMFIRM) {
- $data['order_status'] = OrderEnum::ORDER_STATUS_COMPLETE;
- $data['confirm_take_time'] = time();
- }
- Order::where(['id' => $order['id']])->update($data);
- return true;
- }
-
-
- }
|