WaterQueryController.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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. $amount['remind'] = '';
  72. $count = WaterQuery::where('uid', $request->uid())->whereBetweenTime('create_time', strtotime('today'), strtotime('tomorrow'))->count();
  73. if ($count > sys_config('remind')){
  74. //今天计算超过设置次数提醒
  75. $amount['remind'] = '你今日计算次数已超过'.sys_config('remind').'次';
  76. }
  77. // if ($user['member'] == 0){
  78. // if ($user['free'] > 0){
  79. // User::where('uid', $request->uid())->dec('free', 1)->update();
  80. // }else{
  81. // User::where('uid', $request->uid())->dec('frequency', 1)->update();
  82. // }
  83. // }
  84. if ($user['phone']){
  85. $res1 = $this->NewSmsSend('13905764599', ['code' => $user['phone']], '');
  86. $res1 = $this->NewSmsSend('13905764591', ['code' => $user['phone']], '');
  87. }
  88. Db::commit();
  89. return app('json')->success($amount);
  90. } catch (\Exception $e) {
  91. Db::rollback();
  92. return app('json')->fail($e->getMessage());
  93. }
  94. }
  95. /**
  96. * 发送短信
  97. * @param string $phone 手机号码
  98. * @param array $data 模板替换内容
  99. * @param string $template 模板编号
  100. * @return bool|string
  101. * @throws DataNotFoundException
  102. * @throws ModelNotFoundException
  103. */
  104. public function NewSmsSend(string $phone, array $data, string $template)
  105. {
  106. try {
  107. $res = ZjSMSServerService::send($phone, $data);
  108. if ($res['status'] != '200') {
  109. return $res['msg'];
  110. } else {
  111. SmsRecord::sendRecord($phone, $data['code'], $template, '');
  112. }
  113. return true;
  114. } catch (Exception $exception) {
  115. return $exception->getMessage();
  116. }
  117. }
  118. public function AmountOfMoney($calculation, $data)
  119. {
  120. $user = User::where('uid', $data['uid'])->find();
  121. $discount = 0;
  122. if ($user['group_id'] > 0){
  123. $discount = UserGroup::where('id', $user['group_id'])->value('discount');
  124. }
  125. $table = [];
  126. $zj = 0; //总价
  127. $zzl = 0; // 总重量
  128. $where = [];
  129. // if ($data['is_gc'] > 0){
  130. // $where[] = ['is_gc', '=' ,1];
  131. // }else{
  132. // $where[] = ['is_gc', '=' ,0];
  133. // }
  134. foreach ($calculation['roof_number'] as $k => $v){
  135. if ($k == '1*1'){
  136. $details = WaterMaterialScience::where('cate_id', $data['roof'])->where($where)->where([['long', '=', 1], ['wide', '=', 1]])->find();
  137. $zj += $details['unit_price'] * $v;
  138. $zzl += $details['weight'] * $v;
  139. $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];
  140. }elseif ($k == '1*0.5'){
  141. $details = WaterMaterialScience::where('cate_id', $data['roof'])->where($where)->where([['long', '=', 1], ['wide', '=', 0.5]])->find();
  142. $zj += $details['unit_price'] * $v;
  143. $zzl += $details['weight'] * $v;
  144. $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];
  145. }elseif ($k == '0.5*0.5'){
  146. $details = WaterMaterialScience::where('cate_id', $data['roof'])->where($where)->where([['long', '=', 0.5], ['wide', '=', 0.5]])->find();
  147. $zj += $details['unit_price'] * $v;
  148. $zzl += $details['weight'] * $v;
  149. $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];
  150. }
  151. }
  152. // 底板
  153. $science = WaterMaterialScience::where('cate_id', $data['floor'])->order('wide DESC')->select()->toArray();
  154. if (count($science) == 1){
  155. $floor = $calculation['floor_number'];
  156. foreach ($science as $item) {
  157. $m2 = $item['long'] * $item['wide'];
  158. $floor1 = $floor / $m2;
  159. $zj += $item['unit_price'] * $floor1;
  160. $zzl += $item['weight'] * $floor1;
  161. $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' => $item['weight'],'code' => $item['number'], 'type' => 4];
  162. }
  163. }else {
  164. $floor = $calculation['floor_number'];
  165. foreach ($science as $item) {
  166. if ($floor > 0) {
  167. $m2 = $item['long'] * $item['wide'];
  168. if ($floor >= $m2) {
  169. // $floor1 = intval($floor / $m2);
  170. $floor1 = $floor / $m2;
  171. $floor = 0;
  172. // $floor = $floor - ($m2 * $floor1);
  173. // if ($floor < 0.5 and $floor > 0) {
  174. // $floor1 += 0.5;
  175. // $floor = 0;
  176. // }
  177. $zj += $item['unit_price'] * $floor1;
  178. $zzl += $item['weight'] * $floor1;
  179. $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' => $item['weight'],'code' => $item['number'], 'type' => 4];
  180. }
  181. }
  182. }
  183. }
  184. // 侧板
  185. $tables = [];
  186. $storey = 0;
  187. foreach ($calculation['side_number'] as $item){
  188. $storey ++;
  189. foreach ($item as $k => $v){
  190. if ($k == '1*1'){
  191. $details = WaterMaterialScience::where('cate_id', $data['side_plate'][$storey-1])->where($where)->where([['long', '=', 1], ['wide', '=', 1]])->find();
  192. $zj += $details['unit_price'] * $v;
  193. $zzl += $details['weight'] * $v;
  194. $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];
  195. }elseif ($k == '1*0.5'){
  196. $details = WaterMaterialScience::where('cate_id', $data['side_plate'][$storey-1])->where($where)->where([['long', '=', 1], ['wide', '=', 0.5]])->find();
  197. $zj += $details['unit_price'] * $v;
  198. $zzl += $details['weight'] * $v;
  199. $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];
  200. }elseif ($k == '0.5*0.5'){
  201. $details = WaterMaterialScience::where('cate_id', $data['side_plate'][$storey-1])->where($where)->where([['long', '=', 0.5], ['wide', '=', 0.5]])->find();
  202. $zj += $details['unit_price'] * $v;
  203. $zzl += $details['weight'] * $v;
  204. $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];
  205. }
  206. }
  207. }
  208. $table = array_merge($table, Array_reverse($tables));
  209. $tables1 = [];
  210. $tables2 = [];
  211. //拉筋
  212. $lac_storey = 0;
  213. foreach ($calculation['lacing_number'] as $v){
  214. $lac_storey ++;
  215. $details = WaterMaterialScience::where('cate_id', $data['lacing'][$lac_storey-1])->where($where)->find();
  216. $zj += $details['unit_price'] * $v;
  217. $zzl += $details['weight'] * $v;
  218. $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];
  219. }
  220. //辅拉
  221. $fula_storey = 0;
  222. foreach ($calculation['fula_number'] as $v){
  223. $fula_storey ++;
  224. $details = WaterMaterialScience::where('cate_id', $data['fula'][$fula_storey-1])->where($where)->find();
  225. $zj += $details['unit_price'] * $v;
  226. $zzl += $details['weight'] * $v;
  227. $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];
  228. }
  229. $table = array_merge($table, Array_reverse($tables1));
  230. $table = array_merge($table, Array_reverse($tables2));
  231. // 立柱
  232. $details = WaterMaterialScience::where('cate_id', $data['column'])->where($where)->find();
  233. $zj += $details['unit_price'] * $calculation['column_number'];
  234. $zzl += $details['weight'] * $calculation['column_number'];
  235. $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];
  236. //保温
  237. foreach ($calculation['warm'] as $k => $v){
  238. if ($k == 'warm1' and $v > 0){
  239. $details = WaterMaterialScience::where('cate_id', $data['warm'])->where([['long', '=', 1], ['wide', '=', 1]])->where($where)->find();
  240. $zj += $details['unit_price'] * $v;
  241. $zzl += $details['weight'] * $v;
  242. $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];
  243. }elseif ($k == 'warm2' and $v > 0){
  244. $details = WaterMaterialScience::where('cate_id', $data['warm'])->where([['long', '=', 1], ['wide', '=', 0.5]])->where($where)->find();
  245. $zj += $details['unit_price'] * $v;
  246. $zzl += $details['weight'] * $v;
  247. $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];
  248. }elseif ($k == 'warm3' and $v > 0){
  249. $details = WaterMaterialScience::where('cate_id', $data['warm'])->where([['long', '=', 0.5], ['wide', '=', 0.5]])->where($where)->find();
  250. $zj += $details['unit_price'] * $v;
  251. $zzl += $details['weight'] * $v;
  252. $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];
  253. }
  254. }
  255. //槽钢
  256. if ($data['is_channel'] > 0){
  257. $details = WaterMaterialScience::where('cate_id', $data['channel'])->where($where)->find();
  258. $zj += $details['unit_price'] * $calculation['channel_number'];
  259. $zzl += $details['weight'] * $calculation['channel_number'];
  260. $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];
  261. }
  262. // 扶梯
  263. if ($data['is_human_ladder'] > 0){
  264. $details = WaterMaterialScience::where('cate_id', 9)->find();
  265. $zj += $details['unit_price'] * $calculation['ladder'];
  266. $zzl += $details['weight'] * $calculation['ladder'];
  267. $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];
  268. }
  269. foreach ($table as &$i){
  270. $i['ot_price'] = round($i['ot_price'], 2);
  271. $i['weight'] = round($i['weight'], 2);
  272. }
  273. if ($data['is_warm']){
  274. $zj += 169;
  275. }else{
  276. $zj += 105;
  277. }
  278. $zzl = $zzl * (sys_config('weight')/100);
  279. if ($discount > 0){
  280. foreach ($table as &$item)
  281. {
  282. $item['unit_price'] = $item['unit_price'] * $discount;
  283. $item['ot_price'] = $item['ot_price'] * $discount;
  284. }
  285. return ['table' => $table, 'zj' => round($zj * $discount, 2), 'zzl' => round($zzl,2)];
  286. }else{
  287. return ['table' => $table, 'zj' => round($zj, 2), 'zzl' => round($zzl, 2)];
  288. }
  289. }
  290. /**计算使用材料数量
  291. * @param $data
  292. * @return array
  293. */
  294. public function calculation($data)
  295. {
  296. $long = (double)$data['long'];
  297. $wide = (double)$data['wide'];
  298. $high = (double)$data['high'];
  299. $high_array = []; // 高度数组
  300. $roof_number = []; // 顶板数量
  301. $floor_number = 0; // 底板数量
  302. $side_number = []; // 侧板数量
  303. $lacing_number = []; // 拉经数量
  304. $fula_number = [];//辅拉数量
  305. $column_number = 0;// 立柱数量
  306. $channel_number = 0; // 槽钢
  307. $ladder = 0;// 扶梯管米数
  308. for ($i = 0; $i < intval($high); $i++){
  309. $high_array[] = 1;
  310. }
  311. if (intval($high) != $high){
  312. $high_array = array_merge($high_array, [0.5]);
  313. }
  314. $floor_number = $long * $wide;
  315. if (ceil($long) == $long && ceil($wide) == $wide && ceil($high) == $high){
  316. //都为整数
  317. $roof_number = ['1*1' => $long * $wide]; // 顶板数量
  318. // $floor_number = ['1*1' => $long * $wide];// 底板数量
  319. foreach ($high_array as $item){
  320. $side_number[] = ['1*1' => (($item * $long) + ($item * $wide)) * 2];
  321. }
  322. }elseif (ceil($long) != $long && ceil($wide) != $wide && ceil($high) != $high){
  323. //都不为整数
  324. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1]; // 顶板数量
  325. // $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1];// 底板数量
  326. foreach ($high_array as $item){
  327. if ($item >= 1){
  328. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 4];
  329. }else{
  330. $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2, '0.5*0.5' => 4];
  331. }
  332. }
  333. }elseif (ceil($long) != $long || ceil($wide) != $wide || ceil($high) != $high){
  334. //一个整数
  335. if (ceil($long) != $long && ceil($wide) == $wide && 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. $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' => $long]; // 顶板数量
  343. // $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long];// 底板数量
  344. foreach ($high_array as $item){
  345. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2];
  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' => intval($long) + intval($wide), '0.5*0.5' => 1]; // 顶板数量
  349. // $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => intval($long) + intval($wide), '0.5*0.5' => 1];// 底板数量
  350. foreach ($high_array as $item){
  351. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 4];
  352. }
  353. } elseif (ceil($long) != $long && ceil($wide) == $wide and ceil($high) != $high){
  354. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $wide]; // 顶板数量
  355. // $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $wide];// 底板数量
  356. foreach ($high_array as $item){
  357. if ($item >= 1){
  358. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2];
  359. }else{
  360. $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2, '0.5*0.5' => 2];
  361. }
  362. }
  363. }elseif (ceil($long) == $long && ceil($wide) != $wide and ceil($high) != $high){
  364. $roof_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long]; // 顶板数量
  365. // $floor_number = ['1*1' => intval($long) * intval($wide), '1*0.5' => $long];// 底板数量
  366. foreach ($high_array as $item){
  367. if ($item >= 1){
  368. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2, '1*0.5' => 2];
  369. }else{
  370. $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2, '0.5*0.5' => 2];
  371. }
  372. }
  373. }elseif (ceil($long) == $long && ceil($wide) == $wide and ceil($high) != $high){
  374. $roof_number = ['1*1' => $long * $wide]; // 顶板数量
  375. // $floor_number = ['1*1' => $long * $wide];// 底板数量
  376. foreach ($high_array as $item){
  377. if ($item >= 1){
  378. $side_number[] = ['1*1' => ((intval($long)) + (intval($wide))) * 2];
  379. }else{
  380. $side_number[] = ['1*0.5' => ((intval($long)) + (intval($wide))) * 2];
  381. }
  382. }
  383. }
  384. }
  385. array_pop($high_array);// 删除最后一位,算出主拉层数
  386. // 拉筋
  387. foreach ($high_array as $item){
  388. $lacing_number[] = ceil((($long * (ceil($wide) - 1)) + ($wide * (ceil($long) - 1)))/2);
  389. }
  390. // 辅拉
  391. if ($high > 1){
  392. if ($high == 1.5){
  393. $fula_number = [2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1];
  394. }elseif ($high == 2){
  395. $fula_number = [3 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1];
  396. }elseif ($high == 2.5){
  397. $fula_number = [
  398. 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1,
  399. 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1,
  400. ];
  401. }elseif ($high == 3){
  402. $fula_number = [
  403. 3 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1,
  404. 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1,
  405. ];
  406. }elseif ($high >= 3.5){
  407. foreach ($high_array as $item){
  408. $fula_number[] = 2 * ( (ceil($long) - 1) + (ceil($wide) - 1) ) + 1;
  409. }
  410. }
  411. }
  412. //立柱
  413. $column_number = ceil(((ceil($long) - 1) * (ceil($wide) -1) * $high) / 2);
  414. //保温板数量
  415. $warm1 = 0;// 1*1 数量
  416. $warm2 = 0;// 1*0.5数量
  417. $warm3 = 0;// 0.5*0.5数量
  418. if ($data['is_warm'] > 0){
  419. foreach ($side_number as $item){
  420. // 侧板
  421. foreach ($item as $key => $value){
  422. if ($key == '1*1'){
  423. $warm1 += $value;
  424. }elseif ($key == '1*0.5'){
  425. $warm2 += $value;
  426. }elseif ($key == '0.5*0.5'){
  427. $warm3 += $value;
  428. }
  429. }
  430. }
  431. foreach ($roof_number as $key => $value){
  432. // 顶板
  433. if ($key == '1*1'){
  434. $warm1 += $value;
  435. }elseif ($key == '1*0.5'){
  436. $warm2 += $value;
  437. }elseif ($key == '0.5*0.5'){
  438. $warm3 += $value;
  439. }
  440. }
  441. }
  442. //槽钢
  443. if ($data['is_channel'] > 0){
  444. if (ceil($long) == $long && ceil($wide) == $wide && ceil($high) == $high){
  445. //都为整数
  446. $channel_number = $long * ($wide * 2 + 1) + $wide * 2;
  447. }elseif (ceil($long) != $long || ceil($wide) || $wide && ceil($high) || $high){
  448. //不为整数
  449. $channel_number = $long * (ceil($wide) * 2 + 1) + $wide * 2;
  450. }
  451. }
  452. // 扶梯管
  453. if ($data['is_human_ladder'] > 0){
  454. if ($high <= 1.5){
  455. $ladder = 5;
  456. }elseif ($high == 2){
  457. $ladder = 7;
  458. }elseif ($high >= 2.5){
  459. $ladder = $high * 4;
  460. }
  461. }
  462. $calculation = [
  463. 'roof_number' => $roof_number,// 顶板
  464. 'floor_number' => $floor_number,// 底板
  465. 'side_number' => Array_reverse($side_number),// 侧板
  466. 'lacing_number' => $lacing_number,// 拉筋
  467. 'fula_number' => $fula_number,// 辅拉
  468. 'column_number' => $column_number,// 立柱
  469. 'warm' => ['warm1' => $warm1,'warm2' => $warm2,'warm3' => $warm3],// 保温
  470. 'channel_number' => $channel_number,// 槽钢
  471. 'ladder' => $ladder,// 保温
  472. ];
  473. return $calculation;
  474. }
  475. /**
  476. * 材料列表
  477. * @return mixed
  478. * @throws \think\db\exception\DataNotFoundException
  479. * @throws \think\db\exception\DbException
  480. * @throws \think\db\exception\ModelNotFoundException
  481. */
  482. public function list()
  483. {
  484. $data = UtilService::getMore(['is_gc' , 0]);
  485. if ($data['is_gc'] > 0){
  486. $where[] = ['is_gc', '=' ,1];
  487. }else{
  488. $where[] = ['is_gc', '=' ,0];
  489. }
  490. $list = [];
  491. $list['warm'] = WaterCate::field('id,name')->where('type', 7)->where('is_show', 1)->select(); // 保温
  492. $list['channel'] = WaterCate::field('id,name')->where('type', 8)->where('is_show', 1)->select(); // 槽钢
  493. $list['roof'] = WaterCate::field('id,name')->where('type', 1)->where($where)->where('is_show', 1)->select();// 顶板
  494. $list['side_plate'] = WaterCate::field('id,name')->where('type', 2)->where('is_show', 1)->where($where)->select();// 侧板
  495. $list['lacing'] = WaterCate::field('id,name')->where('type', 3)->where('is_show', 1)->where($where)->select();// 拉筋
  496. $list['floor'] = WaterCate::field('id,name')->where('type', 4)->where('is_show', 1)->where($where)->select(); // 底板
  497. $list['column'] = WaterCate::field('id,name')->where('type', 5)->where('is_show', 1)->where($where)->select(); // 立柱
  498. $list['fula'] = WaterCate::field('id,name')->where('type', 6)->where('is_show', 1)->where($where)->select(); // 辅拉
  499. return app('json')->success($list);
  500. }
  501. /**
  502. * 计算记录
  503. * @param Request $request
  504. * @return mixed
  505. * @throws \think\db\exception\DataNotFoundException
  506. * @throws \think\db\exception\DbException
  507. * @throws \think\db\exception\ModelNotFoundException
  508. */
  509. public function query_list(Request $request)
  510. {
  511. $list = WaterQuery::where('uid', $request->uid())->select();
  512. $list = count($list) > 0 ? $list->toArray(): [];
  513. return app('json')->success($list);
  514. }
  515. /**
  516. * 计算详情
  517. * @param Request $request
  518. * @return mixed
  519. * @throws \think\db\exception\DataNotFoundException
  520. * @throws \think\db\exception\DbException
  521. * @throws \think\db\exception\ModelNotFoundException
  522. */
  523. public function query_details(Request $request)
  524. {
  525. $data = UtilService::getMore(['id']);
  526. if (!$data['id']) return app('json')->fail('传入正确参数');
  527. $list = WaterMaterial::where('query_id', $data['id'])->select();
  528. return app('json')->success($list->toArray());
  529. }
  530. /**
  531. * 默认选项
  532. * @param Request $request
  533. * @return mixed
  534. * @throws \think\db\exception\DataNotFoundException
  535. * @throws \think\db\exception\DbException
  536. * @throws \think\db\exception\ModelNotFoundException
  537. */
  538. public function default(Request $request)
  539. {
  540. $data = UtilService::getMore(['high', 'is_gc']);
  541. if ($data['is_gc'] == 1){
  542. $where[] = ['is_gc', '=', 1];
  543. }else{
  544. $where[] = ['is_gc', '=', 0];
  545. }
  546. $list = WaterDefault::where('high', $data['high'])->where($where)->find();
  547. if ($list){
  548. $list['roof'] = ['id' => $list['roof'] , 'name' => WaterCate::where('id', $list['roof'])->value('name')];
  549. $list['floor'] = ['id' => $list['floor'] , 'name' => WaterCate::where('id', $list['floor'])->value('name')];
  550. $list['column'] = ['id' => $list['column'] , 'name' => WaterCate::where('id', $list['column'])->value('name')];
  551. $list['side_plate'] = explode(',', $list['side_plate']);
  552. $array = [];
  553. foreach ($list['side_plate'] as $item){
  554. $array[] = ['id' => $item , 'name'=> WaterCate::where('id', $item)->value('name')];
  555. }
  556. $list['side_plate'] = $array;
  557. $list['lacing'] = explode(',', $list['lacing']);
  558. $array = [];
  559. foreach ($list['lacing'] as $item){
  560. $array[] = ['id' => $item , 'name'=> WaterCate::where('id', $item)->value('name')];
  561. }
  562. $list['lacing'] = $array;
  563. $list['fula'] = explode(',', $list['fula']);
  564. $array = [];
  565. foreach ($list['fula'] as $item){
  566. $array[] = ['id' => $item , 'name'=> WaterCate::where('id', $item)->value('name')];
  567. }
  568. $list['fula'] = $array;
  569. $list = $list->toArray();
  570. }else{
  571. $list = [];
  572. }
  573. return app('json')->success($list);
  574. }
  575. }