ShMethodController.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. class ShMethodController extends BaseController
  8. {
  9. /**
  10. * 获取供货商所有的5种配送方式配置
  11. * 如果数据库里没有,则取默认配置进行初始化
  12. */
  13. public function actionGetAllMethod()
  14. {
  15. $ghsId = Yii::$app->request->get('ghsId', 0);
  16. $ghs = GhsClass::getById($ghsId);
  17. if (empty($ghs)) {
  18. util::fail('没有供货商信息');
  19. }
  20. if ($ghs['ownMainId'] != $this->mainId) {
  21. util::fail('不是你的供货商');
  22. }
  23. $shopId = $ghs['shopId'] ?? 0;
  24. $mainId = $ghs['mainId'] ?? 0;
  25. if (!in_array($shopId, [36523, 0])) {
  26. util::success([]);
  27. }
  28. try {
  29. $customId = $ghs['customId'] ?? 0;
  30. $configs = ShMethodClass::getAllConfigs($shopId, $mainId);
  31. if (isset($ghs['homeRule']) && $ghs['homeRule'] == 1) {
  32. foreach ($configs as &$config) {
  33. if ($config['style'] == 0) {
  34. $config['status'] = $ghs['home'] ?? 0;
  35. $config['minAmount'] = $ghs['homeAmount'] ?? 0;
  36. $config['minNum'] = $ghs['homeNum'] ?? 0;
  37. $config['unMeet'] = $ghs['homeUnMeet'] ?? 0;
  38. $config['unMeetFee'] = $ghs['homeUnFee'] ?? 0;
  39. }
  40. }
  41. }
  42. if ($customId > 0) {
  43. foreach ($configs as &$config) {
  44. $style = (int)($config['style'] ?? 0);
  45. $unMeet = (int)($config['unMeet'] ?? 0);
  46. // 针对每个配送方式分别检查是否已支付运费或包装费
  47. $hasPaidSendCost = ShMethodClass::isSendCostPaidToday($customId, $style);
  48. $hasPaidPackCost = ShMethodClass::isPackPaidToday($customId, $style);
  49. // 如果是加收运费或加收包装费,并且今天已经收过对应的费用
  50. // 则将前端展示的条件清空(设为0),从而不再显示要收附加费的提示
  51. if ($unMeet === 0 && $hasPaidSendCost) {
  52. $config['minAmount'] = 0;
  53. $config['minNum'] = 0;
  54. $config['unMeetFee'] = 0;
  55. } elseif ($unMeet === 1 && $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. }