OrderDetailFack.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. /*
  8. * @Author: your name
  9. * @Date: 2021-03-02 09:50:20
  10. * @LastEditTime: 2021-04-29 15:29:26
  11. * @LastEditors: Please set LastEditors
  12. * @Description: In User Settings Edit
  13. * @FilePath: \admin_php\models\OrderDetail.php
  14. */
  15. namespace app\models;
  16. use Yii;
  17. /**
  18. * This is the model class for table "{{%order_detail_fack}}".
  19. *
  20. * @property integer $id
  21. * @property integer $order_id
  22. * @property integer $goods_id
  23. * @property string $goods_name
  24. * @property integer $num
  25. * @property string $total_price
  26. * @property integer $created_at
  27. * @property integer $is_delete
  28. * @property string $attr
  29. * @property string $pic
  30. * @property string $goods_info
  31. * @property integer $is_virtual
  32. */
  33. class OrderDetailFack extends \yii\db\ActiveRecord
  34. {
  35. /**
  36. * 类型枚举
  37. * 快递
  38. */
  39. const GOODS_DELIVERY_EXPRESS = 0;
  40. /**
  41. * 类型枚举
  42. * 自提
  43. */
  44. const GOODS_DELIVERY_SHOP = 1;
  45. /**
  46. * 类型枚举
  47. * 同城
  48. */
  49. const GOODS_DELIVERY_IM = 2;
  50. /**
  51. * @inheritdoc
  52. */
  53. public static function tableName()
  54. {
  55. return '{{%order_detail_fack}}';
  56. }
  57. /**
  58. * @inheritdoc
  59. */
  60. public function rules()
  61. {
  62. return [
  63. [['order_id', 'goods_id', 'attr', 'pic'], 'required'],
  64. [['order_id', 'goods_id', 'num', 'created_at', 'is_delete', 'is_virtual'], 'integer'],
  65. [['total_price'], 'number'],
  66. [['attr', 'goods_info'], 'string'],
  67. [['goods_name', 'pic'], 'string', 'max' => 255],
  68. ];
  69. }
  70. /**
  71. * @inheritdoc
  72. */
  73. public function attributeLabels()
  74. {
  75. return [
  76. 'id' => 'ID',
  77. 'order_id' => 'Order ID',
  78. 'goods_id' => 'Goods ID',
  79. 'goods_name' => '商品名称',
  80. 'num' => '商品数量',
  81. 'total_price' => '此商品的总价',
  82. 'created_at' => '创建时间',
  83. 'is_delete' => '是否删除',
  84. 'attr' => '商品规格',
  85. 'pic' => '商品规格图片',
  86. 'goods_info' => '商品快照',
  87. 'is_virtual' => '是否为虚拟订单详情',
  88. ];
  89. }
  90. /**
  91. * 生成虚拟订单详情
  92. */
  93. public static function generateVirtualOrderDetail($order)
  94. {
  95. $detail = new self();
  96. $detail->order_id = $order->id;
  97. $detail->goods_id = $order->goods_id;
  98. $detail->goods_name = $order->goods_name ?: '虚拟商品';
  99. $detail->num = 1;
  100. $detail->total_price = $order->pay_price;
  101. $detail->created_at = $order->created_at;
  102. $detail->is_delete = 0;
  103. $detail->attr = json_encode(['规格' => '默认规格']);
  104. $detail->pic = '/images/default-goods.jpg';
  105. $detail->goods_info = json_encode(['商品快照信息']);
  106. $detail->is_virtual = 1;
  107. return $detail->save();
  108. }
  109. /**
  110. * 获取订单的详情
  111. */
  112. public static function getOrderDetails($orderId)
  113. {
  114. return self::find()
  115. ->where(['order_id' => $orderId, 'is_delete' => 0])
  116. ->all();
  117. }
  118. }