OrderManager.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2017/5/24
  6. * Time: 下午3:11
  7. */
  8. namespace app\common\modules\order;
  9. use app\backend\modules\order\models\Order;
  10. use app\common\models\order\OrderCoupon;
  11. use app\common\models\order\OrderDeduction;
  12. use app\common\models\order\OrderDiscount;
  13. use app\common\modules\trade\models\Trade;
  14. use app\framework\Log\SimpleLog;
  15. use app\frontend\models\MemberCart;
  16. use app\frontend\models\OrderAddress;
  17. use app\frontend\modules\dispatch\models\PreOrderAddress;
  18. use app\frontend\modules\orderGoods\models\PreOrderGoods;
  19. use app\frontend\modules\order\models\PreOrder;
  20. use Illuminate\Container\Container;
  21. class OrderManager extends Container
  22. {
  23. private $setting;
  24. /**
  25. * @var SimpleLog
  26. */
  27. public $log;
  28. public function __construct()
  29. {
  30. $this->log = new SimpleLog('order/order');
  31. $this->bindModels();
  32. $this->singleton(OrderOperationsCollector::class, function ($orderManager) {
  33. return new OrderOperationsCollector();
  34. });
  35. $this->setting = \app\common\modules\shop\ShopConfig::current()->get('shop-foundation.order');
  36. }
  37. public function setting($key = null)
  38. {
  39. return array_get($this->setting, $key);
  40. }
  41. private function bindModels()
  42. {
  43. $this->bind('PreOrderGoods', function ($orderManager, $attributes) {
  44. return new PreOrderGoods($attributes);
  45. });
  46. $this->bind('PreOrder', function ($orderManager, $attributes) {
  47. return new PreOrder($attributes);
  48. });
  49. $this->bind('PreOrderAddress', function ($orderManager, $attributes) {
  50. return new PreOrderAddress($attributes);
  51. });
  52. // 订单model
  53. $this->bind('Order', function ($orderManager, $attributes) {
  54. if (\YunShop::isApi()) {
  55. return new \app\frontend\models\Order($attributes);
  56. } else {
  57. return new Order();
  58. }
  59. });
  60. $this->bind('Member', function ($orderManager, $attributes) {
  61. return new \app\frontend\models\Member($attributes);
  62. });
  63. $this->bind('OrderDeduction', function ($orderManager, $attributes) {
  64. return new OrderDeduction($attributes);
  65. });
  66. $this->bind('OrderDiscount', function ($orderManager, $attributes) {
  67. return new OrderDiscount($attributes);
  68. });
  69. $this->bind('OrderCoupon', function ($orderManager, $attributes) {
  70. return new OrderCoupon($attributes);
  71. });
  72. $this->bind('MemberCart', function ($orderManager, $attributes) {
  73. return new MemberCart($attributes);
  74. });
  75. $this->bind('OrderAddress', function ($orderManager, $attributes) {
  76. return new OrderAddress($attributes);
  77. });
  78. $this->bind(Trade::class, function ($orderManager, $attributes) {
  79. return new Trade($attributes);
  80. });
  81. $this->bind(OrderCollection::class, function ($orderManager, $attributes) {
  82. return new OrderCollection($attributes);
  83. });
  84. }
  85. }