WaterQueryController.php 31 KB

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