/** * 关联会员表 */
public function member() { return $this->hasOne(Member::class, 'member_id', 'member_id'); }
关联写法
/** * 详情 * @param int $order_id * @return array */ public function getDetail(int $refund_id) { $field = 'refund_id, order_id, order_goods_id, order_refund_no, refund_type, reason, member_id, apply_money, money, status, create_time, transfer_time, remark, voucher, source, timeout, refund_no, delivery, shop_reason, refund_address'; $info = $this->model->where([ [ 'refund_id', '=', $refund_id ], ['site_id', '=', $this->site_id] ])->field($field) ->with( [ 'order_main' => function($query) { $query->field('order_id,order_no,order_type,order_from,out_trade_no,status,member_id,ip,goods_money,delivery_money,order_money,invoice_id,create_time,pay_time,delivery_time,take_time,finish_time,close_time,delivery_type,taker_name,taker_mobile,taker_province,taker_city,taker_district,taker_address,taker_full_address,taker_longitude,taker_latitude,take_store_id,is_enable_refund,member_remark,shop_remark,close_remark,discount_money') ->append([ 'order_from_name', 'order_type_name', 'status_name', 'delivery_type_name' ]); }, 'order_goods' => function($query) { $query->field('order_goods_id, order_id, member_id, goods_id, sku_id, goods_name, sku_name, goods_image, sku_image, price, num, goods_money, is_enable_refund, goods_type'); }, 'member' => function($query) { $query->field('member_id, nickname, mobile, headimg'); }, 'pay_refund' => function($query) { $query->field('refund_no, type, money, create_time, refund_time')->append([ 'type_name' ]); }, 'refund_log' => function($query) { $query->field('order_refund_no, content, main_type, create_time ,main_id, type')->order("create_time desc")->append([ 'main_name', 'type_name', 'main_type_name' ]); } ])->append(['status_name', 'refund_type_name'])->findOrEmpty()->toArray(); return $info; }
标签:refund,name,便捷,order,time,thinkphp,简写,type,id From: https://www.cnblogs.com/agressor/p/17962920