PackageOrder.php 1.1 KB
<?php
namespace app\mobile\model;

use think\Model;
use think\Db;

class PackageOrder extends Model
{
	// 表名
    protected $name = 'mobile_package_order';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    // 课程信息
    public function course(){
    	return $this->belongsTo('Course');
    }

    /**
     * 新增订单
     */
    public function add($user, $order, $pay_type)
    {
        // 记录订单信息
        $this->save([
            'user_id' => $user['id'],
            'company_id' => Company::where('user_id',$user['id'])->value('id'),
            'package_id' => $order['package_info']['id'],
            'order_sn' => get_order_sn(),
            'pay_price' => $order['pay_price'],
            'pay_type' => $pay_type,
            'package_price' => $order['package_price'],
            'people_num' => $order['spec_info']['people_num'],
            'course_spec_id' => $order['spec_info']['id'],
            'is_top' => $order['spec_info']['is_top']
        ]);
        return true;
    }
}