PlayServer.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. namespace app\admin\server\life;
  3. use app\admin\model\LifePlay;
  4. class PlayServer
  5. {
  6. /**
  7. * Notes:获取农庄美食/采摘游玩列表
  8. * @param string $keywords
  9. * @param int $page
  10. * @param int $limit
  11. * @return array
  12. * User: ZQ
  13. * Date: 2022/10/18
  14. */
  15. public static function getPlayList(int $page, int $limit, string $keywords)
  16. {
  17. [$list, $count] = LifePlay::getPlayList($page, $limit, $keywords);
  18. if (!empty($list)){
  19. foreach ($list as $k => $v){
  20. $list[$k]['play_materials'] = json_decode($v['play_materials'],true);
  21. $list[$k]['play_condiment'] = json_decode($v['play_condiment'],true);
  22. $list[$k]['play_create_time'] = date('Y-m-d H:i:s',$v['play_create_time']);
  23. if (!empty($v['play_update_time'])){
  24. $list[$k]['play_update_time'] = date('Y-m-d H:i:s',$v['play_update_time']);
  25. }
  26. }
  27. }
  28. return compact('list', 'page', 'limit', 'count');
  29. }
  30. /**
  31. * Notes:获取分类下的美食列表
  32. * @return int
  33. * User: ZQ
  34. * Date: 2022/10/18
  35. */
  36. public static function getPlayAll()
  37. {
  38. $where = [];
  39. $where['play_is_del'] = 0;
  40. $where['play_status'] = 0;
  41. $where['play_type'] = 1;
  42. $list = LifePlay::where($where)
  43. ->select(['play_id','play_name'])
  44. ->get()
  45. ->toArray();
  46. return $list;
  47. }
  48. /**
  49. * Notes:修改农庄美食/采摘游玩
  50. * @param string $play_name
  51. * @param int $play_id
  52. * @return int
  53. * User: ZQ
  54. * Date: 2022/10/18
  55. */
  56. public static function updatePlay($play_id, $play_name, $play_img, $play_price, $play_shop_id, $play_valid, $play_time, $play_type, $play_package, $play_label, $play_status, $play_content, $play_category, $admin_id)
  57. {
  58. LifePlay::affairBegin();
  59. try {
  60. $where = [];
  61. $where['play_id'] = $play_id;
  62. $data = [];
  63. $data['play_name'] = $play_name;
  64. $data['play_img'] = $play_img;
  65. $data['play_price'] = $play_price;
  66. $data['play_shop_id'] = $play_shop_id;
  67. $data['play_valid'] = $play_valid;
  68. $data['play_time'] = $play_time;
  69. $data['play_category'] = $play_category;
  70. $data['play_type'] = $play_type;
  71. $data['play_package'] = $play_package;
  72. $data['play_label'] = $play_label;
  73. $data['play_status'] = $play_status;
  74. $data['play_content'] = $play_content;
  75. $data['play_update_time'] = time();
  76. $result = LifePlay::where($where)->update($data);
  77. if ($result !== false){
  78. if ($play_category == 1){
  79. $name = '农庄美食';
  80. }else{
  81. $name = '采摘游玩';
  82. }
  83. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '修改'.$name.'-编号: ' . $play_id;
  84. plog('life-play-update', '悦活-'.$name.'-修改'.$name, $msg);
  85. LifePlay::affairCommit();
  86. return true;
  87. }
  88. throw new \Exception('操作失败!');
  89. }catch (\Exception $exception){
  90. LifePlay::affairRollback();
  91. throw new \Exception($exception->getMessage(), 500);
  92. }
  93. }
  94. /**
  95. * Notes:删除农庄美食/采摘游玩
  96. * @param int $play_id
  97. * @return int
  98. * User: ZQ
  99. * Date: 2022/10/18
  100. */
  101. public static function delPlay($play_id,$admin_id)
  102. {
  103. LifePlay::affairBegin();
  104. try {
  105. $where = [];
  106. $where['play_id'] = $play_id;
  107. $data['play_is_del'] = 1;
  108. $result = LifePlay::where($where)->update($data);
  109. if (!empty($result)){
  110. // $play_category = LifePlay::where($where)->first('play_category');
  111. // if ($play_category == 1){
  112. // $name = '农庄美食';
  113. // }else{
  114. // $name = '采摘游玩';
  115. // }
  116. $name = '农庄美食';
  117. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除'.$name.'-编号: ' . $play_id;
  118. plog('life-play-delete', '悦活-'.$name.'-删除'.$name, $msg);
  119. LifePlay::affairCommit();
  120. return true;
  121. }else{
  122. return false;
  123. }
  124. }catch (\Exception $exception){
  125. LifePlay::affairRollback();
  126. throw new \Exception($exception->getMessage(), 500);
  127. }
  128. }
  129. /**
  130. * Notes: 添加农庄美食/采摘游玩
  131. * @param string $play_name
  132. * @param array $play_rules
  133. * @return int
  134. * User: ZQ
  135. * Date: 2022/10/18
  136. */
  137. public static function insertPlay($play_name, $play_img, $play_price, $play_shop_id, $play_valid, $play_time, $play_type, $play_package, $play_label, $play_status, $play_content, $play_category, $admin_id)
  138. {
  139. LifePlay::affairBegin();
  140. try {
  141. $data = [];
  142. $data['play_name'] = $play_name;
  143. $data['play_img'] = $play_img;
  144. $data['play_price'] = $play_price;
  145. $data['play_shop_id'] = $play_shop_id;
  146. $data['play_valid'] = $play_valid;
  147. $data['play_time'] = $play_time;
  148. $data['play_category'] = $play_category;
  149. $data['play_type'] = $play_type;
  150. $data['play_package'] = $play_package;
  151. $data['play_label'] = $play_label;
  152. $data['play_status'] = $play_status;
  153. $data['play_content'] = $play_content;
  154. $data['play_create_time'] = time();
  155. $result = LifePlay::insertGetId($data);
  156. if (!empty($result)){
  157. if ($play_category == 1){
  158. $name = '农庄美食';
  159. }else{
  160. $name = '采摘游玩';
  161. }
  162. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加'.$name.'-编号: ' . $result;
  163. plog('life-play-create', '悦活-'.$name.'-添加'.$name, $msg);
  164. LifePlay::affairCommit();
  165. return $result;
  166. }
  167. throw new \Exception('操作失败!');
  168. }catch (\Exception $exception){
  169. LifePlay::affairRollback();
  170. throw new \Exception($exception->getMessage(), 500);
  171. }
  172. }
  173. /**
  174. * Notes:查询农庄美食/采摘游玩
  175. * @param int $play_id
  176. * @return int
  177. * User: ZQ
  178. * Date: 2022/10/18
  179. */
  180. public static function playInfo($play_id)
  181. {
  182. $where = [];
  183. $where['play_id'] = $play_id;
  184. $result = LifePlay::where($where)->first();
  185. if (!empty($result)){
  186. $result['play_materials'] = json_decode($result['play_materials'],true);
  187. $result['play_condiment'] = json_decode($result['play_condiment'],true);
  188. $result['play_create_time'] = date('Y-m-d H:i:s',$result['play_create_time']);
  189. if (!empty($result['play_update_time'])){
  190. $result['play_update_time'] = date('Y-m-d H:i:s',$result['play_update_time']);
  191. }
  192. }
  193. return $result;
  194. }
  195. /**
  196. * Notes:修改农庄美食/采摘游玩状态
  197. * @param string $play_name
  198. * @param int $play_status
  199. * @return int
  200. * User: ZQ
  201. * Date: 2022/9/15
  202. */
  203. public static function updateStatus($play_id, $play_status)
  204. {
  205. LifePlay::affairBegin();
  206. try {
  207. $where = [];
  208. $where['play_id'] = $play_id;
  209. $data = [];
  210. $data['play_status'] = $play_status;
  211. $result = LifePlay::where($where)->update($data);
  212. if ($result !== false){
  213. LifePlay::affairCommit();
  214. return true;
  215. }
  216. throw new \Exception('操作失败!');
  217. }catch (\Exception $exception){
  218. LifePlay::affairRollback();
  219. throw new \Exception($exception->getMessage(), 500);
  220. }
  221. }
  222. }