OrderFrontendButtonBase.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/7/28
  8. * Time: 9:10
  9. */
  10. namespace app\frontend\modules\order\services;
  11. use app\common\models\Order;
  12. use app\frontend\modules\order\operations\OrderOperationInterface;
  13. abstract class OrderFrontendButtonBase
  14. {
  15. /**
  16. * @var Order
  17. */
  18. protected $order;
  19. public function init(Order $order)
  20. {
  21. $this->order = $order;
  22. }
  23. abstract function enable();
  24. abstract function getButton();
  25. protected function getStatus()
  26. {
  27. $method = $this->__getStatus($this->order->status);
  28. if (empty($method) || !method_exists($this,$method)) {
  29. return [];
  30. }
  31. return $this->$method();
  32. }
  33. protected function __getStatus($status)
  34. {
  35. $arr = [
  36. -1 => 'close',
  37. 0 => 'waitPay',
  38. 1 => 'waitSend',
  39. 2 => 'waitReceive',
  40. 3 => 'complete',
  41. ];
  42. return $arr[$status];
  43. }
  44. protected function waitPay()
  45. {
  46. $arr = \app\common\modules\shop\OrderFrontendButtonConfig::current()->get('member_order_operations.waitPay');
  47. return $this->replaceButton($arr,'waitPay');
  48. }
  49. protected function waitSend()
  50. {
  51. $arr = \app\common\modules\shop\OrderFrontendButtonConfig::current()->get('member_order_operations.waitSend');
  52. return $this->replaceButton($arr,'waitSend');
  53. }
  54. protected function waitReceive()
  55. {
  56. $arr = \app\common\modules\shop\OrderFrontendButtonConfig::current()->get('member_order_operations.waitReceive');
  57. return $this->replaceButton($arr,'waitReceive');
  58. }
  59. protected function complete()
  60. {
  61. $arr = \app\common\modules\shop\OrderFrontendButtonConfig::current()->get('member_order_operations.complete');
  62. return $this->replaceButton($arr,'complete');
  63. }
  64. protected function close()
  65. {
  66. $arr = \app\common\modules\shop\OrderFrontendButtonConfig::current()->get('member_order_operations.close');
  67. return $this->replaceButton($arr,'close');
  68. }
  69. /**
  70. * 执行按钮替换
  71. * @param $button
  72. * @param $key
  73. * @return array
  74. */
  75. protected function replaceButton($button,$key)
  76. {
  77. $replace = \app\common\modules\shop\OrderFrontendButtonConfig::current()->get('replace_order_frontend_button.'.$key);
  78. foreach ($replace as $value) {
  79. /**
  80. * @var OrderOperationInterface $operation
  81. */
  82. if (!class_exists($value['replace'])) {
  83. continue;
  84. }
  85. $operation = new $value['replace']($this->order);
  86. if (method_exists($operation,'isReplace') && $operation->isReplace()) {
  87. //替换验证通过
  88. $key = array_search($value['search'],$button);
  89. if ($key === false) {//未找到,直接加入
  90. $button[] = $value['replace'];
  91. } else {
  92. $button[$key] = $value['replace'];
  93. }
  94. }
  95. }
  96. return $button;
  97. }
  98. }