WaterQueryController.php 28 KB

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