HomeGoodsServer.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\admin\server\home;
  3. use app\admin\model\HomeGoods;
  4. use app\admin\model\HomeBanner;
  5. use app\admin\model\SystemMenu;
  6. use support\Redis;
  7. class HomeGoodsServer
  8. {
  9. /**
  10. * Notes:获取项目列表
  11. * @param string $keywords
  12. * @param int $page
  13. * @param int $limit
  14. * @return array
  15. * User: YCP
  16. * Date: 2022/10/31
  17. */
  18. public static function getGoodsList(int $page,int $limit,string $keywords,$category_id)
  19. {
  20. [$list, $count] = HomeGoods::getGoodsList($page,$limit,$keywords,$category_id);
  21. return compact('list','count');
  22. }
  23. /**
  24. * Notes: 添加项目
  25. * @param string $goods_name
  26. * @param array $goods_rules
  27. * @return int
  28. * User: YCP
  29. * Date: 2022/10/31
  30. */
  31. public static function insertGoods(array $params, int $admin_id)
  32. {
  33. HomeGoods::affairBegin();
  34. try {
  35. $params['goods_create_time'] = time();
  36. $result = HomeGoods::insertGetId($params);
  37. if (!empty($result)){
  38. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加居家项目-编号: ' . $result;
  39. plog('life-homegoods-create', '居家-添加项目', $msg);
  40. HomeGoods::affairCommit();
  41. return $result;
  42. }
  43. throw new \Exception('操作失败!');
  44. }catch (\Exception $exception){
  45. HomeGoods::affairRollback();
  46. throw new \Exception($exception->getMessage(), 500);
  47. }
  48. }
  49. /**
  50. * Notes:修改项目
  51. * @param string $goods_name
  52. * @param int $goods_id
  53. * @return int
  54. * User: YCP
  55. * Date: 2022/10/31
  56. */
  57. public static function updateGoods(array $params, int $admin_id)
  58. {
  59. HomeGoods::affairBegin();
  60. try {
  61. $where = [];
  62. $where['goods_id'] = $params['goods_id'];
  63. $info = HomeGoods::where($where)->first();
  64. if(empty($info) || $info === false)
  65. {
  66. throw new \Exception('项目信息不存在');
  67. }
  68. $params['goods_update_time'] = time();
  69. $result = HomeGoods::where($where)->update($params);
  70. if ($result !== false){
  71. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '修改居家项目-编号: ' . $params['goods_id'];
  72. plog('life-homegoods-update', '居家-修改项目', $msg);
  73. HomeGoods::affairCommit();
  74. return true;
  75. }
  76. throw new \Exception('操作失败!');
  77. }catch (\Exception $exception){
  78. HomeGoods::affairRollback();
  79. throw new \Exception($exception->getMessage(), 500);
  80. }
  81. }
  82. /**
  83. * Notes:删除项目
  84. * @param int $goods_id
  85. * @return int
  86. * User: YCP
  87. * Date: 2022/10/31
  88. */
  89. public static function delGoods($goods_id,$admin_id)
  90. {
  91. HomeGoods::affairBegin();
  92. try {
  93. $where = [];
  94. $where['goods_id'] = $goods_id;
  95. $data['goods_is_del'] = 1;
  96. $result = HomeGoods::where($where)->update($data);
  97. if (!empty($result)){
  98. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除项目-编号: ' . $goods_id;
  99. plog('life-homegoods-delete', '居家-删除项目', $msg);
  100. HomeGoods::affairCommit();
  101. return true;
  102. }else{
  103. return false;
  104. }
  105. }catch (\Exception $exception){
  106. HomeGoods::affairRollback();
  107. throw new \Exception($exception->getMessage(), 500);
  108. }
  109. }
  110. /**
  111. * Notes:查询项目
  112. * @param int $goods_id
  113. * @return int
  114. * User: YCP
  115. * Date: 2022/10/31
  116. */
  117. public static function goodsInfo($goods_id)
  118. {
  119. $where = [];
  120. $where['goods_id'] = $goods_id;
  121. $result = HomeGoods::where($where)->first();
  122. if(empty($result) || $result === false)
  123. {
  124. throw new \Exception('项目信息不存在');
  125. }
  126. return $result;
  127. }
  128. }