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