ShMethodController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace hd\controllers;
  3. use bizGhs\order\classes\ShMethodClass;
  4. use bizHd\ghs\classes\GhsClass;
  5. use Yii;
  6. use common\components\util;
  7. /**
  8. * 花店配送方式接口(供货商 xhSh* 表,供进货结算等场景)
  9. * 用途:门店向供货商下单时读取配送配置;设置页请走 PsMethodController
  10. */
  11. class ShMethodController extends BaseController
  12. {
  13. /**
  14. * 获取供货商所有的5种配送方式配置
  15. * 如果数据库里没有,则取默认配置进行初始化
  16. */
  17. public function actionGetAllMethod()
  18. {
  19. $ghsId = Yii::$app->request->get('ghsId', 0);
  20. $ghs = GhsClass::getById($ghsId);
  21. if (empty($ghs)) {
  22. util::fail('没有供货商信息');
  23. }
  24. if ($ghs['ownMainId'] != $this->mainId) {
  25. util::fail('不是你的供货商');
  26. }
  27. $shopId = $ghs['shopId'] ?? 0;
  28. $mainId = $ghs['mainId'] ?? 0;
  29. if (!in_array($shopId, [36523, 0])) {
  30. util::success([]);
  31. }
  32. try {
  33. $customId = $ghs['customId'] ?? 0;
  34. $configs = ShMethodClass::getAllConfigs($shopId, $mainId);
  35. if (isset($ghs['homeRule']) && $ghs['homeRule'] == 1) {
  36. foreach ($configs as &$config) {
  37. if ($config['style'] == 0) {
  38. $config['status'] = $ghs['home'] ?? 0;
  39. $config['minAmount'] = $ghs['homeAmount'] ?? 0;
  40. $config['minNum'] = $ghs['homeNum'] ?? 0;
  41. $config['unMeet'] = $ghs['homeUnMeet'] ?? 0;
  42. $config['unMeetFee'] = $ghs['homeUnFee'] ?? 0;
  43. }
  44. }
  45. }
  46. if ($customId > 0) {
  47. foreach ($configs as &$config) {
  48. $style = (int)($config['style'] ?? 0);
  49. $unMeet = (int)($config['unMeet'] ?? 0);
  50. // 针对每个配送方式分别检查是否已支付运费或包装费
  51. $hasPaidSendCost = ShMethodClass::isSendCostPaidToday($customId, $style);
  52. $hasPaidPackCost = ShMethodClass::isPackPaidToday($customId, $style);
  53. // 如果是加收运费、加收包装费或不能下单,并且今天已经成功下单/收取过费用
  54. // 则将前端展示的条件清空(设为0),从而不再显示要收附加费或限制下单的提示
  55. if (($unMeet === 0 && $hasPaidSendCost) || ($unMeet === 1 && $hasPaidPackCost) || ($unMeet === 2 && ($hasPaidSendCost || $hasPaidPackCost))) {
  56. $config['minAmount'] = 0;
  57. $config['minNum'] = 0;
  58. $config['unMeetFee'] = 0;
  59. }
  60. }
  61. }
  62. util::success(['method' => $configs]);
  63. } catch (\Exception $e) {
  64. util::fail($e->getMessage());
  65. }
  66. }
  67. }