<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 订单数据
 */
namespace app\citys\model;
use think\Model;

class CitysOrder extends Model{
    
    protected $pk    = 'id';

    /**
     * @return \think\model\relation\HasOne
     * 商品
     */
    public function info(){
        return $this->hasOne('citys','id','info_id');
    }

    /**
     * @return \think\model\relation\HasOne
     * 用户
     */
    public function user(){
        return $this->hasOne('app\common\model\SystemUser','id','uid');
    }

    /**
     * @param $data
     * @param $order_no
     * 购买商品生成订单数据
     */
    public static function insertOrder($param,$order_no){
        $order = [
            'order_no'          => $order_no,
            'info_id'           => $param['id'],
            'member_miniapp_id' => $param['member_miniapp_id'],
            'phone'             => $param['telphone'],
            'message'           => $param['message'],
            'uid'               => $param['uid'],
            'amount'            => $param['amount'],
            'cache'             => $param['cache'],
            'fields'            => $param['fields'],
            'status'            => 0,
            'is_del'            => 0,
            'paid_at'           => 0,
            'create_time'       => time()
        ];
        return self::create($order);
    }
}
