uid())->find(); if ($user['member'] == 0){ if ($user['frequency'] == 0 and $user['free'] == 0){ return app('json')->fail('查询次数已用完'); } } //顶板 $calculation = $this->calculation($data); $amount = $this->AmountOfMoney($calculation, $data);// 计算总价,表格 Db::startTrans(); try { $res = WaterQuery::create([ 'uid' => $request->uid(), 'long' => $data['long'], 'wide' => $data['wide'], 'high' => $data['high'], 'is_warm' => $data['is_warm'], 'is_channel' => $data['is_channel'], 'is_ladder' => $data['is_human_ladder'], 'is_gc' => $data['is_gc'], 'price' => $amount['zj'], 'weight' => $amount['zzl'], ]); foreach ($amount['table'] as $item){ $item['query_id'] = $res['id']; WaterMaterial::create($item); } if ($user['member'] == 0){ if ($user['free'] > 0){ User::where('uid', $request->uid())->dec('free', 1)->update(); }else{ User::where('uid', $request->uid())->dec('frequency', 1)->update(); } } Db::commit(); return app('json')->success($amount); } catch (\Exception $e) { Db::rollback(); return app('json')->fail($e->getMessage()); } } public function AmountOfMoney($calculation, $data) { $table = []; $zj = 0; //总价 $zzl = 0; // 总重量 if ($data['is_gc'] > 0){ $where[] = ['is_gc', '=' ,1]; }else{ $where[] = ['is_gc', '=' ,0]; } foreach ($calculation['roof_number'] as $k => $v){ if ($k == '1*1'){ $details = WaterMaterialScience::where('cate_id', $data['roof'])->where($where)->where([['long', '=', 1], ['wide', '=', 1]])->find(); $zj += $details['unit_price'] * $v; $zzl += $details['weight'] * $v; $table[] = ['title' => '顶板', 'name' => $details['name'], 'specifications' => $details['long'].'*'.$details['wide'], 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v ,'type' => 1]; }elseif ($k == '1*0.5'){ $details = WaterMaterialScience::where('cate_id', $data['roof'])->where($where)->where([['long', '=', 1], ['wide', '=', 0.5]])->find(); $zj += $details['unit_price'] * $v; $zzl += $details['weight'] * $v; $table[] = ['title' => '顶板','name' => $details['name'], 'specifications' => $details['long'].'*'.$details['wide'], 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v ,'type' => 1]; }elseif ($k == '0.5*0.5'){ $details = WaterMaterialScience::where('cate_id', $data['roof'])->where($where)->where([['long', '=', 0.5], ['wide', '=', 0.5]])->find(); $zj += $details['unit_price'] * $v; $zzl += $details['weight'] * $v; $table[] = ['title' => '顶板','name' => $details['name'], 'specifications' => $details['long'].'*'.$details['wide'], 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 1]; } } // 底板 foreach ($calculation['floor_number'] as $k => $v){ if ($k == '1*1'){ $details = WaterMaterialScience::where('cate_id', $data['floor'])->where($where)->where([['long', '=', 1], ['wide', '=', 1]])->find(); $zj += $details['unit_price'] * $v; $zzl += $details['weight'] * $v; $table[] = ['title' => '底板','name' => $details['name'], 'specifications' => $details['long'].'*'.$details['wide'], 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v ,'type' => 4]; }elseif ($k == '1*0.5'){ $details = WaterMaterialScience::where('cate_id', $data['floor'])->where($where)->where([['long', '=', 1], ['wide', '=', 0.5]])->find(); $zj += $details['unit_price'] * $v; $zzl += $details['weight'] * $v; $table[] = ['title' => '底板','name' => $details['name'], 'specifications' => $details['long'].'*'.$details['wide'], 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v ,'type' => 4]; }elseif ($k == '0.5*0.5'){ $details = WaterMaterialScience::where('cate_id', $data['floor'])->where($where)->where([['long', '=', 0.5], ['wide', '=', 0.5]])->find(); $zj += $details['unit_price'] * $v; $zzl += $details['weight'] * $v; $table[] = ['title' => '底板','name' => $details['name'], 'specifications' => $details['long'].'*'.$details['wide'], 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 4]; } } // 侧板 $storey = 0; foreach ($calculation['side_number'] as $item){ $storey ++; foreach ($item as $k => $v){ if ($k == '1*1'){ $details = WaterMaterialScience::where('cate_id', $data['side_plate'][$storey-1])->where($where)->where([['long', '=', 1], ['wide', '=', 1]])->find(); $zj += $details['unit_price'] * $v; $zzl += $details['weight'] * $v; $table[] = ['title' => '侧板B'.$storey.'层' , 'name' => $details['name'], 'specifications' => $details['long'].'*'.$details['wide'], 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 2]; }elseif ($k == '1*0.5'){ $details = WaterMaterialScience::where('cate_id', $data['side_plate'][$storey-1])->where($where)->where([['long', '=', 1], ['wide', '=', 0.5]])->find(); $zj += $details['unit_price'] * $v; $zzl += $details['weight'] * $v; $table[] = ['title' => '侧板B'.$storey.'层' , 'name' => $details['name'], 'specifications' => $details['long'].'*'.$details['wide'], 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 2]; }elseif ($k == '0.5*0.5'){ $details = WaterMaterialScience::where('cate_id', $data['side_plate'][$storey-1])->where($where)->where([['long', '=', 0.5], ['wide', '=', 0.5]])->find(); $zj += $details['unit_price'] * $v; $zzl += $details['weight'] * $v; $table[] = ['title' => '侧板B'.$storey.'层' , 'name' => $details['name'], 'specifications' => $details['long'].'*'.$details['wide'], 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 2]; } } } //拉筋 $lac_storey = 0; foreach ($calculation['lacing_number'] as $v){ $lac_storey ++; $details = WaterMaterialScience::where('cate_id', $data['lacing'][$lac_storey-1])->where($where)->find(); $zj += $details['unit_price'] * $v; $zzl += $details['weight'] * $v; $table[] = ['title' => '辅拉B'.$lac_storey.'层' , 'name' => $details['name'], 'specifications' => '1', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 3]; } $fula_storey = 0; foreach ($calculation['fula_number'] as $v){ $fula_storey ++; $details = WaterMaterialScience::where('cate_id', $data['fula'][$fula_storey-1])->where($where)->find(); $zj += $details['unit_price'] * $v; $zzl += $details['weight'] * $v; $table[] = ['title' => '辅拉B'.$fula_storey.'层' , 'name' => $details['name'], 'specifications' => '1', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 6]; } // 立柱 $details = WaterMaterialScience::where('cate_id', $data['column'])->where($where)->find(); $zj += $details['unit_price'] * $calculation['column_number']; $zzl += $details['weight'] * $calculation['column_number']; $table[] = ['title' => '立柱' , 'name' => $details['name'], 'specifications' => '1', 'number' => $calculation['column_number'], 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $calculation['column_number'], 'weight' => $details['weight'] * $calculation['column_number'] , 'type' => 5]; //保温 foreach ($calculation['warm'] as $k => $v){ if ($k == 'warm1' and $v > 0){ $details = WaterMaterialScience::where('cate_id', $data['is_warm'])->where([['long', '=', 1], ['wide', '=', 1]])->where($where)->find(); $zj += $details['unit_price'] * $v; $zzl += $details['weight'] * $v; $table[] = ['title' => '保温板' , 'name' => $details['name'], 'specifications' => '1*1', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 7]; }elseif ($k == 'warm2' and $v > 0){ $details = WaterMaterialScience::where('cate_id', $data['is_warm'])->where([['long', '=', 1], ['wide', '=', 0.5]])->where($where)->find(); $zj += $details['unit_price'] * $v; $zzl += $details['weight'] * $v; $table[] = ['title' => '保温板' , 'name' => $details['name'], 'specifications' => '1*0.5', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 7]; }elseif ($k == 'warm3' and $v > 0){ $details = WaterMaterialScience::where('cate_id', $data['is_warm'])->where([['long', '=', 0.5], ['wide', '=', 0.5]])->where($where)->find(); $zj += $details['unit_price'] * $v; $zzl += $details['weight'] * $v; $table[] = ['title' => '保温板' , 'name' => $details['name'], 'specifications' => '0.5*0.5', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 7]; } } //槽钢 if ($data['is_channel'] > 0){ $details = WaterMaterialScience::where('cate_id', $data['is_channel'])->where($where)->find(); $zj += $details['unit_price'] * $calculation['channel_number']; $zzl += $details['weight'] * $calculation['channel_number']; $table[] = ['title' => '槽钢' , 'name' => $details['name'], 'specifications' => '1', 'number' => $calculation['channel_number'], 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $calculation['channel_number'], 'weight' => $details['weight'] * $calculation['channel_number'] , 'type' => 8]; } // 扶梯 if ($data['is_human_ladder'] > 0){ $details = WaterMaterialScience::where('cate_id', 9)->find(); $zj += $details['unit_price'] * $calculation['ladder']; $zzl += $details['weight'] * $calculation['ladder']; $table[] = ['title' => '扶梯' , 'name' => $details['name'], 'specifications' => '1', 'number' => $calculation['ladder'], 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $calculation['ladder'], 'weight' => $details['weight'] * $calculation['ladder'] , 'type' => 9]; } return ['table' => $table, 'zj' => $zj, 'zzl' => $zzl]; } /**计算使用材料数量 * @param $data * @return array */ public function calculation($data) { $long = (double)$data['long']; $wide = (double)$data['wide']; $high = (double)$data['high']; $high_array = []; // 高度数组 $roof_number = []; // 顶板数量 $floor_number = []; // 底板数量 $side_number = []; // 侧板数量 $lacing_number = []; // 拉经数量 $fula_number = [];//辅拉数量 $column_number = 0;// 立柱数量 $channel_number = 0; // 槽钢 $ladder = 0;// 扶梯管米数 for ($i = 0; $i < intval($high); $i++){ $high_array[] = 1; } if (intval($high) != $high){ $high_array = array_merge($high_array, [0.5]); } if (ceil($long) == $long && ceil($wide) == $wide && ceil($high) == $high){ //都为整数 $roof_number = ['1*1' => $long * $wide]; // 顶板数量 $floor_number = ['1*1' => $long * $wide];// 底板数量 foreach ($high_array as $item){ $side_number[] = ['1*1' => (($item * $long) + ($item * $wide)) * 2]; } }elseif (ceil($long) != $long && ceil($wide) != $wide && ceil($high) != $high){ //都不为整数 $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1]; // 顶板数量 $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1];// 底板数量 foreach ($high_array as $item){ if ($item >= 1){ $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 4]; }else{ $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2, '0.5*0.5' => 4]; } } }elseif (ceil($long) != $long || ceil($wide) != $wide || ceil($high) != $high){ //一个整数 if (ceil($long) != $long && ceil($wide) == $wide && ceil($high) == $high){ $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $wide]; // 顶板数量 $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $wide];// 底板数量 foreach ($high_array as $item){ $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2]; } }elseif (ceil($long) == $long && ceil($wide) != $wide and ceil($high) == $high){ $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long]; // 顶板数量 $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long];// 底板数量 foreach ($high_array as $item){ $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2]; } }elseif (ceil($long) != $long && ceil($wide) != $wide and ceil($high) == $high){ $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1]; // 顶板数量 $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1];// 底板数量 foreach ($high_array as $item){ $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 4]; } } elseif (ceil($long) != $long && ceil($wide) == $wide and ceil($high) != $high){ $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $wide]; // 顶板数量 $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $wide];// 底板数量 foreach ($high_array as $item){ if ($item >= 1){ $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2]; }else{ $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2, '0.5*0.5' => 2]; } } }elseif (ceil($long) == $long && ceil($wide) != $wide and ceil($high) != $high){ $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long]; // 顶板数量 $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long];// 底板数量 foreach ($high_array as $item){ if ($item >= 1){ $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2]; }else{ $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2, '0.5*0.5' => 2]; } } }elseif (ceil($long) == $long && ceil($wide) == $wide and ceil($high) != $high){ $roof_number = ['1*1' => $long * $wide]; // 顶板数量 $floor_number = ['1*1' => $long * $wide];// 底板数量 foreach ($high_array as $item){ if ($item >= 1){ $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2]; }else{ $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2]; } } } } array_pop($high_array);// 删除最后一位,算出主拉层数 // 拉筋 foreach ($high_array as $item){ $lacing_number[] = ceil((($long * (ceil($wide) - 1)) + ($wide * (ceil($long) - 1)))/2); } // 辅拉 if ($high > 1){ if ($high == 1.5){ $fula_number = [2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1]; }elseif ($high == 2){ $fula_number = [3 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1]; }elseif ($high == 2.5){ $fula_number = [ 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1, 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1, ]; }elseif ($high == 3){ $fula_number = [ 3 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1, 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1, ]; }elseif ($high >= 3.5){ foreach ($high_array as $item){ $fula_number[] = 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1; } } } //立柱 $column_number = ceil((ceil($long) - 1) * (ceil($wide) -1) * $wide / 2); //保温板数量 $warm1 = 0;// 1*1 数量 $warm2 = 0;// 1*0.5数量 $warm3 = 0;// 0.5*0.5数量 if ($data['is_warm'] > 0){ foreach ($side_number as $item){ // 侧板 foreach ($item as $key => $value){ if ($key == '1*1'){ $warm1 += $value; }elseif ($key == '1*0.5'){ $warm2 += $value; }elseif ($key == '0.5*0.5'){ $warm3 += $value; } } } foreach ($floor_number as $key => $value){ // 顶板 if ($key == '1*1'){ $warm1 += $value; }elseif ($key == '1*0.5'){ $warm2 += $value; }elseif ($key == '0.5*0.5'){ $warm3 += $value; } } } //槽钢 if ($data['is_channel'] > 0){ if (ceil($long) == $long && ceil($wide) == $wide && ceil($high) == $high){ //都为整数 $channel_number = $long * ($wide * 2 + 1) + $wide * 2; }elseif (ceil($long) != $long || ceil($wide) || $wide && ceil($high) || $high){ //不为整数 $channel_number = $long * (ceil($wide) * 2 + 1) + $wide * 2; } } // 扶梯管 if ($data['is_human_ladder'] > 0){ if ($high <= 1.5){ $ladder = 5; }elseif ($high == 2){ $ladder = 7; }elseif ($high >= 2.5){ $ladder = $high * 4; } } $calculation = [ 'roof_number' => $roof_number,// 顶板 'floor_number' => $floor_number,// 底板 'side_number' => $side_number,// 侧板 'lacing_number' => $lacing_number,// 拉筋 'fula_number' => $fula_number,// 辅拉 'column_number' => $column_number,// 立柱 'warm' => ['warm1' => $warm1,'warm2' => $warm2,'warm3' => $warm3],// 保温 'channel_number' => $channel_number,// 槽钢 'ladder' => $ladder,// 保温 ]; return $calculation; } /** * 材料列表 * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function list() { $list = []; $list['warm'] = WaterCate::field('id,name')->where('type', 7)->select(); // 保温 $list['channel'] = WaterCate::field('id,name')->where('type', 8)->select(); // 槽钢 $list['roof'] = WaterCate::field('id,name')->where('type', 1)->select();// 顶板 $list['side_plate'] = WaterCate::field('id,name')->where('type', 2)->select();// 侧板 $list['lacing'] = WaterCate::field('id,name')->where('type', 3)->select();// 拉筋 $list['floor'] = WaterCate::field('id,name')->where('type', 4)->select(); // 底板 $list['column'] = WaterCate::field('id,name')->where('type', 5)->select(); // 立柱 $list['fula'] = WaterCate::field('id,name')->where('type', 6)->select(); // 辅拉 return app('json')->success($list); } /** * 计算记录 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function query_list(Request $request) { $list = WaterQuery::where('uid', $request->uid())->select(); $list = count($list) > 0 ? $list->toArray(): []; return app('json')->success($list); } /** * 计算详情 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function query_details(Request $request) { $data = UtilService::getMore(['id']); if (!$data['id']) return app('json')->fail('传入正确参数'); $list = WaterMaterial::where('query_id', $data['id'])->select(); return app('json')->success($list->toArray()); } }