Spec.php 4.1 KB

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