WaterQueryController.php 26 KB

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