GoodsCate.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021 勾股工作室
  4. * @license https://opensource.org/licenses/Apache-2.0
  5. * @link https://www.gougucms.com
  6. */
  7. namespace app\admin\model;
  8. use think\model;
  9. class GoodsCate extends Model
  10. {
  11. /**
  12. * 获取分页列表
  13. * @param $where
  14. * @param $param
  15. */
  16. public function getGoodsCateList($where, $param)
  17. {
  18. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  19. $order = empty($param['order']) ? 'id desc' : $param['order'];
  20. try {
  21. $list = $this->where($where)->order($order)->paginate($rows, false, ['query' => $param]);
  22. return $list;
  23. } catch(\Exception $e) {
  24. return ['code' => 1, 'data' => [], 'msg' => $e->getMessage()];
  25. }
  26. }
  27. /**
  28. * 添加数据
  29. * @param $param
  30. */
  31. public function addGoodsCate($param)
  32. {
  33. $insertId = 0;
  34. try {
  35. $param['create_time'] = time();
  36. $insertId = $this->strict(false)->field(true)->insertGetId($param);
  37. add_log('add', $insertId, $param);
  38. } catch(\Exception $e) {
  39. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  40. }
  41. return to_assign(0,'操作成功',['aid'=>$insertId]);
  42. }
  43. /**
  44. * 编辑信息
  45. * @param $param
  46. */
  47. public function editGoodsCate($param)
  48. {
  49. try {
  50. $param['update_time'] = time();
  51. $this->where('id', $param['id'])->strict(false)->field(true)->update($param);
  52. add_log('edit', $param['id'], $param);
  53. } catch(\Exception $e) {
  54. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  55. }
  56. return to_assign();
  57. }
  58. /**
  59. * 根据id获取信息
  60. * @param $id
  61. */
  62. public function getGoodsCateById($id)
  63. {
  64. $info = $this->where('id', $id)->find();
  65. return $info;
  66. }
  67. /**
  68. * 删除信息
  69. * @param $id
  70. * @return array
  71. */
  72. public function delGoodsCateById($id,$type=0)
  73. {
  74. if($type==0){
  75. //逻辑删除
  76. try {
  77. $param['delete_time'] = time();
  78. $this->where('id', $id)->update(['delete_time'=>time()]);
  79. add_log('delete', $id);
  80. } catch(\Exception $e) {
  81. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  82. }
  83. }
  84. else{
  85. //物理删除
  86. try {
  87. $this->where('id', $id)->delete();
  88. add_log('delete', $id);
  89. } catch(\Exception $e) {
  90. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  91. }
  92. }
  93. return to_assign();
  94. }
  95. }