| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- /*
- * @Author: your name
- * @Date: 2021-03-02 09:50:20
- * @LastEditTime: 2021-04-29 15:29:26
- * @LastEditors: Please set LastEditors
- * @Description: In User Settings Edit
- * @FilePath: \admin_php\models\OrderDetail.php
- */
- namespace app\models;
- use Yii;
- /**
- * This is the model class for table "{{%order_detail_fack}}".
- *
- * @property integer $id
- * @property integer $order_id
- * @property integer $goods_id
- * @property string $goods_name
- * @property integer $num
- * @property string $total_price
- * @property integer $created_at
- * @property integer $is_delete
- * @property string $attr
- * @property string $pic
- * @property string $goods_info
- * @property integer $is_virtual
- */
- class OrderDetailFack extends \yii\db\ActiveRecord
- {
- /**
- * 类型枚举
- * 快递
- */
- const GOODS_DELIVERY_EXPRESS = 0;
- /**
- * 类型枚举
- * 自提
- */
- const GOODS_DELIVERY_SHOP = 1;
- /**
- * 类型枚举
- * 同城
- */
- const GOODS_DELIVERY_IM = 2;
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%order_detail_fack}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['order_id', 'goods_id', 'attr', 'pic'], 'required'],
- [['order_id', 'goods_id', 'num', 'created_at', 'is_delete', 'is_virtual'], 'integer'],
- [['total_price'], 'number'],
- [['attr', 'goods_info'], 'string'],
- [['goods_name', 'pic'], 'string', 'max' => 255],
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'order_id' => 'Order ID',
- 'goods_id' => 'Goods ID',
- 'goods_name' => '商品名称',
- 'num' => '商品数量',
- 'total_price' => '此商品的总价',
- 'created_at' => '创建时间',
- 'is_delete' => '是否删除',
- 'attr' => '商品规格',
- 'pic' => '商品规格图片',
- 'goods_info' => '商品快照',
- 'is_virtual' => '是否为虚拟订单详情',
- ];
- }
- /**
- * 生成虚拟订单详情
- */
- public static function generateVirtualOrderDetail($order)
- {
- $detail = new self();
- $detail->order_id = $order->id;
- $detail->goods_id = $order->goods_id;
- $detail->goods_name = $order->goods_name ?: '虚拟商品';
- $detail->num = 1;
- $detail->total_price = $order->pay_price;
- $detail->created_at = $order->created_at;
- $detail->is_delete = 0;
- $detail->attr = json_encode(['规格' => '默认规格']);
- $detail->pic = '/images/default-goods.jpg';
- $detail->goods_info = json_encode(['商品快照信息']);
- $detail->is_virtual = 1;
- return $detail->save();
- }
- /**
- * 获取订单的详情
- */
- public static function getOrderDetails($orderId)
- {
- return self::find()
- ->where(['order_id' => $orderId, 'is_delete' => 0])
- ->all();
- }
- }
|