198 lines
9.3 KiB
PHP
198 lines
9.3 KiB
PHP
<?php
|
||
|
||
namespace app\models;
|
||
|
||
use Yii;
|
||
use app\models\integral\mall\IntegralMallOrder;
|
||
use app\models\Model;
|
||
|
||
/**
|
||
* This is the model class for table "{{%order}}".
|
||
*
|
||
* @property int $id ID
|
||
* @property int $cx_mch_id 平台商户ID
|
||
* @property int $user_id 用户ID
|
||
* @property string $order_no 订单号
|
||
* @property float $total_price 订单总金额(含运费)
|
||
* @property float $total_pay_price 实际支付总费用(含运费)
|
||
* @property float $express_original_price 运费(后台修改前)
|
||
* @property float $express_price 运费(后台修改后)
|
||
* @property float $total_goods_price 订单商品总金额(优惠后)
|
||
* @property float $total_goods_original_price 订单商品总金额(优惠前)
|
||
* @property int $use_user_coupon_id 使用的用户优惠券id
|
||
* @property float $coupon_discount_price 优惠券优惠金额
|
||
* @property string $name 收件人姓名
|
||
* @property string $mobile 收件人手机号
|
||
* @property string $address 收件人地址
|
||
* @property string $remark 用户订单备注
|
||
* @property string $seller_words 商家留言
|
||
* @property string $seller_remark 商家订单备注
|
||
* @property int $is_pay 是否支付:0=未支付,1=已支付
|
||
* @property int $pay_type 支付方式
|
||
* @property int $pay_time 支付时间
|
||
* @property int $is_send 是否发货:0=未发货,1=已发货
|
||
* @property int $send_time 发货时间
|
||
* @property string|null $customer_name 京东商家编号
|
||
* @property string $express 物流公司
|
||
* @property string $express_no 物流订单号
|
||
* @property int $is_sale 是否过售后时间
|
||
* @property int $is_confirm 收货状态:0=未收货,1=已收货
|
||
* @property int $confirm_time 确认收货时间
|
||
* @property int $cancel_status 订单取消状态:0=未取消,1=已取消,2=申请取消
|
||
* @property int $cancel_time 订单取消时间
|
||
* @property int $created_at 添加时间
|
||
* @property int $updated_at 更新时间
|
||
* @property int $deleted_at 删除时间
|
||
* @property int $is_delete 是否删除:0=否,1=是
|
||
* @property int $is_recycle 是否加入回收站:0=否,1=是
|
||
* @property int $send_type 配送方式:0=快递配送,1=到店自提,2=同城配送,3=无配送,4=商家自配
|
||
* @property string $plugin_sign 插件标识
|
||
* @property string|null $support_pay_types 支持的支付方式,空表示支持系统设置支持的所有方式
|
||
* @property int $is_comment 是否评价:0=否,1=是
|
||
* @property int $comment_time 评价时间
|
||
* @property int $apply_after_sale 是否申请售后
|
||
* @property int $status 订单状态:1=进行中,0=已完成
|
||
* @property int|null $auto_cancel_time 自动取消时间
|
||
* @property int|null $auto_confirm_time 自动确认收货时间
|
||
* @property int|null $auto_sales_time 自动售后时间
|
||
* @property int|null $distance 同城配送距离,-1不在范围内,正数为距离M
|
||
* @property string|null $city_mobile 同城配送联系方式
|
||
* @property string|null $location 经纬度:纬度,经度
|
||
* @property string|null $city_name 同城配送城市名称
|
||
* @property string|null $city_info 同城配送城市信息
|
||
* @property string|null $store_id 门店ID
|
||
* @property string|null $coach_id 教练ID
|
||
*/
|
||
class Order extends \yii\db\ActiveRecord
|
||
{
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public static function tableName()
|
||
{
|
||
return '{{%order}}';
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function rules()
|
||
{
|
||
return [
|
||
[['support_pay_types', 'order_no', 'name', 'customer_name', 'express', 'mobile', 'address', 'remark', 'seller_words', 'seller_remark', 'express_no', 'plugin_sign', 'location', 'city_name', 'city_info', 'city_mobile'], 'trim'],
|
||
[['cx_mch_id', 'user_id', 'total_price', 'total_pay_price', 'express_original_price', 'express_price', 'total_goods_price', 'total_goods_original_price', 'use_user_coupon_id', 'coupon_discount_price', 'pay_type',], 'required'],
|
||
[['cx_mch_id', 'user_id', 'use_user_coupon_id', 'is_pay', 'pay_type', 'pay_time', 'is_send', 'send_time', 'is_sale', 'is_confirm', 'confirm_time', 'cancel_status', 'cancel_time', 'created_at', 'updated_at', 'deleted_at', 'is_delete', 'is_recycle', 'send_type', 'is_comment', 'comment_time', 'apply_after_sale', 'status', 'auto_cancel_time', 'auto_confirm_time', 'auto_sales_time', 'distance','coach_id'], 'integer'],
|
||
[['total_price', 'total_pay_price', 'express_original_price', 'express_price', 'total_goods_price', 'total_goods_original_price', 'coupon_discount_price'], 'number'],
|
||
[['support_pay_types'], 'string'],
|
||
[['order_no'], 'string', 'max' => 64],
|
||
[['name', 'customer_name', 'express'], 'string', 'max' => 65],
|
||
[['mobile', 'address', 'remark', 'seller_words', 'seller_remark', 'express_no', 'plugin_sign', 'location', 'city_name', 'city_info'], 'string', 'max' => 255],
|
||
[['city_mobile'], 'string', 'max' => 100],
|
||
];
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function attributeLabels()
|
||
{
|
||
return [
|
||
'id' => 'ID',
|
||
'cx_mch_id' => '平台商户ID',
|
||
'user_id' => '用户ID',
|
||
'order_no' => '订单号',
|
||
'total_price' => '订单总金额(含运费)',
|
||
'total_pay_price' => '实际支付总费用(含运费)',
|
||
'express_original_price' => '运费(后台修改前)',
|
||
'express_price' => '运费(后台修改后)',
|
||
'total_goods_price' => '订单商品总金额(优惠后)',
|
||
'total_goods_original_price' => '订单商品总金额(优惠前)',
|
||
'use_user_coupon_id' => '使用的用户优惠券id',
|
||
'coupon_discount_price' => '优惠券优惠金额',
|
||
'name' => '收件人姓名',
|
||
'mobile' => '收件人手机号',
|
||
'address' => '收件人地址',
|
||
'remark' => '用户订单备注',
|
||
'seller_words' => '商家留言',
|
||
'seller_remark' => '商家订单备注',
|
||
'is_pay' => '是否支付:0=未支付,1=已支付',
|
||
'pay_type' => '支付方式',
|
||
'pay_time' => '支付时间',
|
||
'is_send' => '是否发货:0=未发货,1=已发货',
|
||
'send_time' => '发货时间',
|
||
'customer_name' => '京东商家编号',
|
||
'express' => '物流公司',
|
||
'express_no' => '物流订单号',
|
||
'is_sale' => '是否过售后时间',
|
||
'is_confirm' => '收货状态:0=未收货,1=已收货',
|
||
'confirm_time' => '确认收货时间',
|
||
'cancel_status' => '订单取消状态:0=未取消,1=已取消,2=申请取消',
|
||
'cancel_time' => '订单取消时间',
|
||
'created_at' => '添加时间',
|
||
'updated_at' => '更新时间',
|
||
'deleted_at' => '删除时间',
|
||
'is_delete' => '是否删除:0=否,1=是',
|
||
'is_recycle' => '是否加入回收站:0=否,1=是',
|
||
'send_type' => '配送方式:0=快递配送,1=到店自提,2=同城配送,3=无配送,4=商家自配',
|
||
'plugin_sign' => '插件标识',
|
||
'support_pay_types' => '支持的支付方式,空表示支持系统设置支持的所有方式',
|
||
'is_comment' => '是否评价:0=否,1=是',
|
||
'comment_time' => '评价时间',
|
||
'apply_after_sale' => '是否申请售后',
|
||
'status' => '订单状态:1=进行中,0=已完成',
|
||
'auto_cancel_time' => '自动取消时间',
|
||
'auto_confirm_time' => '自动确认收货时间',
|
||
'auto_sales_time' => '自动售后时间',
|
||
'distance' => '同城配送距离,-1不在范围内,正数为距离M',
|
||
'city_mobile' => '同城配送联系方式',
|
||
'location' => '经纬度:纬度,经度',
|
||
'city_name' => '同城配送城市名称',
|
||
'city_info' => '同城配送城市信息',
|
||
];
|
||
}
|
||
|
||
|
||
public function beforeSave($insert)
|
||
{
|
||
if (parent::beforeSave($insert)) {
|
||
if ($this->isNewRecord) {
|
||
$this->created_at = time();
|
||
}
|
||
$this->updated_at = time();
|
||
if ($this->is_delete == 1)
|
||
$this->deleted_at = time();
|
||
$this->htmlTagFilter();
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public function htmlTagFilter()
|
||
{
|
||
$this->name = Model::htmlTagFilter($this->name);
|
||
$this->mobile = Model::htmlTagFilter($this->mobile);
|
||
$this->address = Model::htmlTagFilter($this->address);
|
||
$this->remark = Model::htmlTagFilter($this->remark);
|
||
$this->seller_remark = Model::htmlTagFilter($this->seller_remark);
|
||
$this->seller_words = Model::htmlTagFilter($this->seller_words);
|
||
}
|
||
|
||
|
||
//积分商城订单
|
||
public function getIntegralMallOrder()
|
||
{
|
||
return $this->hasOne(IntegralMallOrder::className(), ['order_id' => 'id'])->where(['is_delete' => 0]);
|
||
}
|
||
|
||
public static function statusLabels()
|
||
{
|
||
return [
|
||
'0' => '待支付',
|
||
'1' => '已支付',
|
||
// '2' => '已取消',
|
||
'3' => '已完成',
|
||
];
|
||
}
|
||
}
|