where(['is_del'=>0])->get(); return \Yz::Return(true, '查询成功', ['list' => $list]); } public function Save() { $Info = request('Info'); if (!isset($Info['name'])) return \Yz::echoError1("名称不能为空"); if (!isset($Info['his_id'])) return \Yz::echoError1("Id不能为空"); if (!isset($Info['type'])) return \Yz::echoError1("类型不能为空"); $data = [ 'name' => $Info['name'], 'type' => $Info['type'], 'his_id' => $Info['his_id'], 'updated_at' => date("Y-m-d H:i:s"), ]; $u = false; if (isset($Info['id']) and $Info['id'] <> 0) { //更新 $u = DB::table('coupons')->where('id', $Info['id'])->update($data); DB::table('coupons_combos')->where('coupon_hisid', $Info['his_id'])->delete(); } else { $cha=DB::table('coupons')->where(['his_id'=> $Info['his_id']])->first(); if(!!$cha) return \Yz::echoError1("已存在id相同的代金券,不可重复复添加"); //添加 $u = DB::table('coupons')->insert($data); DB::table('coupons_combos')->insert([ 'coupon_hisid'=>$Info['his_id'], ]); } if(isset($Info['combo_ids'])){ foreach ($Info['combo_ids'] as $combo_id) { DB::table('coupons_combos')->insert([ 'coupon_hisid'=>$Info['his_id'], 'combo_id'=>$combo_id, ]); } } if ($u) { return \Yz::Return(true, "操作完成", []); } else { return \Yz::echoError1("操作失败"); } } public function GetDetail() { $id = request('id'); $info = DB::table('coupons')->where('id', $id)->first(); $combos = DB::table('coupons_combos')->where('coupon_hisid', $info->his_id)->pluck('combo_id')->toArray(); $info->combo_ids = $combos; return \Yz::Return(true, '查询成功', ['info' => $info]); } public function Del() { $id = request('id'); $d = DB::table('coupons')->where('id', $id)->update([ 'is_del' => 1 ]); if ($d) { return \Yz::Return(true, "操作完成", []); } else { return \Yz::echoError1("操作失败"); } } }