GoodsResource.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class GoodsResource extends BaseModel
  12. {
  13. public $page_info;
  14. /**
  15. * 查询列表
  16. * @access public
  17. * @author csdeshang
  18. * @param array $condition 检索条件
  19. * @param int $pagesize 分页信息
  20. * @param string $order 排序
  21. * @return array
  22. */
  23. public function getGoodsResourceList($condition, $pagesize = 0, $order = 'goods_resource_id desc')
  24. {
  25. if ($pagesize) {
  26. $res = Db::name('goods_resource')->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  27. $this->page_info = $res;
  28. return $res->items();
  29. } else {
  30. return Db::name('goods_resource')->where($condition)->order($order)->select()->toArray();
  31. }
  32. }
  33. /**
  34. * 取单个内容
  35. * @access public
  36. * @author csdeshang
  37. * @param int $id 分类ID
  38. * @return array 数组类型的返回结果
  39. */
  40. public function getGoodsResourceInfo($condition)
  41. {
  42. return Db::name('goods_resource')->where($condition)->find();
  43. }
  44. /**
  45. * 新增
  46. * @access public
  47. * @author csdeshang
  48. * @param array $data 参数内容
  49. * @return bool 布尔类型的返回结果
  50. */
  51. public function addGoodsResource($data)
  52. {
  53. return Db::name('goods_resource')->insertGetId($data);
  54. }
  55. /**
  56. * 更新信息
  57. * @access public
  58. * @author csdeshang
  59. * @param array $data 更新数据
  60. * @param array $condition 条件数组
  61. * @return bool 布尔类型的返回结果
  62. */
  63. public function editGoodsResource($data, $condition)
  64. {
  65. return Db::name('goods_resource')->where($condition)->update($data);
  66. }
  67. /**
  68. * 删除图片信息,根据where
  69. * @access public
  70. * @author csdeshang
  71. * @param array $condition 条件数组
  72. * @return bool 布尔类型的返回结果
  73. */
  74. public function delGoodsResource($condition, $store_id)
  75. {
  76. if (empty($condition)) {
  77. return false;
  78. }
  79. $image_more = Db::name('goods_resource')->where($condition)->field('file_name')->select()->toArray();
  80. if (is_array($image_more) && !empty($image_more)) {
  81. foreach ($image_more as $v) {
  82. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_GOODS_RESOURCE . DIRECTORY_SEPARATOR . $store_id . DIRECTORY_SEPARATOR . $v['file_name']);
  83. }
  84. }
  85. $state = Db::name('goods_resource')->where($condition)->delete();
  86. return $state;
  87. }
  88. }