WebParts.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace addons\qingdongams\controller;
  3. use addons\qingdongams\model\Product;
  4. use addons\qingdongams\model\Parts as PartsModel;
  5. use think\Db;
  6. class WebParts extends WebIndexApi
  7. {
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. }
  12. // 获取产品列表
  13. public function getProductList(){
  14. $name = input('name');
  15. $where = [];
  16. if ($name) {
  17. $where['name'] = ['like', "%{$name}%"];
  18. }
  19. $list = Product::where($where)->with(['createStaff'])->field('id,name,status')->select();
  20. $this->success('请求成功', $list);
  21. }
  22. // 获取配件列表
  23. public function getPartsList(){
  24. $limit = input("limit/d", 10);
  25. $params = $this->request->post();
  26. $where = $followWhere = [];
  27. $order = 'id desc';
  28. if (isset($params['name']) && $params['name']) {//配件名称
  29. $where['name'] = ['like', "%{$params['name']}%"];
  30. }
  31. if (isset($params['product_id']) && $params['product_id']) {//产品名称
  32. $product_id=intval($params['product_id']);
  33. $followWhere[] = ['exp', Db::raw('FIND_IN_SET(' .$product_id. ',product_id)')];
  34. }
  35. $list = PartsModel::where($where)->where($followWhere)->order($order)->paginate($limit);
  36. $this->success('请求成功', $list);
  37. }
  38. }