PackageServer.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace app\admin\server\life;
  3. use app\admin\model\LifePackage;
  4. use app\admin\model\SystemMenu;
  5. use support\Redis;
  6. class PackageServer
  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/18
  16. */
  17. public static function getPackageList(int $page, int $limit, string $keywords,$package_type)
  18. {
  19. [$list, $count] = LifePackage::getPackageList($page, $limit, $keywords,$package_type);
  20. /*if (!empty($list)){
  21. foreach ($list as $k => $v){
  22. $list[$k]['package_create_time'] = date('Y-m-d H:i:s',$v['package_create_time']);
  23. if (!empty($v['package_update_time'])){
  24. $list[$k]['package_update_time'] = date('Y-m-d H:i:s',$v['package_update_time']);
  25. }
  26. }
  27. }*/
  28. return compact('list', 'page', 'limit', 'count');
  29. }
  30. /**
  31. * Notes: 添加套餐
  32. * @param string $package_name
  33. * @param array $package_rules
  34. * @return int
  35. * User: YCP
  36. * Date: 2022/10/18
  37. */
  38. public static function insertPackage(array $params, int $admin_id)
  39. {
  40. LifePackage::affairBegin();
  41. try {
  42. //检测套餐名是否重复
  43. if(LifePackage::checkPackageName($params['package_name']))
  44. {
  45. throw new \Exception($params['package_name'] . '套餐名已存在');
  46. }
  47. $params['package_create_time'] = time();
  48. $result = LifePackage::insertGetId($params);
  49. if (!empty($result)){
  50. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加悦活套餐-编号: ' . $result;
  51. plog('life-package-create', '悦活-添加套餐', $msg);
  52. LifePackage::affairCommit();
  53. return $result;
  54. }
  55. throw new \Exception('操作失败!');
  56. }catch (\Exception $exception){
  57. LifePackage::affairRollback();
  58. throw new \Exception($exception->getMessage(), 500);
  59. }
  60. }
  61. /**
  62. * Notes:修改套餐
  63. * @param string $package_name
  64. * @param int $package_id
  65. * @return int
  66. * User: YCP
  67. * Date: 2022/10/18
  68. */
  69. public static function updatePackage(array $params, int $admin_id)
  70. {
  71. LifePackage::affairBegin();
  72. try {
  73. $where = [];
  74. $where['package_id'] = $params['package_id'];
  75. $info = LifePackage::where($where)->first();
  76. if(empty($info) || $info === false)
  77. {
  78. throw new \Exception('套餐信息不存在');
  79. }
  80. $params['package_update_time'] = time();
  81. $result = LifePackage::where($where)->update($params);
  82. if ($result !== false){
  83. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '修改悦活套餐-编号: ' . $params['package_id'];
  84. plog('life-package-update', '悦活-修改套餐', $msg);
  85. LifePackage::affairCommit();
  86. return true;
  87. }
  88. throw new \Exception('操作失败!');
  89. }catch (\Exception $exception){
  90. LifePackage::affairRollback();
  91. throw new \Exception($exception->getMessage(), 500);
  92. }
  93. }
  94. /**
  95. * Notes:删除套餐
  96. * @param int $package_id
  97. * @return int
  98. * User: YCP
  99. * Date: 2022/10/18
  100. */
  101. public static function delPackage($package_id,$admin_id)
  102. {
  103. LifePackage::affairBegin();
  104. try {
  105. $where = [];
  106. $where['package_id'] = $package_id;
  107. $data['package_is_del'] = 1;
  108. $result = LifePackage::where($where)->update($data);
  109. if (!empty($result)){
  110. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除套餐-编号: ' . $package_id;
  111. plog('life-farm-package-delete', '悦活-删除套餐', $msg);
  112. LifePackage::affairCommit();
  113. return true;
  114. }else{
  115. return false;
  116. }
  117. }catch (\Exception $exception){
  118. LifePackage::affairRollback();
  119. throw new \Exception($exception->getMessage(), 500);
  120. }
  121. }
  122. /**
  123. * Notes:查询套餐
  124. * @param int $package_id
  125. * @return int
  126. * User: YCP
  127. * Date: 2022/10/18
  128. */
  129. public static function packageInfo($package_id)
  130. {
  131. $where = [];
  132. $where['package_id'] = $package_id;
  133. $result = LifePackage::where($where)->first();
  134. if(empty($result) || $result === false)
  135. {
  136. throw new \Exception('套餐信息不存在');
  137. }
  138. $result['package_images'] = explode(",",$result['package_images']);
  139. /*if (!empty($result)){
  140. $result['package_create_time'] = date('Y-m-d H:i:s',$result['package_create_time']);
  141. if (!empty($result['package_update_time'])){
  142. $result['package_update_time'] = date('Y-m-d H:i:s',$result['package_update_time']);
  143. }
  144. }*/
  145. return $result;
  146. }
  147. }