CategoryLogic.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\shop\logic\goods;
  3. use app\common\model\shop\ShopGoodsCategory as ShopGoodsCategoryModel;
  4. class CategoryLogic
  5. {
  6. public static function lists($get)
  7. {
  8. $lists = ShopGoodsCategoryModel::where(['del' => 0, 'shop_id' => $get['shop_id']])
  9. ->page($get['page'], $get['limit'])
  10. ->order('sort', 'asc')
  11. ->select();
  12. $count = ShopGoodsCategoryModel::where(['del' => 0, 'shop_id' => $get['shop_id']])->count();
  13. if($lists) {
  14. $lists = $lists->toArray();
  15. }
  16. $data = [
  17. 'count' => $count,
  18. 'lists' => $lists
  19. ];
  20. return $data;
  21. }
  22. /**
  23. * 添加
  24. */
  25. public static function add($post)
  26. {
  27. $post['create_time'] = time();
  28. return ShopGoodsCategoryModel::create($post);
  29. }
  30. /**
  31. * 获取商品分类信息
  32. */
  33. public static function getCategory($id)
  34. {
  35. return ShopGoodsCategoryModel::find($id);
  36. }
  37. /**
  38. * 编辑商品分类
  39. */
  40. public static function edit($post)
  41. {
  42. $post['update_time'] = time();
  43. return ShopGoodsCategoryModel::update($post);
  44. }
  45. /**
  46. * 删除商品分类
  47. */
  48. public static function del($post)
  49. {
  50. $post['update_time'] = time();
  51. $post['del'] = 1;
  52. return ShopGoodsCategoryModel::update($post);
  53. }
  54. /**
  55. * 修改是否显示状态
  56. */
  57. public static function switchStatus($post)
  58. {
  59. $post['is_show'] = $post['status'];
  60. unset($post['status']);
  61. return ShopGoodsCategoryModel::update($post);
  62. }
  63. /**
  64. * 店铺商品分类
  65. */
  66. public static function listAll($shop_id)
  67. {
  68. $lists = ShopGoodsCategoryModel::field('id,name')->where([
  69. 'del'=>0,
  70. 'shop_id' => $shop_id
  71. ])->order('id', 'asc')->select();
  72. return empty($lists) ? [] : $lists->toArray();
  73. }
  74. }