WaterQueryController.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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'].'m*'.$details['wide'].'m', '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'].'m*'.$details['wide'].'m', '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'].'m*'.$details['wide'].'m', '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'].'m*'.$item['wide'].'m', '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'].'m*'.$item['wide'].'m', '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. $tables = [];
  174. $storey = 0;
  175. foreach ($calculation['side_number'] as $item){
  176. $storey ++;
  177. foreach ($item as $k => $v){
  178. if ($k == '1*1'){
  179. $details = WaterMaterialScience::where('cate_id', $data['side_plate'][$storey-1])->where($where)->where([['long', '=', 1], ['wide', '=', 1]])->find();
  180. $zj += $details['unit_price'] * $v;
  181. $zzl += $details['weight'] * $v;
  182. $tables[] = ['title' => '侧板'.$storey.'层' , 'name' => $details['name'], 'specifications' => $details['long'].'m*'.$details['wide'].'m', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 2];
  183. }elseif ($k == '1*0.5'){
  184. $details = WaterMaterialScience::where('cate_id', $data['side_plate'][$storey-1])->where($where)->where([['long', '=', 1], ['wide', '=', 0.5]])->find();
  185. $zj += $details['unit_price'] * $v;
  186. $zzl += $details['weight'] * $v;
  187. $tables[] = ['title' => '侧板'.$storey.'层' , 'name' => $details['name'], 'specifications' => $details['long'].'m*'.$details['wide'].'m', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 2];
  188. }elseif ($k == '0.5*0.5'){
  189. $details = WaterMaterialScience::where('cate_id', $data['side_plate'][$storey-1])->where($where)->where([['long', '=', 0.5], ['wide', '=', 0.5]])->find();
  190. $zj += $details['unit_price'] * $v;
  191. $zzl += $details['weight'] * $v;
  192. $tables[] = ['title' => '侧板'.$storey.'层' , 'name' => $details['name'], 'specifications' => $details['long'].'m*'.$details['wide'].'m', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 2];
  193. }
  194. }
  195. }
  196. $table = array_merge($table, Array_reverse($tables));
  197. $tables1 = [];
  198. $tables2 = [];
  199. //拉筋
  200. $lac_storey = 0;
  201. foreach ($calculation['lacing_number'] as $v){
  202. $lac_storey ++;
  203. $details = WaterMaterialScience::where('cate_id', $data['lacing'][$lac_storey-1])->where($where)->find();
  204. $zj += $details['unit_price'] * $v;
  205. $zzl += $details['weight'] * $v;
  206. $tables1[] = ['title' => '主拉'.$lac_storey.'层' , 'name' => $details['name'], 'specifications' => $details['long'].'*'.$details['wide'].'*'.'2.1', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 3];
  207. }
  208. //辅拉
  209. $fula_storey = 0;
  210. foreach ($calculation['fula_number'] as $v){
  211. $fula_storey ++;
  212. $details = WaterMaterialScience::where('cate_id', $data['fula'][$fula_storey-1])->where($where)->find();
  213. $zj += $details['unit_price'] * $v;
  214. $zzl += $details['weight'] * $v;
  215. $tables2[] = ['title' => '辅拉'.$fula_storey.'层' , 'name' => $details['name'], 'specifications' => $details['long'].'*'.$details['wide'].'*'.'2.1', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 6];
  216. }
  217. $table = array_merge($table, Array_reverse($tables1));
  218. $table = array_merge($table, Array_reverse($tables2));
  219. // 立柱
  220. $details = WaterMaterialScience::where('cate_id', $data['column'])->where($where)->find();
  221. $zj += $details['unit_price'] * $calculation['column_number'];
  222. $zzl += $details['weight'] * $calculation['column_number'];
  223. $table[] = ['title' => '立柱' , 'name' => $details['name'], 'specifications' => $details['long'].'*'.$details['wide'].'*'.'2.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];
  224. //保温
  225. foreach ($calculation['warm'] as $k => $v){
  226. if ($k == 'warm1' and $v > 0){
  227. $details = WaterMaterialScience::where('cate_id', $data['warm'])->where([['long', '=', 1], ['wide', '=', 1]])->where($where)->find();
  228. $zj += $details['unit_price'] * $v;
  229. $zzl += $details['weight'] * $v;
  230. $table[] = ['title' => '保温板' , 'name' => $details['name'], 'specifications' => '1m*1m', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 7];
  231. }elseif ($k == 'warm2' and $v > 0){
  232. $details = WaterMaterialScience::where('cate_id', $data['warm'])->where([['long', '=', 1], ['wide', '=', 0.5]])->where($where)->find();
  233. $zj += $details['unit_price'] * $v;
  234. $zzl += $details['weight'] * $v;
  235. $table[] = ['title' => '保温板' , 'name' => $details['name'], 'specifications' => '1m*0.5m', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 7];
  236. }elseif ($k == 'warm3' and $v > 0){
  237. $details = WaterMaterialScience::where('cate_id', $data['warm'])->where([['long', '=', 0.5], ['wide', '=', 0.5]])->where($where)->find();
  238. $zj += $details['unit_price'] * $v;
  239. $zzl += $details['weight'] * $v;
  240. $table[] = ['title' => '保温板' , 'name' => $details['name'], 'specifications' => '0.5m*0.5m', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 7];
  241. }
  242. }
  243. //槽钢
  244. if ($data['is_channel'] > 0){
  245. $details = WaterMaterialScience::where('cate_id', $data['channel'])->where($where)->find();
  246. $zj += $details['unit_price'] * $calculation['channel_number'];
  247. $zzl += $details['weight'] * $calculation['channel_number'];
  248. $table[] = ['title' => '槽钢' , 'name' => $details['name'], 'specifications' => $details['company'], '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];
  249. }
  250. // 扶梯
  251. if ($data['is_human_ladder'] > 0){
  252. $details = WaterMaterialScience::where('cate_id', 9)->find();
  253. $zj += $details['unit_price'] * $calculation['ladder'];
  254. $zzl += $details['weight'] * $calculation['ladder'];
  255. $table[] = ['title' => '扶梯' , 'name' => $details['name'], 'specifications' => $details['company'], '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];
  256. }
  257. foreach ($table as &$i){
  258. $i['ot_price'] = round($i['ot_price'], 2);
  259. $i['weight'] = round($i['weight'], 2);
  260. }
  261. if ($discount > 0){
  262. foreach ($table as &$item)
  263. {
  264. $item['unit_price'] = $item['unit_price'] * $discount;
  265. $item['ot_price'] = $item['ot_price'] * $discount;
  266. }
  267. return ['table' => $table, 'zj' => round($zj * $discount, 2), 'zzl' => round($zzl,2)];
  268. }else{
  269. return ['table' => $table, 'zj' => round($zj, 2), 'zzl' => round($zzl, 2)];
  270. }
  271. }
  272. /**计算使用材料数量
  273. * @param $data
  274. * @return array
  275. */
  276. public function calculation($data)
  277. {
  278. $long = (double)$data['long'];
  279. $wide = (double)$data['wide'];
  280. $high = (double)$data['high'];
  281. $high_array = []; // 高度数组
  282. $roof_number = []; // 顶板数量
  283. $floor_number = 0; // 底板数量
  284. $side_number = []; // 侧板数量
  285. $lacing_number = []; // 拉经数量
  286. $fula_number = [];//辅拉数量
  287. $column_number = 0;// 立柱数量
  288. $channel_number = 0; // 槽钢
  289. $ladder = 0;// 扶梯管米数
  290. for ($i = 0; $i < intval($high); $i++){
  291. $high_array[] = 1;
  292. }
  293. if (intval($high) != $high){
  294. $high_array = array_merge($high_array, [0.5]);
  295. }
  296. $floor_number = $long * $wide;
  297. if (ceil($long) == $long && ceil($wide) == $wide && ceil($high) == $high){
  298. //都为整数
  299. $roof_number = ['1*1' => $long * $wide]; // 顶板数量
  300. // $floor_number = ['1*1' => $long * $wide];// 底板数量
  301. foreach ($high_array as $item){
  302. $side_number[] = ['1*1' => (($item * $long) + ($item * $wide)) * 2];
  303. }
  304. }elseif (ceil($long) != $long && ceil($wide) != $wide && ceil($high) != $high){
  305. //都不为整数
  306. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1]; // 顶板数量
  307. // $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1];// 底板数量
  308. foreach ($high_array as $item){
  309. if ($item >= 1){
  310. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 4];
  311. }else{
  312. $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2, '0.5*0.5' => 4];
  313. }
  314. }
  315. }elseif (ceil($long) != $long || ceil($wide) != $wide || ceil($high) != $high){
  316. //一个整数
  317. if (ceil($long) != $long && ceil($wide) == $wide && ceil($high) == $high){
  318. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $wide]; // 顶板数量
  319. // $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $wide];// 底板数量
  320. foreach ($high_array as $item){
  321. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2];
  322. }
  323. }elseif (ceil($long) == $long && ceil($wide) != $wide and ceil($high) == $high){
  324. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long]; // 顶板数量
  325. // $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long];// 底板数量
  326. foreach ($high_array as $item){
  327. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2];
  328. }
  329. }elseif (ceil($long) != $long && ceil($wide) != $wide and ceil($high) == $high){
  330. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1]; // 顶板数量
  331. // $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1];// 底板数量
  332. foreach ($high_array as $item){
  333. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 4];
  334. }
  335. } elseif (ceil($long) != $long && ceil($wide) == $wide and ceil($high) != $high){
  336. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $wide]; // 顶板数量
  337. // $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $wide];// 底板数量
  338. foreach ($high_array as $item){
  339. if ($item >= 1){
  340. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2];
  341. }else{
  342. $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2, '0.5*0.5' => 2];
  343. }
  344. }
  345. }elseif (ceil($long) == $long && ceil($wide) != $wide and ceil($high) != $high){
  346. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long]; // 顶板数量
  347. // $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long];// 底板数量
  348. foreach ($high_array as $item){
  349. if ($item >= 1){
  350. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2];
  351. }else{
  352. $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2, '0.5*0.5' => 2];
  353. }
  354. }
  355. }elseif (ceil($long) == $long && ceil($wide) == $wide and ceil($high) != $high){
  356. $roof_number = ['1*1' => $long * $wide]; // 顶板数量
  357. // $floor_number = ['1*1' => $long * $wide];// 底板数量
  358. foreach ($high_array as $item){
  359. if ($item >= 1){
  360. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2];
  361. }else{
  362. $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2];
  363. }
  364. }
  365. }
  366. }
  367. array_pop($high_array);// 删除最后一位,算出主拉层数
  368. // 拉筋
  369. foreach ($high_array as $item){
  370. $lacing_number[] = ceil((($long * (ceil($wide) - 1)) + ($wide * (ceil($long) - 1)))/2);
  371. }
  372. // 辅拉
  373. if ($high > 1){
  374. if ($high == 1.5){
  375. $fula_number = [2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1];
  376. }elseif ($high == 2){
  377. $fula_number = [3 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1];
  378. }elseif ($high == 2.5){
  379. $fula_number = [
  380. 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1,
  381. 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1,
  382. ];
  383. }elseif ($high == 3){
  384. $fula_number = [
  385. 3 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1,
  386. 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1,
  387. ];
  388. }elseif ($high >= 3.5){
  389. foreach ($high_array as $item){
  390. $fula_number[] = 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1;
  391. }
  392. }
  393. }
  394. //立柱
  395. $column_number = ceil(((ceil($long) - 1) * (ceil($wide) -1) * $high) / 2);
  396. //保温板数量
  397. $warm1 = 0;// 1*1 数量
  398. $warm2 = 0;// 1*0.5数量
  399. $warm3 = 0;// 0.5*0.5数量
  400. if ($data['is_warm'] > 0){
  401. foreach ($side_number as $item){
  402. // 侧板
  403. foreach ($item as $key => $value){
  404. if ($key == '1*1'){
  405. $warm1 += $value;
  406. }elseif ($key == '1*0.5'){
  407. $warm2 += $value;
  408. }elseif ($key == '0.5*0.5'){
  409. $warm3 += $value;
  410. }
  411. }
  412. }
  413. foreach ($roof_number as $key => $value){
  414. // 顶板
  415. if ($key == '1*1'){
  416. $warm1 += $value;
  417. }elseif ($key == '1*0.5'){
  418. $warm2 += $value;
  419. }elseif ($key == '0.5*0.5'){
  420. $warm3 += $value;
  421. }
  422. }
  423. }
  424. //槽钢
  425. if ($data['is_channel'] > 0){
  426. if (ceil($long) == $long && ceil($wide) == $wide && ceil($high) == $high){
  427. //都为整数
  428. $channel_number = $long * ($wide * 2 + 1) + $wide * 2;
  429. }elseif (ceil($long) != $long || ceil($wide) || $wide && ceil($high) || $high){
  430. //不为整数
  431. $channel_number = $long * (ceil($wide) * 2 + 1) + $wide * 2;
  432. }
  433. }
  434. // 扶梯管
  435. if ($data['is_human_ladder'] > 0){
  436. if ($high <= 1.5){
  437. $ladder = 5;
  438. }elseif ($high == 2){
  439. $ladder = 7;
  440. }elseif ($high >= 2.5){
  441. $ladder = $high * 4;
  442. }
  443. }
  444. $calculation = [
  445. 'roof_number' => $roof_number,// 顶板
  446. 'floor_number' => $floor_number,// 底板
  447. 'side_number' => Array_reverse($side_number),// 侧板
  448. 'lacing_number' => $lacing_number,// 拉筋
  449. 'fula_number' => $fula_number,// 辅拉
  450. 'column_number' => $column_number,// 立柱
  451. 'warm' => ['warm1' => $warm1,'warm2' => $warm2,'warm3' => $warm3],// 保温
  452. 'channel_number' => $channel_number,// 槽钢
  453. 'ladder' => $ladder,// 保温
  454. ];
  455. return $calculation;
  456. }
  457. /**
  458. * 材料列表
  459. * @return mixed
  460. * @throws \think\db\exception\DataNotFoundException
  461. * @throws \think\db\exception\DbException
  462. * @throws \think\db\exception\ModelNotFoundException
  463. */
  464. public function list()
  465. {
  466. $data = UtilService::getMore(['is_gc' , 0]);
  467. if ($data['is_gc'] > 0){
  468. $where[] = ['is_gc', '=' ,1];
  469. }else{
  470. $where[] = ['is_gc', '=' ,0];
  471. }
  472. $list = [];
  473. $list['warm'] = WaterCate::field('id,name')->where('type', 7)->select(); // 保温
  474. $list['channel'] = WaterCate::field('id,name')->where('type', 8)->select(); // 槽钢
  475. $list['roof'] = WaterCate::field('id,name')->where('type', 1)->where($where)->select();// 顶板
  476. $list['side_plate'] = WaterCate::field('id,name')->where('type', 2)->where($where)->select();// 侧板
  477. $list['lacing'] = WaterCate::field('id,name')->where('type', 3)->where($where)->select();// 拉筋
  478. $list['floor'] = WaterCate::field('id,name')->where('type', 4)->where($where)->select(); // 底板
  479. $list['column'] = WaterCate::field('id,name')->where('type', 5)->where($where)->select(); // 立柱
  480. $list['fula'] = WaterCate::field('id,name')->where('type', 6)->where($where)->select(); // 辅拉
  481. return app('json')->success($list);
  482. }
  483. /**
  484. * 计算记录
  485. * @param Request $request
  486. * @return mixed
  487. * @throws \think\db\exception\DataNotFoundException
  488. * @throws \think\db\exception\DbException
  489. * @throws \think\db\exception\ModelNotFoundException
  490. */
  491. public function query_list(Request $request)
  492. {
  493. $list = WaterQuery::where('uid', $request->uid())->select();
  494. $list = count($list) > 0 ? $list->toArray(): [];
  495. return app('json')->success($list);
  496. }
  497. /**
  498. * 计算详情
  499. * @param Request $request
  500. * @return mixed
  501. * @throws \think\db\exception\DataNotFoundException
  502. * @throws \think\db\exception\DbException
  503. * @throws \think\db\exception\ModelNotFoundException
  504. */
  505. public function query_details(Request $request)
  506. {
  507. $data = UtilService::getMore(['id']);
  508. if (!$data['id']) return app('json')->fail('传入正确参数');
  509. $list = WaterMaterial::where('query_id', $data['id'])->select();
  510. return app('json')->success($list->toArray());
  511. }
  512. /**
  513. * 默认选项
  514. * @param Request $request
  515. * @return mixed
  516. * @throws \think\db\exception\DataNotFoundException
  517. * @throws \think\db\exception\DbException
  518. * @throws \think\db\exception\ModelNotFoundException
  519. */
  520. public function default(Request $request)
  521. {
  522. $data = UtilService::getMore(['high']);
  523. $list = WaterDefault::where('high', $data['high'])->find();
  524. if ($list){
  525. $list['roof'] = ['id' => $list['roof'] , 'name' => WaterCate::where('id', $list['roof'])->value('name')];
  526. $list['floor'] = ['id' => $list['floor'] , 'name' => WaterCate::where('id', $list['floor'])->value('name')];
  527. $list['column'] = ['id' => $list['column'] , 'name' => WaterCate::where('id', $list['column'])->value('name')];
  528. $list['side_plate'] = explode(',', $list['side_plate']);
  529. $array = [];
  530. foreach ($list['side_plate'] as $item){
  531. $array[] = ['id' => $item , 'name'=> WaterCate::where('id', $item)->value('name')];
  532. }
  533. $list['side_plate'] = $array;
  534. $list['lacing'] = explode(',', $list['lacing']);
  535. $array = [];
  536. foreach ($list['lacing'] as $item){
  537. $array[] = ['id' => $item , 'name'=> WaterCate::where('id', $item)->value('name')];
  538. }
  539. $list['lacing'] = $array;
  540. $list['fula'] = explode(',', $list['fula']);
  541. $array = [];
  542. foreach ($list['fula'] as $item){
  543. $array[] = ['id' => $item , 'name'=> WaterCate::where('id', $item)->value('name')];
  544. }
  545. $list['fula'] = $array;
  546. $list = $list->toArray();
  547. }else{
  548. $list = [];
  549. }
  550. return app('json')->success($list);
  551. }
  552. }