WaterQueryController.php 26 KB

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