FoodOrder.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\plugins\food\models;
  8. use Yii;
  9. use Codeception\PHPUnit\ResultPrinter\HTML;
  10. /**
  11. * This is the model class for table "{{%food_order}}".
  12. *
  13. * @property integer $id
  14. * @property integer $store_id
  15. * @property integer $user_id
  16. * @property string $order_no
  17. * @property string $total_price
  18. * @property string $pay_price
  19. * @property string $name
  20. * @property string $mobile
  21. * @property string $remark
  22. * @property integer $is_pay
  23. * @property integer $pay_type
  24. * @property integer $pay_time
  25. * @property integer $is_comment
  26. * @property integer $created_at
  27. * @property integer $is_delete
  28. * @property integer $is_price
  29. * @property integer $parent_id
  30. * @property string $coupon_sub_price
  31. * @property string $content
  32. * @property string $before_update_price
  33. * @property string $discount
  34. * @property integer $user_coupon_id
  35. * @property integer $parent_id_1
  36. * @property integer $parent_id_2
  37. * @property integer $is_sale
  38. * @property string $words
  39. * @property integer $is_recycle
  40. * @property string $seller_comments
  41. * @property string $alipay_trade_no
  42. * @property string $table_num
  43. * @property integer $is_use_platform_mch
  44. */
  45. class FoodOrder extends \yii\db\ActiveRecord
  46. {
  47. /**
  48. * 订单来源 公众号或网站
  49. */
  50. const ORDER_SOURCE_WEB = 1;
  51. /**
  52. * 订单来源 app
  53. */
  54. const ORDER_SOURCE_APP = 2;
  55. /**
  56. * 订单来源 小程序
  57. */
  58. const ORDER_SOURCE_MINI = 3;
  59. /**
  60. * 是否支付:已支付
  61. */
  62. const IS_PAY_TRUE = 1;
  63. /**
  64. * 是否支付:未支付
  65. */
  66. const IS_PAY_FALSE = 0;
  67. /**
  68. * 支付方式:未支付
  69. */
  70. const PAY_TYPE_UNPAID = 0;
  71. /**
  72. * 支付方式:微信支付
  73. */
  74. const PAY_TYPE_WECHAT = 1;
  75. /**
  76. * 支付方式:货到付款
  77. */
  78. const PAY_TYPE_COD = 2;
  79. /**
  80. * 支付方式:余额支付
  81. */
  82. const PAY_TYPE_BALANCE_PAID = 3;
  83. /**
  84. * @inheritdoc
  85. */
  86. public static function tableName()
  87. {
  88. return '{{%food_order}}';
  89. }
  90. /**
  91. * @inheritdoc
  92. */
  93. public function rules()
  94. {
  95. return [
  96. [['store_id', 'user_id', 'order_no'], 'required'],
  97. [['store_id', 'user_id', 'is_pay', 'pay_type', 'pay_time',
  98. 'is_comment', 'created_at', 'is_delete', 'parent_id', 'user_coupon_id', 'parent_id_1',
  99. 'parent_id_2', 'is_use_platform_mch'], 'integer'],
  100. [['total_price', 'pay_price', 'coupon_sub_price','discount'], 'number'],
  101. [['order_no', 'name', 'mobile', 'alipay_trade_no', 'table_num'], 'string', 'max' => 255],
  102. [['remark'], 'string', 'max' => 1000],
  103. ];
  104. }
  105. /**
  106. * @inheritdoc
  107. */
  108. public function attributeLabels()
  109. {
  110. return [
  111. 'id' => 'ID',
  112. 'store_id' => 'Store ID',
  113. 'user_id' => '用户id',
  114. 'order_no' => '订单号',
  115. 'total_price' => '订单总费用(包含运费)',
  116. 'pay_price' => '实际支付总费用(含运费)',
  117. 'name' => '收货人姓名',
  118. 'mobile' => '收货人手机',
  119. 'remark' => '订单备注',
  120. 'is_pay' => '支付状态:0=未支付,1=已支付',
  121. 'pay_type' => '支付方式:1=微信支付',
  122. 'pay_time' => '支付时间',
  123. 'is_comment' => '是否已评价:0=未评价,1=已评价',
  124. 'created_at' => 'Addtime',
  125. 'is_delete' => 'Is Delete',
  126. 'parent_id' => '用户上级ID',
  127. 'coupon_sub_price' => '优惠券抵消金额',
  128. 'discount' => '会员折扣',
  129. 'user_coupon_id' => '使用的优惠券ID',
  130. 'parent_id_1' => '用户上二级ID',
  131. 'parent_id_2' => '用户上三级ID',
  132. 'words' => '商家留言',
  133. 'alipay_trade_no' => '支付宝订单号',
  134. 'is_use_platform_mch' => '供应链系统下单时是否使用平台商户号,1使用,0未使用',
  135. ];
  136. }
  137. public function getOrderDetail()
  138. {
  139. return $this->hasMany(FoodOrderDetail::className(), ['order_id' => 'id'])->alias('od')
  140. ->leftJoin(['g' => FoodGoods::tableName()], 'g.id=od.goods_id')->select(['od.*', 'g.name', 'g.attr goods_attr', 'g.cost_price']);
  141. }
  142. public function getDetail()
  143. {
  144. return $this->hasMany(FoodOrderDetail::className(), ['order_id' => 'id']);
  145. }
  146. public function getGoods()
  147. {
  148. return $this->hasMany(FoodGoods::className(), ['id' => 'goods_id'])->alias('g')
  149. ->viaTable(FoodOrderDetail::tableName() . ' od', ['order_id' => 'id']);
  150. }
  151. }