WaterQueryController.php 26 KB

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