Product.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class Product extends Model
  5. {
  6. public $page_info;
  7. /*
  8. * 新增产品
  9. */
  10. public function addProduct($param)
  11. {
  12. return db('product')->insertGetId($param);
  13. }
  14. /*
  15. * 编辑产品
  16. */
  17. public function editProduct($condition, $update)
  18. {
  19. return db('product')->where($condition)->update($update);
  20. }
  21. /**
  22. * 删除产品
  23. * @param unknown $condition
  24. * @return boolean
  25. */
  26. public function delProduct($condition)
  27. {
  28. $product_array = $this->getProductList($condition, 'product_id');
  29. $productid_array = array();
  30. foreach ($product_array as $value) {
  31. $productid_array[] = $value['product_id'];
  32. // @unlink(BASE_UPLOAD_PATH . DS . ATTACH_PRODUCT . DS . $value['product_img']);
  33. }
  34. return db('product')->where(array('product_id' => array('in', $productid_array)))->delete();
  35. }
  36. /*
  37. * 产品列表
  38. */
  39. public function getProductList($condition, $field = '*', $page = 0, $order = 'product_id desc', $limit = '')
  40. {
  41. if ($limit) {
  42. return db('product')->where($condition)->field($field)->order($order)->page($page)->limit($limit)->select();
  43. } else {
  44. $res = db('product')->where($condition)->field($field)->order($order)->paginate($page);
  45. $this->page_info = $res;
  46. return $res->items();
  47. }
  48. }
  49. /**
  50. * 取单个产品内容
  51. */
  52. public function getOneProduct($condition, $field = '*')
  53. {
  54. return db('product')->field($field)->where($condition)->find();
  55. }
  56. }
  57. ?>