Spec.php 4.2 KB

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