You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

192 lines
6.0 KiB

<?php
namespace backend\modules\shop\models\ars;
use common\models\User;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\helpers\ArrayHelper;
/**
* This is the model class for table "ats_order".
*
* @property int $id
* @property int $user_id 用户id
* @property string $order_sn 订单号
* @property string $invoice_id 发票单号
* @property int $status 状态
* @property int $type 类型
* @property int $goods_count 商品数量
* @property int $goods_amount 商品金额
* @property int $shipping_amount 物流金额
* @property int $shipping_type 物流类型
* @property string $consignee 收件人
* @property string $phone 手机号码
* @property string $province 省份
* @property string $city 城市
* @property string $area 区域
* @property int $taking_site 自提点
* @property int $pay_type 支付方式
* @property int $pay_at 支付时间
* @property string $payment_sn 付款单号
* @property int $payment_amount 支付金额
* @property int $receivables 应收款
* @property string $remarks 备注
* @property int $discount_amount 折扣金额
* @property string $discount_description 折扣说明
* @property int $updated_at 更新时间
* @property int $created_at 创建时间
* @property string $address 详细地址
*/
class Order extends \yii\db\ActiveRecord
{
/*支付类型*/
const PAY_TYPE_WX = 1;//微信支付
const PAY_TYPE_BALANCES = 2;//余额支付
const PAY_TYPE_POINT_EXCHANGE = 3;//积分兑换
/*支付id*/
const PAY_ID_WX = 1;//微信公众号支付
const PAY_ID_MINI = 2;//小程序支付
const PAY_ID_POINTS_SHOP = 3;//积分商城兑换
/*配送方式*/
const SHIPPING_TYPE_NO_SHIPPING = 0;//无需配送
const SHIPPING_TYPE_PICKED_UP_BY_CUSTOMER = 1;//自提
const SHIPPING_TYPE_EXPRESS = 2;//快递物流
/*发货状态*/
const SHIPPING_STATUS_UNSHIPPED = 0;/*未发货*/
const SHIPPING_STATUS_SHIPMENT = 1;/*已发货*/
const SHIPPING_STATUS_TAKE = 2;/*已收货*/
const SHIPPING_STATUS_RETURN = 3;/*退货*/
const SHIPPING_STATUS_PORTION = 4;/*部分发货*/
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'ats_order';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['user_id'], 'required'],
[['user_id', 'status', 'type', 'goods_count', 'goods_amount', 'shipping_amount', 'shipping_type', 'taking_site', 'pay_type', 'pay_at', 'payment_amount', 'receivables', 'discount_amount'], 'integer'],
[['discount_description', 'address'], 'string'],
[['order_sn', 'invoice_id'], 'string', 'max' => 64],
[['consignee', 'phone'], 'string', 'max' => 20],
[['province', 'city', 'area'], 'string', 'max' => 10],
[['payment_sn'], 'string', 'max' => 120],
[['remarks'], 'string', 'max' => 255],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'id',
'user_id' => '用户id',
'order_sn' => '订单号',
'invoice_id' => '发票单号',
'status' => '状态',
'type' => '类型',
'goods_count' => '商品数量',
'goods_amount' => '商品金额',
'shipping_amount' => '物流金额',
'shipping_type' => '物流类型',
'consignee' => '收件人',
'phone' => '手机号码',
'province' => '省份',
'city' => '城市',
'area' => '区域',
'taking_site' => '自提点',
'pay_type' => '支付方式',
'pay_at' => '支付时间',
'payment_sn' => '付款单号',
'payment_amount' => '支付金额',
'receivables' => '应收款',
'remarks' => '备注',
'discount_amount' => '折扣金额',
'discount_description' => '折扣说明',
'updated_at' => '更新时间',
'created_at' => '创建时间',
'address' => '详细地址',
];
}
/**
* @author linyao
* @email 602604991@qq.com
* @created Nov 8, 2019
*
* 行为存储创建时间和更新时间
*/
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => function() {
return time();
},
],
];
}
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
public function getProvinceId()
{
return $this->hasOne(Province::className(), ['province_id' => 'province']);
}
public function getCityId()
{
return $this->hasOne(City::className(), ['city_id' => 'city']);
}
public function getAreaId()
{
return $this->hasOne(Area::className(), ['area_id' => 'area']);
}
/**
* @param $column
* @param null $value
* @return bool
* 获取各状态数组
*/
public static function dropDown($column, $value = null)
{
$types = ExpressType::find()->asArray()->all();
$data = ArrayHelper::map($types, 'id', 'shipping_name');
$data[0] = '无需配送';
$dropDownList = [
'pay_type' => [
'0' => '未支付',
'1' => '微信支付',
'2' => '余额支付',
'3' => '积分兑换',
],
'shipping_type' => $data,
];
//根据具体值显示对应的值
if ($value !== null)
return array_key_exists($column, $dropDownList) ? $dropDownList[$column][$value] : false;
//返回关联数组,用户下拉的filter实现
else
return array_key_exists($column, $dropDownList) ? $dropDownList[$column] : false;
}
}