LiveProduct.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\api\model\plus\live;
  3. use app\common\model\plus\live\LiveProduct as LiveProductModel;
  4. /**
  5. * 直播模型
  6. */
  7. class LiveProduct extends LiveProductModel
  8. {
  9. /**
  10. * 获取商品列表
  11. */
  12. public function getList($data)
  13. {
  14. return $this->with(['product.image.file'])
  15. ->where('shop_supplier_id', '=', $data['shop_supplier_id'])
  16. ->order(['create_time' => 'asc'])
  17. ->paginate($data);
  18. }
  19. /**
  20. * 保存
  21. */
  22. public function add($user, $productIds)
  23. {
  24. if(!isset($productIds) || $productIds == ''){
  25. return true;
  26. }
  27. $this->startTrans();
  28. try {
  29. $productList = [];
  30. $productIdArr = explode(',', $productIds);
  31. foreach ($productIdArr as $productId) {
  32. $productList[] = [
  33. 'user_id' => $user['user_id'],
  34. 'shop_supplier_id' => $user['supplierUser']['shop_supplier_id'],
  35. 'product_id' => $productId,
  36. 'app_id' => self::$app_id
  37. ];
  38. }
  39. $this->saveAll($productList);
  40. // 事务提交
  41. $this->commit();
  42. return true;
  43. } catch (\Exception $e) {
  44. $this->error = $e->getMessage();
  45. $this->rollback();
  46. return false;
  47. }
  48. }
  49. public function remove($product_id){
  50. return $this->where('product_id', '=', $product_id)
  51. ->delete();
  52. }
  53. //查询已经添加产品
  54. public function livProduct($shop_supplier_id){
  55. return $this->where('shop_supplier_id','=',$shop_supplier_id)->column('product_id');
  56. }
  57. }