PackageGoodsServer.php 5.2 KB

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