购买详情增加剩余统收额度字段

wenjuan
yanzai 1 year ago
parent fb8f815be2
commit 7ccad991c1

@ -11,8 +11,8 @@ class ComboController extends Controller
{ {
public function select(Request $request) public function select(Request $request)
{ {
$combo=DB::table('combo_type')->select('id as value','name as label')->get(); $combo = DB::table('combo_type')->select('id as value', 'name as label')->get();
$person=DB::table('combo_crowd')->select('id as value','name as label')->get(); $person = DB::table('combo_crowd')->select('id as value', 'name as label')->get();
// $combo = [[ // $combo = [[
// 'label' => '类型一', // 'label' => '类型一',
// 'value' => '1', // 'value' => '1',
@ -45,68 +45,68 @@ class ComboController extends Controller
$combo_price = $request->post('combo_price'); $combo_price = $request->post('combo_price');
$combo_item = $request->post('combo_item'); $combo_item = $request->post('combo_item');
$hospital= DB::table('hospitals')->select('id','name','address','latitude','longitude')->where(['id'=>$hospital])->first(); $hospital = DB::table('hospitals')->select('id', 'name', 'address', 'latitude', 'longitude')->where(['id' => $hospital])->first();
$user=DB::table('web_users')->where(['openid'=>$openid,'status'=>1,'is_del'=>0])->first(); $user = DB::table('web_users')->where(['openid' => $openid, 'status' => 1, 'is_del' => 0])->first();
if(!$user) return \Yz::echoError1('openid对应用户不存在'); if (!$user) return \Yz::echoError1('openid对应用户不存在');
$person=DB::table('web_user_person')->where(['user_id'=>$user->id,'is_del'=>0,'is_default'=>1])->first(); $person = DB::table('web_user_person')->where(['user_id' => $user->id, 'is_del' => 0, 'is_default' => 1])->first();
if(!$person) return \Yz::echoError1("请选择就诊人"); if (!$person) return \Yz::echoError1("请选择就诊人");
//用户绑定就诊人数量 //用户绑定就诊人数量
$personCount=DB::table('web_user_person')->where(['user_id'=>$user->id,'is_del'=>0])->count(); $personCount = DB::table('web_user_person')->where(['user_id' => $user->id, 'is_del' => 0])->count();
$canshu=[]; $canshu = [];
$sql=''; $sql = '';
if(isset($combo_price)){ if (isset($combo_price)) {
$price_list=[ $price_list = [
"1"=>[0,299], "1" => [0, 299],
"2"=>[300,999], "2" => [300, 999],
"3"=>[1000,1499], "3" => [1000, 1499],
"4"=>[1500,2999], "4" => [1500, 2999],
"5"=>[3000,999999], "5" => [3000, 999999],
]; ];
$sql=" and (a.price>=? and a.price<=?) "; $sql = " and (a.price>=? and a.price<=?) ";
$canshu[]=$price_list[$combo_price][0]; $canshu[] = $price_list[$combo_price][0];
$canshu[]=$price_list[$combo_price][1]; $canshu[] = $price_list[$combo_price][1];
} }
if(isset($combo_type)){ if (isset($combo_type)) {
$sql=$sql." and a.type_id=? "; $sql = $sql . " and a.type_id=? ";
$canshu[]=$combo_type; $canshu[] = $combo_type;
} }
if(isset($combo_crowd)){ if (isset($combo_crowd)) {
$sql=$sql." and a.crowd_id=? "; $sql = $sql . " and a.crowd_id=? ";
$canshu[]=$combo_crowd; $canshu[] = $combo_crowd;
} }
if(isset($combo_sort)){ if (isset($combo_sort)) {
if($combo_sort==1){ if ($combo_sort == 1) {
$sql=$sql." "; $sql = $sql . " ";
} }
if($combo_sort==2){ if ($combo_sort == 2) {
$sql=$sql." "; $sql = $sql . " ";
} }
if($combo_sort==3){ if ($combo_sort == 3) {
$sql=$sql." order by a.price"; $sql = $sql . " order by a.price";
} }
if($combo_sort==4){ if ($combo_sort == 4) {
$sql=$sql." order by a.price desc"; $sql = $sql . " order by a.price desc";
} }
} }
$combos=DB::select("select * from combos as a LEFT JOIN ( $combos = DB::select("select * from combos as a LEFT JOIN (
select combo_id as c_id,count(*) as count from orders where status in(2,4) group by combo_id select combo_id as c_id,count(*) as count from orders where status in(2,4) group by combo_id
) as b on a.combo_id=b.c_id where a.status=1".$sql,$canshu); ) as b on a.combo_id=b.c_id where a.status=1" . $sql, $canshu);
foreach ($combos as $key=>$combo){ foreach ($combos as $key => $combo) {
$tags=json_decode($combo->tags,true); $tags = json_decode($combo->tags, true);
$combo->tags2=json_decode($combo->tags2,true); $combo->tags2 = json_decode($combo->tags2, true);
foreach ($tags as$k=> $tag){ foreach ($tags as $k => $tag) {
$tags[$k]=['text'=>$tag, $tags[$k] = ['text' => $tag,
'text_color' => '#47ABD8', 'text_color' => '#47ABD8',
'color' => '#EBF5FC' 'color' => '#EBF5FC'
]; ];
} }
$combo->tag=$tags; $combo->tag = $tags;
$combo->tag[]=[ $combo->tag[] = [
'text' => $combo->item_count.'个项目', 'text' => $combo->item_count . '个项目',
'text_color' => '#34C292', 'text_color' => '#34C292',
'color' => '#E9F8F3', 'color' => '#E9F8F3',
]; ];
@ -142,7 +142,7 @@ select combo_id as c_id,count(*) as count from orders where status in(2,4) group
// 'latitude' => '39.867671', // 'latitude' => '39.867671',
// 'longitude' => '119.514223', // 'longitude' => '119.514223',
// ]; // ];
$hospital_info=$hospital; $hospital_info = $hospital;
$info = [ $info = [
'name' => $person->name, 'name' => $person->name,
'sex' => $person->sex, 'sex' => $person->sex,
@ -155,7 +155,7 @@ select combo_id as c_id,count(*) as count from orders where status in(2,4) group
]; ];
return \Yz::Return(true, '获取成功', [ return \Yz::Return(true, '获取成功', [
'list' =>$combos, 'list' => $combos,
'hospital' => $hospital_info, 'hospital' => $hospital_info,
'doctor' => $doctor_info, 'doctor' => $doctor_info,
'info' => $info, 'info' => $info,
@ -165,80 +165,80 @@ select combo_id as c_id,count(*) as count from orders where status in(2,4) group
//获取套餐类型、适用人群 //获取套餐类型、适用人群
public function GetComboSort() public function GetComboSort()
{ {
$type=DB::table('combo_type')->get(); $type = DB::table('combo_type')->get();
$crowd=DB::table('combo_crowd')->get(); $crowd = DB::table('combo_crowd')->get();
$sort_list=[ $sort_list = [
["id"=>1,'name'=>'综合排序'], ["id" => 1, 'name' => '综合排序'],
["id"=>2,'name'=>'预约最多'], ["id" => 2, 'name' => '预约最多'],
["id"=>3,'name'=>'低价优先'], ["id" => 3, 'name' => '低价优先'],
["id"=>4,'name'=>'高价优先'], ["id" => 4, 'name' => '高价优先'],
]; ];
$price_list=[ $price_list = [
['name'=>'300以下','id'=>1], ['name' => '300以下', 'id' => 1],
['name'=>'300-1000','id'=>2], ['name' => '300-1000', 'id' => 2],
['name'=>'1000-1500','id'=>3], ['name' => '1000-1500', 'id' => 3],
['name'=>'1500-3000','id'=>4], ['name' => '1500-3000', 'id' => 4],
['name'=>'3000以上','id'=>5], ['name' => '3000以上', 'id' => 5],
]; ];
$item_label=[ $item_label = [
["id"=>1,'name'=>'一般检查'], ["id" => 1, 'name' => '一般检查'],
["id"=>2,'name'=>'血常规'], ["id" => 2, 'name' => '血常规'],
["id"=>3,'name'=>'尿常规'], ["id" => 3, 'name' => '尿常规'],
["id"=>4,'name'=>'肝功能'], ["id" => 4, 'name' => '肝功能'],
["id"=>5,'name'=>'肾功能'], ["id" => 5, 'name' => '肾功能'],
["id"=>6,'name'=>'血糖'] ["id" => 6, 'name' => '血糖']
]; ];
return \Yz::Return(true,"查询成功",['sort_list'=>$sort_list,'combo_type'=>$type,'combo_crowd'=>$crowd,'combo_price'=>$price_list,'combo_item'=>$item_label]); return \Yz::Return(true, "查询成功", ['sort_list' => $sort_list, 'combo_type' => $type, 'combo_crowd' => $crowd, 'combo_price' => $price_list, 'combo_item' => $item_label]);
} }
//获取购买详情内容(详情页信息) //获取购买详情内容(详情页信息)
public function BuyInfo() public function BuyInfo()
{ {
$hospital_id =request('hospital'); $hospital_id = request('hospital');
$combo_id =request('combo_id'); //购买的套餐id $combo_id = request('combo_id'); //购买的套餐id
$item_ids =request('item_ids'); //自选项目ids $item_ids = request('item_ids'); //自选项目ids
$group_id =request('group_id'); //团检登记id $group_id = request('group_id'); //团检登记id
if(!isset($hospital_id)) return \Yz::echoError1("医院id不能为空"); if (!isset($hospital_id)) return \Yz::echoError1("医院id不能为空");
$hospital=DB::table('hospitals')->where(['id'=>1,'status'=>1,'is_del'=>0])->first(); $hospital = DB::table('hospitals')->where(['id' => 1, 'status' => 1, 'is_del' => 0])->first();
$combo_info=[];//套餐信息 $combo_info = [];//套餐信息
$pay_item_count=0;//需自费项目个数 $pay_item_count = 0;//需自费项目个数
$all_original_price=0; $all_original_price = 0;
$true_price=0; $true_price = 0;
if(isset($combo_id) and $combo_id!=0){ if (isset($combo_id) and $combo_id != 0) {
// $combo=DB::table('combos')->where(['hospital_id'=>$hospital_id,'combo_id'=>$combo_id,'status'=>1])->first(); // $combo=DB::table('combos')->where(['hospital_id'=>$hospital_id,'combo_id'=>$combo_id,'status'=>1])->first();
$combo=DB::select("select a.*,b.*,c.name as crowd_name from combos as a LEFT JOIN ( $combo = DB::select("select a.*,b.*,c.name as crowd_name from combos as a LEFT JOIN (
select combo_id as c_id,count(*) as sale_count from orders where status in(2,4) group by combo_id select combo_id as c_id,count(*) as sale_count from orders where status in(2,4) group by combo_id
) as b on a.combo_id=b.c_id left join combo_crowd as c on a.crowd_id=c.id where a.combo_id=? and a.status=1 ",[$combo_id]); ) as b on a.combo_id=b.c_id left join combo_crowd as c on a.crowd_id=c.id where a.combo_id=? and a.status=1 ", [$combo_id]);
if(!$combo) return \Yz::echoError1("套餐不存在"); if (!$combo) return \Yz::echoError1("套餐不存在");
$combo=$combo[0]; $combo = $combo[0];
$combo_info['hospital_name']=$hospital->name; $combo_info['hospital_name'] = $hospital->name;
$combo_info['combo_name']=$combo->name; $combo_info['combo_name'] = $combo->name;
$combo_info['crowd_name']=$combo->crowd_name; $combo_info['crowd_name'] = $combo->crowd_name;
$combo_info['img']=$combo->cover; $combo_info['img'] = $combo->cover;
$combo_info['sale_count']=$combo->sale_count; $combo_info['sale_count'] = $combo->sale_count;
$tags=json_decode($combo->tags,true); $tags = json_decode($combo->tags, true);
$combo->tags2=json_decode($combo->tags2,true); $combo->tags2 = json_decode($combo->tags2, true);
foreach ($tags as$k=> $tag){ foreach ($tags as $k => $tag) {
$tags[$k]=['text'=>$tag, $tags[$k] = ['text' => $tag,
'text_color' => '#47ABD8', 'text_color' => '#47ABD8',
'color' => '#EBF5FC' 'color' => '#EBF5FC'
]; ];
} }
$combo->tag=$tags; $combo->tag = $tags;
$combo->tag[]=[ $combo->tag[] = [
'text' => $combo->item_count.'个项目', 'text' => $combo->item_count . '个项目',
'text_color' => '#34C292', 'text_color' => '#34C292',
'color' => '#E9F8F3', 'color' => '#E9F8F3',
]; ];
$combo_info['tags']=$combo->tag; $combo_info['tags'] = $combo->tag;
$combo_info['tags2']=$combo->tags2; $combo_info['tags2'] = $combo->tags2;
$combo_info['price']=$combo->price; $combo_info['price'] = $combo->price;
$combo_info['original_price']=$combo->original_price; $combo_info['original_price'] = $combo->original_price;
$all_original_price+=$combo_info['original_price']; $all_original_price += $combo_info['original_price'];
$combo_items=json_decode($combo->items,true); $combo_items = json_decode($combo->items, true);
$groupedData = []; $groupedData = [];
foreach ($combo_items as $item){ foreach ($combo_items as $item) {
$keshiName = $item['keshi_name']; $keshiName = $item['keshi_name'];
if (!isset($groupedData[$keshiName])) { if (!isset($groupedData[$keshiName])) {
$groupedData[$keshiName] = []; $groupedData[$keshiName] = [];
@ -251,61 +251,70 @@ select combo_id as c_id,count(*) as sale_count from orders where status in(2,4)
'children' => $children 'children' => $children
]; ];
} }
$pay_item_count+=$combo->item_count; $pay_item_count += $combo->item_count;
$true_price+=$combo_info['price']; $true_price += $combo_info['price'];
} }
$items_info=[];//自选项目信息 $items_info = [];//自选项目信息
if(isset($item_ids) and !empty($item_ids)){ if (isset($item_ids) and !empty($item_ids)) {
$price=0; $price = 0;
$items_original_price=0; $items_original_price = 0;
$items=DB::table('items')->whereIn('item_id',$item_ids)->where(['status'=>1])->get(); $items = DB::table('items')->whereIn('item_id', $item_ids)->where(['status' => 1])->get();
$groupedData = []; $groupedData = [];
foreach ($items as $item){ foreach ($items as $item) {
// $price=$price+$item->price; // $price=$price+$item->price;
$price= bcadd($price, $item->price, 2); $price = bcadd($price, $item->price, 2);
// $all_original_price+=$item->original_price; // $all_original_price+=$item->original_price;
$all_original_price=bcadd($all_original_price, $item->original_price, 2); $all_original_price = bcadd($all_original_price, $item->original_price, 2);
// $items_original_price+=$item->original_price; // $items_original_price+=$item->original_price;
$items_original_price=bcadd($items_original_price, $item->original_price, 2); $items_original_price = bcadd($items_original_price, $item->original_price, 2);
$keshiName = $item->keshi_name; $keshiName = $item->keshi_name;
if (!isset($groupedData[$keshiName])) { if (!isset($groupedData[$keshiName])) {
$groupedData[$keshiName] = []; $groupedData[$keshiName] = [];
} }
$groupedData[$keshiName][] = ['desc'=>$item->jianjie,'name'=>$item->name]; $groupedData[$keshiName][] = ['desc' => $item->jianjie, 'name' => $item->name];
} }
$items_info['price']=$price; $items_info['price'] = $price;
$items_info['original_price']=$items_original_price; $items_info['original_price'] = $items_original_price;
foreach ($groupedData as $keshiName => $children) { foreach ($groupedData as $keshiName => $children) {
$items_info['items'][] = [ $items_info['items'][] = [
'keshi_name' => $keshiName, 'keshi_name' => $keshiName,
'children' => $children 'children' => $children
]; ];
} }
$pay_item_count+=count($items); $pay_item_count += count($items);
$true_price+=$items_info['price']; $true_price += $items_info['price'];
} }
//调用his接口查询用户积分和预存款计算可以抵扣的金额 //调用his接口查询用户积分和预存款计算可以抵扣的金额
$integral_money = 90;//积分抵扣金额 $integral_money = 90;//积分抵扣金额
$save_money = 150;//预存款抵扣金额 $save_money = 150;//预存款抵扣金额
$coupon_money=50;//优惠券抵扣金额 $coupon_money = 50;//优惠券抵扣金额
//用户真实支付价格,应减去抵扣(二期实现) //用户真实支付价格,应减去抵扣(二期实现)
$group_info = false; $group_info = false;
$lose_price=0;
if (!!$group_id) { if (!!$group_id) {
$P=new PersonController(); $P = new PersonController();
$data = [ $data = [
'电话号码' => null, '电话号码' => null,
'证件号码' => null, '证件号码' => null,
'预约Id'=>$group_id '预约Id' => $group_id
]; ];
$group_info = $P->group_info($hospital_id,$data); $group_info = $P->group_info($hospital_id, $data);
if(count($group_info)==0) return \Yz::echoError1("获取团检登记信息失败");
//如果是团检统收限额大于0并且没有自带项目则判断剩余金额
if($group_info[0]['tongshou_xiane']>0 and count($group_info[0]['items'])==0){
$lose_price=$group_info[0]['tongshou_xiane']- $true_price;
if($lose_price<0) $lose_price=0;
}
$true_price = $true_price + $group_info[0]['sixi_zong_ji_jin_e'];
$true_price = ($true_price - $group_info[0]['tongshou_xiane']) > 0 ? $true_price - $group_info[0]['tongshou_xiane'] : 0;
$all_items=DB::table('items')->where(['status'=>1])->get(); $all_items = DB::table('items')->where(['status' => 1])->get();
$item_new=[]; $item_new = [];
foreach ($group_info[0]['items'] as $item) { foreach ($group_info[0]['items'] as $item) {
$item['keshi_name'] = '其他'; $item['keshi_name'] = '其他';
$item['desc'] = ''; $item['desc'] = '';
@ -316,18 +325,18 @@ select combo_id as c_id,count(*) as sale_count from orders where status in(2,4)
break; break;
} }
} }
$item_new[] =$item; $item_new[] = $item;
} }
$groupedData = []; $groupedData = [];
foreach ($item_new as $item){ foreach ($item_new as $item) {
$keshiName = $item['keshi_name']; $keshiName = $item['keshi_name'];
if (!isset($groupedData[$keshiName])) { if (!isset($groupedData[$keshiName])) {
$groupedData[$keshiName] = []; $groupedData[$keshiName] = [];
} }
$groupedData[$keshiName][] = ['desc'=>$item['desc'],'name'=>$item['name'],'id'=>$item['id'],'keshi_name'=>$item['keshi_name']]; $groupedData[$keshiName][] = ['desc' => $item['desc'], 'name' => $item['name'], 'id' => $item['id'], 'keshi_name' => $item['keshi_name']];
} }
$group_info[0]['items']=[];//清空原来的item $group_info[0]['items'] = [];//清空原来的item
foreach ($groupedData as $keshiName => $children) { foreach ($groupedData as $keshiName => $children) {
$group_info[0]['items'][] = [ $group_info[0]['items'][] = [
'keshi_name' => $keshiName, 'keshi_name' => $keshiName,
@ -337,70 +346,72 @@ select combo_id as c_id,count(*) as sale_count from orders where status in(2,4)
} }
$data=[ $data = [
'group_info'=>$group_info, 'group_info' => $group_info,
'combo_info'=>$combo_info, 'combo_info' => $combo_info,
'items_info'=>$items_info, 'items_info' => $items_info,
'integral_money'=>$integral_money, 'integral_money' => $integral_money,
'save_money'=>$save_money, 'save_money' => $save_money,
'coupon_money'=>$coupon_money, 'coupon_money' => $coupon_money,
'true_price'=>$true_price,//需要用户支付的金的 'true_price' => $true_price,//需要用户支付的金的
'original_price'=>$all_original_price,//总原价 'original_price' => $all_original_price,//总原价
'pay_item_count'=>$pay_item_count,//需要付费的项目数量 'pay_item_count' => $pay_item_count,//需要付费的项目数量
'nmr_list'=>[[ 'lose_price'=>$lose_price,//剩余的不用就会浪费的金额
'item_id'=>"1", 'nmr_list' => [[
"name"=>"磁共振平扫(腰椎)" 'item_id' => "1",
"name" => "磁共振平扫(腰椎)"
]]//核磁项目列表 ]]//核磁项目列表
]; ];
return \Yz::Return(true,"查询成功",$data); return \Yz::Return(true, "查询成功", $data);
} }
public function ComboCompare() public function ComboCompare()
{ {
$combo_ids =request('combo_ids'); //购买的套餐id $combo_ids = request('combo_ids'); //购买的套餐id
$combos=DB::table('combos as a') $combos = DB::table('combos as a')
->leftJoin('checkup_type as b','a.checkup_type_id','=','b.id') ->leftJoin('checkup_type as b', 'a.checkup_type_id', '=', 'b.id')
->select('a.*','b.name as checkup_type_name') ->select('a.*', 'b.name as checkup_type_name')
->whereIn('a.combo_id',$combo_ids)->where(['a.status'=>1])->get(); ->whereIn('a.combo_id', $combo_ids)->where(['a.status' => 1])->get();
foreach ($combos as $key =>$combo){ foreach ($combos as $key => $combo) {
$combo->items=json_decode($combo->items,true); $combo->items = json_decode($combo->items, true);
$count= DB::table('orders')->where(['combo_id'=>$combo->combo_id])->whereIn('status',[2,4])->count(); $count = DB::table('orders')->where(['combo_id' => $combo->combo_id])->whereIn('status', [2, 4])->count();
$combo->saleCount=$count; $combo->saleCount = $count;
} }
return \Yz::Return(true,"查询完成",['list'=>$combos]); return \Yz::Return(true, "查询完成", ['list' => $combos]);
} }
//推荐套餐 //推荐套餐
public function ComboRecommend() public function ComboRecommend()
{ {
$item_ids =request('item_ids'); //购买的套餐id $item_ids = request('item_ids'); //购买的套餐id
$person_id=request('person_id'); //就诊人id $person_id = request('person_id'); //就诊人id
$combos=DB::select("select * from combos as a LEFT JOIN ( $combos = DB::select("select * from combos as a LEFT JOIN (
select combo_id as c_id,count(*) as count from orders where status in(2,4) group by combo_id select combo_id as c_id,count(*) as count from orders where status in(2,4) group by combo_id
) as b on a.combo_id=b.c_id where a.status=1 and a.combo_id in ('2053','1135')"); ) as b on a.combo_id=b.c_id where a.status=1 and a.combo_id in ('2053','1135')");
foreach ($combos as $key=>$combo){ foreach ($combos as $key => $combo) {
$tags=json_decode($combo->tags,true); $tags = json_decode($combo->tags, true);
$combo->tags2=json_decode($combo->tags2,true); $combo->tags2 = json_decode($combo->tags2, true);
foreach ($tags as$k=> $tag){ foreach ($tags as $k => $tag) {
$tags[$k]=['text'=>$tag, $tags[$k] = ['text' => $tag,
'text_color' => '#47ABD8', 'text_color' => '#47ABD8',
'color' => '#EBF5FC' 'color' => '#EBF5FC'
]; ];
} }
$combo->tags=$tags; $combo->tags = $tags;
$combo->tags[]=[ $combo->tags[] = [
'text' => $combo->item_count.'个项目', 'text' => $combo->item_count . '个项目',
'text_color' => '#34C292', 'text_color' => '#34C292',
'color' => '#E9F8F3', 'color' => '#E9F8F3',
]; ];
$combo->recommend=[ $combo->recommend = [
'xiangsidu'=>'80%', 'xiangsidu' => '80%',
'count'=>"-5", 'count' => "-5",
'money'=>"-150" 'money' => "-150"
]; ];
} }
return \Yz::Return(true,"查询完成",['combos'=>$combos]); return \Yz::Return(true, "查询完成", ['combos' => $combos]);
} }
} }

Loading…
Cancel
Save