WaterQueryController.php 29 KB

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