GoodsResource.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 数据层模型
  14. */
  15. class GoodsResource extends BaseModel {
  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. if ($pagesize) {
  28. $res = Db::name('goods_resource')->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  29. $this->page_info = $res;
  30. return $res->items();
  31. } else {
  32. return Db::name('goods_resource')->where($condition)->order($order)->select()->toArray();
  33. }
  34. }
  35. /**
  36. * 取单个内容
  37. * @access public
  38. * @author csdeshang
  39. * @param int $id 分类ID
  40. * @return array 数组类型的返回结果
  41. */
  42. public function getGoodsResourceInfo($condition) {
  43. return Db::name('goods_resource')->where($condition)->find();
  44. }
  45. /**
  46. * 新增
  47. * @access public
  48. * @author csdeshang
  49. * @param array $data 参数内容
  50. * @return bool 布尔类型的返回结果
  51. */
  52. public function addGoodsResource($data) {
  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. return Db::name('goods_resource')->where($condition)->update($data);
  65. }
  66. /**
  67. * 删除图片信息,根据where
  68. * @access public
  69. * @author csdeshang
  70. * @param array $condition 条件数组
  71. * @return bool 布尔类型的返回结果
  72. */
  73. public function delGoodsResource($condition, $store_id) {
  74. if (empty($condition)) {
  75. return false;
  76. }
  77. $image_more = Db::name('goods_resource')->where($condition)->field('file_name')->select()->toArray();
  78. if (is_array($image_more) && !empty($image_more)) {
  79. foreach ($image_more as $v) {
  80. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_GOODS_RESOURCE . DIRECTORY_SEPARATOR . $store_id . DIRECTORY_SEPARATOR . $v['file_name']);
  81. }
  82. }
  83. $state = Db::name('goods_resource')->where($condition)->delete();
  84. return $state;
  85. }
  86. }