WaterQueryController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <?php
  2. namespace app\api\controller\water;
  3. use app\admin\model\water\WaterCate;
  4. use app\admin\model\water\WaterMaterial;
  5. use app\admin\model\water\WaterMaterialScience;
  6. use app\admin\model\water\WaterQuery;
  7. use app\models\user\User;
  8. use app\Request;
  9. use crmeb\services\GroupDataService;
  10. use crmeb\services\QrcodeService;
  11. use crmeb\services\UtilService;
  12. use think\facade\Db;
  13. /**
  14. * 秒杀产品类
  15. * Class StoreSeckillController
  16. * @package app\api\controller\activity
  17. */
  18. class WaterQueryController
  19. {
  20. public function query(Request $request)
  21. {
  22. $data = UtilService::postMore([
  23. ['long', ''],// 长
  24. ['wide', ''],// 宽
  25. ['high', ''],// 高
  26. ['is_warm', ''], // 是否保温
  27. ['is_channel', ''], // 是否需要槽钢
  28. ['is_human_ladder', ''] ,// 是否需要人梯
  29. ['is_gc', ''] ,// 公差
  30. ['roof', ''], // 顶板厚度
  31. ['floor', ''], // 底板厚度
  32. ['side_plate', []], // 侧板厚度
  33. ['column', ''], // 立柱厚度
  34. ['lacing', []], // 拉筋厚度
  35. ['fula', []], // 辅拉
  36. ]);
  37. $user = User::where('uid', $request->uid())->find();
  38. if ($user['member'] == 0){
  39. if ($user['frequency'] == 0 and $user['free'] == 0){
  40. return app('json')->fail('查询次数已用完');
  41. }
  42. }
  43. //顶板
  44. $calculation = $this->calculation($data);
  45. $amount = $this->AmountOfMoney($calculation, $data);// 计算总价,表格
  46. Db::startTrans();
  47. try {
  48. $res = WaterQuery::create([
  49. 'uid' => $request->uid(),
  50. 'long' => $data['long'],
  51. 'wide' => $data['wide'],
  52. 'high' => $data['high'],
  53. 'is_warm' => $data['is_warm'],
  54. 'is_channel' => $data['is_channel'],
  55. 'is_ladder' => $data['is_human_ladder'],
  56. 'is_gc' => $data['is_gc'],
  57. 'price' => $amount['zj'],
  58. 'weight' => $amount['zzl'],
  59. ]);
  60. foreach ($amount['table'] as $item){
  61. $item['query_id'] = $res['id'];
  62. WaterMaterial::create($item);
  63. }
  64. if ($user['member'] == 0){
  65. if ($user['free'] > 0){
  66. User::where('uid', $request->uid())->dec('free', 1)->update();
  67. }else{
  68. User::where('uid', $request->uid())->dec('frequency', 1)->update();
  69. }
  70. }
  71. Db::commit();
  72. return app('json')->success($amount);
  73. } catch (\Exception $e) {
  74. Db::rollback();
  75. return app('json')->fail($e->getMessage());
  76. }
  77. }
  78. public function AmountOfMoney($calculation, $data)
  79. {
  80. $table = [];
  81. $zj = 0; //总价
  82. $zzl = 0; // 总重量
  83. if ($data['is_gc'] > 0){
  84. $where[] = ['is_gc', '=' ,1];
  85. }else{
  86. $where[] = ['is_gc', '=' ,0];
  87. }
  88. foreach ($calculation['roof_number'] as $k => $v){
  89. if ($k == '1*1'){
  90. $details = WaterMaterialScience::where('cate_id', $data['roof'])->where($where)->where([['long', '=', 1], ['wide', '=', 1]])->find();
  91. $zj += $details['unit_price'] * $v;
  92. $zzl += $details['weight'] * $v;
  93. $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];
  94. }elseif ($k == '1*0.5'){
  95. $details = WaterMaterialScience::where('cate_id', $data['roof'])->where($where)->where([['long', '=', 1], ['wide', '=', 0.5]])->find();
  96. $zj += $details['unit_price'] * $v;
  97. $zzl += $details['weight'] * $v;
  98. $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];
  99. }elseif ($k == '0.5*0.5'){
  100. $details = WaterMaterialScience::where('cate_id', $data['roof'])->where($where)->where([['long', '=', 0.5], ['wide', '=', 0.5]])->find();
  101. $zj += $details['unit_price'] * $v;
  102. $zzl += $details['weight'] * $v;
  103. $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];
  104. }
  105. }
  106. // 底板
  107. foreach ($calculation['floor_number'] as $k => $v){
  108. if ($k == '1*1'){
  109. $details = WaterMaterialScience::where('cate_id', $data['floor'])->where($where)->where([['long', '=', 1], ['wide', '=', 1]])->find();
  110. $zj += $details['unit_price'] * $v;
  111. $zzl += $details['weight'] * $v;
  112. $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];
  113. }elseif ($k == '1*0.5'){
  114. $details = WaterMaterialScience::where('cate_id', $data['floor'])->where($where)->where([['long', '=', 1], ['wide', '=', 0.5]])->find();
  115. $zj += $details['unit_price'] * $v;
  116. $zzl += $details['weight'] * $v;
  117. $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];
  118. }elseif ($k == '0.5*0.5'){
  119. $details = WaterMaterialScience::where('cate_id', $data['floor'])->where($where)->where([['long', '=', 0.5], ['wide', '=', 0.5]])->find();
  120. $zj += $details['unit_price'] * $v;
  121. $zzl += $details['weight'] * $v;
  122. $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];
  123. }
  124. }
  125. // 侧板
  126. $storey = 0;
  127. foreach ($calculation['side_number'] as $item){
  128. $storey ++;
  129. foreach ($item as $k => $v){
  130. if ($k == '1*1'){
  131. $details = WaterMaterialScience::where('cate_id', $data['side_plate'][$storey-1])->where($where)->where([['long', '=', 1], ['wide', '=', 1]])->find();
  132. $zj += $details['unit_price'] * $v;
  133. $zzl += $details['weight'] * $v;
  134. $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];
  135. }elseif ($k == '1*0.5'){
  136. $details = WaterMaterialScience::where('cate_id', $data['side_plate'][$storey-1])->where($where)->where([['long', '=', 1], ['wide', '=', 0.5]])->find();
  137. $zj += $details['unit_price'] * $v;
  138. $zzl += $details['weight'] * $v;
  139. $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];
  140. }elseif ($k == '0.5*0.5'){
  141. $details = WaterMaterialScience::where('cate_id', $data['side_plate'][$storey-1])->where($where)->where([['long', '=', 0.5], ['wide', '=', 0.5]])->find();
  142. $zj += $details['unit_price'] * $v;
  143. $zzl += $details['weight'] * $v;
  144. $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];
  145. }
  146. }
  147. }
  148. //拉筋
  149. $lac_storey = 0;
  150. foreach ($calculation['lacing_number'] as $v){
  151. $lac_storey ++;
  152. $details = WaterMaterialScience::where('cate_id', $data['lacing'][$lac_storey-1])->where($where)->find();
  153. $zj += $details['unit_price'] * $v;
  154. $zzl += $details['weight'] * $v;
  155. $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];
  156. }
  157. $fula_storey = 0;
  158. foreach ($calculation['fula_number'] as $v){
  159. $fula_storey ++;
  160. $details = WaterMaterialScience::where('cate_id', $data['fula'][$fula_storey-1])->where($where)->find();
  161. $zj += $details['unit_price'] * $v;
  162. $zzl += $details['weight'] * $v;
  163. $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];
  164. }
  165. // 立柱
  166. $details = WaterMaterialScience::where('cate_id', $data['column'])->where($where)->find();
  167. $zj += $details['unit_price'] * $calculation['column_number'];
  168. $zzl += $details['weight'] * $calculation['column_number'];
  169. $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];
  170. //保温
  171. foreach ($calculation['warm'] as $k => $v){
  172. if ($k == 'warm1' and $v > 0){
  173. $details = WaterMaterialScience::where('cate_id', $data['is_warm'])->where([['long', '=', 1], ['wide', '=', 1]])->where($where)->find();
  174. $zj += $details['unit_price'] * $v;
  175. $zzl += $details['weight'] * $v;
  176. $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];
  177. }elseif ($k == 'warm2' and $v > 0){
  178. $details = WaterMaterialScience::where('cate_id', $data['is_warm'])->where([['long', '=', 1], ['wide', '=', 0.5]])->where($where)->find();
  179. $zj += $details['unit_price'] * $v;
  180. $zzl += $details['weight'] * $v;
  181. $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];
  182. }elseif ($k == 'warm3' and $v > 0){
  183. $details = WaterMaterialScience::where('cate_id', $data['is_warm'])->where([['long', '=', 0.5], ['wide', '=', 0.5]])->where($where)->find();
  184. $zj += $details['unit_price'] * $v;
  185. $zzl += $details['weight'] * $v;
  186. $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];
  187. }
  188. }
  189. //槽钢
  190. if ($data['is_channel'] > 0){
  191. $details = WaterMaterialScience::where('cate_id', $data['is_channel'])->where($where)->find();
  192. $zj += $details['unit_price'] * $calculation['channel_number'];
  193. $zzl += $details['weight'] * $calculation['channel_number'];
  194. $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];
  195. }
  196. // 扶梯
  197. if ($data['is_human_ladder'] > 0){
  198. $details = WaterMaterialScience::where('cate_id', 9)->find();
  199. $zj += $details['unit_price'] * $calculation['ladder'];
  200. $zzl += $details['weight'] * $calculation['ladder'];
  201. $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];
  202. }
  203. return ['table' => $table, 'zj' => $zj, 'zzl' => $zzl];
  204. }
  205. /**计算使用材料数量
  206. * @param $data
  207. * @return array
  208. */
  209. public function calculation($data)
  210. {
  211. $long = (double)$data['long'];
  212. $wide = (double)$data['wide'];
  213. $high = (double)$data['high'];
  214. $high_array = []; // 高度数组
  215. $roof_number = []; // 顶板数量
  216. $floor_number = []; // 底板数量
  217. $side_number = []; // 侧板数量
  218. $lacing_number = []; // 拉经数量
  219. $fula_number = [];//辅拉数量
  220. $column_number = 0;// 立柱数量
  221. $channel_number = 0; // 槽钢
  222. $ladder = 0;// 扶梯管米数
  223. for ($i = 0; $i < intval($high); $i++){
  224. $high_array[] = 1;
  225. }
  226. if (intval($high) != $high){
  227. $high_array = array_merge($high_array, [0.5]);
  228. }
  229. if (ceil($long) == $long && ceil($wide) == $wide && ceil($high) == $high){
  230. //都为整数
  231. $roof_number = ['1*1' => $long * $wide]; // 顶板数量
  232. $floor_number = ['1*1' => $long * $wide];// 底板数量
  233. foreach ($high_array as $item){
  234. $side_number[] = ['1*1' => (($item * $long) + ($item * $wide)) * 2];
  235. }
  236. }elseif (ceil($long) != $long && ceil($wide) != $wide && ceil($high) != $high){
  237. //都不为整数
  238. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1]; // 顶板数量
  239. $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1];// 底板数量
  240. foreach ($high_array as $item){
  241. if ($item >= 1){
  242. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 4];
  243. }else{
  244. $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2, '0.5*0.5' => 4];
  245. }
  246. }
  247. }elseif (ceil($long) != $long || ceil($wide) != $wide || ceil($high) != $high){
  248. //一个整数
  249. if (ceil($long) != $long && ceil($wide) == $wide && ceil($high) == $high){
  250. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $wide]; // 顶板数量
  251. $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $wide];// 底板数量
  252. foreach ($high_array as $item){
  253. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2];
  254. }
  255. }elseif (ceil($long) == $long && ceil($wide) != $wide and ceil($high) == $high){
  256. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long]; // 顶板数量
  257. $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long];// 底板数量
  258. foreach ($high_array as $item){
  259. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2];
  260. }
  261. }elseif (ceil($long) != $long && ceil($wide) != $wide and ceil($high) == $high){
  262. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1]; // 顶板数量
  263. $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1];// 底板数量
  264. foreach ($high_array as $item){
  265. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 4];
  266. }
  267. } elseif (ceil($long) != $long && ceil($wide) == $wide and ceil($high) != $high){
  268. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $wide]; // 顶板数量
  269. $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $wide];// 底板数量
  270. foreach ($high_array as $item){
  271. if ($item >= 1){
  272. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2];
  273. }else{
  274. $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2, '0.5*0.5' => 2];
  275. }
  276. }
  277. }elseif (ceil($long) == $long && ceil($wide) != $wide and ceil($high) != $high){
  278. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long]; // 顶板数量
  279. $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long];// 底板数量
  280. foreach ($high_array as $item){
  281. if ($item >= 1){
  282. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2];
  283. }else{
  284. $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2, '0.5*0.5' => 2];
  285. }
  286. }
  287. }elseif (ceil($long) == $long && ceil($wide) == $wide and ceil($high) != $high){
  288. $roof_number = ['1*1' => $long * $wide]; // 顶板数量
  289. $floor_number = ['1*1' => $long * $wide];// 底板数量
  290. foreach ($high_array as $item){
  291. if ($item >= 1){
  292. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2];
  293. }else{
  294. $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2];
  295. }
  296. }
  297. }
  298. }
  299. array_pop($high_array);// 删除最后一位,算出主拉层数
  300. // 拉筋
  301. foreach ($high_array as $item){
  302. $lacing_number[] = ceil((($long * (ceil($wide) - 1)) + ($wide * (ceil($long) - 1)))/2);
  303. }
  304. // 辅拉
  305. if ($high > 1){
  306. if ($high == 1.5){
  307. $fula_number = [2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1];
  308. }elseif ($high == 2){
  309. $fula_number = [3 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1];
  310. }elseif ($high == 2.5){
  311. $fula_number = [
  312. 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1,
  313. 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1,
  314. ];
  315. }elseif ($high == 3){
  316. $fula_number = [
  317. 3 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1,
  318. 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1,
  319. ];
  320. }elseif ($high >= 3.5){
  321. foreach ($high_array as $item){
  322. $fula_number[] = 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1;
  323. }
  324. }
  325. }
  326. //立柱
  327. $column_number = ceil((ceil($long) - 1) * (ceil($wide) -1) * $wide / 2);
  328. //保温板数量
  329. $warm1 = 0;// 1*1 数量
  330. $warm2 = 0;// 1*0.5数量
  331. $warm3 = 0;// 0.5*0.5数量
  332. if ($data['is_warm'] > 0){
  333. foreach ($side_number as $item){
  334. // 侧板
  335. foreach ($item as $key => $value){
  336. if ($key == '1*1'){
  337. $warm1 += $value;
  338. }elseif ($key == '1*0.5'){
  339. $warm2 += $value;
  340. }elseif ($key == '0.5*0.5'){
  341. $warm3 += $value;
  342. }
  343. }
  344. }
  345. foreach ($floor_number as $key => $value){
  346. // 顶板
  347. if ($key == '1*1'){
  348. $warm1 += $value;
  349. }elseif ($key == '1*0.5'){
  350. $warm2 += $value;
  351. }elseif ($key == '0.5*0.5'){
  352. $warm3 += $value;
  353. }
  354. }
  355. }
  356. //槽钢
  357. if ($data['is_channel'] > 0){
  358. if (ceil($long) == $long && ceil($wide) == $wide && ceil($high) == $high){
  359. //都为整数
  360. $channel_number = $long * ($wide * 2 + 1) + $wide * 2;
  361. }elseif (ceil($long) != $long || ceil($wide) || $wide && ceil($high) || $high){
  362. //不为整数
  363. $channel_number = $long * (ceil($wide) * 2 + 1) + $wide * 2;
  364. }
  365. }
  366. // 扶梯管
  367. if ($data['is_human_ladder'] > 0){
  368. if ($high <= 1.5){
  369. $ladder = 5;
  370. }elseif ($high == 2){
  371. $ladder = 7;
  372. }elseif ($high >= 2.5){
  373. $ladder = $high * 4;
  374. }
  375. }
  376. $calculation = [
  377. 'roof_number' => $roof_number,// 顶板
  378. 'floor_number' => $floor_number,// 底板
  379. 'side_number' => $side_number,// 侧板
  380. 'lacing_number' => $lacing_number,// 拉筋
  381. 'fula_number' => $fula_number,// 辅拉
  382. 'column_number' => $column_number,// 立柱
  383. 'warm' => ['warm1' => $warm1,'warm2' => $warm2,'warm3' => $warm3],// 保温
  384. 'channel_number' => $channel_number,// 槽钢
  385. 'ladder' => $ladder,// 保温
  386. ];
  387. return $calculation;
  388. }
  389. /**
  390. * 材料列表
  391. * @return mixed
  392. * @throws \think\db\exception\DataNotFoundException
  393. * @throws \think\db\exception\DbException
  394. * @throws \think\db\exception\ModelNotFoundException
  395. */
  396. public function list()
  397. {
  398. $list = [];
  399. $list['warm'] = WaterCate::field('id,name')->where('type', 7)->select(); // 保温
  400. $list['channel'] = WaterCate::field('id,name')->where('type', 8)->select(); // 槽钢
  401. $list['roof'] = WaterCate::field('id,name')->where('type', 1)->select();// 顶板
  402. $list['side_plate'] = WaterCate::field('id,name')->where('type', 2)->select();// 侧板
  403. $list['lacing'] = WaterCate::field('id,name')->where('type', 3)->select();// 拉筋
  404. $list['floor'] = WaterCate::field('id,name')->where('type', 4)->select(); // 底板
  405. $list['column'] = WaterCate::field('id,name')->where('type', 5)->select(); // 立柱
  406. $list['fula'] = WaterCate::field('id,name')->where('type', 6)->select(); // 辅拉
  407. return app('json')->success($list);
  408. }
  409. /**
  410. * 计算记录
  411. * @param Request $request
  412. * @return mixed
  413. * @throws \think\db\exception\DataNotFoundException
  414. * @throws \think\db\exception\DbException
  415. * @throws \think\db\exception\ModelNotFoundException
  416. */
  417. public function query_list(Request $request)
  418. {
  419. $list = WaterQuery::where('uid', $request->uid())->select();
  420. $list = count($list) > 0 ? $list->toArray(): [];
  421. return app('json')->success($list);
  422. }
  423. /**
  424. * 计算详情
  425. * @param Request $request
  426. * @return mixed
  427. * @throws \think\db\exception\DataNotFoundException
  428. * @throws \think\db\exception\DbException
  429. * @throws \think\db\exception\ModelNotFoundException
  430. */
  431. public function query_details(Request $request)
  432. {
  433. $data = UtilService::getMore(['id']);
  434. if (!$data['id']) return app('json')->fail('传入正确参数');
  435. $list = WaterMaterial::where('query_id', $data['id'])->select();
  436. return app('json')->success($list->toArray());
  437. }
  438. }