GoodsManager.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2017/6/27
  6. * Time: 上午10:14
  7. */
  8. namespace app\frontend\modules\goods\services;
  9. use app\frontend\models\Goods;
  10. use app\frontend\models\goods\Sale;
  11. use app\frontend\models\GoodsOption;
  12. use Illuminate\Container\Container;
  13. class GoodsManager extends Container
  14. {
  15. public function __construct()
  16. {
  17. $this->bind('Goods', function ($goodsManager, $attributes = []) {
  18. if(\YunShop::isApi()){
  19. //前台
  20. return new Goods($attributes);
  21. }else{
  22. //后台
  23. return new \app\backend\modules\goods\models\Goods($attributes);
  24. }
  25. });
  26. $this->bind('GoodsOption', function ($goodsManager, $attributes = []) {
  27. if(\YunShop::isApi()){
  28. //前台
  29. return new GoodsOption($attributes);
  30. }else{
  31. //后台
  32. return new \app\backend\modules\goods\models\GoodsOption($attributes);
  33. }
  34. });
  35. $this->bind('GoodsSale', function ($goodsManager, $attributes = []) {
  36. if(\YunShop::isApi()){
  37. //前台
  38. return new Sale($attributes);
  39. }else{
  40. //后台
  41. return new \app\backend\modules\goods\models\Sale($attributes);
  42. }
  43. });
  44. }
  45. }