FarmGoodsServer.php 5.1 KB

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