## 订单信息
>[info]功能:
1,显示数据:查询 `wp_order` 订单表 显示订单信息 订单由前台用户购买商品生成
/*
*@desc 根据登录账号信息获取数据列表
*/
public function scopeDefaultWhere($query)
{
parent::scopeDefaultWhere($query);
/*
*@desc 根据订单编号查询
*/
$wq = request_data('wq');
if($wq){
$query->where(function($q)use($wq){
$q->where('order_id', 'like', "%".$wq."%");
});
}
/*
*@desc 根据订单状态查询
*/
$status = request_data('status');
if($status){
if($status == 6){
$query->where('order_status','>',1);
}else{
$query->where('order_status',$status);
}
}
/*
*@desc 根据订单时间查询
*/
$start_time = request_data('start_time')?:date('Y-m-d 00:00:00', time());
$end_time = request_data('end_time')?date('Y-m-d 23:59:59', strtotime(request_data('end_time'))):date('Y-m-d 23:59:59', time());
$query->where('ended','>=',strtotime($start_time))->where('ended','<=',strtotime($end_time));
$in = \cs\login::login_user(1);
if($in){
$query->whereIn('shop_id',$in);
}
}
>[info] 2,关联`wp_order_value` 订单详情表 查看此订单下详细的购买商品情况 ;
/*
*
*@desc 关联订单详情
*/
public function wp_order_value(){
return $this->hasMany('models\wp_order_value','order_id','order_id');
}
>[info]3, 通过`wp_order_value`关联`wp_order_return` 可以进行退货操作;
/**
* 获取退货订单信息
*/
public function wp_order_return()
{
return $this->hasMany('models\wp_order_return','order_id','order_id');
}
/*
* 退货处理
* */
static public function saveForm(){
try{
DB::transaction(function()
{
$data = get_data();
if($data){
foreach($data['goods_id'] as $k=>$v){
if($data['goods_num'][$k] != 0 && $data['goods_price'][$k] != 0){
$arr[$k]['goods_id'] = $v;
$arr[$k]['goods_num'] = $data['goods_num'][$k];
$arr[$k]['goods_price'] = $data['goods_price'][$k];
}
}
}
if($arr){
foreach($arr as $k=>$v){
$li = yf_goods_common::where('id',$v['goods_id'])->first();
$date['common_stock'] = $li->common_stock + $v['goods_num'];
$li->where('id',$v['goods_id'])->update($date);
if($li->common_goods_from == 1){
order::getGoodscommon($li->goods_id,'add',$v['goods_num']);
}
$list['num'] = $v['goods_num'];
$list['order_id'] = $data['order_id'];
$list['goods_id'] = $v['goods_id'];
$list['goods_name'] = $li->common_name;
$list['goods_values'] = $li->common_spec_name;
$list['shop_id'] = cookie('shop_id');
$list['shop_name'] = cookie('shop_name');
$list['status'] = 2;
$list['return_payid'] = config('payment.cash');
$list['good_price_ori'] = $v['goods_price'];
$list['goods_price'] = $v['goods_price'];
$list['shop_users_id'] = cookie('id');
$list['created'] = time();
$model = new self;
if($v['goods_num'] == 0) continue;
$model->insert($list);
}
}else{
exit(json_encode(['status'=>0,'msg'=>__('请选择退货商品') ]));
}
});
}catch(Exception $e){
return false;
}
return true;
}