OrderModel.php 2.0 KB
<?php


namespace api\common\model;


use EasyWeChat\Payment\Order;
use think\Model;

class OrderModel extends Model
{
    protected $name = 'orders';


    public function  setOrder($user_id,$good_id,$num,$address_id,$remark=''){
           $GoodModel= new GoodsModel();
           $good=$GoodModel->where('id',$good_id)->find();
           $Address=new AddressModel();
           $address=$Address->where('id',$address_id)->find();
           $insert['order_sn']=cmf_get_order_sn();
           $insert['good_id']=$good_id;
           $insert['create_time']=time();
           $insert['user_id']=$user_id;
           $insert['num']=$num;
           $insert['is_real']=$good['real_good'];
           $insert['address_info']=$address['address'];
           $insert['name']=$address['name'];
           $insert['mobile']=$address['tel'];
           $insert['remark']=$remark;
           $insert['expend']=$good['work_time']*$num;
           $insert['address']=$address['province'].$address['city'].$address['district'];
           $this->insert($insert);
           return $insert['order_sn'];
    }

    /**
     * @param $order_id
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function orderInfo($order_id){
         $map['o.id']=$order_id;
         $order_info=$this->alias('o')
             ->field('o.*')
             ->join('goods g','o.good_id=g.id')
             ->where($map)
             ->find();
         $goodModel=new GoodsModel();
         $order_info['remark']=cmf_replace_content_file_url(htmlspecialchars_decode($order_info['remark']));
         $order_info['content_info']=cmf_replace_content_file_url(htmlspecialchars_decode($order_info['content_info']));
         $order_info['reason']=cmf_replace_content_file_url(htmlspecialchars_decode($order_info['reason']));


         $order_info['good']=$goodModel->getGoods($order_info['good_id']);
         return $order_info;
    }


}