WaterQueryController.php 26 KB

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