WaterQueryController.php 27 KB

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