GoodsResource.php 3.0 KB

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