FarmLandServer.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. namespace app\admin\server\life;
  3. use app\admin\model\LifeFarmLand;
  4. use app\admin\model\SystemMenu;
  5. use support\Redis;
  6. class FarmlandServer
  7. {
  8. /**
  9. * Notes:获取地块列表
  10. * @param string $keywords
  11. * @param int $page
  12. * @param int $limit
  13. * @return array
  14. * User: YCP
  15. * Date: 2022/10/17
  16. */
  17. public static function getlandList(int $page, int $limit, string $keywords)
  18. {
  19. [$list, $count] = LifeFarmLand::getlandList($page, $limit, $keywords);
  20. if (!empty($list)){
  21. foreach ($list as $k => $v){
  22. $list[$k]['land_create_time'] = date('Y-m-d H:i:s',$v['land_create_time']);
  23. if (!empty($v['land_update_time'])){
  24. $list[$k]['land_update_time'] = date('Y-m-d H:i:s',$v['land_update_time']);
  25. }
  26. }
  27. }
  28. return compact('list', 'page', 'limit', 'count');
  29. }
  30. /**
  31. * Notes: 添加地块
  32. * @param string $land_name
  33. * @param array $land_rules
  34. * @return int
  35. * User: YCP
  36. * Date: 2022/10/17
  37. */
  38. public static function insertland($land_name, $land_price, $land_longitude, $land_latitude, $admin_id)
  39. {
  40. LifeFarmLand::affairBegin();
  41. try {
  42. //检测地块名是否重复
  43. if(LifeFarmLand::checkLandName($land_name))
  44. {
  45. throw new \Exception($land_name . '地块名已存在');
  46. }
  47. //检测经纬度是否重复
  48. if(LifeFarmLand::checkLandPoint($land_longitude,$land_latitude))
  49. {
  50. throw new \Exception('该坐标已存在');
  51. }
  52. $data = [];
  53. $data['land_name'] = $land_name;
  54. $data['land_price'] = $land_price;
  55. $data['land_longitude'] = $land_longitude;
  56. $data['land_latitude'] = $land_latitude;
  57. $data['land_create_time'] = time();
  58. $result = LifeFarmLand::insertGetId($data);
  59. if (!empty($result)){
  60. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加一亩心田地块-编号: ' . $result;
  61. plog('life-farm-land-create', '悦活-生态农场-一亩心田-添加地块', $msg);
  62. LifeFarmLand::affairCommit();
  63. return $result;
  64. }
  65. throw new \Exception('操作失败!');
  66. }catch (\Exception $exception){
  67. LifeFarmLand::affairRollback();
  68. throw new \Exception($exception->getMessage(), 500);
  69. }
  70. }
  71. /**
  72. * Notes:修改地块
  73. * @param string $land_name
  74. * @param int $land_id
  75. * @return int
  76. * User: YCP
  77. * Date: 2022/10/17
  78. */
  79. public static function updateland($land_id, $land_name, $land_price, $land_longitude, $land_latitude, $admin_id)
  80. {
  81. LifeFarmLand::affairBegin();
  82. try {
  83. $where = [];
  84. $where['land_id'] = $land_id;
  85. $info = LifeFarmLand::where($where)->first();
  86. if(empty($info) || $info === false)
  87. {
  88. throw new \Exception('地块信息不存在');
  89. }
  90. $data = [];
  91. $data['land_name'] = $land_name;
  92. $data['land_price'] = $land_price;
  93. $data['land_longitude'] = $land_longitude;
  94. $data['land_latitude'] = $land_latitude;
  95. $data['land_update_time'] = time();
  96. $result = LifeFarmLand::where($where)->update($data);
  97. if ($result !== false){
  98. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '修改一亩心田地块-编号: ' . $land_id;
  99. plog('life-farm-land-update', '悦活-生态农场-一亩心田-修改地块', $msg);
  100. LifeFarmLand::affairCommit();
  101. return true;
  102. }
  103. throw new \Exception('操作失败!');
  104. }catch (\Exception $exception){
  105. LifeFarmLand::affairRollback();
  106. throw new \Exception($exception->getMessage(), 500);
  107. }
  108. }
  109. /**
  110. * Notes:删除地块
  111. * @param int $land_id
  112. * @return int
  113. * User: YCP
  114. * Date: 2022/10/17
  115. */
  116. public static function delland($land_id,$admin_id)
  117. {
  118. LifeFarmLand::affairBegin();
  119. try {
  120. $where = [];
  121. $where['land_id'] = $land_id;
  122. $data['land_is_del'] = 1;
  123. $result = LifeFarmLand::where($where)->update($data);
  124. if (!empty($result)){
  125. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除一亩心田地块-编号: ' . $land_id;
  126. plog('life-farm-land-delete', '悦活-生态农场-一亩心田-删除地块', $msg);
  127. LifeFarmLand::affairCommit();
  128. return true;
  129. }else{
  130. return false;
  131. }
  132. }catch (\Exception $exception){
  133. LifeFarmLand::affairRollback();
  134. throw new \Exception($exception->getMessage(), 500);
  135. }
  136. }
  137. /**
  138. * Notes:查询地块
  139. * @param int $land_id
  140. * @return int
  141. * User: YCP
  142. * Date: 2022/10/17
  143. */
  144. public static function landInfo($land_id)
  145. {
  146. $where = [];
  147. $where['land_id'] = $land_id;
  148. $result = LifeFarmLand::where($where)->first();
  149. if(empty($result) || $result === false)
  150. {
  151. throw new \Exception('地块信息不存在');
  152. }
  153. if (!empty($result)){
  154. $result['land_create_time'] = date('Y-m-d H:i:s',$result['land_create_time']);
  155. if (!empty($result['land_update_time'])){
  156. $result['land_update_time'] = date('Y-m-d H:i:s',$result['land_update_time']);
  157. }
  158. }
  159. return $result;
  160. }
  161. }