Spec.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Spec extends BaseModel
  12. {
  13. public $page_info;
  14. /**
  15. * 规格列表
  16. * @access public
  17. * @author csdeshang
  18. * @param type $condition 条件
  19. * @param type $pagesize 分页
  20. * @param type $order 排序
  21. * @return type
  22. */
  23. public function getSpecList($condition, $pagesize = '', $order = 'sp_id desc')
  24. {
  25. if ($pagesize) {
  26. $result = Db::name('spec')->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  27. $this->page_info = $result;
  28. return $result->items();
  29. } else {
  30. return Db::name('spec')->where($condition)->order($order)->select()->toArray();
  31. }
  32. }
  33. /**
  34. * 单条规格信息
  35. * @access public
  36. * @author csdeshang
  37. * @param type $sp_id 规格ID
  38. * @param type $field 字段
  39. * @return type
  40. */
  41. public function getSpecInfo($sp_id, $field = '*')
  42. {
  43. return Db::name('spec')->where('sp_id', $sp_id)->field($field)->find();
  44. }
  45. /**
  46. * 规格值列表
  47. * @access public
  48. * @author csdeshang
  49. * @param type $where 条件
  50. * @param type $field 字段
  51. * @param type $order 排序
  52. * @return type
  53. */
  54. public function getSpecvalueList($where, $field = '*', $order = 'spvalue_sort asc,spvalue_id asc')
  55. {
  56. $result = Db::name('specvalue')->field($field)->where($where)->order($order)->select()->toArray();
  57. return empty($result) ? array() : $result;
  58. }
  59. /**
  60. * 更新规格值
  61. * @access public
  62. * @author csdeshang
  63. * @param array $update 更新数据
  64. * @param array $where 条件
  65. * @return boolean
  66. */
  67. public function editSpecvalue($update, $where)
  68. {
  69. $result = Db::name('specvalue')->where($where)->update($update);
  70. return $result;
  71. }
  72. /**
  73. * 增加规格值
  74. * @access public
  75. * @author csdeshang
  76. * @param array $data 数据
  77. * @return boolean
  78. */
  79. public function addSpecvalue($data)
  80. {
  81. $result = Db::name('specvalue')->insertGetId($data);
  82. return $result;
  83. }
  84. /**
  85. * 添加规格 多条
  86. * @access public
  87. * @author csdeshang
  88. * @param array $data 数据
  89. * @return boolean
  90. */
  91. public function addSpecvalueALL($data)
  92. {
  93. $result = Db::name('specvalue')->insertAll($data);
  94. return $result;
  95. }
  96. /**
  97. * 删除规格值
  98. * @access public
  99. * @author csdeshang
  100. * @param array $where 条件
  101. * @return boolean
  102. */
  103. public function delSpecvalue($where)
  104. {
  105. $result = Db::name('specvalue')->where($where)->delete();
  106. return $result;
  107. }
  108. /**
  109. * 更新规格信息
  110. * @access public
  111. * @author csdeshang
  112. * @param type $update 更新数据
  113. * @param type $condition 条件
  114. * @return boolean
  115. */
  116. public function editSpec($update, $condition)
  117. {
  118. if (empty($update)) {
  119. return false;
  120. }
  121. return Db::name('spec')->where($condition)->update($update);
  122. }
  123. /**
  124. * 添加规格信息
  125. * @access public
  126. * @author csdeshang
  127. * @param type $data 数据
  128. * @return type
  129. */
  130. public function addSpec($data)
  131. {
  132. // 规格表插入数据
  133. $result = Db::name('spec')->insertGetId($data);
  134. return $result;
  135. }
  136. /**
  137. * 删除规格
  138. * @access public
  139. * @author csdeshang
  140. * @param type $condition 条件
  141. * @return type
  142. */
  143. public function delSpec($condition)
  144. {
  145. return Db::name('spec')->where($condition)->delete();
  146. }
  147. }