WaterQueryController.php 31 KB

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